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/plugin_installer_infobar_delegate.h" | 11 #include "chrome/browser/plugin_installer_infobar_delegate.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
13 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 14 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
15 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "content/browser/user_metrics.h" | 19 #include "content/browser/user_metrics.h" |
19 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 PluginInstallerInfoBarDelegate* PluginObserver::GetPluginInstaller() { | 308 PluginInstallerInfoBarDelegate* PluginObserver::GetPluginInstaller() { |
308 if (plugin_installer_ == NULL) | 309 if (plugin_installer_ == NULL) |
309 plugin_installer_.reset(new PluginInstallerInfoBarDelegate(tab_contents())); | 310 plugin_installer_.reset(new PluginInstallerInfoBarDelegate(tab_contents())); |
310 return plugin_installer_->AsPluginInstallerInfoBarDelegate(); | 311 return plugin_installer_->AsPluginInstallerInfoBarDelegate(); |
311 } | 312 } |
312 | 313 |
313 void PluginObserver::OnMissingPluginStatus(int status) { | 314 void PluginObserver::OnMissingPluginStatus(int status) { |
314 // TODO(PORT): pull in when plug-ins work | 315 // TODO(PORT): pull in when plug-ins work |
315 #if defined(OS_WIN) | 316 #if defined(OS_WIN) |
316 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) { | 317 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) { |
317 tab_contents_->AddInfoBar( | 318 tab_contents_->infobar_tab_helper()->AddInfoBar( |
Peter Kasting
2011/08/31 18:47:32
Nit: Factor this infobar_tab_helper() out to a tem
| |
318 new PluginInstallerInfoBarDelegate(tab_contents())); | 319 new PluginInstallerInfoBarDelegate(tab_contents())); |
319 return; | 320 return; |
320 } | 321 } |
321 | 322 |
322 DCHECK_EQ(webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD, | 323 DCHECK_EQ(webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD, |
323 status); | 324 status); |
324 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { | 325 for (size_t i = 0; |
325 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); | 326 i < tab_contents_->infobar_tab_helper()->infobar_count(); |
327 ++i) { | |
328 InfoBarDelegate* delegate = | |
329 tab_contents_->infobar_tab_helper()->GetInfoBarDelegateAt(i); | |
326 if (delegate->AsPluginInstallerInfoBarDelegate() != NULL) { | 330 if (delegate->AsPluginInstallerInfoBarDelegate() != NULL) { |
327 tab_contents_->RemoveInfoBar(delegate); | 331 tab_contents_->infobar_tab_helper()->RemoveInfoBar(delegate); |
328 return; | 332 return; |
329 } | 333 } |
330 } | 334 } |
331 #endif | 335 #endif |
332 } | 336 } |
333 | 337 |
334 void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) { | 338 void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) { |
335 DCHECK(!plugin_path.value().empty()); | 339 DCHECK(!plugin_path.value().empty()); |
336 | 340 |
337 string16 plugin_name = plugin_path.LossyDisplayName(); | 341 string16 plugin_name = plugin_path.LossyDisplayName(); |
338 webkit::WebPluginInfo plugin_info; | 342 webkit::WebPluginInfo plugin_info; |
339 if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | 343 if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
340 plugin_path, &plugin_info) && | 344 plugin_path, &plugin_info) && |
341 !plugin_info.name.empty()) { | 345 !plugin_info.name.empty()) { |
342 plugin_name = plugin_info.name; | 346 plugin_name = plugin_info.name; |
343 #if defined(OS_MACOSX) | 347 #if defined(OS_MACOSX) |
344 // Many plugins on the Mac have .plugin in the actual name, which looks | 348 // Many plugins on the Mac have .plugin in the actual name, which looks |
345 // terrible, so look for that and strip it off if present. | 349 // terrible, so look for that and strip it off if present. |
346 const std::string kPluginExtension = ".plugin"; | 350 const std::string kPluginExtension = ".plugin"; |
347 if (EndsWith(plugin_name, ASCIIToUTF16(kPluginExtension), true)) | 351 if (EndsWith(plugin_name, ASCIIToUTF16(kPluginExtension), true)) |
348 plugin_name.erase(plugin_name.length() - kPluginExtension.length()); | 352 plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
349 #endif // OS_MACOSX | 353 #endif // OS_MACOSX |
350 } | 354 } |
351 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 355 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
352 IDR_INFOBAR_PLUGIN_CRASHED); | 356 IDR_INFOBAR_PLUGIN_CRASHED); |
353 tab_contents_->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), | 357 tab_contents_->infobar_tab_helper()->AddInfoBar( |
354 icon, | 358 new SimpleAlertInfoBarDelegate( |
355 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), | 359 tab_contents(), |
356 true)); | 360 icon, |
361 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), | |
362 true)); | |
357 } | 363 } |
358 | 364 |
359 void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, | 365 void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, |
360 const GURL& update_url) { | 366 const GURL& update_url) { |
361 tab_contents_->AddInfoBar(update_url.is_empty() ? | 367 tab_contents_->infobar_tab_helper()->AddInfoBar(update_url.is_empty() ? |
362 static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( | 368 static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( |
363 tab_contents(), name)) : | 369 tab_contents(), name)) : |
364 new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url)); | 370 new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url)); |
365 } | 371 } |
OLD | NEW |