| 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" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autocomplete_history_manager.h" | 12 #include "chrome/browser/autocomplete_history_manager.h" |
| 13 #include "chrome/browser/autofill/autofill_manager.h" | 13 #include "chrome/browser/autofill/autofill_manager.h" |
| 14 #include "chrome/browser/automation/automation_tab_helper.h" | 14 #include "chrome/browser/automation/automation_tab_helper.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
| 17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | |
| 19 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" | |
| 20 #include "chrome/browser/download/download_request_limiter_observer.h" | 18 #include "chrome/browser/download/download_request_limiter_observer.h" |
| 21 #include "chrome/browser/extensions/extension_tab_helper.h" | 19 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 22 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 20 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
| 23 #include "chrome/browser/external_protocol/external_protocol_observer.h" | 21 #include "chrome/browser/external_protocol/external_protocol_observer.h" |
| 24 #include "chrome/browser/favicon/favicon_tab_helper.h" | 22 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 25 #include "chrome/browser/file_select_helper.h" | 23 #include "chrome/browser/file_select_helper.h" |
| 26 #include "chrome/browser/google/google_util.h" | 24 #include "chrome/browser/google/google_util.h" |
| 27 #include "chrome/browser/history/history_tab_helper.h" | 25 #include "chrome/browser/history/history_tab_helper.h" |
| 28 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" | |
| 29 #include "chrome/browser/intents/web_intent_data.h" | 26 #include "chrome/browser/intents/web_intent_data.h" |
| 30 #include "chrome/browser/omnibox_search_hint.h" | 27 #include "chrome/browser/omnibox_search_hint.h" |
| 31 #include "chrome/browser/password_manager/password_manager.h" | 28 #include "chrome/browser/password_manager/password_manager.h" |
| 32 #include "chrome/browser/password_manager_delegate_impl.h" | 29 #include "chrome/browser/password_manager_delegate_impl.h" |
| 33 #include "chrome/browser/pdf_unsupported_feature.h" | 30 #include "chrome/browser/pdf_unsupported_feature.h" |
| 34 #include "chrome/browser/plugin_observer.h" | 31 #include "chrome/browser/plugin_observer.h" |
| 35 #include "chrome/browser/prefs/pref_service.h" | 32 #include "chrome/browser/prefs/pref_service.h" |
| 36 #include "chrome/browser/prerender/prerender_observer.h" | 33 #include "chrome/browser/prerender/prerender_observer.h" |
| 37 #include "chrome/browser/printing/print_preview_message_handler.h" | 34 #include "chrome/browser/printing/print_preview_message_handler.h" |
| 38 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 #include "chrome/browser/themes/theme_service.h" | 48 #include "chrome/browser/themes/theme_service.h" |
| 52 #include "chrome/browser/themes/theme_service_factory.h" | 49 #include "chrome/browser/themes/theme_service_factory.h" |
| 53 #include "chrome/browser/translate/translate_tab_helper.h" | 50 #include "chrome/browser/translate/translate_tab_helper.h" |
| 54 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 51 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| 55 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 52 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 56 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 53 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 57 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 54 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 58 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 55 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
| 59 #include "chrome/common/chrome_notification_types.h" | 56 #include "chrome/common/chrome_notification_types.h" |
| 60 #include "chrome/common/chrome_switches.h" | 57 #include "chrome/common/chrome_switches.h" |
| 61 #include "chrome/common/custom_handlers/protocol_handler.h" | |
| 62 #include "chrome/common/pref_names.h" | 58 #include "chrome/common/pref_names.h" |
| 63 #include "chrome/common/render_messages.h" | 59 #include "chrome/common/render_messages.h" |
| 64 #include "content/browser/child_process_security_policy.h" | 60 #include "content/browser/child_process_security_policy.h" |
| 65 #include "content/browser/renderer_host/render_view_host.h" | 61 #include "content/browser/renderer_host/render_view_host.h" |
| 66 #include "content/browser/tab_contents/navigation_details.h" | 62 #include "content/browser/tab_contents/navigation_details.h" |
| 67 #include "content/browser/tab_contents/tab_contents.h" | 63 #include "content/browser/tab_contents/tab_contents.h" |
| 68 #include "content/browser/tab_contents/tab_contents_view.h" | 64 #include "content/browser/tab_contents/tab_contents_view.h" |
| 69 #include "content/browser/user_metrics.h" | 65 #include "content/browser/user_metrics.h" |
| 70 #include "content/common/notification_service.h" | 66 #include "content/common/notification_service.h" |
| 71 #include "content/common/view_messages.h" | 67 #include "content/common/view_messages.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 } | 486 } |
| 491 | 487 |
| 492 void TabContentsWrapper::DidBecomeSelected() { | 488 void TabContentsWrapper::DidBecomeSelected() { |
| 493 WebCacheManager::GetInstance()->ObserveActivity( | 489 WebCacheManager::GetInstance()->ObserveActivity( |
| 494 tab_contents()->GetRenderProcessHost()->id()); | 490 tab_contents()->GetRenderProcessHost()->id()); |
| 495 } | 491 } |
| 496 | 492 |
| 497 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { | 493 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { |
| 498 bool handled = true; | 494 bool handled = true; |
| 499 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) | 495 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) |
| 500 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) | |
| 501 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, | |
| 502 OnRegisterProtocolHandler) | |
| 503 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterIntentHandler, | |
| 504 OnRegisterIntentHandler) | |
| 505 IPC_MESSAGE_HANDLER(ViewHostMsg_WebIntentDispatch, | |
| 506 OnWebIntentDispatch) | |
| 507 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot) | 496 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot) |
| 508 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, | 497 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, |
| 509 OnPDFHasUnsupportedFeature) | 498 OnPDFHasUnsupportedFeature) |
| 510 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, | 499 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, |
| 511 OnDidBlockDisplayingInsecureContent) | 500 OnDidBlockDisplayingInsecureContent) |
| 512 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, | 501 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, |
| 513 OnDidBlockRunningInsecureContent) | 502 OnDidBlockRunningInsecureContent) |
| 514 IPC_MESSAGE_UNHANDLED(handled = false) | 503 IPC_MESSAGE_UNHANDLED(handled = false) |
| 515 IPC_END_MESSAGE_MAP() | 504 IPC_END_MESSAGE_MAP() |
| 516 return handled; | 505 return handled; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 infobars_.erase(infobars_.begin() + i + 1); | 628 infobars_.erase(infobars_.begin() + i + 1); |
| 640 } | 629 } |
| 641 | 630 |
| 642 InfoBarDelegate* TabContentsWrapper::GetInfoBarDelegateAt(size_t index) { | 631 InfoBarDelegate* TabContentsWrapper::GetInfoBarDelegateAt(size_t index) { |
| 643 return infobars_[index]; | 632 return infobars_[index]; |
| 644 } | 633 } |
| 645 | 634 |
| 646 //////////////////////////////////////////////////////////////////////////////// | 635 //////////////////////////////////////////////////////////////////////////////// |
| 647 // Internal helpers | 636 // Internal helpers |
| 648 | 637 |
| 649 void TabContentsWrapper::OnJSOutOfMemory() { | |
| 650 AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), | |
| 651 NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); | |
| 652 } | |
| 653 | |
| 654 void TabContentsWrapper::OnRegisterProtocolHandler(const std::string& protocol, | |
| 655 const GURL& url, | |
| 656 const string16& title) { | |
| 657 if (profile()->IsOffTheRecord()) | |
| 658 return; | |
| 659 | |
| 660 ChildProcessSecurityPolicy* policy = | |
| 661 ChildProcessSecurityPolicy::GetInstance(); | |
| 662 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol)) | |
| 663 return; | |
| 664 | |
| 665 ProtocolHandler handler = | |
| 666 ProtocolHandler::CreateProtocolHandler(protocol, url, title); | |
| 667 | |
| 668 ProtocolHandlerRegistry* registry = profile()->GetProtocolHandlerRegistry(); | |
| 669 if (!registry->enabled() || registry->IsRegistered(handler) || | |
| 670 registry->IsIgnored(handler)) | |
| 671 return; | |
| 672 | |
| 673 if (!handler.IsEmpty() && | |
| 674 registry->CanSchemeBeOverridden(handler.protocol())) { | |
| 675 UserMetrics::RecordAction( | |
| 676 UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); | |
| 677 AddInfoBar(new RegisterProtocolHandlerInfoBarDelegate(tab_contents(), | |
| 678 registry, | |
| 679 handler)); | |
| 680 } | |
| 681 } | |
| 682 | |
| 683 void TabContentsWrapper::OnRegisterIntentHandler(const string16& action, | |
| 684 const string16& type, | |
| 685 const string16& href, | |
| 686 const string16& title) { | |
| 687 if (profile()->IsOffTheRecord()) | |
| 688 return; | |
| 689 | |
| 690 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) | |
| 691 return; | |
| 692 | |
| 693 GURL service_url(href); | |
| 694 if (!service_url.is_valid()) { | |
| 695 const GURL& url = tab_contents()->GetURL(); | |
| 696 service_url = url.Resolve(href); | |
| 697 } | |
| 698 | |
| 699 WebIntentData intent; | |
| 700 intent.service_url = service_url; | |
| 701 intent.action = action; | |
| 702 intent.type = type; | |
| 703 intent.title = title; | |
| 704 AddInfoBar(new RegisterIntentHandlerInfoBarDelegate(tab_contents(), intent)); | |
| 705 } | |
| 706 | |
| 707 void TabContentsWrapper::OnWebIntentDispatch(const IPC::Message& message, | |
| 708 const string16& action, | |
| 709 const string16& type, | |
| 710 const string16& data, | |
| 711 int intent_id) { | |
| 712 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) | |
| 713 return; | |
| 714 | |
| 715 DLOG(INFO) << "Browser tab contents received intent:" | |
| 716 << "\naction=" << UTF16ToASCII(action) | |
| 717 << "\ntype=" << UTF16ToASCII(type) | |
| 718 << "\nrenderer_id=" << message.routing_id() | |
| 719 << "\nid=" << intent_id; | |
| 720 } | |
| 721 | |
| 722 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { | 638 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) { |
| 723 NotificationService::current()->Notify( | 639 NotificationService::current()->Notify( |
| 724 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, | 640 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, |
| 725 Source<TabContentsWrapper>(this), | 641 Source<TabContentsWrapper>(this), |
| 726 Details<const SkBitmap>(&bitmap)); | 642 Details<const SkBitmap>(&bitmap)); |
| 727 } | 643 } |
| 728 | 644 |
| 729 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { | 645 void TabContentsWrapper::OnPDFHasUnsupportedFeature() { |
| 730 PDFHasUnsupportedFeature(this); | 646 PDFHasUnsupportedFeature(this); |
| 731 } | 647 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } | 754 } |
| 839 | 755 |
| 840 void TabContentsWrapper::RemoveAllInfoBars(bool animate) { | 756 void TabContentsWrapper::RemoveAllInfoBars(bool animate) { |
| 841 while (!infobars_.empty()) | 757 while (!infobars_.empty()) |
| 842 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); | 758 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); |
| 843 } | 759 } |
| 844 | 760 |
| 845 void TabContentsWrapper::ExitFullscreenMode() { | 761 void TabContentsWrapper::ExitFullscreenMode() { |
| 846 Send(new ViewMsg_ExitFullscreen(routing_id())); | 762 Send(new ViewMsg_ExitFullscreen(routing_id())); |
| 847 } | 763 } |
| OLD | NEW |