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 | 39 |
40 base::FilePath profile_path_copy(base::MakeAbsoluteFilePath(profile_path)); | 40 base::FilePath profile_path_copy(base::MakeAbsoluteFilePath(profile_path)); |
41 if (!profile_path.empty() && !profile_path_copy.empty()) { | 41 if (!profile_path.empty() && !profile_path_copy.empty()) |
42 *profile_path_out = profile_path.LossyDisplayName(); | 42 *profile_path_out = profile_path.LossyDisplayName(); |
43 } else { | 43 else |
44 *profile_path_out = | 44 *profile_path_out = l10n_util::GetStringUTF16(IDS_VERSION_UI_PATH_NOTFOUND); |
45 l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_PATH_NOTFOUND); | |
46 } | |
47 } | 45 } |
48 | 46 |
49 } // namespace | 47 } // namespace |
50 | 48 |
51 VersionHandler::VersionHandler() | 49 VersionHandler::VersionHandler() |
52 : weak_ptr_factory_(this) { | 50 : weak_ptr_factory_(this) { |
53 } | 51 } |
54 | 52 |
55 VersionHandler::~VersionHandler() { | 53 VersionHandler::~VersionHandler() { |
56 } | 54 } |
57 | 55 |
58 void VersionHandler::RegisterMessages() { | 56 void VersionHandler::RegisterMessages() { |
59 web_ui()->RegisterMessageCallback( | 57 web_ui()->RegisterMessageCallback( |
60 "requestVersionInfo", | 58 version_ui::kRequestVersionInfo, |
61 base::Bind(&VersionHandler::HandleRequestVersionInfo, | 59 base::Bind(&VersionHandler::HandleRequestVersionInfo, |
62 base::Unretained(this))); | 60 base::Unretained(this))); |
63 } | 61 } |
64 | 62 |
65 void VersionHandler::HandleRequestVersionInfo(const base::ListValue* args) { | 63 void VersionHandler::HandleRequestVersionInfo(const base::ListValue* args) { |
66 #if defined(ENABLE_PLUGINS) | 64 #if defined(ENABLE_PLUGINS) |
67 // The Flash version information is needed in the response, so make sure | 65 // The Flash version information is needed in the response, so make sure |
68 // the plugins are loaded. | 66 // the plugins are loaded. |
69 content::PluginService::GetInstance()->GetPlugins( | 67 content::PluginService::GetInstance()->GetPlugins( |
70 base::Bind(&VersionHandler::OnGotPlugins, | 68 base::Bind(&VersionHandler::OnGotPlugins, |
71 weak_ptr_factory_.GetWeakPtr())); | 69 weak_ptr_factory_.GetWeakPtr())); |
72 #endif | 70 #endif |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 variations::GetFieldTrialActiveGroupIdsAsStrings(&variations); | 103 variations::GetFieldTrialActiveGroupIdsAsStrings(&variations); |
106 #endif | 104 #endif |
107 | 105 |
108 base::ListValue variations_list; | 106 base::ListValue variations_list; |
109 for (std::vector<std::string>::const_iterator it = variations.begin(); | 107 for (std::vector<std::string>::const_iterator it = variations.begin(); |
110 it != variations.end(); ++it) { | 108 it != variations.end(); ++it) { |
111 variations_list.Append(new base::StringValue(*it)); | 109 variations_list.Append(new base::StringValue(*it)); |
112 } | 110 } |
113 | 111 |
114 // In release mode, this will return an empty list to clear the section. | 112 // In release mode, this will return an empty list to clear the section. |
115 web_ui()->CallJavascriptFunction("returnVariationInfo", variations_list); | 113 web_ui()->CallJavascriptFunction(version_ui::kReturnVariationInfo, |
| 114 variations_list); |
116 } | 115 } |
117 | 116 |
118 void VersionHandler::OnGotFilePaths(base::string16* executable_path_data, | 117 void VersionHandler::OnGotFilePaths(base::string16* executable_path_data, |
119 base::string16* profile_path_data) { | 118 base::string16* profile_path_data) { |
120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
121 | 120 |
122 base::StringValue exec_path(*executable_path_data); | 121 base::StringValue exec_path(*executable_path_data); |
123 base::StringValue profile_path(*profile_path_data); | 122 base::StringValue profile_path(*profile_path_data); |
124 web_ui()->CallJavascriptFunction("returnFilePaths", exec_path, profile_path); | 123 web_ui()->CallJavascriptFunction(version_ui::kReturnFilePaths, exec_path, |
| 124 profile_path); |
125 } | 125 } |
126 | 126 |
127 #if defined(ENABLE_PLUGINS) | 127 #if defined(ENABLE_PLUGINS) |
128 void VersionHandler::OnGotPlugins( | 128 void VersionHandler::OnGotPlugins( |
129 const std::vector<content::WebPluginInfo>& plugins) { | 129 const std::vector<content::WebPluginInfo>& plugins) { |
130 // Obtain the version of the first enabled Flash plugin. | 130 // Obtain the version of the first enabled Flash plugin. |
131 std::vector<content::WebPluginInfo> info_array; | 131 std::vector<content::WebPluginInfo> info_array; |
132 content::PluginService::GetInstance()->GetPluginInfoArray( | 132 content::PluginService::GetInstance()->GetPluginInfoArray( |
133 GURL(), content::kFlashPluginSwfMimeType, false, &info_array, NULL); | 133 GURL(), content::kFlashPluginSwfMimeType, false, &info_array, NULL); |
134 base::string16 flash_version = | 134 base::string16 flash_version = |
135 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); | 135 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); |
136 PluginPrefs* plugin_prefs = | 136 PluginPrefs* plugin_prefs = |
137 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get(); | 137 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get(); |
138 if (plugin_prefs) { | 138 if (plugin_prefs) { |
139 for (size_t i = 0; i < info_array.size(); ++i) { | 139 for (size_t i = 0; i < info_array.size(); ++i) { |
140 if (plugin_prefs->IsPluginEnabled(info_array[i])) { | 140 if (plugin_prefs->IsPluginEnabled(info_array[i])) { |
141 flash_version = info_array[i].version; | 141 flash_version = info_array[i].version; |
142 break; | 142 break; |
143 } | 143 } |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 base::StringValue arg(flash_version); | 147 base::StringValue arg(flash_version); |
148 web_ui()->CallJavascriptFunction("returnFlashVersion", arg); | 148 web_ui()->CallJavascriptFunction(version_ui::kReturnFlashVersion, arg); |
149 } | 149 } |
150 #endif // defined(ENABLE_PLUGINS) | 150 #endif // defined(ENABLE_PLUGINS) |
OLD | NEW |