Commit 2a565a3b authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

Serve chrome://apps from a regular WebUIDataSource.

Previously because of the long history of this page (which at some
point served as the NTP, aka NTP4) it was served by a custom class
which delegated logic to NTPResourceCache. There is no good reason to
use the NTPResourceCache for chrome://apps anymore, AFAIK.

Using a WebUIDataSource makes a lot of things simpler, like registering
resources, localized strings, load time data, and many more.

This is in preparation of possibly migrating chrome://apps to JS modules
(TBD). Regardless, moving away from NTPResourceCache is a positive step.

Bug: 1168053
Change-Id: If82d634c8d7e699dc1c906517c23c40bfaa0b6b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2629855Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846035}
parent 90f41215
......@@ -16,6 +16,8 @@
<link id="themecss" rel="stylesheet">
<script src="../../../../ui/webui/resources/js/assert.js"></script>
<script src="../../../../ui/webui/resources/js/util.js"></script>
<script src="../../../../ui/webui/resources/js/load_time_data.js"></script>
<script src="chrome://apps/strings.js"></script>
<script>
// Until themes can clear the cache, force-reload the theme stylesheet.
$('themecss').href = 'chrome://theme/css/new_tab_theme.css?' + Date.now();
......
......@@ -6,7 +6,7 @@
#define CHROME_BROWSER_UI_WEBUI_APP_LAUNCHER_PAGE_UI_H_
#include "base/macros.h"
#include "content/public/browser/url_data_source.h"
#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/web_ui_controller.h"
#include "ui/base/layout.h"
......@@ -31,32 +31,10 @@ class AppLauncherPageUI : public content::WebUIController {
const base::ListValue& args) override;
private:
class HTMLSource : public content::URLDataSource {
public:
explicit HTMLSource(Profile* profile);
~HTMLSource() override;
// content::URLDataSource implementation.
std::string GetSource() override;
void StartDataRequest(
const GURL& url,
const content::WebContents::Getter& wc_getter,
content::URLDataSource::GotDataCallback callback) override;
std::string GetMimeType(const std::string&) override;
bool ShouldReplaceExistingSource() override;
bool AllowCaching() override;
std::string GetContentSecurityPolicy(
network::mojom::CSPDirectiveName directive) override;
private:
// Pointer back to the original profile.
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(HTMLSource);
};
void OnHideWebStoreIconChanged();
Profile* GetProfile() const;
PrefChangeRegistrar pref_change_registrar_;
DISALLOW_COPY_AND_ASSIGN(AppLauncherPageUI);
};
......
......@@ -404,11 +404,12 @@ void AppLauncherHandler::CreateExtensionInfo(const Extension* extension,
}
// static
void AppLauncherHandler::GetLocalizedValues(Profile* profile,
base::DictionaryValue* values) {
void AppLauncherHandler::RegisterLoadTimeData(
Profile* profile,
content::WebUIDataSource* source) {
PrefService* prefs = profile->GetPrefs();
int shown_page = prefs->GetInteger(prefs::kNtpShownPage);
values->SetInteger("shown_page_index", shown_page & INDEX_MASK);
source->AddInteger("shown_page_index", shown_page & INDEX_MASK);
}
// static
......
......@@ -25,6 +25,7 @@
#include "components/sync/model/string_ordinal.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
......@@ -69,8 +70,8 @@ class AppLauncherHandler
base::DictionaryValue* value);
// Registers values (strings etc.) for the page.
static void GetLocalizedValues(Profile* profile,
base::DictionaryValue* values);
static void RegisterLoadTimeData(Profile* profile,
content::WebUIDataSource* source);
// Register per-profile preferences.
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
......
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