diff options
author | stevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-26 00:18:12 +0000 |
---|---|---|
committer | stevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-26 00:18:12 +0000 |
commit | 0eeeba6d4db597c734ea84b299aa9ab138a13fdf (patch) | |
tree | 85d35e5f56997d76fe58c5a8657671a948edf493 /chrome | |
parent | f72804892c91e5f45074922af62f9ec60f8b1e38 (diff) | |
download | chromium_src-0eeeba6d4db597c734ea84b299aa9ab138a13fdf.zip chromium_src-0eeeba6d4db597c734ea84b299aa9ab138a13fdf.tar.gz chromium_src-0eeeba6d4db597c734ea84b299aa9ab138a13fdf.tar.bz2 |
Refactor the about:version code out of about_ui.
BUG=None
TEST=No user visible changes in about:version.
Review URL: https://chromiumcodereview.appspot.com/10916182
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158699 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/resources/about_version.html | 27 | ||||
-rw-r--r-- | chrome/browser/resources/about_version.js | 35 | ||||
-rw-r--r-- | chrome/browser/ui/webui/about_ui.cc | 283 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_data_source.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_data_source.h | 8 | ||||
-rw-r--r-- | chrome/browser/ui/webui/version_handler.cc | 152 | ||||
-rw-r--r-- | chrome/browser/ui/webui/version_handler.h | 45 | ||||
-rw-r--r-- | chrome/browser/ui/webui/version_handler_chromeos.cc | 30 | ||||
-rw-r--r-- | chrome/browser/ui/webui/version_handler_chromeos.h | 37 | ||||
-rw-r--r-- | chrome/browser/ui/webui/version_ui.cc | 136 | ||||
-rw-r--r-- | chrome/browser/ui/webui/version_ui.h | 19 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 6 |
13 files changed, 488 insertions, 301 deletions
diff --git a/chrome/browser/resources/about_version.html b/chrome/browser/resources/about_version.html index 45ab5b2..fa72761c 100644 --- a/chrome/browser/resources/about_version.html +++ b/chrome/browser/resources/about_version.html @@ -14,6 +14,8 @@ about:version template page <if expr="pp_ifdef('android')"> <link rel="stylesheet" href="about_version_android.css"> </if> + <script src="chrome://resources/js/cr.js"></script> + <script src="chrome://resources/js/load_time_data.js"></script> <script src="chrome://resources/js/parse_html_subset.js"></script> <script src="chrome://resources/js/util.js"></script> <script src="chrome://version/version.js"></script> @@ -34,22 +36,35 @@ about:version template page </div> <table id="inner" cellpadding="0" cellspacing="0" border="0"> <tr><td class="label" valign="top" id="name" i18n-content="name"></td> - <td class="version" id="version"><span i18n-content="version"></span> (<span i18n-content="official"></span> <span i18n-content="cl"></span>) <span i18n-content="version_modifier"></span></td> + <td class="version" id="version"> + <span i18n-content="version"></span> + (<span i18n-content="official"> + </span> <span i18n-content="cl"></span>) + <span i18n-content="version_modifier"></span> + </td> </tr> <if expr="not pp_ifdef('chromeos')"> <tr><td class="label" valign="top" i18n-content="os_name"></td> - <td class="version" id="os_type"><span i18n-content="os_type"></span> <span i18n-content="os_version"></span></td> + <td class="version" id="os_type"> + <span i18n-content="os_type"></span> + <span id="os_version" i18n-content="os_version"></span> + </td> </if> <if expr="pp_ifdef('chromeos')"> <tr><td class="label" valign="top" i18n-content="platform"></td> - <td class="version" id="os_type"><span i18n-content="os_version"></span></td> + <td class="version" id="os_type"> + <span id="os_version" i18n-content="os_version"></span> + </td> </if> </tr> <tr><td class="label" valign="top">WebKit</td> <td class="version" id="webkit_version" i18n-content="webkit_version"></td> </tr> <tr><td class="label" valign="top">JavaScript</td> - <td class="version" id="js_engine"><span i18n-content="js_engine"></span> <span i18n-content="js_version"></span></td> + <td class="version" id="js_engine"> + <span i18n-content="js_engine"></span> + <span i18n-content="js_version"></span> + </td> </tr> <if expr="not pp_ifdef('android')"> <tr><td class="label" valign="top" i18n-content="flash_plugin"></td> @@ -74,9 +89,7 @@ about:version template page </tr> </table> </div> - <script src="chrome://resources/js/i18n_template.js"></script> - <script src="chrome://resources/js/i18n_process.js"></script> - <script src="chrome://resources/js/jstemplate_compiled.js"></script> + <script src="chrome://resources/js/i18n_template2.js"></script> </body> </html> diff --git a/chrome/browser/resources/about_version.js b/chrome/browser/resources/about_version.js index 88417fe..d971917 100644 --- a/chrome/browser/resources/about_version.js +++ b/chrome/browser/resources/about_version.js @@ -8,20 +8,41 @@ * section if there are none to display. * @param {!Array.<string>} variationsList The list of variations. */ -function returnVariationsList(variationsList) { +function returnVariationInfo(variationsList) { $('variations-section').hidden = !variationsList.length; $('variations-list').appendChild( parseHtmlSubset(variationsList.join('<br>'), ['BR'])); } +/** + * Callback from the backend with the executable and profile paths to display. + * @param {string} execPath The executable path to display. + * @param {string} profilePath The profile path to display. + */ +function returnFilePaths(execPath, profilePath) { + $('executable_path').textContent = execPath; + $('profile_path').textContent = profilePath; +} + +/** + * Callback from the backend with the Flash version to display. + * @param {string} flashVersion The Flash version to display. + */ +function returnFlashVersion(flashVersion) { + $('flash_version').textContent = flashVersion; +} + +/** + * Callback from the backend with the OS version to display. + * @param {string} osVersion The OS version to display. + */ +function returnOsVersion(osVersion) { + $('os_version').textContent = osVersion; +} + /* All the work we do onload. */ function onLoadWork() { - // This is the javascript code that processes the template: - var input = new JsEvalContext(templateData); - var output = $('t'); - jstProcess(input, output); - - chrome.send('requestVariationsList'); + chrome.send('requestVersionInfo'); } document.addEventListener('DOMContentLoaded', onLoadWork); diff --git a/chrome/browser/ui/webui/about_ui.cc b/chrome/browser/ui/webui/about_ui.cc index 69262e5..899e33c 100644 --- a/chrome/browser/ui/webui/about_ui.cc +++ b/chrome/browser/ui/webui/about_ui.cc @@ -16,15 +16,12 @@ #include "base/file_util.h" #include "base/i18n/number_formatting.h" #include "base/json/json_writer.h" -#include "base/memory/ref_counted_memory.h" #include "base/memory/singleton.h" -#include "base/metrics/field_trial.h" #include "base/metrics/statistics_recorder.h" #include "base/metrics/stats_table.h" #include "base/path_service.h" #include "base/string_number_conversions.h" #include "base/string_piece.h" -#include "base/string_split.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/threading/thread.h" @@ -37,25 +34,19 @@ #include "chrome/browser/memory_details.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/net/url_fixer_upper.h" -#include "chrome/browser/plugins/plugin_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_version_info.h" #include "chrome/common/jstemplate_builder.h" -#include "chrome/common/metrics/variations/variations_util.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/plugin_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" -#include "content/public/browser/web_ui.h" -#include "content/public/browser/web_ui_message_handler.h" #include "content/public/common/content_client.h" #include "content/public/common/process_type.h" #include "google_apis/gaia/google_service_auth_error.h" @@ -69,10 +60,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/layout.h" #include "ui/base/resource/resource_bundle.h" -#include "v8/include/v8.h" -#include "webkit/glue/webkit_glue.h" -#include "webkit/plugins/webplugininfo.h" -#include "webkit/user_agent/user_agent_util.h" #if defined(ENABLE_THEMES) #include "chrome/browser/ui/webui/theme_source.h" @@ -93,7 +80,6 @@ #include "chrome/browser/chromeos/customization_document.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/oom_priority_manager.h" -#include "chrome/browser/chromeos/version_loader.h" #endif #if defined(USE_ASH) @@ -104,7 +90,6 @@ using base::Time; using base::TimeDelta; using content::BrowserThread; -using content::PluginService; using content::WebContents; namespace { @@ -113,7 +98,6 @@ const char kCreditsJsPath[] = "credits.js"; const char kMemoryJsPath[] = "memory.js"; const char kStatsJsPath[] = "stats.js"; const char kStringsJsPath[] = "strings.js"; -const char kVersionJsPath[] = "version.js"; // When you type about:memory, it actually loads this intermediate URL that // redirects you to the final page. This avoids the problem where typing @@ -156,34 +140,6 @@ class AboutMemoryHandler : public MemoryDetails { }; #if defined(OS_CHROMEOS) -// ChromeOSAboutVersionHandler is responsible for loading the Chrome OS -// version. -// ChromeOSAboutVersionHandler handles deleting itself once the version has -// been obtained and AboutUIHTMLSource notified. -class ChromeOSAboutVersionHandler { - public: - ChromeOSAboutVersionHandler(AboutUIHTMLSource* source, int request_id); - - // Callback from chromeos::VersionLoader giving the version. - void OnVersion(chromeos::VersionLoader::Handle handle, - const std::string& version); - - private: - // Where the results are fed to. - scoped_refptr<AboutUIHTMLSource> source_; - - // ID identifying the request. - int request_id_; - - // Handles asynchronously loading the version. - chromeos::VersionLoader loader_; - - // Used to request the version. - CancelableRequestConsumer consumer_; - - DISALLOW_COPY_AND_ASSIGN(ChromeOSAboutVersionHandler); -}; - class ChromeOSTermsHandler : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { public: @@ -1006,137 +962,6 @@ std::string AboutSandbox() { } #endif -std::string AboutVersionStaticContent(const std::string& query) { - return ResourceBundle::GetSharedInstance().GetRawDataResource( - query == kVersionJsPath ? - IDR_ABOUT_VERSION_JS : - IDR_ABOUT_VERSION_HTML, ui::SCALE_FACTOR_NONE).as_string(); -} - -std::string AboutVersionStrings(DictionaryValue* localized_strings, - Profile* profile) { - DCHECK(profile); - localized_strings->SetString("title", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_TITLE)); - chrome::VersionInfo version_info; - - localized_strings->SetString("name", - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - localized_strings->SetString("version", version_info.Version()); - // Bug 79458: Need to evaluate the use of getting the version string on - // this thread. - base::ThreadRestrictions::ScopedAllowIO allow_io; - localized_strings->SetString("version_modifier", - chrome::VersionInfo::GetVersionStringModifier()); - localized_strings->SetString("os_name", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS)); - localized_strings->SetString("platform", - l10n_util::GetStringUTF16(IDS_PLATFORM_LABEL)); - localized_strings->SetString("os_type", version_info.OSType()); - localized_strings->SetString("webkit_version", - webkit_glue::GetWebKitVersion()); - localized_strings->SetString("js_engine", "V8"); - localized_strings->SetString("js_version", v8::V8::GetVersion()); - -#if !defined(OS_ANDROID) - // Obtain the version of the first enabled Flash plugin. - std::vector<webkit::WebPluginInfo> info_array; - PluginService::GetInstance()->GetPluginInfoArray( - GURL(), "application/x-shockwave-flash", false, &info_array, NULL); - string16 flash_version = - l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); - PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); - if (plugin_prefs) { - for (size_t i = 0; i < info_array.size(); ++i) { - if (plugin_prefs->IsPluginEnabled(info_array[i])) { - flash_version = info_array[i].version; - break; - } - } - } - localized_strings->SetString("flash_plugin", "Flash"); - localized_strings->SetString("flash_version", flash_version); -#endif - localized_strings->SetString("company", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMPANY_NAME)); - localized_strings->SetString("copyright", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COPYRIGHT)); - localized_strings->SetString("cl", version_info.LastChange()); - localized_strings->SetString("official", - l10n_util::GetStringUTF16( - version_info.IsOfficialBuild() ? - IDS_ABOUT_VERSION_OFFICIAL - : IDS_ABOUT_VERSION_UNOFFICIAL)); - localized_strings->SetString("user_agent_name", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_USER_AGENT)); - localized_strings->SetString("useragent", content::GetUserAgent(GURL())); - localized_strings->SetString("command_line_name", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_COMMAND_LINE)); - -#if defined(OS_WIN) - localized_strings->SetString("command_line", - WideToUTF16(CommandLine::ForCurrentProcess()->GetCommandLineString())); -#elif defined(OS_POSIX) - std::string command_line = ""; - typedef std::vector<std::string> ArgvList; - const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); - for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) - command_line += " " + *iter; - // TODO(viettrungluu): |command_line| could really have any encoding, whereas - // below we assumes it's UTF-8. - localized_strings->SetString("command_line", command_line); -#endif - - // Allow IO temporarily based on allow_io (defined above) - // since the following operation will complete quickly - localized_strings->SetString("executable_path_name", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_EXECUTABLE_PATH)); - FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram(); - if (file_util::AbsolutePath(&executable_path)) { - localized_strings->SetString("executable_path", executable_path.value()); - } else { - localized_strings->SetString("executable_path", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); - } - localized_strings->SetString("profile_path_name", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PROFILE_PATH)); - if (profile) { - FilePath profile_path = profile->GetPath(); - if (file_util::AbsolutePath(&profile_path)) { - localized_strings->SetString("profile_path", profile_path.value()); - } else { - localized_strings->SetString("profile_path", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); - } - } else { - localized_strings->SetString("profile_path", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND)); - } - ChromeWebUIDataSource::SetFontAndTextDirection(localized_strings); - - localized_strings->SetString("variations_name", - l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_VARIATIONS)); - - std::string data; - jstemplate_builder::AppendJsonJS(localized_strings, &data); - return data; -} - -// Used as a callback for PluginService::GetPlugins(). -void HandleAboutVersionStrings(AboutUIHTMLSource* source, - int request_id, - const std::vector<webkit::WebPluginInfo>&) { -#if defined(OS_CHROMEOS) - new ChromeOSAboutVersionHandler(source, request_id); -#else - DictionaryValue localized_strings; - localized_strings.SetString("os_version", ""); - source->FinishDataRequest( - AboutVersionStrings(&localized_strings, source->profile()), - request_id); -#endif -} - // AboutMemoryHandler ---------------------------------------------------------- // Helper for AboutMemory to bind results from a ProcessMetrics object @@ -1182,7 +1007,6 @@ void AboutMemoryHandler::AppendProcess(ListValue* child_data, titles->Append(new StringValue(info->titles[i])); } - void AboutMemoryHandler::OnDetailsAvailable() { // the root of the JSON hierarchy for about:memory jstemplate DictionaryValue root; @@ -1267,99 +1091,6 @@ void AboutMemoryHandler::OnDetailsAvailable() { source_->FinishDataRequest(data, request_id_); } -#if defined(OS_CHROMEOS) -// ChromeOSAboutVersionHandler ----------------------------------------------- - -ChromeOSAboutVersionHandler::ChromeOSAboutVersionHandler( - AboutUIHTMLSource* source, - int request_id) - : source_(source), - request_id_(request_id) { - loader_.GetVersion(&consumer_, - base::Bind(&ChromeOSAboutVersionHandler::OnVersion, - base::Unretained(this)), - chromeos::VersionLoader::VERSION_FULL); -} - -void ChromeOSAboutVersionHandler::OnVersion( - chromeos::VersionLoader::Handle handle, - const std::string& version) { - DictionaryValue localized_strings; - localized_strings.SetString("os_version", version); - source_->FinishDataRequest(AboutVersionStrings( - &localized_strings, source_->profile()), request_id_); - - // CancelableRequestProvider isn't happy when it's deleted and servicing a - // task, so we delay the deletion. - MessageLoop::current()->DeleteSoon(FROM_HERE, this); -} - -#endif - -class VersionDOMHandler : public content::WebUIMessageHandler { - public: - VersionDOMHandler(); - virtual ~VersionDOMHandler(); - - // content::WebUIMessageHandler implementation. - virtual void RegisterMessages() OVERRIDE; - - // Callback for the "requestVariationsList" message. This requests the list of - // variations from the client and sends it to the frontend. - void HandleRequestVariationsList(const ListValue* args); - - private: - DISALLOW_COPY_AND_ASSIGN(VersionDOMHandler); -}; - -VersionDOMHandler::VersionDOMHandler() { -} - -VersionDOMHandler::~VersionDOMHandler() { -} - -void VersionDOMHandler::RegisterMessages() { - web_ui()->RegisterMessageCallback( - "requestVariationsList", - base::Bind(&VersionDOMHandler::HandleRequestVariationsList, - base::Unretained(this))); -} - -void VersionDOMHandler::HandleRequestVariationsList(const ListValue* args) { - scoped_ptr<ListValue> variations_list(new ListValue()); - std::vector<std::string> variations; -#if !defined(NDEBUG) - std::string variation_state; - base::FieldTrialList::StatesToString(&variation_state); - - std::vector<std::string> tokens; - base::SplitString(variation_state, - base::FieldTrialList::kPersistentStringSeparator, - &tokens); - // Since StatesToString appends a separator at the end, SplitString will - // append an extra empty string in the vector. Drop it. There should - // always be an even number of tokens left. - tokens.pop_back(); - DCHECK_EQ(0U, tokens.size() % 2); - for (size_t i = 0; i < tokens.size(); i += 2) - variations.push_back(tokens[i] + ":" + tokens[i + 1]); -#else - // In release mode, display the hashes only. - std::vector<string16> selected_groups; - chrome_variations::GetFieldTrialSelectedGroupIdsAsStrings(&selected_groups); - for (size_t i = 0; i < selected_groups.size(); ++i) - variations.push_back(UTF16ToASCII(selected_groups[i])); -#endif - - for (std::vector<std::string>::const_iterator it = variations.begin(); - it != variations.end(); ++it) { - variations_list->Append(Value::CreateStringValue(*it)); - } - - web_ui()->CallJavascriptFunction("returnVariationsList", - *variations_list.release()); -} - } // namespace // AboutUIHTMLSource ---------------------------------------------------------- @@ -1425,17 +1156,6 @@ void AboutUIHTMLSource::StartDataRequest(const std::string& path, #else response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); #endif - } else if (host == chrome::kChromeUIVersionHost) { - if (path == kStringsJsPath) { - // The Flash version information is needed on this page, so make sure - // the plugins are loaded. - PluginService::GetInstance()->GetPlugins( - base::Bind(&HandleAboutVersionStrings, - make_scoped_refptr(this), request_id)); - return; - } else { - response = AboutVersionStaticContent(path); - } } FinishDataRequest(response, request_id); @@ -1451,7 +1171,6 @@ std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { if (path == kCreditsJsPath || path == kStatsJsPath || path == kStringsJsPath || - path == kVersionJsPath || path == kMemoryJsPath) { return "application/javascript"; } @@ -1468,8 +1187,6 @@ AboutUI::AboutUI(content::WebUI* web_ui, const std::string& name) ChromeURLDataManager::AddDataSource(profile, theme); #endif - web_ui->AddMessageHandler(new VersionDOMHandler()); - ChromeURLDataManager::DataSource* source = new AboutUIHTMLSource(name, profile); if (source) { diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index 00dc376..0908c89 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -51,6 +51,7 @@ #include "chrome/browser/ui/webui/task_manager/task_manager_ui.h" #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" #include "chrome/browser/ui/webui/tracing_ui.h" +#include "chrome/browser/ui/webui/version_ui.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_switch_utils.h" @@ -222,6 +223,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, return &NewWebUI<SyncInternalsUI>; if (url.host() == chrome::kChromeUISyncResourcesHost) return &NewWebUI<WebDialogUI>; + if (url.host() == chrome::kChromeUIVersionHost) + return &NewWebUI<VersionUI>; /**************************************************************************** * OS Specific #defines @@ -362,8 +365,7 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, url.host() == chrome::kChromeUIMemoryHost || url.host() == chrome::kChromeUIMemoryRedirectHost || url.host() == chrome::kChromeUIStatsHost || - url.host() == chrome::kChromeUITermsHost || - url.host() == chrome::kChromeUIVersionHost + url.host() == chrome::kChromeUITermsHost #if defined(OS_LINUX) || defined(OS_OPENBSD) || url.host() == chrome::kChromeUILinuxProxyConfigHost || url.host() == chrome::kChromeUISandboxHost diff --git a/chrome/browser/ui/webui/chrome_web_ui_data_source.cc b/chrome/browser/ui/webui/chrome_web_ui_data_source.cc index 1fa1457..69c61f2 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_data_source.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_data_source.cc @@ -34,6 +34,11 @@ void ChromeWebUIDataSource::AddString(const std::string& name, localized_strings_.SetString(name, value); } +void ChromeWebUIDataSource::AddString(const std::string& name, + const std::string& value) { + localized_strings_.SetString(name, value); +} + void ChromeWebUIDataSource::AddLocalizedString(const std::string& name, int ids) { localized_strings_.SetString(name, l10n_util::GetStringUTF16(ids)); diff --git a/chrome/browser/ui/webui/chrome_web_ui_data_source.h b/chrome/browser/ui/webui/chrome_web_ui_data_source.h index 8b38260..83376c0 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_data_source.h +++ b/chrome/browser/ui/webui/chrome_web_ui_data_source.h @@ -21,10 +21,14 @@ class ChromeWebUIDataSource : public ChromeURLDataManager::DataSource { explicit ChromeWebUIDataSource(const std::string& source_name); ChromeWebUIDataSource(const std::string& source_name, MessageLoop* loop); - // Adds a string and its equivalent to our dictionary. + // Adds a string keyed to its name to our dictionary. void AddString(const std::string& name, const string16& value); - // Adds a name and its equivaled localized string to our dictionary. + // Adds a string keyed to its name to our dictionary. + void AddString(const std::string& name, const std::string& value); + + // Adds a localized string with resource |ids| keyed to its name to our + // dictionary. void AddLocalizedString(const std::string& name, int ids); // Add strings from |localized_strings| to our dictionary. diff --git a/chrome/browser/ui/webui/version_handler.cc b/chrome/browser/ui/webui/version_handler.cc new file mode 100644 index 0000000..73988d7 --- /dev/null +++ b/chrome/browser/ui/webui/version_handler.cc @@ -0,0 +1,152 @@ +// Copyright (c) 2012 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/version_handler.h" + +#include "base/command_line.h" +#include "base/file_util.h" +#include "base/metrics/field_trial.h" +#include "base/string_split.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/plugins/plugin_prefs.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/metrics/variations/variations_util.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/plugin_service.h" +#include "content/public/browser/web_ui.h" +#include "googleurl/src/gurl.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +namespace { + +// Retrieves the executable and profile paths on the FILE thread. +void GetFilePaths(const FilePath& profile_path, + string16* exec_path_out, + string16* profile_path_out) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); + + FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram(); + if (file_util::AbsolutePath(&executable_path)) { + *exec_path_out = executable_path.LossyDisplayName(); + } else { + *exec_path_out = + l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND); + } + + FilePath profile_path_copy(profile_path); + if (!profile_path.empty() && file_util::AbsolutePath(&profile_path_copy)) { + *profile_path_out = profile_path.LossyDisplayName(); + } else { + *profile_path_out = + l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND); + } +} + +} // namespace + +VersionHandler::VersionHandler() + : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { +} + +VersionHandler::~VersionHandler() { +} + +void VersionHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback( + "requestVersionInfo", + base::Bind(&VersionHandler::HandleRequestVersionInfo, + base::Unretained(this))); +} + +void VersionHandler::HandleRequestVersionInfo(const ListValue* args) { + // The Flash version information is needed in the response, so make sure + // the plugins are loaded. + content::PluginService::GetInstance()->GetPlugins( + base::Bind(&VersionHandler::OnGotPlugins, + weak_ptr_factory_.GetWeakPtr())); + + // Grab the executable path on the FILE thread. It is returned in + // OnGotFilePaths. + string16* exec_path_buffer = new string16; + string16* profile_path_buffer = new string16; + content::BrowserThread::PostTaskAndReply( + content::BrowserThread::FILE, FROM_HERE, + base::Bind(&GetFilePaths, Profile::FromWebUI(web_ui())->GetPath(), + base::Unretained(exec_path_buffer), + base::Unretained(profile_path_buffer)), + base::Bind(&VersionHandler::OnGotFilePaths, + weak_ptr_factory_.GetWeakPtr(), + base::Owned(exec_path_buffer), + base::Owned(profile_path_buffer))); + + // Respond with the variations info immediately. + scoped_ptr<ListValue> variations_list(new ListValue()); + std::vector<std::string> variations; +#if !defined(NDEBUG) + std::string variation_state; + base::FieldTrialList::StatesToString(&variation_state); + + std::vector<std::string> tokens; + base::SplitString(variation_state, + base::FieldTrialList::kPersistentStringSeparator, + &tokens); + // Since StatesToString appends a separator at the end, SplitString will + // append an extra empty string in the vector. Drop it. There should + // always be an even number of tokens left. + tokens.pop_back(); + DCHECK_EQ(0U, tokens.size() % 2); + for (size_t i = 0; i < tokens.size(); i += 2) + variations.push_back(tokens[i] + ":" + tokens[i + 1]); +#else + // In release mode, display the hashes only. + std::vector<string16> selected_groups; + chrome_variations::GetFieldTrialSelectedGroupIdsAsStrings(&selected_groups); + for (size_t i = 0; i < selected_groups.size(); ++i) + variations.push_back(UTF16ToASCII(selected_groups[i])); +#endif + + for (std::vector<std::string>::const_iterator it = variations.begin(); + it != variations.end(); ++it) { + variations_list->Append(Value::CreateStringValue(*it)); + } + + // In release mode, this will return an empty list to clear the section. + web_ui()->CallJavascriptFunction("returnVariationInfo", + *variations_list.release()); +} + +void VersionHandler::OnGotFilePaths(string16* executable_path_data, + string16* profile_path_data) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + + StringValue exec_path(*executable_path_data); + StringValue profile_path(*profile_path_data); + web_ui()->CallJavascriptFunction("returnFilePaths", exec_path, profile_path); +} + +void VersionHandler::OnGotPlugins( + const std::vector<webkit::WebPluginInfo>& plugins) { +#if !defined(OS_ANDROID) + // Obtain the version of the first enabled Flash plugin. + std::vector<webkit::WebPluginInfo> info_array; + content::PluginService::GetInstance()->GetPluginInfoArray( + GURL(), "application/x-shockwave-flash", false, &info_array, NULL); + string16 flash_version = + l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); + PluginPrefs* plugin_prefs = + PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())); + if (plugin_prefs) { + for (size_t i = 0; i < info_array.size(); ++i) { + if (plugin_prefs->IsPluginEnabled(info_array[i])) { + flash_version = info_array[i].version; + break; + } + } + } + + StringValue arg(flash_version); + web_ui()->CallJavascriptFunction("returnFlashVersion", arg); +#endif +} diff --git a/chrome/browser/ui/webui/version_handler.h b/chrome/browser/ui/webui/version_handler.h new file mode 100644 index 0000000..a8f5b11 --- /dev/null +++ b/chrome/browser/ui/webui/version_handler.h @@ -0,0 +1,45 @@ +// Copyright (c) 2012 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_VERSION_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_VERSION_HANDLER_H_ + +#include <vector> + +#include "base/memory/weak_ptr.h" +#include "base/values.h" +#include "content/public/browser/web_ui_message_handler.h" +#include "webkit/plugins/webplugininfo.h" + +// Handler class for Version page operations. +class VersionHandler : public content::WebUIMessageHandler { + public: + VersionHandler(); + virtual ~VersionHandler(); + + // content::WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; + + // Callback for the "requestVersionInfo" message. This asynchronously requests + // the flash version and eventually returns it to the front end along with the + // list of variations using OnGotPlugins. + virtual void HandleRequestVersionInfo(const ListValue* args); + + private: + // Callback which handles returning the executable and profile paths to the + // front end. + void OnGotFilePaths(string16* executable_path_data, + string16* profile_path_data); + + // Callback for GetPlugins which responds to the page with the Flash version. + // This also initiates the OS Version load on ChromeOS. + void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins); + + // Factory for the creating refs in callbacks. + base::WeakPtrFactory<VersionHandler> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(VersionHandler); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_VERSION_HANDLER_H_ diff --git a/chrome/browser/ui/webui/version_handler_chromeos.cc b/chrome/browser/ui/webui/version_handler_chromeos.cc new file mode 100644 index 0000000..9a0fcf6 --- /dev/null +++ b/chrome/browser/ui/webui/version_handler_chromeos.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2012 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/version_handler_chromeos.h" + +#include "content/public/browser/web_ui.h" + +VersionHandlerChromeOS::VersionHandlerChromeOS() { +} + +VersionHandlerChromeOS::~VersionHandlerChromeOS() { +} + +void VersionHandlerChromeOS::HandleRequestVersionInfo(const ListValue* args) { + // Start the asynchronous load of the version. + loader_.GetVersion(&consumer_, + base::Bind(&VersionHandlerChromeOS::OnVersion, + base::Unretained(this)), + chromeos::VersionLoader::VERSION_FULL); + + // Parent class takes care of the rest. + VersionHandler::HandleRequestVersionInfo(args); +} + +void VersionHandlerChromeOS::OnVersion(chromeos::VersionLoader::Handle handle, + const std::string& version) { + StringValue arg(version); + web_ui()->CallJavascriptFunction("returnOsVersion", arg); +} diff --git a/chrome/browser/ui/webui/version_handler_chromeos.h b/chrome/browser/ui/webui/version_handler_chromeos.h new file mode 100644 index 0000000..cb4ce2f --- /dev/null +++ b/chrome/browser/ui/webui/version_handler_chromeos.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 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_VERSION_HANDLER_CHROMEOS_H_ +#define CHROME_BROWSER_UI_WEBUI_VERSION_HANDLER_CHROMEOS_H_ + +#include <string> + +#include "chrome/browser/chromeos/version_loader.h" +#include "chrome/browser/ui/webui/version_handler.h" + +// VersionHandlerChromeOS is responsible for loading the Chrome OS +// version. +class VersionHandlerChromeOS : public VersionHandler { + public: + VersionHandlerChromeOS(); + virtual ~VersionHandlerChromeOS(); + + // VersionHandler overrides: + virtual void HandleRequestVersionInfo(const ListValue* args) OVERRIDE; + + // Callback from chromeos::VersionLoader giving the version. + void OnVersion(chromeos::VersionLoader::Handle handle, + const std::string& version); + + private: + // Handles asynchronously loading the version. + chromeos::VersionLoader loader_; + + // Used to request the version. + CancelableRequestConsumer consumer_; + + DISALLOW_COPY_AND_ASSIGN(VersionHandlerChromeOS); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_VERSION_HANDLER_CHROMEOS_H_ diff --git a/chrome/browser/ui/webui/version_ui.cc b/chrome/browser/ui/webui/version_ui.cc new file mode 100644 index 0000000..80d35cf --- /dev/null +++ b/chrome/browser/ui/webui/version_ui.cc @@ -0,0 +1,136 @@ +// Copyright (c) 2012 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/version_ui.h" + +#include "base/command_line.h" +#include "base/file_util.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/chrome_url_data_manager.h" +#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" +#include "chrome/browser/ui/webui/version_handler.h" +#include "chrome/common/chrome_version_info.h" +#include "chrome/common/jstemplate_builder.h" +#include "chrome/common/url_constants.h" +#include "content/public/browser/web_ui.h" +#include "content/public/common/content_client.h" +#include "grit/browser_resources.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "grit/google_chrome_strings.h" +#include "v8/include/v8.h" +#include "webkit/user_agent/user_agent_util.h" + +#if defined(ENABLE_THEMES) +#include "chrome/browser/ui/webui/theme_source.h" +#endif + +#if defined(OS_CHROMEOS) +#include "chrome/browser/ui/webui/version_handler_chromeos.h" +#endif + +namespace { + +ChromeWebUIDataSource* CreateVersionUIDataSource(Profile* profile) { + ChromeWebUIDataSource* html_source = + new ChromeWebUIDataSource(chrome::kChromeUIVersionHost); + + // Localized and data strings. + html_source->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE); + html_source->AddLocalizedString("name", IDS_PRODUCT_NAME); + chrome::VersionInfo version_info; + html_source->AddString("version", version_info.Version()); + { + // http://crbug.com/79458: Need to evaluate the use of getting the version + // string on this thread. + base::ThreadRestrictions::ScopedAllowIO allow_io; + html_source->AddString("version_modifier", + chrome::VersionInfo::GetVersionStringModifier()); + } + html_source->AddLocalizedString("os_name", IDS_ABOUT_VERSION_OS); + html_source->AddLocalizedString("platform", IDS_PLATFORM_LABEL); + html_source->AddString("os_type", version_info.OSType()); + html_source->AddString("os_version", std::string()); + html_source->AddString("webkit_version", webkit_glue::GetWebKitVersion()); + html_source->AddString("js_engine", "V8"); + html_source->AddString("js_version", v8::V8::GetVersion()); + +#if !defined(OS_ANDROID) + html_source->AddString("flash_plugin", "Flash"); + // Note that the Flash version is retrieve asynchronously and returned in + // VersionHandler::OnGotPlugins. The area is initially blank. + html_source->AddString("flash_version", std::string()); +#endif + html_source->AddLocalizedString("company", IDS_ABOUT_VERSION_COMPANY_NAME); + html_source->AddLocalizedString("copyright", IDS_ABOUT_VERSION_COPYRIGHT); + html_source->AddString("cl", version_info.LastChange()); + html_source->AddLocalizedString("official", + version_info.IsOfficialBuild() ? IDS_ABOUT_VERSION_OFFICIAL : + IDS_ABOUT_VERSION_UNOFFICIAL); + html_source->AddLocalizedString("user_agent_name", + IDS_ABOUT_VERSION_USER_AGENT); + html_source->AddString("useragent", content::GetUserAgent(GURL())); + html_source->AddLocalizedString("command_line_name", + IDS_ABOUT_VERSION_COMMAND_LINE); + +#if defined(OS_WIN) + html_source->AddString("command_line", + WideToUTF16(CommandLine::ForCurrentProcess()->GetCommandLineString())); +#elif defined(OS_POSIX) + std::string command_line = ""; + typedef std::vector<std::string> ArgvList; + const ArgvList& argv = CommandLine::ForCurrentProcess()->argv(); + for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++) + command_line += " " + *iter; + // TODO(viettrungluu): |command_line| could really have any encoding, whereas + // below we assumes it's UTF-8. + html_source->AddString("command_line", command_line); +#endif + + // Note that the executable path and profile path are retrieved asynchronously + // and returned in VersionHandler::OnGotFilePaths. The area is initially + // blank. + html_source->AddLocalizedString("executable_path_name", + IDS_ABOUT_VERSION_EXECUTABLE_PATH); + html_source->AddString("executable_path", std::string()); + + html_source->AddLocalizedString("profile_path_name", + IDS_ABOUT_VERSION_PROFILE_PATH); + html_source->AddString("profile_path", std::string()); + + html_source->AddLocalizedString("variations_name", + IDS_ABOUT_VERSION_VARIATIONS); + + html_source->set_use_json_js_format_v2(); + html_source->set_json_path("strings.js"); + html_source->add_resource_path("version.js", IDR_ABOUT_VERSION_JS); + html_source->set_default_resource(IDR_ABOUT_VERSION_HTML); + return html_source; +} + +} // namespace + +VersionUI::VersionUI(content::WebUI* web_ui) + : content::WebUIController(web_ui) { + Profile* profile = Profile::FromWebUI(web_ui); + +#if defined(OS_CHROMEOS) + web_ui->AddMessageHandler(new VersionHandlerChromeOS()); +#else + web_ui->AddMessageHandler(new VersionHandler()); +#endif + +#if defined(ENABLE_THEMES) + // Set up the chrome://theme/ source. + ThemeSource* theme = new ThemeSource(profile); + ChromeURLDataManager::AddDataSource(profile, theme); +#endif + + ChromeURLDataManager::AddDataSource(profile, + CreateVersionUIDataSource(profile)); +} + +VersionUI::~VersionUI() { +} diff --git a/chrome/browser/ui/webui/version_ui.h b/chrome/browser/ui/webui/version_ui.h new file mode 100644 index 0000000..5170665 --- /dev/null +++ b/chrome/browser/ui/webui/version_ui.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 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_VERSION_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_VERSION_UI_H_ + +#include "content/public/browser/web_ui_controller.h" + +// The WebUI handler for chrome://version. +class VersionUI : public content::WebUIController { + public: + explicit VersionUI(content::WebUI* web_ui); + virtual ~VersionUI(); + private: + DISALLOW_COPY_AND_ASSIGN(VersionUI); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_VERSION_UI_H_ diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index bb165da..708109b 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2002,6 +2002,12 @@ 'browser/ui/webui/tracing_ui.h', 'browser/ui/webui/uber/uber_ui.cc', 'browser/ui/webui/uber/uber_ui.h', + 'browser/ui/webui/version_handler.cc', + 'browser/ui/webui/version_handler.h', + 'browser/ui/webui/version_handler_chromeos.cc', + 'browser/ui/webui/version_handler_chromeos.h', + 'browser/ui/webui/version_ui.cc', + 'browser/ui/webui/version_ui.h', 'browser/ui/webui/web_ui_util.cc', 'browser/ui/webui/web_ui_util.h', 'browser/ui/webui/welcome_ui_android.cc', |