Index: chrome/browser/ui/webui/options/font_settings_handler.cc |
diff --git a/chrome/browser/ui/webui/options/font_settings_handler.cc b/chrome/browser/ui/webui/options/font_settings_handler.cc |
index 23f7d6a2977811e495986b13093fcb8874cb8cb6..5563c8ede5a5ede3943dc9839a3af9f1e912cd1e 100644 |
--- a/chrome/browser/ui/webui/options/font_settings_handler.cc |
+++ b/chrome/browser/ui/webui/options/font_settings_handler.cc |
@@ -13,15 +13,22 @@ |
#include "base/prefs/pref_service.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_util.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/character_encoding.h" |
#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/extensions/extension_system.h" |
+#include "chrome/browser/extensions/extension_tab_util.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/webui/options/font_settings_utils.h" |
+#include "chrome/common/extensions/extension.h" |
#include "chrome/common/pref_names.h" |
#include "content/public/browser/font_list_async.h" |
#include "content/public/browser/notification_details.h" |
+#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_ui.h" |
#include "grit/chromium_strings.h" |
#include "grit/generated_resources.h" |
@@ -47,6 +54,9 @@ std::string MaybeGetLocalizedFontName(const std::string& font_name) { |
#endif |
} |
+const char kAdvancedFontSettingsExtensionId[] = |
+ "caclkomlalccbpcdllchkeecicepbmbm"; |
+ |
} // namespace |
@@ -81,6 +91,8 @@ void FontSettingsHandler::GetLocalizedValues( |
IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_HUGE }, |
{ "fontSettingsLoremIpsum", |
IDS_FONT_LANGUAGE_SETTING_LOREM_IPSUM }, |
+ { "advancedFontSettingsOptions", |
+ IDS_FONT_LANGUAGE_SETTING_ADVANCED_FONT_SETTINGS_OPTIONS } |
}; |
RegisterStrings(localized_strings, resources, arraysize(resources)); |
@@ -89,6 +101,21 @@ void FontSettingsHandler::GetLocalizedValues( |
localized_strings->SetString("fontSettingsPlaceholder", |
l10n_util::GetStringUTF16( |
IDS_FONT_LANGUAGE_SETTING_PLACEHOLDER)); |
+ |
+ std::string install_url = extension_urls::GetWebstoreItemDetailURLPrefix() + |
Dan Beam
2013/10/23 18:04:00
nit: IMO use GURL
GURL install_url(extension_urls
falken
2013/10/24 12:09:41
Looks nice. Done.
|
+ kAdvancedFontSettingsExtensionId; |
+ localized_strings->SetString("advancedFontSettingsInstall", |
+ l10n_util::GetStringFUTF16( |
+ IDS_FONT_LANGUAGE_SETTING_ADVANCED_FONT_SETTINGS_INSTALL, |
+ UTF8ToUTF16(install_url))); |
+} |
+ |
+void FontSettingsHandler::InitializeHandler() { |
+ DCHECK(web_ui()); |
Dan Beam
2013/10/23 18:04:00
^ why is this here?
falken
2013/10/24 12:09:41
I guess I don't need it. Basically I was copying I
|
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
+ content::NotificationService::AllSources()); |
} |
void FontSettingsHandler::InitializePage() { |
@@ -98,6 +125,7 @@ void FontSettingsHandler::InitializePage() { |
SetUpSansSerifFontSample(); |
SetUpFixedFontSample(); |
SetUpMinimumFontSample(); |
+ NotifyAdvancedFontSettingsAvailability(); |
} |
void FontSettingsHandler::RegisterMessages() { |
@@ -142,6 +170,15 @@ void FontSettingsHandler::RegisterMessages() { |
web_ui()->RegisterMessageCallback("fetchFontsData", |
base::Bind(&FontSettingsHandler::HandleFetchFontsData, |
base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("openAdvancedFontSettingsOptions", |
+ base::Bind(&FontSettingsHandler::OpenAdvancedFontSettingsOptions, |
Dan Beam
2013/10/23 18:04:00
the callback method should be named "HandleOpenAdv
falken
2013/10/24 12:09:41
I see. Done.
|
+ base::Unretained(this))); |
+} |
+ |
+void FontSettingsHandler::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
Dan Beam
2013/10/23 18:04:00
DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOAD
falken
2013/10/24 12:09:41
Done.
|
+ NotifyAdvancedFontSettingsAvailability(); |
} |
void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { |
@@ -244,6 +281,34 @@ void FontSettingsHandler::SetUpMinimumFontSample() { |
size_value); |
} |
+const extensions::Extension* |
+FontSettingsHandler::GetAdvancedFontSettingsExtension() { |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ ExtensionService* service = |
+ extensions::ExtensionSystem::Get(profile)->extension_service(); |
+ const extensions::Extension* extension = |
+ service->GetInstalledExtension(kAdvancedFontSettingsExtensionId); |
+ if (extension && |
+ service->IsExtensionEnabled(kAdvancedFontSettingsExtensionId)) |
Dan Beam
2013/10/23 18:04:00
curlies
falken
2013/10/24 12:09:41
I added them, but aren't they optional here? I jus
|
+ return extension; |
+ return NULL; |
+} |
+ |
+void FontSettingsHandler::NotifyAdvancedFontSettingsAvailability() { |
+ web_ui()->CallJavascriptFunction( |
+ "FontSettings.notifyAdvancedFontSettingsAvailability", |
+ base::FundamentalValue(GetAdvancedFontSettingsExtension() != NULL)); |
+} |
+ |
+void FontSettingsHandler::OpenAdvancedFontSettingsOptions( |
+ const base::ListValue* args) { |
+ const extensions::Extension* extension = GetAdvancedFontSettingsExtension(); |
+ if (!extension) |
+ return; |
+ ExtensionTabUtil::OpenOptionsPage(extension, |
+ chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); |
+} |
+ |
void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { |
SetUpStandardFontSample(); |
SetUpSerifFontSample(); |