Skip to content

Commit

Permalink
Added a TopLevelBrowsingContextId type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed May 22, 2017
1 parent b428a94 commit 4257736
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 231 deletions.
16 changes: 14 additions & 2 deletions components/constellation/browsingcontext.rs
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use euclid::size::TypedSize2D;
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, PipelineId};
use pipeline::Pipeline;
use script_traits::LoadData;
use std::collections::HashMap;
Expand All @@ -23,6 +23,9 @@ pub struct BrowsingContext {
/// The browsing context id.
pub id: BrowsingContextId,

/// The top-level browsing context ancestor
pub top_level_id: TopLevelBrowsingContextId,

/// The size of the frame.
pub size: Option<TypedSize2D<f32, CSSPixel>>,

Expand All @@ -45,9 +48,15 @@ pub struct BrowsingContext {
impl BrowsingContext {
/// Create a new browsing context.
/// Note this just creates the browsing context, it doesn't add it to the constellation's set of browsing contexts.
pub fn new(id: BrowsingContextId, pipeline_id: PipelineId, load_data: LoadData) -> BrowsingContext {
pub fn new(id: BrowsingContextId,
top_level_id: TopLevelBrowsingContextId,
pipeline_id: PipelineId,
load_data: LoadData)
-> BrowsingContext
{
BrowsingContext {
id: id,
top_level_id: top_level_id,
size: None,
pipeline_id: pipeline_id,
instant: Instant::now(),
Expand Down Expand Up @@ -118,6 +127,9 @@ pub struct SessionHistoryChange {
/// The browsing context to change.
pub browsing_context_id: BrowsingContextId,

/// The top-level browsing context ancestor.
pub top_level_browsing_context_id: TopLevelBrowsingContextId,

/// The pipeline for the document being loaded.
pub new_pipeline_id: PipelineId,

Expand Down
297 changes: 161 additions & 136 deletions components/constellation/constellation.rs

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions components/constellation/pipeline.rs
Expand Up @@ -15,7 +15,7 @@ use ipc_channel::Error;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use layout_traits::LayoutThreadFactory;
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, PipelineNamespaceId};
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, FrameType, PipelineId, PipelineNamespaceId};
use net::image_cache::ImageCacheImpl;
use net_traits::{IpcSend, ResourceThreads};
use net_traits::image_cache::ImageCache;
Expand Down Expand Up @@ -104,7 +104,7 @@ pub struct InitialPipelineState {
pub browsing_context_id: BrowsingContextId,

/// The ID of the top-level browsing context that contains this Pipeline.
pub top_level_browsing_context_id: BrowsingContextId,
pub top_level_browsing_context_id: TopLevelBrowsingContextId,

/// The ID of the parent pipeline and frame type, if any.
/// If `None`, this is the root.
Expand Down Expand Up @@ -201,6 +201,7 @@ impl Pipeline {
parent_info: state.parent_info,
new_pipeline_id: state.id,
browsing_context_id: state.browsing_context_id,
top_level_browsing_context_id: state.top_level_browsing_context_id,
load_data: state.load_data,
window_size: window_size,
pipeline_port: pipeline_port,
Expand Down Expand Up @@ -393,7 +394,7 @@ impl Pipeline {
/// This will cause an event to be fired on an iframe in the document,
/// or on the `Window` if no frame is given.
pub fn trigger_mozbrowser_event(&self,
child_id: Option<BrowsingContextId>,
child_id: Option<TopLevelBrowsingContextId>,
event: MozBrowserEvent) {
assert!(PREFS.is_mozbrowser_enabled());

Expand Down Expand Up @@ -433,8 +434,8 @@ impl Pipeline {
#[derive(Deserialize, Serialize)]
pub struct UnprivilegedPipelineContent {
id: PipelineId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: BrowsingContextId,
parent_info: Option<(PipelineId, FrameType)>,
constellation_chan: IpcSender<ScriptMsg>,
layout_to_constellation_chan: IpcSender<LayoutMsg>,
Expand Down Expand Up @@ -491,7 +492,7 @@ impl UnprivilegedPipelineContent {
}, self.load_data.clone());

LTF::create(self.id,
Some(self.top_level_browsing_context_id),
self.top_level_browsing_context_id,
self.load_data.url,
self.parent_info.is_some(),
layout_pair,
Expand Down
18 changes: 12 additions & 6 deletions components/layout_thread/lib.rs
Expand Up @@ -74,7 +74,8 @@ use layout::webrender_helpers::WebRenderDisplayListConverter;
use layout::wrapper::LayoutNodeLayoutData;
use layout::wrapper::drop_style_and_layout_data;
use layout_traits::LayoutThreadFactory;
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use msg::constellation_msg::PipelineId;
use msg::constellation_msg::TopLevelBrowsingContextId;
use net_traits::image_cache::{ImageCache, UsePlaceholder};
use parking_lot::RwLock;
use profile_traits::mem::{self, Report, ReportKind, ReportsChan};
Expand Down Expand Up @@ -130,6 +131,9 @@ pub struct LayoutThread {
/// The ID of the pipeline that we belong to.
id: PipelineId,

/// The ID of the top-level browsing context that we belong to.
top_level_browsing_context_id: TopLevelBrowsingContextId,

/// The URL of the pipeline that we belong to.
url: ServoUrl,

Expand Down Expand Up @@ -244,7 +248,7 @@ impl LayoutThreadFactory for LayoutThread {

/// Spawns a new layout thread.
fn create(id: PipelineId,
top_level_browsing_context_id: Option<BrowsingContextId>,
top_level_browsing_context_id: TopLevelBrowsingContextId,
url: ServoUrl,
is_iframe: bool,
chan: (Sender<Msg>, Receiver<Msg>),
Expand All @@ -261,13 +265,13 @@ impl LayoutThreadFactory for LayoutThread {
thread::Builder::new().name(format!("LayoutThread {:?}", id)).spawn(move || {
thread_state::initialize(thread_state::LAYOUT);

if let Some(top_level_browsing_context_id) = top_level_browsing_context_id {
BrowsingContextId::install(top_level_browsing_context_id);
}
// In order to get accurate crash reports, we install the top-level bc id.
TopLevelBrowsingContextId::install(top_level_browsing_context_id);

{ // Ensures layout thread is destroyed before we send shutdown message
let sender = chan.0;
let layout = LayoutThread::new(id,
top_level_browsing_context_id,
url,
is_iframe,
chan.1,
Expand Down Expand Up @@ -417,6 +421,7 @@ fn add_font_face_rules(stylesheet: &Stylesheet,
impl LayoutThread {
/// Creates a new `LayoutThread` structure.
fn new(id: PipelineId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
url: ServoUrl,
is_iframe: bool,
port: Receiver<Msg>,
Expand Down Expand Up @@ -465,6 +470,7 @@ impl LayoutThread {

LayoutThread {
id: id,
top_level_browsing_context_id: top_level_browsing_context_id,
url: url,
is_iframe: is_iframe,
port: port,
Expand Down Expand Up @@ -732,7 +738,7 @@ impl LayoutThread {

fn create_layout_thread(&self, info: NewLayoutThreadInfo) {
LayoutThread::create(info.id,
BrowsingContextId::installed(),
self.top_level_browsing_context_id,
info.url.clone(),
info.is_parent,
info.layout_pair,
Expand Down
5 changes: 3 additions & 2 deletions components/layout_traits/lib.rs
Expand Up @@ -20,7 +20,8 @@ extern crate webrender_traits;

use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use msg::constellation_msg::PipelineId;
use msg::constellation_msg::TopLevelBrowsingContextId;
use net_traits::image_cache::ImageCache;
use profile_traits::{mem, time};
use script_traits::{ConstellationControlMsg, LayoutControlMsg};
Expand All @@ -34,7 +35,7 @@ use std::sync::mpsc::{Receiver, Sender};
pub trait LayoutThreadFactory {
type Message;
fn create(id: PipelineId,
top_level_browsing_context_id: Option<BrowsingContextId>,
top_level_browsing_context_id: TopLevelBrowsingContextId,
url: ServoUrl,
is_iframe: bool,
chan: (Sender<Self::Message>, Receiver<Self::Message>),
Expand Down
37 changes: 29 additions & 8 deletions components/msg/constellation_msg.rs
Expand Up @@ -258,8 +258,6 @@ impl fmt::Display for PipelineId {
}
}

thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell<Option<BrowsingContextId>> = Cell::new(None));

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
pub struct BrowsingContextIndex(pub u32);

Expand All @@ -278,22 +276,45 @@ impl BrowsingContextId {
new_browsing_context_id
})
}
}

impl fmt::Display for BrowsingContextId {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let PipelineNamespaceId(namespace_id) = self.namespace_id;
let BrowsingContextIndex(index) = self.index;
write!(fmt, "({},{})", namespace_id, index)
}
}

thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell<Option<TopLevelBrowsingContextId>> = Cell::new(None));

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
pub struct TopLevelBrowsingContextId(BrowsingContextId);

impl TopLevelBrowsingContextId {
pub fn new() -> TopLevelBrowsingContextId {
TopLevelBrowsingContextId(BrowsingContextId::new())
}
/// Each script and layout thread should have the top-level browsing context id installed,
/// since it is used by crash reporting.
pub fn install(id: BrowsingContextId) {
pub fn install(id: TopLevelBrowsingContextId) {
TOP_LEVEL_BROWSING_CONTEXT_ID.with(|tls| tls.set(Some(id)))
}

pub fn installed() -> Option<BrowsingContextId> {
pub fn installed() -> Option<TopLevelBrowsingContextId> {
TOP_LEVEL_BROWSING_CONTEXT_ID.with(|tls| tls.get())
}
}

impl fmt::Display for BrowsingContextId {
impl fmt::Display for TopLevelBrowsingContextId {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let PipelineNamespaceId(namespace_id) = self.namespace_id;
let BrowsingContextIndex(index) = self.index;
write!(fmt, "({},{})", namespace_id, index)
self.0.fmt(fmt)
}
}

impl From<TopLevelBrowsingContextId> for BrowsingContextId {
fn from(id: TopLevelBrowsingContextId) -> BrowsingContextId {
id.0
}
}

Expand Down
5 changes: 3 additions & 2 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -58,7 +58,7 @@ use js::glue::{CallObjectTracer, CallValueTracer};
use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
use js::jsval::JSVal;
use js::rust::Runtime;
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId};
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, TopLevelBrowsingContextId};
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceThreads};
use net_traits::filemanager_thread::RelativePos;
use net_traits::image::base::{Image, ImageMetadata};
Expand Down Expand Up @@ -336,7 +336,8 @@ unsafe_no_jsmanaged_fields!(TrustedPromise);
unsafe_no_jsmanaged_fields!(PropertyDeclarationBlock);
// These three are interdependent, if you plan to put jsmanaged data
// in one of these make sure it is propagated properly to containing structs
unsafe_no_jsmanaged_fields!(DocumentActivity, BrowsingContextId, FrameType, WindowSizeData, WindowSizeType, PipelineId);
unsafe_no_jsmanaged_fields!(DocumentActivity, WindowSizeData, WindowSizeType);
unsafe_no_jsmanaged_fields!(BrowsingContextId, FrameType, PipelineId, TopLevelBrowsingContextId);
unsafe_no_jsmanaged_fields!(TimerEventId, TimerSource);
unsafe_no_jsmanaged_fields!(TimelineMarkerType);
unsafe_no_jsmanaged_fields!(WorkerId);
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/dedicatedworkerglobalscope.rs
Expand Up @@ -27,7 +27,7 @@ use js::jsapi::{HandleValue, JS_SetInterruptCallback};
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsval::UndefinedValue;
use js::rust::Runtime;
use msg::constellation_msg::BrowsingContextId;
use msg::constellation_msg::TopLevelBrowsingContextId;
use net_traits::{IpcSend, load_whole_resource};
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, get_reports, new_rt_and_cx};
Expand Down Expand Up @@ -159,13 +159,13 @@ impl DedicatedWorkerGlobalScope {
closing: Arc<AtomicBool>) {
let serialized_worker_url = worker_url.to_string();
let name = format!("WebWorker for {}", serialized_worker_url);
let top_level_browsing_context_id = BrowsingContextId::installed();
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed();

thread::Builder::new().name(name).spawn(move || {
thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER);

if let Some(top_level_browsing_context_id) = top_level_browsing_context_id {
BrowsingContextId::install(top_level_browsing_context_id);
TopLevelBrowsingContextId::install(top_level_browsing_context_id);
}

let roots = RootCollection::new();
Expand Down
18 changes: 16 additions & 2 deletions components/script/dom/document.rs
Expand Up @@ -100,7 +100,7 @@ use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{JSContext, JSObject, JSRuntime};
use js::jsapi::JS_GetRuntime;
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState};
use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId};
use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy};
use net_traits::CookieSource::NonHTTP;
use net_traits::CoreResourceMsg::{GetCookiesForUrl, SetCookiesForUrl};
Expand Down Expand Up @@ -1899,7 +1899,21 @@ impl Document {
/// Find an iframe element in the document.
pub fn find_iframe(&self, browsing_context_id: BrowsingContextId) -> Option<Root<HTMLIFrameElement>> {
self.iter_iframes()
.find(|node| node.browsing_context_id() == browsing_context_id)
.find(|node| node.browsing_context_id() == Some(browsing_context_id))
}

/// Find a mozbrowser iframe element in the document.
pub fn find_mozbrowser_iframe(&self,
top_level_browsing_context_id: TopLevelBrowsingContextId)
-> Option<Root<HTMLIFrameElement>>
{
match self.find_iframe(BrowsingContextId::from(top_level_browsing_context_id)) {
None => None,
Some(iframe) => {
assert!(iframe.Mozbrowser());
Some(iframe)
},
}
}

pub fn get_dom_loading(&self) -> u64 {
Expand Down

0 comments on commit 4257736

Please sign in to comment.