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