| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "chrome/browser/autocomplete_history_manager.h" | 9 #include "chrome/browser/autocomplete_history_manager.h" |
| 10 #include "chrome/browser/autofill/autofill_manager.h" | 10 #include "chrome/browser/autofill/autofill_manager.h" |
| 11 #include "chrome/browser/automation/automation_tab_helper.h" | 11 #include "chrome/browser/automation/automation_tab_helper.h" |
| 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_shutdown.h" | 13 #include "chrome/browser/browser_shutdown.h" |
| 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 14 #include "chrome/browser/custom_handlers/protocol_handler.h" | 15 #include "chrome/browser/custom_handlers/protocol_handler.h" |
| 15 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 16 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 16 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" | 17 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" |
| 17 #include "chrome/browser/extensions/extension_tab_helper.h" | 18 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 18 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 19 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
| 19 #include "chrome/browser/external_protocol/external_protocol_observer.h" | 20 #include "chrome/browser/external_protocol/external_protocol_observer.h" |
| 20 #include "chrome/browser/favicon/favicon_tab_helper.h" | 21 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 21 #include "chrome/browser/file_select_helper.h" | 22 #include "chrome/browser/file_select_helper.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 69 |
| 69 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > | 70 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > |
| 70 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); | 71 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); |
| 71 | 72 |
| 72 // The list of prefs we want to observe. | 73 // The list of prefs we want to observe. |
| 73 const char* kPrefsToObserve[] = { | 74 const char* kPrefsToObserve[] = { |
| 74 prefs::kAlternateErrorPagesEnabled, | 75 prefs::kAlternateErrorPagesEnabled, |
| 75 prefs::kDefaultCharset, | 76 prefs::kDefaultCharset, |
| 76 prefs::kDefaultZoomLevel, | 77 prefs::kDefaultZoomLevel, |
| 77 prefs::kEnableReferrers, | 78 prefs::kEnableReferrers, |
| 79 #if defined (ENABLE_SAFE_BROWSING) |
| 80 prefs::kSafeBrowsingEnabled, |
| 81 #endif |
| 78 prefs::kWebKitAllowDisplayingInsecureContent, | 82 prefs::kWebKitAllowDisplayingInsecureContent, |
| 79 prefs::kWebKitAllowRunningInsecureContent, | 83 prefs::kWebKitAllowRunningInsecureContent, |
| 80 prefs::kWebKitDefaultFixedFontSize, | 84 prefs::kWebKitDefaultFixedFontSize, |
| 81 prefs::kWebKitDefaultFontSize, | 85 prefs::kWebKitDefaultFontSize, |
| 82 prefs::kWebKitFixedFontFamily, | 86 prefs::kWebKitFixedFontFamily, |
| 83 prefs::kWebKitJavaEnabled, | 87 prefs::kWebKitJavaEnabled, |
| 84 prefs::kWebKitJavascriptEnabled, | 88 prefs::kWebKitJavascriptEnabled, |
| 85 prefs::kWebKitLoadsImagesAutomatically, | 89 prefs::kWebKitLoadsImagesAutomatically, |
| 86 prefs::kWebKitMinimumFontSize, | 90 prefs::kWebKitMinimumFontSize, |
| 87 prefs::kWebKitMinimumLogicalFontSize, | 91 prefs::kWebKitMinimumLogicalFontSize, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 download_tab_helper_.reset(new DownloadTabHelper(this)); | 125 download_tab_helper_.reset(new DownloadTabHelper(this)); |
| 122 extension_tab_helper_.reset(new ExtensionTabHelper(this)); | 126 extension_tab_helper_.reset(new ExtensionTabHelper(this)); |
| 123 favicon_tab_helper_.reset(new FaviconTabHelper(contents)); | 127 favicon_tab_helper_.reset(new FaviconTabHelper(contents)); |
| 124 find_tab_helper_.reset(new FindTabHelper(contents)); | 128 find_tab_helper_.reset(new FindTabHelper(contents)); |
| 125 history_tab_helper_.reset(new HistoryTabHelper(contents)); | 129 history_tab_helper_.reset(new HistoryTabHelper(contents)); |
| 126 restore_tab_helper_.reset(new RestoreTabHelper(this)); | 130 restore_tab_helper_.reset(new RestoreTabHelper(this)); |
| 127 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); | 131 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); |
| 128 password_manager_.reset( | 132 password_manager_.reset( |
| 129 new PasswordManager(contents, password_manager_delegate_.get())); | 133 new PasswordManager(contents, password_manager_delegate_.get())); |
| 130 #if defined(ENABLE_SAFE_BROWSING) | 134 #if defined(ENABLE_SAFE_BROWSING) |
| 131 safebrowsing_detection_host_.reset( | 135 if (profile()->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 132 safe_browsing::ClientSideDetectionHost::Create(contents)); | 136 g_browser_process->safe_browsing_detection_service()) { |
| 137 safebrowsing_detection_host_.reset( |
| 138 safe_browsing::ClientSideDetectionHost::Create(contents)); |
| 139 } |
| 133 #endif | 140 #endif |
| 134 search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents)); | 141 search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents)); |
| 135 ssl_helper_.reset(new TabContentsSSLHelper(this)); | 142 ssl_helper_.reset(new TabContentsSSLHelper(this)); |
| 136 content_settings_.reset(new TabSpecificContentSettings(contents)); | 143 content_settings_.reset(new TabSpecificContentSettings(contents)); |
| 137 translate_tab_helper_.reset(new TranslateTabHelper(contents)); | 144 translate_tab_helper_.reset(new TranslateTabHelper(contents)); |
| 138 print_view_manager_.reset(new printing::PrintViewManager(this)); | 145 print_view_manager_.reset(new printing::PrintViewManager(this)); |
| 139 | 146 |
| 140 // Create the per-tab observers. | 147 // Create the per-tab observers. |
| 141 external_protocol_observer_.reset(new ExternalProtocolObserver(contents)); | 148 external_protocol_observer_.reset(new ExternalProtocolObserver(contents)); |
| 142 file_select_observer_.reset(new FileSelectObserver(contents)); | 149 file_select_observer_.reset(new FileSelectObserver(contents)); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { | 458 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { |
| 452 UpdateAlternateErrorPageURL(render_view_host()); | 459 UpdateAlternateErrorPageURL(render_view_host()); |
| 453 } else if ((*pref_name_in == prefs::kDefaultCharset) || | 460 } else if ((*pref_name_in == prefs::kDefaultCharset) || |
| 454 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { | 461 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { |
| 455 UpdateWebPreferences(); | 462 UpdateWebPreferences(); |
| 456 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | 463 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { |
| 457 Send(new ViewMsg_SetZoomLevel( | 464 Send(new ViewMsg_SetZoomLevel( |
| 458 routing_id(), tab_contents()->GetZoomLevel())); | 465 routing_id(), tab_contents()->GetZoomLevel())); |
| 459 } else if (*pref_name_in == prefs::kEnableReferrers) { | 466 } else if (*pref_name_in == prefs::kEnableReferrers) { |
| 460 UpdateRendererPreferences(); | 467 UpdateRendererPreferences(); |
| 468 } else if (*pref_name_in == prefs::kSafeBrowsingEnabled) { |
| 469 UpdateSafebrowsingDetectionHost(); |
| 461 } else { | 470 } else { |
| 462 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; | 471 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; |
| 463 } | 472 } |
| 464 break; | 473 break; |
| 465 } | 474 } |
| 466 default: | 475 default: |
| 467 NOTREACHED(); | 476 NOTREACHED(); |
| 468 } | 477 } |
| 469 } | 478 } |
| 470 | 479 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 RenderViewHostDelegate* rvhd = tab_contents(); | 633 RenderViewHostDelegate* rvhd = tab_contents(); |
| 625 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs())); | 634 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs())); |
| 626 } | 635 } |
| 627 | 636 |
| 628 void TabContentsWrapper::UpdateRendererPreferences() { | 637 void TabContentsWrapper::UpdateRendererPreferences() { |
| 629 renderer_preferences_util::UpdateFromSystemSettings( | 638 renderer_preferences_util::UpdateFromSystemSettings( |
| 630 tab_contents()->GetMutableRendererPrefs(), profile()); | 639 tab_contents()->GetMutableRendererPrefs(), profile()); |
| 631 render_view_host()->SyncRendererPrefs(); | 640 render_view_host()->SyncRendererPrefs(); |
| 632 } | 641 } |
| 633 | 642 |
| 643 void TabContentsWrapper::UpdateSafebrowsingDetectionHost() { |
| 644 PrefService* prefs = profile()->GetPrefs(); |
| 645 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); |
| 646 if (safe_browsing && |
| 647 g_browser_process->safe_browsing_detection_service()) { |
| 648 if (!safebrowsing_detection_host_.get()) { |
| 649 safebrowsing_detection_host_.reset( |
| 650 safe_browsing::ClientSideDetectionHost::Create(tab_contents())); |
| 651 } |
| 652 } else { |
| 653 safebrowsing_detection_host_.reset(); |
| 654 } |
| 655 render_view_host()->Send( |
| 656 new ViewMsg_SetClientSidePhishingDetection(routing_id(), safe_browsing)); |
| 657 } |
| 658 |
| 634 void TabContentsWrapper::RemoveInfoBarInternal(InfoBarDelegate* delegate, | 659 void TabContentsWrapper::RemoveInfoBarInternal(InfoBarDelegate* delegate, |
| 635 bool animate) { | 660 bool animate) { |
| 636 if (!infobars_enabled_) { | 661 if (!infobars_enabled_) { |
| 637 DCHECK(infobars_.empty()); | 662 DCHECK(infobars_.empty()); |
| 638 return; | 663 return; |
| 639 } | 664 } |
| 640 | 665 |
| 641 size_t i; | 666 size_t i; |
| 642 for (i = 0; i < infobars_.size(); ++i) { | 667 for (i = 0; i < infobars_.size(); ++i) { |
| 643 if (GetInfoBarDelegateAt(i) == delegate) | 668 if (GetInfoBarDelegateAt(i) == delegate) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 657 if (infobars_.empty()) { | 682 if (infobars_.empty()) { |
| 658 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 683 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 659 Source<NavigationController>(&tab_contents_->controller())); | 684 Source<NavigationController>(&tab_contents_->controller())); |
| 660 } | 685 } |
| 661 } | 686 } |
| 662 | 687 |
| 663 void TabContentsWrapper::RemoveAllInfoBars(bool animate) { | 688 void TabContentsWrapper::RemoveAllInfoBars(bool animate) { |
| 664 while (!infobars_.empty()) | 689 while (!infobars_.empty()) |
| 665 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); | 690 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); |
| 666 } | 691 } |
| OLD | NEW |