diff options
Diffstat (limited to 'chromium/chrome/browser/ui/webui/internals')
10 files changed, 371 insertions, 0 deletions
diff --git a/chromium/chrome/browser/ui/webui/internals/internals_ui.cc b/chromium/chrome/browser/ui/webui/internals/internals_ui.cc new file mode 100644 index 00000000000..4a5abeb02fc --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/internals_ui.cc @@ -0,0 +1,59 @@ +// Copyright 2020 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/internals/internals_ui.h" + +#include "chrome/common/url_constants.h" +#include "chrome/grit/dev_ui_browser_resources.h" +#include "content/public/browser/web_ui.h" +#include "content/public/browser/web_ui_controller.h" +#include "content/public/browser/web_ui_data_source.h" + +#if defined(OS_ANDROID) +#include "chrome/browser/ui/webui/internals/query_tiles/query_tiles_internals_ui_message_handler.h" +#else +#include "chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.h" +#include "mojo/public/cpp/bindings/self_owned_receiver.h" +#endif // defined(OS_ANDROID) + +InternalsUI::InternalsUI(content::WebUI* web_ui) + : ui::MojoWebUIController(web_ui, /*enable_chrome_send=*/true) { + profile_ = Profile::FromWebUI(web_ui); + source_ = content::WebUIDataSource::Create(chrome::kChromeUIInternalsHost); + + // Add your sub-URL internals WebUI here. +#if defined(OS_ANDROID) + // chrome://internals/query-tiles + AddQueryTilesInternals(web_ui); +#else + // chrome://internals/web-app + WebAppInternalsPageHandlerImpl::AddPageResources(source_); +#endif // defined(OS_ANDROID) + + content::WebUIDataSource::Add(profile_, source_); +} + +InternalsUI::~InternalsUI() = default; + +#if defined(OS_ANDROID) +void InternalsUI::AddQueryTilesInternals(content::WebUI* web_ui) { + source_->AddResourcePath("query_tiles_internals.js", + IDR_QUERY_TILES_INTERNALS_JS); + source_->AddResourcePath("query_tiles_internals_browser_proxy.js", + IDR_QUERY_TILES_INTERNALS_BROWSER_PROXY_JS); + source_->AddResourcePath("query-tiles", IDR_QUERY_TILES_INTERNALS_HTML); + web_ui->AddMessageHandler( + std::make_unique<QueryTilesInternalsUIMessageHandler>(profile_)); +} +#else // defined(OS_ANDROID) +void InternalsUI::BindInterface( + mojo::PendingReceiver<mojom::web_app_internals::WebAppInternalsPageHandler> + receiver) { + mojo::MakeSelfOwnedReceiver( + std::make_unique<WebAppInternalsPageHandlerImpl>(profile_), + std::move(receiver)); +} +#endif // defined(OS_ANDROID) + +WEB_UI_CONTROLLER_TYPE_IMPL(InternalsUI) diff --git a/chromium/chrome/browser/ui/webui/internals/internals_ui.h b/chromium/chrome/browser/ui/webui/internals/internals_ui.h new file mode 100644 index 00000000000..7339b46df97 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/internals_ui.h @@ -0,0 +1,48 @@ +// Copyright 2020 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_INTERNALS_INTERNALS_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_INTERNALS_INTERNALS_UI_H_ + +#include "build/build_config.h" +#include "chrome/browser/profiles/profile.h" +#include "content/public/browser/web_ui_data_source.h" +#include "ui/webui/mojo_web_ui_controller.h" + +#if !defined(OS_ANDROID) +// gn check doesn't understand "#if !defined(OS_ANDROID)" and fails this +// non-Android include on Android. +#include "chrome/browser/ui/webui/internals/web_app/web_app_internals.mojom.h" // nogncheck +#endif + +namespace content { +class WebUI; +} // namespace content + +// Client could put debug WebUI as sub-URL under chrome://internals/. +// e.g. chrome://internals/your-feature. +class InternalsUI : public ui::MojoWebUIController { + public: + explicit InternalsUI(content::WebUI* web_ui); + ~InternalsUI() override; + +#if !defined(OS_ANDROID) + void BindInterface( + mojo::PendingReceiver< + mojom::web_app_internals::WebAppInternalsPageHandler> receiver); +#endif // !defined(OS_ANDROID) + + private: + WEB_UI_CONTROLLER_TYPE_DECL(); + +#if defined(OS_ANDROID) + // Add resources and message handler for chrome://internals/query-tiles. + void AddQueryTilesInternals(content::WebUI* web_ui); +#endif // defined(OS_ANDROID) + + Profile* profile_; + content::WebUIDataSource* source_; +}; + +#endif // CHROME_BROWSER_UI_WEBUI_INTERNALS_INTERNALS_UI_H_ diff --git a/chromium/chrome/browser/ui/webui/internals/query_tiles/OWNERS b/chromium/chrome/browser/ui/webui/internals/query_tiles/OWNERS new file mode 100644 index 00000000000..593e722800d --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/query_tiles/OWNERS @@ -0,0 +1 @@ +file://components/query_tiles/OWNERS diff --git a/chromium/chrome/browser/ui/webui/internals/query_tiles/query_tiles_internals_ui_message_handler.cc b/chromium/chrome/browser/ui/webui/internals/query_tiles/query_tiles_internals_ui_message_handler.cc new file mode 100644 index 00000000000..c0bbb708bd5 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/query_tiles/query_tiles_internals_ui_message_handler.cc @@ -0,0 +1,70 @@ +// Copyright 2020 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/internals/query_tiles/query_tiles_internals_ui_message_handler.h" + +#include <memory> +#include <string> +#include <utility> + +#include "base/bind.h" +#include "base/values.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_key.h" +#include "chrome/browser/query_tiles/tile_service_factory.h" +#include "components/query_tiles/tile_service.h" +#include "content/public/browser/web_ui.h" + +QueryTilesInternalsUIMessageHandler::QueryTilesInternalsUIMessageHandler( + Profile* profile) + : tile_service_(query_tiles::TileServiceFactory::GetForKey( + profile->GetProfileKey())) { + DCHECK(tile_service_); +} + +QueryTilesInternalsUIMessageHandler::~QueryTilesInternalsUIMessageHandler() = + default; + +void QueryTilesInternalsUIMessageHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback( + "startFetch", base::BindRepeating( + &QueryTilesInternalsUIMessageHandler::HandleStartFetch, + base::Unretained(this))); + web_ui()->RegisterMessageCallback( + "purgeDb", + base::BindRepeating(&QueryTilesInternalsUIMessageHandler::HandlePurgeDb, + base::Unretained(this))); + + web_ui()->RegisterMessageCallback( + "getServiceStatus", + base::Bind(&QueryTilesInternalsUIMessageHandler::HandleGetServiceStatus, + weak_ptr_factory_.GetWeakPtr())); + + web_ui()->RegisterMessageCallback( + "getTileData", + base::Bind(&QueryTilesInternalsUIMessageHandler::HandleGetTileData, + weak_ptr_factory_.GetWeakPtr())); +} + +void QueryTilesInternalsUIMessageHandler::HandleGetTileData( + const base::ListValue* args) { + NOTIMPLEMENTED(); +} + +void QueryTilesInternalsUIMessageHandler::HandleGetServiceStatus( + const base::ListValue* args) { + NOTIMPLEMENTED(); +} + +void QueryTilesInternalsUIMessageHandler::HandleStartFetch( + const base::ListValue* args) { + AllowJavascript(); + tile_service_->StartFetchForTiles(false /*is_from_reduce_mode*/, + base::BindOnce([](bool reschedule) {})); +} + +void QueryTilesInternalsUIMessageHandler::HandlePurgeDb( + const base::ListValue* args) { + tile_service_->PurgeDb(); +} diff --git a/chromium/chrome/browser/ui/webui/internals/query_tiles/query_tiles_internals_ui_message_handler.h b/chromium/chrome/browser/ui/webui/internals/query_tiles/query_tiles_internals_ui_message_handler.h new file mode 100644 index 00000000000..1bd47eb5935 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/query_tiles/query_tiles_internals_ui_message_handler.h @@ -0,0 +1,43 @@ +// Copyright 2020 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_INTERNALS_QUERY_TILES_QUERY_TILES_INTERNALS_UI_MESSAGE_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_INTERNALS_QUERY_TILES_QUERY_TILES_INTERNALS_UI_MESSAGE_HANDLER_H_ + +#include "base/macros.h" +#include "base/memory/weak_ptr.h" +#include "content/public/browser/web_ui_message_handler.h" + +namespace base { +class ListValue; +} // namespace base + +class Profile; + +namespace query_tiles { +class TileService; +} + +class QueryTilesInternalsUIMessageHandler + : public content::WebUIMessageHandler { + public: + explicit QueryTilesInternalsUIMessageHandler(Profile* profile); + ~QueryTilesInternalsUIMessageHandler() override; + + // content::WebUIMessageHandler implementation. + void RegisterMessages() override; + + private: + void HandleGetServiceStatus(const base::ListValue* args); + void HandleGetTileData(const base::ListValue* args); + void HandleStartFetch(const base::ListValue* args); + void HandlePurgeDb(const base::ListValue* args); + + query_tiles::TileService* tile_service_; + + base::WeakPtrFactory<QueryTilesInternalsUIMessageHandler> weak_ptr_factory_{ + this}; +}; + +#endif // CHROME_BROWSER_UI_WEBUI_INTERNALS_QUERY_TILES_QUERY_TILES_INTERNALS_UI_MESSAGE_HANDLER_H_ diff --git a/chromium/chrome/browser/ui/webui/internals/web_app/BUILD.gn b/chromium/chrome/browser/ui/webui/internals/web_app/BUILD.gn new file mode 100644 index 00000000000..70ca6d1bce8 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/web_app/BUILD.gn @@ -0,0 +1,9 @@ +# Copyright 2020 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 = [ "web_app_internals.mojom" ] +} diff --git a/chromium/chrome/browser/ui/webui/internals/web_app/OWNERS b/chromium/chrome/browser/ui/webui/internals/web_app/OWNERS new file mode 100644 index 00000000000..a74f1031167 --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/web_app/OWNERS @@ -0,0 +1,4 @@ +file://chrome/browser/web_applications/OWNERS + +per-file *.mojom=set noparent +per-file *.mojom=file://ipc/SECURITY_OWNERS diff --git a/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals.mojom b/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals.mojom new file mode 100644 index 00000000000..0a05fcafaca --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals.mojom @@ -0,0 +1,30 @@ +// Copyright 2020 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 mojom.web_app_internals; + +struct WebApp { + // The web app's ID. + string id; + + // The web app's name. + string name; + + // Debugging info about the web app's internal state. + string debug_info; +}; + +// Provides access to browser side internal information about installed web apps +// (also known as PWAs) for chrome://internals/web-app. +interface WebAppInternalsPageHandler { + // Whether the BMO web app backend is enabled. + IsBmoEnabled() => (bool is_bmo_enabled); + + // Returns details of all the installed web apps for the current profile. + GetWebApps() => (array<WebApp> web_app_list); + + // Returns the prefs used for keeping track of non-user installed web apps. + GetExternallyInstalledWebAppPrefs() => + (string externally_installed_web_app_prefs); +}; diff --git a/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.cc b/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.cc new file mode 100644 index 00000000000..79a536d5d9b --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.cc @@ -0,0 +1,68 @@ +// Copyright 2017 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 <sstream> + +#include "chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.h" + +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/web_applications/components/web_app_provider_base.h" +#include "chrome/browser/web_applications/web_app.h" +#include "chrome/browser/web_applications/web_app_registrar.h" +#include "chrome/common/chrome_features.h" +#include "chrome/common/pref_names.h" +#include "chrome/grit/dev_ui_browser_resources.h" +#include "components/prefs/pref_service.h" +#include "content/public/browser/web_ui_data_source.h" + +WebAppInternalsPageHandlerImpl::WebAppInternalsPageHandlerImpl(Profile* profile) + : profile_(profile) {} + +WebAppInternalsPageHandlerImpl::~WebAppInternalsPageHandlerImpl() = default; + +void WebAppInternalsPageHandlerImpl::AddPageResources( + content::WebUIDataSource* source) { + source->AddResourcePath("web_app_internals.mojom-lite.js", + IDR_WEB_APP_INTERNALS_MOJOM_LITE_JS); + source->AddResourcePath("web_app_internals.js", IDR_WEB_APP_INTERNALS_JS); + source->AddResourcePath("web-app", IDR_WEB_APP_INTERNALS_HTML); +} + +void WebAppInternalsPageHandlerImpl::IsBmoEnabled( + IsBmoEnabledCallback callback) { + std::move(callback).Run( + base::FeatureList::IsEnabled(features::kDesktopPWAsWithoutExtensions)); +} + +void WebAppInternalsPageHandlerImpl::GetWebApps(GetWebAppsCallback callback) { + auto* provider = web_app::WebAppProviderBase::GetProviderBase(profile_); + if (!provider) + std::move(callback).Run({}); + + web_app::AppRegistrar& registrar_base = provider->registrar(); + web_app::WebAppRegistrar* registrar = registrar_base.AsWebAppRegistrar(); + if (!registrar) + std::move(callback).Run({}); + + std::vector<mojom::web_app_internals::WebAppPtr> result; + for (const web_app::WebApp& web_app : registrar->AllApps()) { + mojom::web_app_internals::WebAppPtr info( + mojom::web_app_internals::WebApp::New()); + info->name = web_app.name(); + info->id = web_app.app_id(); + std::stringstream ss; + ss << web_app; + info->debug_info = ss.str(); + result.push_back(std::move(info)); + } + + std::move(callback).Run(std::move(result)); +} + +void WebAppInternalsPageHandlerImpl::GetExternallyInstalledWebAppPrefs( + GetExternallyInstalledWebAppPrefsCallback callback) { + std::stringstream ss; + ss << *profile_->GetPrefs()->GetDictionary(prefs::kWebAppsExtensionIDs); + std::move(callback).Run(ss.str()); +} diff --git a/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.h b/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.h new file mode 100644 index 00000000000..ac2d034f03d --- /dev/null +++ b/chromium/chrome/browser/ui/webui/internals/web_app/web_app_internals_page_handler_impl.h @@ -0,0 +1,39 @@ +// Copyright 2020 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_INTERNALS_WEB_APP_WEB_APP_INTERNALS_PAGE_HANDLER_IMPL_H_ +#define CHROME_BROWSER_UI_WEBUI_INTERNALS_WEB_APP_WEB_APP_INTERNALS_PAGE_HANDLER_IMPL_H_ + +#include "chrome/browser/ui/webui/internals/web_app/web_app_internals.mojom.h" + +class Profile; + +namespace content { +class WebUIDataSource; +} + +// Handles API requests from chrome://internals/web-app. +class WebAppInternalsPageHandlerImpl + : public mojom::web_app_internals::WebAppInternalsPageHandler { + public: + explicit WebAppInternalsPageHandlerImpl(Profile* profile); + WebAppInternalsPageHandlerImpl(const WebAppInternalsPageHandlerImpl&) = + delete; + WebAppInternalsPageHandlerImpl& operator=( + const WebAppInternalsPageHandlerImpl&) = delete; + ~WebAppInternalsPageHandlerImpl() override; + + static void AddPageResources(content::WebUIDataSource* source); + + // mojom::web_app_internals::WebAppInternalsPageHandler: + void IsBmoEnabled(IsBmoEnabledCallback callback) override; + void GetWebApps(GetWebAppsCallback callback) override; + void GetExternallyInstalledWebAppPrefs( + GetExternallyInstalledWebAppPrefsCallback callback) override; + + private: + Profile* profile_ = nullptr; +}; + +#endif // CHROME_BROWSER_UI_WEBUI_INTERNALS_WEB_APP_WEB_APP_INTERNALS_PAGE_HANDLER_IMPL_H_ |