OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/flash_ui.h" | 5 #include "chrome/browser/ui/webui/flash_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback_old.h" | 13 #include "base/callback_old.h" |
14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
| 15 #include "base/memory/weak_ptr.h" |
15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
18 #include "base/timer.h" | 19 #include "base/timer.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "chrome/browser/crash_upload_list.h" | 22 #include "chrome/browser/crash_upload_list.h" |
22 #include "chrome/browser/plugin_prefs.h" | 23 #include "chrome/browser/plugin_prefs.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 25 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
25 #include "chrome/browser/ui/webui/crashes_ui.h" | 26 #include "chrome/browser/ui/webui/crashes_ui.h" |
26 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
28 #include "content/browser/gpu/gpu_data_manager.h" | 29 #include "content/browser/gpu/gpu_data_manager.h" |
| 30 #include "content/browser/plugin_service.h" |
29 #include "content/browser/tab_contents/tab_contents.h" | 31 #include "content/browser/tab_contents/tab_contents.h" |
30 #include "content/browser/user_metrics.h" | 32 #include "content/browser/user_metrics.h" |
31 #include "grit/browser_resources.h" | 33 #include "grit/browser_resources.h" |
32 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
34 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
35 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
37 #include "webkit/plugins/npapi/plugin_list.h" | |
38 #include "webkit/plugins/webplugininfo.h" | 39 #include "webkit/plugins/webplugininfo.h" |
39 | 40 |
40 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
41 #include "base/win/windows_version.h" | 42 #include "base/win/windows_version.h" |
42 #endif | 43 #endif |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 ChromeWebUIDataSource* CreateFlashUIHTMLSource() { | 47 ChromeWebUIDataSource* CreateFlashUIHTMLSource() { |
47 ChromeWebUIDataSource* source = | 48 ChromeWebUIDataSource* source = |
(...skipping 27 matching lines...) Expand all Loading... |
75 | 76 |
76 // CrashUploadList::Delegate implementation. | 77 // CrashUploadList::Delegate implementation. |
77 virtual void OnCrashListAvailable() OVERRIDE; | 78 virtual void OnCrashListAvailable() OVERRIDE; |
78 | 79 |
79 // Callback for the "requestFlashInfo" message. | 80 // Callback for the "requestFlashInfo" message. |
80 void HandleRequestFlashInfo(const ListValue* args); | 81 void HandleRequestFlashInfo(const ListValue* args); |
81 | 82 |
82 // Callback for the GPU information update. | 83 // Callback for the GPU information update. |
83 void OnGpuInfoUpdate(); | 84 void OnGpuInfoUpdate(); |
84 | 85 |
| 86 // Callback for the Flash plugin information. |
| 87 void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins); |
| 88 |
85 private: | 89 private: |
86 // Called when we think we might have enough information to return data back | 90 // Called when we think we might have enough information to return data back |
87 // to the page. | 91 // to the page. |
88 void MaybeRespondToPage(); | 92 void MaybeRespondToPage(); |
89 | 93 |
90 // In certain cases we might not get called back from the GPU process so we | 94 // In certain cases we might not get called back from the GPU process so we |
91 // set an upper limit on the time we wait. This function gets called when the | 95 // set an upper limit on the time we wait. This function gets called when the |
92 // time has passed. This actually doesn't prevent the rest of the information | 96 // time has passed. This actually doesn't prevent the rest of the information |
93 // to appear later, the page will just reflow when more information becomes | 97 // to appear later, the page will just reflow when more information becomes |
94 // available. | 98 // available. |
95 void OnTimeout(); | 99 void OnTimeout(); |
96 | 100 |
97 // A timer to keep track of when the data fetching times out. | 101 // A timer to keep track of when the data fetching times out. |
98 base::OneShotTimer<FlashDOMHandler> timeout_; | 102 base::OneShotTimer<FlashDOMHandler> timeout_; |
99 | 103 |
100 // GPU variables. | 104 // GPU variables. |
101 GpuDataManager* gpu_data_manager_; | 105 GpuDataManager* gpu_data_manager_; |
102 Callback0::Type* gpu_info_update_callback_; | 106 Callback0::Type* gpu_info_update_callback_; |
103 | 107 |
104 // Crash list. | 108 // Crash list. |
105 scoped_refptr<CrashUploadList> upload_list_; | 109 scoped_refptr<CrashUploadList> upload_list_; |
106 | 110 |
| 111 // Factory for the creating refs in callbacks. |
| 112 base::WeakPtrFactory<FlashDOMHandler> weak_ptr_factory_; |
| 113 |
107 // Whether the list of all crashes is available. | 114 // Whether the list of all crashes is available. |
108 bool crash_list_available_; | 115 bool crash_list_available_; |
109 // Whether the page has requested data. | 116 // Whether the page has requested data. |
110 bool page_has_requested_data_; | 117 bool page_has_requested_data_; |
111 // Whether the GPU data has been collected. | 118 // Whether the GPU data has been collected. |
112 bool has_gpu_info_; | 119 bool has_gpu_info_; |
| 120 // Whether the plugin information is ready. |
| 121 bool has_plugin_info_; |
113 | 122 |
114 DISALLOW_COPY_AND_ASSIGN(FlashDOMHandler); | 123 DISALLOW_COPY_AND_ASSIGN(FlashDOMHandler); |
115 }; | 124 }; |
116 | 125 |
117 FlashDOMHandler::FlashDOMHandler() | 126 FlashDOMHandler::FlashDOMHandler() |
118 : crash_list_available_(false), | 127 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 128 crash_list_available_(false), |
119 page_has_requested_data_(false), | 129 page_has_requested_data_(false), |
120 has_gpu_info_(false) { | 130 has_gpu_info_(false), |
| 131 has_plugin_info_(false) { |
121 // Request Crash data asynchronously. | 132 // Request Crash data asynchronously. |
122 upload_list_ = CrashUploadList::Create(this); | 133 upload_list_ = CrashUploadList::Create(this); |
123 upload_list_->LoadCrashListAsynchronously(); | 134 upload_list_->LoadCrashListAsynchronously(); |
124 | 135 |
125 // Watch for changes in GPUInfo. | 136 // Watch for changes in GPUInfo. |
126 gpu_data_manager_ = GpuDataManager::GetInstance(); | 137 gpu_data_manager_ = GpuDataManager::GetInstance(); |
127 gpu_info_update_callback_ = | 138 gpu_info_update_callback_ = |
128 NewCallback(this, &FlashDOMHandler::OnGpuInfoUpdate); | 139 NewCallback(this, &FlashDOMHandler::OnGpuInfoUpdate); |
129 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); | 140 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); |
130 | 141 |
131 // Tell GpuDataManager it should have full GpuInfo. If the | 142 // Tell GpuDataManager it should have full GpuInfo. If the |
132 // GPU process has not run yet, this will trigger its launch. | 143 // GPU process has not run yet, this will trigger its launch. |
133 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); | 144 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); |
134 | 145 |
135 // GPU access might not be allowed at all, which will cause us not to get a | 146 // GPU access might not be allowed at all, which will cause us not to get a |
136 // call back. | 147 // call back. |
137 if (!gpu_data_manager_->GpuAccessAllowed()) | 148 if (!gpu_data_manager_->GpuAccessAllowed()) |
138 OnGpuInfoUpdate(); | 149 OnGpuInfoUpdate(); |
139 | 150 |
| 151 PluginService::GetInstance()->GetPlugins(base::Bind( |
| 152 &FlashDOMHandler::OnGotPlugins, weak_ptr_factory_.GetWeakPtr())); |
| 153 |
140 // And lastly, we fire off a timer to make sure we never get stuck at the | 154 // And lastly, we fire off a timer to make sure we never get stuck at the |
141 // "Loading..." message. | 155 // "Loading..." message. |
142 timeout_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimeout), | 156 timeout_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimeout), |
143 this, &FlashDOMHandler::OnTimeout); | 157 this, &FlashDOMHandler::OnTimeout); |
144 } | 158 } |
145 | 159 |
146 void FlashDOMHandler::RegisterMessages() { | 160 void FlashDOMHandler::RegisterMessages() { |
147 web_ui_->RegisterMessageCallback("requestFlashInfo", | 161 web_ui_->RegisterMessageCallback("requestFlashInfo", |
148 base::Bind(&FlashDOMHandler::HandleRequestFlashInfo, | 162 base::Bind(&FlashDOMHandler::HandleRequestFlashInfo, |
149 base::Unretained(this))); | 163 base::Unretained(this))); |
(...skipping 18 matching lines...) Expand all Loading... |
168 void FlashDOMHandler::HandleRequestFlashInfo(const ListValue* args) { | 182 void FlashDOMHandler::HandleRequestFlashInfo(const ListValue* args) { |
169 page_has_requested_data_ = true; | 183 page_has_requested_data_ = true; |
170 MaybeRespondToPage(); | 184 MaybeRespondToPage(); |
171 } | 185 } |
172 | 186 |
173 void FlashDOMHandler::OnGpuInfoUpdate() { | 187 void FlashDOMHandler::OnGpuInfoUpdate() { |
174 has_gpu_info_ = true; | 188 has_gpu_info_ = true; |
175 MaybeRespondToPage(); | 189 MaybeRespondToPage(); |
176 } | 190 } |
177 | 191 |
| 192 void FlashDOMHandler::OnGotPlugins( |
| 193 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 194 has_plugin_info_ = true; |
| 195 MaybeRespondToPage(); |
| 196 } |
| 197 |
178 void FlashDOMHandler::OnTimeout() { | 198 void FlashDOMHandler::OnTimeout() { |
179 // We don't set page_has_requested_data_ because that is guaranteed to appear | 199 // We don't set page_has_requested_data_ because that is guaranteed to appear |
180 // and we shouldn't be responding to the page before then. | 200 // and we shouldn't be responding to the page before then. |
181 has_gpu_info_ = true; | 201 has_gpu_info_ = true; |
182 crash_list_available_ = true; | 202 crash_list_available_ = true; |
| 203 has_plugin_info_ = true; |
183 MaybeRespondToPage(); | 204 MaybeRespondToPage(); |
184 } | 205 } |
185 | 206 |
186 void FlashDOMHandler::MaybeRespondToPage() { | 207 void FlashDOMHandler::MaybeRespondToPage() { |
187 // We don't reply until everything is ready. The page is showing a 'loading' | 208 // We don't reply until everything is ready. The page is showing a 'loading' |
188 // message until then. If you add criteria to this list, please update the | 209 // message until then. If you add criteria to this list, please update the |
189 // function OnTimeout() as well. | 210 // function OnTimeout() as well. |
190 if (!page_has_requested_data_ || !crash_list_available_ || !has_gpu_info_) | 211 if (!page_has_requested_data_ || !crash_list_available_ || !has_gpu_info_ || |
| 212 !has_plugin_info_) { |
191 return; | 213 return; |
| 214 } |
192 | 215 |
193 timeout_.Stop(); | 216 timeout_.Stop(); |
194 | 217 |
195 // This is code that runs only when the user types in about:flash. We don't | 218 // This is code that runs only when the user types in about:flash. We don't |
196 // need to jump through hoops to offload this to the IO thread. | 219 // need to jump through hoops to offload this to the IO thread. |
197 base::ThreadRestrictions::ScopedAllowIO allow_io; | 220 base::ThreadRestrictions::ScopedAllowIO allow_io; |
198 | 221 |
199 // Obtain the Chrome version info. | 222 // Obtain the Chrome version info. |
200 chrome::VersionInfo version_info; | 223 chrome::VersionInfo version_info; |
201 | 224 |
(...skipping 23 matching lines...) Expand all Loading... |
225 os_label += " SP" + base::IntToString(os->service_pack().major); | 248 os_label += " SP" + base::IntToString(os->service_pack().major); |
226 if (os->service_pack().minor > 0) | 249 if (os->service_pack().minor > 0) |
227 os_label += "." + base::IntToString(os->service_pack().minor); | 250 os_label += "." + base::IntToString(os->service_pack().minor); |
228 if (os->architecture() == base::win::OSInfo::X64_ARCHITECTURE) | 251 if (os->architecture() == base::win::OSInfo::X64_ARCHITECTURE) |
229 os_label += " 64 bit"; | 252 os_label += " 64 bit"; |
230 #endif | 253 #endif |
231 AddPair(list, l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS), os_label); | 254 AddPair(list, l10n_util::GetStringUTF16(IDS_ABOUT_VERSION_OS), os_label); |
232 | 255 |
233 // Obtain the version of the Flash plugins. | 256 // Obtain the version of the Flash plugins. |
234 std::vector<webkit::WebPluginInfo> info_array; | 257 std::vector<webkit::WebPluginInfo> info_array; |
235 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( | 258 PluginService::GetInstance()->GetPluginInfoArray( |
236 GURL(), "application/x-shockwave-flash", false, NULL, &info_array, NULL); | 259 GURL(), "application/x-shockwave-flash", false, &info_array, NULL); |
237 string16 flash_version; | 260 string16 flash_version; |
238 if (info_array.empty()) { | 261 if (info_array.empty()) { |
239 AddPair(list, ASCIIToUTF16("Flash plugin"), "Disabled"); | 262 AddPair(list, ASCIIToUTF16("Flash plugin"), "Disabled"); |
240 } else { | 263 } else { |
241 PluginPrefs* plugin_prefs = | 264 PluginPrefs* plugin_prefs = |
242 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_)); | 265 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_)); |
243 for (size_t i = 0; i < info_array.size(); ++i) { | 266 for (size_t i = 0; i < info_array.size(); ++i) { |
244 if (plugin_prefs->IsPluginEnabled(info_array[i])) { | 267 if (plugin_prefs->IsPluginEnabled(info_array[i])) { |
245 flash_version = info_array[i].version + ASCIIToUTF16(" ") + | 268 flash_version = info_array[i].version + ASCIIToUTF16(" ") + |
246 info_array[i].path.LossyDisplayName(); | 269 info_array[i].path.LossyDisplayName(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // Set up the about:flash source. | 368 // Set up the about:flash source. |
346 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 369 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
347 profile->GetChromeURLDataManager()->AddDataSource(CreateFlashUIHTMLSource()); | 370 profile->GetChromeURLDataManager()->AddDataSource(CreateFlashUIHTMLSource()); |
348 } | 371 } |
349 | 372 |
350 // static | 373 // static |
351 RefCountedMemory* FlashUI::GetFaviconResourceBytes() { | 374 RefCountedMemory* FlashUI::GetFaviconResourceBytes() { |
352 // Use the default icon for now. | 375 // Use the default icon for now. |
353 return NULL; | 376 return NULL; |
354 } | 377 } |
OLD | NEW |