Auto merge of #23368 - gterzian:clean_up_navigation, r=asajeffrey

Clean-up navigation

<!-- Please describe your changes on the following line: -->

1. Navigation as a result of following a hyperlink should be done in a task: https://html.spec.whatwg.org/multipage/links.html#following-hyperlinks:dom-manipulation-task-source
2. The javascript url navigation should also be done in a task: https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigating-across-documents:dom-manipulation-task-source
3. In `window.load_url`, it seems there is no need to send a message to the script-thread(the entirety of `load_url` should instead be done in a task when appropriate), so we can just do that last part "sync" by calling a method on the script, which will send a message to the constellation(for the parallel navigation steps), or queue task(for the JS navigation), as appropriate.
4. Separate the "normal" navigation flow from the handling of "navigate an iframe" message from constellation, since doing everything in one method as was previously done with `handle_navigate`, is confusing.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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/23368)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-07-18 14:22:03 -04:00 committed by GitHub
commit 2dfbbd0ca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 402 additions and 220 deletions

View file

@ -145,11 +145,11 @@ use script_traits::{
use script_traits::{
ConstellationControlMsg, ConstellationMsg as FromCompositorMsg, DiscardBrowsingContext,
};
use script_traits::{DocumentActivity, DocumentState, LayoutControlMsg, LoadData};
use script_traits::{DocumentActivity, DocumentState, LayoutControlMsg, LoadData, LoadOrigin};
use script_traits::{HistoryEntryReplacement, IFrameSizeMsg, WindowSizeData, WindowSizeType};
use script_traits::{
IFrameLoadInfo, IFrameLoadInfoWithData, IFrameSandboxState, TimerSchedulerMsg,
};
use script_traits::{IFrameSizeMsg, WindowSizeData, WindowSizeType};
use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, ScriptThreadFactory};
use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use serde::{Deserialize, Serialize};
@ -171,7 +171,7 @@ use style_traits::viewport::ViewportConstraints;
use style_traits::CSSPixel;
use webvr_traits::{WebVREvent, WebVRMsg};
type PendingApprovalNavigations = HashMap<PipelineId, (LoadData, bool)>;
type PendingApprovalNavigations = HashMap<PipelineId, (LoadData, HistoryEntryReplacement)>;
/// Servo supports tabs (referred to as browsers), so `Constellation` needs to
/// store browser specific data for bookkeeping.
@ -1332,7 +1332,7 @@ where
// If there is already a pending page (self.pending_changes), it will not be overridden;
// However, if the id is not encompassed by another change, it will be.
FromCompositorMsg::LoadUrl(top_level_browsing_context_id, url) => {
let load_data = LoadData::new(url, None, None, None);
let load_data = LoadData::new(LoadOrigin::Constellation, url, None, None, None);
let ctx_id = BrowsingContextId::from(top_level_browsing_context_id);
let pipeline_id = match self.browsing_contexts.get(&ctx_id) {
Some(ctx) => ctx.pipeline_id,
@ -1345,7 +1345,12 @@ where
};
// Since this is a top-level load, initiated by the embedder, go straight to load_url,
// bypassing schedule_navigation.
self.load_url(top_level_browsing_context_id, pipeline_id, load_data, false);
self.load_url(
top_level_browsing_context_id,
pipeline_id,
load_data,
HistoryEntryReplacement::Disabled,
);
},
FromCompositorMsg::IsReadyToSaveImage(pipeline_states) => {
let is_ready = self.handle_is_ready_to_save_image(pipeline_states);
@ -1911,7 +1916,7 @@ where
warn!("creating replacement pipeline for about:failure");
let new_pipeline_id = PipelineId::new();
let load_data = LoadData::new(failure_url, None, None, None);
let load_data = LoadData::new(LoadOrigin::Constellation, failure_url, None, None, None);
let sandbox = IFrameSandboxState::IFrameSandboxed;
let is_private = false;
self.new_pipeline(
@ -2030,7 +2035,7 @@ where
);
self.embedder_proxy.send(msg);
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
let load_data = LoadData::new(url, None, None, None);
let load_data = LoadData::new(LoadOrigin::Constellation, url, None, None, None);
let sandbox = IFrameSandboxState::IFrameUnsandboxed;
let is_private = false;
let is_visible = true;
@ -2191,7 +2196,9 @@ where
// see https://html.spec.whatwg.org/multipage/#the-iframe-element:completely-loaded
debug!("checking old pipeline? {:?}", load_info.old_pipeline_id);
if let Some(old_pipeline) = old_pipeline {
replace |= !old_pipeline.completely_loaded;
if !old_pipeline.completely_loaded {
replace = HistoryEntryReplacement::Enabled;
}
debug!(
"old pipeline is {}completely loaded",
if old_pipeline.completely_loaded {
@ -2202,16 +2209,6 @@ where
);
}
let load_data = load_info.load_data.unwrap_or_else(|| {
let url = match old_pipeline {
Some(old_pipeline) => old_pipeline.url.clone(),
None => ServoUrl::parse("about:blank").expect("infallible"),
};
// TODO - loaddata here should have referrer info (not None, None)
LoadData::new(url, Some(parent_pipeline_id), None, None)
});
let is_parent_private = {
let parent_browsing_context_id = match self.pipelines.get(&parent_pipeline_id) {
Some(pipeline) => pipeline.browsing_context_id,
@ -2245,10 +2242,11 @@ where
},
};
let replace = if replace {
Some(NeedsToReload::No(browsing_context.pipeline_id))
} else {
None
let replace = match replace {
HistoryEntryReplacement::Enabled => {
Some(NeedsToReload::No(browsing_context.pipeline_id))
},
HistoryEntryReplacement::Disabled => None,
};
// https://github.com/rust-lang/rust/issues/59159
@ -2263,7 +2261,7 @@ where
Some(parent_pipeline_id),
None,
browsing_context_size,
load_data,
load_info.load_data,
load_info.sandbox,
is_private,
browsing_context_is_visible,
@ -2280,7 +2278,7 @@ where
fn handle_script_new_iframe(
&mut self,
load_info: IFrameLoadInfo,
load_info: IFrameLoadInfoWithData,
layout_sender: IpcSender<LayoutControlMsg>,
) {
let IFrameLoadInfo {
@ -2290,12 +2288,7 @@ where
top_level_browsing_context_id,
is_private,
..
} = load_info;
let url = ServoUrl::parse("about:blank").expect("infallible");
// TODO: Referrer?
let load_data = LoadData::new(url.clone(), Some(parent_pipeline_id), None, None);
} = load_info.info;
let (script_sender, parent_browsing_context_id) =
match self.pipelines.get(&parent_pipeline_id) {
@ -2321,9 +2314,8 @@ where
script_sender,
layout_sender,
self.compositor_proxy.clone(),
url,
is_parent_visible,
load_data,
load_info.load_data,
);
assert!(!self.pipelines.contains_key(&new_pipeline_id));
@ -2348,17 +2340,13 @@ where
layout_sender: IpcSender<LayoutControlMsg>,
) {
let AuxiliaryBrowsingContextLoadInfo {
load_data,
opener_pipeline_id,
new_top_level_browsing_context_id,
new_browsing_context_id,
new_pipeline_id,
} = load_info;
let url = ServoUrl::parse("about:blank").expect("infallible");
// TODO: Referrer?
let load_data = LoadData::new(url.clone(), None, None, None);
let (script_sender, opener_browsing_context_id) =
match self.pipelines.get(&opener_pipeline_id) {
Some(pipeline) => (pipeline.event_loop.clone(), pipeline.browsing_context_id),
@ -2387,7 +2375,6 @@ where
script_sender,
layout_sender,
self.compositor_proxy.clone(),
url,
is_opener_visible,
load_data,
);
@ -2491,7 +2478,7 @@ where
top_level_browsing_context_id: TopLevelBrowsingContextId,
source_id: PipelineId,
load_data: LoadData,
replace: bool,
replace: HistoryEntryReplacement,
) {
match self.pending_approval_navigations.entry(source_id) {
Entry::Occupied(_) => {
@ -2517,13 +2504,15 @@ where
top_level_browsing_context_id: TopLevelBrowsingContextId,
source_id: PipelineId,
load_data: LoadData,
replace: bool,
replace: HistoryEntryReplacement,
) -> Option<PipelineId> {
let replace_debug = match replace {
HistoryEntryReplacement::Enabled => "",
HistoryEntryReplacement::Disabled => "not",
};
debug!(
"Loading {} in pipeline {}, {}replacing.",
load_data.url,
source_id,
if replace { "" } else { "not " }
load_data.url, source_id, replace_debug
);
// If this load targets an iframe, its framing element may exist
// in a separate script thread than the framed document that initiated
@ -2564,7 +2553,7 @@ where
Some(parent_pipeline_id) => {
// Find the script thread for the pipeline containing the iframe
// and issue an iframe load through there.
let msg = ConstellationControlMsg::Navigate(
let msg = ConstellationControlMsg::NavigateIframe(
parent_pipeline_id,
browsing_context_id,
load_data,
@ -2607,10 +2596,9 @@ where
// Create the new pipeline
let replace = if replace {
Some(NeedsToReload::No(pipeline_id))
} else {
None
let replace = match replace {
HistoryEntryReplacement::Enabled => Some(NeedsToReload::No(pipeline_id)),
HistoryEntryReplacement::Disabled => None,
};
let new_pipeline_id = PipelineId::new();
@ -2725,7 +2713,7 @@ where
&mut self,
pipeline_id: PipelineId,
new_url: ServoUrl,
replacement_enabled: bool,
replacement_enabled: HistoryEntryReplacement,
) {
let (top_level_browsing_context_id, old_url) = match self.pipelines.get_mut(&pipeline_id) {
Some(pipeline) => {
@ -2740,15 +2728,18 @@ where
},
};
if !replacement_enabled {
let diff = SessionHistoryDiff::HashDiff {
pipeline_reloader: NeedsToReload::No(pipeline_id),
new_url,
old_url,
};
self.get_joint_session_history(top_level_browsing_context_id)
.push_diff(diff);
self.notify_history_changed(top_level_browsing_context_id);
match replacement_enabled {
HistoryEntryReplacement::Disabled => {
let diff = SessionHistoryDiff::HashDiff {
pipeline_reloader: NeedsToReload::No(pipeline_id),
new_url,
old_url,
};
self.get_joint_session_history(top_level_browsing_context_id)
.push_diff(diff);
self.notify_history_changed(top_level_browsing_context_id);
},
HistoryEntryReplacement::Enabled => {},
}
}
@ -3390,7 +3381,12 @@ where
));
},
WebDriverCommandMsg::LoadUrl(top_level_browsing_context_id, load_data, reply) => {
self.load_url_for_webdriver(top_level_browsing_context_id, load_data, reply, false);
self.load_url_for_webdriver(
top_level_browsing_context_id,
load_data,
reply,
HistoryEntryReplacement::Disabled,
);
},
WebDriverCommandMsg::Refresh(top_level_browsing_context_id, reply) => {
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
@ -3407,7 +3403,12 @@ where
Some(pipeline) => pipeline.load_data.clone(),
None => return warn!("Pipeline {} refresh after closure.", pipeline_id),
};
self.load_url_for_webdriver(top_level_browsing_context_id, load_data, reply, true);
self.load_url_for_webdriver(
top_level_browsing_context_id,
load_data,
reply,
HistoryEntryReplacement::Enabled,
);
},
WebDriverCommandMsg::ScriptCommand(browsing_context_id, cmd) => {
let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) {
@ -3590,7 +3591,7 @@ where
top_level_browsing_context_id: TopLevelBrowsingContextId,
load_data: LoadData,
reply: IpcSender<webdriver_msg::LoadStatus>,
replace: bool,
replace: HistoryEntryReplacement,
) {
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) {