| 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/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 13 #include "chrome/browser/custom_handlers/protocol_handler.h" | 13 #include "chrome/browser/custom_handlers/protocol_handler.h" |
| 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 15 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" | 15 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" |
| 16 #include "chrome/browser/extensions/extension_tab_helper.h" | 16 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 17 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 17 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
| 18 #include "chrome/browser/external_protocol/external_protocol_observer.h" | 18 #include "chrome/browser/external_protocol/external_protocol_observer.h" |
| 19 #include "chrome/browser/favicon/favicon_tab_helper.h" | 19 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 20 #include "chrome/browser/file_select_helper.h" | 20 #include "chrome/browser/file_select_helper.h" |
| 21 #include "chrome/browser/google/google_util.h" |
| 21 #include "chrome/browser/history/history_tab_helper.h" | 22 #include "chrome/browser/history/history_tab_helper.h" |
| 22 #include "chrome/browser/omnibox_search_hint.h" | 23 #include "chrome/browser/omnibox_search_hint.h" |
| 23 #include "chrome/browser/password_manager/password_manager.h" | 24 #include "chrome/browser/password_manager/password_manager.h" |
| 24 #include "chrome/browser/password_manager_delegate_impl.h" | 25 #include "chrome/browser/password_manager_delegate_impl.h" |
| 25 #include "chrome/browser/pdf_unsupported_feature.h" | 26 #include "chrome/browser/pdf_unsupported_feature.h" |
| 26 #include "chrome/browser/plugin_observer.h" | 27 #include "chrome/browser/plugin_observer.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/prerender/prerender_observer.h" | 29 #include "chrome/browser/prerender/prerender_observer.h" |
| 29 #include "chrome/browser/printing/print_preview_message_handler.h" | 30 #include "chrome/browser/printing/print_preview_message_handler.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/renderer_preferences_util.h" |
| 31 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 33 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 32 #include "chrome/browser/tab_contents/infobar_delegate.h" | 34 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 33 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 35 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
| 34 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" | 36 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
| 35 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 37 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 36 #include "chrome/browser/translate/translate_tab_helper.h" | 38 #include "chrome/browser/translate/translate_tab_helper.h" |
| 37 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 39 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 38 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 40 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 39 #include "chrome/browser/ui/download/download_tab_helper.h" | 41 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 40 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 42 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 41 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 43 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 42 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 44 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
| 43 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
| 44 #include "chrome/common/pref_names.h" | 46 #include "chrome/common/pref_names.h" |
| 45 #include "chrome/common/render_messages.h" | 47 #include "chrome/common/render_messages.h" |
| 48 #include "content/browser/renderer_host/render_view_host.h" |
| 46 #include "content/browser/tab_contents/tab_contents.h" | 49 #include "content/browser/tab_contents/tab_contents.h" |
| 47 #include "content/common/notification_service.h" | 50 #include "content/common/notification_service.h" |
| 48 #include "content/common/view_messages.h" | 51 #include "content/common/view_messages.h" |
| 49 #include "grit/generated_resources.h" | 52 #include "grit/generated_resources.h" |
| 50 #include "grit/locale_settings.h" | 53 #include "grit/locale_settings.h" |
| 51 #include "grit/platform_locale_settings.h" | 54 #include "grit/platform_locale_settings.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "webkit/glue/webpreferences.h" | 56 #include "webkit/glue/webpreferences.h" |
| 54 | 57 |
| 58 namespace { |
| 59 |
| 55 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > | 60 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > |
| 56 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); | 61 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); |
| 57 | 62 |
| 63 // The list of prefs we want to observe. |
| 64 const char* kPrefsToObserve[] = { |
| 65 prefs::kAlternateErrorPagesEnabled, |
| 66 prefs::kDefaultCharset, |
| 67 prefs::kDefaultZoomLevel, |
| 68 prefs::kEnableReferrers |
| 69 }; |
| 70 |
| 71 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); |
| 72 |
| 73 } |
| 74 |
| 58 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
| 59 // TabContentsWrapper, public: | 76 // TabContentsWrapper, public: |
| 60 | 77 |
| 61 TabContentsWrapper::TabContentsWrapper(TabContents* contents) | 78 TabContentsWrapper::TabContentsWrapper(TabContents* contents) |
| 62 : TabContentsObserver(contents), | 79 : TabContentsObserver(contents), |
| 63 delegate_(NULL), | 80 delegate_(NULL), |
| 64 infobars_enabled_(true), | 81 infobars_enabled_(true), |
| 65 tab_contents_(contents) { | 82 tab_contents_(contents) { |
| 66 DCHECK(contents); | 83 DCHECK(contents); |
| 67 DCHECK(!GetCurrentWrapperForContents(contents)); | 84 DCHECK(!GetCurrentWrapperForContents(contents)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Start the in-browser thumbnailing if the feature is enabled. | 119 // Start the in-browser thumbnailing if the feature is enabled. |
| 103 if (CommandLine::ForCurrentProcess()->HasSwitch( | 120 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 104 switches::kEnableInBrowserThumbnailing)) { | 121 switches::kEnableInBrowserThumbnailing)) { |
| 105 thumbnail_generation_observer_.reset(new ThumbnailGenerator); | 122 thumbnail_generation_observer_.reset(new ThumbnailGenerator); |
| 106 thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get()); | 123 thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get()); |
| 107 } | 124 } |
| 108 | 125 |
| 109 // Set-up the showing of the omnibox search infobar if applicable. | 126 // Set-up the showing of the omnibox search infobar if applicable. |
| 110 if (OmniboxSearchHint::IsEnabled(contents->profile())) | 127 if (OmniboxSearchHint::IsEnabled(contents->profile())) |
| 111 omnibox_search_hint_.reset(new OmniboxSearchHint(this)); | 128 omnibox_search_hint_.reset(new OmniboxSearchHint(this)); |
| 129 |
| 130 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED, |
| 131 NotificationService::AllSources()); |
| 132 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED, |
| 133 NotificationService::AllSources()); |
| 134 #if defined(OS_LINUX) |
| 135 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 136 NotificationService::AllSources()); |
| 137 #endif |
| 138 |
| 139 // Register for notifications about all interested prefs change. |
| 140 PrefService* prefs = profile()->GetPrefs(); |
| 141 pref_change_registrar_.Init(prefs); |
| 142 if (prefs) { |
| 143 for (int i = 0; i < kPrefsToObserveLength; ++i) |
| 144 pref_change_registrar_.Add(kPrefsToObserve[i], this); |
| 145 } |
| 146 |
| 147 renderer_preferences_util::UpdateFromSystemSettings( |
| 148 tab_contents()->GetMutableRendererPrefs(), profile()); |
| 112 } | 149 } |
| 113 | 150 |
| 114 TabContentsWrapper::~TabContentsWrapper() { | 151 TabContentsWrapper::~TabContentsWrapper() { |
| 115 // Notify any lasting InfobarDelegates that have not yet been removed that | 152 // Notify any lasting InfobarDelegates that have not yet been removed that |
| 116 // whatever infobar they were handling in this TabContents has closed, | 153 // whatever infobar they were handling in this TabContents has closed, |
| 117 // because the TabContents is going away entirely. | 154 // because the TabContents is going away entirely. |
| 118 // This must happen after the TAB_CONTENTS_DESTROYED notification as the | 155 // This must happen after the TAB_CONTENTS_DESTROYED notification as the |
| 119 // notification may trigger infobars calls that access their delegate. (and | 156 // notification may trigger infobars calls that access their delegate. (and |
| 120 // some implementations of InfoBarDelegate do delete themselves on | 157 // some implementations of InfoBarDelegate do delete themselves on |
| 121 // InfoBarClosed()). | 158 // InfoBarClosed()). |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 TabContents* contents) { | 320 TabContents* contents) { |
| 284 TabContentsWrapper** wrapper = | 321 TabContentsWrapper** wrapper = |
| 285 property_accessor()->GetProperty(contents->property_bag()); | 322 property_accessor()->GetProperty(contents->property_bag()); |
| 286 | 323 |
| 287 return wrapper ? *wrapper : NULL; | 324 return wrapper ? *wrapper : NULL; |
| 288 } | 325 } |
| 289 | 326 |
| 290 //////////////////////////////////////////////////////////////////////////////// | 327 //////////////////////////////////////////////////////////////////////////////// |
| 291 // TabContentsWrapper implementation: | 328 // TabContentsWrapper implementation: |
| 292 | 329 |
| 330 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) { |
| 331 UpdateAlternateErrorPageURL(render_view_host); |
| 332 } |
| 333 |
| 293 void TabContentsWrapper::RenderViewGone() { | 334 void TabContentsWrapper::RenderViewGone() { |
| 294 // Remove all infobars. | 335 // Remove all infobars. |
| 295 while (!infobar_delegates_.empty()) | 336 while (!infobar_delegates_.empty()) |
| 296 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); | 337 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); |
| 297 } | 338 } |
| 298 | 339 |
| 299 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { | 340 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { |
| 300 bool handled = true; | 341 bool handled = true; |
| 301 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) | 342 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) |
| 302 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) | 343 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 325 // use iterators, as the RemoveInfoBar() call synchronously modifies our | 366 // use iterators, as the RemoveInfoBar() call synchronously modifies our |
| 326 // delegate list. | 367 // delegate list. |
| 327 for (size_t i = infobar_delegates_.size(); i > 0; --i) { | 368 for (size_t i = infobar_delegates_.size(); i > 0; --i) { |
| 328 InfoBarDelegate* delegate = infobar_delegates_[i - 1]; | 369 InfoBarDelegate* delegate = infobar_delegates_[i - 1]; |
| 329 if (delegate->ShouldExpire(committed_details)) | 370 if (delegate->ShouldExpire(committed_details)) |
| 330 RemoveInfoBar(delegate); | 371 RemoveInfoBar(delegate); |
| 331 } | 372 } |
| 332 | 373 |
| 333 break; | 374 break; |
| 334 } | 375 } |
| 376 case NotificationType::GOOGLE_URL_UPDATED: |
| 377 UpdateAlternateErrorPageURL(render_view_host()); |
| 378 break; |
| 379 case NotificationType::USER_STYLE_SHEET_UPDATED: |
| 380 UpdateWebPreferences(); |
| 381 break; |
| 382 #if defined(OS_LINUX) |
| 383 case NotificationType::BROWSER_THEME_CHANGED: { |
| 384 UpdateRendererPreferences(); |
| 385 break; |
| 386 } |
| 387 #endif |
| 388 case NotificationType::PREF_CHANGED: { |
| 389 std::string* pref_name_in = Details<std::string>(details).ptr(); |
| 390 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); |
| 391 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { |
| 392 UpdateAlternateErrorPageURL(render_view_host()); |
| 393 } else if ((*pref_name_in == prefs::kDefaultCharset) || |
| 394 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { |
| 395 UpdateWebPreferences(); |
| 396 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { |
| 397 Send(new ViewMsg_SetZoomLevel( |
| 398 routing_id(), tab_contents()->GetZoomLevel())); |
| 399 } else if (*pref_name_in == prefs::kEnableReferrers) { |
| 400 UpdateRendererPreferences(); |
| 401 } else { |
| 402 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; |
| 403 } |
| 404 break; |
| 405 } |
| 335 default: | 406 default: |
| 336 NOTREACHED(); | 407 NOTREACHED(); |
| 337 } | 408 } |
| 338 } | 409 } |
| 339 | 410 |
| 340 void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { | 411 void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { |
| 341 if (!infobars_enabled_) { | 412 if (!infobars_enabled_) { |
| 342 delegate->InfoBarClosed(); | 413 delegate->InfoBarClosed(); |
| 343 return; | 414 return; |
| 344 } | 415 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { | 524 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { |
| 454 NotificationService::current()->Notify( | 525 NotificationService::current()->Notify( |
| 455 NotificationType::TAB_SNAPSHOT_TAKEN, | 526 NotificationType::TAB_SNAPSHOT_TAKEN, |
| 456 Source<TabContentsWrapper>(this), | 527 Source<TabContentsWrapper>(this), |
| 457 Details<const SkBitmap>(&bitmap)); | 528 Details<const SkBitmap>(&bitmap)); |
| 458 } | 529 } |
| 459 | 530 |
| 460 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { | 531 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { |
| 461 PDFHasUnsupportedFeature(this); | 532 PDFHasUnsupportedFeature(this); |
| 462 } | 533 } |
| 534 |
| 535 GURL TabContentsWrapper::GetAlternateErrorPageURL() const { |
| 536 GURL url; |
| 537 // Disable alternate error pages when in Incognito mode. |
| 538 if (profile()->IsOffTheRecord()) |
| 539 return url; |
| 540 |
| 541 PrefService* prefs = profile()->GetPrefs(); |
| 542 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { |
| 543 url = google_util::AppendGoogleLocaleParam( |
| 544 GURL(google_util::kLinkDoctorBaseURL)); |
| 545 url = google_util::AppendGoogleTLDParam(url); |
| 546 } |
| 547 return url; |
| 548 } |
| 549 |
| 550 void TabContentsWrapper::UpdateAlternateErrorPageURL(RenderViewHost* rvh) { |
| 551 rvh->Send(new ViewMsg_SetAltErrorPageURL( |
| 552 rvh->routing_id(), GetAlternateErrorPageURL())); |
| 553 } |
| 554 |
| 555 void TabContentsWrapper::UpdateWebPreferences() { |
| 556 RenderViewHostDelegate* rvhd = tab_contents(); |
| 557 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs())); |
| 558 } |
| 559 |
| 560 void TabContentsWrapper::UpdateRendererPreferences() { |
| 561 renderer_preferences_util::UpdateFromSystemSettings( |
| 562 tab_contents()->GetMutableRendererPrefs(), profile()); |
| 563 render_view_host()->SyncRendererPrefs(); |
| 564 } |
| OLD | NEW |