Commit ab0964c8 authored by Justin DeWitt's avatar Justin DeWitt Committed by Commit Bot

[Eos] Add WebUI infrastructure for serving the internals page.

* Adds chrome://explore-sites-internals to webui urls
* Adds a mojom file defining the interface, and the UI and handler classes
as required by Mojo webui pages.
* Implements the interface on native side.
* Adds a placeholder HTML page.

This leaves the JS/CSS/HTML work to a future CL.

Bug: 900673
Change-Id: Ic3506010828e9db385099d9289f45d69861e05c4
Reviewed-on: https://chromium-review.googlesource.com/c/1383491
Commit-Queue: Justin DeWitt <dewittj@chromium.org>
Reviewed-by: default avatarCathy Li <chili@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618409}
parent f47e3f84
......@@ -199,6 +199,7 @@
<include name="IDR_EOC_INTERNALS_CSS" file="resources\eoc_internals\eoc_internals.css" compress="gzip" type="BINDATA" />
<include name="IDR_EOC_INTERNALS_JS" file="resources\eoc_internals\eoc_internals.js" compress="gzip" type="BINDATA" />
<include name="IDR_EOC_INTERNALS_MOJO_JS" file="${root_gen_dir}\chrome\browser\ui\webui\eoc_internals\eoc_internals.mojom.js" use_base_dir="false" type="BINDATA" compress="gzip" />
<include name="IDR_EXPLORE_SITES_INTERNALS_HTML" file="resources\explore_sites_internals\explore_sites_internals.html" allowexternalscript="true" compress="gzip" type="BINDATA" />
<include name="IDR_OFFLINE_INTERNALS_HTML" file="resources\offline_pages\offline_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" compress="gzip" />
<include name="IDR_OFFLINE_INTERNALS_CSS" file="resources\offline_pages\offline_internals.css" type="BINDATA" compress="gzip" />
<include name="IDR_OFFLINE_INTERNALS_JS" file="resources\offline_pages\offline_internals.js" type="BINDATA" compress="gzip" />
......
file://chrome/browser/android/explore_sites/OWNERS
<!--
Copyright 2018 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.
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Explore Sites Internals</title>
</head>
<body>
<h1>Explore Sites Internals</h1>
</body>
</html>
......@@ -563,6 +563,7 @@ jumbo_split_static_library("ui") {
if (is_android) {
deps += [
"//chrome/browser/ui/webui/eoc_internals:mojo_bindings",
"//chrome/browser/ui/webui/explore_sites_internals:mojo_bindings",
"//chrome/browser/ui/webui/snippets_internals:mojo_bindings",
]
}
......@@ -714,6 +715,10 @@ jumbo_split_static_library("ui") {
"webui/eoc_internals/eoc_internals_page_handler.h",
"webui/eoc_internals/eoc_internals_ui.cc",
"webui/eoc_internals/eoc_internals_ui.h",
"webui/explore_sites_internals/explore_sites_internals_page_handler.cc",
"webui/explore_sites_internals/explore_sites_internals_page_handler.h",
"webui/explore_sites_internals/explore_sites_internals_ui.cc",
"webui/explore_sites_internals/explore_sites_internals_ui.h",
"webui/offline/offline_internals_ui.cc",
"webui/offline/offline_internals_ui.h",
"webui/offline/offline_internals_ui_message_handler.cc",
......
......@@ -118,6 +118,7 @@
#if defined(OS_ANDROID)
#include "chrome/browser/ui/webui/eoc_internals/eoc_internals_ui.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"
#include "chrome/browser/ui/webui/webapks_ui.h"
......@@ -527,6 +528,9 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
if (url.host_piece() == chrome::kChromeUIEocInternalsHost &&
!profile->IsOffTheRecord())
return &NewWebUI<EocInternalsUI>;
if (url.host_piece() == chrome::kChromeUIExploreSitesInternalsHost &&
!profile->IsOffTheRecord())
return &NewWebUI<explore_sites::ExploreSitesInternalsUI>;
if (url.host_piece() == chrome::kChromeUIOfflineInternalsHost)
return &NewWebUI<OfflineInternalsUI>;
if (url.host_piece() == chrome::kChromeUISnippetsInternalsHost &&
......
# Copyright 2018 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 = [
"explore_sites_internals.mojom",
]
}
file://chrome/browser/android/explore_sites/OWNERS
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
// Copyright 2018 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 explore_sites_internals.mojom;
// Browser interface for the page. Consists of calls for data and hooks for
// interactivity.
interface PageHandler {
// Get a key/value mapping of properties.
GetProperties() => (map<string, string> properties);
// Clear the cached suggestions.
ClearCachedExploreSitesCatalog() => (bool success);
// Force the fetcher to ping the server for a new catalog.
ForceNetworkRequest() => (bool success);
// Force the fetcher to use a different country code than that provided by
// Finch.
OverrideCountryCode(string country_code) => (bool success);
};
// Copyright 2018 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/explore_sites_internals/explore_sites_internals_page_handler.h"
#include <string>
#include <vector>
#include "base/containers/flat_map.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/android/explore_sites/explore_sites_feature.h"
#include "chrome/browser/android/explore_sites/url_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
namespace explore_sites {
using chrome::android::explore_sites::ExploreSitesVariation;
using chrome::android::explore_sites::GetExploreSitesVariation;
namespace {
std::string GetChromeFlagsSetupString() {
switch (GetExploreSitesVariation()) {
case ExploreSitesVariation::ENABLED:
return "Enabled";
case ExploreSitesVariation::EXPERIMENT:
return "Experiment";
case ExploreSitesVariation::DISABLED:
return "Disabled";
}
}
} // namespace
ExploreSitesInternalsPageHandler::ExploreSitesInternalsPageHandler(
explore_sites_internals::mojom::PageHandlerRequest request,
ExploreSitesService* explore_sites_service,
Profile* profile)
: binding_(this, std::move(request)),
explore_sites_service_(explore_sites_service),
profile_(profile) {}
ExploreSitesInternalsPageHandler::~ExploreSitesInternalsPageHandler() {}
void ExploreSitesInternalsPageHandler::GetProperties(
GetPropertiesCallback callback) {
base::flat_map<std::string, std::string> properties;
properties["chrome-flags-setup"] = GetChromeFlagsSetupString();
properties["server-endpoint"] = GetCatalogURL().spec();
properties["country-code"] = explore_sites_service_->GetCountryCode();
std::move(callback).Run(properties);
}
void ExploreSitesInternalsPageHandler::ClearCachedExploreSitesCatalog(
ClearCachedExploreSitesCatalogCallback callback) {
if (ExploreSitesVariation::ENABLED != GetExploreSitesVariation()) {
std::move(callback).Run(false);
return;
}
explore_sites_service_->ClearCachedCatalogsForDebugging();
std::move(callback).Run(true);
}
void ExploreSitesInternalsPageHandler::ForceNetworkRequest(
ForceNetworkRequestCallback callback) {
explore_sites_service_->UpdateCatalogFromNetwork(
true /* is_immediate_fetch */,
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
std::move(callback));
}
void ExploreSitesInternalsPageHandler::OverrideCountryCode(
const std::string& country_code,
OverrideCountryCodeCallback callback) {
if (ExploreSitesVariation::ENABLED != GetExploreSitesVariation()) {
std::move(callback).Run(false);
return;
}
explore_sites_service_->OverrideCountryCodeForDebugging(country_code);
std::move(callback).Run(true);
}
} // namespace explore_sites
// Copyright 2018 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_EXPLORE_SITES_INTERNALS_EXPLORE_SITES_INTERNALS_PAGE_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_EXPLORE_SITES_INTERNALS_EXPLORE_SITES_INTERNALS_PAGE_HANDLER_H_
#include "base/macros.h"
#include "chrome/browser/android/explore_sites/explore_sites_service.h"
#include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
class Profile;
namespace explore_sites {
// Concrete implementation of explore_sites_internals::mojom::PageHandler.
class ExploreSitesInternalsPageHandler
: public explore_sites_internals::mojom::PageHandler {
public:
ExploreSitesInternalsPageHandler(
explore_sites_internals::mojom::PageHandlerRequest request,
ExploreSitesService* explore_sites_service,
Profile* profile);
~ExploreSitesInternalsPageHandler() override;
private:
// explore_sites_internals::mojom::ExploreSitesInternalsPageHandler
void GetProperties(GetPropertiesCallback) override;
void ClearCachedExploreSitesCatalog(
ClearCachedExploreSitesCatalogCallback) override;
void OverrideCountryCode(const std::string& country_code,
OverrideCountryCodeCallback) override;
void ForceNetworkRequest(ForceNetworkRequestCallback) override;
mojo::Binding<explore_sites_internals::mojom::PageHandler> binding_;
ExploreSitesService* explore_sites_service_;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(ExploreSitesInternalsPageHandler);
};
} // namespace explore_sites
#endif // CHROME_BROWSER_UI_WEBUI_EXPLORE_SITES_INTERNALS_EXPLORE_SITES_INTERNALS_PAGE_HANDLER_H_
// Copyright 2018 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/explore_sites_internals/explore_sites_internals_ui.h"
#include "build/build_config.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/android/explore_sites/explore_sites_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals_page_handler.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "content/public/browser/web_ui_data_source.h"
namespace explore_sites {
ExploreSitesInternalsUI::ExploreSitesInternalsUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui) {
content::WebUIDataSource* source = content::WebUIDataSource::Create(
chrome::kChromeUIExploreSitesInternalsHost);
source->SetDefaultResource(IDR_EXPLORE_SITES_INTERNALS_HTML);
source->UseGzip();
Profile* profile = Profile::FromWebUI(web_ui);
explore_sites_service_ =
ExploreSitesServiceFactory::GetForBrowserContext(profile);
content::WebUIDataSource::Add(profile, source);
// "BindExploreSitesInternalsPageHandler" will be invoked by
// explore_sites_internals.js, which is only possible while this object is
// alive, so this base::Unretained is safe.
AddHandlerToRegistry(base::BindRepeating(
&ExploreSitesInternalsUI::BindExploreSitesInternalsPageHandler,
base::Unretained(this)));
}
ExploreSitesInternalsUI::~ExploreSitesInternalsUI() {}
void ExploreSitesInternalsUI::BindExploreSitesInternalsPageHandler(
explore_sites_internals::mojom::PageHandlerRequest request) {
page_handler_.reset(new ExploreSitesInternalsPageHandler(
std::move(request), explore_sites_service_,
Profile::FromWebUI(web_ui())));
}
} // namespace explore_sites
// Copyright 2018 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_EXPLORE_SITES_INTERNALS_EXPLORE_SITES_INTERNALS_UI_H_
#define CHROME_BROWSER_UI_WEBUI_EXPLORE_SITES_INTERNALS_EXPLORE_SITES_INTERNALS_UI_H_
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals.mojom.h"
#include "chrome/browser/ui/webui/explore_sites_internals/explore_sites_internals_page_handler.h"
#include "ui/webui/mojo_web_ui_controller.h"
namespace explore_sites {
// UI controller for chrome://explore-sites-internals, hooks up a concrete
// implementation of explore_sites_internals::mojom::PageHandler to requests for
// that page handler that will come from the frontend.
class ExploreSitesInternalsUI : public ui::MojoWebUIController {
public:
explicit ExploreSitesInternalsUI(content::WebUI* web_ui);
~ExploreSitesInternalsUI() override;
private:
void BindExploreSitesInternalsPageHandler(
explore_sites_internals::mojom::PageHandlerRequest request);
std::unique_ptr<ExploreSitesInternalsPageHandler> page_handler_;
ExploreSitesService* explore_sites_service_;
DISALLOW_COPY_AND_ASSIGN(ExploreSitesInternalsUI);
};
} // namespace explore_sites
#endif // CHROME_BROWSER_UI_WEBUI_EXPLORE_SITES_INTERNALS_EXPLORE_SITES_INTERNALS_UI_H_
......@@ -174,6 +174,7 @@ const char kDeprecatedChromeUIHistoryFrameURL[] = "chrome://history-frame/";
#if defined(OS_ANDROID)
const char kChromeUIEocInternalsHost[] = "eoc-internals";
const char kChromeUIExploreSitesInternalsHost[] = "explore-sites-internals";
const char kChromeUIJavaCrashURL[] = "chrome://java-crash/";
const char kChromeUINativeBookmarksURL[] = "chrome-native://bookmarks/";
const char kChromeUINativeExploreURL[] = "chrome-native://explore";
......@@ -393,6 +394,7 @@ const char* const kChromeHostURLs[] = {
#endif
#if defined(OS_ANDROID)
kChromeUIEocInternalsHost,
kChromeUIExploreSitesInternalsHost,
kChromeUIOfflineInternalsHost,
kChromeUISnippetsInternalsHost,
kChromeUIWebApksHost,
......
......@@ -174,6 +174,7 @@ extern const char kDeprecatedChromeUIHistoryFrameHost[];
extern const char kDeprecatedChromeUIHistoryFrameURL[];
#if defined(OS_ANDROID)
extern const char kChromeUIExploreSitesInternalsHost[];
extern const char kChromeUIEocInternalsHost[];
extern const char kChromeUIJavaCrashURL[];
extern const char kChromeUINativeBookmarksURL[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment