| 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 "content/browser/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #include "chrome/common/extensions/extension_action.h" | 62 #include "chrome/common/extensions/extension_action.h" |
| 63 #include "chrome/common/extensions/extension_icon_set.h" | 63 #include "chrome/common/extensions/extension_icon_set.h" |
| 64 #include "chrome/common/extensions/extension_resource.h" | 64 #include "chrome/common/extensions/extension_resource.h" |
| 65 #include "chrome/common/extensions/url_pattern.h" | 65 #include "chrome/common/extensions/url_pattern.h" |
| 66 #include "chrome/common/net/url_request_context_getter.h" | 66 #include "chrome/common/net/url_request_context_getter.h" |
| 67 #include "chrome/common/pref_names.h" | 67 #include "chrome/common/pref_names.h" |
| 68 #include "chrome/common/render_messages.h" | 68 #include "chrome/common/render_messages.h" |
| 69 #include "chrome/common/render_messages_params.h" | 69 #include "chrome/common/render_messages_params.h" |
| 70 #include "chrome/common/url_constants.h" | 70 #include "chrome/common/url_constants.h" |
| 71 #include "content/browser/child_process_security_policy.h" | 71 #include "content/browser/child_process_security_policy.h" |
| 72 #include "content/browser/content_browser_client.h" |
| 72 #include "content/browser/host_zoom_map.h" | 73 #include "content/browser/host_zoom_map.h" |
| 73 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 74 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
| 74 #include "content/browser/renderer_host/render_process_host.h" | 75 #include "content/browser/renderer_host/render_process_host.h" |
| 75 #include "content/browser/renderer_host/render_view_host.h" | 76 #include "content/browser/renderer_host/render_view_host.h" |
| 76 #include "content/browser/renderer_host/render_widget_host_view.h" | 77 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 77 #include "content/browser/renderer_host/resource_request_details.h" | 78 #include "content/browser/renderer_host/resource_request_details.h" |
| 78 #include "content/browser/site_instance.h" | 79 #include "content/browser/site_instance.h" |
| 79 #include "content/browser/tab_contents/interstitial_page.h" | 80 #include "content/browser/tab_contents/interstitial_page.h" |
| 80 #include "content/browser/tab_contents/navigation_entry.h" | 81 #include "content/browser/tab_contents/navigation_entry.h" |
| 81 #include "content/browser/tab_contents/provisional_load_details.h" | 82 #include "content/browser/tab_contents/provisional_load_details.h" |
| 82 #include "content/browser/tab_contents/tab_contents_delegate.h" | 83 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 83 #include "content/browser/tab_contents/tab_contents_observer.h" | 84 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 84 #include "content/browser/tab_contents/tab_contents_view.h" | 85 #include "content/browser/tab_contents/tab_contents_view.h" |
| 85 #include "content/browser/webui/web_ui.h" | 86 #include "content/browser/webui/web_ui_factory.h" |
| 87 #include "content/common/content_client.h" |
| 86 #include "content/common/navigation_types.h" | 88 #include "content/common/navigation_types.h" |
| 87 #include "content/common/notification_service.h" | 89 #include "content/common/notification_service.h" |
| 88 #include "content/common/view_messages.h" | 90 #include "content/common/view_messages.h" |
| 89 #include "net/base/net_util.h" | 91 #include "net/base/net_util.h" |
| 90 #include "net/base/registry_controlled_domain.h" | 92 #include "net/base/registry_controlled_domain.h" |
| 91 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 93 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 92 #include "ui/base/resource/resource_bundle.h" | 94 #include "ui/base/resource/resource_bundle.h" |
| 93 #include "ui/gfx/codec/png_codec.h" | 95 #include "ui/gfx/codec/png_codec.h" |
| 94 #include "webkit/glue/password_form.h" | 96 #include "webkit/glue/password_form.h" |
| 95 #include "webkit/glue/webpreferences.h" | 97 #include "webkit/glue/webpreferences.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 displayed_insecure_content_(false), | 248 displayed_insecure_content_(false), |
| 247 extension_app_(NULL), | 249 extension_app_(NULL), |
| 248 capturing_contents_(false), | 250 capturing_contents_(false), |
| 249 is_being_destroyed_(false), | 251 is_being_destroyed_(false), |
| 250 notify_disconnection_(false), | 252 notify_disconnection_(false), |
| 251 #if defined(OS_WIN) | 253 #if defined(OS_WIN) |
| 252 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), | 254 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 253 #endif | 255 #endif |
| 254 suppress_javascript_messages_(false), | 256 suppress_javascript_messages_(false), |
| 255 is_showing_before_unload_dialog_(false), | 257 is_showing_before_unload_dialog_(false), |
| 256 opener_web_ui_type_(WebUIFactory::kNoWebUI), | 258 opener_web_ui_type_(WebUI::kNoWebUI), |
| 257 language_state_(&controller_), | 259 language_state_(&controller_), |
| 258 closed_by_user_gesture_(false), | 260 closed_by_user_gesture_(false), |
| 259 minimum_zoom_percent_( | 261 minimum_zoom_percent_( |
| 260 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), | 262 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
| 261 maximum_zoom_percent_( | 263 maximum_zoom_percent_( |
| 262 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), | 264 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
| 263 temporary_zoom_settings_(false), | 265 temporary_zoom_settings_(false), |
| 264 content_restrictions_(0) { | 266 content_restrictions_(0) { |
| 265 renderer_preferences_util::UpdateFromSystemSettings( | 267 renderer_preferences_util::UpdateFromSystemSettings( |
| 266 &renderer_preferences_, profile); | 268 &renderer_preferences_, profile); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 549 |
| 548 bool TabContents::ShouldDisplayURL() { | 550 bool TabContents::ShouldDisplayURL() { |
| 549 // Don't hide the url in view source mode and with interstitials. | 551 // Don't hide the url in view source mode and with interstitials. |
| 550 NavigationEntry* entry = controller_.GetActiveEntry(); | 552 NavigationEntry* entry = controller_.GetActiveEntry(); |
| 551 if (entry && (entry->IsViewSourceMode() || | 553 if (entry && (entry->IsViewSourceMode() || |
| 552 entry->page_type() == INTERSTITIAL_PAGE)) { | 554 entry->page_type() == INTERSTITIAL_PAGE)) { |
| 553 return true; | 555 return true; |
| 554 } | 556 } |
| 555 | 557 |
| 556 // We always display the URL for non-WebUI URLs to prevent spoofing. | 558 // We always display the URL for non-WebUI URLs to prevent spoofing. |
| 557 if (entry && !WebUIFactory::HasWebUIScheme(entry->url())) | 559 if (entry && !content::GetContentClient()->browser()->GetWebUIFactory()-> |
| 560 HasWebUIScheme(entry->url())) { |
| 558 return true; | 561 return true; |
| 562 } |
| 559 | 563 |
| 560 WebUI* web_ui = GetWebUIForCurrentState(); | 564 WebUI* web_ui = GetWebUIForCurrentState(); |
| 561 if (web_ui) | 565 if (web_ui) |
| 562 return !web_ui->should_hide_url(); | 566 return !web_ui->should_hide_url(); |
| 563 return true; | 567 return true; |
| 564 } | 568 } |
| 565 | 569 |
| 566 SkBitmap TabContents::GetFavicon() const { | 570 SkBitmap TabContents::GetFavicon() const { |
| 567 // Like GetTitle(), we also want to use the favicon for the last committed | 571 // Like GetTitle(), we also want to use the favicon for the last committed |
| 568 // entry rather than a pending navigation entry. | 572 // entry rather than a pending navigation entry. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 return false; // Unable to create the desired render view host. | 727 return false; // Unable to create the desired render view host. |
| 724 | 728 |
| 725 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { | 729 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { |
| 726 dest_render_view_host->EnablePreferredSizeChangedMode( | 730 dest_render_view_host->EnablePreferredSizeChangedMode( |
| 727 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); | 731 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
| 728 } | 732 } |
| 729 | 733 |
| 730 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 734 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
| 731 // Double check that here. | 735 // Double check that here. |
| 732 int enabled_bindings = dest_render_view_host->enabled_bindings(); | 736 int enabled_bindings = dest_render_view_host->enabled_bindings(); |
| 733 bool is_allowed_in_web_ui_renderer = | 737 bool is_allowed_in_web_ui_renderer = content::GetContentClient()-> |
| 734 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url()); | 738 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(), |
| 739 entry.url()); |
| 735 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) || | 740 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) || |
| 736 is_allowed_in_web_ui_renderer); | 741 is_allowed_in_web_ui_renderer); |
| 737 | 742 |
| 738 // Tell DevTools agent that it is attached prior to the navigation. | 743 // Tell DevTools agent that it is attached prior to the navigation. |
| 739 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 744 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
| 740 if (devtools_manager) { // NULL in unit tests. | 745 if (devtools_manager) { // NULL in unit tests. |
| 741 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), | 746 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), |
| 742 dest_render_view_host, | 747 dest_render_view_host, |
| 743 entry.url()); | 748 entry.url()); |
| 744 } | 749 } |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 // | 1605 // |
| 1601 // - Normal state with no load: committed nav entry + no pending nav entry: | 1606 // - Normal state with no load: committed nav entry + no pending nav entry: |
| 1602 // -> Use committed Web UI. | 1607 // -> Use committed Web UI. |
| 1603 if (controller_.pending_entry() && | 1608 if (controller_.pending_entry() && |
| 1604 (controller_.GetLastCommittedEntry() || | 1609 (controller_.GetLastCommittedEntry() || |
| 1605 render_manager_.pending_web_ui())) | 1610 render_manager_.pending_web_ui())) |
| 1606 return render_manager_.pending_web_ui(); | 1611 return render_manager_.pending_web_ui(); |
| 1607 return render_manager_.web_ui(); | 1612 return render_manager_.web_ui(); |
| 1608 } | 1613 } |
| 1609 | 1614 |
| 1615 WebUI::WebUITypeID TabContents::GetWebUITypeForCurrentState() { |
| 1616 return content::GetContentClient()->browser()->GetWebUIFactory()-> |
| 1617 GetWebUIType(profile(), GetURL()); |
| 1618 } |
| 1619 |
| 1610 void TabContents::DidNavigateMainFramePostCommit( | 1620 void TabContents::DidNavigateMainFramePostCommit( |
| 1611 const NavigationController::LoadCommittedDetails& details, | 1621 const NavigationController::LoadCommittedDetails& details, |
| 1612 const ViewHostMsg_FrameNavigate_Params& params) { | 1622 const ViewHostMsg_FrameNavigate_Params& params) { |
| 1613 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) { | 1623 if (opener_web_ui_type_ != WebUI::kNoWebUI) { |
| 1614 // If this is a window.open navigation, use the same WebUI as the renderer | 1624 // If this is a window.open navigation, use the same WebUI as the renderer |
| 1615 // that opened the window, as long as both renderers have the same | 1625 // that opened the window, as long as both renderers have the same |
| 1616 // privileges. | 1626 // privileges. |
| 1617 if (opener_web_ui_type_ == | 1627 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { |
| 1618 WebUIFactory::GetWebUIType(profile(), GetURL())) { | 1628 WebUI* web_ui = content::GetContentClient()->browser()-> |
| 1619 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL()); | 1629 GetWebUIFactory()->CreateWebUIForURL(this, GetURL()); |
| 1620 // web_ui might be NULL if the URL refers to a non-existent extension. | 1630 // web_ui might be NULL if the URL refers to a non-existent extension. |
| 1621 if (web_ui) { | 1631 if (web_ui) { |
| 1622 render_manager_.SetWebUIPostCommit(web_ui); | 1632 render_manager_.SetWebUIPostCommit(web_ui); |
| 1623 web_ui->RenderViewCreated(render_view_host()); | 1633 web_ui->RenderViewCreated(render_view_host()); |
| 1624 } | 1634 } |
| 1625 } | 1635 } |
| 1626 opener_web_ui_type_ = WebUIFactory::kNoWebUI; | 1636 opener_web_ui_type_ = WebUI::kNoWebUI; |
| 1627 } | 1637 } |
| 1628 | 1638 |
| 1629 if (details.is_user_initiated_main_frame_load()) { | 1639 if (details.is_user_initiated_main_frame_load()) { |
| 1630 // Clear the status bubble. This is a workaround for a bug where WebKit | 1640 // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1631 // doesn't let us know that the cursor left an element during a | 1641 // doesn't let us know that the cursor left an element during a |
| 1632 // transition (this is also why the mouse cursor remains as a hand after | 1642 // transition (this is also why the mouse cursor remains as a hand after |
| 1633 // clicking on a link); see bugs 1184641 and 980803. We don't want to | 1643 // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1634 // clear the bubble when a user navigates to a named anchor in the same | 1644 // clear the bubble when a user navigates to a named anchor in the same |
| 1635 // page. | 1645 // page. |
| 1636 UpdateTargetURL(details.entry->page_id(), GURL()); | 1646 UpdateTargetURL(details.entry->page_id(), GURL()); |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 NotificationService::current()->Notify( | 2006 NotificationService::current()->Notify( |
| 1997 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, | 2007 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 1998 Source<TabContents>(this), | 2008 Source<TabContents>(this), |
| 1999 Details<RenderViewHost>(render_view_host)); | 2009 Details<RenderViewHost>(render_view_host)); |
| 2000 NavigationEntry* entry = controller_.GetActiveEntry(); | 2010 NavigationEntry* entry = controller_.GetActiveEntry(); |
| 2001 if (!entry) | 2011 if (!entry) |
| 2002 return; | 2012 return; |
| 2003 | 2013 |
| 2004 // When we're creating views, we're still doing initial setup, so we always | 2014 // When we're creating views, we're still doing initial setup, so we always |
| 2005 // use the pending Web UI rather than any possibly existing committed one. | 2015 // use the pending Web UI rather than any possibly existing committed one. |
| 2006 if (render_manager_.pending_web_ui()) { | 2016 if (render_manager_.pending_web_ui()) |
| 2007 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); | 2017 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
| 2008 } | |
| 2009 | 2018 |
| 2010 if (entry->IsViewSourceMode()) { | 2019 if (entry->IsViewSourceMode()) { |
| 2011 // Put the renderer in view source mode. | 2020 // Put the renderer in view source mode. |
| 2012 render_view_host->Send( | 2021 render_view_host->Send( |
| 2013 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); | 2022 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); |
| 2014 } | 2023 } |
| 2015 | 2024 |
| 2016 view()->RenderViewCreated(render_view_host); | 2025 view()->RenderViewCreated(render_view_host); |
| 2017 } | 2026 } |
| 2018 | 2027 |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2590 | 2599 |
| 2591 void TabContents::NotifySwappedFromRenderManager() { | 2600 void TabContents::NotifySwappedFromRenderManager() { |
| 2592 NotifySwapped(); | 2601 NotifySwapped(); |
| 2593 } | 2602 } |
| 2594 | 2603 |
| 2595 NavigationController& TabContents::GetControllerForRenderManager() { | 2604 NavigationController& TabContents::GetControllerForRenderManager() { |
| 2596 return controller(); | 2605 return controller(); |
| 2597 } | 2606 } |
| 2598 | 2607 |
| 2599 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { | 2608 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { |
| 2600 return WebUIFactory::CreateWebUIForURL(this, url); | 2609 return content::GetContentClient()->browser()->GetWebUIFactory()-> |
| 2610 CreateWebUIForURL(this, url); |
| 2601 } | 2611 } |
| 2602 | 2612 |
| 2603 NavigationEntry* | 2613 NavigationEntry* |
| 2604 TabContents::GetLastCommittedNavigationEntryForRenderManager() { | 2614 TabContents::GetLastCommittedNavigationEntryForRenderManager() { |
| 2605 return controller_.GetLastCommittedEntry(); | 2615 return controller_.GetLastCommittedEntry(); |
| 2606 } | 2616 } |
| 2607 | 2617 |
| 2608 bool TabContents::CreateRenderViewForRenderManager( | 2618 bool TabContents::CreateRenderViewForRenderManager( |
| 2609 RenderViewHost* render_view_host) { | 2619 RenderViewHost* render_view_host) { |
| 2610 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); | 2620 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2777 | 2787 |
| 2778 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2788 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2779 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2789 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2780 rwh_view->SetSize(view()->GetContainerSize()); | 2790 rwh_view->SetSize(view()->GetContainerSize()); |
| 2781 } | 2791 } |
| 2782 | 2792 |
| 2783 void TabContents::OnOnlineStateChanged(bool online) { | 2793 void TabContents::OnOnlineStateChanged(bool online) { |
| 2784 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2794 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2785 render_view_host()->routing_id(), online)); | 2795 render_view_host()->routing_id(), online)); |
| 2786 } | 2796 } |
| OLD | NEW |