| 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/favicon/favicon_tab_helper.h" | 18 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 19 #include "chrome/browser/file_select_helper.h" | 19 #include "chrome/browser/file_select_helper.h" |
| 20 #include "chrome/browser/history/history.h" | 20 #include "chrome/browser/history/history_tab_helper.h" |
| 21 #include "chrome/browser/history/top_sites.h" | |
| 22 #include "chrome/browser/omnibox_search_hint.h" | 21 #include "chrome/browser/omnibox_search_hint.h" |
| 23 #include "chrome/browser/password_manager/password_manager.h" | 22 #include "chrome/browser/password_manager/password_manager.h" |
| 24 #include "chrome/browser/password_manager_delegate_impl.h" | 23 #include "chrome/browser/password_manager_delegate_impl.h" |
| 25 #include "chrome/browser/pdf_unsupported_feature.h" | 24 #include "chrome/browser/pdf_unsupported_feature.h" |
| 26 #include "chrome/browser/plugin_observer.h" | 25 #include "chrome/browser/plugin_observer.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/prerender/prerender_observer.h" | 27 #include "chrome/browser/prerender/prerender_observer.h" |
| 29 #include "chrome/browser/printing/print_preview_message_handler.h" | 28 #include "chrome/browser/printing/print_preview_message_handler.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 30 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // Create the tab helpers. | 71 // Create the tab helpers. |
| 73 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); | 72 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); |
| 74 autofill_manager_.reset(new AutofillManager(this)); | 73 autofill_manager_.reset(new AutofillManager(this)); |
| 75 automation_tab_helper_.reset(new AutomationTabHelper(contents)); | 74 automation_tab_helper_.reset(new AutomationTabHelper(contents)); |
| 76 blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); | 75 blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); |
| 77 bookmark_tab_helper_.reset(new BookmarkTabHelper(this)); | 76 bookmark_tab_helper_.reset(new BookmarkTabHelper(this)); |
| 78 download_tab_helper_.reset(new DownloadTabHelper(this)); | 77 download_tab_helper_.reset(new DownloadTabHelper(this)); |
| 79 extension_tab_helper_.reset(new ExtensionTabHelper(this)); | 78 extension_tab_helper_.reset(new ExtensionTabHelper(this)); |
| 80 favicon_tab_helper_.reset(new FaviconTabHelper(contents)); | 79 favicon_tab_helper_.reset(new FaviconTabHelper(contents)); |
| 81 find_tab_helper_.reset(new FindTabHelper(contents)); | 80 find_tab_helper_.reset(new FindTabHelper(contents)); |
| 81 history_tab_helper_.reset(new HistoryTabHelper(contents)); |
| 82 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); | 82 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); |
| 83 password_manager_.reset( | 83 password_manager_.reset( |
| 84 new PasswordManager(contents, password_manager_delegate_.get())); | 84 new PasswordManager(contents, password_manager_delegate_.get())); |
| 85 safebrowsing_detection_host_.reset( | 85 safebrowsing_detection_host_.reset( |
| 86 safe_browsing::ClientSideDetectionHost::Create(contents)); | 86 safe_browsing::ClientSideDetectionHost::Create(contents)); |
| 87 search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents)); | 87 search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents)); |
| 88 ssl_helper_.reset(new TabContentsSSLHelper(this)); | 88 ssl_helper_.reset(new TabContentsSSLHelper(this)); |
| 89 content_settings_.reset(new TabSpecificContentSettings(contents)); | 89 content_settings_.reset(new TabSpecificContentSettings(contents)); |
| 90 translate_tab_helper_.reset(new TranslateTabHelper(contents)); | 90 translate_tab_helper_.reset(new TranslateTabHelper(contents)); |
| 91 print_view_manager_.reset(new printing::PrintViewManager(contents)); | 91 print_view_manager_.reset(new printing::PrintViewManager(contents)); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 290 |
| 291 void TabContentsWrapper::RenderViewGone() { | 291 void TabContentsWrapper::RenderViewGone() { |
| 292 // Remove all infobars. | 292 // Remove all infobars. |
| 293 while (!infobar_delegates_.empty()) | 293 while (!infobar_delegates_.empty()) |
| 294 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); | 294 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1)); |
| 295 } | 295 } |
| 296 | 296 |
| 297 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { | 297 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { |
| 298 bool handled = true; | 298 bool handled = true; |
| 299 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) | 299 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) |
| 300 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) | |
| 301 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) | 300 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) |
| 302 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, | 301 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, |
| 303 OnRegisterProtocolHandler) | 302 OnRegisterProtocolHandler) |
| 304 IPC_MESSAGE_HANDLER(ViewHostMsg_Thumbnail, OnThumbnail) | |
| 305 IPC_MESSAGE_HANDLER(ViewHostMsg_Snapshot, OnSnapshot) | 303 IPC_MESSAGE_HANDLER(ViewHostMsg_Snapshot, OnSnapshot) |
| 306 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature, | 304 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature, |
| 307 OnPDFHasUnsupportedFeature) | 305 OnPDFHasUnsupportedFeature) |
| 308 IPC_MESSAGE_UNHANDLED(handled = false) | 306 IPC_MESSAGE_UNHANDLED(handled = false) |
| 309 IPC_END_MESSAGE_MAP() | 307 IPC_END_MESSAGE_MAP() |
| 310 return handled; | 308 return handled; |
| 311 } | 309 } |
| 312 | 310 |
| 313 void TabContentsWrapper::Observe(NotificationType type, | 311 void TabContentsWrapper::Observe(NotificationType type, |
| 314 const NotificationSource& source, | 312 const NotificationSource& source, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // Add the new one. | 415 // Add the new one. |
| 418 DCHECK(find(infobar_delegates_.begin(), | 416 DCHECK(find(infobar_delegates_.begin(), |
| 419 infobar_delegates_.end(), new_delegate) == | 417 infobar_delegates_.end(), new_delegate) == |
| 420 infobar_delegates_.end()); | 418 infobar_delegates_.end()); |
| 421 infobar_delegates_.push_back(new_delegate); | 419 infobar_delegates_.push_back(new_delegate); |
| 422 } | 420 } |
| 423 | 421 |
| 424 //////////////////////////////////////////////////////////////////////////////// | 422 //////////////////////////////////////////////////////////////////////////////// |
| 425 // Internal helpers | 423 // Internal helpers |
| 426 | 424 |
| 427 void TabContentsWrapper::OnPageContents(const GURL& url, | |
| 428 int32 page_id, | |
| 429 const string16& contents) { | |
| 430 // Don't index any https pages. People generally don't want their bank | |
| 431 // accounts, etc. indexed on their computer, especially since some of these | |
| 432 // things are not marked cachable. | |
| 433 // TODO(brettw) we may want to consider more elaborate heuristics such as | |
| 434 // the cachability of the page. We may also want to consider subframes (this | |
| 435 // test will still index subframes if the subframe is SSL). | |
| 436 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable | |
| 437 // content indexing for chromeos in some future releases. | |
| 438 #if !defined(OS_CHROMEOS) | |
| 439 if (!url.SchemeIsSecure()) { | |
| 440 Profile* p = profile(); | |
| 441 if (p && !p->IsOffTheRecord()) { | |
| 442 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS); | |
| 443 if (hs) | |
| 444 hs->SetPageContents(url, contents); | |
| 445 } | |
| 446 } | |
| 447 #endif | |
| 448 } | |
| 449 | |
| 450 void TabContentsWrapper::OnJSOutOfMemory() { | 425 void TabContentsWrapper::OnJSOutOfMemory() { |
| 451 AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), | 426 AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), |
| 452 NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); | 427 NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); |
| 453 } | 428 } |
| 454 | 429 |
| 455 void TabContentsWrapper::OnRegisterProtocolHandler(const std::string& protocol, | 430 void TabContentsWrapper::OnRegisterProtocolHandler(const std::string& protocol, |
| 456 const GURL& url, | 431 const GURL& url, |
| 457 const string16& title) { | 432 const string16& title) { |
| 458 ProtocolHandlerRegistry* registry = profile()->GetProtocolHandlerRegistry(); | 433 ProtocolHandlerRegistry* registry = profile()->GetProtocolHandlerRegistry(); |
| 459 if (!registry->enabled()) { | 434 if (!registry->enabled()) { |
| 460 return; | 435 return; |
| 461 } | 436 } |
| 462 ProtocolHandler handler = | 437 ProtocolHandler handler = |
| 463 ProtocolHandler::CreateProtocolHandler(protocol, url, title); | 438 ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
| 464 if (!handler.IsEmpty() && | 439 if (!handler.IsEmpty() && |
| 465 registry->CanSchemeBeOverridden(handler.protocol())) { | 440 registry->CanSchemeBeOverridden(handler.protocol())) { |
| 466 AddInfoBar(registry->IsRegistered(handler) ? | 441 AddInfoBar(registry->IsRegistered(handler) ? |
| 467 static_cast<InfoBarDelegate*>(new SimpleAlertInfoBarDelegate( | 442 static_cast<InfoBarDelegate*>(new SimpleAlertInfoBarDelegate( |
| 468 tab_contents(), NULL, l10n_util::GetStringFUTF16( | 443 tab_contents(), NULL, l10n_util::GetStringFUTF16( |
| 469 IDS_REGISTER_PROTOCOL_HANDLER_ALREADY_REGISTERED, | 444 IDS_REGISTER_PROTOCOL_HANDLER_ALREADY_REGISTERED, |
| 470 handler.title(), UTF8ToUTF16(handler.protocol())), true)) : | 445 handler.title(), UTF8ToUTF16(handler.protocol())), true)) : |
| 471 new RegisterProtocolHandlerInfoBarDelegate(tab_contents(), registry, | 446 new RegisterProtocolHandlerInfoBarDelegate(tab_contents(), registry, |
| 472 handler)); | 447 handler)); |
| 473 } | 448 } |
| 474 } | 449 } |
| 475 | 450 |
| 476 void TabContentsWrapper::OnThumbnail(const GURL& url, | |
| 477 const ThumbnailScore& score, | |
| 478 const SkBitmap& bitmap) { | |
| 479 if (profile()->IsOffTheRecord()) | |
| 480 return; | |
| 481 | |
| 482 // Tell History about this thumbnail | |
| 483 history::TopSites* ts = profile()->GetTopSites(); | |
| 484 if (ts) | |
| 485 ts->SetPageThumbnail(url, bitmap, score); | |
| 486 } | |
| 487 | |
| 488 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { | 451 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { |
| 489 NotificationService::current()->Notify( | 452 NotificationService::current()->Notify( |
| 490 NotificationType::TAB_SNAPSHOT_TAKEN, | 453 NotificationType::TAB_SNAPSHOT_TAKEN, |
| 491 Source<TabContentsWrapper>(this), | 454 Source<TabContentsWrapper>(this), |
| 492 Details<const SkBitmap>(&bitmap)); | 455 Details<const SkBitmap>(&bitmap)); |
| 493 } | 456 } |
| 494 | 457 |
| 495 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { | 458 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { |
| 496 PDFHasUnsupportedFeature(this); | 459 PDFHasUnsupportedFeature(this); |
| 497 } | 460 } |
| OLD | NEW |