Chromium Code Reviews| 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/plugins/plugin_observer.h" | 5 #include "chrome/browser/plugins/plugin_observer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/debug/crash_logging.h" | 11 #include "base/debug/crash_logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
| 19 #include "chrome/browser/plugins/plugin_finder.h" | 19 #include "chrome/browser/plugins/plugin_finder.h" |
| 20 #include "chrome/browser/plugins/plugin_infobar_delegates.h" | 20 #include "chrome/browser/plugins/plugin_infobar_delegates.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 22 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
| 23 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 26 #include "components/component_updater/component_updater_service.h" | |
| 26 #include "components/content_settings/content/common/content_settings_messages.h " | 27 #include "components/content_settings/content/common/content_settings_messages.h " |
| 27 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 28 #include "components/infobars/core/confirm_infobar_delegate.h" | 29 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 29 #include "components/infobars/core/infobar.h" | 30 #include "components/infobars/core/infobar.h" |
| 30 #include "components/infobars/core/infobar_delegate.h" | 31 #include "components/infobars/core/infobar_delegate.h" |
| 31 #include "components/infobars/core/simple_alert_infobar_delegate.h" | 32 #include "components/infobars/core/simple_alert_infobar_delegate.h" |
| 32 #include "components/metrics_services_manager/metrics_services_manager.h" | 33 #include "components/metrics_services_manager/metrics_services_manager.h" |
| 33 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
| 34 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
| 35 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 } | 249 } |
| 249 | 250 |
| 250 private: | 251 private: |
| 251 // Weak pointer; owns us. | 252 // Weak pointer; owns us. |
| 252 PluginObserver* observer_; | 253 PluginObserver* observer_; |
| 253 | 254 |
| 254 int routing_id_; | 255 int routing_id_; |
| 255 }; | 256 }; |
| 256 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | 257 #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
| 257 | 258 |
| 259 class ComponentObserver : public update_client::UpdateClient::Observer { | |
| 260 using Events = update_client::UpdateClient::Observer::Events; | |
|
Bernhard Bauer
2016/07/28 10:25:10
Should this come inside of the public: section?
waffles
2016/07/28 20:06:27
Done.
| |
| 261 | |
| 262 public: | |
| 263 ComponentObserver( | |
| 264 PluginObserver* observer, | |
| 265 int routing_id, | |
| 266 const std::string& component_id) | |
| 267 : observer_(observer), | |
| 268 routing_id_(routing_id), | |
|
Bernhard Bauer
2016/07/28 10:25:10
I think these should be aligned with |observer_|?
waffles
2016/07/28 20:06:27
Done.
| |
| 269 component_id_(component_id) { | |
| 270 } | |
| 271 | |
| 272 void OnEvent(Events event, const std::string& id) override { | |
| 273 if (id != component_id_) { | |
|
Bernhard Bauer
2016/07/28 10:25:10
Nit: no braces for single-line bodies.
waffles
2016/07/28 20:06:27
Done.
| |
| 274 return; | |
| 275 } | |
| 276 switch (event) { | |
| 277 case Events::COMPONENT_UPDATED: | |
| 278 observer_->Send( | |
| 279 new ChromeViewMsg_PluginComponentUpdateSuccess(routing_id_)); | |
| 280 observer_->RemoveComponentObserver(routing_id_); | |
| 281 break; | |
| 282 case Events::COMPONENT_UPDATE_FOUND: | |
| 283 observer_->Send( | |
| 284 new ChromeViewMsg_PluginComponentUpdateDownloading(routing_id_)); | |
| 285 break; | |
| 286 case Events::COMPONENT_NOT_UPDATED: | |
| 287 observer_->Send( | |
| 288 new ChromeViewMsg_PluginComponentUpdateFailure(routing_id_)); | |
| 289 observer_->RemoveComponentObserver(routing_id_); | |
| 290 break; | |
| 291 default: | |
| 292 // No message to send. | |
| 293 break; | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 private: | |
| 298 PluginObserver* observer_; | |
| 299 int routing_id_; | |
| 300 std::string component_id_; | |
|
Bernhard Bauer
2016/07/28 10:25:10
DISALLOW_COPY_AND_ASSIGN?
waffles
2016/07/28 20:06:27
Done.
| |
| 301 }; | |
| 302 | |
| 258 PluginObserver::PluginObserver(content::WebContents* web_contents) | 303 PluginObserver::PluginObserver(content::WebContents* web_contents) |
| 259 : content::WebContentsObserver(web_contents), | 304 : content::WebContentsObserver(web_contents), |
| 260 weak_ptr_factory_(this) { | 305 weak_ptr_factory_(this) { |
| 261 } | 306 } |
| 262 | 307 |
| 263 PluginObserver::~PluginObserver() { | 308 PluginObserver::~PluginObserver() { |
| 264 #if defined(ENABLE_PLUGIN_INSTALLATION) | 309 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 265 STLDeleteValues(&plugin_placeholders_); | 310 STLDeleteValues(&plugin_placeholders_); |
| 266 #endif | 311 #endif |
|
Bernhard Bauer
2016/07/28 10:25:10
Another advantage of using unique_ptr<> in the map
waffles
2016/07/28 20:06:27
Acknowledged.
| |
| 267 } | 312 } |
| 268 | 313 |
| 269 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path, | 314 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path, |
| 270 base::ProcessId plugin_pid) { | 315 base::ProcessId plugin_pid) { |
| 271 DCHECK(!plugin_path.value().empty()); | 316 DCHECK(!plugin_path.value().empty()); |
| 272 | 317 |
| 273 base::string16 plugin_name = | 318 base::string16 plugin_name = |
| 274 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); | 319 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); |
| 275 base::string16 infobar_text; | 320 base::string16 infobar_text; |
| 276 #if defined(OS_WIN) | 321 #if defined(OS_WIN) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 &web_contents()->GetController(), | 359 &web_contents()->GetController(), |
| 315 infobar_text); | 360 infobar_text); |
| 316 } | 361 } |
| 317 | 362 |
| 318 bool PluginObserver::OnMessageReceived( | 363 bool PluginObserver::OnMessageReceived( |
| 319 const IPC::Message& message, | 364 const IPC::Message& message, |
| 320 content::RenderFrameHost* render_frame_host) { | 365 content::RenderFrameHost* render_frame_host) { |
| 321 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) | 366 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) |
| 322 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, | 367 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, |
| 323 OnBlockedOutdatedPlugin) | 368 OnBlockedOutdatedPlugin) |
| 369 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUpdatePlugin, | |
| 370 OnBlockedUpdatePlugin) | |
| 324 #if defined(ENABLE_PLUGIN_INSTALLATION) | 371 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 325 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, | 372 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, |
| 326 OnRemovePluginPlaceholderHost) | 373 OnRemovePluginPlaceholderHost) |
| 327 #endif | 374 #endif |
| 328 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins, | 375 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins, |
| 329 OnOpenAboutPlugins) | 376 OnOpenAboutPlugins) |
| 330 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin, | 377 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin, |
| 331 OnCouldNotLoadPlugin) | 378 OnCouldNotLoadPlugin) |
| 332 | 379 |
| 333 IPC_MESSAGE_UNHANDLED(return false) | 380 IPC_MESSAGE_UNHANDLED(return false) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 352 } else { | 399 } else { |
| 353 NOTREACHED(); | 400 NOTREACHED(); |
| 354 } | 401 } |
| 355 #else | 402 #else |
| 356 // If we don't support third-party plugin installation, we shouldn't have | 403 // If we don't support third-party plugin installation, we shouldn't have |
| 357 // outdated plugins. | 404 // outdated plugins. |
| 358 NOTREACHED(); | 405 NOTREACHED(); |
| 359 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | 406 #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
| 360 } | 407 } |
| 361 | 408 |
| 409 void PluginObserver::OnBlockedUpdatePlugin(int placeholder_id, | |
| 410 const std::string& identifier) { | |
| 411 ComponentObserver* observer = | |
| 412 new ComponentObserver(this, placeholder_id, identifier); | |
| 413 component_observers_[placeholder_id] = observer; | |
| 414 component_updater::ComponentUpdateService* cus = | |
| 415 g_browser_process->component_updater(); | |
| 416 cus->AddObserver(observer); | |
| 417 cus->GetOnDemandUpdater().OnDemandUpdate(identifier); | |
| 418 } | |
| 419 | |
| 420 void PluginObserver::RemoveComponentObserver(int placeholder_id) { | |
| 421 std::map<int, ComponentObserver*>::iterator it = | |
| 422 component_observers_.find(placeholder_id); | |
| 423 if (it == component_observers_.end()) { | |
| 424 NOTREACHED(); | |
| 425 return; | |
| 426 } | |
| 427 g_browser_process->component_updater()->RemoveObserver(it->second); | |
| 428 delete it->second; | |
| 429 component_observers_.erase(it); | |
| 430 } | |
| 431 | |
| 362 #if defined(ENABLE_PLUGIN_INSTALLATION) | 432 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 363 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { | 433 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { |
| 364 std::map<int, PluginPlaceholderHost*>::iterator it = | 434 std::map<int, PluginPlaceholderHost*>::iterator it = |
| 365 plugin_placeholders_.find(placeholder_id); | 435 plugin_placeholders_.find(placeholder_id); |
| 366 if (it == plugin_placeholders_.end()) { | 436 if (it == plugin_placeholders_.end()) { |
| 367 NOTREACHED(); | 437 NOTREACHED(); |
| 368 return; | 438 return; |
| 369 } | 439 } |
| 370 delete it->second; | 440 delete it->second; |
| 371 plugin_placeholders_.erase(it); | 441 plugin_placeholders_.erase(it); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 393 IDR_INFOBAR_PLUGIN_CRASHED, | 463 IDR_INFOBAR_PLUGIN_CRASHED, |
| 394 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 464 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 395 gfx::VectorIconId::EXTENSION_CRASHED, | 465 gfx::VectorIconId::EXTENSION_CRASHED, |
| 396 #else | 466 #else |
| 397 gfx::VectorIconId::VECTOR_ICON_NONE, | 467 gfx::VectorIconId::VECTOR_ICON_NONE, |
| 398 #endif | 468 #endif |
| 399 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, | 469 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, |
| 400 plugin_name), | 470 plugin_name), |
| 401 true); | 471 true); |
| 402 } | 472 } |
| OLD | NEW |