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/plugin_infobar_delegates.h" | 5 #include "chrome/browser/plugin_infobar_delegates.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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 | 45 |
46 PluginInfoBarDelegate::~PluginInfoBarDelegate() { | 46 PluginInfoBarDelegate::~PluginInfoBarDelegate() { |
47 } | 47 } |
48 | 48 |
49 bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 49 bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
50 OpenURLParams params( | 50 OpenURLParams params( |
51 GURL(GetLearnMoreURL()), Referrer(), | 51 GURL(GetLearnMoreURL()), Referrer(), |
52 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 52 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
53 content::PAGE_TRANSITION_LINK, | 53 content::PAGE_TRANSITION_LINK, |
54 false); | 54 false); |
55 owner()->web_contents()->OpenURL(params); | 55 owner()->GetWebContents()->OpenURL(params); |
56 return false; | 56 return false; |
57 } | 57 } |
58 | 58 |
59 void PluginInfoBarDelegate::LoadBlockedPlugins() { | 59 void PluginInfoBarDelegate::LoadBlockedPlugins() { |
60 owner()->Send( | 60 content::WebContents* web_contents = owner()->GetWebContents(); |
61 new ChromeViewMsg_LoadBlockedPlugins(owner()->routing_id(), identifier_)); | 61 if (web_contents) { |
62 web_contents->Send(new ChromeViewMsg_LoadBlockedPlugins( | |
63 web_contents->GetRoutingID(), identifier_)); | |
64 } | |
62 } | 65 } |
63 | 66 |
64 gfx::Image* PluginInfoBarDelegate::GetIcon() const { | 67 gfx::Image* PluginInfoBarDelegate::GetIcon() const { |
65 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 68 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
66 IDR_INFOBAR_PLUGIN_INSTALL); | 69 IDR_INFOBAR_PLUGIN_INSTALL); |
67 } | 70 } |
68 | 71 |
69 string16 PluginInfoBarDelegate::GetLinkText() const { | 72 string16 PluginInfoBarDelegate::GetLinkText() const { |
70 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 73 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
71 } | 74 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 bool UnauthorizedPluginInfoBarDelegate::Accept() { | 122 bool UnauthorizedPluginInfoBarDelegate::Accept() { |
120 content::RecordAction( | 123 content::RecordAction( |
121 UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); | 124 UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); |
122 LoadBlockedPlugins(); | 125 LoadBlockedPlugins(); |
123 return true; | 126 return true; |
124 } | 127 } |
125 | 128 |
126 bool UnauthorizedPluginInfoBarDelegate::Cancel() { | 129 bool UnauthorizedPluginInfoBarDelegate::Cancel() { |
127 content::RecordAction( | 130 content::RecordAction( |
128 UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); | 131 UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); |
129 content_settings_->AddExceptionForURL(owner()->web_contents()->GetURL(), | 132 content_settings_->AddExceptionForURL(owner()->GetWebContents()->GetURL(), |
130 owner()->web_contents()->GetURL(), | 133 owner()->GetWebContents()->GetURL(), |
131 CONTENT_SETTINGS_TYPE_PLUGINS, | 134 CONTENT_SETTINGS_TYPE_PLUGINS, |
132 std::string(), | 135 std::string(), |
133 CONTENT_SETTING_ALLOW); | 136 CONTENT_SETTING_ALLOW); |
134 LoadBlockedPlugins(); | 137 LoadBlockedPlugins(); |
135 return true; | 138 return true; |
136 } | 139 } |
137 | 140 |
138 void UnauthorizedPluginInfoBarDelegate::InfoBarDismissed() { | 141 void UnauthorizedPluginInfoBarDelegate::InfoBarDismissed() { |
139 content::RecordAction( | 142 content::RecordAction( |
140 UserMetricsAction("BlockedPluginInfobar.Dismissed")); | 143 UserMetricsAction("BlockedPluginInfobar.Dismissed")); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); | 222 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); |
220 } | 223 } |
221 | 224 |
222 bool OutdatedPluginInfoBarDelegate::Accept() { | 225 bool OutdatedPluginInfoBarDelegate::Accept() { |
223 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); | 226 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); |
224 if (installer()->state() != PluginInstaller::INSTALLER_STATE_IDLE) { | 227 if (installer()->state() != PluginInstaller::INSTALLER_STATE_IDLE) { |
225 NOTREACHED(); | 228 NOTREACHED(); |
226 return false; | 229 return false; |
227 } | 230 } |
228 | 231 |
229 content::WebContents* web_contents = owner()->web_contents(); | 232 content::WebContents* web_contents = owner()->GetWebContents(); |
230 if (installer()->url_for_display()) { | 233 if (installer()->url_for_display()) { |
231 installer()->OpenDownloadURL(web_contents); | 234 installer()->OpenDownloadURL(web_contents); |
232 } else { | 235 } else { |
233 installer()->StartInstalling(observer_->tab_contents()); | 236 installer()->StartInstalling(observer_->tab_contents()); |
234 } | 237 } |
235 return false; | 238 return false; |
236 } | 239 } |
237 | 240 |
238 bool OutdatedPluginInfoBarDelegate::Cancel() { | 241 bool OutdatedPluginInfoBarDelegate::Cancel() { |
239 content::RecordAction( | 242 content::RecordAction( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( | 286 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( |
284 const string16& message) { | 287 const string16& message) { |
285 // Return early if the message doesn't change. This is important in case the | 288 // Return early if the message doesn't change. This is important in case the |
286 // PluginInstaller is still iterating over its observers (otherwise we would | 289 // PluginInstaller is still iterating over its observers (otherwise we would |
287 // keep replacing infobar delegates infinitely). | 290 // keep replacing infobar delegates infinitely). |
288 if (message_ == message) | 291 if (message_ == message) |
289 return; | 292 return; |
290 if (!owner()) | 293 if (!owner()) |
291 return; | 294 return; |
292 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( | 295 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( |
293 owner(), installer(), base::Closure(), false, message); | 296 static_cast<InfoBarTabHelper*>(owner()), |
erikwright (departed)
2012/08/20 05:54:46
Perhaps it would make sense to convert PluginInsta
Jói
2012/08/20 12:30:15
Done.
| |
297 installer(), base::Closure(), false, message); | |
294 owner()->ReplaceInfoBar(this, delegate); | 298 owner()->ReplaceInfoBar(this, delegate); |
295 } | 299 } |
296 | 300 |
297 // PluginInstallerInfoBarDelegate --------------------------------------------- | 301 // PluginInstallerInfoBarDelegate --------------------------------------------- |
298 | 302 |
299 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate( | 303 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate( |
300 InfoBarTabHelper* infobar_helper, | 304 InfoBarTabHelper* infobar_helper, |
301 PluginInstaller* installer, | 305 PluginInstaller* installer, |
302 const base::Closure& callback, | 306 const base::Closure& callback, |
303 bool new_install, | 307 bool new_install, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 GURL url(installer()->help_url()); | 370 GURL url(installer()->help_url()); |
367 if (url.is_empty()) { | 371 if (url.is_empty()) { |
368 url = google_util::AppendGoogleLocaleParam(GURL( | 372 url = google_util::AppendGoogleLocaleParam(GURL( |
369 "https://www.google.com/support/chrome/bin/answer.py?answer=142064")); | 373 "https://www.google.com/support/chrome/bin/answer.py?answer=142064")); |
370 } | 374 } |
371 | 375 |
372 OpenURLParams params( | 376 OpenURLParams params( |
373 url, Referrer(), | 377 url, Referrer(), |
374 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 378 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
375 content::PAGE_TRANSITION_LINK, false); | 379 content::PAGE_TRANSITION_LINK, false); |
376 owner()->web_contents()->OpenURL(params); | 380 owner()->GetWebContents()->OpenURL(params); |
377 return false; | 381 return false; |
378 } | 382 } |
379 | 383 |
380 void PluginInstallerInfoBarDelegate::DownloadStarted() { | 384 void PluginInstallerInfoBarDelegate::DownloadStarted() { |
381 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING, | 385 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING, |
382 installer()->name())); | 386 installer()->name())); |
383 } | 387 } |
384 | 388 |
385 void PluginInstallerInfoBarDelegate::DownloadCancelled() { | 389 void PluginInstallerInfoBarDelegate::DownloadCancelled() { |
386 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED, | 390 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED, |
(...skipping 20 matching lines...) Expand all Loading... | |
407 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( | 411 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( |
408 const string16& message) { | 412 const string16& message) { |
409 // Return early if the message doesn't change. This is important in case the | 413 // Return early if the message doesn't change. This is important in case the |
410 // PluginInstaller is still iterating over its observers (otherwise we would | 414 // PluginInstaller is still iterating over its observers (otherwise we would |
411 // keep replacing infobar delegates infinitely). | 415 // keep replacing infobar delegates infinitely). |
412 if (message_ == message) | 416 if (message_ == message) |
413 return; | 417 return; |
414 if (!owner()) | 418 if (!owner()) |
415 return; | 419 return; |
416 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( | 420 InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( |
417 owner(), installer(), base::Closure(), new_install_, message); | 421 static_cast<InfoBarTabHelper*>(owner()), |
422 installer(), base::Closure(), new_install_, message); | |
418 owner()->ReplaceInfoBar(this, delegate); | 423 owner()->ReplaceInfoBar(this, delegate); |
419 } | 424 } |
420 | 425 |
421 // PluginMetroModeInfoBarDelegate --------------------------------------------- | 426 // PluginMetroModeInfoBarDelegate --------------------------------------------- |
422 #if defined(OS_WIN) | 427 #if defined(OS_WIN) |
423 InfoBarDelegate* PluginMetroModeInfoBarDelegate::Create( | 428 InfoBarDelegate* PluginMetroModeInfoBarDelegate::Create( |
424 InfoBarTabHelper* infobar_helper, const string16& plugin_name) { | 429 InfoBarTabHelper* infobar_helper, const string16& plugin_name) { |
425 string16 message = l10n_util::GetStringFUTF16( | 430 string16 message = l10n_util::GetStringFUTF16( |
426 IDS_METRO_MISSING_PLUGIN_PROMPT, plugin_name); | 431 IDS_METRO_MISSING_PLUGIN_PROMPT, plugin_name); |
427 return new PluginMetroModeInfoBarDelegate( | 432 return new PluginMetroModeInfoBarDelegate( |
(...skipping 22 matching lines...) Expand all Loading... | |
450 return BUTTON_OK; | 455 return BUTTON_OK; |
451 } | 456 } |
452 | 457 |
453 string16 PluginMetroModeInfoBarDelegate::GetButtonLabel( | 458 string16 PluginMetroModeInfoBarDelegate::GetButtonLabel( |
454 InfoBarButton button) const { | 459 InfoBarButton button) const { |
455 DCHECK_EQ(BUTTON_OK, button); | 460 DCHECK_EQ(BUTTON_OK, button); |
456 return l10n_util::GetStringUTF16(IDS_METRO_SWITCH_TO_DESKTOP_BUTTON); | 461 return l10n_util::GetStringUTF16(IDS_METRO_SWITCH_TO_DESKTOP_BUTTON); |
457 } | 462 } |
458 | 463 |
459 bool PluginMetroModeInfoBarDelegate::Accept() { | 464 bool PluginMetroModeInfoBarDelegate::Accept() { |
460 content::WebContents* web_contents = owner()->web_contents(); | 465 content::WebContents* web_contents = owner()->GetWebContents(); |
461 if (!web_contents) | 466 if (!web_contents) |
462 return false; | 467 return false; |
463 // Note that empty urls are not valid. | 468 // Note that empty urls are not valid. |
464 if (!web_contents->GetURL().is_valid()) | 469 if (!web_contents->GetURL().is_valid()) |
465 return false; | 470 return false; |
466 std::string url(web_contents->GetURL().spec()); | 471 std::string url(web_contents->GetURL().spec()); |
467 // This obscure use of the 'log usage' mask for windows 8 is documented | 472 // This obscure use of the 'log usage' mask for windows 8 is documented |
468 // here http://goo.gl/HBOe9. | 473 // here http://goo.gl/HBOe9. |
469 ui::win::OpenAnyViaShell(UTF8ToUTF16(url), | 474 ui::win::OpenAnyViaShell(UTF8ToUTF16(url), |
470 string16(), | 475 string16(), |
471 SEE_MASK_FLAG_LOG_USAGE); | 476 SEE_MASK_FLAG_LOG_USAGE); |
472 return true; | 477 return true; |
473 } | 478 } |
474 | 479 |
475 string16 PluginMetroModeInfoBarDelegate::GetLinkText() const { | 480 string16 PluginMetroModeInfoBarDelegate::GetLinkText() const { |
476 return l10n_util::GetStringUTF16(IDS_METRO_SWITCH_WHY_LINK); | 481 return l10n_util::GetStringUTF16(IDS_METRO_SWITCH_WHY_LINK); |
477 } | 482 } |
478 | 483 |
479 bool PluginMetroModeInfoBarDelegate::LinkClicked( | 484 bool PluginMetroModeInfoBarDelegate::LinkClicked( |
480 WindowOpenDisposition disposition) { | 485 WindowOpenDisposition disposition) { |
481 // TODO(cpu): replace with the final url. | 486 // TODO(cpu): replace with the final url. |
482 GURL url = google_util::AppendGoogleLocaleParam(GURL( | 487 GURL url = google_util::AppendGoogleLocaleParam(GURL( |
483 "https://support.google.com/chrome/?ib_display_in_desktop")); | 488 "https://support.google.com/chrome/?ib_display_in_desktop")); |
484 OpenURLParams params( | 489 OpenURLParams params( |
485 url, Referrer(), | 490 url, Referrer(), |
486 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 491 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
487 content::PAGE_TRANSITION_LINK, false); | 492 content::PAGE_TRANSITION_LINK, false); |
488 owner()->web_contents()->OpenURL(params); | 493 owner()->GetWebContents()->OpenURL(params); |
489 return false; | 494 return false; |
490 } | 495 } |
491 #endif // defined(OS_WIN) | 496 #endif // defined(OS_WIN) |
492 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | 497 #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
OLD | NEW |