Commit 830545a0 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Cleanup createNewWindow

* Use LocalDOMWindow rather than LocalFrame/Document for most things.
* Change probe::WindowOpen() to take a KURL rather than a url String,
  to avoid an unnecessary CompleteURL() call.
* Remove an obsolete TODO, which refers to a Frame being remote when
  at a point where it is known to be local.

Change-Id: I0860485758fa1ff12843bf965e03c9816e5f2390
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414277
Commit-Queue: Nate Chapin <japhet@chromium.org>
Auto-Submit: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808601}
parent 6a43db05
...@@ -1051,13 +1051,11 @@ void InspectorPageAgent::PageLayoutInvalidated(bool resized) { ...@@ -1051,13 +1051,11 @@ void InspectorPageAgent::PageLayoutInvalidated(bool resized) {
client_->PageLayoutInvalidated(resized); client_->PageLayoutInvalidated(resized);
} }
void InspectorPageAgent::WindowOpen(Document* document, void InspectorPageAgent::WindowOpen(const KURL& url,
const String& url,
const AtomicString& window_name, const AtomicString& window_name,
const WebWindowFeatures& window_features, const WebWindowFeatures& window_features,
bool user_gesture) { bool user_gesture) {
KURL completed_url = url.IsEmpty() ? BlankURL() : document->CompleteURL(url); GetFrontend()->windowOpen(url.IsEmpty() ? BlankURL() : url, window_name,
GetFrontend()->windowOpen(completed_url.GetString(), window_name,
GetEnabledWindowFeatures(window_features), GetEnabledWindowFeatures(window_features),
user_gesture); user_gesture);
GetFrontend()->flush(); GetFrontend()->flush();
......
...@@ -201,8 +201,7 @@ class CORE_EXPORT InspectorPageAgent final ...@@ -201,8 +201,7 @@ class CORE_EXPORT InspectorPageAgent final
void Did(const probe::UpdateLayout&); void Did(const probe::UpdateLayout&);
void Will(const probe::RecalculateStyle&); void Will(const probe::RecalculateStyle&);
void Did(const probe::RecalculateStyle&); void Did(const probe::RecalculateStyle&);
void WindowOpen(Document*, void WindowOpen(const KURL&,
const String&,
const AtomicString&, const AtomicString&,
const WebWindowFeatures&, const WebWindowFeatures&,
bool); bool);
......
...@@ -226,15 +226,16 @@ static void MaybeLogWindowOpen(LocalFrame& opener_frame) { ...@@ -226,15 +226,16 @@ static void MaybeLogWindowOpen(LocalFrame& opener_frame) {
Frame* CreateNewWindow(LocalFrame& opener_frame, Frame* CreateNewWindow(LocalFrame& opener_frame,
FrameLoadRequest& request, FrameLoadRequest& request,
const AtomicString& frame_name) { const AtomicString& frame_name) {
LocalDOMWindow& opener_window = *opener_frame.DomWindow();
DCHECK(request.GetResourceRequest().RequestorOrigin() || DCHECK(request.GetResourceRequest().RequestorOrigin() ||
opener_frame.GetDocument()->Url().IsEmpty()); opener_window.Url().IsEmpty());
DCHECK_EQ(kNavigationPolicyCurrentTab, request.GetNavigationPolicy()); DCHECK_EQ(kNavigationPolicyCurrentTab, request.GetNavigationPolicy());
// Exempting window.open() from this check here is necessary to support a // Exempting window.open() from this check here is necessary to support a
// special policy that will be removed in Chrome 88. // special policy that will be removed in Chrome 88.
// See https://crbug.com/937569 // See https://crbug.com/937569
if (!request.IsWindowOpen() && if (!request.IsWindowOpen() &&
opener_frame.GetDocument()->PageDismissalEventBeingDispatched() != opener_window.document()->PageDismissalEventBeingDispatched() !=
Document::kNoDismissal) { Document::kNoDismissal) {
return nullptr; return nullptr;
} }
...@@ -242,61 +243,57 @@ Frame* CreateNewWindow(LocalFrame& opener_frame, ...@@ -242,61 +243,57 @@ Frame* CreateNewWindow(LocalFrame& opener_frame,
request.SetFrameType(mojom::RequestContextFrameType::kAuxiliary); request.SetFrameType(mojom::RequestContextFrameType::kAuxiliary);
const KURL& url = request.GetResourceRequest().Url(); const KURL& url = request.GetResourceRequest().Url();
if (url.ProtocolIsJavaScript() && auto* csp_for_world = opener_window.GetContentSecurityPolicyForCurrentWorld();
opener_frame.DomWindow()->GetContentSecurityPolicyForCurrentWorld()) { if (url.ProtocolIsJavaScript() && csp_for_world) {
String script_source = DecodeURLEscapeSequences( String script_source = DecodeURLEscapeSequences(
url.GetString(), DecodeURLMode::kUTF8OrIsomorphic); url.GetString(), DecodeURLMode::kUTF8OrIsomorphic);
if (!opener_frame.DomWindow() if (!csp_for_world->AllowInline(
->GetContentSecurityPolicyForCurrentWorld() ContentSecurityPolicy::InlineType::kNavigation,
->AllowInline(ContentSecurityPolicy::InlineType::kNavigation, nullptr /* element */, script_source, String() /* nonce */,
nullptr /* element */, script_source, opener_window.Url(), OrdinalNumber())) {
String() /* nonce */,
opener_frame.DomWindow()->Url(), OrdinalNumber())) {
return nullptr; return nullptr;
} }
} }
if (!opener_frame.DomWindow()->GetSecurityOrigin()->CanDisplay(url)) { if (!opener_window.GetSecurityOrigin()->CanDisplay(url)) {
opener_frame.DomWindow()->AddConsoleMessage( opener_window.AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>(
MakeGarbageCollected<ConsoleMessage>( mojom::blink::ConsoleMessageSource::kSecurity,
mojom::ConsoleMessageSource::kSecurity, mojom::blink::ConsoleMessageLevel::kError,
mojom::ConsoleMessageLevel::kError, "Not allowed to load local resource: " + url.ElidedString()));
"Not allowed to load local resource: " + url.ElidedString()));
return nullptr; return nullptr;
} }
const WebWindowFeatures& features = request.GetWindowFeatures(); const WebWindowFeatures& features = request.GetWindowFeatures();
request.SetNavigationPolicy(NavigationPolicyForCreateWindow(features)); request.SetNavigationPolicy(NavigationPolicyForCreateWindow(features));
probe::WindowOpen(opener_frame.GetDocument(), url, frame_name, features, probe::WindowOpen(&opener_window, url, frame_name, features,
LocalFrame::HasTransientUserActivation(&opener_frame)); LocalFrame::HasTransientUserActivation(&opener_frame));
// Sandboxed frames cannot open new auxiliary browsing contexts. // Sandboxed frames cannot open new auxiliary browsing contexts.
if (opener_frame.DomWindow()->IsSandboxed( if (opener_window.IsSandboxed(
network::mojom::blink::WebSandboxFlags::kPopups)) { network::mojom::blink::WebSandboxFlags::kPopups)) {
// FIXME: This message should be moved off the console once a solution to // FIXME: This message should be moved off the console once a solution to
// https://bugs.webkit.org/show_bug.cgi?id=103274 exists. // https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
opener_frame.DomWindow()->AddConsoleMessage( opener_window.AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>(
MakeGarbageCollected<ConsoleMessage>( mojom::blink::ConsoleMessageSource::kSecurity,
mojom::ConsoleMessageSource::kSecurity, mojom::blink::ConsoleMessageLevel::kError,
mojom::ConsoleMessageLevel::kError, "Blocked opening '" + url.ElidedString() +
"Blocked opening '" + url.ElidedString() + "' in a new window because the request was made in a sandboxed "
"' in a new window because the request was made in a sandboxed " "frame whose 'allow-popups' permission is not set."));
"frame whose 'allow-popups' permission is not set."));
return nullptr; return nullptr;
} }
bool propagate_sandbox = opener_frame.DomWindow()->IsSandboxed( bool propagate_sandbox =
network::mojom::blink::WebSandboxFlags:: opener_window.IsSandboxed(network::mojom::blink::WebSandboxFlags::
kPropagatesToAuxiliaryBrowsingContexts); kPropagatesToAuxiliaryBrowsingContexts);
network::mojom::blink::WebSandboxFlags sandbox_flags = network::mojom::blink::WebSandboxFlags sandbox_flags =
propagate_sandbox ? opener_frame.DomWindow()->GetSandboxFlags() propagate_sandbox ? opener_window.GetSandboxFlags()
: network::mojom::blink::WebSandboxFlags::kNone; : network::mojom::blink::WebSandboxFlags::kNone;
bool not_sandboxed = opener_frame.DomWindow()->GetSandboxFlags() == bool not_sandboxed = opener_window.GetSandboxFlags() ==
network::mojom::blink::WebSandboxFlags::kNone; network::mojom::blink::WebSandboxFlags::kNone;
FeaturePolicyFeatureState opener_feature_state = FeaturePolicyFeatureState opener_feature_state =
(not_sandboxed || propagate_sandbox) ? opener_frame.GetSecurityContext() (not_sandboxed || propagate_sandbox) ? opener_window.GetSecurityContext()
->GetFeaturePolicy() .GetFeaturePolicy()
->GetFeatureState() ->GetFeatureState()
: FeaturePolicyFeatureState(); : FeaturePolicyFeatureState();
...@@ -316,16 +313,6 @@ Frame* CreateNewWindow(LocalFrame& opener_frame, ...@@ -316,16 +313,6 @@ Frame* CreateNewWindow(LocalFrame& opener_frame,
if (!page) if (!page)
return nullptr; return nullptr;
auto* new_local_frame = DynamicTo<LocalFrame>(page->MainFrame());
if (request.GetShouldSendReferrer() == kMaybeSendReferrer) {
// TODO(japhet): Does network::mojom::ReferrerPolicy need to be proagated
// for RemoteFrames?
if (new_local_frame) {
new_local_frame->DomWindow()->SetReferrerPolicy(
opener_frame.DomWindow()->GetReferrerPolicy());
}
}
if (page == old_page) { if (page == old_page) {
Frame* frame = &opener_frame.Tree().Top(); Frame* frame = &opener_frame.Tree().Top();
if (!opener_frame.CanNavigate(*frame)) if (!opener_frame.CanNavigate(*frame))
...@@ -338,6 +325,9 @@ Frame* CreateNewWindow(LocalFrame& opener_frame, ...@@ -338,6 +325,9 @@ Frame* CreateNewWindow(LocalFrame& opener_frame,
DCHECK(page->MainFrame()); DCHECK(page->MainFrame());
LocalFrame& frame = *To<LocalFrame>(page->MainFrame()); LocalFrame& frame = *To<LocalFrame>(page->MainFrame());
if (request.GetShouldSendReferrer() == kMaybeSendReferrer)
frame.DomWindow()->SetReferrerPolicy(opener_window.GetReferrerPolicy());
page->SetWindowFeatures(features); page->SetWindowFeatures(features);
frame.View()->SetCanHaveScrollbars(features.scrollbars_visible); frame.View()->SetCanHaveScrollbars(features.scrollbars_visible);
......
...@@ -142,7 +142,7 @@ interface CoreProbes { ...@@ -142,7 +142,7 @@ interface CoreProbes {
void PseudoElementDestroyed([Keep] PseudoElement*); void PseudoElementDestroyed([Keep] PseudoElement*);
void DidCreateAnimation(Document*, unsigned); void DidCreateAnimation(Document*, unsigned);
void AnimationPlayStateChanged(Document*, Animation*, Animation::AnimationPlayState old_play_state, Animation::AnimationPlayState new_play_state); void AnimationPlayStateChanged(Document*, Animation*, Animation::AnimationPlayState old_play_state, Animation::AnimationPlayState new_play_state);
void WindowOpen([Keep] Document*, const String& url, const AtomicString& window_name, const WebWindowFeatures& window_features, bool user_gestrue); void WindowOpen(ExecutionContext*, const KURL& url, const AtomicString& window_name, const WebWindowFeatures& window_features, bool user_gestrue);
void ConsoleMessageAdded(ExecutionContext*, ConsoleMessage*); void ConsoleMessageAdded(ExecutionContext*, ConsoleMessage*);
void InspectorIssueAdded(CoreProbeSink*, InspectorIssue*); void InspectorIssueAdded(CoreProbeSink*, InspectorIssue*);
void WillRunJavaScriptDialog(LocalFrame* frame); void WillRunJavaScriptDialog(LocalFrame* frame);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment