Commit cb9aed04 authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

cros: Add GetOobeWebContents to LoginDisplayHost

Right now GetWebContents is done by first fetching GetWebUILoginView, which is
not available in LoginDisplayHostMojo; however, LoginDisplayHostMojo does have
an associated WebContents instance when it is hosting oobe in a dialog, so
return that.

Bug: 851012
Change-Id: Icb1f296ce4513369ecae424c717f9991baa142c0
Reviewed-on: https://chromium-review.googlesource.com/1100384Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569310}
parent e4182b17
......@@ -142,7 +142,7 @@ IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, EnrollmentSpinner) {
ASSERT_TRUE(view);
test::JSChecker checker(
LoginDisplayHost::default_host()->GetWebUILoginView()->GetWebContents());
LoginDisplayHost::default_host()->GetOobeWebContents());
// Run through the flow
view->Show();
......
......@@ -228,8 +228,7 @@ void LoginManagerTest::InitializeWebContents() {
LoginDisplayHost* host = LoginDisplayHost::default_host();
EXPECT_TRUE(host != NULL);
content::WebContents* web_contents =
host->GetWebUILoginView()->GetWebContents();
content::WebContents* web_contents = host->GetOobeWebContents();
EXPECT_TRUE(web_contents != NULL);
set_web_contents(web_contents);
js_checker_.set_web_contents(web_contents);
......
......@@ -94,10 +94,6 @@ IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest,
// Flaky: https://crbug.com/481651 and https://crbug.com/772072
IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest,
DISABLED_ProxyAuthDialogOnUserBoardScreen) {
LoginDisplayHost* login_display_host = LoginDisplayHost::default_host();
WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
OobeUI* oobe_ui = web_ui_login_view->GetOobeUI();
{
OobeScreenWaiter screen_waiter(OobeScreen::SCREEN_ACCOUNT_PICKER);
ProxyAuthDialogWaiter auth_dialog_waiter;
......@@ -111,8 +107,9 @@ IN_PROC_BROWSER_TEST_F(ProxyAuthOnUserBoardScreenTest,
{
OobeScreenWaiter screen_waiter(OobeScreen::SCREEN_GAIA_SIGNIN);
ProxyAuthDialogWaiter auth_dialog_waiter;
ASSERT_TRUE(content::ExecuteScript(oobe_ui->web_ui()->GetWebContents(),
"$('add-user-button').click()"));
ASSERT_TRUE(content::ExecuteScript(
LoginDisplayHost::default_host()->GetOobeWebContents(),
"$('add-user-button').click()"));
screen_waiter.Wait();
auth_dialog_waiter.Wait();
ASSERT_TRUE(auth_dialog_waiter.login_handler());
......
......@@ -109,7 +109,7 @@ void ErrorScreen::AllowOfflineLogin(bool allowed) {
void ErrorScreen::FixCaptivePortal() {
if (!captive_portal_window_proxy_.get()) {
content::WebContents* web_contents =
LoginDisplayHost::default_host()->GetWebUILoginView()->GetWebContents();
LoginDisplayHost::default_host()->GetOobeWebContents();
captive_portal_window_proxy_.reset(new CaptivePortalWindowProxy(
network_state_informer_.get(), web_contents));
}
......
......@@ -115,7 +115,7 @@ void OobeBaseTest::SetUpOnMainThread() {
content::NotificationService::AllSources()));
js_checker_.set_web_contents(
LoginDisplayHost::default_host()->GetWebUILoginView()->GetWebContents());
LoginDisplayHost::default_host()->GetOobeWebContents());
test::UserSessionManagerTestApi session_manager_test_api(
UserSessionManager::GetInstance());
......
......@@ -78,7 +78,7 @@ class CaptivePortalWindowTest : public InProcessBrowserTest {
void SetUpOnMainThread() override {
content::WebContents* web_contents =
LoginDisplayHost::default_host()->GetWebUILoginView()->GetWebContents();
LoginDisplayHost::default_host()->GetOobeWebContents();
captive_portal_window_proxy_.reset(
new CaptivePortalWindowProxy(&delegate_, web_contents));
}
......
......@@ -41,6 +41,10 @@ OobeUI* FakeLoginDisplayHost::GetOobeUI() const {
return nullptr;
}
content::WebContents* FakeLoginDisplayHost::GetOobeWebContents() const {
return nullptr;
}
WebUILoginView* FakeLoginDisplayHost::GetWebUILoginView() const {
return nullptr;
}
......
......@@ -26,6 +26,7 @@ class FakeLoginDisplayHost : public LoginDisplayHost {
LoginDisplay* GetLoginDisplay() override;
gfx::NativeWindow GetNativeWindow() const override;
OobeUI* GetOobeUI() const override;
content::WebContents* GetOobeWebContents() const override;
WebUILoginView* GetWebUILoginView() const override;
void BeforeSessionStart() override;
void Finalize(base::OnceClosure) override;
......
......@@ -19,6 +19,10 @@
class AccountId;
namespace content {
class WebContents;
}
namespace chromeos {
class AppLaunchController;
......@@ -61,6 +65,9 @@ class LoginDisplayHost {
// Returns instance of the OOBE WebUI.
virtual OobeUI* GetOobeUI() const = 0;
// Return the WebContents instance of OOBE, if any.
virtual content::WebContents* GetOobeWebContents() const = 0;
// Returns the current login view.
virtual WebUILoginView* GetWebUILoginView() const = 0;
......
......@@ -117,6 +117,12 @@ OobeUI* LoginDisplayHostMojo::GetOobeUI() const {
return dialog_->GetOobeUI();
}
content::WebContents* LoginDisplayHostMojo::GetOobeWebContents() const {
if (!dialog_)
return nullptr;
return dialog_->GetWebContents();
}
WebUILoginView* LoginDisplayHostMojo::GetWebUILoginView() const {
NOTREACHED();
return nullptr;
......
......@@ -70,6 +70,7 @@ class LoginDisplayHostMojo : public LoginDisplayHostCommon,
LoginDisplay* GetLoginDisplay() override;
gfx::NativeWindow GetNativeWindow() const override;
OobeUI* GetOobeUI() const override;
content::WebContents* GetOobeWebContents() const override;
WebUILoginView* GetWebUILoginView() const override;
void OnFinalize() override;
void SetStatusAreaVisible(bool visible) override;
......
......@@ -774,6 +774,11 @@ OobeUI* LoginDisplayHostWebUI::GetOobeUI() const {
return login_view_->GetOobeUI();
}
content::WebContents* LoginDisplayHostWebUI::GetOobeWebContents() const {
if (!login_view_)
return nullptr;
return login_view_->GetWebContents();
}
////////////////////////////////////////////////////////////////////////////////
// LoginDisplayHostWebUI, content:NotificationObserver:
......
......@@ -57,6 +57,7 @@ class LoginDisplayHostWebUI : public LoginDisplayHostCommon,
LoginDisplay* GetLoginDisplay() override;
gfx::NativeWindow GetNativeWindow() const override;
OobeUI* GetOobeUI() const override;
content::WebContents* GetOobeWebContents() const override;
WebUILoginView* GetWebUILoginView() const override;
void OnFinalize() override;
void SetStatusAreaVisible(bool visible) override;
......
......@@ -22,6 +22,7 @@ class MockLoginDisplayHost : public LoginDisplayHost {
MOCK_METHOD0(GetLoginDisplay, LoginDisplay*());
MOCK_CONST_METHOD0(GetNativeWindow, gfx::NativeWindow(void));
MOCK_CONST_METHOD0(GetOobeUI, OobeUI*(void));
MOCK_CONST_METHOD0(GetOobeWebContents, content::WebContents*(void));
MOCK_CONST_METHOD0(GetWebUILoginView, WebUILoginView*(void));
MOCK_METHOD0(BeforeSessionStart, void(void));
......
......@@ -59,6 +59,10 @@ void OobeUIDialogDelegate::Init() {
dialog_view_->web_contents());
}
content::WebContents* OobeUIDialogDelegate::GetWebContents() {
return dialog_view_->web_contents();
}
void OobeUIDialogDelegate::Show(bool closable_by_esc) {
closable_by_esc_ = closable_by_esc;
dialog_widget_->Show();
......
......@@ -12,6 +12,10 @@
#include "base/strings/string16.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
namespace content {
class WebContents;
}
namespace ui {
class Accelerator;
}
......@@ -55,6 +59,8 @@ class OobeUIDialogDelegate : public ui::WebDialogDelegate {
// Initialize the dialog widget.
void Init();
content::WebContents* GetWebContents();
void SetSize(int width, int height);
OobeUI* GetOobeUI() const;
gfx::NativeWindow GetNativeWindow() const;
......
......@@ -65,7 +65,7 @@ class SimpleWebViewDialogTest : public LoginManagerTest {
IN_PROC_BROWSER_TEST_F(SimpleWebViewDialogTest, Interstitial) {
content::WebContents* web_contents =
LoginDisplayHost::default_host()->GetWebUILoginView()->GetWebContents();
LoginDisplayHost::default_host()->GetOobeWebContents();
StubDelegate delegate;
CaptivePortalWindowProxy proxy(&delegate, web_contents);
proxy.Show();
......
......@@ -352,11 +352,8 @@ class WizardControllerTest : public WizardInProcessBrowserTest {
content::WebContents* GetWebContents() {
LoginDisplayHost* host = LoginDisplayHost::default_host();
if (!host)
return NULL;
WebUILoginView* webui_login_view = host->GetWebUILoginView();
if (!webui_login_view)
return NULL;
return webui_login_view->GetWebContents();
return nullptr;
return host->GetOobeWebContents();
}
void WaitUntilJSIsReady() {
......
......@@ -474,12 +474,7 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
chromeos::LoginDisplayHost* host =
chromeos::LoginDisplayHost::default_host();
ASSERT_TRUE(host);
chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
ASSERT_TRUE(web_ui_login_view);
content::WebUI* web_ui = web_ui_login_view->GetWebUI();
ASSERT_TRUE(web_ui);
contents_ = web_ui->GetWebContents();
contents_ = host->GetOobeWebContents();
ASSERT_TRUE(contents_);
// Wait for the login UI to be ready.
......
......@@ -315,11 +315,7 @@ class ShutdownPolicyLoginTest : public ShutdownPolicyBaseTest {
content::NotificationService::AllSources()).Wait();
LoginDisplayHost* host = LoginDisplayHost::default_host();
ASSERT_TRUE(host);
WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
ASSERT_TRUE(web_ui_login_view);
content::WebUI* web_ui = web_ui_login_view->GetWebUI();
ASSERT_TRUE(web_ui);
contents_ = web_ui->GetWebContents();
contents_ = host->GetOobeWebContents();
ASSERT_TRUE(contents_);
// Wait for the login UI to be ready.
......
......@@ -184,9 +184,7 @@ IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableWithEphemeralUsers) {
// show the login screen. Simulate this.
const LoginDisplayHost* host = LoginDisplayHost::default_host();
ASSERT_TRUE(host);
WebUILoginView* webui_login_view = host->GetWebUILoginView();
ASSERT_TRUE(webui_login_view);
content::WebContents* web_contents = webui_login_view->GetWebContents();
content::WebContents* web_contents = host->GetOobeWebContents();
ASSERT_TRUE(web_contents);
ASSERT_TRUE(content::ExecuteScript(web_contents,
"Oobe.showAddUserForTesting();"));
......
......@@ -27,13 +27,8 @@ bool ChromeOSLoginMediaAccessHandler::SupportsStreamType(
const extensions::Extension* extension) {
if (!web_contents)
return false;
chromeos::LoginDisplayHost* login_display_host =
chromeos::LoginDisplayHost::default_host();
chromeos::WebUILoginView* webui_login_view =
login_display_host ? login_display_host->GetWebUILoginView() : nullptr;
content::WebContents* login_web_contents =
webui_login_view ? webui_login_view->GetWebContents() : nullptr;
return web_contents == login_web_contents;
chromeos::LoginDisplayHost* host = chromeos::LoginDisplayHost::default_host();
return host && web_contents == host->GetOobeWebContents();
}
bool ChromeOSLoginMediaAccessHandler::CheckMediaAccessPermission(
......
......@@ -103,15 +103,8 @@ scoped_refptr<SelectFileDialogExtension> PendingDialog::Find(
#if defined(OS_CHROMEOS)
// Return the Chrome OS WebUI login WebContents, if applicable.
content::WebContents* GetLoginWebContents() {
chromeos::LoginDisplayHost* const login_display_host =
chromeos::LoginDisplayHost::default_host();
if (!login_display_host)
return nullptr;
chromeos::WebUILoginView* const view =
login_display_host->GetWebUILoginView();
if (!view)
return nullptr;
return view->GetWebContents();
chromeos::LoginDisplayHost* host = chromeos::LoginDisplayHost::default_host();
return host ? host->GetOobeWebContents() : nullptr;
}
#endif
......
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