Skip to content

Commit

Permalink
nw2: fix new-win-policy ctrl-click and frameless
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Nov 17, 2019
1 parent 9bb3c4b commit 5ac1df9
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
16 changes: 11 additions & 5 deletions chrome/browser/ui/browser_navigator.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Expand Down Expand Up @@ -101,10 +102,12 @@ bool WindowCanOpenTabs(Browser* browser) {

// Finds an existing Browser compatible with |profile|, making a new one if no
// such Browser is located.
Browser* GetOrCreateBrowser(Profile* profile, bool user_gesture, const gfx::Rect& bounds) {
Browser* GetOrCreateBrowser(Profile* profile, const NavigateParams& params) {
Browser* browser = chrome::FindTabbedBrowser(profile, false);
Browser::CreateParams browser_params(profile, params.user_gesture, params.window_bounds);
browser_params.frameless = params.frameless;
return browser ? browser
: new Browser(Browser::CreateParams(profile, user_gesture, bounds));
: new Browser(browser_params);
}

Browser* GetOrCreateBrowser(Profile* profile, bool user_gesture) {
Expand Down Expand Up @@ -211,7 +214,7 @@ std::pair<Browser*, int> GetBrowserAndTabForDisposition(

// Find a compatible window and re-execute this command in it. Otherwise
// re-run with NEW_WINDOW.
return {GetOrCreateBrowser(profile, params.user_gesture, params.window_bounds), -1};
return {GetOrCreateBrowser(profile, params), -1};
case WindowOpenDisposition::NEW_POPUP: {
// Make a new popup window.
// Coerce app-style if |source| represents an app.
Expand Down Expand Up @@ -243,10 +246,13 @@ std::pair<Browser*, int> GetBrowserAndTabForDisposition(
profile, params.user_gesture)),
-1};
}
case WindowOpenDisposition::NEW_WINDOW:
case WindowOpenDisposition::NEW_WINDOW: {
Browser::CreateParams browser_params(profile, params.user_gesture, params.window_bounds);
browser_params.frameless = params.frameless;
// Make a new normal browser window.
return {new Browser(Browser::CreateParams(profile, params.user_gesture)),
return {new Browser(browser_params),
-1};
}
case WindowOpenDisposition::OFF_THE_RECORD:
// Make or find an incognito window.
return {GetOrCreateBrowser(profile->GetOffTheRecordProfile(),
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/ui/browser_navigator_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ struct NavigateParams {
// Show and activate the browser window after navigating.
SHOW_WINDOW,
// Show the browser window after navigating but do not activate.
SHOW_WINDOW_INACTIVE
SHOW_WINDOW_INACTIVE,
SHOW_FULLSCREEN
};
// Default is NO_ACTION (don't show or activate the window).
// If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to
Expand All @@ -204,7 +205,7 @@ struct NavigateParams {

// If false then the navigation was not initiated by a user gesture.
bool user_gesture = true;

bool frameless = false;
// What to do with the path component of the URL for singleton navigations.
enum PathBehavior {
// Two URLs with differing paths are different.
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/browser_tabstrip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void AddWebContents(Browser* browser,
gfx::Rect rect = initial_rect;
int height = 0; int width = 0;
int x = 0; int y = 0;
bool has_frame = true;
if (!manifest.empty()) {
std::unique_ptr<base::Value> val = base::JSONReader().ReadToValueDeprecated(manifest);
if (val && val->is_dict()) {
Expand All @@ -77,13 +78,15 @@ void AddWebContents(Browser* browser,
rect.set_x(x);
if (mnfst->GetInteger("y", &y))
rect.set_y(y);
mnfst->GetBoolean("frame", &has_frame);
}
}
NavigateParams params(browser, std::move(new_contents));
params.source_contents = source_contents;
params.disposition = disposition;
params.window_bounds = rect;
params.window_action = NavigateParams::SHOW_WINDOW;
params.frameless = !has_frame;
// At this point, we're already beyond the popup blocker. Even if the popup
// was created without a user gesture, we have to set |user_gesture| to true,
// so it gets correctly focused.
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/bindings/core/v8/window_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class WindowProxy : public GarbageCollectedFinalized<WindowProxy> {
virtual bool IsLocal() const { return false; }

enum FrameReuseStatus { kFrameWillNotBeReused, kFrameWillBeReused };
bool ContextNotReady() const { return lifecycle_ == Lifecycle::kContextIsUninitialized;}

protected:
// Lifecycle represents the following four states.
Expand Down Expand Up @@ -265,7 +266,6 @@ class WindowProxy : public GarbageCollectedFinalized<WindowProxy> {

v8::Isolate* GetIsolate() const { return isolate_; }
Frame* GetFrame() const { return frame_.Get(); }

#if DCHECK_IS_ON()
void DidAttachGlobalObject() { is_global_object_attached_ = true; }
void DidDetachGlobalObject() { is_global_object_attached_ = false; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class WindowProxyManager : public GarbageCollected<WindowProxyManager> {
return window_proxy_;
}

bool ContextNotReady(DOMWrapperWorld& world) {
WindowProxy* window_proxy = WindowProxyMaybeUninitialized(world);
return window_proxy->ContextNotReady();
}

WindowProxy* GetWindowProxy(DOMWrapperWorld& world) {
WindowProxy* window_proxy = WindowProxyMaybeUninitialized(world);
window_proxy->InitializeIfNeeded();
Expand Down
4 changes: 4 additions & 0 deletions third_party/blink/renderer/core/frame/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ WindowProxy* Frame::GetWindowProxy(DOMWrapperWorld& world) {
return window_proxy_manager_->GetWindowProxy(world);
}

bool Frame::ContextNotReady(DOMWrapperWorld& world) const {
return window_proxy_manager_->ContextNotReady(world);
}

void Frame::DidChangeVisibilityState() {
HeapVector<Member<Frame>> child_frames;
for (Frame* child = Tree().FirstChild(); child;
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/frame/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class CORE_EXPORT Frame : public GarbageCollectedFinalized<Frame> {
return window_proxy_manager_;
}
WindowProxy* GetWindowProxy(DOMWrapperWorld&);
bool ContextNotReady(DOMWrapperWorld& world) const;

virtual void DidChangeVisibilityState();

Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/page/create_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Frame* CreateNewWindow(LocalFrame& opener_frame,
const AtomicString& frame_name, WebString* manifest) {
DCHECK(request.GetResourceRequest().RequestorOrigin() ||
opener_frame.GetDocument()->Url().IsEmpty());
DCHECK_EQ(kNavigationPolicyCurrentTab, request.GetNavigationPolicy());
//DCHECK_EQ(kNavigationPolicyCurrentTab, request.GetNavigationPolicy());

// Exempting window.open() from this check here is necessary to support a
// special policy that will be removed in Chrome 82.
Expand Down
7 changes: 6 additions & 1 deletion third_party/blink/renderer/core/page/frame_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ FrameTree::FindResult FrameTree::FindOrCreateFrameForNavigation(
// Named frame lookup should always be relative to a local frame.
DCHECK(IsA<LocalFrame>(this_frame_.Get()));
LocalFrame* current_frame = To<LocalFrame>(this_frame_.Get());
bool policy_changed = false;

NavigationPolicy policy = request.GetNavigationPolicy();
NavigationPolicy policy0 = policy;
if (name == "_blank")
policy = kNavigationPolicyNewWindow;

Expand All @@ -208,12 +210,15 @@ FrameTree::FindResult FrameTree::FindOrCreateFrameForNavigation(
current_frame->Client()->willHandleNavigationPolicy(request.GetResourceRequest(), &policy, &manifest);
if (policy == kNavigationPolicyIgnore)
return FindResult(nullptr, false);
request.SetNavigationPolicy(policy);
request.SetManifest(manifest);
if (!manifest.IsEmpty() || policy != policy0)
policy_changed = true;
}
// A GetNavigationPolicy() value other than kNavigationPolicyCurrentTab at
// this point indicates that a user event modified the navigation policy
// (e.g., a ctrl-click). Let the user's action override any target attribute.
if (request.GetNavigationPolicy() != kNavigationPolicyCurrentTab)
if (policy0 != kNavigationPolicyCurrentTab && !policy_changed)
return FindResult(current_frame, false);

bool new_window = false;
Expand Down

0 comments on commit 5ac1df9

Please sign in to comment.