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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/version_ui.h"
6
7 #include "base/command_line.h"
8 #include "base/file_util.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/string_split.h"
11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
14 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
15 #include "chrome/browser/plugin_prefs.h"
16 #include "chrome/common/chrome_version_info.h"
17 #include "chrome/common/url_constants.h"
18 #include "content/public/browser/plugin_service.h"
19 #include "content/public/browser/web_ui.h"
20 #include "content/public/browser/web_ui_message_handler.h"
21 #include "content/public/common/content_client.h"
22 #include "grit/browser_resources.h"
23 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h"
25 #include "grit/google_chrome_strings.h"
26 #include "ui/base/l10n/l10n_util.h"
27 #include "v8/include/v8.h"
28 #include "webkit/glue/user_agent.h"
29 #include "webkit/plugins/webplugininfo.h"
30
31 namespace {
32
33 // Handler class for Version page operations.
34 class VersionDOMHandler : public content::WebUIMessageHandler {
35 public:
36 VersionDOMHandler();
37 virtual ~VersionDOMHandler();
38
39 // content::WebUIMessageHandler implementation.
40 virtual void RegisterMessages() OVERRIDE;
41
42 // Callback for the "requestVariationsList" message. This requests the list of
43 // variations from the client and sends it to the frontend.
44 void HandleRequestVariationsList(const ListValue* args);
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(VersionDOMHandler);
48 };
49
50 VersionDOMHandler::VersionDOMHandler() {
51 }
52
53 VersionDOMHandler::~VersionDOMHandler() {
54 }
55
56 void VersionDOMHandler::RegisterMessages() {
57 web_ui()->RegisterMessageCallback(
58 "requestVariationsList",
59 base::Bind(&VersionDOMHandler::HandleRequestVariationsList,
60 base::Unretained(this)));
61 }
62
63 void VersionDOMHandler::HandleRequestVariationsList(const ListValue* args) {
64 scoped_ptr<ListValue> variations_list(new ListValue());
65 #if !defined(NDEBUG)
66 std::string variation_state;
67 base::FieldTrialList::StatesToString(&variation_state);
68
69 std::vector<std::string> tokens;
70 base::SplitString(variation_state,
71 base::FieldTrialList::kPersistentStringSeparator,
72 &tokens);
73 // Since StatesToString appends a separator at the end, SplitString will
74 // append an extra empty string in the vector. Drop it. There should
75 // always be an even number of tokens left.
76 tokens.pop_back();
77 DCHECK_EQ(0U, tokens.size() % 2);
78
79 // |variations| is used to store the formatted strings that will be passed to
80 // the Javascript through |variations_list|.
81 std::vector<std::string> variations;
82 for (size_t i = 0; i < tokens.size(); i += 2)
83 variations.push_back(tokens[i] + ":" + tokens[i + 1]);
84
85 for (std::vector<std::string>::const_iterator it = variations.begin();
86 it != variations.end(); ++it) {
87 variations_list->Append(Value::CreateStringValue(*it));
88 }
89 #endif
90 // In release mode, this will return an empty list to clear the section.
91 web_ui()->CallJavascriptFunction("returnVariationsList",
92 *variations_list.release());
93 }
94
95 ChromeWebUIDataSource* CreateVersionUIDataSource(Profile* profile) {
96 // Set up the chrome://version source.
97 ChromeWebUIDataSource* html_source =
98 new ChromeWebUIDataSource(chrome::kChromeUIVersionHost);
99 html_source->set_use_json_js_format_v2();
100
101 // Localized and data strings.
102 html_source->AddLocalizedString("title", IDS_ABOUT_VERSION_TITLE);
103 chrome::VersionInfo version_info;
104 html_source->AddLocalizedString("name", IDS_PRODUCT_NAME);
105 html_source->AddString("version", ASCIIToUTF16(version_info.Version()));
106 // Bug 79458: Need to evaluate the use of getting the version string on
107 // this thread.
108 base::ThreadRestrictions::ScopedAllowIO allow_io;
109 html_source->AddString("version_modifier",
110 ASCIIToUTF16(chrome::VersionInfo::GetVersionStringModifier()));
111 html_source->AddLocalizedString("os_name", IDS_ABOUT_VERSION_OS);
112 html_source->AddLocalizedString("platform", IDS_PLATFORM_LABEL);
113 html_source->AddString("os_type", ASCIIToUTF16(version_info.OSType()));
114 html_source->AddString("os_version", string16());
115 html_source->AddString("webkit_version",
116 ASCIIToUTF16(webkit_glue::GetWebKitVersion()));
117 html_source->AddString("js_engine", ASCIIToUTF16("V8"));
118 html_source->AddString("js_version", ASCIIToUTF16(v8::V8::GetVersion()));
119
120 // Add required resources.
121 html_source->set_json_path("strings.js");
122 html_source->add_resource_path("version.js", IDR_ABOUT_VERSION_JS);
123 html_source->set_default_resource(IDR_ABOUT_VERSION_HTML);
124
125 #if !defined(OS_ANDROID)
126 // Obtain the version of the first enabled Flash plugin.
127 std::vector<webkit::WebPluginInfo> info_array;
128 content::PluginService::GetInstance()->GetPluginInfoArray(
129 GURL(), "application/x-shockwave-flash", false, &info_array, NULL);
130 string16 flash_version =
131 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
132 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
133 if (plugin_prefs) {
134 for (size_t i = 0; i < info_array.size(); ++i) {
135 if (plugin_prefs->IsPluginEnabled(info_array[i])) {
136 flash_version = info_array[i].version;
137 break;
138 }
139 }
140 }
141 html_source->AddString("flash_plugin", ASCIIToUTF16("Flash"));
142 html_source->AddString("flash_version", flash_version);
143 #endif
144 html_source->AddLocalizedString("company", IDS_ABOUT_VERSION_COMPANY_NAME);
145 html_source->AddLocalizedString("copyright", IDS_ABOUT_VERSION_COPYRIGHT);
146 html_source->AddString("cl", ASCIIToUTF16(version_info.LastChange()));
147 html_source->AddLocalizedString("official",
148 version_info.IsOfficialBuild() ?
149 IDS_ABOUT_VERSION_OFFICIAL
150 : IDS_ABOUT_VERSION_UNOFFICIAL);
151 html_source->AddLocalizedString("user_agent_name",
152 IDS_ABOUT_VERSION_USER_AGENT);
153 html_source->AddString("useragent",
154 ASCIIToUTF16(content::GetUserAgent(GURL())));
155 html_source->AddLocalizedString("command_line_name",
156 IDS_ABOUT_VERSION_COMMAND_LINE);
157
158 #if defined(OS_WIN)
159 html_source->AddString("command_line",
160 WideToUTF16(CommandLine::ForCurrentProcess()->GetCommandLineString()));
161 #elif defined(OS_POSIX)
162 std::string command_line = "";
163 typedef std::vector<std::string> ArgvList;
164 const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
165 for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
166 command_line += " " + *iter;
167 // TODO(viettrungluu): |command_line| could really have any encoding, whereas
168 // below we assumes it's UTF-8.
169 html_source->AddString("command_line", ASCIIToUTF16(command_line));
170 #endif
171
172 // Allow IO temporarily based on allow_io (defined above)
173 // since the following operation will complete quickly
174 html_source->AddLocalizedString("executable_path_name",
175 IDS_ABOUT_VERSION_EXECUTABLE_PATH);
176 FilePath executable_path = CommandLine::ForCurrentProcess()->GetProgram();
177 if (file_util::AbsolutePath(&executable_path)) {
178 html_source->AddString("executable_path",
179 ASCIIToUTF16(executable_path.value()));
180 } else {
181 html_source->AddLocalizedString("executable_path",
182 IDS_ABOUT_VERSION_PATH_NOTFOUND);
183 }
184 html_source->AddLocalizedString("profile_path_name",
185 IDS_ABOUT_VERSION_PROFILE_PATH);
186 if (profile) {
187 FilePath profile_path = profile->GetPath();
188 if (file_util::AbsolutePath(&profile_path)) {
189 html_source->AddString("profile_path",
190 ASCIIToUTF16(profile_path.value()));
191 } else {
192 html_source->AddLocalizedString("profile_path",
193 IDS_ABOUT_VERSION_PATH_NOTFOUND);
194 }
195 } else {
196 html_source->AddLocalizedString("profile_path",
197 IDS_ABOUT_VERSION_PATH_NOTFOUND);
198 }
199 // TODO(reviewer): Do I need some equivalent to this?
200 // ChromeWebUIDataSource::SetFontAndTextDirection(localized_strings);
SteveT 2012/09/10 15:40:00 Any thoughts here on this TODO?
Evan Stade 2012/09/10 17:07:23 I think you should use this line, yes... it will m
SteveT 2012/09/10 20:14:51 Oh, I think that |html_source| calls SetFontAndTex
201
202 #if !defined(NDEBUG)
203 html_source->AddLocalizedString("variations_name",
204 IDS_ABOUT_VERSION_VARIATIONS);
205 #endif
206
207 return html_source;
208 }
209
210 } // namespace
211
212 VersionUI::VersionUI(content::WebUI* web_ui)
213 : content::WebUIController(web_ui) {
214 Profile* profile = Profile::FromWebUI(web_ui);
215
216 web_ui->AddMessageHandler(new VersionDOMHandler());
217
218 ChromeURLDataManager::AddDataSource(profile,
219 CreateVersionUIDataSource(profile));
220 }
221
222 VersionUI::~VersionUI() {
223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698