diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-02-19 12:49:35 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-02-19 12:49:35 +0530 |
commit | ee158cc65f117f8fa10c4b706ff4009c579c7775 (patch) | |
tree | f5850266b77be37caa759bf1e92b2c628c58aa6c /components/script/dom/browsingcontext.rs | |
parent | ddf5e9dba56fe593a657c9b7fa4827604906b698 (diff) | |
parent | 152cec69eb20f52217aa1905255e4d439a7119b6 (diff) | |
download | servo-ee158cc65f117f8fa10c4b706ff4009c579c7775.tar.gz servo-ee158cc65f117f8fa10c4b706ff4009c579c7775.zip |
Auto merge of #9603 - Ms2ger:document-bc, r=jdm
Store a pointer to the browsing context in the Document.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9603)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/browsingcontext.rs')
-rw-r--r-- | components/script/dom/browsingcontext.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/components/script/dom/browsingcontext.rs b/components/script/dom/browsingcontext.rs index 7cd856cad7c..603b2c27f80 100644 --- a/components/script/dom/browsingcontext.rs +++ b/components/script/dom/browsingcontext.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::bindings::cell::DOMRefCell; use dom::bindings::conversions::{ToJSValConvertible, root_from_handleobject}; use dom::bindings::js::{JS, Root, RootedReference}; use dom::bindings::proxyhandler::{fill_property_descriptor, get_property_descriptor}; @@ -25,26 +26,24 @@ use js::jsval::{ObjectValue, UndefinedValue, PrivateValue}; #[dom_struct] pub struct BrowsingContext { reflector: Reflector, - history: Vec<SessionHistoryEntry>, + history: DOMRefCell<Vec<SessionHistoryEntry>>, active_index: usize, frame_element: Option<JS<Element>>, } impl BrowsingContext { - pub fn new_inherited(document: &Document, frame_element: Option<&Element>) -> BrowsingContext { + pub fn new_inherited(frame_element: Option<&Element>) -> BrowsingContext { BrowsingContext { reflector: Reflector::new(), - history: vec![SessionHistoryEntry::new(document)], + history: DOMRefCell::new(vec![]), active_index: 0, frame_element: frame_element.map(JS::from_ref), } } #[allow(unsafe_code)] - pub fn new(document: &Document, frame_element: Option<&Element>) -> Root<BrowsingContext> { + pub fn new(window: &Window, frame_element: Option<&Element>) -> Root<BrowsingContext> { unsafe { - let window = document.window(); - let WindowProxyHandler(handler) = window.windowproxy_handler(); assert!(!handler.is_null()); @@ -58,7 +57,7 @@ impl BrowsingContext { NewWindowProxy(cx, parent, handler)); assert!(!window_proxy.ptr.is_null()); - let object = box BrowsingContext::new_inherited(document, frame_element); + let object = box BrowsingContext::new_inherited(frame_element); let raw = Box::into_raw(object); SetProxyExtra(window_proxy.ptr, 0, PrivateValue(raw as *const _)); @@ -69,12 +68,18 @@ impl BrowsingContext { } } - pub fn active_document(&self) -> &Document { - &*self.history[self.active_index].document + pub fn init(&self, document: &Document) { + assert!(self.history.borrow().is_empty()); + assert_eq!(self.active_index, 0); + self.history.borrow_mut().push(SessionHistoryEntry::new(document)); + } + + pub fn active_document(&self) -> Root<Document> { + Root::from_ref(&*self.history.borrow()[self.active_index].document) } - pub fn active_window(&self) -> &Window { - self.active_document().window() + pub fn active_window(&self) -> Root<Window> { + Root::from_ref(self.active_document().window()) } pub fn frame_element(&self) -> Option<&Element> { |