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

Side by Side Diff: chrome/browser/ui/webui/version_handler.cc

Issue 1486403002: Mojo-ifying chrome://version. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change slashes Created 4 years, 5 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
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
11 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
12 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/plugins/plugin_prefs.h" 16 #include "chrome/browser/plugins/plugin_prefs.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
17 #include "components/variations/active_field_trials.h" 19 #include "components/variations/active_field_trials.h"
18 #include "components/version_ui/version_handler_helper.h" 20 #include "components/version_ui/version_handler_helper.h"
19 #include "components/version_ui/version_ui_constants.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/plugin_service.h" 22 #include "content/public/browser/plugin_service.h"
22 #include "content/public/browser/web_ui.h" 23 #include "content/public/browser/web_ui.h"
23 #include "content/public/common/content_constants.h" 24 #include "content/public/common/content_constants.h"
24 #include "grit/components_strings.h" 25 #include "grit/components_strings.h"
26 #include "mojo/common/common_type_converters.h"
25 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
26 #include "url/gurl.h" 28 #include "url/gurl.h"
27 29
30 #if defined(OS_CHROMEOS)
31 #include "chromeos/system/version_loader.h"
32 #endif
33
28 namespace { 34 namespace {
29 35
30 // Retrieves the executable and profile paths on the FILE thread. 36 // Retrieves the executable and profile paths on the FILE thread.
31 void GetFilePaths(const base::FilePath& profile_path, 37 void RetrieveFilePaths(const base::FilePath& profile_path,
32 base::string16* exec_path_out, 38 base::string16* exec_path_out,
33 base::string16* profile_path_out) { 39 base::string16* profile_path_out) {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 40 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
35 41
36 base::FilePath executable_path = base::MakeAbsoluteFilePath( 42 base::FilePath executable_path = base::MakeAbsoluteFilePath(
37 base::CommandLine::ForCurrentProcess()->GetProgram()); 43 base::CommandLine::ForCurrentProcess()->GetProgram());
38 if (!executable_path.empty()) 44 if (!executable_path.empty())
39 *exec_path_out = executable_path.LossyDisplayName(); 45 *exec_path_out = executable_path.LossyDisplayName();
40 else 46 else
41 *exec_path_out = l10n_util::GetStringUTF16(IDS_VERSION_UI_PATH_NOTFOUND); 47 *exec_path_out = l10n_util::GetStringUTF16(IDS_VERSION_UI_PATH_NOTFOUND);
42 48
43 base::FilePath profile_path_copy(base::MakeAbsoluteFilePath(profile_path)); 49 base::FilePath profile_path_copy(base::MakeAbsoluteFilePath(profile_path));
44 if (!profile_path.empty() && !profile_path_copy.empty()) 50 if (!profile_path.empty() && !profile_path_copy.empty())
45 *profile_path_out = profile_path.LossyDisplayName(); 51 *profile_path_out = profile_path.LossyDisplayName();
46 else 52 else
47 *profile_path_out = l10n_util::GetStringUTF16(IDS_VERSION_UI_PATH_NOTFOUND); 53 *profile_path_out = l10n_util::GetStringUTF16(IDS_VERSION_UI_PATH_NOTFOUND);
48 } 54 }
49 55
50 } // namespace 56 } // namespace
51 57
52 VersionHandler::VersionHandler() 58 VersionHandler::VersionHandler(
53 : weak_ptr_factory_(this) { 59 content::WebUI* web_ui,
54 } 60 mojo::InterfaceRequest<mojom::VersionPageHandler> request)
61 : web_ui_(web_ui),
62 binding_(this, std::move(request)),
63 weak_ptr_factory_(this) {}
55 64
56 VersionHandler::~VersionHandler() { 65 VersionHandler::~VersionHandler() {}
57 }
58 66
59 void VersionHandler::RegisterMessages() { 67 void VersionHandler::GetFilePaths(const GetFilePathsCallback& callback) {
60 web_ui()->RegisterMessageCallback(
61 version_ui::kRequestVersionInfo,
62 base::Bind(&VersionHandler::HandleRequestVersionInfo,
63 base::Unretained(this)));
64 }
65
66 void VersionHandler::HandleRequestVersionInfo(const base::ListValue* args) {
67 #if defined(ENABLE_PLUGINS)
68 // The Flash version information is needed in the response, so make sure
69 // the plugins are loaded.
70 content::PluginService::GetInstance()->GetPlugins(
71 base::Bind(&VersionHandler::OnGotPlugins,
72 weak_ptr_factory_.GetWeakPtr()));
73 #endif
74
75 // Grab the executable path on the FILE thread. It is returned in 68 // Grab the executable path on the FILE thread. It is returned in
76 // OnGotFilePaths. 69 // OnGotFilePaths.
77 base::string16* exec_path_buffer = new base::string16; 70 base::string16* exec_path_buffer = new base::string16;
78 base::string16* profile_path_buffer = new base::string16; 71 base::string16* profile_path_buffer = new base::string16;
79 content::BrowserThread::PostTaskAndReply( 72 content::BrowserThread::PostTaskAndReply(
80 content::BrowserThread::FILE, FROM_HERE, 73 content::BrowserThread::FILE, FROM_HERE,
81 base::Bind(&GetFilePaths, Profile::FromWebUI(web_ui())->GetPath(), 74 base::Bind(&RetrieveFilePaths, Profile::FromWebUI(web_ui_)->GetPath(),
82 base::Unretained(exec_path_buffer), 75 base::Unretained(exec_path_buffer),
83 base::Unretained(profile_path_buffer)), 76 base::Unretained(profile_path_buffer)),
84 base::Bind(&VersionHandler::OnGotFilePaths, 77 base::Bind(&VersionHandler::OnGotFilePaths,
85 weak_ptr_factory_.GetWeakPtr(), 78 weak_ptr_factory_.GetWeakPtr(), base::Owned(exec_path_buffer),
86 base::Owned(exec_path_buffer), 79 base::Owned(profile_path_buffer), callback));
87 base::Owned(profile_path_buffer)));
88
89 // Respond with the variations info immediately.
90 web_ui()->CallJavascriptFunctionUnsafe(version_ui::kReturnVariationInfo,
91 *version_ui::GetVariationsList());
92 } 80 }
93 81
94 void VersionHandler::OnGotFilePaths(base::string16* executable_path_data, 82 void VersionHandler::OnGotFilePaths(base::string16* executable_path_data,
95 base::string16* profile_path_data) { 83 base::string16* profile_path_data,
84 const GetFilePathsCallback& callback) {
96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86 callback.Run(mojo::String::From(*executable_path_data),
87 mojo::String::From(*profile_path_data));
88 }
97 89
98 base::StringValue exec_path(*executable_path_data); 90 void VersionHandler::GetFlashVersion(const GetFlashVersionCallback& callback) {
99 base::StringValue profile_path(*profile_path_data); 91 #if defined(ENABLE_PLUGINS)
100 web_ui()->CallJavascriptFunctionUnsafe(version_ui::kReturnFilePaths, 92 // The Flash version information is needed in the response, so make sure
101 exec_path, profile_path); 93 // the plugins are loaded.
94 content::PluginService::GetInstance()->GetPlugins(base::Bind(
95 &VersionHandler::OnGotPlugins, weak_ptr_factory_.GetWeakPtr(), callback));
96 #endif
102 } 97 }
103 98
99 void VersionHandler::GetVariations(const GetVariationsCallback& callback) {
100 std::vector<std::string> variations = version_ui::GetVariations();
101 callback.Run(variations);
102 }
103
104 void VersionHandler::GetOsVersion(const GetOsVersionCallback& callback) {
105 #if defined(OS_CHROMEOS)
106 base::PostTaskAndReplyWithResult(
107 content::BrowserThread::GetBlockingPool(), FROM_HERE,
108 base::Bind(&chromeos::version_loader::GetVersion,
109 chromeos::version_loader::VERSION_FULL),
110 base::Bind(&VersionHandler::OnGotOsVersion,
111 weak_ptr_factory_.GetWeakPtr(), callback));
112 #endif // defined(OS_CHROMEOS)
113 }
114
115 void VersionHandler::GetArcVersion(const GetArcVersionCallback& callback) {
116 #if defined(OS_CHROMEOS)
117 base::PostTaskAndReplyWithResult(
118 content::BrowserThread::GetBlockingPool(),
119 FROM_HERE,
120 base::Bind(&chromeos::version_loader::GetARCVersion),
121 base::Bind(&VersionHandler::OnGotArcVersion,
122 weak_ptr_factory_.GetWeakPtr(), callback));
123 #endif // defined(OS_CHROMEOS)
124 }
125
126 #if defined(OS_CHROMEOS)
127 void VersionHandler::OnGotOsVersion(const GetOsVersionCallback& callback,
128 const std::string& version) {
129 callback.Run(mojo::String::From(version));
130 }
131
132 void VersionHandler::OnGotArcVersion(const GetArcVersionCallback& callback,
133 const std::string& version) {
134 callback.Run(mojo::String::From(version));
135 }
136 #endif // defined(OS_CHROMEOS)
137
104 #if defined(ENABLE_PLUGINS) 138 #if defined(ENABLE_PLUGINS)
105 void VersionHandler::OnGotPlugins( 139 void VersionHandler::OnGotPlugins(
140 const GetFlashVersionCallback& callback,
106 const std::vector<content::WebPluginInfo>& plugins) { 141 const std::vector<content::WebPluginInfo>& plugins) {
107 // Obtain the version of the first enabled Flash plugin. 142 // Obtain the version of the first enabled Flash plugin.
108 std::vector<content::WebPluginInfo> info_array; 143 std::vector<content::WebPluginInfo> info_array;
109 content::PluginService::GetInstance()->GetPluginInfoArray( 144 content::PluginService::GetInstance()->GetPluginInfoArray(
110 GURL(), content::kFlashPluginSwfMimeType, false, &info_array, NULL); 145 GURL(), content::kFlashPluginSwfMimeType, false, &info_array, NULL);
111 base::string16 flash_version = 146 base::string16 flash_version =
112 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN); 147 l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
113 PluginPrefs* plugin_prefs = 148 PluginPrefs* plugin_prefs =
114 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get(); 149 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_)).get();
115 if (plugin_prefs) { 150 if (plugin_prefs) {
116 for (size_t i = 0; i < info_array.size(); ++i) { 151 for (size_t i = 0; i < info_array.size(); ++i) {
117 if (plugin_prefs->IsPluginEnabled(info_array[i])) { 152 if (plugin_prefs->IsPluginEnabled(info_array[i])) {
118 flash_version = info_array[i].version; 153 flash_version = info_array[i].version;
119 break; 154 break;
120 } 155 }
121 } 156 }
122 } 157 }
123 158
124 base::StringValue arg(flash_version); 159 callback.Run(mojo::String::From(flash_version));
125 web_ui()->CallJavascriptFunctionUnsafe(version_ui::kReturnFlashVersion, arg);
126 } 160 }
127 #endif // defined(ENABLE_PLUGINS) 161 #endif // defined(ENABLE_PLUGINS)
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/version_handler.h ('k') | chrome/browser/ui/webui/version_handler_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698