Commit 747c10c3 authored by ginkage's avatar ginkage Committed by Commit bot

Fix browser launch on the login screen.

For the login screen, if there is some web content displayed, and the user clicks a link that is specified to open in a new window, a new browser window indeed opens, which is highly undesirable at the login screen.
To avoid this, a new delegate method was introduced, which should decide if we want to allow displaying any additional contents.

BUG=443096
TEST=manual

Review URL: https://codereview.chromium.org/812763003

Cr-Commit-Position: refs/heads/master@{#314311}
parent da58b9ae
......@@ -10,6 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
......@@ -157,6 +158,23 @@ bool LoginWebDialog::HandleContextMenu(
return true;
}
bool LoginWebDialog::HandleOpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params,
content::WebContents** out_new_contents) {
// On a login screen, if a missing extension is trying to show in a web
// dialog, a NetErrorHelper is displayed instead (hence we have a |source|),
// but there is no browser window associated with it. A helper screen will
// fire an auto-reload, which in turn leads to opening a new browser window,
// so we must suppress it.
// http://crbug.com/443096
return (source && !chrome::FindBrowserWithWebContents(source));
}
bool LoginWebDialog::HandleShouldCreateWebContents() {
return false;
}
void LoginWebDialog::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......
......@@ -81,6 +81,10 @@ class LoginWebDialog : public ui::WebDialogDelegate,
bool* out_close_dialog) override;
bool ShouldShowDialogTitle() const override;
bool HandleContextMenu(const content::ContextMenuParams& params) override;
bool HandleOpenURLFromTab(content::WebContents* source,
const content::OpenURLParams& params,
content::WebContents** out_new_contents) override;
bool HandleShouldCreateWebContents() override;
// content::NotificationObserver implementation.
void Observe(int type,
......
......@@ -331,6 +331,20 @@ void WebDialogView::BeforeUnloadFired(content::WebContents* tab,
*proceed_to_fire_unload = proceed;
}
bool WebDialogView::ShouldCreateWebContents(
content::WebContents* web_contents,
int route_id,
int main_frame_route_id,
WindowContainerType window_container_type,
const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) {
if (delegate_)
return delegate_->HandleShouldCreateWebContents();
return true;
}
////////////////////////////////////////////////////////////////////////////////
// WebDialogView, private:
......
......@@ -111,6 +111,15 @@ class WEBVIEW_EXPORT WebDialogView : public views::ClientView,
void BeforeUnloadFired(content::WebContents* tab,
bool proceed,
bool* proceed_to_fire_unload) override;
bool ShouldCreateWebContents(
content::WebContents* web_contents,
int route_id,
int main_frame_route_id,
WindowContainerType window_container_type,
const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) override;
private:
FRIEND_TEST_ALL_PREFIXES(WebDialogBrowserTest, WebContentRendered);
......
......@@ -48,4 +48,8 @@ bool WebDialogDelegate::HandleAddNewContents(
return false;
}
bool WebDialogDelegate::HandleShouldCreateWebContents() {
return true;
}
} // namespace ui
......@@ -9,6 +9,7 @@
#include <vector>
#include "base/strings/string16.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/base/ui_base_types.h"
#include "ui/base/window_open_disposition.h"
#include "ui/web_dialogs/web_dialogs_export.h"
......@@ -128,6 +129,10 @@ class WEB_DIALOGS_EXPORT WebDialogDelegate {
const gfx::Rect& initial_pos,
bool user_gesture);
// A callback to control whether a WebContents will be created. Returns
// false to disallow the creation. Return true to use the default handler.
virtual bool HandleShouldCreateWebContents();
// Stores the dialog bounds.
virtual void StoreDialogSize(const gfx::Size& dialog_size) {}
......
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