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

Unified Diff: chrome/browser/ui/webui/version_ui.cc

Issue 10916182: Refactor the about:version code out of about_ui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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/version_ui.cc
===================================================================
--- chrome/browser/ui/webui/version_ui.cc (revision 0)
+++ chrome/browser/ui/webui/version_ui.cc (revision 0)
@@ -0,0 +1,220 @@
+// 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/metrics/field_trial.h"
+#include "base/string_split.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/plugin_prefs.h"
+#include "chrome/common/chrome_version_info.h"
+#include "chrome/common/url_constants.h"
+#include "content/public/browser/plugin_service.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 "grit/browser_resources.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/google_chrome_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "v8/include/v8.h"
+#include "webkit/glue/user_agent.h"
+#include "webkit/plugins/webplugininfo.h"
+
+namespace {
+
+// Handler class for Version page operations.
+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());
+#if !defined(NDEBUG)
+ std::vector<std::string> variations;
Evan Stade 2012/09/10 09:46:59 declare where it's used.
SteveT 2012/09/10 15:14:57 Added a comment and moved it down closer to the us
+ 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]);
+
+ for (std::vector<std::string>::const_iterator it = variations.begin();
+ it != variations.end(); ++it) {
+ variations_list->Append(Value::CreateStringValue(*it));
+ }
+#endif
+ // In release mode, this will return an empty list to clear the section.
+ web_ui()->CallJavascriptFunction("returnVariationsList",
+ *variations_list.release());
+}
+
+ChromeWebUIDataSource* CreateVersionUIDataSource(Profile* profile) {
+ // Set up the chrome://version source.
+ ChromeWebUIDataSource* html_source =
+ new ChromeWebUIDataSource(chrome::kChromeUIVersionHost);
+ html_source->set_use_json_js_format_v2();
+
+ // Localized and data strings.
+ html_source->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE);
+ chrome::VersionInfo version_info;
+ html_source->AddLocalizedString("name", IDS_PRODUCT_NAME);
+ html_source->AddString("version", ASCIIToUTF16(version_info.Version()));
+ // Bug 79458: Need to evaluate the use of getting the version string on
+ // this thread.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ html_source->AddString("version_modifier",
+ ASCIIToUTF16(chrome::VersionInfo::GetVersionStringModifier()));
+ html_source->AddLocalizedString("os_name", IDS_ABOUT_VERSION_OS);
+ html_source->AddLocalizedString("platform", IDS_PLATFORM_LABEL);
+ html_source->AddString("os_type", ASCIIToUTF16(version_info.OSType()));
+ html_source->AddString("os_version", string16());
+ html_source->AddString("webkit_version",
+ ASCIIToUTF16(webkit_glue::GetWebKitVersion()));
+ html_source->AddString("js_engine", ASCIIToUTF16("V8"));
+ html_source->AddString("js_version", ASCIIToUTF16(v8::V8::GetVersion()));
+
+ // Add required resources.
+ 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);
+
+#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);
+ 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;
+ }
+ }
+ }
+ html_source->AddString("flash_plugin", ASCIIToUTF16("Flash"));
+ html_source->AddString("flash_version", flash_version);
+#endif
+ html_source->AddLocalizedString("company", IDS_ABOUT_VERSION_COMPANY_NAME);
+ html_source->AddLocalizedString("copyright", IDS_ABOUT_VERSION_COPYRIGHT);
+ html_source->AddString("cl", ASCIIToUTF16(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",
+ ASCIIToUTF16(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", ASCIIToUTF16(command_line));
+#endif
+
+ // Allow IO temporarily based on allow_io (defined above)
+ // since the following operation will complete quickly
+ html_source->AddLocalizedString("executable_path_name",
+ IDS_ABOUT_VERSION_EXECUTABLE_PATH);
+ FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
+ if (file_util::AbsolutePath(&executable_path)) {
+ html_source->AddString("executable_path",
+ ASCIIToUTF16(executable_path.value()));
+ } else {
+ html_source->AddLocalizedString("executable_path",
+ IDS_ABOUT_VERSION_PATH_NOTFOUND);
+ }
+ html_source->AddLocalizedString("profile_path_name",
+ IDS_ABOUT_VERSION_PROFILE_PATH);
+ if (profile) {
+ FilePath profile_path = profile->GetPath();
+ if (file_util::AbsolutePath(&profile_path)) {
+ html_source->AddString("profile_path",
+ ASCIIToUTF16(profile_path.value()));
+ } else {
+ html_source->AddLocalizedString("profile_path",
+ IDS_ABOUT_VERSION_PATH_NOTFOUND);
+ }
+ } else {
+ html_source->AddLocalizedString("profile_path",
+ IDS_ABOUT_VERSION_PATH_NOTFOUND);
+ }
+ // TODO(reviewer): Do I need some equivalent to this?
+ // ChromeWebUIDataSource::SetFontAndTextDirection(localized_strings);
+
+#if !defined(NDEBUG)
+ html_source->AddLocalizedString("variations_name",
+ IDS_ABOUT_VERSION_VARIATIONS);
+#endif
+
+ return html_source;
+}
+
+} // namespace
+
+VersionUI::VersionUI(content::WebUI* web_ui)
+ : content::WebUIController(web_ui) {
+ Profile* profile = Profile::FromWebUI(web_ui);
+
+ web_ui->AddMessageHandler(new VersionDOMHandler());
+
+ ChromeURLDataManager::AddDataSource(profile,
+ CreateVersionUIDataSource(profile));
+}
+
+VersionUI::~VersionUI() {
+}
Property changes on: chrome/browser/ui/webui/version_ui.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698