Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: chrome/browser/ui/webui/settings/font_handler.cc

Issue 1896463003: WebUI: Add JavaScript lifecycle-control to WebUIMessageHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/font_handler.cc
diff --git a/chrome/browser/ui/webui/settings/font_handler.cc b/chrome/browser/ui/webui/settings/font_handler.cc
index 9192acd162776b396ee9033ec44fbcd552e8d2d1..2c10ff2aa7f04a9de623607433532ad198347fd9 100644
--- a/chrome/browser/ui/webui/settings/font_handler.cc
+++ b/chrome/browser/ui/webui/settings/font_handler.cc
@@ -59,6 +59,15 @@ void FontHandler::RegisterMessages() {
base::Unretained(this)));
}
+void FontHandler::OnJavascriptAllowed() {
+ extension_registry_observer_.Add(
+ extensions::ExtensionRegistry::Get(profile_));
+}
+
+void FontHandler::OnJavascriptDisallowed() {
+ extension_registry_observer_.RemoveAll();
+}
+
void FontHandler::HandleFetchFontsData(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
std::string callback_id;
@@ -71,10 +80,7 @@ void FontHandler::HandleFetchFontsData(const base::ListValue* args) {
void FontHandler::HandleObserveAdvancedFontExtensionAvailable(
const base::ListValue* /*args*/) {
- extensions::ExtensionRegistry* observer =
- extensions::ExtensionRegistry::Get(profile_);
- if (!extension_registry_observer_.IsObserving(observer))
- extension_registry_observer_.Add(observer);
+ AllowJavascript();
NotifyAdvancedFontSettingsAvailability();
}
@@ -97,7 +103,7 @@ const extensions::Extension* FontHandler::GetAdvancedFontSettingsExtension() {
}
void FontHandler::NotifyAdvancedFontSettingsAvailability() {
- web_ui()->CallJavascriptFunction(
+ CallJavascriptFunction(
"cr.webUIListenerCallback",
base::StringValue("advanced-font-settings-installed"),
base::FundamentalValue(GetAdvancedFontSettingsExtension() != nullptr));
@@ -171,8 +177,4 @@ void FontHandler::FontListHasLoaded(std::string callback_id,
ResolveJavascriptCallback(base::StringValue(callback_id), response);
}
-void FontHandler::RenderViewReused() {
- extension_registry_observer_.RemoveAll();
-}
-
} // namespace settings

Powered by Google App Engine
This is Rietveld 408576698