OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/version_handler.h" | 5 #include "chrome/browser/ui/webui/version_handler.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/plugins/plugin_prefs.h" | 12 #include "chrome/browser/plugins/plugin_prefs.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "components/variations/active_field_trials.h" | 15 #include "components/variations/active_field_trials.h" |
16 #include "components/version_ui/version_ui_constants.h" | |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/plugin_service.h" | 18 #include "content/public/browser/plugin_service.h" |
18 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
19 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
21 #include "grit/components_strings.h" | |
20 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
21 #include "url/gurl.h" | 23 #include "url/gurl.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // Retrieves the executable and profile paths on the FILE thread. | 27 // Retrieves the executable and profile paths on the FILE thread. |
26 void GetFilePaths(const base::FilePath& profile_path, | 28 void GetFilePaths(const base::FilePath& profile_path, |
27 base::string16* exec_path_out, | 29 base::string16* exec_path_out, |
28 base::string16* profile_path_out) { | 30 base::string16* profile_path_out) { |
29 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 31 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
30 | 32 |
31 base::FilePath executable_path = base::MakeAbsoluteFilePath( | 33 base::FilePath executable_path = base::MakeAbsoluteFilePath( |
32 base::CommandLine::ForCurrentProcess()->GetProgram()); | 34 base::CommandLine::ForCurrentProcess()->GetProgram()); |
33 if (!executable_path.empty()) { | 35 if (!executable_path.empty()) { |
34 *exec_path_out = executable_path.LossyDisplayName(); | 36 *exec_path_out = executable_path.LossyDisplayName(); |
35 } else { | 37 } else { |
36 *exec_path_out = | 38 *exec_path_out = l10n_util::GetStringUTF16(IDS_VERSION_UI_PATH_NOTFOUND); |
37 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND); | |
38 } | 39 } |
Dan Beam
2015/10/15 04:02:35
nit: no more curlies for either of this conditiona
| |
39 | 40 |
40 base::FilePath profile_path_copy(base::MakeAbsoluteFilePath(profile_path)); | 41 base::FilePath profile_path_copy(base::MakeAbsoluteFilePath(profile_path)); |
41 if (!profile_path.empty() && !profile_path_copy.empty()) { | 42 if (!profile_path.empty() && !profile_path_copy.empty()) { |
42 *profile_path_out = profile_path.LossyDisplayName(); | 43 *profile_path_out = profile_path.LossyDisplayName(); |
43 } else { | 44 } else { |
44 *profile_path_out = | 45 *profile_path_out = l10n_util::GetStringUTF16(IDS_VERSION_UI_PATH_NOTFOUND); |
45 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND); | |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 VersionHandler::VersionHandler() | 51 VersionHandler::VersionHandler() |
52 : weak_ptr_factory_(this) { | 52 : weak_ptr_factory_(this) { |
53 } | 53 } |
54 | 54 |
55 VersionHandler::~VersionHandler() { | 55 VersionHandler::~VersionHandler() { |
56 } | 56 } |
57 | 57 |
58 void VersionHandler::RegisterMessages() { | 58 void VersionHandler::RegisterMessages() { |
59 web_ui()->RegisterMessageCallback( | 59 web_ui()->RegisterMessageCallback( |
60 "requestVersionInfo", | 60 version_ui::kRequestVersionInfo, |
61 base::Bind(&VersionHandler::HandleRequestVersionInfo, | 61 base::Bind(&VersionHandler::HandleRequestVersionInfo, |
62 base::Unretained(this))); | 62 base::Unretained(this))); |
63 } | 63 } |
64 | 64 |
65 void VersionHandler::HandleRequestVersionInfo(const base::ListValue* args) { | 65 void VersionHandler::HandleRequestVersionInfo(const base::ListValue* args) { |
66 #if defined(ENABLE_PLUGINS) | 66 #if defined(ENABLE_PLUGINS) |
67 // The Flash version information is needed in the response, so make sure | 67 // The Flash version information is needed in the response, so make sure |
68 // the plugins are loaded. | 68 // the plugins are loaded. |
69 content::PluginService::GetInstance()->GetPlugins( | 69 content::PluginService::GetInstance()->GetPlugins( |
70 base::Bind(&VersionHandler::OnGotPlugins, | 70 base::Bind(&VersionHandler::OnGotPlugins, |
71 weak_ptr_factory_.GetWeakPtr())); | 71 weak_ptr_factory_.GetWeakPtr())); |
72 #endif | 72 #endif |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 variations::GetFieldTrialActiveGroupIdsAsStrings(&variations); | 105 variations::GetFieldTrialActiveGroupIdsAsStrings(&variations); |
106 #endif | 106 #endif |
107 | 107 |
108 base::ListValue variations_list; | 108 base::ListValue variations_list; |
109 for (std::vector<std::string>::const_iterator it = variations.begin(); | 109 for (std::vector<std::string>::const_iterator it = variations.begin(); |
110 it != variations.end(); ++it) { | 110 it != variations.end(); ++it) { |
111 variations_list.Append(new base::StringValue(*it)); | 111 variations_list.Append(new base::StringValue(*it)); |
112 } | 112 } |
113 | 113 |
114 // In release mode, this will return an empty list to clear the section. | 114 // In release mode, this will return an empty list to clear the section. |
115 web_ui()->CallJavascriptFunction("returnVariationInfo", variations_list); | 115 web_ui()->CallJavascriptFunction(version_ui::kReturnVariationInfo, |
116 variations_list); | |
116 } | 117 } |
117 | 118 |
118 void VersionHandler::OnGotFilePaths(base::string16* executable_path_data, | 119 void VersionHandler::OnGotFilePaths(base::string16* executable_path_data, |
119 base::string16* profile_path_data) { | 120 base::string16* profile_path_data) { |
120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
121 | 122 |
122 base::StringValue exec_path(*executable_path_data); | 123 base::StringValue exec_path(*executable_path_data); |
123 base::StringValue profile_path(*profile_path_data); | 124 base::StringValue profile_path(*profile_path_data); |
124 web_ui()->CallJavascriptFunction("returnFilePaths", exec_path, profile_path); | 125 web_ui()->CallJavascriptFunction(version_ui::kReturnFilePaths, exec_path, |
126 profile_path); | |
125 } | 127 } |
126 | 128 |
127 #if defined(ENABLE_PLUGINS) | 129 #if defined(ENABLE_PLUGINS) |
128 void VersionHandler::OnGotPlugins( | 130 void VersionHandler::OnGotPlugins( |
129 const std::vector<content::WebPluginInfo>& plugins) { | 131 const std::vector<content::WebPluginInfo>& plugins) { |
130 // Obtain the version of the first enabled Flash plugin. | 132 // Obtain the version of the first enabled Flash plugin. |
131 std::vector<content::WebPluginInfo> info_array; | 133 std::vector<content::WebPluginInfo> info_array; |
132 content::PluginService::GetInstance()->GetPluginInfoArray( | 134 content::PluginService::GetInstance()->GetPluginInfoArray( |
133 GURL(), content::kFlashPluginSwfMimeType, false, &info_array, NULL); | 135 GURL(), content::kFlashPluginSwfMimeType, false, &info_array, NULL); |
134 base::string16 flash_version = | 136 base::string16 flash_version = |
135 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); | 137 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); |
136 PluginPrefs* plugin_prefs = | 138 PluginPrefs* plugin_prefs = |
137 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get(); | 139 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get(); |
138 if (plugin_prefs) { | 140 if (plugin_prefs) { |
139 for (size_t i = 0; i < info_array.size(); ++i) { | 141 for (size_t i = 0; i < info_array.size(); ++i) { |
140 if (plugin_prefs->IsPluginEnabled(info_array[i])) { | 142 if (plugin_prefs->IsPluginEnabled(info_array[i])) { |
141 flash_version = info_array[i].version; | 143 flash_version = info_array[i].version; |
142 break; | 144 break; |
143 } | 145 } |
144 } | 146 } |
145 } | 147 } |
146 | 148 |
147 base::StringValue arg(flash_version); | 149 base::StringValue arg(flash_version); |
148 web_ui()->CallJavascriptFunction("returnFlashVersion", arg); | 150 web_ui()->CallJavascriptFunction(version_ui::kReturnFlashVersion, arg); |
149 } | 151 } |
150 #endif // defined(ENABLE_PLUGINS) | 152 #endif // defined(ENABLE_PLUGINS) |
OLD | NEW |