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/tab_contents/tab_contents_wrapper.h" | 5 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 | 8 |
9 #include "base/command_line.h" | |
10 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
11 #include "base/utf_string_conversions.h" | 10 #include "base/stringprintf.h" |
12 #include "chrome/browser/autocomplete_history_manager.h" | 11 #include "chrome/browser/autocomplete_history_manager.h" |
13 #include "chrome/browser/autofill/autofill_manager.h" | 12 #include "chrome/browser/autofill/autofill_manager.h" |
14 #include "chrome/browser/automation/automation_tab_helper.h" | 13 #include "chrome/browser/automation/automation_tab_helper.h" |
15 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/browser_shutdown.h" | 15 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
18 #include "chrome/browser/download/download_request_limiter_observer.h" | 17 #include "chrome/browser/download/download_request_limiter_observer.h" |
19 #include "chrome/browser/extensions/extension_tab_helper.h" | 18 #include "chrome/browser/extensions/extension_tab_helper.h" |
20 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 19 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
21 #include "chrome/browser/external_protocol/external_protocol_observer.h" | 20 #include "chrome/browser/external_protocol/external_protocol_observer.h" |
22 #include "chrome/browser/favicon/favicon_tab_helper.h" | 21 #include "chrome/browser/favicon/favicon_tab_helper.h" |
23 #include "chrome/browser/file_select_helper.h" | |
24 #include "chrome/browser/google/google_util.h" | 22 #include "chrome/browser/google/google_util.h" |
25 #include "chrome/browser/history/history_tab_helper.h" | 23 #include "chrome/browser/history/history_tab_helper.h" |
26 #include "chrome/browser/intents/web_intent_data.h" | 24 #include "chrome/browser/infobars/infobar_tab_helper.h" |
27 #include "chrome/browser/omnibox_search_hint.h" | 25 #include "chrome/browser/omnibox_search_hint.h" |
28 #include "chrome/browser/password_manager/password_manager.h" | 26 #include "chrome/browser/password_manager/password_manager.h" |
29 #include "chrome/browser/password_manager_delegate_impl.h" | 27 #include "chrome/browser/password_manager_delegate_impl.h" |
30 #include "chrome/browser/pdf_unsupported_feature.h" | 28 #include "chrome/browser/pdf_unsupported_feature.h" |
31 #include "chrome/browser/plugin_observer.h" | 29 #include "chrome/browser/plugin_observer.h" |
32 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
33 #include "chrome/browser/prerender/prerender_tab_helper.h" | 31 #include "chrome/browser/prerender/prerender_tab_helper.h" |
34 #include "chrome/browser/printing/print_preview_message_handler.h" | 32 #include "chrome/browser/printing/print_preview_message_handler.h" |
35 #include "chrome/browser/printing/print_view_manager.h" | 33 #include "chrome/browser/printing/print_view_manager.h" |
36 #include "chrome/browser/profiles/profile.h" | |
37 #include "chrome/browser/remoting/firewall_traversal_observer.h" | 34 #include "chrome/browser/remoting/firewall_traversal_observer.h" |
38 #include "chrome/browser/renderer_host/web_cache_manager.h" | 35 #include "chrome/browser/renderer_host/web_cache_manager.h" |
39 #include "chrome/browser/renderer_preferences_util.h" | 36 #include "chrome/browser/renderer_preferences_util.h" |
40 #include "chrome/browser/sessions/restore_tab_helper.h" | 37 #include "chrome/browser/sessions/restore_tab_helper.h" |
41 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 38 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
42 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | |
43 #include "chrome/browser/tab_contents/infobar.h" | |
44 #include "chrome/browser/tab_contents/infobar_delegate.h" | |
45 #include "chrome/browser/tab_contents/insecure_content_infobar_delegate.h" | |
46 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | |
47 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" | 39 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
48 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 40 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
49 #include "chrome/browser/themes/theme_service.h" | 41 #include "chrome/browser/themes/theme_service.h" |
50 #include "chrome/browser/themes/theme_service_factory.h" | 42 #include "chrome/browser/themes/theme_service_factory.h" |
51 #include "chrome/browser/translate/translate_tab_helper.h" | 43 #include "chrome/browser/translate/translate_tab_helper.h" |
52 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 44 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
53 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 45 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
54 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 46 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
55 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 47 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
56 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 48 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
57 #include "chrome/common/chrome_notification_types.h" | 49 #include "chrome/common/chrome_notification_types.h" |
58 #include "chrome/common/chrome_switches.h" | 50 #include "chrome/common/chrome_switches.h" |
59 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
60 #include "chrome/common/render_messages.h" | 52 #include "chrome/common/render_messages.h" |
61 #include "content/browser/child_process_security_policy.h" | |
62 #include "content/browser/renderer_host/render_view_host.h" | 53 #include "content/browser/renderer_host/render_view_host.h" |
63 #include "content/browser/tab_contents/navigation_details.h" | |
64 #include "content/browser/tab_contents/tab_contents.h" | |
65 #include "content/browser/tab_contents/tab_contents_view.h" | 54 #include "content/browser/tab_contents/tab_contents_view.h" |
66 #include "content/browser/user_metrics.h" | |
67 #include "content/common/notification_service.h" | 55 #include "content/common/notification_service.h" |
68 #include "content/common/view_messages.h" | 56 #include "content/common/view_messages.h" |
69 #include "grit/generated_resources.h" | 57 #include "grit/generated_resources.h" |
70 #include "grit/locale_settings.h" | 58 #include "grit/locale_settings.h" |
71 #include "grit/platform_locale_settings.h" | 59 #include "grit/platform_locale_settings.h" |
72 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
73 #include "webkit/glue/webpreferences.h" | 61 #include "webkit/glue/webpreferences.h" |
74 | 62 |
75 namespace { | 63 namespace { |
76 | 64 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 #endif | 191 #endif |
204 | 192 |
205 } // namespace | 193 } // namespace |
206 | 194 |
207 //////////////////////////////////////////////////////////////////////////////// | 195 //////////////////////////////////////////////////////////////////////////////// |
208 // TabContentsWrapper, public: | 196 // TabContentsWrapper, public: |
209 | 197 |
210 TabContentsWrapper::TabContentsWrapper(TabContents* contents) | 198 TabContentsWrapper::TabContentsWrapper(TabContents* contents) |
211 : TabContentsObserver(contents), | 199 : TabContentsObserver(contents), |
212 delegate_(NULL), | 200 delegate_(NULL), |
213 infobars_enabled_(true), | |
214 ALLOW_THIS_IN_INITIALIZER_LIST( | 201 ALLOW_THIS_IN_INITIALIZER_LIST( |
215 synced_tab_delegate_(new TabContentsWrapperSyncedTabDelegate(this))), | 202 synced_tab_delegate_(new TabContentsWrapperSyncedTabDelegate(this))), |
216 in_destructor_(false), | 203 in_destructor_(false), |
217 tab_contents_(contents) { | 204 tab_contents_(contents) { |
218 DCHECK(contents); | 205 DCHECK(contents); |
219 DCHECK(!GetCurrentWrapperForContents(contents)); | 206 DCHECK(!GetCurrentWrapperForContents(contents)); |
220 // Stash this in the property bag so it can be retrieved without having to | 207 // Stash this in the property bag so it can be retrieved without having to |
221 // go to a Browser. | 208 // go to a Browser. |
222 property_accessor()->SetProperty(contents->property_bag(), this); | 209 property_accessor()->SetProperty(contents->property_bag(), this); |
223 | 210 |
224 // Create the tab helpers. | 211 // Create the tab helpers. |
225 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); | 212 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); |
226 autofill_manager_.reset(new AutofillManager(this)); | 213 autofill_manager_.reset(new AutofillManager(this)); |
227 automation_tab_helper_.reset(new AutomationTabHelper(contents)); | 214 automation_tab_helper_.reset(new AutomationTabHelper(contents)); |
228 blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); | 215 blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); |
229 bookmark_tab_helper_.reset(new BookmarkTabHelper(this)); | 216 bookmark_tab_helper_.reset(new BookmarkTabHelper(this)); |
230 extension_tab_helper_.reset(new ExtensionTabHelper(this)); | 217 extension_tab_helper_.reset(new ExtensionTabHelper(this)); |
231 favicon_tab_helper_.reset(new FaviconTabHelper(contents)); | 218 favicon_tab_helper_.reset(new FaviconTabHelper(contents)); |
232 find_tab_helper_.reset(new FindTabHelper(contents)); | 219 find_tab_helper_.reset(new FindTabHelper(contents)); |
233 history_tab_helper_.reset(new HistoryTabHelper(contents)); | 220 history_tab_helper_.reset(new HistoryTabHelper(contents)); |
| 221 infobar_tab_helper_.reset(new InfoBarTabHelper(this)); |
234 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); | 222 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); |
235 password_manager_.reset( | 223 password_manager_.reset( |
236 new PasswordManager(contents, password_manager_delegate_.get())); | 224 new PasswordManager(contents, password_manager_delegate_.get())); |
237 prerender_tab_helper_.reset(new prerender::PrerenderTabHelper(this)); | 225 prerender_tab_helper_.reset(new prerender::PrerenderTabHelper(this)); |
238 print_view_manager_.reset(new printing::PrintViewManager(this)); | 226 print_view_manager_.reset(new printing::PrintViewManager(this)); |
239 restore_tab_helper_.reset(new RestoreTabHelper(this)); | 227 restore_tab_helper_.reset(new RestoreTabHelper(this)); |
240 #if defined(ENABLE_SAFE_BROWSING) | 228 #if defined(ENABLE_SAFE_BROWSING) |
241 if (profile()->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 229 if (profile()->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
242 g_browser_process->safe_browsing_detection_service()) { | 230 g_browser_process->safe_browsing_detection_service()) { |
243 safebrowsing_detection_host_.reset( | 231 safebrowsing_detection_host_.reset( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 pref_change_registrar_.Add(kPrefsToObserve[i], this); | 274 pref_change_registrar_.Add(kPrefsToObserve[i], this); |
287 } | 275 } |
288 | 276 |
289 renderer_preferences_util::UpdateFromSystemSettings( | 277 renderer_preferences_util::UpdateFromSystemSettings( |
290 tab_contents()->GetMutableRendererPrefs(), profile()); | 278 tab_contents()->GetMutableRendererPrefs(), profile()); |
291 } | 279 } |
292 | 280 |
293 TabContentsWrapper::~TabContentsWrapper() { | 281 TabContentsWrapper::~TabContentsWrapper() { |
294 in_destructor_ = true; | 282 in_destructor_ = true; |
295 | 283 |
296 // Destroy all remaining InfoBars. It's important to not animate here so that | 284 // Need to tear down infobars before the TabContents goes away. |
297 // we guarantee that we'll delete all delegates before we do anything else. | 285 infobar_tab_helper_.reset(); |
298 // | |
299 // TODO(pkasting): If there is no InfoBarContainer, this leaks all the | |
300 // InfoBarDelegates. This will be fixed once we call CloseSoon() directly on | |
301 // Infobars. | |
302 RemoveAllInfoBars(false); | |
303 } | 286 } |
304 | 287 |
305 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { | 288 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { |
306 return g_tab_contents_wrapper_property_accessor.Pointer(); | 289 return g_tab_contents_wrapper_property_accessor.Pointer(); |
307 } | 290 } |
308 | 291 |
309 void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) { | 292 void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) { |
310 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, | 293 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, |
311 true, | 294 true, |
312 PrefService::SYNCABLE_PREF); | 295 PrefService::SYNCABLE_PREF); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 } | 492 } |
510 | 493 |
511 //////////////////////////////////////////////////////////////////////////////// | 494 //////////////////////////////////////////////////////////////////////////////// |
512 // TabContentsWrapper implementation: | 495 // TabContentsWrapper implementation: |
513 | 496 |
514 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) { | 497 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) { |
515 UpdateAlternateErrorPageURL(render_view_host); | 498 UpdateAlternateErrorPageURL(render_view_host); |
516 } | 499 } |
517 | 500 |
518 void TabContentsWrapper::RenderViewGone() { | 501 void TabContentsWrapper::RenderViewGone() { |
519 RemoveAllInfoBars(true); | |
520 | |
521 // Tell the view that we've crashed so it can prepare the sad tab page. | 502 // Tell the view that we've crashed so it can prepare the sad tab page. |
522 // Only do this if we're not in browser shutdown, so that TabContents | 503 // Only do this if we're not in browser shutdown, so that TabContents |
523 // objects that are not in a browser (e.g., HTML dialogs) and thus are | 504 // objects that are not in a browser (e.g., HTML dialogs) and thus are |
524 // visible do not flash a sad tab page. | 505 // visible do not flash a sad tab page. |
525 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID) { | 506 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID) { |
526 tab_contents()->view()->OnTabCrashed( | 507 tab_contents()->view()->OnTabCrashed( |
527 tab_contents()->crashed_status(), tab_contents()->crashed_error_code()); | 508 tab_contents()->crashed_status(), tab_contents()->crashed_error_code()); |
528 } | 509 } |
529 } | 510 } |
530 | 511 |
531 void TabContentsWrapper::DidBecomeSelected() { | 512 void TabContentsWrapper::DidBecomeSelected() { |
532 WebCacheManager::GetInstance()->ObserveActivity( | 513 WebCacheManager::GetInstance()->ObserveActivity( |
533 tab_contents()->GetRenderProcessHost()->id()); | 514 tab_contents()->GetRenderProcessHost()->id()); |
534 } | 515 } |
535 | 516 |
536 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { | 517 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { |
537 bool handled = true; | 518 bool handled = true; |
538 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) | 519 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) |
539 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot) | 520 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot) |
540 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, | 521 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, |
541 OnPDFHasUnsupportedFeature) | 522 OnPDFHasUnsupportedFeature) |
542 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, | |
543 OnDidBlockDisplayingInsecureContent) | |
544 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, | |
545 OnDidBlockRunningInsecureContent) | |
546 IPC_MESSAGE_UNHANDLED(handled = false) | 523 IPC_MESSAGE_UNHANDLED(handled = false) |
547 IPC_END_MESSAGE_MAP() | 524 IPC_END_MESSAGE_MAP() |
548 return handled; | 525 return handled; |
549 } | 526 } |
550 | 527 |
551 void TabContentsWrapper::TabContentsDestroyed(TabContents* tab) { | 528 void TabContentsWrapper::TabContentsDestroyed(TabContents* tab) { |
552 // Destruction of the TabContents should only be done by us from our | 529 // Destruction of the TabContents should only be done by us from our |
553 // destructor. Otherwise it's very likely we (or one of the helpers we own) | 530 // destructor. Otherwise it's very likely we (or one of the helpers we own) |
554 // will attempt to access the TabContents and we'll crash. | 531 // will attempt to access the TabContents and we'll crash. |
555 DCHECK(in_destructor_); | 532 DCHECK(in_destructor_); |
556 } | 533 } |
557 | 534 |
558 void TabContentsWrapper::Observe(int type, | 535 void TabContentsWrapper::Observe(int type, |
559 const NotificationSource& source, | 536 const NotificationSource& source, |
560 const NotificationDetails& details) { | 537 const NotificationDetails& details) { |
561 switch (type) { | 538 switch (type) { |
562 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | |
563 DCHECK(&tab_contents_->controller() == | |
564 Source<NavigationController>(source).ptr()); | |
565 | |
566 content::LoadCommittedDetails& committed_details = | |
567 *(Details<content::LoadCommittedDetails>(details).ptr()); | |
568 | |
569 // NOTE: It is not safe to change the following code to count upwards or | |
570 // use iterators, as the RemoveInfoBar() call synchronously modifies our | |
571 // delegate list. | |
572 for (size_t i = infobars_.size(); i > 0; --i) { | |
573 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1); | |
574 if (delegate->ShouldExpire(committed_details)) | |
575 RemoveInfoBar(delegate); | |
576 } | |
577 | |
578 break; | |
579 } | |
580 case chrome::NOTIFICATION_GOOGLE_URL_UPDATED: | 539 case chrome::NOTIFICATION_GOOGLE_URL_UPDATED: |
581 UpdateAlternateErrorPageURL(render_view_host()); | 540 UpdateAlternateErrorPageURL(render_view_host()); |
582 break; | 541 break; |
583 case chrome::NOTIFICATION_USER_STYLE_SHEET_UPDATED: | 542 case chrome::NOTIFICATION_USER_STYLE_SHEET_UPDATED: |
584 UpdateWebPreferences(); | 543 UpdateWebPreferences(); |
585 break; | 544 break; |
586 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 545 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
587 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 546 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
588 UpdateRendererPreferences(); | 547 UpdateRendererPreferences(); |
589 break; | 548 break; |
(...skipping 17 matching lines...) Expand all Loading... |
607 } else { | 566 } else { |
608 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; | 567 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; |
609 } | 568 } |
610 break; | 569 break; |
611 } | 570 } |
612 default: | 571 default: |
613 NOTREACHED(); | 572 NOTREACHED(); |
614 } | 573 } |
615 } | 574 } |
616 | 575 |
617 void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { | |
618 if (!infobars_enabled_) { | |
619 delegate->InfoBarClosed(); | |
620 return; | |
621 } | |
622 | |
623 for (size_t i = 0; i < infobars_.size(); ++i) { | |
624 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { | |
625 delegate->InfoBarClosed(); | |
626 return; | |
627 } | |
628 } | |
629 | |
630 infobars_.push_back(delegate); | |
631 NotificationService::current()->Notify( | |
632 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | |
633 Source<TabContentsWrapper>(this), Details<InfoBarAddedDetails>(delegate)); | |
634 | |
635 // Add ourselves as an observer for navigations the first time a delegate is | |
636 // added. We use this notification to expire InfoBars that need to expire on | |
637 // page transitions. | |
638 if (infobars_.size() == 1) { | |
639 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
640 Source<NavigationController>(&tab_contents_->controller())); | |
641 } | |
642 } | |
643 | |
644 void TabContentsWrapper::RemoveInfoBar(InfoBarDelegate* delegate) { | |
645 RemoveInfoBarInternal(delegate, true); | |
646 } | |
647 | |
648 void TabContentsWrapper::ReplaceInfoBar(InfoBarDelegate* old_delegate, | |
649 InfoBarDelegate* new_delegate) { | |
650 if (!infobars_enabled_) { | |
651 AddInfoBar(new_delegate); // Deletes the delegate. | |
652 return; | |
653 } | |
654 | |
655 size_t i; | |
656 for (i = 0; i < infobars_.size(); ++i) { | |
657 if (GetInfoBarDelegateAt(i) == old_delegate) | |
658 break; | |
659 } | |
660 DCHECK_LT(i, infobars_.size()); | |
661 | |
662 infobars_.insert(infobars_.begin() + i, new_delegate); | |
663 | |
664 old_delegate->clear_owner(); | |
665 InfoBarReplacedDetails replaced_details(old_delegate, new_delegate); | |
666 NotificationService::current()->Notify( | |
667 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, | |
668 Source<TabContentsWrapper>(this), | |
669 Details<InfoBarReplacedDetails>(&replaced_details)); | |
670 | |
671 infobars_.erase(infobars_.begin() + i + 1); | |
672 } | |
673 | |
674 InfoBarDelegate* TabContentsWrapper::GetInfoBarDelegateAt(size_t index) { | |
675 return infobars_[index]; | |
676 } | |
677 | |
678 //////////////////////////////////////////////////////////////////////////////// | 576 //////////////////////////////////////////////////////////////////////////////// |
679 // Internal helpers | 577 // Internal helpers |
680 | 578 |
681 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { | 579 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { |
682 NotificationService::current()->Notify( | 580 NotificationService::current()->Notify( |
683 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, | 581 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, |
684 Source<TabContentsWrapper>(this), | 582 Source<TabContentsWrapper>(this), |
685 Details<const SkBitmap>(&bitmap)); | 583 Details<const SkBitmap>(&bitmap)); |
686 } | 584 } |
687 | 585 |
688 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { | 586 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { |
689 PDFHasUnsupportedFeature(this); | 587 PDFHasUnsupportedFeature(this); |
690 } | 588 } |
691 | 589 |
692 void TabContentsWrapper::OnDidBlockDisplayingInsecureContent() { | |
693 // At most one infobar and do not supersede the stronger running content bar. | |
694 for (size_t i = 0; i < infobars_.size(); ++i) { | |
695 if (GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate()) | |
696 return; | |
697 } | |
698 AddInfoBar(new InsecureContentInfoBarDelegate(this, | |
699 InsecureContentInfoBarDelegate::DISPLAY)); | |
700 } | |
701 | |
702 void TabContentsWrapper::OnDidBlockRunningInsecureContent() { | |
703 // At most one infobar superseding any weaker displaying content bar. | |
704 for (size_t i = 0; i < infobars_.size(); ++i) { | |
705 InsecureContentInfoBarDelegate* delegate = | |
706 GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate(); | |
707 if (delegate) { | |
708 if (delegate->type() != InsecureContentInfoBarDelegate::RUN) { | |
709 ReplaceInfoBar(delegate, new InsecureContentInfoBarDelegate(this, | |
710 InsecureContentInfoBarDelegate::RUN)); | |
711 } | |
712 return; | |
713 } | |
714 } | |
715 AddInfoBar(new InsecureContentInfoBarDelegate(this, | |
716 InsecureContentInfoBarDelegate::RUN)); | |
717 } | |
718 | |
719 GURL TabContentsWrapper::GetAlternateErrorPageURL() const { | 590 GURL TabContentsWrapper::GetAlternateErrorPageURL() const { |
720 GURL url; | 591 GURL url; |
721 // Disable alternate error pages when in Incognito mode. | 592 // Disable alternate error pages when in Incognito mode. |
722 if (profile()->IsOffTheRecord()) | 593 if (profile()->IsOffTheRecord()) |
723 return url; | 594 return url; |
724 | 595 |
725 PrefService* prefs = profile()->GetPrefs(); | 596 PrefService* prefs = profile()->GetPrefs(); |
726 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { | 597 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { |
727 url = google_util::AppendGoogleLocaleParam( | 598 url = google_util::AppendGoogleLocaleParam( |
728 GURL(google_util::kLinkDoctorBaseURL)); | 599 GURL(google_util::kLinkDoctorBaseURL)); |
(...skipping 30 matching lines...) Expand all Loading... |
759 } | 630 } |
760 } else { | 631 } else { |
761 safebrowsing_detection_host_.reset(); | 632 safebrowsing_detection_host_.reset(); |
762 } | 633 } |
763 render_view_host()->Send( | 634 render_view_host()->Send( |
764 new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(), | 635 new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(), |
765 safe_browsing)); | 636 safe_browsing)); |
766 #endif | 637 #endif |
767 } | 638 } |
768 | 639 |
769 void TabContentsWrapper::RemoveInfoBarInternal(InfoBarDelegate* delegate, | |
770 bool animate) { | |
771 if (!infobars_enabled_) { | |
772 DCHECK(infobars_.empty()); | |
773 return; | |
774 } | |
775 | |
776 size_t i; | |
777 for (i = 0; i < infobars_.size(); ++i) { | |
778 if (GetInfoBarDelegateAt(i) == delegate) | |
779 break; | |
780 } | |
781 DCHECK_LT(i, infobars_.size()); | |
782 InfoBarDelegate* infobar = infobars_[i]; | |
783 | |
784 infobar->clear_owner(); | |
785 InfoBarRemovedDetails removed_details(infobar, animate); | |
786 NotificationService::current()->Notify( | |
787 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | |
788 Source<TabContentsWrapper>(this), | |
789 Details<InfoBarRemovedDetails>(&removed_details)); | |
790 | |
791 infobars_.erase(infobars_.begin() + i); | |
792 // Remove ourselves as an observer if we are tracking no more InfoBars. | |
793 if (infobars_.empty()) { | |
794 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
795 Source<NavigationController>(&tab_contents_->controller())); | |
796 } | |
797 } | |
798 | |
799 void TabContentsWrapper::RemoveAllInfoBars(bool animate) { | |
800 while (!infobars_.empty()) | |
801 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); | |
802 } | |
803 | |
804 void TabContentsWrapper::ExitFullscreenMode() { | 640 void TabContentsWrapper::ExitFullscreenMode() { |
805 Send(new ViewMsg_ExitFullscreen(routing_id())); | 641 Send(new ViewMsg_ExitFullscreen(routing_id())); |
806 } | 642 } |
OLD | NEW |