| 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/plugin_observer.h" | 5 #include "chrome/browser/plugin_observer.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 9 #include "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
| 10 #include "chrome/browser/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 13 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 17 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
| 18 #include "content/browser/user_metrics.h" | 17 #include "content/browser/user_metrics.h" |
| 19 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 20 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 21 #include "grit/theme_resources_standard.h" | 20 #include "grit/theme_resources_standard.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 PluginObserver::PluginObserver(TabContentsWrapper* tab_contents) | 285 PluginObserver::PluginObserver(TabContentsWrapper* tab_contents) |
| 287 : TabContentsObserver(tab_contents->tab_contents()), | 286 : TabContentsObserver(tab_contents->tab_contents()), |
| 288 tab_contents_(tab_contents) { | 287 tab_contents_(tab_contents) { |
| 289 } | 288 } |
| 290 | 289 |
| 291 PluginObserver::~PluginObserver() { | 290 PluginObserver::~PluginObserver() { |
| 292 } | 291 } |
| 293 | 292 |
| 294 bool PluginObserver::OnMessageReceived(const IPC::Message& message) { | 293 bool PluginObserver::OnMessageReceived(const IPC::Message& message) { |
| 295 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) | 294 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) |
| 296 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) | |
| 297 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, | 295 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, |
| 298 OnBlockedOutdatedPlugin) | 296 OnBlockedOutdatedPlugin) |
| 299 IPC_MESSAGE_UNHANDLED(return false) | 297 IPC_MESSAGE_UNHANDLED(return false) |
| 300 IPC_END_MESSAGE_MAP() | 298 IPC_END_MESSAGE_MAP() |
| 301 | 299 |
| 302 return true; | 300 return true; |
| 303 } | 301 } |
| 304 | 302 |
| 305 void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) { | |
| 306 DCHECK(!plugin_path.value().empty()); | |
| 307 | |
| 308 string16 plugin_name = plugin_path.LossyDisplayName(); | |
| 309 webkit::WebPluginInfo plugin_info; | |
| 310 if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | |
| 311 plugin_path, &plugin_info) && | |
| 312 !plugin_info.name.empty()) { | |
| 313 plugin_name = plugin_info.name; | |
| 314 #if defined(OS_MACOSX) | |
| 315 // Many plugins on the Mac have .plugin in the actual name, which looks | |
| 316 // terrible, so look for that and strip it off if present. | |
| 317 const std::string kPluginExtension = ".plugin"; | |
| 318 if (EndsWith(plugin_name, ASCIIToUTF16(kPluginExtension), true)) | |
| 319 plugin_name.erase(plugin_name.length() - kPluginExtension.length()); | |
| 320 #endif // OS_MACOSX | |
| 321 } | |
| 322 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 323 IDR_INFOBAR_PLUGIN_CRASHED); | |
| 324 tab_contents_->infobar_tab_helper()->AddInfoBar( | |
| 325 new SimpleAlertInfoBarDelegate( | |
| 326 tab_contents(), | |
| 327 icon, | |
| 328 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), | |
| 329 true)); | |
| 330 } | |
| 331 | |
| 332 void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, | 303 void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, |
| 333 const GURL& update_url) { | 304 const GURL& update_url) { |
| 334 tab_contents_->infobar_tab_helper()->AddInfoBar(update_url.is_empty() ? | 305 tab_contents_->infobar_tab_helper()->AddInfoBar(update_url.is_empty() ? |
| 335 static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( | 306 static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( |
| 336 tab_contents(), name)) : | 307 tab_contents(), name)) : |
| 337 new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url)); | 308 new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url)); |
| 338 } | 309 } |
| OLD | NEW |