From 3a1ce1c3f9088343719d3761bb1a91d7d0e0c909 Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Wed, 16 Oct 2019 17:34:04 +0000 Subject: [PATCH] Reland "[DevUI DFM] Change install flow to use NavigationThrottle." This reverts commit 168860e0580de842b3a3ae9dda7dff376703c74c. Reason for reland: Fixed problem: The target source_set("dev_ui_loader") had missing dependencies, and doesn't reach. third_party/blink/public/mojom:mojom_platform Two ways to fix this are: A: Add the missing dependencies to chrome/browser/dev_ui/android:dev_ui_loader B: Remove chrome/browser/dev_ui/android:dev_ui_loader, and fold its {sources, deps} into chrome/browser:browser. We're choosing B for simplicity, but may adopt A eventually. Original change's description: > Revert "[DevUI DFM] Change install flow to use NavigationThrottle." > > Reason for revert: Seems to have broken android-archive-rel compile, though this may be exposing some pre-existing bad dependency elsewhere: https://ci.chromium.org/p/chromium/builders/ci/android-archive-rel/5717 > > Change-Id: I7eff36d7e01c31a76f39250a255d27972b0962d9 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864392 > Commit-Queue: Peter Kasting > Original change's description: > > [DevUI DFM] Change install flow to use NavigationThrottle. > > > > Bug: 927131,987040,1013522 > > Change-Id: I5c384671c858d26a303afc58c03f4314c8ef0117 > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1854524 > > Commit-Queue: Samuel Huang TBR=pkasting@chromium.org,creis@chromium.org,huangs@chromium.org,thestig@chromium.org,dbeam@chromium.org,agrieve@chromium.org,tiborg@chromium.org Bug: 927131, 987040, 1013522 Change-Id: I526f3194b0115171721a53fca60fa6ffa6e3c441 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864411 Reviewed-by: Samuel Huang Reviewed-by: Tibor Goldschwendt Reviewed-by: Lei Zhang Commit-Queue: Samuel Huang Cr-Commit-Position: refs/heads/master@{#706514} --- .../dev_ui/provider/dev_ui_module_provider.cc | 14 +- .../dev_ui/provider/dev_ui_module_provider.h | 11 +- chrome/browser/BUILD.gn | 11 +- .../android/dev_ui/dev_ui_url_handler.h | 33 -- chrome/browser/browser_resources.grd | 2 +- .../browser/chrome_content_browser_client.cc | 16 +- chrome/browser/dev_ui/OWNERS | 2 + .../{android/dev_ui => dev_ui/android}/DEPS | 0 .../android/dev_ui_loader_error_page.cc | 33 ++ .../dev_ui/android/dev_ui_loader_error_page.h | 16 + .../android/dev_ui_loader_throttle.cc} | 80 +++-- .../dev_ui/android/dev_ui_loader_throttle.h | 54 +++ .../dev_ui_loader_throttle_unittest.cc | 308 ++++++++++++++++++ .../dev_ui_loader_error.html} | 29 +- .../dev_ui_loader/dev_ui_loader.grdp | 6 - .../dev_ui_loader/dev_ui_loader.html | 22 -- .../resources/dev_ui_loader/dev_ui_loader.js | 51 --- .../dev_ui_loader_message_handler.cc | 68 ---- .../dev_ui_loader_message_handler.h | 61 ---- .../android/dev_ui_loader/dev_ui_loader_ui.cc | 30 -- .../android/dev_ui_loader/dev_ui_loader_ui.h | 32 -- .../webui/chrome_web_ui_controller_factory.cc | 20 -- chrome/common/webui_url_constants.cc | 1 - chrome/common/webui_url_constants.h | 1 - chrome/test/BUILD.gn | 4 + ui/strings/ui_strings.grd | 13 + 26 files changed, 538 insertions(+), 380 deletions(-) delete mode 100644 chrome/browser/android/dev_ui/dev_ui_url_handler.h create mode 100644 chrome/browser/dev_ui/OWNERS rename chrome/browser/{android/dev_ui => dev_ui/android}/DEPS (100%) create mode 100644 chrome/browser/dev_ui/android/dev_ui_loader_error_page.cc create mode 100644 chrome/browser/dev_ui/android/dev_ui_loader_error_page.h rename chrome/browser/{android/dev_ui/dev_ui_url_handler.cc => dev_ui/android/dev_ui_loader_throttle.cc} (65%) create mode 100644 chrome/browser/dev_ui/android/dev_ui_loader_throttle.h create mode 100644 chrome/browser/dev_ui/android/dev_ui_loader_throttle_unittest.cc rename chrome/browser/resources/{dev_ui_loader/dev_ui_loader.css => dev_ui/dev_ui_loader_error.html} (57%) delete mode 100644 chrome/browser/resources/dev_ui_loader/dev_ui_loader.grdp delete mode 100644 chrome/browser/resources/dev_ui_loader/dev_ui_loader.html delete mode 100644 chrome/browser/resources/dev_ui_loader/dev_ui_loader.js delete mode 100644 chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.cc delete mode 100644 chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.h delete mode 100644 chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.cc delete mode 100644 chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.h diff --git a/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.cc b/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.cc index 1879bbf14bf50f..4e2513730dc43d 100644 --- a/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.cc +++ b/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.cc @@ -12,16 +12,20 @@ namespace dev_ui { -// static -DevUiModuleProvider* DevUiModuleProvider::test_instance_ = nullptr; +namespace { + +// Global DevUiModuleProvider instance for testing. +DevUiModuleProvider* g_test_instance = nullptr; + +} // namespace // Destructor is public to enable management by std::unique_ptr<>. DevUiModuleProvider::~DevUiModuleProvider() = default; // static DevUiModuleProvider* DevUiModuleProvider::GetInstance() { - if (test_instance_) - return test_instance_; + if (g_test_instance) + return g_test_instance; static DevUiModuleProvider instance; return &instance; @@ -29,7 +33,7 @@ DevUiModuleProvider* DevUiModuleProvider::GetInstance() { // static void DevUiModuleProvider::SetTestInstance(DevUiModuleProvider* test_instance) { - test_instance_ = test_instance; + g_test_instance = test_instance; } bool DevUiModuleProvider::ModuleInstalled() { diff --git a/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.h b/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.h index c8eb037439c287..0f925d9381611f 100644 --- a/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.h +++ b/chrome/android/modules/dev_ui/provider/dev_ui_module_provider.h @@ -14,20 +14,20 @@ class DevUiModuleProvider { // Returns the singleton, which can be overridden using SetTestInstance(). static DevUiModuleProvider* GetInstance(); - // Overrides the singleton with caller-owned |test_instance|. Caller tests + // Overrides the singleton with caller-owned |test_instance|. Callers in tests // are responsible for resetting this to null on cleanup. static void SetTestInstance(DevUiModuleProvider* test_instance); - // Returns true if the DevUI module is installed. + // Returns true if the DevUI module is installed. Virtual to enable testing. virtual bool ModuleInstalled(); // Asynchronously requests to install the DevUI module. |on_complete| is // called after the module install is completed, and takes a bool to indicate - // whether module install is successful. + // whether module install is successful. Virtual to enable testing. virtual void InstallModule(base::OnceCallback on_complete); // Assuming that the DevUI module is installed, loads DevUI resources if not - // already loaded. + // already loaded. Virtual to enable testing. virtual void LoadModule(); protected: @@ -35,9 +35,6 @@ class DevUiModuleProvider { virtual ~DevUiModuleProvider(); DevUiModuleProvider(const DevUiModuleProvider&) = delete; DevUiModuleProvider& operator=(const DevUiModuleProvider&) = delete; - - private: - static DevUiModuleProvider* test_instance_; }; } // namespace dev_ui diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 1acf4d71a0ff41..0fa3cc141150cf 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -2911,13 +2911,12 @@ jumbo_split_static_library("browser") { } if (dfmify_dev_ui) { + # TODO(huangs): Extracting this to a separate target. sources += [ - "android/dev_ui/dev_ui_url_handler.cc", - "android/dev_ui/dev_ui_url_handler.h", - "ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.cc", - "ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.h", - "ui/webui/android/dev_ui_loader/dev_ui_loader_ui.cc", - "ui/webui/android/dev_ui_loader/dev_ui_loader_ui.h", + "dev_ui/android/dev_ui_loader_error_page.cc", + "dev_ui/android/dev_ui_loader_error_page.h", + "dev_ui/android/dev_ui_loader_throttle.cc", + "dev_ui/android/dev_ui_loader_throttle.h", ] deps += [ "//chrome/android/modules/dev_ui/provider:native" ] } diff --git a/chrome/browser/android/dev_ui/dev_ui_url_handler.h b/chrome/browser/android/dev_ui/dev_ui_url_handler.h deleted file mode 100644 index 6554bbe45f88b7..00000000000000 --- a/chrome/browser/android/dev_ui/dev_ui_url_handler.h +++ /dev/null @@ -1,33 +0,0 @@ -// 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_ANDROID_DEV_UI_DEV_UI_URL_HANDLER_H_ -#define CHROME_BROWSER_ANDROID_DEV_UI_DEV_UI_URL_HANDLER_H_ - -#include "build/build_config.h" -#include "chrome/android/features/dev_ui/buildflags.h" - -#if !defined(OS_ANDROID) || !BUILDFLAG(DFMIFY_DEV_UI) -#error Unsupported platform. -#endif - -class GURL; - -namespace content { -class BrowserContext; -} - -namespace chrome { -namespace android { - -// Handles chrome:// hosts for pages in the Developer UI Dynamic Feature Module -// (DevUI DFM). If not installed or not loaded, then replaces |url| with the -// chrome:// URL to the DevUI loader to install and load the DevUI DFM. -bool HandleDfmifiedDevUiPageURL(GURL* url, - content::BrowserContext* /* browser_context */); - -} // namespace android -} // namespace chrome - -#endif // CHROME_BROWSER_ANDROID_DEV_UI_DEV_UI_URL_HANDLER_H_ diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 43961e30884eab..b15a43825cb8c6 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -171,6 +171,7 @@ + @@ -187,7 +188,6 @@ - diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index d32f48c4edcac5..1f7f6bea4a2f88 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -415,7 +415,7 @@ #include "ui/base/resource/resource_bundle_android.h" #include "ui/base/ui_base_paths.h" #if BUILDFLAG(DFMIFY_DEV_UI) -#include "chrome/browser/android/dev_ui/dev_ui_url_handler.h" +#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h" #endif // BUILDFLAG(DFMIFY_DEV_UI) #elif defined(OS_POSIX) #include "chrome/browser/chrome_browser_main_posix.h" @@ -3349,12 +3349,6 @@ void ChromeContentBrowserClient::BrowserURLHandlerCreated( // Handler to rewrite chrome://newtab on Android. handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, BrowserURLHandler::null_handler()); -#if BUILDFLAG(DFMIFY_DEV_UI) - // Handler to rewrite chrome:// URLs in the DevUI DFM, if not installed. - handler->AddHandlerPair(&chrome::android::HandleDfmifiedDevUiPageURL, - BrowserURLHandler::null_handler()); -#endif // BUILDFLAG(DFMIFY_DEV_UI) - #else // defined(OS_ANDROID) // Handler to rewrite chrome://newtab for InstantExtended. handler->AddHandlerPair(&search::HandleNewTabURLRewrite, @@ -3832,6 +3826,14 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation( handle, navigation_interception::SynchronyMode::kAsync)); } throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle)); + +#if BUILDFLAG(DFMIFY_DEV_UI) + // If the DevUI DFM is already installed, then this is a no-op, except for the + // side effect of ensuring that the DevUI DFM is loaded. + MaybeAddThrottle(&throttles, + dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle)); +#endif // BUILDFLAG(DFMIFY_DEV_UI) + #elif BUILDFLAG(ENABLE_EXTENSIONS) if (handle->IsInMainFrame()) { // Redirect some navigations to apps that have registered matching URL diff --git a/chrome/browser/dev_ui/OWNERS b/chrome/browser/dev_ui/OWNERS new file mode 100644 index 00000000000000..1553f0ec2e55d4 --- /dev/null +++ b/chrome/browser/dev_ui/OWNERS @@ -0,0 +1,2 @@ +huangs@chromium.org +tiborg@chromium.org diff --git a/chrome/browser/android/dev_ui/DEPS b/chrome/browser/dev_ui/android/DEPS similarity index 100% rename from chrome/browser/android/dev_ui/DEPS rename to chrome/browser/dev_ui/android/DEPS diff --git a/chrome/browser/dev_ui/android/dev_ui_loader_error_page.cc b/chrome/browser/dev_ui/android/dev_ui_loader_error_page.cc new file mode 100644 index 00000000000000..cd1cc3d8f066bc --- /dev/null +++ b/chrome/browser/dev_ui/android/dev_ui_loader_error_page.cc @@ -0,0 +1,33 @@ +// 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/dev_ui/android/dev_ui_loader_error_page.h" + +#include "chrome/grit/browser_resources.h" +#include "components/strings/grit/components_strings.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/template_expressions.h" +#include "ui/strings/grit/ui_strings.h" + +namespace dev_ui { + +std::string BuildErrorPageHtml() { + ui::TemplateReplacements replacements; + replacements["h1"] = + l10n_util::GetStringUTF8(IDS_DEV_UI_LOADER_ERROR_HEADING); + replacements["p"] = + l10n_util::GetStringUTF8(IDS_ERRORPAGES_SUGGESTION_LIST_HEADER); + replacements["li-1"] = + l10n_util::GetStringUTF8(IDS_DEV_UI_LOADER_ERROR_SUGGEST_RELOAD); + replacements["li-2"] = + l10n_util::GetStringUTF8(IDS_DEV_UI_LOADER_ERROR_SUGGEST_CHECK_INTERNET); + + std::string source = + ui::ResourceBundle::GetSharedInstance().DecompressDataResource( + IDR_DEV_UI_LOADER_ERROR_HTML); + return ui::ReplaceTemplateExpressions(source, replacements); +} + +} // namespace dev_ui diff --git a/chrome/browser/dev_ui/android/dev_ui_loader_error_page.h b/chrome/browser/dev_ui/android/dev_ui_loader_error_page.h new file mode 100644 index 00000000000000..695cddd8b15969 --- /dev/null +++ b/chrome/browser/dev_ui/android/dev_ui_loader_error_page.h @@ -0,0 +1,16 @@ +// 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_DEV_UI_ANDROID_DEV_UI_LOADER_ERROR_PAGE_H_ +#define CHROME_BROWSER_DEV_UI_ANDROID_DEV_UI_LOADER_ERROR_PAGE_H_ + +#include + +namespace dev_ui { + +std::string BuildErrorPageHtml(); + +} // namespace dev_ui + +#endif // CHROME_BROWSER_DEV_UI_ANDROID_DEV_UI_LOADER_ERROR_PAGE_H_ diff --git a/chrome/browser/android/dev_ui/dev_ui_url_handler.cc b/chrome/browser/dev_ui/android/dev_ui_loader_throttle.cc similarity index 65% rename from chrome/browser/android/dev_ui/dev_ui_url_handler.cc rename to chrome/browser/dev_ui/android/dev_ui_loader_throttle.cc index a90b2906fc12e3..022b78c7a76360 100644 --- a/chrome/browser/android/dev_ui/dev_ui_url_handler.cc +++ b/chrome/browser/dev_ui/android/dev_ui_loader_throttle.cc @@ -2,15 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/android/dev_ui/dev_ui_url_handler.h" +#include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h" #include +#include +#include "base/logging.h" #include "chrome/android/modules/dev_ui/provider/dev_ui_module_provider.h" +#include "chrome/browser/dev_ui/android/dev_ui_loader_error_page.h" #include "chrome/common/webui_url_constants.h" #include "components/safe_browsing/web_ui/constants.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/navigation_handle.h" #include "content/public/common/url_constants.h" -#include "net/base/url_util.h" +#include "net/base/net_errors.h" #include "url/gurl.h" namespace { @@ -71,30 +76,65 @@ bool IsWebUiHostInDevUiDfm(const std::string& host) { } // namespace -namespace chrome { -namespace android { +namespace dev_ui { -bool HandleDfmifiedDevUiPageURL( - GURL* url, - content::BrowserContext* /* browser_context */) { - if (!url->SchemeIs(content::kChromeUIScheme) || - !IsWebUiHostInDevUiDfm(url->host())) { - return false; - } +// static +bool DevUiLoaderThrottle::ShouldInstallDevUiDfm(const GURL& url) { + return url.SchemeIs(content::kChromeUIScheme) && + IsWebUiHostInDevUiDfm(url.host()); +} + +// static +std::unique_ptr +DevUiLoaderThrottle::MaybeCreateThrottleFor(content::NavigationHandle* handle) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK(handle); + if (!handle->IsInMainFrame()) + return nullptr; + + if (!ShouldInstallDevUiDfm(handle->GetURL())) + return nullptr; // If module is already installed, ensure that it is loaded. if (dev_ui::DevUiModuleProvider::GetInstance()->ModuleInstalled()) { // Synchronously load module (if not already loaded). dev_ui::DevUiModuleProvider::GetInstance()->LoadModule(); - return false; + return nullptr; + } + + return std::make_unique(handle); +} + +DevUiLoaderThrottle::DevUiLoaderThrottle( + content::NavigationHandle* navigation_handle) + : content::NavigationThrottle(navigation_handle) {} + +DevUiLoaderThrottle::~DevUiLoaderThrottle() = default; + +const char* DevUiLoaderThrottle::GetNameForLogging() { + return "DevUiLoaderThrottle"; +} + +content::NavigationThrottle::ThrottleCheckResult +DevUiLoaderThrottle::WillStartRequest() { + if (!dev_ui::DevUiModuleProvider::GetInstance()->ModuleInstalled()) { + // Can handle multiple install requests. + dev_ui::DevUiModuleProvider::GetInstance()->InstallModule( + base::BindOnce(&DevUiLoaderThrottle::OnDevUiDfmInstallWithStatus, + weak_ptr_factory_.GetWeakPtr())); + return DEFER; + } + return PROCEED; +} + +void DevUiLoaderThrottle::OnDevUiDfmInstallWithStatus(bool success) { + if (success) { + dev_ui::DevUiModuleProvider::GetInstance()->LoadModule(); + Resume(); + } else { + std::string html = BuildErrorPageHtml(); + CancelDeferredNavigation({BLOCK_REQUEST, net::ERR_CONNECTION_FAILED, html}); } - // Create URL to the DevUI loader with "?url=" so that - // after install, the loader can redirect to the original URL. - *url = net::AppendQueryParameter( - GURL(std::string(kChromeUIDevUiLoaderURL) + "dev_ui_loader.html"), "url", - url->spec()); - return true; } -} // namespace android -} // namespace chrome +} // namespace dev_ui diff --git a/chrome/browser/dev_ui/android/dev_ui_loader_throttle.h b/chrome/browser/dev_ui/android/dev_ui_loader_throttle.h new file mode 100644 index 00000000000000..24c24071dbd901 --- /dev/null +++ b/chrome/browser/dev_ui/android/dev_ui_loader_throttle.h @@ -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. + +#ifndef CHROME_BROWSER_DEV_UI_ANDROID_DEV_UI_LOADER_THROTTLE_H_ +#define CHROME_BROWSER_DEV_UI_ANDROID_DEV_UI_LOADER_THROTTLE_H_ + +#include + +#include "base/memory/weak_ptr.h" +#include "content/public/browser/navigation_throttle.h" + +namespace content { +class NavigationHandle; +} // namespace content + +class GURL; + +namespace dev_ui { + +// For DevUI page navigations, if the DevUI DFM is not installed then delay +// navigation and perform installation. On success, resumes navigation. On +// failure, displays error (retries install on refresh). +class DevUiLoaderThrottle : public content::NavigationThrottle { + public: + // Determines whether visiting |url| should trigger DevUI DFM install. + static bool ShouldInstallDevUiDfm(const GURL& url); + + // Creates a throttle if the DevUI DFM needs to be installed. If the DevUI DFM + // will be used, is installed, but is not loaded, then resource load takes + // place as a side effect. + static std::unique_ptr MaybeCreateThrottleFor( + content::NavigationHandle* handle); + + explicit DevUiLoaderThrottle(content::NavigationHandle* navigation_handle); + ~DevUiLoaderThrottle() override; + DevUiLoaderThrottle(const DevUiLoaderThrottle&) = delete; + const DevUiLoaderThrottle& operator=(const DevUiLoaderThrottle&) = delete; + + // content::NavigationThrottle: + const char* GetNameForLogging() override; + ThrottleCheckResult WillStartRequest() override; + + private: + // Callback for dev_ui::DevUiModuleProvider::InstallModule(). + void OnDevUiDfmInstallWithStatus(bool success); + + // Factory for creating references in callbacks. + base::WeakPtrFactory weak_ptr_factory_{this}; +}; + +} // namespace dev_ui + +#endif // CHROME_BROWSER_DEV_UI_ANDROID_DEV_UI_LOADER_THROTTLE_H_ diff --git a/chrome/browser/dev_ui/android/dev_ui_loader_throttle_unittest.cc b/chrome/browser/dev_ui/android/dev_ui_loader_throttle_unittest.cc new file mode 100644 index 00000000000000..c4c76eefa3c01f --- /dev/null +++ b/chrome/browser/dev_ui/android/dev_ui_loader_throttle_unittest.cc @@ -0,0 +1,308 @@ +// 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/dev_ui/android/dev_ui_loader_throttle.h" + +#include +#include +#include + +#include "chrome/android/modules/dev_ui/provider/dev_ui_module_provider.h" +#include "chrome/test/base/chrome_render_view_host_test_harness.h" +#include "content/public/browser/navigation_handle.h" +#include "content/public/test/mock_navigation_handle.h" +#include "net/base/net_errors.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace dev_ui { + +namespace { + +const char* const kNonDevUiUrls[] = { + "https://example.com", + "https://example.com/path?query#frag", + "chrome://credits", + "chrome://credits/path?query#frag", +}; + +const char* const kDevUiUrls[] = { + "chrome://bluetooth-internals", + "chrome://bluetooth-internals/path?query#frag", +}; + +/******** MockDevUiModuleProvider ********/ + +// Mock DevUiModuleProvider that overrides the main module install / load +// functions, and provides SimulateAsyncInstall(). +class MockDevUiModuleProvider : public DevUiModuleProvider { + public: + MockDevUiModuleProvider() = default; + ~MockDevUiModuleProvider() override = default; + + // DevUiModuleProvider: + bool ModuleInstalled() override { return is_installed_; } + + // DevUiModuleProvider: + void InstallModule(base::OnceCallback on_complete) override { + on_complete_queue_.emplace_back(std::move(on_complete)); + } + + // DevUiModuleProvider: + void LoadModule() override { is_loaded_ = true; } + + void Reset() { + is_installed_ = false; + is_loaded_ = false; + on_complete_queue_.clear(); + } + + // Simulate DevUI DFN install, and dispatches all on-complete callbacks. + void SimulateAsyncInstall(bool install_succeeds) { + is_installed_ = is_installed_ || install_succeeds; + while (!on_complete_queue_.empty()) { + std::move(on_complete_queue_.front()).Run(install_succeeds); + on_complete_queue_.pop_front(); + } + } + + // Direct access of fake installation states. + void SetIsInstalled(bool is_installed) { is_installed_ = is_installed; } + bool GetIsInstalled() const { return is_installed_; } + void SetIsLoaded(bool is_loaded) { is_loaded_ = is_loaded; } + bool GetIsLoaded() const { return is_loaded_; } + + private: + bool is_installed_ = false; + bool is_loaded_ = false; + std::deque> on_complete_queue_; +}; + +/******** TestDevUiLoaderThrottle ********/ + +// DevUiLoaderThrottle that overrides and captures Resume() and +// CancelDeferredNavigation(). This is needed because: +// * In actual usage, both functions can lead to throttle deletion, which is +// problematic since the tests own the throttle instance. +// * We want to record results for verification. +// Note that this is instantiated directly, instead of using +// DevUiLoaderThrottle::MaybeCreateThrottleFor(). +class TestDevUiLoaderThrottle : public DevUiLoaderThrottle { + public: + explicit TestDevUiLoaderThrottle(content::NavigationHandle* navigation_handle) + : DevUiLoaderThrottle(navigation_handle), cancel_result(LAST) {} + ~TestDevUiLoaderThrottle() override = default; + TestDevUiLoaderThrottle(const TestDevUiLoaderThrottle&) = delete; + const TestDevUiLoaderThrottle& operator=(const TestDevUiLoaderThrottle&) = + delete; + + // content::NavigationThrottle: + void Resume() override { called_resume = true; } + + // content::NavigationThrottle: + void CancelDeferredNavigation( + content::NavigationThrottle::ThrottleCheckResult result) override { + called_cancel = true; + cancel_result = std::move(result); + } + + bool called_resume = false; + bool called_cancel = false; + content::NavigationThrottle::ThrottleCheckResult cancel_result; +}; + +/******** DevUiLoaderThrottleTest ********/ + +class DevUiLoaderThrottleTest : public ChromeRenderViewHostTestHarness { + public: + DevUiLoaderThrottleTest() = default; + ~DevUiLoaderThrottleTest() override = default; + DevUiLoaderThrottleTest(const DevUiLoaderThrottleTest&) = delete; + const DevUiLoaderThrottleTest& operator=(const DevUiLoaderThrottleTest&) = + delete; + + void SetUp() override { + ChromeRenderViewHostTestHarness::SetUp(); + DevUiModuleProvider::SetTestInstance(&mock_provider_); + } + + void TearDown() override { + mock_provider_.Reset(); + DevUiModuleProvider::SetTestInstance(nullptr); + ChromeRenderViewHostTestHarness::TearDown(); + } + + protected: + MockDevUiModuleProvider mock_provider_; +}; + +} // namespace + +TEST_F(DevUiLoaderThrottleTest, ShouldInstallDevUiDfm) { + auto ShouldInstallDevUiDfm = DevUiLoaderThrottle::ShouldInstallDevUiDfm; + for (const char* url_string : kNonDevUiUrls) + EXPECT_FALSE(ShouldInstallDevUiDfm(GURL(url_string))); + for (const char* url_string : kDevUiUrls) + EXPECT_TRUE(ShouldInstallDevUiDfm(GURL(url_string))); +} + +TEST_F(DevUiLoaderThrottleTest, MaybeCreateThrottleFor) { + bool is_installed = false; + auto creates_throttle = [&](const std::string& url_string) -> bool { + mock_provider_.Reset(); + mock_provider_.SetIsInstalled(is_installed); + content::MockNavigationHandle handle(GURL(url_string), main_rfh()); + std::unique_ptr throttle = + DevUiLoaderThrottle::MaybeCreateThrottleFor(&handle); + return throttle != nullptr; + }; + + // Case 1: DevUI DFM is not installed. + is_installed = false; + // Case 1a: Non DevUI URLs: Throttle not created. + for (const char* url_string : kNonDevUiUrls) { + EXPECT_FALSE(creates_throttle(url_string)); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + } + // Case 1b: DevUI URLs: Throttle created, but no load takes place. + for (const char* url_string : kDevUiUrls) { + EXPECT_TRUE(creates_throttle(url_string)); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + } + + // Case 2: DevUI DFM is installed. + is_installed = true; + // Case 2a: Non DevUI URLs: Throttle not created. + for (const char* url_string : kNonDevUiUrls) { + EXPECT_FALSE(creates_throttle(url_string)); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + } + // Case 2b: DevUI URLs: Throttle not created, but load takes place. + for (const char* url_string : kDevUiUrls) { + EXPECT_FALSE(creates_throttle(url_string)); + EXPECT_TRUE(mock_provider_.GetIsLoaded()); + } +} + +TEST_F(DevUiLoaderThrottleTest, InstallSuccess) { + for (const char* url_string : kDevUiUrls) { + mock_provider_.Reset(); + content::MockNavigationHandle handle(GURL(url_string), main_rfh()); + auto throttle = std::make_unique(&handle); + EXPECT_FALSE(throttle->called_resume); + EXPECT_FALSE(throttle->called_cancel); + EXPECT_FALSE(mock_provider_.GetIsInstalled()); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + + // Simulate request start. + EXPECT_EQ(content::NavigationThrottle::DEFER, throttle->WillStartRequest()); + EXPECT_FALSE(throttle->called_resume); + EXPECT_FALSE(throttle->called_cancel); + EXPECT_FALSE(mock_provider_.GetIsInstalled()); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + + // Simulate actual install (success) + mock_provider_.SimulateAsyncInstall(true); // ! + EXPECT_TRUE(throttle->called_resume); + EXPECT_FALSE(throttle->called_cancel); + EXPECT_TRUE(mock_provider_.GetIsInstalled()); + EXPECT_TRUE(mock_provider_.GetIsLoaded()); + } +} + +TEST_F(DevUiLoaderThrottleTest, InstallQueued) { + mock_provider_.Reset(); + // Page 1 request. + content::MockNavigationHandle handle1(GURL(kDevUiUrls[0]), main_rfh()); + auto throttle1 = std::make_unique(&handle1); + // Page 2 request. + content::MockNavigationHandle handle2(GURL(kDevUiUrls[1]), main_rfh()); + auto throttle2 = std::make_unique(&handle2); + EXPECT_FALSE(mock_provider_.GetIsInstalled()); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + + // Simulate request start of page 1. This triggers install. + EXPECT_EQ(content::NavigationThrottle::DEFER, throttle1->WillStartRequest()); + + // Simulate request start of page 2. This does not trigger install. However, + // the on-complete callback is queued, and will be called. + EXPECT_EQ(content::NavigationThrottle::DEFER, throttle2->WillStartRequest()); + + // Simulate actual install. + mock_provider_.SimulateAsyncInstall(true); // ! + EXPECT_TRUE(throttle1->called_resume); + EXPECT_FALSE(throttle1->called_cancel); + EXPECT_TRUE(throttle2->called_resume); + EXPECT_FALSE(throttle2->called_cancel); + EXPECT_TRUE(mock_provider_.GetIsInstalled()); + EXPECT_TRUE(mock_provider_.GetIsLoaded()); +} + +TEST_F(DevUiLoaderThrottleTest, InstallRedundant) { + mock_provider_.Reset(); + // Page 1 request. + content::MockNavigationHandle handle1(GURL(kDevUiUrls[0]), main_rfh()); + auto throttle1 = std::make_unique(&handle1); + // Page 2 request. + content::MockNavigationHandle handle2(GURL(kDevUiUrls[1]), main_rfh()); + auto throttle2 = std::make_unique(&handle2); + EXPECT_FALSE(mock_provider_.GetIsInstalled()); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + + // Simulate request start of page 1. + EXPECT_EQ(content::NavigationThrottle::DEFER, throttle1->WillStartRequest()); + + // Simulate actual install. + mock_provider_.SimulateAsyncInstall(true); // ! + EXPECT_TRUE(throttle1->called_resume); + EXPECT_FALSE(throttle1->called_cancel); + EXPECT_TRUE(mock_provider_.GetIsInstalled()); + EXPECT_TRUE(mock_provider_.GetIsLoaded()); + + // Simulate request start of page 2. The request was made before install + // completes, but request start occurs after install completes. In this case, + // simply proceed. + EXPECT_EQ(content::NavigationThrottle::PROCEED, + throttle2->WillStartRequest()); + EXPECT_FALSE(throttle2->called_resume); + EXPECT_FALSE(throttle2->called_cancel); + EXPECT_TRUE(mock_provider_.GetIsInstalled()); + EXPECT_TRUE(mock_provider_.GetIsLoaded()); +} + +TEST_F(DevUiLoaderThrottleTest, InstallFailure) { + for (const char* url_string : kDevUiUrls) { + mock_provider_.Reset(); + content::MockNavigationHandle handle(GURL(url_string), main_rfh()); + auto throttle = std::make_unique(&handle); + EXPECT_FALSE(throttle->called_resume); + EXPECT_FALSE(throttle->called_cancel); + EXPECT_FALSE(mock_provider_.GetIsInstalled()); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + + // Simulate request start. + EXPECT_EQ(content::NavigationThrottle::DEFER, throttle->WillStartRequest()); + EXPECT_FALSE(throttle->called_resume); + EXPECT_FALSE(throttle->called_cancel); + EXPECT_FALSE(mock_provider_.GetIsInstalled()); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + + // Simulate actual install (failure) + mock_provider_.SimulateAsyncInstall(false); // ! + EXPECT_FALSE(throttle->called_resume); + EXPECT_TRUE(throttle->called_cancel); + EXPECT_FALSE(mock_provider_.GetIsInstalled()); + EXPECT_FALSE(mock_provider_.GetIsLoaded()); + EXPECT_EQ(net::ERR_CONNECTION_FAILED, + throttle->cancel_result.net_error_code()); + EXPECT_EQ(content::NavigationThrottle::BLOCK_REQUEST, + throttle->cancel_result.action()); + EXPECT_TRUE(throttle->cancel_result.error_page_content().has_value()); + std::string page_content = + throttle->cancel_result.error_page_content().value(); + EXPECT_NE(std::string::npos, page_content.find(" + + + + + DevUI DFM Loader + + + +
+

$i18n{h1}

+

$i18n{p}

+
    +
  • $i18n{li-1}
  • +
  • $i18n{li-2}
  • +
+
+ + diff --git a/chrome/browser/resources/dev_ui_loader/dev_ui_loader.grdp b/chrome/browser/resources/dev_ui_loader/dev_ui_loader.grdp deleted file mode 100644 index 547e30b812d009..00000000000000 --- a/chrome/browser/resources/dev_ui_loader/dev_ui_loader.grdp +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/chrome/browser/resources/dev_ui_loader/dev_ui_loader.html b/chrome/browser/resources/dev_ui_loader/dev_ui_loader.html deleted file mode 100644 index fc95229fb39916..00000000000000 --- a/chrome/browser/resources/dev_ui_loader/dev_ui_loader.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - DevUI DFM Loader - - - - - - - - - diff --git a/chrome/browser/resources/dev_ui_loader/dev_ui_loader.js b/chrome/browser/resources/dev_ui_loader/dev_ui_loader.js deleted file mode 100644 index 5c295a93fafc76..00000000000000 --- a/chrome/browser/resources/dev_ui_loader/dev_ui_loader.js +++ /dev/null @@ -1,51 +0,0 @@ -// 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. - -(function() { -'use strict'; - -/** @return {!URL} */ -function getRedirectUrl() { - try { // For potential TypeError from new URL(). - const urlString = new URL(location).searchParams.get('url'); - if (urlString) { - const url = new URL(decodeURIComponent(urlString)); - // Perform basic filtering. Also skip 'dev-ui-loader' to avoid redirect - // cycle (benign but bizarre). Note that |url.host| is always lowercase. - if (url.protocol === 'chrome:' && url.host.match(/[a-z0-9_\-]+/) && - url.host !== 'dev-ui-loader') { - return url; - } - } - } catch (e) { - } - return new URL('chrome://chrome-urls'); -} - -function redirectToChromePage() { - // Use replace() so the current page disappears from history. - location.replace(getRedirectUrl()); -} - -function doInstall() { - cr.sendWithPromise('installDevUiDfm').then((response) => { - const status = response[0]; - if (status === 'success' || status === 'noop') { - redirectToChromePage(); - } else if (status === 'failure') { - document.querySelector('#failure-message').hidden = false; - } - }); -} - -document.addEventListener('DOMContentLoaded', () => { - cr.sendWithPromise('getDevUiDfmState').then((state) => { - if (state === 'installed') { - redirectToChromePage(); - } else if (state === 'not-installed') { - doInstall(); - } - }); -}); -})(); diff --git a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.cc b/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.cc deleted file mode 100644 index bccb1f37cb4daf..00000000000000 --- a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.cc +++ /dev/null @@ -1,68 +0,0 @@ -// 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/android/dev_ui_loader/dev_ui_loader_message_handler.h" - -#include "base/bind.h" -#include "base/logging.h" -#include "base/values.h" -#include "chrome/android/modules/dev_ui/provider/dev_ui_module_provider.h" - -DevUiLoaderMessageHandler::DevUiLoaderMessageHandler() = default; - -DevUiLoaderMessageHandler::~DevUiLoaderMessageHandler() = default; - -void DevUiLoaderMessageHandler::RegisterMessages() { - web_ui()->RegisterMessageCallback( - "getDevUiDfmState", - base::BindRepeating(&DevUiLoaderMessageHandler::HandleGetDevUiDfmState, - weak_ptr_factory_.GetWeakPtr())); - web_ui()->RegisterMessageCallback( - "installDevUiDfm", - base::BindRepeating(&DevUiLoaderMessageHandler::HandleInstallDevUiDfm, - weak_ptr_factory_.GetWeakPtr())); -} - -void DevUiLoaderMessageHandler::HandleGetDevUiDfmState( - const base::ListValue* args) { - const base::Value* callback_id = nullptr; - CHECK(args->Get(0, &callback_id)); - const char* response = - dev_ui::DevUiModuleProvider::GetInstance()->ModuleInstalled() - ? "installed" - : "not-installed"; - AllowJavascript(); - ResolveJavascriptCallback(*callback_id, base::Value(response)); -} - -void DevUiLoaderMessageHandler::ReplyToJavaScript( - const base::Value& callback_id, - const char* return_value) { - AllowJavascript(); - base::ListValue response; - response.Append(base::Value(return_value)); - ResolveJavascriptCallback(callback_id, response); -} - -void DevUiLoaderMessageHandler::HandleInstallDevUiDfm( - const base::ListValue* args) { - const base::Value* callback_id = nullptr; - CHECK(args->Get(0, &callback_id)); - - if (!dev_ui::DevUiModuleProvider::GetInstance()->ModuleInstalled()) { - dev_ui::DevUiModuleProvider::GetInstance()->InstallModule(base::BindOnce( - &DevUiLoaderMessageHandler::OnDevUiDfmInstallWithStatus, - weak_ptr_factory_.GetWeakPtr(), callback_id->GetString())); - } else { - ReplyToJavaScript(*callback_id, "noop"); - } -} - -void DevUiLoaderMessageHandler::OnDevUiDfmInstallWithStatus( - std::string callback_id_string, - bool success) { - ReplyToJavaScript(base::Value(callback_id_string), - success ? "success" : "failure"); -} - diff --git a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.h b/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.h deleted file mode 100644 index 1dda9141316789..00000000000000 --- a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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_ANDROID_DEV_UI_LOADER_DEV_UI_LOADER_MESSAGE_HANDLER_H_ -#define CHROME_BROWSER_UI_WEBUI_ANDROID_DEV_UI_LOADER_DEV_UI_LOADER_MESSAGE_HANDLER_H_ - -#include - -#include "base/memory/weak_ptr.h" -#include "build/build_config.h" -#include "chrome/android/features/dev_ui/buildflags.h" -#include "content/public/browser/web_ui_message_handler.h" - -#if !defined(OS_ANDROID) || !BUILDFLAG(DFMIFY_DEV_UI) -#error Unsupported platform. -#endif - -namespace base { -class ListValue; -class Value; -} // namespace base - -class DevUiLoaderMessageHandler : public content::WebUIMessageHandler { - public: - DevUiLoaderMessageHandler(); - ~DevUiLoaderMessageHandler() override; - - private: - DevUiLoaderMessageHandler(const DevUiLoaderMessageHandler&) = delete; - void operator=(const DevUiLoaderMessageHandler&) = delete; - - // WebUIMessageHandler - void RegisterMessages() override; - - // Called from JavaScript. |args| specifies id for callback, which receives - // one of the following responses: - // * "not-installed" if the DevUI DFM is not installed. - // * "installed" if the DevUI DFM is installed. - void HandleGetDevUiDfmState(const base::ListValue* args); - - // Helper for HandleInstallAndLoadDevUiDfm(). - void ReplyToJavaScript(const base::Value& callback_id, - const char* return_value); - - // Called from JavaScript. |args| specifies id for callback, which receives - // one of the following responses: - // * "noop" if the DevUI DFM is already installed and loaded. - // * "success" if DevUI DFM install takes place, and succeeds. - // * "failure" if DevUI DFM install takes place, but fails. - void HandleInstallDevUiDfm(const base::ListValue* args); - - // Callback for dev_ui::DevUiModuleProvider::InstallModule(). - void OnDevUiDfmInstallWithStatus(std::string callback_id_string, - bool success); - - // Factory for creating references in callbacks. - base::WeakPtrFactory weak_ptr_factory_{this}; -}; - -#endif // CHROME_BROWSER_UI_WEBUI_ANDROID_DEV_UI_LOADER_DEV_UI_LOADER_MESSAGE_HANDLER_H_ diff --git a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.cc b/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.cc deleted file mode 100644 index 52622ee0b68c66..00000000000000 --- a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.cc +++ /dev/null @@ -1,30 +0,0 @@ -// 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/android/dev_ui_loader/dev_ui_loader_ui.h" - -#include -#include - -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_message_handler.h" -#include "chrome/grit/browser_resources.h" -#include "content/public/browser/web_ui_data_source.h" -#include "url/gurl.h" - -DevUiLoaderUI::DevUiLoaderUI(content::WebUI* web_ui_in, const GURL& url) - : WebUIController(web_ui_in) { - std::unique_ptr html_source; - html_source.reset(content::WebUIDataSource::Create(url.host())); - html_source->SetDefaultResource(IDR_DEV_UI_LOADER_HTML); - html_source->AddResourcePath("dev_ui_loader.html", IDR_DEV_UI_LOADER_HTML); - html_source->AddResourcePath("dev_ui_loader.js", IDR_DEV_UI_LOADER_JS); - html_source->AddResourcePath("dev_ui_loader.css", IDR_DEV_UI_LOADER_CSS); - - Profile* profile = Profile::FromWebUI(web_ui()); - content::WebUIDataSource::Add(profile, html_source.release()); - web_ui()->AddMessageHandler(std::make_unique()); -} - -DevUiLoaderUI::~DevUiLoaderUI() = default; diff --git a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.h b/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.h deleted file mode 100644 index d8b70e7161593f..00000000000000 --- a/chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.h +++ /dev/null @@ -1,32 +0,0 @@ -// 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_ANDROID_DEV_UI_LOADER_DEV_UI_LOADER_UI_H_ -#define CHROME_BROWSER_UI_WEBUI_ANDROID_DEV_UI_LOADER_DEV_UI_LOADER_UI_H_ - -#include "base/memory/weak_ptr.h" -#include "build/build_config.h" -#include "chrome/android/features/dev_ui/buildflags.h" -#include "content/public/browser/web_ui_controller.h" - -#if !defined(OS_ANDROID) || !BUILDFLAG(DFMIFY_DEV_UI) -#error Unsupported platform. -#endif - -class GURL; - -class DevUiLoaderUI : public content::WebUIController { - public: - DevUiLoaderUI(content::WebUI* web_ui_in, const GURL& url); - ~DevUiLoaderUI() override; - - private: - DevUiLoaderUI(const DevUiLoaderUI&) = delete; - void operator=(const DevUiLoaderUI&) = delete; - - // Factory for creating references in callbacks. - base::WeakPtrFactory weak_ptr_factory_{this}; -}; - -#endif // CHROME_BROWSER_UI_WEBUI_ANDROID_DEV_UI_LOADER_DEV_UI_LOADER_UI_H_ diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index aee567a0ebbaa8..49a65a4d7ab9dc 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -118,7 +118,6 @@ #endif #if defined(OS_ANDROID) -#include "chrome/android/features/dev_ui/buildflags.h" #include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals_ui.h" #include "chrome/browser/ui/webui/offline/offline_internals_ui.h" #include "chrome/browser/ui/webui/snippets_internals/snippets_internals_ui.h" @@ -128,9 +127,6 @@ #if BUILDFLAG(ENABLE_FEED_IN_CHROME) #include "chrome/browser/ui/webui/feed_internals/feed_internals_ui.h" #endif // BUILDFLAG(ENABLE_FEED_IN_CHROME) -#if BUILDFLAG(DFMIFY_DEV_UI) -#include "chrome/browser/ui/webui/android/dev_ui_loader/dev_ui_loader_ui.h" -#endif // BUILDFLAG(DFMIFY_DEV_UI) #else // defined(OS_ANDROID) #include "chrome/browser/ui/webui/bookmarks/bookmarks_ui.h" #include "chrome/browser/ui/webui/devtools_ui.h" @@ -263,15 +259,6 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { return new T(web_ui); } -#if defined(OS_ANDROID) -#if BUILDFLAG(DFMIFY_DEV_UI) -template <> -WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { - return new DevUiLoaderUI(web_ui, url); -} -#endif // BUILDFLAG(DFMIFY_DEV_UI) -#endif // defined(OS_ANDROID) - #if !defined(OS_ANDROID) template <> WebUIController* NewWebUI(WebUI* web_ui, @@ -344,13 +331,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, return nullptr; } -#if defined(OS_ANDROID) -#if BUILDFLAG(DFMIFY_DEV_UI) - if (url.host_piece() == chrome::kChromeUIDevUiLoaderHost) - return &NewWebUI; -#endif // BUILDFLAG(DFMIFY_DEV_UI) -#endif // defined(OS_ANDROID) - // Please keep this in alphabetical order. If #ifs or special logics are // required, add it below in the appropriate section. // diff --git a/chrome/common/webui_url_constants.cc b/chrome/common/webui_url_constants.cc index fce988c54a85f7..542bc070e02708 100644 --- a/chrome/common/webui_url_constants.cc +++ b/chrome/common/webui_url_constants.cc @@ -55,7 +55,6 @@ const char kChromeUIDevToolsURL[] = const char kChromeUIDeviceLogHost[] = "device-log"; const char kChromeUIDevicesHost[] = "devices"; const char kChromeUIDevicesURL[] = "chrome://devices/"; -const char kChromeUIDevUiLoaderHost[] = "dev-ui-loader"; const char kChromeUIDevUiLoaderURL[] = "chrome://dev-ui-loader/"; const char kChromeUIDomainReliabilityInternalsHost[] = "domain-reliability-internals"; diff --git a/chrome/common/webui_url_constants.h b/chrome/common/webui_url_constants.h index 1c17c6e90ba3af..f15bbd3f919423 100644 --- a/chrome/common/webui_url_constants.h +++ b/chrome/common/webui_url_constants.h @@ -62,7 +62,6 @@ extern const char kChromeUIDevToolsURL[]; extern const char kChromeUIDeviceLogHost[]; extern const char kChromeUIDevicesHost[]; extern const char kChromeUIDevicesURL[]; -extern const char kChromeUIDevUiLoaderHost[]; extern const char kChromeUIDevUiLoaderURL[]; extern const char kChromeUIDomainReliabilityInternalsHost[]; extern const char kChromeUIDownloadInternalsHost[]; diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn index c32996457fe10b..017313e804350b 100644 --- a/chrome/test/BUILD.gn +++ b/chrome/test/BUILD.gn @@ -3651,6 +3651,10 @@ test("unit_tests") { deps += [ "//v8:v8_external_startup_data_assets" ] } if (dfmify_dev_ui) { + sources += [ + "//chrome/browser/dev_ui/android/dev_ui_loader_throttle_unittest.cc", + ] + # If DevUI DFM is on, include Java classes and native resource split so # that DevUI page tests would work. deps += [ diff --git a/ui/strings/ui_strings.grd b/ui/strings/ui_strings.grd index 3c290930b66227..1f6e9ce370c886 100644 --- a/ui/strings/ui_strings.grd +++ b/ui/strings/ui_strings.grd @@ -1014,6 +1014,19 @@ need to be translated for each locale.--> Try sharing the text in smaller chunks. + + + + + Something went wrong + + + Reloading this page + + + Checking your internet connection + +