diff options
Diffstat (limited to 'chromium/chrome/browser/ui/webui/chromeos')
74 files changed, 1454 insertions, 649 deletions
diff --git a/chromium/chrome/browser/ui/webui/chromeos/account_manager_error_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/account_manager_error_ui.cc new file mode 100644 index 00000000000..ed686a24eec --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/account_manager_error_ui.cc @@ -0,0 +1,54 @@ +// Copyright 2019 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. + +#include "chrome/browser/ui/webui/chromeos/account_manager_error_ui.h" + +#include "base/bind.h" +#include "build/branding_buildflags.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/url_constants.h" +#include "chrome/common/webui_url_constants.h" +#include "chrome/grit/browser_resources.h" +#include "chrome/grit/generated_resources.h" +#include "content/public/browser/web_ui_data_source.h" +#include "ui/strings/grit/ui_strings.h" + +namespace chromeos { + +AccountManagerErrorUI::AccountManagerErrorUI(content::WebUI* web_ui) + : ui::WebDialogUI(web_ui), weak_factory_(this) { + content::WebUIDataSource* html_source = content::WebUIDataSource::Create( + chrome::kChromeUIAccountManagerErrorHost); + + web_ui->RegisterMessageCallback( + "closeDialog", base::BindRepeating(&WebDialogUI::CloseDialog, + weak_factory_.GetWeakPtr())); + + html_source->UseStringsJs(); + + html_source->AddLocalizedString( + "errorTitle", IDS_ACCOUNT_MANAGER_SECONDARY_ACCOUNTS_DISABLED_TITLE); + html_source->AddLocalizedString( + "errorMessage", IDS_ACCOUNT_MANAGER_SECONDARY_ACCOUNTS_DISABLED_TEXT); + html_source->AddLocalizedString("okButton", IDS_APP_OK); +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) + html_source->AddResourcePath("googleg.svg", + IDR_ACCOUNT_MANAGER_WELCOME_GOOGLE_LOGO_SVG); +#endif + + // Add required resources. + html_source->AddResourcePath("account_manager_shared.css", + IDR_ACCOUNT_MANAGER_SHARED_CSS); + html_source->AddResourcePath("account_manager_error.js", + IDR_ACCOUNT_MANAGER_ERROR_JS); + + html_source->SetDefaultResource(IDR_ACCOUNT_MANAGER_ERROR_HTML); + + Profile* profile = Profile::FromWebUI(web_ui); + content::WebUIDataSource::Add(profile, html_source); +} + +AccountManagerErrorUI::~AccountManagerErrorUI() = default; + +} // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/account_manager_error_ui.h b/chromium/chrome/browser/ui/webui/chromeos/account_manager_error_ui.h new file mode 100644 index 00000000000..60396df2316 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/account_manager_error_ui.h @@ -0,0 +1,27 @@ +// Copyright 2019 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. + +#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_ACCOUNT_MANAGER_ERROR_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_ACCOUNT_MANAGER_ERROR_UI_H_ + +#include "base/macros.h" +#include "base/memory/weak_ptr.h" +#include "ui/web_dialogs/web_dialog_ui.h" + +namespace chromeos { + +// For chrome:://account-manager-error +class AccountManagerErrorUI : public ui::WebDialogUI { + public: + explicit AccountManagerErrorUI(content::WebUI* web_ui); + ~AccountManagerErrorUI() override; + + private: + base::WeakPtrFactory<AccountManagerErrorUI> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(AccountManagerErrorUI); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_ACCOUNT_MANAGER_ERROR_UI_H_ diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.cc index e418a046414..626b2d4cc9a 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.cc @@ -11,12 +11,13 @@ #include "base/stl_util.h" #include "chrome/browser/apps/app_service/app_service_proxy.h" #include "chrome/browser/apps/app_service/app_service_proxy_factory.h" -#include "chrome/browser/chromeos/arc/arc_session_manager.h" +#include "chrome/browser/chromeos/arc/session/arc_session_manager.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/supervised_user/supervised_user_service.h" #include "chrome/browser/supervised_user/supervised_user_service_factory.h" #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" +#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision.mojom.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler_utils.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder.h" #include "chrome/services/app_service/public/cpp/app_registry_cache.h" @@ -26,17 +27,20 @@ #include "components/user_manager/user_manager.h" #include "content/public/browser/web_ui.h" #include "google_apis/gaia/gaia_constants.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/receiver.h" namespace chromeos { AddSupervisionHandler::AddSupervisionHandler( - add_supervision::mojom::AddSupervisionHandlerRequest request, + mojo::PendingReceiver<add_supervision::mojom::AddSupervisionHandler> + receiver, content::WebUI* web_ui, + signin::IdentityManager* identity_manager, Delegate* delegate) : web_ui_(web_ui), - identity_manager_( - IdentityManagerFactory::GetForProfile(Profile::FromWebUI(web_ui))), - binding_(this, std::move(request)), + identity_manager_(identity_manager), + receiver_(this, std::move(receiver)), delegate_(delegate) {} AddSupervisionHandler::~AddSupervisionHandler() = default; diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.h b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.h index 63db8d65ecd..8310d5bda98 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.h @@ -9,7 +9,8 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision.mojom.h" -#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/receiver.h" namespace content { class WebUI; @@ -39,8 +40,10 @@ class AddSupervisionHandler // |delegate| is owned by the caller and its lifetime must outlive |this|. AddSupervisionHandler( - add_supervision::mojom::AddSupervisionHandlerRequest request, + mojo::PendingReceiver<add_supervision::mojom::AddSupervisionHandler> + receiver, content::WebUI* web_ui, + signin::IdentityManager* identity_manager, Delegate* delegate); ~AddSupervisionHandler() override; @@ -63,7 +66,7 @@ class AddSupervisionHandler signin::IdentityManager* identity_manager_; std::unique_ptr<signin::AccessTokenFetcher> oauth2_access_token_fetcher_; - mojo::Binding<add_supervision::mojom::AddSupervisionHandler> binding_; + mojo::Receiver<add_supervision::mojom::AddSupervisionHandler> receiver_; Delegate* delegate_; diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder_browsertest.cc b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder_browsertest.cc index 3071dacac19..72e41559d58 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder_browsertest.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder_browsertest.cc @@ -14,6 +14,7 @@ #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h" #include "chrome/test/base/in_process_browser_test.h" #include "chromeos/constants/chromeos_features.h" +#include "components/signin/public/identity_manager/identity_test_environment.h" #include "content/public/test/test_web_ui.h" namespace chromeos { @@ -55,10 +56,12 @@ class AddSupervisionMetricsRecorderTest : public InProcessBrowserTest { } void NotifySupervisionEnabled() { + signin::IdentityTestEnvironment identity_test_env; add_supervision::mojom::AddSupervisionHandlerRequest request; AddSupervisionUI add_supervision_ui(&test_web_ui_); AddSupervisionHandler add_supervision_handler( - std::move(request), &test_web_ui_, &add_supervision_ui); + std::move(request), &test_web_ui_, identity_test_env.identity_manager(), + &add_supervision_ui); add_supervision_handler.NotifySupervisionEnabled(); } diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.cc index c0c3fb9b98f..6579db46102 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.cc @@ -12,7 +12,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/signin/identity_manager_factory.h" +#include "chrome/browser/supervised_user/supervised_user_service.h" +#include "chrome/browser/supervised_user/supervised_user_service_factory.h" #include "chrome/browser/ui/views/chrome_web_dialog_view.h" +#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision.mojom.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler_utils.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h" @@ -22,7 +25,7 @@ #include "components/google/core/common/google_util.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_data_source.h" -#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/base/resource/resource_bundle.h" #include "ui/resources/grit/ui_resources.h" #include "ui/web_dialogs/web_dialog_delegate.h" @@ -50,22 +53,6 @@ const char kAddSupervisionDefaultURL[] = const char kAddSupervisionFlowType[] = "1"; const char kAddSupervisionSwitch[] = "add-supervision-url"; -// Returns the URL of the Add Supervision flow from the command-line switch, -// or the default value if it's not defined. -GURL GetAddSupervisionURL() { - std::string url; - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(kAddSupervisionSwitch)) { - url = command_line->GetSwitchValueASCII(kAddSupervisionSwitch); - } else { - url = kAddSupervisionDefaultURL; - } - const GURL result(url); - DCHECK(result.is_valid()) << "Invalid URL \"" << url << "\" for switch \"" - << kAddSupervisionSwitch << "\""; - return result; -} - } // namespace // AddSupervisionDialog implementations. @@ -144,6 +131,9 @@ AddSupervisionDialog::~AddSupervisionDialog() = default; // AddSupervisionUI implementations. +// static +signin::IdentityManager* AddSupervisionUI::test_identity_manager_ = nullptr; + AddSupervisionUI::AddSupervisionUI(content::WebUI* web_ui) : ui::MojoWebUIController(web_ui) { // Register the Mojo API handler. @@ -151,17 +141,47 @@ AddSupervisionUI::AddSupervisionUI(content::WebUI* web_ui) &AddSupervisionUI::BindAddSupervisionHandler, base::Unretained(this))); // Set up the basic page framework. - SetupResources(); + SetUpResources(); +} + +AddSupervisionUI::~AddSupervisionUI() = default; + +bool AddSupervisionUI::CloseDialog() { + bool showing_confirm_dialog = MaybeShowConfirmSignoutDialog(); + if (!showing_confirm_dialog) { + // We aren't showing the confirm dialog, so close the AddSupervisionDialog. + AddSupervisionDialog::Close(); + } + return !showing_confirm_dialog; +} + +// static +void AddSupervisionUI::SetUpForTest(signin::IdentityManager* identity_manager) { + test_identity_manager_ = identity_manager; } -void AddSupervisionUI::SetupResources() { +void AddSupervisionUI::BindAddSupervisionHandler( + mojo::PendingReceiver<add_supervision::mojom::AddSupervisionHandler> + receiver) { + signin::IdentityManager* identity_manager = + test_identity_manager_ + ? test_identity_manager_ + : IdentityManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); + + mojo_api_handler_ = std::make_unique<AddSupervisionHandler>( + std::move(receiver), web_ui(), identity_manager, this); +} + +void AddSupervisionUI::SetUpResources() { Profile* profile = Profile::FromWebUI(web_ui()); std::unique_ptr<content::WebUIDataSource> source( content::WebUIDataSource::Create(chrome::kChromeUIAddSupervisionHost)); // Initialize supervision URL from the command-line arguments (if provided). supervision_url_ = GetAddSupervisionURL(); - DCHECK(supervision_url_.DomainIs("google.com")); + if (!allow_non_google_url_for_tests_) { + DCHECK(supervision_url_.DomainIs("google.com")); + } // Forward data to the WebUI. source->AddResourcePath("post_message_api.js", @@ -201,21 +221,24 @@ void AddSupervisionUI::SetupResources() { content::WebUIDataSource::Add(profile, source.release()); } -AddSupervisionUI::~AddSupervisionUI() = default; - -bool AddSupervisionUI::CloseDialog() { - bool showing_confirm_dialog = MaybeShowConfirmSignoutDialog(); - if (!showing_confirm_dialog) { - // We aren't showing the confirm dialog, so close the AddSupervisionDialog. - AddSupervisionDialog::Close(); +// Returns the URL of the Add Supervision flow from the command-line switch, +// or the default value if it's not defined. +GURL AddSupervisionUI::GetAddSupervisionURL() { + std::string url; + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(kAddSupervisionSwitch)) { + url = command_line->GetSwitchValueASCII(kAddSupervisionSwitch); + // The URL should only be set on the command line for testing purposes, + // which may include pointing to a non-google URL (i.e. http://localhost/). + // Therefore, we allow non-Google URLs in this instance. + allow_non_google_url_for_tests_ = true; + } else { + url = kAddSupervisionDefaultURL; } - return !showing_confirm_dialog; -} - -void AddSupervisionUI::BindAddSupervisionHandler( - add_supervision::mojom::AddSupervisionHandlerRequest request) { - mojo_api_handler_ = std::make_unique<AddSupervisionHandler>( - std::move(request), web_ui(), this); + const GURL result(url); + DCHECK(result.is_valid()) << "Invalid URL \"" << url << "\" for switch \"" + << kAddSupervisionSwitch << "\""; + return result; } } // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h index 02afc8e1d8e..a05b13f8b31 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h @@ -11,6 +11,7 @@ #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision.mojom.h" #include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/native_widget_types.h" #include "ui/views/controls/label.h" @@ -64,16 +65,23 @@ class AddSupervisionUI : public ui::MojoWebUIController, // AddSupervisionHandler::Delegate: bool CloseDialog() override; + static void SetUpForTest(signin::IdentityManager* identity_manager); + private: void BindAddSupervisionHandler( - add_supervision::mojom::AddSupervisionHandlerRequest request); - void SetupResources(); + mojo::PendingReceiver<add_supervision::mojom::AddSupervisionHandler> + receiver); + void SetUpResources(); + GURL GetAddSupervisionURL(); std::unique_ptr<add_supervision::mojom::AddSupervisionHandler> mojo_api_handler_; GURL supervision_url_; + static signin::IdentityManager* test_identity_manager_; + bool allow_non_google_url_for_tests_ = false; + DISALLOW_COPY_AND_ASSIGN(AddSupervisionUI); }; diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui_browsertest.cc b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui_browsertest.cc new file mode 100644 index 00000000000..f0995d1b6d7 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui_browsertest.cc @@ -0,0 +1,242 @@ +// Copyright 2019 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. + +#include <string> + +#include "base/macros.h" +#include "base/test/metrics/histogram_tester.h" +#include "base/test/metrics/user_action_tester.h" +#include "base/test/scoped_feature_list.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_metrics_recorder.h" +#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_ui.h" +#include "chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h" +#include "chrome/common/webui_url_constants.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "chromeos/constants/chromeos_features.h" +#include "components/signin/public/identity_manager/identity_test_environment.h" +#include "content/public/browser/web_contents.h" +#include "content/public/test/browser_test_utils.h" +#include "content/public/test/network_connection_change_simulator.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +// NOTE: This test is flaky and therefore disabled under MSAN: +// https://crbug.com/1002560 +#if !defined(MEMORY_SANITIZER) + +namespace { + +const char kGetAddSupervisionUIElementJS[] = + "document.querySelector('add-supervision-ui')"; +} + +// Base class for AddSupervision tests. +class AddSupervisionBrowserTest : public InProcessBrowserTest { + public: + AddSupervisionBrowserTest() { + scoped_feature_list_.InitWithFeatures( + {chromeos::features::kParentalControlsSettings}, {}); + } + ~AddSupervisionBrowserTest() override = default; + + void SetUpOnMainThread() override { + // TODO(danan): See if this is possible to do this instead using + // FakeGaia.IssueOAuthToken(). + identity_test_env_ = std::make_unique<signin::IdentityTestEnvironment>(); + identity_test_env_->MakePrimaryAccountAvailable("example@gmail.com"); + // This makes the identity manager return the string "access_token" for the + // access token. + identity_test_env_->SetAutomaticIssueOfAccessTokens(true); + AddSupervisionUI::SetUpForTest(identity_test_env_->identity_manager()); + + // Set start_time_ so that the DCHECK(!start_time_.is_null()) in + // AddSupervisionMetricsRecorder::RecordUserTime() doesn't throw. + AddSupervisionMetricsRecorder::GetInstance() + ->RecordAddSupervisionEnrollment( + AddSupervisionMetricsRecorder::EnrollmentState::kInitiated); + } + + chromeos::AddSupervisionUI* GetAddSupervisionUI() { + return static_cast<chromeos::AddSupervisionUI*>( + contents()->GetWebUI()->GetController()); + } + + content::WebContents* contents() { + return browser()->tab_strip_model()->GetActiveWebContents(); + } + + GURL settings_webui_url() { return GURL(chrome::kChromeUISettingsURL); } + + GURL add_supervision_webui_url() { + return GURL(chrome::kChromeUIAddSupervisionURL); + } + + bool IsElementVisible(const std::string& element_selector) { + bool found; + bool hidden; + std::string script = std::string("domAutomationController.send(") + + element_selector + ".hidden);"; + LOG(ERROR) << "Script: " << script; + found = content::ExecuteScriptAndExtractBool(contents(), script, &hidden); + return found && !hidden; + } + + private: + base::test::ScopedFeatureList scoped_feature_list_; + std::unique_ptr<signin::IdentityTestEnvironment> identity_test_env_; + + DISALLOW_COPY_AND_ASSIGN(AddSupervisionBrowserTest); +}; + +// Disabled on ASan and LSAn builds, because it's very flaky. See +// crbug.com/1004237 +#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) +#define MAYBE_URLParameters DISABLED_URLParameters +#else +#define MAYBE_URLParameters URLParameters +#endif +IN_PROC_BROWSER_TEST_F(AddSupervisionBrowserTest, MAYBE_URLParameters) { + // Open the Add Supervision URL. + ui_test_utils::NavigateToURL(browser(), add_supervision_webui_url()); + content::WaitForLoadStop(contents()); + + // Get the URL from the embedded webview. + std::string webview_url; + ASSERT_TRUE(content::ExecuteScriptAndExtractString( + contents(), + std::string("domAutomationController.send(") + + std::string(kGetAddSupervisionUIElementJS) + + ".shadowRoot.querySelector('#webview').getAttribute('src')" + + std::string(");"), + &webview_url)); + + GURL webview_gurl(webview_url); + ASSERT_TRUE(webview_gurl.has_query()); + + // Split the query string into a map of keys to values. + std::string query_str = webview_gurl.query(); + url::Component query(0, query_str.length()); + url::Component key; + url::Component value; + std::map<std::string, std::string> query_parts; + while (url::ExtractQueryKeyValue(query_str.c_str(), &query, &key, &value)) { + query_parts[query_str.substr(key.begin, key.len)] = + query_str.substr(value.begin, value.len); + } + + // Validate the query parameters. + ASSERT_EQ(query_parts.at("flow_type"), "1"); + ASSERT_EQ(query_parts.at("platform_version"), + base::SysInfo::OperatingSystemVersion()); + ASSERT_EQ(query_parts.at("access_token"), "access_token"); + ASSERT_EQ(query_parts.at("hl"), "en-US"); +} + +IN_PROC_BROWSER_TEST_F(AddSupervisionBrowserTest, ShowOfflineScreen) { + // Open the Add Supervision URL. + ui_test_utils::NavigateToURL(browser(), add_supervision_webui_url()); + content::WaitForLoadStop(contents()); + + // Webview div should be initially visible. + ASSERT_TRUE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) + + std::string(".webviewDiv"))); + + // Simulate going offline. + ASSERT_TRUE(content::ExecuteScript( + contents(), "window.dispatchEvent(new CustomEvent('offline'));")); + + // Ensure the offline content view is shown. + ASSERT_TRUE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) + + std::string(".offlineContentDiv"))); + + // Ensure the online webview content content is hidden. + ASSERT_FALSE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) + + std::string(".webviewDiv"))); + + // Simulate going online. + ASSERT_TRUE(content::ExecuteScript( + contents(), "window.dispatchEvent(new CustomEvent('online'));")); + + // Offline div should be hidden. + ASSERT_FALSE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) + + std::string(".offlineContentDiv"))); + + // Webview div should be shown. + ASSERT_TRUE(IsElementVisible(std::string(kGetAddSupervisionUIElementJS) + + std::string(".webviewDiv"))); +} + +// Disabled on ASan and LSAn builds, because it's very flaky. See +// crbug.com/1004237 +#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) +#define MAYBE_ShowConfirmSignoutDialog DISABLED_ShowConfirmSignoutDialog +#else +#define MAYBE_ShowConfirmSignoutDialog ShowConfirmSignoutDialog +#endif +IN_PROC_BROWSER_TEST_F(AddSupervisionBrowserTest, + MAYBE_ShowConfirmSignoutDialog) { + // Open the Add Supervision URL. + ui_test_utils::NavigateToURL(browser(), add_supervision_webui_url()); + content::WaitForLoadStop(contents()); + + // Request that the dialog close before supervision has been enabled. + ASSERT_TRUE(content::ExecuteScript( + contents(), std::string(kGetAddSupervisionUIElementJS) + + std::string(".server.requestClose()"))); + // Confirm that the signout dialog isn't showing + ASSERT_FALSE(ConfirmSignoutDialog::IsShowing()); + + // Simulate supervision being enabled. + ASSERT_TRUE(content::ExecuteScript( + contents(), std::string(kGetAddSupervisionUIElementJS) + + std::string(".server.notifySupervisionEnabled()"))); + + // Request that the dialog is closed again. + ASSERT_TRUE(content::ExecuteScript( + contents(), std::string(kGetAddSupervisionUIElementJS) + + std::string(".server.requestClose()"))); + + // Confirm that the dialog is showing. + ASSERT_TRUE(ConfirmSignoutDialog::IsShowing()); +} + +IN_PROC_BROWSER_TEST_F(AddSupervisionBrowserTest, UMATest) { + base::HistogramTester histogram_tester; + base::UserActionTester user_action_tester; + + // Should see 0 Add Supervision enrollment metrics at first. + histogram_tester.ExpectTotalCount("AddSupervisionDialog.Enrollment", 0); + + // Should see 0 user actions at first. + EXPECT_EQ(user_action_tester.GetActionCount( + "AddSupervisionDialog_AttemptedSignoutAfterEnrollment"), + 0); + + // Open the Add Supervision URL. + ui_test_utils::NavigateToURL(browser(), add_supervision_webui_url()); + content::WaitForLoadStop(contents()); + + // Simulate supervision being enabled. + ASSERT_TRUE(content::ExecuteScript( + contents(), std::string(kGetAddSupervisionUIElementJS) + + std::string(".server.notifySupervisionEnabled()"))); + + // Should see 1 Add Supervision process completed. + histogram_tester.ExpectUniqueSample( + "AddSupervisionDialog.Enrollment", + AddSupervisionMetricsRecorder::EnrollmentState::kCompleted, 1); + histogram_tester.ExpectTotalCount("AddSupervisionDialog.Enrollment", 1); + + // Should see 1 EnrollmentCompleted action. + EXPECT_EQ(user_action_tester.GetActionCount( + "AddSupervisionDialog_EnrollmentCompleted"), + 1); +} + +#endif // !defined(MEMORY_SANITIZER) + +} // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.cc b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.cc index b0754f4a57b..f9594134ec5 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.cc @@ -29,6 +29,14 @@ const int kDialogBodyTextWidth = 250; } // namespace ConfirmSignoutDialog::ConfirmSignoutDialog() { + DialogDelegate::set_button_label( + ui::DIALOG_BUTTON_OK, + l10n_util::GetStringUTF16( + IDS_ADD_SUPERVISION_EXIT_DIALOG_SIGNOUT_BUTTON_LABEL)); + DialogDelegate::set_button_label( + ui::DIALOG_BUTTON_CANCEL, + l10n_util::GetStringUTF16( + IDS_ADD_SUPERVISION_EXIT_DIALOG_CANCEL_BUTTON_LABEL)); SetLayoutManager(std::make_unique<views::FillLayout>()); SetBorder(views::CreateEmptyBorder( views::LayoutProvider::Get()->GetDialogInsetsForContentType( @@ -44,7 +52,9 @@ ConfirmSignoutDialog::ConfirmSignoutDialog() { AddChildView(body); } -ConfirmSignoutDialog::~ConfirmSignoutDialog() = default; +ConfirmSignoutDialog::~ConfirmSignoutDialog() { + ConfirmSignoutDialog::current_instance_ = nullptr; +} ui::ModalType ConfirmSignoutDialog::GetModalType() const { return ui::ModalType::MODAL_TYPE_SYSTEM; @@ -64,23 +74,22 @@ int ConfirmSignoutDialog::GetDialogButtons() const { ui::DialogButton::DIALOG_BUTTON_CANCEL; } -base::string16 ConfirmSignoutDialog::GetDialogButtonLabel( - ui::DialogButton button) const { - if (button == ui::DialogButton::DIALOG_BUTTON_OK) { - return l10n_util::GetStringUTF16( - IDS_ADD_SUPERVISION_EXIT_DIALOG_SIGNOUT_BUTTON_LABEL); - } - return l10n_util::GetStringUTF16( - IDS_ADD_SUPERVISION_EXIT_DIALOG_CANCEL_BUTTON_LABEL); -} +// static +views::Widget* ConfirmSignoutDialog::current_instance_ = nullptr; // static void ConfirmSignoutDialog::Show() { // Ownership of the ConfirmSignoutDialog is passed to the views system. // Dialog is system-modal, so no parent window is needed. - constrained_window::CreateBrowserModalDialogViews(new ConfirmSignoutDialog(), - nullptr /* parent window */) - ->Show(); + ConfirmSignoutDialog::current_instance_ = + constrained_window::CreateBrowserModalDialogViews( + new ConfirmSignoutDialog(), nullptr /* parent window */); + current_instance_->Show(); +} + +// static +bool ConfirmSignoutDialog::IsShowing() { + return ConfirmSignoutDialog::current_instance_ != nullptr; } } // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h index 6e7bff69d73..c8d7a820a6b 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h +++ b/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h @@ -9,6 +9,10 @@ #include "ui/base/ui_base_types.h" #include "ui/views/window/dialog_delegate.h" +namespace views { +class Widget; +} + namespace chromeos { // Dialog shown when the user tries to close the flow when account has already @@ -25,12 +29,13 @@ class ConfirmSignoutDialog : public views::DialogDelegateView { // views::DialogDelegate: bool Accept() override; int GetDialogButtons() const override; - base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; static void Show(); + static bool IsShowing(); private: ConfirmSignoutDialog(); + static views::Widget* current_instance_; DISALLOW_COPY_AND_ASSIGN(ConfirmSignoutDialog); }; diff --git a/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.cc index 3c918789930..56515216033 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.cc @@ -404,9 +404,16 @@ void ArcGraphicsTracingHandler::StartTracing() { base::trace_event::TraceConfig config( "-*,exo,viz,toplevel,gpu,cc,blink,disabled-by-default-android " - "gfx,disabled-by-default-android hal,disabled-by-default-android view", + "gfx,disabled-by-default-android view", base::trace_event::RECORD_CONTINUOUSLY); config.EnableSystrace(); + // By default, systracing starts pre-defined set of categories with predefined + // set of events in each category. Limit events to what we actually analyze in + // ArcTracingModel. + config.EnableSystraceEvent("i915:intel_gpu_freq_change"); + config.EnableSystraceEvent("power:cpu_idle"); + config.EnableSystraceEvent("sched:sched_wakeup"); + config.EnableSystraceEvent("sched:sched_switch"); tracing_active_ = true; if (jank_detector_) jank_detector_->Reset(); @@ -434,8 +441,8 @@ void ArcGraphicsTracingHandler::StopTracing() { return; controller->StopTracing(content::TracingController::CreateStringEndpoint( - base::BindRepeating(&ArcGraphicsTracingHandler::OnTracingStopped, - weak_ptr_factory_.GetWeakPtr()))); + base::BindOnce(&ArcGraphicsTracingHandler::OnTracingStopped, + weak_ptr_factory_.GetWeakPtr()))); } void ArcGraphicsTracingHandler::SetStatus(const std::string& status) { @@ -452,10 +459,9 @@ void ArcGraphicsTracingHandler::OnTracingStarted() { } void ArcGraphicsTracingHandler::OnTracingStopped( - std::unique_ptr<const base::DictionaryValue> metadata, - base::RefCountedString* trace_data) { + std::unique_ptr<std::string> trace_data) { std::string string_data; - string_data.swap(trace_data->data()); + string_data.swap(*trace_data); base::PostTaskAndReplyWithResult( FROM_HERE, {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT}, diff --git a/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.h b/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.h index bd774e39149..63849de5602 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/arc_graphics_tracing/arc_graphics_tracing_handler.h @@ -24,7 +24,6 @@ class ArcSystemStatCollector; namespace base { class ListValue; -class RefCountedString; } // namespace base namespace exo { @@ -71,8 +70,7 @@ class ArcGraphicsTracingHandler : public content::WebUIMessageHandler, void SetStatus(const std::string& status); void OnTracingStarted(); - void OnTracingStopped(std::unique_ptr<const base::DictionaryValue> metadata, - base::RefCountedString* trace_data); + void OnTracingStopped(std::unique_ptr<std::string> trace_data); // Called when graphics model is built or load. Extra string parameter // contains a status. In case model cannot be built/load empty |base::Value| diff --git a/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_ui.cc index 03a052c6863..72e6a511441 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_ui.cc @@ -8,10 +8,11 @@ #include <string> #include <utility> -#include "ash/public/mojom/voice_interaction_controller.mojom.h" #include "base/bind.h" #include "base/macros.h" #include "base/strings/string_number_conversions.h" +#include "build/buildflag.h" +#include "chrome/browser/chromeos/assistant/assistant_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/ash/ash_util.h" @@ -19,7 +20,9 @@ #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" #include "chrome/common/url_constants.h" #include "chrome/grit/browser_resources.h" +#include "chromeos/assistant/buildflags.h" #include "chromeos/services/assistant/public/cpp/assistant_prefs.h" +#include "chromeos/services/assistant/public/features.h" #include "components/prefs/pref_service.h" #include "components/session_manager/core/session_manager.h" #include "content/public/browser/host_zoom_map.h" @@ -80,7 +83,6 @@ AssistantOptInUI::AssistantOptInUI(content::WebUI* web_ui) source->UseStringsJs(); source->AddResourcePath("assistant_optin.js", IDR_ASSISTANT_OPTIN_JS); source->AddResourcePath("assistant_logo.png", IDR_ASSISTANT_LOGO_PNG); - source->AddBoolean("hotwordDspAvailable", chromeos::IsHotwordDspAvailable()); source->SetDefaultResource(IDR_ASSISTANT_OPTIN_HTML); source->AddResourcePath("voice_match_animation.json", IDR_ASSISTANT_VOICE_MATCH_ANIMATION); @@ -123,10 +125,24 @@ void AssistantOptInUI::Initialize() { void AssistantOptInDialog::Show( ash::FlowType type, ash::AssistantSetup::StartAssistantOptInFlowCallback callback) { +#if !BUILDFLAG(ENABLE_CROS_LIBASSISTANT) + std::move(callback).Run(false); + return; +#endif + + // Check Assistant allowed state. + if (::assistant::IsAssistantAllowedForProfile( + ProfileManager::GetActiveUserProfile()) != + ash::mojom::AssistantAllowedState::ALLOWED) { + std::move(callback).Run(false); + return; + } + // Check session state here to prevent timing issue -- session state might // have changed during the mojom calls to launch the opt-in dalog. if (session_manager::SessionManager::Get()->session_state() != session_manager::SessionState::ACTIVE) { + std::move(callback).Run(false); return; } if (g_dialog) { diff --git a/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.cc b/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.cc index 96f8106a00d..802664295d6 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.cc @@ -111,7 +111,7 @@ base::Value CreateZippyData(const SettingZippyList& zippy_list) { data.SetKey("iconUri", base::Value(setting_zippy.icon_uri())); data.SetKey("popupLink", base::Value(l10n_util::GetStringUTF16( IDS_ASSISTANT_ACTIVITY_CONTROL_POPUP_LINK))); - zippy_data.GetList().push_back(std::move(data)); + zippy_data.Append(std::move(data)); } return zippy_data; } @@ -131,7 +131,7 @@ base::Value CreateDisclosureData(const SettingZippyList& disclosure_list) { base::Value(disclosure.additional_info_paragraph(0))); } data.SetKey("iconUri", base::Value(disclosure.icon_uri())); - disclosure_data.GetList().push_back(std::move(data)); + disclosure_data.Append(std::move(data)); } return disclosure_data; } @@ -157,7 +157,7 @@ base::Value CreateGetMoreData(bool email_optin_needed, "iconUri", base::Value("https://www.gstatic.com/images/icons/material/system/" "2x/screen_search_desktop_grey600_24dp.png")); - get_more_data.GetList().push_back(std::move(context_data)); + get_more_data.Append(std::move(context_data)); // Process email optin data. if (email_optin_needed) { @@ -169,7 +169,7 @@ base::Value CreateGetMoreData(bool email_optin_needed, base::Value(email_optin_ui.default_enabled())); data.SetKey("iconUri", base::Value(email_optin_ui.icon_uri())); data.SetKey("legalText", base::Value(email_optin_ui.legal_text())); - get_more_data.GetList().push_back(std::move(data)); + get_more_data.Append(std::move(data)); } return get_more_data; diff --git a/chromium/chrome/browser/ui/webui/chromeos/camera/camera_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/camera/camera_ui.cc index 8a40f0cbdba..7a9dfa6bb52 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/camera/camera_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/camera/camera_ui.cc @@ -37,6 +37,8 @@ content::WebUIDataSource* CreateCameraUIHTMLSource() { IDR_CAMERA_WEBUI_BROWSER_PROXY); // Add mojom-lite files under expected paths. + source->AddResourcePath("src/js/mojo/camera_intent.mojom-lite.js", + IDR_CAMERA_CAMERA_INTENT_MOJOM_LITE_JS); source->AddResourcePath("src/js/mojo/image_capture.mojom-lite.js", IDR_CAMERA_IMAGE_CAPTURE_MOJOM_LITE_JS); source->AddResourcePath("src/js/mojo/camera_common.mojom-lite.js", diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/BUILD.gn b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/BUILD.gn new file mode 100644 index 00000000000..998e86183ac --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/BUILD.gn @@ -0,0 +1,11 @@ +# Copyright 2019 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. + +import("//mojo/public/tools/bindings/mojom.gni") + +mojom("mojo_bindings") { + sources = [ + "crostini_installer.mojom", + ] +} diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/OWNERS b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/OWNERS new file mode 100644 index 00000000000..08850f42120 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/OWNERS @@ -0,0 +1,2 @@ +per-file *.mojom=set noparent +per-file *.mojom=file://ipc/SECURITY_OWNERS diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom new file mode 100644 index 00000000000..0091ecbc389 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom @@ -0,0 +1,34 @@ +// Copyright 2019 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. + +module chromeos.crostini_installer.mojom; + +// Lives in the browser process. A renderer uses this to create a page handler +// for controlling Crostini installation. +interface PageHandlerFactory { + // Create a page handler to control Crostini installation. + CreatePageHandler(pending_remote<Page> page, + pending_receiver<PageHandler> handler); +}; + +// Lives in the browser process. A renderer use this to control Crostini +// installation. +interface PageHandler { + // Start installation + Install(); + // Cancel an on-going installation + Cancel(); + // If a user cancels the installation without starting it at all, this should + // be called so that metrics can be recorded. + CancelBeforeStart(); + // The page normally is displayed in a dialog. Call this to close the dialog. + // chrome.send('dialogClose') should not be used, which could kill the page + // handler before previous mojom calls have been run. + Close(); +}; + +// Lives in the renderer process. The browser uses this to sends installation +// updates to the web page in the render. +interface Page { +}; diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.cc b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.cc new file mode 100644 index 00000000000..77020c743d1 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.cc @@ -0,0 +1,44 @@ +// Copyright 2019 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. + +#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h" + +#include "chrome/browser/chromeos/crostini/crostini_manager.h" +#include "chrome/common/webui_url_constants.h" + +namespace { +GURL GetUrl() { + return GURL{chrome::kChromeUICrostiniInstallerUrl}; +} +} // namespace + +namespace chromeos { + +void CrostiniInstallerDialog::Show(Profile* profile) { + DCHECK(crostini::IsCrostiniUIAllowedForProfile(profile)); + auto* instance = SystemWebDialogDelegate::FindInstance(GetUrl().spec()); + if (instance) { + instance->Focus(); + return; + } + + // TODO(lxj): Move installer status tracking into the CrostiniInstaller. + DCHECK(!crostini::CrostiniManager::GetForProfile(profile) + ->GetInstallerViewStatus()); + crostini::CrostiniManager::GetForProfile(profile)->SetInstallerViewStatus( + true); + + instance = new CrostiniInstallerDialog(profile); + instance->ShowSystemDialog(); +} + +CrostiniInstallerDialog::CrostiniInstallerDialog(Profile* profile) + : SystemWebDialogDelegate{GetUrl(), /*title=*/{}}, profile_{profile} {} + +CrostiniInstallerDialog::~CrostiniInstallerDialog() { + crostini::CrostiniManager::GetForProfile(profile_)->SetInstallerViewStatus( + false); +} + +} // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h new file mode 100644 index 00000000000..5c56ffaba34 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_dialog.h @@ -0,0 +1,27 @@ +// Copyright 2019 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. + +#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_DIALOG_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_DIALOG_H_ + +#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" + +class Profile; + +namespace chromeos { + +class CrostiniInstallerDialog : public SystemWebDialogDelegate { + public: + static void Show(Profile* profile); + + private: + explicit CrostiniInstallerDialog(Profile* profile); + ~CrostiniInstallerDialog() override; + + Profile* profile_; +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_DIALOG_H_ diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.cc new file mode 100644 index 00000000000..8b971423ec4 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.cc @@ -0,0 +1,64 @@ +// Copyright 2019 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. + +#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h" + +#include <utility> + +#include "base/bind.h" +#include "chrome/browser/chromeos/crostini/crostini_installer_ui_delegate.h" + +namespace chromeos { + +CrostiniInstallerPageHandler::CrostiniInstallerPageHandler( + crostini::CrostiniInstallerUIDelegate* installer_ui_delegate, + mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler> + pending_page_handler, + mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> pending_page, + base::OnceClosure close_dialog_callback) + : installer_ui_delegate_{installer_ui_delegate}, + receiver_{this, std::move(pending_page_handler)}, + page_{std::move(pending_page)}, + close_dialog_callback_{std::move(close_dialog_callback)} {} + +CrostiniInstallerPageHandler::~CrostiniInstallerPageHandler() = default; + +void CrostiniInstallerPageHandler::Install() { + installer_ui_delegate_->Install( + base::BindRepeating(&CrostiniInstallerPageHandler::OnProgressUpdate, + weak_ptr_factory_.GetWeakPtr()), + base::BindOnce(&CrostiniInstallerPageHandler::OnInstallFinished, + weak_ptr_factory_.GetWeakPtr())); +} + +void CrostiniInstallerPageHandler::Cancel() { + installer_ui_delegate_->Cancel( + base::BindOnce(&CrostiniInstallerPageHandler::OnCanceled, + weak_ptr_factory_.GetWeakPtr())); +} + +void CrostiniInstallerPageHandler::CancelBeforeStart() { + installer_ui_delegate_->CancelBeforeStart(); +} + +void CrostiniInstallerPageHandler::Close() { + std::move(close_dialog_callback_).Run(); +} + +void CrostiniInstallerPageHandler::OnProgressUpdate( + crostini::mojom::InstallerState installer_state, + double progress_fraction) { + // TODO(lxj) +} + +void CrostiniInstallerPageHandler::OnInstallFinished( + crostini::mojom::InstallerError error) { + // TODO(lxj) +} + +void CrostiniInstallerPageHandler::OnCanceled() { + // TODO(lxj) +} + +} // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h new file mode 100644 index 00000000000..9060a95057b --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h @@ -0,0 +1,60 @@ +// Copyright 2019 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. + +#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_ + +#include "base/callback.h" +#include "base/macros.h" +#include "base/memory/weak_ptr.h" +#include "chrome/browser/chromeos/crostini/crostini_installer_types.mojom-forward.h" +#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/receiver.h" +#include "mojo/public/cpp/bindings/remote.h" + +namespace crostini { +class CrostiniInstallerUIDelegate; +} // namespace crostini + +namespace chromeos { + +class CrostiniInstallerPageHandler + : public chromeos::crostini_installer::mojom::PageHandler { + public: + CrostiniInstallerPageHandler( + crostini::CrostiniInstallerUIDelegate* installer_ui_delegate, + mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler> + pending_page_handler, + mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> + pending_page, + base::OnceClosure close_dialog_callback); + ~CrostiniInstallerPageHandler() override; + + // chromeos::crostini_installer::mojom::PageHandler: + void Install() override; + void Cancel() override; + void CancelBeforeStart() override; + void Close() override; + + private: + void OnProgressUpdate(crostini::mojom::InstallerState installer_state, + double progress_fraction); + void OnInstallFinished(crostini::mojom::InstallerError error); + void OnCanceled(); + + crostini::CrostiniInstallerUIDelegate* installer_ui_delegate_; + mojo::Receiver<chromeos::crostini_installer::mojom::PageHandler> receiver_; + mojo::Remote<chromeos::crostini_installer::mojom::Page> page_; + base::OnceClosure close_dialog_callback_; + + base::WeakPtrFactory<CrostiniInstallerPageHandler> weak_ptr_factory_{this}; + + DISALLOW_COPY_AND_ASSIGN(CrostiniInstallerPageHandler); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_ diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.cc new file mode 100644 index 00000000000..02fe92c3d9a --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.cc @@ -0,0 +1,78 @@ +// Copyright 2019 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. + +#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h" + +#include <utility> + +#include "base/bind.h" +#include "chrome/browser/chromeos/crostini/crostini_installer.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h" +#include "chrome/common/webui_url_constants.h" +#include "chrome/grit/browser_resources.h" +#include "chromeos/constants/chromeos_features.h" +#include "content/public/browser/web_ui_data_source.h" +#include "ui/web_dialogs/web_dialog_ui.h" +#include "ui/webui/mojo_web_ui_controller.h" + +namespace chromeos { + +bool CrostiniInstallerUI::IsEnabled() { + return base::FeatureList::IsEnabled( + chromeos::features::kCrostiniWebUIInstaller); +} + +CrostiniInstallerUI::CrostiniInstallerUI(content::WebUI* web_ui) + : ui::MojoWebDialogUI{web_ui} { + // TODO(lxj): We might want to make sure there is only one instance of this + // class. + + content::WebUIDataSource* source = + content::WebUIDataSource::Create(chrome::kChromeUICrostiniInstallerHost); + + source->AddResourcePath("app.js", IDR_CROSTINI_INSTALLER_APP_JS); + source->AddResourcePath("browser_proxy.js", + IDR_CROSTINI_INSTALLER_BROWSER_PROXY_JS); + source->AddResourcePath("crostini_installer.mojom-lite.js", + IDR_CROSTINI_INSTALLER_MOJO_LITE_JS); + source->SetDefaultResource(IDR_CROSTINI_INSTALLER_INDEX_HTML); + content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); + + AddHandlerToRegistry(base::BindRepeating( + &CrostiniInstallerUI::BindPageHandlerFactory, base::Unretained(this))); +} + +CrostiniInstallerUI::~CrostiniInstallerUI() = default; + +void CrostiniInstallerUI::BindPageHandlerFactory( + mojo::PendingReceiver< + chromeos::crostini_installer::mojom::PageHandlerFactory> + pending_receiver) { + if (page_factory_receiver_.is_bound()) { + page_factory_receiver_.reset(); + } + + page_factory_receiver_.Bind(std::move(pending_receiver)); +} + +void CrostiniInstallerUI::CreatePageHandler( + mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> pending_page, + mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler> + pending_page_handler) { + DCHECK(pending_page.is_valid()); + + page_handler_ = std::make_unique<CrostiniInstallerPageHandler>( + crostini::CrostiniInstaller::GetForProfile(Profile::FromWebUI(web_ui())), + std::move(pending_page_handler), std::move(pending_page), + // Using Unretained(this) because |page_handler_| will not out-live + // |this|. + // + // CloseDialog() is a no-op if we are not in a dialog (e.g. user + // access the page using the URL directly, which is not supported). + base::BindOnce(&CrostiniInstallerUI::CloseDialog, base::Unretained(this), + nullptr)); +} + +} // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h new file mode 100644 index 00000000000..2e5d81d5dd9 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h @@ -0,0 +1,51 @@ +// Copyright 2019 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. + +#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_ + +#include "base/macros.h" +#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/receiver.h" +#include "ui/web_dialogs/web_dialog_ui.h" + +namespace chromeos { + +class CrostiniInstallerPageHandler; + +// The WebUI for chrome://crostini-installer +class CrostiniInstallerUI + : public ui::MojoWebDialogUI, + public chromeos::crostini_installer::mojom::PageHandlerFactory { + public: + static bool IsEnabled(); + + explicit CrostiniInstallerUI(content::WebUI* web_ui); + ~CrostiniInstallerUI() override; + + private: + void BindPageHandlerFactory( + mojo::PendingReceiver< + chromeos::crostini_installer::mojom::PageHandlerFactory> + pending_receiver); + + // chromeos::crostini_installer::mojom::PageHandlerFactory: + void CreatePageHandler( + mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> + pending_page, + mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler> + pending_page_handler) override; + + std::unique_ptr<CrostiniInstallerPageHandler> page_handler_; + mojo::Receiver<chromeos::crostini_installer::mojom::PageHandlerFactory> + page_factory_receiver_{this}; + + DISALLOW_COPY_AND_ASSIGN(CrostiniInstallerUI); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_ diff --git a/chromium/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc index 686d55faf55..857d5816fdf 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc @@ -29,7 +29,6 @@ #include "base/task/post_task.h" #include "base/task/task_traits.h" #include "base/threading/sequenced_task_runner_handle.h" -#include "chrome/browser/chromeos/drive/debug_info_collector.h" #include "chrome/browser/chromeos/drive/drive_integration_service.h" #include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/file_manager/path_util.h" @@ -43,13 +42,9 @@ #include "chromeos/constants/chromeos_features.h" #include "components/download/content/public/all_download_item_notifier.h" #include "components/download/public/common/download_item.h" -#include "components/drive/drive.pb.h" -#include "components/drive/drive_api_util.h" #include "components/drive/drive_notification_manager.h" #include "components/drive/drive_pref_names.h" #include "components/drive/event_logger.h" -#include "components/drive/job_list.h" -#include "components/drive/service/drive_service_interface.h" #include "components/prefs/pref_service.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -152,74 +147,6 @@ std::pair<base::ListValue, base::DictionaryValue> GetGCacheContents( return result; } -// Formats |entry| into text. -std::string FormatEntry(const base::FilePath& path, - const drive::ResourceEntry& entry) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - using base::StringAppendF; - - std::string out; - StringAppendF(&out, "%s\n", path.AsUTF8Unsafe().c_str()); - StringAppendF(&out, " title: %s\n", entry.title().c_str()); - StringAppendF(&out, " local_id: %s\n", entry.local_id().c_str()); - StringAppendF(&out, " resource_id: %s\n", entry.resource_id().c_str()); - StringAppendF(&out, " parent_local_id: %s\n", - entry.parent_local_id().c_str()); - StringAppendF(&out, " shared: %s\n", entry.shared() ? "true" : "false"); - StringAppendF(&out, " shared_with_me: %s\n", - entry.shared_with_me() ? "true" : "false"); - StringAppendF(&out, " alternate_url: %s\n", entry.alternate_url().c_str()); - - const drive::PlatformFileInfoProto& file_info = entry.file_info(); - StringAppendF(&out, " file_info\n"); - StringAppendF(&out, " size: %" PRId64 "\n", file_info.size()); - StringAppendF(&out, " is_directory: %d\n", file_info.is_directory()); - StringAppendF(&out, " is_symbolic_link: %d\n", - file_info.is_symbolic_link()); - - const base::Time last_modified = base::Time::FromInternalValue( - file_info.last_modified()); - const base::Time last_modified_by_me = - base::Time::FromInternalValue(entry.last_modified_by_me()); - const base::Time last_accessed = base::Time::FromInternalValue( - file_info.last_accessed()); - const base::Time creation_time = base::Time::FromInternalValue( - file_info.creation_time()); - StringAppendF(&out, " last_modified: %s\n", - google_apis::util::FormatTimeAsString(last_modified).c_str()); - StringAppendF( - &out, " last_modified_by_me: %s\n", - google_apis::util::FormatTimeAsString(last_modified_by_me).c_str()); - StringAppendF(&out, " last_accessed: %s\n", - google_apis::util::FormatTimeAsString(last_accessed).c_str()); - StringAppendF(&out, " creation_time: %s\n", - google_apis::util::FormatTimeAsString(creation_time).c_str()); - - if (entry.has_file_specific_info()) { - const drive::FileSpecificInfo& file_specific_info = - entry.file_specific_info(); - StringAppendF(&out, " content_mime_type: %s\n", - file_specific_info.content_mime_type().c_str()); - StringAppendF(&out, " file_md5: %s\n", - file_specific_info.md5().c_str()); - StringAppendF(&out, " document_extension: %s\n", - file_specific_info.document_extension().c_str()); - StringAppendF(&out, " is_hosted_document: %d\n", - file_specific_info.is_hosted_document()); - } - - if (entry.has_directory_specific_info()) { - StringAppendF(&out, " directory_info\n"); - const drive::DirectorySpecificInfo& directory_specific_info = - entry.directory_specific_info(); - StringAppendF(&out, " changestamp: %" PRId64 "\n", - directory_specific_info.changestamp()); - } - - return out; -} - // Appends {'key': key, 'value': value, 'class': clazz} dictionary to the // |list|. void AppendKeyValue(base::ListValue* list, @@ -231,7 +158,7 @@ void AppendKeyValue(base::ListValue* list, dict->SetKey(kValue, base::Value(std::move(value))); if (!clazz.empty()) dict->SetKey(kClass, base::Value(std::move(clazz))); - list->GetList().push_back(std::move(*dict)); + list->Append(std::move(*dict)); } ino_t GetInodeValue(const base::FilePath& path) { @@ -335,22 +262,10 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { base::BindRepeating(&DriveInternalsWebUIHandler::OnPeriodicUpdate, weak_ptr_factory_.GetWeakPtr())); web_ui()->RegisterMessageCallback( - "clearAccessToken", - base::BindRepeating(&DriveInternalsWebUIHandler::ClearAccessToken, - weak_ptr_factory_.GetWeakPtr())); - web_ui()->RegisterMessageCallback( - "clearRefreshToken", - base::BindRepeating(&DriveInternalsWebUIHandler::ClearRefreshToken, - weak_ptr_factory_.GetWeakPtr())); - web_ui()->RegisterMessageCallback( "resetDriveFileSystem", base::BindRepeating(&DriveInternalsWebUIHandler::ResetDriveFileSystem, weak_ptr_factory_.GetWeakPtr())); web_ui()->RegisterMessageCallback( - "listFileEntries", - base::BindRepeating(&DriveInternalsWebUIHandler::ListFileEntries, - weak_ptr_factory_.GetWeakPtr())); - web_ui()->RegisterMessageCallback( "zipLogs", base::BindRepeating(&DriveInternalsWebUIHandler::ZipDriveFsLogs, weak_ptr_factory_.GetWeakPtr())); @@ -441,224 +356,23 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { drive_notification_manager ? drive_notification_manager->push_notification_enabled() : false); - auto* drive_service = GetDriveService(); - if (drive_service) { - connection_status.SetBoolean("has-refresh-token", - drive_service->HasRefreshToken()); - connection_status.SetBoolean("has-access-token", - drive_service->HasAccessToken()); - } MaybeCallJavascript("updateConnectionStatus", std::move(connection_status)); } void UpdateAboutResourceSection() { - if (IsDriveFsEnabled()) { - // TODO(crbug.com/896123): Maybe worth implementing. - SetSectionEnabled("account-information-section", false); - return; - } - - SetSectionEnabled("account-information-section", true); - auto* drive_service = GetDriveService(); - if (drive_service) { - drive_service->GetAboutResource( - base::Bind(&DriveInternalsWebUIHandler::OnGetAboutResource, - weak_ptr_factory_.GetWeakPtr())); - } - } - - // Called when GetAboutResource() call to DriveService is complete. - void OnGetAboutResource( - google_apis::DriveApiErrorCode status, - std::unique_ptr<google_apis::AboutResource> about_resource) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - if (status != google_apis::HTTP_SUCCESS) { - LOG(ERROR) << "Failed to get about resource"; - return; - } - DCHECK(about_resource); - - base::DictionaryValue data; - data.SetDouble("account-quota-total", about_resource->quota_bytes_total()); - data.SetDouble("account-quota-used", - about_resource->quota_bytes_used_aggregate()); - data.SetDouble("account-largest-changestamp-remote", - about_resource->largest_change_id()); - data.SetString("root-resource-id", about_resource->root_folder_id()); - - MaybeCallJavascript("updateAboutResource", std::move(data)); + // TODO(crbug.com/896123): Maybe worth implementing. + SetSectionEnabled("account-information-section", false); } void UpdateDeltaUpdateStatusSection() { - if (IsDriveFsEnabled()) { - // TODO(crbug.com/896123): Maybe worth implementing. - SetSectionEnabled("delta-update-status-section", false); - return; - } - - SetSectionEnabled("delta-update-status-section", true); - auto* debug_info_collector = GetDebugInfoCollector(); - if (debug_info_collector) { - debug_info_collector->GetMetadata(base::Bind( - &DriveInternalsWebUIHandler::OnGetFilesystemMetadataForDeltaUpdate, - weak_ptr_factory_.GetWeakPtr())); - } - } - - // Callback for DebugInfoCollector::GetMetadata for delta update. - void OnGetFilesystemMetadataForDeltaUpdate( - const drive::FileSystemMetadata& metadata, - const std::map<std::string, drive::FileSystemMetadata>& - team_drive_metadata) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - auto items = std::make_unique<base::ListValue>(); - // Users default corpus first. - auto app_data = std::make_unique<base::DictionaryValue>(); - app_data->SetString("id", "default corpus"); - app_data->SetString("root_entry_path", metadata.path); - app_data->SetString("start_page_token", metadata.start_page_token); - app_data->SetString("last_check_time", - google_apis::util::FormatTimeAsStringLocaltime( - metadata.last_update_check_time)); - app_data->SetString( - "last_check_result", - drive::FileErrorToString(metadata.last_update_check_error)); - app_data->SetString("refreshing", metadata.refreshing ? "Yes" : "No"); - - items->Append(std::move(app_data)); - - for (const auto& team_drive : team_drive_metadata) { - app_data = std::make_unique<base::DictionaryValue>(); - app_data->SetString("id", team_drive.first); - app_data->SetString("root_entry_path", team_drive.second.path); - app_data->SetString("start_page_token", - team_drive.second.start_page_token); - app_data->SetString("last_check_time", - google_apis::util::FormatTimeAsStringLocaltime( - team_drive.second.last_update_check_time)); - app_data->SetString( - "last_check_result", - drive::FileErrorToString(team_drive.second.last_update_check_error)); - app_data->SetString("refreshing", - team_drive.second.refreshing ? "Yes" : "No"); - items->Append(std::move(app_data)); - } - - base::DictionaryValue delta_update_status; - delta_update_status.Set("items", std::move(items)); - - MaybeCallJavascript("updateDeltaUpdateStatus", - std::move(delta_update_status)); + // TODO(crbug.com/896123): Maybe worth implementing. + SetSectionEnabled("delta-update-status-section", false); } void UpdateInFlightOperationsSection() { - if (IsDriveFsEnabled()) { - // TODO(crbug.com/896123): Maybe worth implementing. - SetSectionEnabled("in-flight-operations-section", false); - return; - } - - SetSectionEnabled("in-flight-operations-section", true); - auto* integration_service = GetIntegrationService(); - if (!integration_service) - return; - drive::JobListInterface* job_list = integration_service->job_list(); - if (!job_list) - return; - std::vector<drive::JobInfo> info_list = job_list->GetJobInfoList(); - - base::ListValue in_flight_operations; - for (size_t i = 0; i < info_list.size(); ++i) { - const drive::JobInfo& info = info_list[i]; - - auto dict = std::make_unique<base::DictionaryValue>(); - dict->SetInteger("id", info.job_id); - dict->SetString("type", drive::JobTypeToString(info.job_type)); - dict->SetString("file_path", info.file_path.AsUTF8Unsafe()); - dict->SetString("state", drive::JobStateToString(info.state)); - dict->SetDouble("progress_current", info.num_completed_bytes); - dict->SetDouble("progress_total", info.num_total_bytes); - in_flight_operations.Append(std::move(dict)); - } - - MaybeCallJavascript("updateInFlightOperations", - std::move(in_flight_operations)); - } - - void UpdateFileSystemContentsSection() { - if (IsDriveFsEnabled()) { - SetSectionEnabled("file-system-contents-section", false); - return; - } - - SetSectionEnabled("file-system-contents-section", true); - drive::DebugInfoCollector* debug_info_collector = GetDebugInfoCollector(); - if (!debug_info_collector) - return; - - // Start rendering the file system tree as text. - const base::FilePath root_path = drive::util::GetDriveGrandRootPath(); - - debug_info_collector->GetResourceEntry( - root_path, - base::BindOnce(&DriveInternalsWebUIHandler::OnGetResourceEntryByPath, - weak_ptr_factory_.GetWeakPtr(), root_path)); - - debug_info_collector->ReadDirectory( - root_path, - base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, - weak_ptr_factory_.GetWeakPtr(), root_path)); - } - - // Called when GetResourceEntryByPath() is complete. - void OnGetResourceEntryByPath(const base::FilePath& path, - drive::FileError error, - std::unique_ptr<drive::ResourceEntry> entry) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - if (error == drive::FILE_ERROR_OK) { - DCHECK(entry.get()); - MaybeCallJavascript("updateFileSystemContents", - base::Value(FormatEntry(path, *entry) + "\n")); - } - } - - // Called when ReadDirectoryByPath() is complete. - void OnReadDirectoryByPath( - const base::FilePath& parent_path, - drive::FileError error, - std::unique_ptr<drive::ResourceEntryVector> entries) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - if (error == drive::FILE_ERROR_OK) { - DCHECK(entries.get()); - - drive::DebugInfoCollector* debug_info_collector = GetDebugInfoCollector(); - std::string file_system_as_text; - for (size_t i = 0; i < entries->size(); ++i) { - const drive::ResourceEntry& entry = (*entries)[i]; - const base::FilePath current_path = parent_path.Append( - base::FilePath::FromUTF8Unsafe(entry.base_name())); - - file_system_as_text.append(FormatEntry(current_path, entry) + "\n"); - - if (entry.file_info().is_directory()) { - debug_info_collector->ReadDirectory( - current_path, - base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, - weak_ptr_factory_.GetWeakPtr(), current_path)); - } - } - - // There may be pending ReadDirectoryByPath() calls, but we can update - // the page with what we have now. This results in progressive - // updates, which is good for a large file system. - MaybeCallJavascript("updateFileSystemContents", - base::Value(file_system_as_text)); - } + // TODO(crbug.com/896123): Maybe worth implementing. + SetSectionEnabled("in-flight-operations-section", false); } void UpdatePathConfigurationsSection() { @@ -727,8 +441,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { PrefService* pref_service = profile()->GetPrefs(); base::ListValue preferences; - AppendKeyValue(&preferences, "DriveFS", - IsDriveFsEnabled() ? "true" : "false"); for (size_t i = 0; i < base::size(kDriveRelatedPreferences); ++i) { const std::string key = kDriveRelatedPreferences[i]; // As of now, all preferences are boolean. @@ -772,10 +484,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { } void UpdateServiceLogSection() { - if (!IsDriveFsEnabled()) { - SetSectionEnabled("service-log-section", false); - return; - } SetSectionEnabled("service-log-section", true); if (service_log_file_is_processing_) @@ -818,36 +526,8 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { } void UpdateCacheContentsSection() { - if (IsDriveFsEnabled()) { - // TODO(crbug.com/896123): Maybe worth implementing. - SetSectionEnabled("cache-contents-section", false); - return; - } - SetSectionEnabled("cache-contents-section", true); - - auto* debug_info_collector = GetDebugInfoCollector(); - if (debug_info_collector) { - debug_info_collector->IterateFileCache( - base::Bind(&DriveInternalsWebUIHandler::OnUpdateCacheEntry, - weak_ptr_factory_.GetWeakPtr()), - base::DoNothing()); - } - } - - // Called as the iterator for DebugInfoCollector::IterateFileCache(). - void OnUpdateCacheEntry(const std::string& local_id, - const drive::FileCacheEntry& cache_entry) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - // Convert |cache_entry| into a dictionary. - base::DictionaryValue value; - value.SetString("local_id", local_id); - value.SetString("md5", cache_entry.md5()); - value.SetBoolean("is_present", cache_entry.is_present()); - value.SetBoolean("is_pinned", cache_entry.is_pinned()); - value.SetBoolean("is_dirty", cache_entry.is_dirty()); - - MaybeCallJavascript("updateCacheContents", std::move(value)); + // TODO(crbug.com/896123): Maybe worth implementing. + SetSectionEnabled("cache-contents-section", false); } void UpdateGCacheContentsSection() { @@ -873,24 +553,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { } // Called when the corresponding button on the page is pressed. - void ClearAccessToken(const base::ListValue* args) { - AllowJavascript(); - - drive::DriveServiceInterface* drive_service = GetDriveService(); - if (drive_service) - drive_service->ClearAccessToken(); - } - - // Called when the corresponding button on the page is pressed. - void ClearRefreshToken(const base::ListValue* args) { - AllowJavascript(); - - drive::DriveServiceInterface* drive_service = GetDriveService(); - if (drive_service) - drive_service->ClearRefreshToken(); - } - - // Called when the corresponding button on the page is pressed. void ResetDriveFileSystem(const base::ListValue* args) { AllowJavascript(); @@ -903,13 +565,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { } } - // Called when the corresponding button on the page is pressed. - void ListFileEntries(const base::ListValue* args) { - AllowJavascript(); - - UpdateFileSystemContentsSection(); - } - void ZipDriveFsLogs(const base::ListValue* args) { AllowJavascript(); @@ -941,24 +596,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { return service; } - // Returns a DriveService instance. - drive::DriveServiceInterface* GetDriveService() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - return drive::util::GetDriveServiceByProfile(profile()); - } - - // Returns a DebugInfoCollector instance. - drive::DebugInfoCollector* GetDebugInfoCollector() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - drive::DriveIntegrationService* service = GetIntegrationService(); - return service ? service->debug_info_collector() : NULL; - } - - // Whether DriveFS is enabled. - bool IsDriveFsEnabled() { - return base::FeatureList::IsEnabled(chromeos::features::kDriveFs); - } - // The last event sent to the JavaScript side. int last_sent_event_id_; diff --git a/chromium/chrome/browser/ui/webui/chromeos/first_run/first_run_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/first_run/first_run_handler.cc index 46afde2fa0d..92020cd21ff 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/first_run/first_run_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/first_run/first_run_handler.cc @@ -6,7 +6,6 @@ #include <utility> -#include "ash/public/mojom/voice_interaction_controller.mojom.h" #include "base/bind.h" #include "base/values.h" #include "chrome/browser/chromeos/assistant/assistant_util.h" diff --git a/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.cc b/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.cc index 4d8cca34874..d341aac11e6 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/webui/chromeos/internet_config_dialog.h" +#include "ash/public/cpp/network_config_service.h" #include "base/json/json_writer.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chromeos/network_element_localized_strings_provider.h" @@ -14,6 +15,7 @@ #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_util.h" +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" // nogncheck #include "components/strings/grit/components_strings.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_data_source.h" @@ -136,7 +138,7 @@ std::string InternetConfigDialog::GetDialogArgs() const { // InternetConfigDialogUI InternetConfigDialogUI::InternetConfigDialogUI(content::WebUI* web_ui) - : ui::WebDialogUI(web_ui) { + : ui::MojoWebDialogUI(web_ui) { content::WebUIDataSource* source = content::WebUIDataSource::Create( chrome::kChromeUIInternetConfigDialogHost); @@ -153,8 +155,18 @@ InternetConfigDialogUI::InternetConfigDialogUI(content::WebUI* web_ui) #endif content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); + + // Add Mojo bindings to this WebUI so that Mojo calls can occur in JavaScript. + AddHandlerToRegistry(base::BindRepeating( + &InternetConfigDialogUI::BindCrosNetworkConfig, base::Unretained(this))); } InternetConfigDialogUI::~InternetConfigDialogUI() {} +void InternetConfigDialogUI::BindCrosNetworkConfig( + mojo::PendingReceiver<chromeos::network_config::mojom::CrosNetworkConfig> + receiver) { + ash::GetNetworkConfigService(std::move(receiver)); +} + } // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.h b/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.h index 848254eba3c..a95f0f75897 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.h +++ b/chromium/chrome/browser/ui/webui/chromeos/internet_config_dialog.h @@ -8,8 +8,9 @@ #include <string> #include "base/macros.h" -#include "base/strings/string16.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h" // nogncheck +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/web_dialogs/web_dialog_ui.h" namespace chromeos { @@ -49,12 +50,16 @@ class InternetConfigDialog : public SystemWebDialogDelegate { // A WebUI to host the network configuration UI in a dialog, used in the // login screen and when a new network is configured from the system tray. -class InternetConfigDialogUI : public ui::WebDialogUI { +class InternetConfigDialogUI : public ui::MojoWebDialogUI { public: explicit InternetConfigDialogUI(content::WebUI* web_ui); ~InternetConfigDialogUI() override; private: + void BindCrosNetworkConfig( + mojo::PendingReceiver<chromeos::network_config::mojom::CrosNetworkConfig> + receiver); + DISALLOW_COPY_AND_ASSIGN(InternetConfigDialogUI); }; diff --git a/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.cc b/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.cc index 2489cb2e124..02ea2ac9977 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.cc @@ -17,6 +17,7 @@ #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_util.h" +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" // nogncheck #include "components/strings/grit/components_strings.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_data_source.h" @@ -45,6 +46,7 @@ void AddInternetStrings(content::WebUIDataSource* html_source) { {"close", IDS_CLOSE}, {"networkButtonConnect", IDS_SETTINGS_INTERNET_BUTTON_CONNECT}, {"networkButtonDisconnect", IDS_SETTINGS_INTERNET_BUTTON_DISCONNECT}, + {"networkButtonForget", IDS_SETTINGS_INTERNET_BUTTON_FORGET}, {"networkIPAddress", IDS_SETTINGS_INTERNET_NETWORK_IP_ADDRESS}, {"networkSectionNetwork", IDS_SETTINGS_INTERNET_NETWORK_SECTION_NETWORK}, {"networkSectionProxy", IDS_SETTINGS_INTERNET_NETWORK_SECTION_PROXY}, @@ -160,8 +162,9 @@ InternetDetailDialogUI::InternetDetailDialogUI(content::WebUI* web_ui) InternetDetailDialogUI::~InternetDetailDialogUI() {} void InternetDetailDialogUI::BindCrosNetworkConfig( - chromeos::network_config::mojom::CrosNetworkConfigRequest request) { - ash::GetNetworkConfigService(std::move(request)); + mojo::PendingReceiver<chromeos::network_config::mojom::CrosNetworkConfig> + receiver) { + ash::GetNetworkConfigService(std::move(receiver)); } } // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.h b/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.h index eec6c4d9a98..fe91980b879 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.h +++ b/chromium/chrome/browser/ui/webui/chromeos/internet_detail_dialog.h @@ -7,7 +7,8 @@ #include "base/macros.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" -#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" // nogncheck +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h" // nogncheck +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/web_dialogs/web_dialog_ui.h" namespace chromeos { @@ -51,7 +52,8 @@ class InternetDetailDialogUI : public ui::MojoWebDialogUI { private: void BindCrosNetworkConfig( - chromeos::network_config::mojom::CrosNetworkConfigRequest request); + mojo::PendingReceiver<chromeos::network_config::mojom::CrosNetworkConfig> + receiver); DISALLOW_COPY_AND_ASSIGN(InternetDetailDialogUI); }; diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/OWNERS b/chromium/chrome/browser/ui/webui/chromeos/login/OWNERS index a18954dc038..5dbb46f035d 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/OWNERS +++ b/chromium/chrome/browser/ui/webui/chromeos/login/OWNERS @@ -1,10 +1,10 @@ -# (in PST) +# primary (in CET) +antrim@chromium.org +rsorokin@chromium.org + +# secondary (in PST) achuith@chromium.org alemate@chromium.org tbarzic@chromium.org -# (in CET) -antrim@chromium.org -per-file *active_directory*=rsorokin@chromium.org - # COMPONENT: UI>Shell>OOBE diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.cc index f53cede13a4..6979bd6f555 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.cc @@ -56,28 +56,25 @@ AssistantOptInFlowScreenHandler::AssistantOptInFlowScreenHandler( AssistantOptInFlowScreenHandler::~AssistantOptInFlowScreenHandler() { if (client_binding_) StopSpeakerIdEnrollment(); - if (arc::VoiceInteractionControllerClient::Get()) { - arc::VoiceInteractionControllerClient::Get()->RemoveObserver(this); - } - if (screen_) { + if (ash::AssistantState::Get()) + ash::AssistantState::Get()->RemoveObserver(this); + if (screen_) screen_->OnViewDestroyed(this); - } } void AssistantOptInFlowScreenHandler::DeclareLocalizedValues( ::login::LocalizedValuesBuilder* builder) { builder->Add("locale", g_browser_process->GetApplicationLocale()); - builder->Add("assistantLogo", IDS_VOICE_INTERACTION_LOGO); - builder->Add("assistantOptinLoading", - IDS_VOICE_INTERACTION_VALUE_PROP_LOADING); + builder->Add("assistantLogo", IDS_ASSISTANT_LOGO); + builder->Add("assistantOptinLoading", IDS_ASSISTANT_VALUE_PROP_LOADING); builder->Add("assistantOptinLoadErrorTitle", - IDS_VOICE_INTERACTION_VALUE_PROP_LOAD_ERROR_TITLE); + IDS_ASSISTANT_VALUE_PROP_LOAD_ERROR_TITLE); builder->Add("assistantOptinLoadErrorMessage", - IDS_VOICE_INTERACTION_VALUE_PROP_LOAD_ERROR_MESSAGE); + IDS_ASSISTANT_VALUE_PROP_LOAD_ERROR_MESSAGE); builder->Add("assistantOptinSkipButton", - IDS_VOICE_INTERACTION_VALUE_PROP_SKIP_BUTTON); + IDS_ASSISTANT_VALUE_PROP_SKIP_BUTTON); builder->Add("assistantOptinRetryButton", - IDS_VOICE_INTERACTION_VALUE_PROP_RETRY_BUTTON); + IDS_ASSISTANT_VALUE_PROP_RETRY_BUTTON); builder->Add("assistantVoiceMatchTitle", IDS_ASSISTANT_VOICE_MATCH_TITLE); builder->Add("assistantVoiceMatchMessage", IDS_ASSISTANT_VOICE_MATCH_MESSAGE); builder->Add("assistantVoiceMatchNoDspMessage", @@ -149,6 +146,14 @@ void AssistantOptInFlowScreenHandler::RegisterMessages() { &AssistantOptInFlowScreenHandler::HandleFlowInitialized); } +void AssistantOptInFlowScreenHandler::GetAdditionalParameters( + base::DictionaryValue* dict) { + dict->SetBoolean("hotwordDspAvailable", chromeos::IsHotwordDspAvailable()); + dict->SetBoolean("voiceMatchDisabled", + chromeos::assistant::features::IsVoiceMatchDisabled()); + BaseScreenHandler::GetAdditionalParameters(dict); +} + void AssistantOptInFlowScreenHandler::Bind(AssistantOptInFlowScreen* screen) { BaseScreenHandler::SetBaseScreen(screen); screen_ = screen; @@ -218,9 +223,9 @@ void AssistantOptInFlowScreenHandler::SetupAssistantConnection() { // Make sure enable Assistant service since we need it during the flow. prefs->SetBoolean(chromeos::assistant::prefs::kAssistantEnabled, true); - if (arc::VoiceInteractionControllerClient::Get()->voice_interaction_state() == - ash::mojom::VoiceInteractionState::NOT_READY) { - arc::VoiceInteractionControllerClient::Get()->AddObserver(this); + if (ash::AssistantState::Get()->assistant_state() == + ash::mojom::AssistantState::NOT_READY) { + ash::AssistantState::Get()->AddObserver(this); } else { BindAssistantSettingsManager(); } @@ -272,11 +277,11 @@ void AssistantOptInFlowScreenHandler::OnDialogClosed() { } } -void AssistantOptInFlowScreenHandler::OnStateChanged( - ash::mojom::VoiceInteractionState state) { - if (state != ash::mojom::VoiceInteractionState::NOT_READY) { +void AssistantOptInFlowScreenHandler::OnAssistantStatusChanged( + ash::mojom::AssistantState state) { + if (state != ash::mojom::AssistantState::NOT_READY) { BindAssistantSettingsManager(); - arc::VoiceInteractionControllerClient::Get()->RemoveObserver(this); + ash::AssistantState::Get()->RemoveObserver(this); } } @@ -326,6 +331,14 @@ void AssistantOptInFlowScreenHandler::OnGetSettingsResponse( UMA_HISTOGRAM_TIMES("Assistant.OptInFlow.GetSettingsRequestTime", time_since_request_sent); + if (ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean( + assistant::prefs::kAssistantDisabledByPolicy)) { + DVLOG(1) << "Assistant is disabled by domain policy. Skip Assistant " + "opt-in flow."; + HandleFlowFinished(); + return; + } + assistant::SettingsUi settings_ui; if (!settings_ui.ParseFromString(settings)) { LOG(ERROR) << "Failed to parse get settings response."; diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.h b/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.h index 9810c088aea..a04c19835e1 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.h @@ -9,8 +9,8 @@ #include <string> #include "ash/public/cpp/assistant/assistant_setup.h" +#include "ash/public/cpp/assistant/assistant_state.h" #include "base/macros.h" -#include "chrome/browser/chromeos/arc/voice_interaction/voice_interaction_controller_client.h" #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" #include "chromeos/services/assistant/public/mojom/settings.mojom.h" #include "mojo/public/cpp/bindings/binding.h" @@ -43,7 +43,7 @@ class AssistantOptInFlowScreenView { class AssistantOptInFlowScreenHandler : public BaseScreenHandler, public AssistantOptInFlowScreenView, - public arc::VoiceInteractionControllerClient::Observer, + public ash::AssistantStateObserver, assistant::mojom::SpeakerIdEnrollmentClient { public: using TView = AssistantOptInFlowScreenView; @@ -63,6 +63,7 @@ class AssistantOptInFlowScreenHandler void DeclareLocalizedValues( ::login::LocalizedValuesBuilder* builder) override; void RegisterMessages() override; + void GetAdditionalParameters(base::DictionaryValue* dict) override; // AssistantOptInFlowScreenView: void Bind(AssistantOptInFlowScreen* screen) override; @@ -93,8 +94,8 @@ class AssistantOptInFlowScreenHandler // BaseScreenHandler: void Initialize() override; - // arc::VoiceInteractionControllerClient::Observer overrides - void OnStateChanged(ash::mojom::VoiceInteractionState state) override; + // ash::AssistantStateObserver: + void OnAssistantStatusChanged(ash::mojom::AssistantState state) override; // Connect to assistant settings manager. void BindAssistantSettingsManager(); diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc index 5474107730b..63c4d1cc21c 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.cc @@ -8,6 +8,7 @@ #include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/event_rewriter_controller.h" +#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/tablet_mode.h" #include "ash/public/mojom/constants.mojom.h" #include "ash/shell.h" @@ -16,6 +17,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/login/configuration_keys.h" @@ -44,6 +46,7 @@ #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" #include "chromeos/constants/chromeos_constants.h" +#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_switches.h" #include "components/login/base_screen_handler_utils.h" #include "components/login/localized_values_builder.h" @@ -101,8 +104,8 @@ CoreOobeHandler::CoreOobeHandler(JSCallsContainer* js_calls_container) // |connector| may be null in tests. auto* connector = content::GetSystemConnector(); if (connector) { - connector->BindInterface(ash::mojom::kServiceName, - &cros_display_config_ptr_); + connector->Connect(ash::mojom::kServiceName, + cros_display_config_.BindNewPipeAndPassReceiver()); } OobeConfiguration::Get()->AddAndFireObserver(this); } @@ -305,6 +308,10 @@ void CoreOobeHandler::SetClientAreaSize(int width, int height) { CallJS("cr.ui.Oobe.setClientAreaSize", width, height); } +void CoreOobeHandler::SetShelfHeight(int height) { + CallJS("cr.ui.Oobe.setShelfHeight", height); +} + void CoreOobeHandler::HandleInitialized() { GetOobeUI()->InitializeHandlers(); AllowJavascript(); @@ -546,6 +553,26 @@ void CoreOobeHandler::UpdateClientAreaSize() { const gfx::Size size = display::Screen::GetScreen()->GetPrimaryDisplay().size(); SetClientAreaSize(size.width(), size.height()); + SetShelfHeight(ash::ShelfConfig::Get()->shelf_size()); +} + +void CoreOobeHandler::SetDialogPaddingMode( + CoreOobeView::DialogPaddingMode mode) { + std::string padding; + switch (mode) { + case CoreOobeView::DialogPaddingMode::MODE_AUTO: + padding = "auto"; + break; + case CoreOobeView::DialogPaddingMode::MODE_NARROW: + padding = "narrow"; + break; + case CoreOobeView::DialogPaddingMode::MODE_WIDE: + padding = "wide"; + break; + default: + NOTREACHED(); + } + CallJS("cr.ui.Oobe.setDialogPaddingMode", padding); } void CoreOobeHandler::OnOobeConfigurationChanged() { @@ -586,7 +613,7 @@ void CoreOobeHandler::HandleGetPrimaryDisplayNameForTesting( const base::Value* callback_id; CHECK(args->Get(0, &callback_id)); - cros_display_config_ptr_->GetDisplayUnitInfoList( + cros_display_config_->GetDisplayUnitInfoList( false /* single_unified */, base::BindOnce(&CoreOobeHandler::GetPrimaryDisplayNameCallback, weak_ptr_factory_.GetWeakPtr(), callback_id->Clone())); diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h b/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h index 8e30d2b5363..0687932d4c3 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h @@ -23,6 +23,7 @@ #include "chrome/browser/chromeos/login/version_info_updater.h" #include "chrome/browser/chromeos/tpm_firmware_update.h" #include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h" +#include "mojo/public/cpp/bindings/remote.h" #include "ui/events/event_source.h" namespace base { @@ -38,6 +39,17 @@ namespace chromeos { class CoreOobeView { public: + // Enum that specifies how inner padding of OOBE dialog should be calculated. + enum class DialogPaddingMode { + // Oobe dialog is displayed full screen, padding will be calculated + // via css depending on media size. + MODE_AUTO, + // Oobe dialog have enough free space around and should use wide padding. + MODE_WIDE, + // Oobe dialog is positioned in limited space and should use narrow padding. + MODE_NARROW, + }; + virtual ~CoreOobeView() {} virtual void ShowSignInError(int login_attempts, @@ -58,6 +70,8 @@ class CoreOobeView { virtual void ReloadEulaContent(const base::DictionaryValue& dictionary) = 0; virtual void SetVirtualKeyboardShown(bool shown) = 0; virtual void SetClientAreaSize(int width, int height) = 0; + virtual void SetShelfHeight(int height) = 0; + virtual void SetDialogPaddingMode(DialogPaddingMode mode) = 0; virtual void ShowDeviceResetScreen() = 0; virtual void ShowEnableDebuggingScreen() = 0; virtual void InitDemoModeDetection() = 0; @@ -137,6 +151,8 @@ class CoreOobeHandler : public BaseWebUIHandler, void ReloadEulaContent(const base::DictionaryValue& dictionary) override; void SetVirtualKeyboardShown(bool displayed) override; void SetClientAreaSize(int width, int height) override; + void SetShelfHeight(int height) override; + void SetDialogPaddingMode(CoreOobeView::DialogPaddingMode mode) override; void ShowDeviceResetScreen() override; void ShowEnableDebuggingScreen() override; void ShowActiveDirectoryPasswordChangeScreen( @@ -222,7 +238,7 @@ class CoreOobeHandler : public BaseWebUIHandler, DemoModeDetector demo_mode_detector_; - ash::mojom::CrosDisplayConfigControllerPtr cros_display_config_ptr_; + mojo::Remote<ash::mojom::CrosDisplayConfigController> cros_display_config_; base::WeakPtrFactory<CoreOobeHandler> weak_ptr_factory_{this}; diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc index 35e15951f2a..49edf06dc4d 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler.cc @@ -21,7 +21,7 @@ #include "chromeos/constants/chromeos_switches.h" #include "chromeos/dbus/cryptohome/cryptohome_client.h" #include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/debug_daemon_client.h" +#include "chromeos/dbus/debug_daemon/debug_daemon_client.h" #include "chromeos/dbus/power/power_manager_client.h" #include "components/login/localized_values_builder.h" #include "components/prefs/pref_registry_simple.h" diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc index d0fa17ef808..6d632c707cf 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc @@ -42,6 +42,7 @@ #include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/google_service_auth_error.h" +#include "services/network/public/mojom/cookie_manager.mojom.h" #include "ui/base/l10n/l10n_util.h" #include "ui/chromeos/devicetype_utils.h" @@ -154,7 +155,7 @@ base::ListValue GetEncryptionTypesList() { enc_option.SetKey("value", base::Value(enc_types.id)); enc_option.SetKey("selected", base::Value(default_types == enc_types.encryption_types)); - encryption_list.GetList().emplace_back(std::move(enc_option)); + encryption_list.Append(std::move(enc_option)); } return encryption_list; } @@ -649,7 +650,7 @@ void EnrollmentScreenHandler::OnAdConfigurationUnlocked( custom.SetKey( "name", base::Value(l10n_util::GetStringUTF8(IDS_AD_CONFIG_SELECTION_CUSTOM))); - options->GetList().push_back(std::move(custom)); + options->Append(std::move(custom)); active_directory_join_type_ = ActiveDirectoryDomainJoinType::USING_CONFIGURATION; CallJS("login.OAuthEnrollmentScreen.setAdJoinConfiguration", *options); @@ -788,11 +789,10 @@ void EnrollmentScreenHandler::HandleCompleteLogin(const std::string& user) { Profile::FromWebUI(web_ui())); content::StoragePartition* partition = signin_partition_manager->GetCurrentStoragePartition(); - net::CookieOptions cookie_options; - cookie_options.set_include_httponly(); partition->GetCookieManagerForBrowserProcess()->GetCookieList( - GaiaUrls::GetInstance()->gaia_url(), cookie_options, + GaiaUrls::GetInstance()->gaia_url(), + net::CookieOptions::MakeAllInclusive(), base::BindOnce(&EnrollmentScreenHandler::OnGetCookiesForCompleteLogin, weak_ptr_factory_.GetWeakPtr(), user)); } diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc index e15b2103638..bb367ef3de4 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc @@ -80,6 +80,10 @@ void ErrorScreenHandler::SetShowConnectingIndicator(bool value) { CallJS("login.ErrorMessageScreen.showConnectingIndicator", value); } +void ErrorScreenHandler::SetIsPersistentError(bool is_persistent) { + CallJS("login.ErrorMessageScreen.setIsPersistentError", is_persistent); +} + void ErrorScreenHandler::SetUIState(NetworkError::UIState ui_state) { CallJS("login.ErrorMessageScreen.setUIState", static_cast<int>(ui_state)); } diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h b/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h index 67a26958e75..acc425a0bf8 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h @@ -51,6 +51,9 @@ class ErrorScreenView { // Updates visibility of the label indicating we're reconnecting. virtual void SetShowConnectingIndicator(bool value) = 0; + // Makes error persistent (e.g. non-closable). + virtual void SetIsPersistentError(bool is_persistent) = 0; + // Sets current UI state of the screen. virtual void SetUIState(NetworkError::UIState ui_state) = 0; }; @@ -75,6 +78,7 @@ class ErrorScreenHandler : public BaseScreenHandler, public ErrorScreenView { void SetGuestSigninAllowed(bool value) override; void SetOfflineSigninAllowed(bool value) override; void SetShowConnectingIndicator(bool value) override; + void SetIsPersistentError(bool is_persistent) override; void SetUIState(NetworkError::UIState ui_state) override; // WebUIMessageHandler: diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/fake_update_required_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/fake_update_required_screen_handler.cc new file mode 100644 index 00000000000..ffbed8d3645 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/login/fake_update_required_screen_handler.cc @@ -0,0 +1,14 @@ +// Copyright 2019 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. + +#include "chrome/browser/ui/webui/chromeos/login/fake_update_required_screen_handler.h" + +namespace chromeos { + +void FakeUpdateRequiredScreenHandler::SetUIState( + UpdateRequiredView::UIState ui_state) { + ui_state_ = ui_state; +} + +} // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/fake_update_required_screen_handler.h b/chromium/chrome/browser/ui/webui/chromeos/login/fake_update_required_screen_handler.h new file mode 100644 index 00000000000..7a36649adf7 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/chromeos/login/fake_update_required_screen_handler.h @@ -0,0 +1,48 @@ +// Copyright 2019 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. + +#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_FAKE_UPDATE_REQUIRED_SCREEN_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_FAKE_UPDATE_REQUIRED_SCREEN_HANDLER_H_ + +#include <string> + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "chrome/browser/chromeos/login/screens/update_required_screen.h" +#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" +#include "chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.h" + +namespace chromeos { + +class UpdateRequiredScreen; + +class FakeUpdateRequiredScreenHandler : public UpdateRequiredView { + public: + FakeUpdateRequiredScreenHandler() = default; + ~FakeUpdateRequiredScreenHandler() override {} + + UpdateRequiredView::UIState ui_state() { return ui_state_; } + + private: + void Show() override {} + void Hide() override {} + void Bind(UpdateRequiredScreen* screen) override {} + void Unbind() override {} + + void SetIsConnected(bool connected) override {} + void SetUpdateProgressUnavailable(bool unavailable) override {} + void SetUpdateProgressValue(int progress) override {} + void SetUpdateProgressMessage(const base::string16& message) override {} + void SetEstimatedTimeLeftVisible(bool visible) override {} + void SetEstimatedTimeLeft(int seconds_left) override {} + void SetUIState(UpdateRequiredView::UIState ui_state) override; + + UpdateRequiredView::UIState ui_state_; + + DISALLOW_COPY_AND_ASSIGN(FakeUpdateRequiredScreenHandler); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_FAKE_UPDATE_REQUIRED_SCREEN_HANDLER_H_ diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.cc index bf674ae60fb..4d4380b17b7 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.cc @@ -55,11 +55,9 @@ FingerprintSetupScreenHandler::FingerprintSetupScreenHandler( : BaseScreenHandler(kScreenId, js_calls_container) { set_user_acted_method_path("login.FingerprintSetupScreen.userActed"); - content::GetSystemConnector()->BindInterface(device::mojom::kServiceName, - &fp_service_); - device::mojom::FingerprintObserverPtr observer; - binding_.Bind(mojo::MakeRequest(&observer)); - fp_service_->AddFingerprintObserver(std::move(observer)); + content::GetSystemConnector()->Connect( + device::mojom::kServiceName, fp_service_.BindNewPipeAndPassReceiver()); + fp_service_->AddFingerprintObserver(receiver_.BindNewPipeAndPassRemote()); } FingerprintSetupScreenHandler::~FingerprintSetupScreenHandler() = default; diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.h b/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.h index 8eef6b9764e..8e752278477 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/fingerprint_setup_screen_handler.h @@ -7,7 +7,8 @@ #include "base/macros.h" #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" -#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/public/cpp/bindings/receiver.h" +#include "mojo/public/cpp/bindings/remote.h" #include "services/device/public/mojom/fingerprint.mojom.h" namespace chromeos { @@ -75,8 +76,8 @@ class FingerprintSetupScreenHandler FingerprintSetupScreen* screen_ = nullptr; - device::mojom::FingerprintPtr fp_service_; - mojo::Binding<device::mojom::FingerprintObserver> binding_{this}; + mojo::Remote<device::mojom::Fingerprint> fp_service_; + mojo::Receiver<device::mojom::FingerprintObserver> receiver_{this}; int enrolled_finger_count_ = 0; bool enroll_session_started_ = false; diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.cc index ee389c1f193..da7467ea754 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.cc @@ -17,6 +17,7 @@ #include "base/json/json_reader.h" #include "base/logging.h" #include "base/memory/ref_counted.h" +#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_macros.h" #include "base/optional.h" #include "base/stl_util.h" @@ -26,6 +27,7 @@ #include "base/task/post_task.h" #include "base/values.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/chromeos/authpolicy/authpolicy_helper.h" #include "chrome/browser/chromeos/certificate_provider/certificate_provider_service.h" #include "chrome/browser/chromeos/certificate_provider/certificate_provider_service_factory.h" @@ -33,6 +35,7 @@ #include "chrome/browser/chromeos/language_preferences.h" #include "chrome/browser/chromeos/login/lock_screen_utils.h" #include "chrome/browser/chromeos/login/reauth_stats.h" +#include "chrome/browser/chromeos/login/saml/public_saml_url_fetcher.h" #include "chrome/browser/chromeos/login/screens/network_error.h" #include "chrome/browser/chromeos/login/signin_partition_manager.h" #include "chrome/browser/chromeos/login/ui/login_display_host.h" @@ -108,6 +111,28 @@ const char kEndpointGen[] = "1.0"; const char kOAUTHCodeCookie[] = "oauth_code"; const char kGAPSCookie[] = "GAPS"; +// Must be kept consistent with ChromeOSSamlApiUsed in enums.xml +// These values are persisted to logs. Entries should not be renumbered and +// numeric values should never be reused +enum class ChromeOSSamlApiUsed { + kNotSamlLogin = 0, + kSamlApiUsed = 1, + kSamlApiNotUsed = 2, + kMaxValue = kSamlApiNotUsed, +}; + +void RecordAPILogin(bool is_third_party_idp, bool is_api_used) { + ChromeOSSamlApiUsed login_type; + if (!is_third_party_idp) { + login_type = ChromeOSSamlApiUsed::kNotSamlLogin; + } else if (is_api_used) { + login_type = ChromeOSSamlApiUsed::kSamlApiUsed; + } else { + login_type = ChromeOSSamlApiUsed::kSamlApiNotUsed; + } + base::UmaHistogramEnumeration("ChromeOS.SAML.APILogin", login_type); +} + policy::DeviceMode GetDeviceMode() { policy::BrowserPolicyConnectorChromeOS* connector = g_browser_process->platform_part()->browser_policy_connector_chromeos(); @@ -365,10 +390,29 @@ void GaiaScreenHandler::LoadGaia(const GaiaContext& context) { login::SigninPartitionManager* signin_partition_manager = login::SigninPartitionManager::Factory::GetForBrowserContext( Profile::FromWebUI(web_ui())); - signin_partition_manager->StartSigninSession( - web_ui()->GetWebContents(), + + auto partition_call = base::BindOnce( + &login::SigninPartitionManager::StartSigninSession, + base::Unretained(signin_partition_manager), web_ui()->GetWebContents(), base::BindOnce(&GaiaScreenHandler::LoadGaiaWithPartition, weak_factory_.GetWeakPtr(), context)); + + if (!context.email.empty()) { + const AccountId account_id = GetAccountId( + context.email, std::string() /* id */, AccountType::UNKNOWN); + const user_manager::User* const user = + user_manager::UserManager::Get()->FindUser(account_id); + + if (user && user->using_saml() && + user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { + public_saml_url_fetcher_ = + std::make_unique<chromeos::PublicSamlUrlFetcher>(account_id); + public_saml_url_fetcher_->Fetch(std::move(partition_call)); + return; + } + } + public_saml_url_fetcher_.reset(); + std::move(partition_call).Run(); } void GaiaScreenHandler::LoadGaiaWithPartition( @@ -399,11 +443,7 @@ void GaiaScreenHandler::LoadGaiaWithPartition( GaiaUrls::GetInstance()->gaia_url(), gaps_cookie_value, base::Time::Now(), base::nullopt /* server_time */)); - net::CookieOptions options; - options.set_include_httponly(); - // Permit it to set a SameSite cookie if it wants to. - options.set_same_site_cookie_context( - net::CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT); + const net::CookieOptions options = net::CookieOptions::MakeAllInclusive(); partition->GetCookieManagerForBrowserProcess()->SetCanonicalCookie( *cc.get(), "https", options, std::move(callback)); } @@ -444,30 +484,6 @@ void GaiaScreenHandler::LoadGaiaWithPartitionAndVersionAndConsent( screen_mode_ = GetGaiaScreenMode(context.email, context.use_offline); params.SetInteger("screenMode", screen_mode_); - if (!context.email.empty()) { - const AccountId account_id = GetAccountId( - context.email, std::string() /* id */, AccountType::UNKNOWN); - const user_manager::User* const user = - user_manager::UserManager::Get()->FindUser(account_id); - if (user && user->using_saml() && - user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT && - base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kPublicAccountsSamlUrl)) { - std::string saml_url = - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kPublicAccountsSamlUrl); - params.SetBoolean("startsOnSamlPage", true); - params.SetString("frameUrl", saml_url); - params.SetString("email", account_id.GetUserEmail()); - CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kPublicAccountsSamlAclUrl)); - std::string saml_acl_url = - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kPublicAccountsSamlAclUrl); - params.SetString("samlAclUrl", saml_acl_url); - } - } - if (screen_mode_ == GAIA_SCREEN_MODE_AD && !authpolicy_login_helper_) authpolicy_login_helper_ = std::make_unique<AuthPolicyHelper>(); @@ -538,6 +554,26 @@ void GaiaScreenHandler::LoadGaiaWithPartitionAndVersionAndConsent( ExtractSamlPasswordAttributesEnabled()); params.SetBoolean("enableGaiaActionButtons", GaiaActionButtonsEnabled()); + if (public_saml_url_fetcher_) { + params.SetBoolean("startsOnSamlPage", true); + DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kPublicAccountsSamlAclUrl)); + std::string saml_acl_url = + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kPublicAccountsSamlAclUrl); + params.SetString("samlAclUrl", saml_acl_url); + if (public_saml_url_fetcher_->FetchSucceeded()) { + params.SetString("frameUrl", public_saml_url_fetcher_->GetRedirectUrl()); + } else { + // TODO: make the string localized. + std::string msg = "Failed to fetch the SAML redirect URL from the server"; + core_oobe_view_->ShowSignInError( + 0, msg, std::string(), HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); + return; + } + } + public_saml_url_fetcher_.reset(); + frame_state_ = FRAME_STATE_LOADING; CallJS("login.GaiaSigninScreen.loadAuthExtension", params); } @@ -676,8 +712,6 @@ void GaiaScreenHandler::RegisterMessages() { AddRawCallback("showAddUser", &GaiaScreenHandler::HandleShowAddUser); AddCallback("getIsSamlUserPasswordless", &GaiaScreenHandler::HandleGetIsSamlUserPasswordless); - AddCallback("updateOobeDialogSize", - &GaiaScreenHandler::HandleUpdateOobeDialogSize); AddCallback("hideOobeDialog", &GaiaScreenHandler::HandleHideOobeDialog); AddCallback("updateSigninUIState", &GaiaScreenHandler::HandleUpdateSigninUIState); @@ -732,6 +766,14 @@ void GaiaScreenHandler::HandleWebviewLoadAborted(int error_code) { << net::ErrorToShortString(error_code); return; } + if (error_code == net::ERR_TIMED_OUT && + is_security_token_pin_dialog_running()) { + // Timeout errors are expected when the security token PIN is not entered by + // the user on time. In that case, return the user back to the first sign-in + // step instead of showing the network error screen. + ReloadGaia(/*force_reload=*/true); + return; + } frame_error_ = static_cast<net::Error>(error_code); LOG(ERROR) << "Gaia webview error: " << net::ErrorToShortString(error_code); @@ -848,9 +890,8 @@ void GaiaScreenHandler::HandleCompleteAuthentication( if (!partition) return; - net::CookieOptions cookie_options; - cookie_options.set_include_httponly(); - + const net::CookieOptions cookie_options = + net::CookieOptions::MakeAllInclusive(); partition->GetCookieManagerForBrowserProcess()->GetCookieList( GaiaUrls::GetInstance()->gaia_url(), cookie_options, base::BindOnce(&GaiaScreenHandler::OnGetCookiesForCompleteAuthentication, @@ -911,15 +952,17 @@ void GaiaScreenHandler::HandleCompleteLogin(const std::string& gaia_id, SamlPasswordAttributes()); } -void GaiaScreenHandler::HandleUsingSAMLAPI() { - SetSAMLPrincipalsAPIUsed(true); +void GaiaScreenHandler::HandleUsingSAMLAPI(bool is_third_party_idp) { + SetSAMLPrincipalsAPIUsed(is_third_party_idp, /*is_api_used=*/true); } void GaiaScreenHandler::HandleScrapedPasswordCount(int password_count) { - SetSAMLPrincipalsAPIUsed(false); + // We are handling scraped passwords here so this is SAML flow without + // Chrome Credentials Passing API + SetSAMLPrincipalsAPIUsed(/*is_third_party_idp=*/true, /*is_api_used=*/false); // Use a histogram that has 11 buckets, one for each of the values in [0, 9] // and an overflow bucket at the end. - UMA_HISTOGRAM_ENUMERATION("ChromeOS.SAML.Scraping.PasswordCount", + UMA_HISTOGRAM_ENUMERATION("ChromeOS.SAML.Scraping.PasswordCountAll", std::min(password_count, 10), 11); if (password_count == 0) HandleScrapedPasswordVerificationFailed(); @@ -954,11 +997,6 @@ void GaiaScreenHandler::HandleGaiaUIReady() { } } -void GaiaScreenHandler::HandleUpdateOobeDialogSize(int width, int height) { - if (LoginDisplayHost::default_host()) - LoginDisplayHost::default_host()->UpdateOobeDialogSize(width, height); -} - void GaiaScreenHandler::HandleHideOobeDialog() { if (LoginDisplayHost::default_host()) LoginDisplayHost::default_host()->HideOobeDialog(); @@ -1028,7 +1066,7 @@ void GaiaScreenHandler::HandleSecurityTokenPinEntered( DCHECK(!security_token_pin_entered_callback_ || security_token_pin_dialog_closed_callback_); - if (!security_token_pin_dialog_closed_callback_) { + if (!is_security_token_pin_dialog_running()) { // The PIN request has already been canceled on the handler side. return; } @@ -1178,9 +1216,12 @@ void GaiaScreenHandler::SubmitLoginFormForTest() { // if they are cleared here. } -void GaiaScreenHandler::SetSAMLPrincipalsAPIUsed(bool api_used) { - using_saml_api_ = api_used; - UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.APIUsed", api_used); +void GaiaScreenHandler::SetSAMLPrincipalsAPIUsed(bool is_third_party_idp, + bool is_api_used) { + using_saml_api_ = is_api_used; + // This correctly records the standard GAIA login and SAML flow + // with Chrome Credentials Passing API used/not used + RecordAPILogin(is_third_party_idp, is_api_used); } void GaiaScreenHandler::ShowGaiaAsync(const AccountId& account_id) { diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h b/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h index 9cba09d99ff..a1e7df1b651 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h @@ -39,6 +39,7 @@ class Key; class SamlPasswordAttributes; class SigninScreenHandler; class UserContext; +class PublicSamlUrlFetcher; class GaiaView { public: @@ -212,7 +213,9 @@ class GaiaScreenHandler : public BaseScreenHandler, void HandleCancelActiveDirectoryAuth(); - void HandleUsingSAMLAPI(); + // Handles SAML/GAIA login flow metrics + // is_third_party_idp == false means GAIA-based authentication + void HandleUsingSAMLAPI(bool is_third_party_idp); void HandleScrapedPasswordCount(int password_count); void HandleScrapedPasswordVerificationFailed(); @@ -221,7 +224,6 @@ class GaiaScreenHandler : public BaseScreenHandler, void HandleIdentifierEntered(const std::string& account_identifier); void HandleAuthExtensionLoaded(); - void HandleUpdateOobeDialogSize(int width, int height); void HandleHideOobeDialog(); void HandleShowAddUser(const base::ListValue* args); void HandleGetIsSamlUserPasswordless(const std::string& callback_id, @@ -271,8 +273,8 @@ class GaiaScreenHandler : public BaseScreenHandler, void SubmitLoginFormForTest(); // Updates the member variable and UMA histogram indicating whether the - // principals API was used during SAML login. - void SetSAMLPrincipalsAPIUsed(bool api_used); + // Chrome Credentials Passing API was used during SAML login. + void SetSAMLPrincipalsAPIUsed(bool is_third_party_idp, bool is_api_used); // Cancels the request to show the sign-in screen while the asynchronous // clean-up process that precedes the screen showing is in progress. @@ -326,6 +328,10 @@ class GaiaScreenHandler : public BaseScreenHandler, UserContext* user_context, std::string* error_message); + bool is_security_token_pin_dialog_running() const { + return !security_token_pin_dialog_closed_callback_.is_null(); + } + // Current state of Gaia frame. FrameState frame_state_ = FRAME_STATE_UNKNOWN; @@ -365,12 +371,9 @@ class GaiaScreenHandler : public BaseScreenHandler, // The active network at the moment when Gaia page was preloaded. std::string gaia_silent_load_network_; - // If the user authenticated via SAML, this indicates whether the principals - // API was used. - // TODO(emaxx): This is also currently set when the user authenticated via - // Gaia, since Gaia uses the same API for passing the password to Chrome. - // Either fix this behavior, or change the naming and the comments to reflect - // it. + // This flag is set when user authenticated using the Chrome Credentials + // Passing API (the login could happen via SAML or, with the current + // server-side implementation, via Gaia). bool using_saml_api_ = false; // Test credentials. @@ -414,6 +417,8 @@ class GaiaScreenHandler : public BaseScreenHandler, std::unique_ptr<LoginClientCertUsageObserver> extension_provided_client_cert_usage_observer_; + std::unique_ptr<chromeos::PublicSamlUrlFetcher> public_saml_url_fetcher_; + // State of the security token PIN dialogs: // Whether this instance is currently registered as a host for showing the diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc b/chromium/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc index e990f0f0868..d26b46a9c28 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/network_state_informer.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/logging.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/chromeos/login/screens/network_error.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chromeos/network/network_state.h" diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.cc b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.cc index 0b45e2d2f8f..818c818751e 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.cc @@ -18,7 +18,6 @@ #include "services/service_manager/public/cpp/connector.h" #include "ui/display/display.h" #include "ui/display/screen.h" -#include "ui/events/devices/device_data_manager.h" #include "ui/events/devices/touchscreen_device.h" using content::BrowserThread; @@ -42,12 +41,12 @@ bool IsWhiteListedVendorId(uint16_t vendor_id) { } // namespace -OobeDisplayChooser::OobeDisplayChooser() : scoped_observer_(this) { +OobeDisplayChooser::OobeDisplayChooser() { // |connector| may be null in tests. auto* connector = content::GetSystemConnector(); if (connector) { - connector->BindInterface(ash::mojom::kServiceName, - &cros_display_config_ptr_); + connector->Connect(ash::mojom::kServiceName, + cros_display_config_.BindNewPipeAndPassReceiver()); } } @@ -95,7 +94,7 @@ void OobeDisplayChooser::MoveToTouchDisplay() { device.target_display_id != display::kInvalidDisplayId) { auto config_properties = ash::mojom::DisplayConfigProperties::New(); config_properties->set_primary = true; - cros_display_config_ptr_->SetDisplayProperties( + cros_display_config_->SetDisplayProperties( base::NumberToString(device.target_display_id), std::move(config_properties), ash::mojom::DisplayConfigSource::kUser, base::DoNothing()); diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h index 555050c7f87..fc9cf2a9e22 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h @@ -9,6 +9,9 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/scoped_observer.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/remote.h" +#include "ui/events/devices/device_data_manager.h" #include "ui/events/devices/input_device_event_observer.h" namespace ui { @@ -26,9 +29,10 @@ class OobeDisplayChooser : public ui::InputDeviceEventObserver { // Must be called on the BrowserThread::UI thread. void TryToPlaceUiOnTouchDisplay(); - void set_cros_display_config_ptr_for_test( - ash::mojom::CrosDisplayConfigControllerPtr cros_display_config_ptr) { - cros_display_config_ptr_ = std::move(cros_display_config_ptr); + void set_cros_display_config_for_test( + mojo::PendingRemote<ash::mojom::CrosDisplayConfigController> + cros_display_config) { + cros_display_config_.Bind(std::move(cros_display_config)); } private: @@ -44,8 +48,8 @@ class OobeDisplayChooser : public ui::InputDeviceEventObserver { void OnDeviceListsComplete() override; ScopedObserver<ui::DeviceDataManager, ui::InputDeviceEventObserver> - scoped_observer_; - ash::mojom::CrosDisplayConfigControllerPtr cros_display_config_ptr_; + scoped_observer_{this}; + mojo::Remote<ash::mojom::CrosDisplayConfigController> cros_display_config_; base::WeakPtrFactory<OobeDisplayChooser> weak_ptr_factory_{this}; diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc index 2fd04181e8a..407ca745758 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc @@ -8,11 +8,14 @@ #include <vector> #include "ash/display/display_configuration_controller.h" +#include "ash/public/mojom/cros_display_config.mojom.h" #include "ash/shell.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "chrome/test/base/chrome_ash_test_base.h" -#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/public/cpp/bindings/pending_associated_remote.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/receiver.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/display/display.h" #include "ui/display/display_observer.h" @@ -29,17 +32,17 @@ namespace { class TestCrosDisplayConfig : public ash::mojom::CrosDisplayConfigController { public: - TestCrosDisplayConfig() : binding_(this) {} + TestCrosDisplayConfig() = default; - ash::mojom::CrosDisplayConfigControllerPtr CreateInterfacePtrAndBind() { - ash::mojom::CrosDisplayConfigControllerPtr ptr; - binding_.Bind(mojo::MakeRequest(&ptr)); - return ptr; + mojo::PendingRemote<ash::mojom::CrosDisplayConfigController> + CreateRemoteAndBind() { + return receiver_.BindNewPipeAndPassRemote(); } // ash::mojom::CrosDisplayConfigController: - void AddObserver(ash::mojom::CrosDisplayConfigObserverAssociatedPtrInfo - observer) override {} + void AddObserver( + mojo::PendingAssociatedRemote<ash::mojom::CrosDisplayConfigObserver> + observer) override {} void GetDisplayLayoutInfo(GetDisplayLayoutInfoCallback callback) override {} void SetDisplayLayoutInfo(ash::mojom::DisplayLayoutInfoPtr info, SetDisplayLayoutInfoCallback callback) override {} @@ -69,7 +72,7 @@ class TestCrosDisplayConfig : public ash::mojom::CrosDisplayConfigController { TouchCalibrationCallback callback) override {} private: - mojo::Binding<ash::mojom::CrosDisplayConfigController> binding_; + mojo::Receiver<ash::mojom::CrosDisplayConfigController> receiver_{this}; DISALLOW_COPY_AND_ASSIGN(TestCrosDisplayConfig); }; @@ -88,8 +91,8 @@ class OobeDisplayChooserTest : public ChromeAshTestBase { cros_display_config_ = std::make_unique<TestCrosDisplayConfig>(); display_chooser_ = std::make_unique<OobeDisplayChooser>(); - display_chooser_->set_cros_display_config_ptr_for_test( - cros_display_config_->CreateInterfacePtrAndBind()); + display_chooser_->set_cros_display_config_for_test( + cros_display_config_->CreateRemoteAndBind()); ui::DeviceDataManagerTestApi().OnDeviceListsComplete(); } diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc index 67f444cbacd..6d8e7ade583 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc @@ -90,6 +90,7 @@ #include "chrome/grit/component_extension_resources.h" #include "chromeos/constants/chromeos_switches.h" #include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h" +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" // nogncheck #include "components/policy/core/common/cloud/cloud_policy_constants.h" #include "components/prefs/pref_service.h" #include "content/public/browser/browser_context.h" @@ -490,20 +491,23 @@ service_manager::Connector* OobeUI::GetLoggedInUserMojoConnector() { } void OobeUI::BindMultiDeviceSetup( - multidevice_setup::mojom::MultiDeviceSetupRequest request) { - GetLoggedInUserMojoConnector()->BindInterface( - multidevice_setup::mojom::kServiceName, std::move(request)); + mojo::PendingReceiver<multidevice_setup::mojom::MultiDeviceSetup> + receiver) { + GetLoggedInUserMojoConnector()->Connect( + multidevice_setup::mojom::kServiceName, std::move(receiver)); } void OobeUI::BindPrivilegedHostDeviceSetter( - multidevice_setup::mojom::PrivilegedHostDeviceSetterRequest request) { - GetLoggedInUserMojoConnector()->BindInterface( - multidevice_setup::mojom::kServiceName, std::move(request)); + mojo::PendingReceiver<multidevice_setup::mojom::PrivilegedHostDeviceSetter> + receiver) { + GetLoggedInUserMojoConnector()->Connect( + multidevice_setup::mojom::kServiceName, std::move(receiver)); } void OobeUI::BindCrosNetworkConfig( - chromeos::network_config::mojom::CrosNetworkConfigRequest request) { - ash::GetNetworkConfigService(std::move(request)); + mojo::PendingReceiver<chromeos::network_config::mojom::CrosNetworkConfig> + receiver) { + ash::GetNetworkConfigService(std::move(receiver)); } OobeUI::OobeUI(content::WebUI* web_ui, const GURL& url) @@ -622,7 +626,7 @@ void OobeUI::CurrentScreenChanged(OobeScreenId new_screen) { current_screen_ = new_screen; for (Observer& observer : observer_list_) - observer.OnCurrentScreenChanged(current_screen_, new_screen); + observer.OnCurrentScreenChanged(previous_screen_, new_screen); } bool OobeUI::IsScreenInitialized(OobeScreenId screen) { diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.h b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.h index 84dc0d2d4ca..cb1f0565315 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/oobe_ui.h @@ -18,7 +18,8 @@ #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" #include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h" #include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h" -#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" // nogncheck +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h" // nogncheck +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/webui/mojo_web_ui_controller.h" namespace base { @@ -156,14 +157,17 @@ class OobeUI : public ui::MojoWebUIController { // display type. void ConfigureOobeDisplay(); - // Adds Mojo bindings for this WebUIController. + // Adds Mojo receivers for this WebUIController. service_manager::Connector* GetLoggedInUserMojoConnector(); void BindMultiDeviceSetup( - multidevice_setup::mojom::MultiDeviceSetupRequest request); + mojo::PendingReceiver<multidevice_setup::mojom::MultiDeviceSetup> + receiver); void BindPrivilegedHostDeviceSetter( - multidevice_setup::mojom::PrivilegedHostDeviceSetterRequest request); + mojo::PendingReceiver< + multidevice_setup::mojom::PrivilegedHostDeviceSetter> receiver); void BindCrosNetworkConfig( - chromeos::network_config::mojom::CrosNetworkConfigRequest request); + mojo::PendingReceiver<chromeos::network_config::mojom::CrosNetworkConfig> + receiver); // Type of UI. std::string display_type_; diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/recommend_apps_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/recommend_apps_screen_handler.cc index d8a5fa15e43..c88297b01a0 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/recommend_apps_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/recommend_apps_screen_handler.cc @@ -5,7 +5,7 @@ #include "chrome/browser/ui/webui/chromeos/login/recommend_apps_screen_handler.h" #include "base/metrics/histogram_macros.h" -#include "chrome/browser/chromeos/arc/arc_session_manager.h" +#include "chrome/browser/chromeos/arc/session/arc_session_manager.h" #include "chrome/browser/chromeos/login/screens/recommend_apps_screen.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc index aa0e6206df5..2e34b2bb0c8 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc @@ -101,6 +101,8 @@ #include "content/public/browser/notification_source.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" +#include "extensions/browser/api/extensions_api_client.h" +#include "extensions/browser/api/feedback_private/feedback_private_delegate.h" #include "google_apis/gaia/gaia_auth_util.h" #include "third_party/cros_system_api/dbus/service_constants.h" #include "ui/base/ime/chromeos/ime_keyboard.h" @@ -296,6 +298,13 @@ SigninScreenHandler::~SigninScreenHandler() { network_state_informer_->RemoveObserver(this); proximity_auth::ScreenlockBridge::Get()->SetLockHandler(nullptr); proximity_auth::ScreenlockBridge::Get()->SetFocusedUser(EmptyAccountId()); + // TODO(https://crbug.com/1033572) Quick fix to close feedback form when login + // was performed. + login_feedback_.reset(); + extensions::FeedbackPrivateDelegate* feedback_private_delegate = + extensions::ExtensionsAPIClient::Get()->GetFeedbackPrivateDelegate(); + feedback_private_delegate->UnloadFeedbackExtension( + Profile::FromWebUI(web_ui())); } void SigninScreenHandler::DeclareLocalizedValues( diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/supervision_transition_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/supervision_transition_screen_handler.cc index 3542f432e78..311bd578880 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/supervision_transition_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/supervision_transition_screen_handler.cc @@ -9,8 +9,8 @@ #include "base/logging.h" #include "base/metrics/histogram_macros.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_util.h" +#include "chrome/browser/chromeos/arc/session/arc_session_manager.h" #include "chrome/browser/chromeos/login/oobe_screen.h" #include "chrome/browser/chromeos/login/screens/supervision_transition_screen.h" #include "chrome/browser/profiles/profile_manager.h" diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.cc index 1a557a318c5..d02af35140b 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.cc @@ -12,6 +12,9 @@ #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" #include "components/login/localized_values_builder.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/chromeos/devicetype_utils.h" +#include "ui/strings/grit/ui_strings.h" namespace chromeos { @@ -20,6 +23,7 @@ constexpr StaticOobeScreenId UpdateRequiredView::kScreenId; UpdateRequiredScreenHandler::UpdateRequiredScreenHandler( JSCallsContainer* js_calls_container) : BaseScreenHandler(kScreenId, js_calls_container) { + set_user_acted_method_path("login.UpdateRequiredScreen.userActed"); } UpdateRequiredScreenHandler::~UpdateRequiredScreenHandler() { @@ -31,6 +35,35 @@ void UpdateRequiredScreenHandler::DeclareLocalizedValues( ::login::LocalizedValuesBuilder* builder) { builder->Add("updateRequiredMessage", IDS_UPDATE_REQUIRED_LOGIN_SCREEN_MESSAGE); + builder->Add("errorMessage", + IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_INTERNAL_ERROR); + builder->Add("eolMessage", + ui::SubstituteChromeOSDeviceType(IDS_EOL_NOTIFICATION_EOL)); + builder->Add("selectNetworkButtonCaption", IDS_APP_START_CONFIGURE_NETWORK); + builder->Add("updateButtonCaption", + IDS_SETTINGS_ABOUT_PAGE_CHECK_FOR_UPDATES); + builder->Add("rebootNeededMessage", IDS_UPDATE_COMPLETED); + + builder->Add("checkingForUpdatesTitle", IDS_CHECKING_FOR_UPDATES); + builder->Add("updatingTitle", IDS_UPDATING_SCREEN_TITLE); + + builder->Add("downloading", IDS_DOWNLOADING); + builder->Add("downloadingTimeLeftLong", IDS_DOWNLOADING_TIME_LEFT_LONG); + builder->Add("downloadingTimeLeftStatusOneHour", + IDS_DOWNLOADING_TIME_LEFT_STATUS_ONE_HOUR); + builder->Add("downloadingTimeLeftStatusMinutes", + IDS_DOWNLOADING_TIME_LEFT_STATUS_MINUTES); + builder->Add("downloadingTimeLeftSmall", IDS_DOWNLOADING_TIME_LEFT_SMALL); + + builder->Add( + "updateOverCellularPromptTitle", + ui::SubstituteChromeOSDeviceType(IDS_UPDATE_OVER_CELLULAR_PROMPT_TITLE)); + builder->Add("updateOverCellularPromptMessage", + IDS_UPDATE_OVER_CELLULAR_PROMPT_MESSAGE); + builder->Add("AcceptUpdateOverCellularButton", + IDS_OFFERS_CONSENT_INFOBAR_ENABLE_BUTTON); + builder->Add("RejectUpdateOverCellularButton", + IDS_OFFERS_CONSENT_INFOBAR_DISABLE_BUTTON); } void UpdateRequiredScreenHandler::Initialize() { @@ -60,4 +93,36 @@ void UpdateRequiredScreenHandler::Unbind() { BaseScreenHandler::SetBaseScreen(nullptr); } +void UpdateRequiredScreenHandler::SetIsConnected(bool connected) { + CallJS("login.UpdateRequiredScreen.setIsConnected", connected); +} + +void UpdateRequiredScreenHandler::SetUpdateProgressUnavailable( + bool unavailable) { + CallJS("login.UpdateRequiredScreen.setUpdateProgressUnavailable", + unavailable); +} + +void UpdateRequiredScreenHandler::SetUpdateProgressValue(int progress) { + CallJS("login.UpdateRequiredScreen.setUpdateProgressValue", progress); +} + +void UpdateRequiredScreenHandler::SetUpdateProgressMessage( + const base::string16& message) { + CallJS("login.UpdateRequiredScreen.setUpdateProgressMessage", message); +} + +void UpdateRequiredScreenHandler::SetEstimatedTimeLeftVisible(bool visible) { + CallJS("login.UpdateRequiredScreen.setEstimatedTimeLeftVisible", visible); +} + +void UpdateRequiredScreenHandler::SetEstimatedTimeLeft(int seconds_left) { + CallJS("login.UpdateRequiredScreen.setEstimatedTimeLeft", seconds_left); +} + +void UpdateRequiredScreenHandler::SetUIState( + UpdateRequiredView::UIState ui_state) { + CallJS("login.UpdateRequiredScreen.setUIState", static_cast<int>(ui_state)); +} + } // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.h b/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.h index 7a194338521..cd52e9f012d 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/login/update_required_screen_handler.h @@ -21,6 +21,16 @@ class UpdateRequiredScreen; class UpdateRequiredView { public: + enum UIState { + UPDATE_REQUIRED_MESSAGE = 0, // 'System update required' message. + UPDATE_PROCESS, // Update is going on. + UPDATE_NEED_PERMISSION, // Need user's permission to proceed. + UPDATE_COMPLETED_NEED_REBOOT, // Update successful, manual reboot is + // needed. + UPDATE_ERROR, // An error has occurred. + EOL // End of Life message. + }; + constexpr static StaticOobeScreenId kScreenId{"update-required"}; virtual ~UpdateRequiredView() {} @@ -36,6 +46,21 @@ class UpdateRequiredView { // Unbinds the screen from the view. virtual void Unbind() = 0; + + // Is device connected to some network? + virtual void SetIsConnected(bool connected) = 0; + // Is progress unavailable (e.g. we are checking for updates)? + virtual void SetUpdateProgressUnavailable(bool unavailable) = 0; + // Set progress percentage. + virtual void SetUpdateProgressValue(int progress) = 0; + // Set progress message (like "Verifying"). + virtual void SetUpdateProgressMessage(const base::string16& message) = 0; + // Set the visibility of the estimated time left. + virtual void SetEstimatedTimeLeftVisible(bool visible) = 0; + // Set the estimated time left, in seconds. + virtual void SetEstimatedTimeLeft(int seconds_left) = 0; + // Set the UI state of the screen. + virtual void SetUIState(UpdateRequiredView::UIState ui_state) = 0; }; class UpdateRequiredScreenHandler : public UpdateRequiredView, @@ -52,6 +77,14 @@ class UpdateRequiredScreenHandler : public UpdateRequiredView, void Bind(UpdateRequiredScreen* screen) override; void Unbind() override; + void SetIsConnected(bool connected) override; + void SetUpdateProgressUnavailable(bool unavailable) override; + void SetUpdateProgressValue(int progress) override; + void SetUpdateProgressMessage(const base::string16& message) override; + void SetEstimatedTimeLeftVisible(bool visible) override; + void SetEstimatedTimeLeft(int seconds_left) override; + void SetUIState(UpdateRequiredView::UIState ui_state) override; + // BaseScreenHandler: void DeclareLocalizedValues( ::login::LocalizedValuesBuilder* builder) override; diff --git a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.cc index f648d2f70a1..673d8f6352a 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.cc @@ -14,18 +14,18 @@ namespace chromeos { namespace machine_learning { MachineLearningInternalsPageHandler::MachineLearningInternalsPageHandler( - mojom::PageHandlerRequest request) - : binding_(this, std::move(request)) {} + mojo::PendingReceiver<mojom::PageHandler> receiver) + : receiver_(this, std::move(receiver)) {} MachineLearningInternalsPageHandler::~MachineLearningInternalsPageHandler() = default; -void MachineLearningInternalsPageHandler::LoadModel( - mojom::ModelSpecPtr spec, - mojom::ModelRequest request, - LoadModelCallback callback) { - ServiceConnection::GetInstance()->LoadModel( - std::move(spec), std::move(request), std::move(callback)); +void MachineLearningInternalsPageHandler::LoadBuiltinModel( + mojom::BuiltinModelSpecPtr spec, + mojo::PendingReceiver<mojom::Model> receiver, + LoadBuiltinModelCallback callback) { + ServiceConnection::GetInstance()->LoadBuiltinModel( + std::move(spec), std::move(receiver), std::move(callback)); } } // namespace machine_learning diff --git a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.h b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.h index afa6d61da03..70c4e963839 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.h +++ b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.h @@ -9,7 +9,8 @@ #include "chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.mojom.h" #include "chromeos/services/machine_learning/public/mojom/machine_learning_service.mojom.h" #include "chromeos/services/machine_learning/public/mojom/model.mojom.h" -#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/receiver.h" namespace chromeos { namespace machine_learning { @@ -19,16 +20,16 @@ namespace machine_learning { class MachineLearningInternalsPageHandler : public mojom::PageHandler { public: explicit MachineLearningInternalsPageHandler( - mojom::PageHandlerRequest request); + mojo::PendingReceiver<mojom::PageHandler> receiver); ~MachineLearningInternalsPageHandler() override; private: // mojom::PageHandler: - void LoadModel(mojom::ModelSpecPtr spec, - mojom::ModelRequest request, - LoadModelCallback callback) override; + void LoadBuiltinModel(mojom::BuiltinModelSpecPtr spec, + mojo::PendingReceiver<mojom::Model> receiver, + LoadBuiltinModelCallback callback) override; - mojo::Binding<mojom::PageHandler> binding_; + mojo::Receiver<mojom::PageHandler> receiver_; DISALLOW_COPY_AND_ASSIGN(MachineLearningInternalsPageHandler); }; diff --git a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.mojom b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.mojom index 3e56bc185cf..84a76d05dc2 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.mojom +++ b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.mojom @@ -9,7 +9,8 @@ import "chromeos/services/machine_learning/public/mojom/model.mojom"; import "chromeos/services/machine_learning/public/mojom/graph_executor.mojom"; interface PageHandler { - // Loads the specified model by forwarding it to Chrome OS ML Service. - LoadModel(ModelSpec spec, Model& request) => (LoadModelResult result); + // Loads the specified builtin model by forwarding it to Chrome OS ML + // Service. + LoadBuiltinModel(BuiltinModelSpec spec, pending_receiver<Model> receiver) + => (LoadModelResult result); }; - diff --git a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.cc index 09f00e14b09..18ff22fb323 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.h" +#include <memory> #include <utility> #include "chrome/browser/profiles/profile.h" @@ -56,9 +57,9 @@ MachineLearningInternalsUI::MachineLearningInternalsUI( MachineLearningInternalsUI::~MachineLearningInternalsUI() = default; void MachineLearningInternalsUI::BindMachineLearningInternalsPageHandler( - mojom::PageHandlerRequest request) { - page_handler_.reset( - new MachineLearningInternalsPageHandler(std::move(request))); + mojo::PendingReceiver<mojom::PageHandler> receiver) { + page_handler_ = std::make_unique<MachineLearningInternalsPageHandler>( + std::move(receiver)); } } // namespace machine_learning diff --git a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.h b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.h index 38517641176..da44a735e5f 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.h +++ b/chromium/chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_ui.h @@ -9,6 +9,7 @@ #include "base/macros.h" #include "chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.mojom.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/webui/mojo_web_ui_controller.h" namespace chromeos { @@ -24,7 +25,7 @@ class MachineLearningInternalsUI : public ui::MojoWebUIController { private: void BindMachineLearningInternalsPageHandler( - mojom::PageHandlerRequest request); + mojo::PendingReceiver<mojom::PageHandler> receiver); std::unique_ptr<MachineLearningInternalsPageHandler> page_handler_; diff --git a/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.cc b/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.cc index dc4915027ca..b01dc8a5e36 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.cc @@ -59,6 +59,12 @@ MultiDeviceSetupDialog* MultiDeviceSetupDialog::Get() { return current_instance_; } +// static +void MultiDeviceSetupDialog::SetInstanceForTesting( + MultiDeviceSetupDialog* instance) { + current_instance_ = instance; +} + void MultiDeviceSetupDialog::AddOnCloseCallback(base::OnceClosure callback) { on_close_callbacks_.push_back(std::move(callback)); } @@ -115,14 +121,15 @@ MultiDeviceSetupDialogUI::MultiDeviceSetupDialogUI(content::WebUI* web_ui) MultiDeviceSetupDialogUI::~MultiDeviceSetupDialogUI() = default; void MultiDeviceSetupDialogUI::BindMultiDeviceSetup( - chromeos::multidevice_setup::mojom::MultiDeviceSetupRequest request) { + mojo::PendingReceiver<chromeos::multidevice_setup::mojom::MultiDeviceSetup> + receiver) { service_manager::Connector* connector = content::BrowserContext::GetConnectorFor( web_ui()->GetWebContents()->GetBrowserContext()); DCHECK(connector); - connector->BindInterface(chromeos::multidevice_setup::mojom::kServiceName, - std::move(request)); + connector->Connect(chromeos::multidevice_setup::mojom::kServiceName, + std::move(receiver)); } } // namespace multidevice_setup diff --git a/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.h b/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.h index 422b8feeeac..e4671891542 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.h +++ b/chromium/chrome/browser/ui/webui/chromeos/multidevice_setup/multidevice_setup_dialog.h @@ -12,6 +12,7 @@ #include "base/macros.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" #include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/web_dialogs/web_dialog_ui.h" namespace chromeos { @@ -31,6 +32,8 @@ class MultiDeviceSetupDialog : public SystemWebDialogDelegate { // nullptr. static MultiDeviceSetupDialog* Get(); + static void SetInstanceForTesting(MultiDeviceSetupDialog* instance); + // Registers a callback which will be called when the dialog is closed. void AddOnCloseCallback(base::OnceClosure callback); @@ -59,7 +62,8 @@ class MultiDeviceSetupDialogUI : public ui::MojoWebDialogUI { private: void BindMultiDeviceSetup( - chromeos::multidevice_setup::mojom::MultiDeviceSetupRequest request); + mojo::PendingReceiver< + chromeos::multidevice_setup::mojom::MultiDeviceSetup> receiver); DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupDialogUI); }; diff --git a/chromium/chrome/browser/ui/webui/chromeos/network_element_localized_strings_provider.cc b/chromium/chrome/browser/ui/webui/chromeos/network_element_localized_strings_provider.cc index 2bea1501801..99c9df466f6 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/network_element_localized_strings_provider.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/network_element_localized_strings_provider.cc @@ -36,7 +36,9 @@ constexpr LocalizedString kElementLocalizedStrings[] = { {"networkListItemConnecting", IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING}, {"networkListItemConnectingTo", IDS_NETWORK_LIST_CONNECTING_TO}, {"networkListItemInitializing", IDS_NETWORK_LIST_INITIALIZING}, + {"networkListItemNotAvailable", IDS_NETWORK_LIST_NOT_AVAILABLE}, {"networkListItemScanning", IDS_SETTINGS_INTERNET_MOBILE_SEARCH}, + {"networkListItemSimCardLocked", IDS_NETWORK_LIST_SIM_CARD_LOCKED}, {"networkListItemNotConnected", IDS_NETWORK_LIST_NOT_CONNECTED}, {"networkListItemNoNetwork", IDS_NETWORK_LIST_NO_NETWORK}, {"vpnNameTemplate", IDS_NETWORK_LIST_THIRD_PARTY_VPN_NAME_TEMPLATE}, diff --git a/chromium/chrome/browser/ui/webui/chromeos/network_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/network_ui.cc index 6e1c9d1f886..53c1cfdcb95 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/network_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/network_ui.cc @@ -28,6 +28,7 @@ #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" #include "chromeos/network/onc/onc_utils.h" +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" #include "components/device_event_log/device_event_log.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/web_contents.h" @@ -44,6 +45,7 @@ namespace { constexpr char kAddNetwork[] = "addNetwork"; constexpr char kGetNetworkProperties[] = "getShillNetworkProperties"; constexpr char kGetDeviceProperties[] = "getShillDeviceProperties"; +constexpr char kGetEthernetEAP[] = "getShillEthernetEAP"; constexpr char kOpenCellularActivationUi[] = "openCellularActivationUi"; constexpr char kShowNetworkDetails[] = "showNetworkDetails"; constexpr char kShowNetworkConfig[] = "showNetworkConfig"; @@ -107,6 +109,10 @@ class NetworkConfigMessageHandler : public content::WebUIMessageHandler { &NetworkConfigMessageHandler::GetShillDeviceProperties, base::Unretained(this))); web_ui()->RegisterMessageCallback( + kGetEthernetEAP, + base::BindRepeating(&NetworkConfigMessageHandler::GetShillEthernetEAP, + base::Unretained(this))); + web_ui()->RegisterMessageCallback( kOpenCellularActivationUi, base::BindRepeating( &NetworkConfigMessageHandler::OpenCellularActivationUi, @@ -191,6 +197,28 @@ class NetworkConfigMessageHandler : public content::WebUIMessageHandler { weak_ptr_factory_.GetWeakPtr(), type, kGetDeviceProperties)); } + void GetShillEthernetEAP(const base::ListValue* arg_list) { + NetworkStateHandler::NetworkStateList list; + NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( + NetworkTypePattern::Primitive(shill::kTypeEthernetEap), + true /* configured_only */, false /* visible_only */, 1 /* limit */, + &list); + + AllowJavascript(); + if (list.empty()) { + CallJavascriptFunction( + base::StringPrintf("NetworkUI.%sResult", kGetEthernetEAP)); + return; + } + const NetworkState* eap = list.front(); + base::Value properties(base::Value::Type::DICTIONARY); + properties.SetStringKey("guid", eap->guid()); + properties.SetStringKey("name", eap->name()); + properties.SetStringKey("type", eap->type()); + CallJavascriptFunction( + base::StringPrintf("NetworkUI.%sResult", kGetEthernetEAP), properties); + } + void OpenCellularActivationUi(const base::ListValue* arg_list) { const NetworkState* cellular_network = NetworkHandler::Get()->network_state_handler()->FirstNetworkByType( @@ -252,12 +280,12 @@ class NetworkConfigMessageHandler : public content::WebUIMessageHandler { std::unique_ptr<base::DictionaryValue> /* error_data */) { NET_LOG(ERROR) << "Shill Error: " << error_name << " id=" << guid_or_type; base::ListValue return_arg_list; - std::unique_ptr<base::DictionaryValue> dictionary; + base::Value dictionary(base::Value::Type::DICTIONARY); std::string key = function_name == kGetDeviceProperties ? shill::kTypeProperty : shill::kGuidProperty; - dictionary->SetKey(key, base::Value(guid_or_type)); - dictionary->SetKey("ShillError", base::Value(error_name)); + dictionary.SetKey(key, base::Value(guid_or_type)); + dictionary.SetKey("ShillError", base::Value(error_name)); return_arg_list.Append(std::move(dictionary)); AllowJavascript(); @@ -325,6 +353,9 @@ void NetworkUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) { "favoriteNetworksLabel", l10n_util::GetStringUTF16(IDS_NETWORK_UI_FAVORITE_NETWORKS)); localized_strings->SetString( + "ethernetEapNetworkLabel", + l10n_util::GetStringUTF16(IDS_NETWORK_UI_ETHERNET_EAP)); + localized_strings->SetString( "devicesLabel", l10n_util::GetStringUTF16(IDS_NETWORK_UI_DEVICES)); localized_strings->SetString( @@ -376,8 +407,8 @@ NetworkUI::NetworkUI(content::WebUI* web_ui) NetworkUI::~NetworkUI() {} void NetworkUI::BindCrosNetworkConfig( - network_config::mojom::CrosNetworkConfigRequest request) { - ash::GetNetworkConfigService(std::move(request)); + mojo::PendingReceiver<network_config::mojom::CrosNetworkConfig> receiver) { + ash::GetNetworkConfigService(std::move(receiver)); } } // namespace chromeos diff --git a/chromium/chrome/browser/ui/webui/chromeos/network_ui.h b/chromium/chrome/browser/ui/webui/chromeos/network_ui.h index 4ed87901d96..a9eb0ab1919 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/network_ui.h +++ b/chromium/chrome/browser/ui/webui/chromeos/network_ui.h @@ -6,7 +6,8 @@ #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_NETWORK_UI_H_ #include "base/macros.h" -#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" +#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "ui/webui/mojo_web_ui_controller.h" namespace base { @@ -25,7 +26,7 @@ class NetworkUI : public ui::MojoWebUIController { private: void BindCrosNetworkConfig( - network_config::mojom::CrosNetworkConfigRequest request); + mojo::PendingReceiver<network_config::mojom::CrosNetworkConfig> receiver); DISALLOW_COPY_AND_ASSIGN(NetworkUI); }; diff --git a/chromium/chrome/browser/ui/webui/chromeos/set_time_ui.cc b/chromium/chrome/browser/ui/webui/chromeos/set_time_ui.cc index 1376878c1d8..f5ec12c71a5 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/set_time_ui.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/set_time_ui.cc @@ -33,6 +33,7 @@ #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_message_handler.h" +#include "ui/resources/grit/webui_resources.h" namespace chromeos { @@ -171,6 +172,8 @@ SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) { // Set up the chrome://set-time source. content::WebUIDataSource* source = content::WebUIDataSource::Create(chrome::kChromeUISetTimeHost); + source->OverrideContentSecurityPolicyScriptSrc( + "script-src chrome://resources chrome://test 'self';"); static constexpr LocalizedString kStrings[] = { {"setTimeTitle", IDS_SET_TIME_TITLE}, @@ -196,13 +199,15 @@ SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) { source->AddLocalizedStrings(values); source->UseStringsJs(); + source->EnableReplaceI18nInJS(); - source->AddResourcePath("set_time_browser_proxy.html", - IDR_SET_TIME_BROWSER_PROXY_HTML); source->AddResourcePath("set_time_browser_proxy.js", IDR_SET_TIME_BROWSER_PROXY_JS); source->AddResourcePath("set_time_dialog.js", IDR_SET_TIME_DIALOG_JS); - source->SetDefaultResource(IDR_SET_TIME_DIALOG_HTML); + source->SetDefaultResource(IDR_SET_TIME_HTML); + + source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER); + source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER); content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); } diff --git a/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.cc index 819e4fb6cf7..791c7954a88 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_handler.cc @@ -25,7 +25,7 @@ smb_client::SmbService* GetSmbService(Profile* profile) { base::Value BuildShareList(const std::vector<smb_client::SmbUrl>& shares) { base::Value shares_list(base::Value::Type::LIST); for (const auto& share : shares) { - shares_list.GetList().push_back(base::Value(share.GetWindowsUNCString())); + shares_list.Append(base::Value(share.GetWindowsUNCString())); } return shares_list; } diff --git a/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_shares_localized_strings_provider.cc b/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_shares_localized_strings_provider.cc index 4a50ff51a44..7270b116329 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_shares_localized_strings_provider.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/smb_shares/smb_shares_localized_strings_provider.cc @@ -44,6 +44,8 @@ void AddLocalizedStrings(content::WebUIDataSource* html_source) { IDS_SETTINGS_DOWNLOADS_SHARE_ADDED_MOUNT_INVALID_URL_MESSAGE}, {"smbShareAddedInvalidSSOURLMessage", IDS_SETTINGS_DOWNLOADS_SHARE_ADDED_MOUNT_INVALID_SSO_URL_MESSAGE}, + {"smbShareDiscoveryMessage", + IDS_SETTINGS_DOWNLOADS_ADD_SHARE_DISCOVERY_MESSAGE}, }; AddLocalizedStringsBulk(html_source, kLocalizedStrings, base::size(kLocalizedStrings)); diff --git a/chromium/chrome/browser/ui/webui/chromeos/sys_internals/sys_internals_message_handler.cc b/chromium/chrome/browser/ui/webui/chromeos/sys_internals/sys_internals_message_handler.cc index 23d28d7e47f..a5376d48f85 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/sys_internals/sys_internals_message_handler.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/sys_internals/sys_internals_message_handler.cc @@ -115,7 +115,7 @@ void SetCpusValue(const std::vector<CpuInfo>& infos, base::Value* result) { cpu_result.SetKey("kernel", base::Value(cpu.kernel)); cpu_result.SetKey("idle", base::Value(cpu.idle)); cpu_result.SetKey("total", base::Value(cpu.total)); - cpu_results.GetList().push_back(std::move(cpu_result)); + cpu_results.Append(std::move(cpu_result)); } result->SetKey("cpus", std::move(cpu_results)); } @@ -214,7 +214,7 @@ void SysInternalsMessageHandler::HandleGetSysInfo(const base::ListValue* args) { DCHECK(args); AllowJavascript(); - const base::Value::ListStorage& list = args->GetList(); + base::span<const base::Value> list = args->GetList(); if (list.size() != 1 || !list[0].is_string()) { NOTREACHED(); return; diff --git a/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_browsertest.cc b/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_browsertest.cc index ce3b17a3858..c23cac4ef3a 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_browsertest.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_browsertest.cc @@ -18,10 +18,10 @@ #include "components/account_id/account_id.h" #include "components/prefs/pref_service.h" #include "content/public/browser/render_view_host.h" -#include "content/public/common/page_zoom.h" #include "content/public/common/service_manager_connection.h" #include "content/public/common/web_preferences.h" #include "services/service_manager/public/cpp/connector.h" +#include "third_party/blink/public/common/page/page_zoom.h" #include "ui/aura/client/aura_constants.h" #include "url/gurl.h" @@ -99,14 +99,21 @@ IN_PROC_BROWSER_TEST_F(SystemWebDialogTest, InstanceTest) { // https://crbug.com/855344. } -IN_PROC_BROWSER_TEST_F(SystemWebDialogTest, FontSize) { +class SystemWebDialogTestWithSplitSettings : public SystemWebDialogTest { + public: + SystemWebDialogTestWithSplitSettings() { + feature_list_.InitAndEnableFeature(chromeos::features::kSplitSettings); + } + + private: + base::test::ScopedFeatureList feature_list_; +}; + +IN_PROC_BROWSER_TEST_F(SystemWebDialogTestWithSplitSettings, FontSize) { const content::WebPreferences kDefaultPrefs; const int kDefaultFontSize = kDefaultPrefs.default_font_size; const int kDefaultFixedFontSize = kDefaultPrefs.default_fixed_font_size; - base::test::ScopedFeatureList features; - features.InitAndEnableFeature(features::kSplitSettings); - // Set the browser font sizes to non-default values. PrefService* profile_prefs = browser()->profile()->GetPrefs(); profile_prefs->SetInteger(prefs::kWebKitDefaultFontSize, @@ -127,12 +134,9 @@ IN_PROC_BROWSER_TEST_F(SystemWebDialogTest, FontSize) { EXPECT_EQ(kDefaultFixedFontSize, dialog_prefs.default_fixed_font_size); } -IN_PROC_BROWSER_TEST_F(SystemWebDialogTest, PageZoom) { - base::test::ScopedFeatureList features; - features.InitAndEnableFeature(features::kSplitSettings); - +IN_PROC_BROWSER_TEST_F(SystemWebDialogTestWithSplitSettings, PageZoom) { // Set the default browser page zoom to 150%. - double level = content::ZoomFactorToZoomLevel(1.5); + double level = blink::PageZoomFactorToZoomLevel(1.5); browser()->profile()->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(level); // Open a system dialog. @@ -142,8 +146,8 @@ IN_PROC_BROWSER_TEST_F(SystemWebDialogTest, PageZoom) { // Dialog page zoom is still 100%. auto* web_contents = dialog->GetWebUIForTest()->GetWebContents(); double dialog_level = content::HostZoomMap::GetZoomLevel(web_contents); - EXPECT_TRUE(content::ZoomValuesEqual(dialog_level, - content::ZoomFactorToZoomLevel(1.0))) + EXPECT_TRUE(blink::PageZoomValuesEqual(dialog_level, + blink::PageZoomFactorToZoomLevel(1.0))) << dialog_level; } diff --git a/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.cc b/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.cc index ce6790a8ec3..23267bce02b 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.cc @@ -19,7 +19,7 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" -#include "content/public/common/page_zoom.h" +#include "third_party/blink/public/common/page/page_zoom.h" #include "ui/aura/window.h" namespace chromeos { @@ -137,7 +137,7 @@ void SystemWebDialogDelegate::OnDialogShown( // Temporary means the lifetime of the WebContents. zoom_map->SetTemporaryZoomLevel(rvh->GetProcess()->GetID(), rvh->GetRoutingID(), - content::ZoomFactorToZoomLevel(1.0)); + blink::PageZoomFactorToZoomLevel(1.0)); } } diff --git a/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc b/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc index 2609acbbbde..1bc97a1d760 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc +++ b/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc @@ -27,7 +27,11 @@ void ReadFile(const base::FilePath& path, const content::URLDataSource::GotDataCallback& callback) { std::string content; bool result = base::ReadFileToString(path, &content); - DCHECK(result) << path; + // Allow missing files in <root>/_locales only. + DCHECK(result || base::FilePath(kTerminalRoot) + .Append("_locales") + .AppendRelativePath(path, nullptr)) + << path; scoped_refptr<base::RefCountedString> response = base::RefCountedString::TakeString(&content); callback.Run(response.get()); @@ -38,6 +42,12 @@ std::string TerminalSource::GetSource() { return chrome::kChromeUITerminalHost; } +#if !BUILDFLAG(OPTIMIZE_WEBUI) +bool TerminalSource::AllowCaching() { + return false; +} +#endif + void TerminalSource::StartDataRequest( const std::string& path, const content::WebContents::Getter& wc_getter, @@ -61,3 +71,8 @@ std::string TerminalSource::GetMimeType(const std::string& path) { net::GetWellKnownMimeTypeFromExtension(ext.substr(1), &mime_type); return mime_type; } + +bool TerminalSource::ShouldServeMimeTypeAsContentTypeHeader() { + // TerminalSource pages include js modules which require an explicit MimeType. + return true; +} diff --git a/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h b/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h index b5acfdeb435..28e1fb9a1fc 100644 --- a/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h +++ b/chromium/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h @@ -8,6 +8,8 @@ #include <string> #include "base/macros.h" +#include "build/buildflag.h" +#include "chrome/common/buildflags.h" #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_contents.h" @@ -18,6 +20,9 @@ class TerminalSource : public content::URLDataSource { private: std::string GetSource() override; +#if !BUILDFLAG(OPTIMIZE_WEBUI) + bool AllowCaching() override; +#endif void StartDataRequest( const std::string& path, @@ -26,6 +31,8 @@ class TerminalSource : public content::URLDataSource { std::string GetMimeType(const std::string& path) override; + bool ShouldServeMimeTypeAsContentTypeHeader() override; + DISALLOW_COPY_AND_ASSIGN(TerminalSource); }; |