| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/plugins_ui.h" | 5 #include "chrome/browser/ui/webui/plugins_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/plugin_updater.h" | 16 #include "chrome/browser/plugin_updater.h" |
| 17 #include "chrome/browser/prefs/pref_member.h" | 17 #include "chrome/browser/prefs/pref_member.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 23 #include "chrome/common/chrome_content_client.h" | 24 #include "chrome/common/chrome_content_client.h" |
| 24 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/jstemplate_builder.h" | |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "content/browser/browser_thread.h" | 28 #include "content/browser/browser_thread.h" |
| 29 #include "content/browser/tab_contents/tab_contents.h" | 29 #include "content/browser/tab_contents/tab_contents.h" |
| 30 #include "content/common/notification_service.h" | 30 #include "content/common/notification_service.h" |
| 31 #include "grit/browser_resources.h" | 31 #include "grit/browser_resources.h" |
| 32 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 33 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | |
| 35 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "webkit/plugins/npapi/plugin_list.h" | 35 #include "webkit/plugins/npapi/plugin_list.h" |
| 37 | 36 |
| 37 static const char kStringsJsFile[] = "strings.js"; |
| 38 static const char kPluginsJsFile[] = "plugins.js"; |
| 39 |
| 38 namespace { | 40 namespace { |
| 39 | 41 |
| 40 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
| 41 // | 43 // |
| 42 // PluginsHTMLSource | 44 // PluginsUIHTMLSource |
| 43 // | 45 // |
| 44 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
| 45 | 47 |
| 46 class PluginsUIHTMLSource : public ChromeURLDataManager::DataSource { | 48 class PluginsUIHTMLSource : public ChromeWebUIDataSource { |
| 47 public: | 49 public: |
| 48 PluginsUIHTMLSource() | 50 PluginsUIHTMLSource(); |
| 49 : DataSource(chrome::kChromeUIPluginsHost, MessageLoop::current()) {} | |
| 50 | 51 |
| 51 // Called when the network layer has requested a resource underneath | 52 // Called when the network layer has requested a resource underneath |
| 52 // the path we registered. | 53 // the path we registered. |
| 53 virtual void StartDataRequest(const std::string& path, | 54 virtual void StartDataRequest(const std::string& path, |
| 54 bool is_incognito, | 55 bool is_incognito, |
| 55 int request_id); | 56 int request_id); |
| 56 virtual std::string GetMimeType(const std::string&) const { | 57 virtual std::string GetMimeType(const std::string&) const; |
| 57 return "text/html"; | |
| 58 } | |
| 59 | 58 |
| 60 private: | 59 private: |
| 61 ~PluginsUIHTMLSource() {} | 60 ~PluginsUIHTMLSource() {} |
| 62 | 61 |
| 63 DISALLOW_COPY_AND_ASSIGN(PluginsUIHTMLSource); | 62 DISALLOW_COPY_AND_ASSIGN(PluginsUIHTMLSource); |
| 64 }; | 63 }; |
| 65 | 64 |
| 65 PluginsUIHTMLSource::PluginsUIHTMLSource() |
| 66 : ChromeWebUIDataSource(chrome::kChromeUIPluginsHost) { |
| 67 AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); |
| 68 AddLocalizedString("pluginsDetailsModeLink", |
| 69 IDS_PLUGINS_DETAILS_MODE_LINK); |
| 70 AddLocalizedString("pluginsNoneInstalled", IDS_PLUGINS_NONE_INSTALLED); |
| 71 AddLocalizedString("pluginDisabled", IDS_PLUGINS_DISABLED_PLUGIN); |
| 72 AddLocalizedString("pluginDisabledByPolicy", |
| 73 IDS_PLUGINS_DISABLED_BY_POLICY_PLUGIN); |
| 74 AddLocalizedString("pluginCannotBeEnabledDueToPolicy", |
| 75 IDS_PLUGINS_CANNOT_ENABLE_DUE_TO_POLICY); |
| 76 AddLocalizedString("pluginEnabledByPolicy", |
| 77 IDS_PLUGINS_ENABLED_BY_POLICY_PLUGIN); |
| 78 AddLocalizedString("pluginCannotBeDisabledDueToPolicy", |
| 79 IDS_PLUGINS_CANNOT_DISABLE_DUE_TO_POLICY); |
| 80 AddLocalizedString("pluginDownload", IDS_PLUGINS_DOWNLOAD); |
| 81 AddLocalizedString("pluginName", IDS_PLUGINS_NAME); |
| 82 AddLocalizedString("pluginVersion", IDS_PLUGINS_VERSION); |
| 83 AddLocalizedString("pluginDescription", IDS_PLUGINS_DESCRIPTION); |
| 84 AddLocalizedString("pluginPath", IDS_PLUGINS_PATH); |
| 85 AddLocalizedString("pluginMimeTypes", IDS_PLUGINS_MIME_TYPES); |
| 86 AddLocalizedString("pluginMimeTypesMimeType", |
| 87 IDS_PLUGINS_MIME_TYPES_MIME_TYPE); |
| 88 AddLocalizedString("pluginMimeTypesDescription", |
| 89 IDS_PLUGINS_MIME_TYPES_DESCRIPTION); |
| 90 AddLocalizedString("pluginMimeTypesFileExtensions", |
| 91 IDS_PLUGINS_MIME_TYPES_FILE_EXTENSIONS); |
| 92 AddLocalizedString("disable", IDS_PLUGINS_DISABLE); |
| 93 AddLocalizedString("enable", IDS_PLUGINS_ENABLE); |
| 94 AddLocalizedString("noPlugins", IDS_PLUGINS_NO_PLUGINS); |
| 95 } |
| 96 |
| 66 void PluginsUIHTMLSource::StartDataRequest(const std::string& path, | 97 void PluginsUIHTMLSource::StartDataRequest(const std::string& path, |
| 67 bool is_incognito, | 98 bool is_incognito, |
| 68 int request_id) { | 99 int request_id) { |
| 69 // Strings used in the JsTemplate file. | 100 if (path == kStringsJsFile) { |
| 70 DictionaryValue localized_strings; | 101 SendLocalizedStringsAsJSON(request_id); |
| 71 localized_strings.SetString("pluginsTitle", | 102 } else { |
| 72 l10n_util::GetStringUTF16(IDS_PLUGINS_TITLE)); | 103 int idr = (path == kPluginsJsFile) ? IDR_PLUGINS_JS : IDR_PLUGINS_HTML; |
| 73 localized_strings.SetString("pluginsDetailsModeLink", | 104 SendFromResourceBundle(request_id, idr); |
| 74 l10n_util::GetStringUTF16(IDS_PLUGINS_DETAILS_MODE_LINK)); | 105 } |
| 75 localized_strings.SetString("pluginsNoneInstalled", | 106 } |
| 76 l10n_util::GetStringUTF16(IDS_PLUGINS_NONE_INSTALLED)); | |
| 77 localized_strings.SetString("pluginDisabled", | |
| 78 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN)); | |
| 79 localized_strings.SetString("pluginDisabledByPolicy", | |
| 80 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_BY_POLICY_PLUGIN)); | |
| 81 localized_strings.SetString("pluginCannotBeEnabledDueToPolicy", | |
| 82 l10n_util::GetStringUTF16(IDS_PLUGINS_CANNOT_ENABLE_DUE_TO_POLICY)); | |
| 83 localized_strings.SetString("pluginEnabledByPolicy", | |
| 84 l10n_util::GetStringUTF16(IDS_PLUGINS_ENABLED_BY_POLICY_PLUGIN)); | |
| 85 localized_strings.SetString("pluginCannotBeDisabledDueToPolicy", | |
| 86 l10n_util::GetStringUTF16(IDS_PLUGINS_CANNOT_DISABLE_DUE_TO_POLICY)); | |
| 87 localized_strings.SetString("pluginDownload", | |
| 88 l10n_util::GetStringUTF16(IDS_PLUGINS_DOWNLOAD)); | |
| 89 localized_strings.SetString("pluginName", | |
| 90 l10n_util::GetStringUTF16(IDS_PLUGINS_NAME)); | |
| 91 localized_strings.SetString("pluginVersion", | |
| 92 l10n_util::GetStringUTF16(IDS_PLUGINS_VERSION)); | |
| 93 localized_strings.SetString("pluginDescription", | |
| 94 l10n_util::GetStringUTF16(IDS_PLUGINS_DESCRIPTION)); | |
| 95 localized_strings.SetString("pluginPath", | |
| 96 l10n_util::GetStringUTF16(IDS_PLUGINS_PATH)); | |
| 97 localized_strings.SetString("pluginMimeTypes", | |
| 98 l10n_util::GetStringUTF16(IDS_PLUGINS_MIME_TYPES)); | |
| 99 localized_strings.SetString("pluginMimeTypesMimeType", | |
| 100 l10n_util::GetStringUTF16(IDS_PLUGINS_MIME_TYPES_MIME_TYPE)); | |
| 101 localized_strings.SetString("pluginMimeTypesDescription", | |
| 102 l10n_util::GetStringUTF16(IDS_PLUGINS_MIME_TYPES_DESCRIPTION)); | |
| 103 localized_strings.SetString("pluginMimeTypesFileExtensions", | |
| 104 l10n_util::GetStringUTF16(IDS_PLUGINS_MIME_TYPES_FILE_EXTENSIONS)); | |
| 105 localized_strings.SetString("disable", | |
| 106 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLE)); | |
| 107 localized_strings.SetString("enable", | |
| 108 l10n_util::GetStringUTF16(IDS_PLUGINS_ENABLE)); | |
| 109 localized_strings.SetString("noPlugins", | |
| 110 l10n_util::GetStringUTF16(IDS_PLUGINS_NO_PLUGINS)); | |
| 111 | 107 |
| 112 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); | 108 std::string PluginsUIHTMLSource::GetMimeType(const std::string& path) const { |
| 109 if (path == kStringsJsFile || path == kPluginsJsFile) |
| 110 return "application/javascript"; |
| 113 | 111 |
| 114 static const base::StringPiece plugins_html( | 112 return "text/html"; |
| 115 ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_PLUGINS_HTML)); | |
| 116 std::string full_html(plugins_html.data(), plugins_html.size()); | |
| 117 jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html); | |
| 118 jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html); | |
| 119 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html); | |
| 120 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); | |
| 121 | |
| 122 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | |
| 123 html_bytes->data.resize(full_html.size()); | |
| 124 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | |
| 125 | |
| 126 SendResponse(request_id, html_bytes); | |
| 127 } | 113 } |
| 128 | 114 |
| 129 //////////////////////////////////////////////////////////////////////////////// | 115 //////////////////////////////////////////////////////////////////////////////// |
| 130 // | 116 // |
| 131 // PluginsDOMHandler | 117 // PluginsDOMHandler |
| 132 // | 118 // |
| 133 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 134 | 120 |
| 135 // The handler for Javascript messages for the chrome://plugins/ page. | 121 // The handler for Javascript messages for the chrome://plugins/ page. |
| 136 // TODO(viettrungluu): Make plugin list updates notify, and then observe | 122 // TODO(viettrungluu): Make plugin list updates notify, and then observe |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, | 359 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, |
| 374 false, | 360 false, |
| 375 PrefService::UNSYNCABLE_PREF); | 361 PrefService::UNSYNCABLE_PREF); |
| 376 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 362 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
| 377 false, | 363 false, |
| 378 PrefService::UNSYNCABLE_PREF); | 364 PrefService::UNSYNCABLE_PREF); |
| 379 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 365 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
| 380 true, | 366 true, |
| 381 PrefService::UNSYNCABLE_PREF); | 367 PrefService::UNSYNCABLE_PREF); |
| 382 } | 368 } |
| OLD | NEW |