Skip to content

Commit d01a866

Browse files
author
bors-servo
authored
Auto merge of #13498 - asajeffrey:script-iframe-stores-frameid, r=glennw
IFrame elements now manage FrameIds rather than the constellation. <!-- Please describe your changes on the following line: --> This PR stores the FrameId as well as the PipelineId in an html iframe. The iframes are now responsible for creating frame ids, not the constellation. This is the first step in fixing #633, because it means we know the frame id of each script thread when it is created. It also means we can share the frame id, for example using it in the debugger. cc @jdm, @ConnorGBrewster and @ejpbruel. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes do not require tests because it's a refactoring. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13498) <!-- Reviewable:end -->
2 parents b1c5b91 + f53408d commit d01a866

File tree

7 files changed

+170
-178
lines changed

7 files changed

+170
-178
lines changed

components/constellation/constellation.rs

Lines changed: 100 additions & 138 deletions
Large diffs are not rendered by default.

components/msg/constellation_msg.rs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ pub enum TraversalDirection {
221221
Back(usize),
222222
}
223223

224-
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, PartialOrd, Ord)]
225-
pub struct FrameId(pub u32);
226-
227224
/// Each pipeline ID needs to be unique. However, it also needs to be possible to
228225
/// generate the pipeline ID from an iframe element (this simplifies a lot of other
229226
/// code that makes use of pipeline IDs).
@@ -242,7 +239,7 @@ pub struct FrameId(pub u32);
242239
#[derive(Clone, Copy)]
243240
pub struct PipelineNamespace {
244241
id: PipelineNamespaceId,
245-
next_index: PipelineIndex,
242+
index: u32,
246243
}
247244

248245
impl PipelineNamespace {
@@ -251,21 +248,29 @@ impl PipelineNamespace {
251248
assert!(tls.get().is_none());
252249
tls.set(Some(PipelineNamespace {
253250
id: namespace_id,
254-
next_index: PipelineIndex(0),
251+
index: 0,
255252
}));
256253
});
257254
}
258255

259-
fn next(&mut self) -> PipelineId {
260-
let pipeline_id = PipelineId {
261-
namespace_id: self.id,
262-
index: self.next_index,
263-
};
256+
fn next_index(&mut self) -> u32 {
257+
let result = self.index;
258+
self.index = result + 1;
259+
result
260+
}
264261

265-
let PipelineIndex(current_index) = self.next_index;
266-
self.next_index = PipelineIndex(current_index + 1);
262+
fn next_pipeline_id(&mut self) -> PipelineId {
263+
PipelineId {
264+
namespace_id: self.id,
265+
index: PipelineIndex(self.next_index()),
266+
}
267+
}
267268

268-
pipeline_id
269+
fn next_frame_id(&mut self) -> FrameId {
270+
FrameId {
271+
namespace_id: self.id,
272+
index: FrameIndex(self.next_index()),
273+
}
269274
}
270275
}
271276

@@ -289,24 +294,12 @@ impl PipelineId {
289294
pub fn new() -> PipelineId {
290295
PIPELINE_NAMESPACE.with(|tls| {
291296
let mut namespace = tls.get().expect("No namespace set for this thread!");
292-
let new_pipeline_id = namespace.next();
297+
let new_pipeline_id = namespace.next_pipeline_id();
293298
tls.set(Some(namespace));
294299
new_pipeline_id
295300
})
296301
}
297302

298-
// TODO(gw): This should be removed. It's only required because of the code
299-
// that uses it in the devtools lib.rs file (which itself is a TODO). Once
300-
// that is fixed, this should be removed. It also relies on the first
301-
// call to PipelineId::new() returning (0,0), which is checked with an
302-
// assert in handle_init_load().
303-
pub fn fake_root_pipeline_id() -> PipelineId {
304-
PipelineId {
305-
namespace_id: PipelineNamespaceId(0),
306-
index: PipelineIndex(0),
307-
}
308-
}
309-
310303
pub fn to_webrender(&self) -> webrender_traits::PipelineId {
311304
let PipelineNamespaceId(namespace_id) = self.namespace_id;
312305
let PipelineIndex(index) = self.index;
@@ -331,6 +324,41 @@ impl fmt::Display for PipelineId {
331324
}
332325
}
333326

327+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
328+
pub struct FrameIndex(pub u32);
329+
330+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
331+
pub struct FrameId {
332+
pub namespace_id: PipelineNamespaceId,
333+
pub index: FrameIndex
334+
}
335+
336+
impl FrameId {
337+
pub fn new() -> FrameId {
338+
PIPELINE_NAMESPACE.with(|tls| {
339+
let mut namespace = tls.get().expect("No namespace set for this thread!");
340+
let new_frame_id = namespace.next_frame_id();
341+
tls.set(Some(namespace));
342+
new_frame_id
343+
})
344+
}
345+
}
346+
347+
impl fmt::Display for FrameId {
348+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
349+
let PipelineNamespaceId(namespace_id) = self.namespace_id;
350+
let FrameIndex(index) = self.index;
351+
write!(fmt, "({},{})", namespace_id, index)
352+
}
353+
}
354+
355+
// We provide ids just for unit testing.
356+
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
357+
pub const TEST_PIPELINE_INDEX: PipelineIndex = PipelineIndex(5678);
358+
pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX };
359+
pub const TEST_FRAME_INDEX: FrameIndex = FrameIndex(8765);
360+
pub const TEST_FRAME_ID: FrameId = FrameId { namespace_id: TEST_NAMESPACE, index: TEST_FRAME_INDEX };
361+
334362
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
335363
pub enum FrameType {
336364
IFrame,

components/script/dom/bindings/trace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
5757
use js::jsval::JSVal;
5858
use js::rust::Runtime;
5959
use libc;
60-
use msg::constellation_msg::{FrameType, PipelineId, ReferrerPolicy, WindowSizeType};
60+
use msg::constellation_msg::{FrameId, FrameType, PipelineId, ReferrerPolicy, WindowSizeType};
6161
use net_traits::{Metadata, NetworkError, ResourceThreads};
6262
use net_traits::filemanager_thread::RelativePos;
6363
use net_traits::image::base::{Image, ImageMetadata};
@@ -308,7 +308,7 @@ no_jsmanaged_fields!(PropertyDeclarationBlock);
308308
no_jsmanaged_fields!(HashSet<T>);
309309
// These three are interdependent, if you plan to put jsmanaged data
310310
// in one of these make sure it is propagated properly to containing structs
311-
no_jsmanaged_fields!(FrameType, WindowSizeData, WindowSizeType, PipelineId);
311+
no_jsmanaged_fields!(FrameId, FrameType, WindowSizeData, WindowSizeType, PipelineId);
312312
no_jsmanaged_fields!(TimerEventId, TimerSource);
313313
no_jsmanaged_fields!(WorkerId);
314314
no_jsmanaged_fields!(QuirksMode);

components/script/dom/htmliframeelement.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use dom::window::{ReflowReason, Window};
3838
use ipc_channel::ipc;
3939
use js::jsapi::{JSAutoCompartment, JSContext, MutableHandleValue};
4040
use js::jsval::{NullValue, UndefinedValue};
41-
use msg::constellation_msg::{FrameType, LoadData, PipelineId, TraversalDirection};
41+
use msg::constellation_msg::{FrameType, FrameId, LoadData, PipelineId, TraversalDirection};
4242
use net_traits::response::HttpsState;
4343
use script_layout_interface::message::ReflowQueryType;
4444
use script_traits::{IFrameLoadInfo, MozBrowserEvent, ScriptMsg as ConstellationMsg};
@@ -67,6 +67,7 @@ bitflags! {
6767
#[dom_struct]
6868
pub struct HTMLIFrameElement {
6969
htmlelement: HTMLElement,
70+
frame_id: FrameId,
7071
pipeline_id: Cell<Option<PipelineId>>,
7172
sandbox: MutNullableHeap<JS<DOMTokenList>>,
7273
sandbox_allowance: Cell<Option<SandboxAllowance>>,
@@ -130,6 +131,7 @@ impl HTMLIFrameElement {
130131
let load_info = IFrameLoadInfo {
131132
load_data: load_data,
132133
parent_pipeline_id: global_scope.pipeline_id(),
134+
frame_id: self.frame_id,
133135
old_pipeline_id: old_pipeline_id,
134136
new_pipeline_id: new_pipeline_id,
135137
sandbox: sandboxed,
@@ -181,6 +183,7 @@ impl HTMLIFrameElement {
181183
document: &Document) -> HTMLIFrameElement {
182184
HTMLIFrameElement {
183185
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
186+
frame_id: FrameId::new(),
184187
pipeline_id: Cell::new(None),
185188
sandbox: Default::default(),
186189
sandbox_allowance: Cell::new(None),

components/script_traits/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ pub struct IFrameLoadInfo {
449449
pub load_data: Option<LoadData>,
450450
/// Pipeline ID of the parent of this iframe
451451
pub parent_pipeline_id: PipelineId,
452+
/// The ID for this iframe.
453+
pub frame_id: FrameId,
452454
/// The old pipeline ID for this iframe, if a page was previously loaded.
453455
pub old_pipeline_id: Option<PipelineId>,
454456
/// The new pipeline ID that the iframe has generated.

tests/unit/net/fetch.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hyper::server::{Handler, Listening, Server};
1919
use hyper::server::{Request as HyperRequest, Response as HyperResponse};
2020
use hyper::status::StatusCode;
2121
use hyper::uri::RequestUri;
22-
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
22+
use msg::constellation_msg::{ReferrerPolicy, TEST_PIPELINE_ID};
2323
use net::fetch::cors_cache::CORSCache;
2424
use net::fetch::methods::{FetchContext, fetch, fetch_with_cors_cache};
2525
use net::http_loader::HttpState;
@@ -776,8 +776,7 @@ fn test_fetch_with_devtools() {
776776
let (mut server, url) = make_server(handler);
777777

778778
let origin = Origin::Origin(url.origin());
779-
let pipeline_id = PipelineId::fake_root_pipeline_id();
780-
let request = Request::new(url.clone(), Some(origin), false, Some(pipeline_id));
779+
let request = Request::new(url.clone(), Some(origin), false, Some(TEST_PIPELINE_ID));
781780
*request.referrer.borrow_mut() = Referrer::NoReferrer;
782781

783782
let (devtools_chan, devtools_port) = channel::<DevtoolsControlMsg>();
@@ -815,7 +814,7 @@ fn test_fetch_with_devtools() {
815814
method: Method::Get,
816815
headers: headers,
817816
body: None,
818-
pipeline_id: pipeline_id,
817+
pipeline_id: TEST_PIPELINE_ID,
819818
startedDateTime: devhttprequest.startedDateTime,
820819
timeStamp: devhttprequest.timeStamp,
821820
connect_time: devhttprequest.connect_time,
@@ -832,7 +831,7 @@ fn test_fetch_with_devtools() {
832831
headers: Some(response_headers),
833832
status: Some((200, b"OK".to_vec())),
834833
body: None,
835-
pipeline_id: pipeline_id,
834+
pipeline_id: TEST_PIPELINE_ID,
836835
};
837836

838837
assert_eq!(devhttprequest, httprequest);

tests/unit/net/http_loader.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hyper::http::RawStatus;
1818
use hyper::method::Method;
1919
use hyper::mime::{Mime, SubLevel, TopLevel};
2020
use hyper::status::StatusCode;
21-
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
21+
use msg::constellation_msg::{PipelineId, ReferrerPolicy, TEST_PIPELINE_ID};
2222
use net::cookie::Cookie;
2323
use net::cookie_storage::CookieStorage;
2424
use net::hsts::HstsEntry;
@@ -47,7 +47,7 @@ impl LoadOrigin for HttpTest {
4747
None
4848
}
4949
fn pipeline_id(&self) -> Option<PipelineId> {
50-
Some(PipelineId::fake_root_pipeline_id())
50+
Some(TEST_PIPELINE_ID)
5151
}
5252
}
5353

@@ -472,8 +472,6 @@ fn test_request_and_response_data_with_network_messages() {
472472

473473
let url = Url::parse("https://mozilla.com").unwrap();
474474
let (devtools_chan, devtools_port) = mpsc::channel::<DevtoolsControlMsg>();
475-
// This will probably have to be changed as it uses fake_root_pipeline_id which is marked for removal.
476-
let pipeline_id = PipelineId::fake_root_pipeline_id();
477475
let mut load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
478476
let mut request_headers = Headers::new();
479477
request_headers.set(Host { hostname: "bar.foo".to_owned(), port: None });
@@ -521,7 +519,7 @@ fn test_request_and_response_data_with_network_messages() {
521519
method: Method::Get,
522520
headers: headers,
523521
body: None,
524-
pipeline_id: pipeline_id,
522+
pipeline_id: TEST_PIPELINE_ID,
525523
startedDateTime: devhttprequest.startedDateTime,
526524
timeStamp: devhttprequest.timeStamp,
527525
connect_time: devhttprequest.connect_time,
@@ -538,7 +536,7 @@ fn test_request_and_response_data_with_network_messages() {
538536
headers: Some(response_headers),
539537
status: Some((200, b"OK".to_vec())),
540538
body: None,
541-
pipeline_id: pipeline_id,
539+
pipeline_id: TEST_PIPELINE_ID,
542540
};
543541

544542
assert_eq!(devhttprequest, httprequest);

0 commit comments

Comments
 (0)