| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #include "chrome/common/extensions/extension_action.h" | 59 #include "chrome/common/extensions/extension_action.h" |
| 60 #include "chrome/common/extensions/extension_icon_set.h" | 60 #include "chrome/common/extensions/extension_icon_set.h" |
| 61 #include "chrome/common/extensions/extension_messages.h" | 61 #include "chrome/common/extensions/extension_messages.h" |
| 62 #include "chrome/common/extensions/extension_resource.h" | 62 #include "chrome/common/extensions/extension_resource.h" |
| 63 #include "chrome/common/extensions/url_pattern.h" | 63 #include "chrome/common/extensions/url_pattern.h" |
| 64 #include "chrome/common/net/url_request_context_getter.h" | 64 #include "chrome/common/net/url_request_context_getter.h" |
| 65 #include "chrome/common/pref_names.h" | 65 #include "chrome/common/pref_names.h" |
| 66 #include "chrome/common/render_messages.h" | 66 #include "chrome/common/render_messages.h" |
| 67 #include "chrome/common/url_constants.h" | 67 #include "chrome/common/url_constants.h" |
| 68 #include "content/browser/child_process_security_policy.h" | 68 #include "content/browser/child_process_security_policy.h" |
| 69 #include "content/browser/content_browser_client.h" | |
| 70 #include "content/browser/host_zoom_map.h" | 69 #include "content/browser/host_zoom_map.h" |
| 71 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 70 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
| 72 #include "content/browser/renderer_host/render_process_host.h" | 71 #include "content/browser/renderer_host/render_process_host.h" |
| 73 #include "content/browser/renderer_host/render_view_host.h" | 72 #include "content/browser/renderer_host/render_view_host.h" |
| 74 #include "content/browser/renderer_host/render_widget_host_view.h" | 73 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 75 #include "content/browser/renderer_host/resource_request_details.h" | 74 #include "content/browser/renderer_host/resource_request_details.h" |
| 76 #include "content/browser/site_instance.h" | 75 #include "content/browser/site_instance.h" |
| 77 #include "content/browser/tab_contents/interstitial_page.h" | 76 #include "content/browser/tab_contents/interstitial_page.h" |
| 78 #include "content/browser/tab_contents/navigation_entry.h" | 77 #include "content/browser/tab_contents/navigation_entry.h" |
| 79 #include "content/browser/tab_contents/provisional_load_details.h" | 78 #include "content/browser/tab_contents/provisional_load_details.h" |
| 80 #include "content/browser/tab_contents/tab_contents_delegate.h" | 79 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 81 #include "content/browser/tab_contents/tab_contents_observer.h" | 80 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 82 #include "content/browser/tab_contents/tab_contents_view.h" | 81 #include "content/browser/tab_contents/tab_contents_view.h" |
| 83 #include "content/browser/webui/web_ui_factory.h" | 82 #include "content/browser/webui/web_ui.h" |
| 84 #include "content/common/content_client.h" | |
| 85 #include "content/common/navigation_types.h" | 83 #include "content/common/navigation_types.h" |
| 86 #include "content/common/notification_service.h" | 84 #include "content/common/notification_service.h" |
| 87 #include "content/common/view_messages.h" | 85 #include "content/common/view_messages.h" |
| 88 #include "net/base/net_util.h" | 86 #include "net/base/net_util.h" |
| 89 #include "net/base/registry_controlled_domain.h" | 87 #include "net/base/registry_controlled_domain.h" |
| 90 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 88 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 91 #include "ui/base/resource/resource_bundle.h" | 89 #include "ui/base/resource/resource_bundle.h" |
| 92 #include "ui/gfx/codec/png_codec.h" | 90 #include "ui/gfx/codec/png_codec.h" |
| 93 #include "webkit/glue/password_form.h" | 91 #include "webkit/glue/password_form.h" |
| 94 #include "webkit/glue/webpreferences.h" | 92 #include "webkit/glue/webpreferences.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 displayed_insecure_content_(false), | 243 displayed_insecure_content_(false), |
| 246 extension_app_(NULL), | 244 extension_app_(NULL), |
| 247 capturing_contents_(false), | 245 capturing_contents_(false), |
| 248 is_being_destroyed_(false), | 246 is_being_destroyed_(false), |
| 249 notify_disconnection_(false), | 247 notify_disconnection_(false), |
| 250 #if defined(OS_WIN) | 248 #if defined(OS_WIN) |
| 251 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), | 249 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 252 #endif | 250 #endif |
| 253 suppress_javascript_messages_(false), | 251 suppress_javascript_messages_(false), |
| 254 is_showing_before_unload_dialog_(false), | 252 is_showing_before_unload_dialog_(false), |
| 255 opener_web_ui_type_(WebUI::kNoWebUI), | 253 opener_web_ui_type_(WebUIFactory::kNoWebUI), |
| 256 language_state_(&controller_), | 254 language_state_(&controller_), |
| 257 closed_by_user_gesture_(false), | 255 closed_by_user_gesture_(false), |
| 258 minimum_zoom_percent_( | 256 minimum_zoom_percent_( |
| 259 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), | 257 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
| 260 maximum_zoom_percent_( | 258 maximum_zoom_percent_( |
| 261 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), | 259 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
| 262 temporary_zoom_settings_(false), | 260 temporary_zoom_settings_(false), |
| 263 content_restrictions_(0) { | 261 content_restrictions_(0) { |
| 264 renderer_preferences_util::UpdateFromSystemSettings( | 262 renderer_preferences_util::UpdateFromSystemSettings( |
| 265 &renderer_preferences_, profile); | 263 &renderer_preferences_, profile); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 | 543 |
| 546 bool TabContents::ShouldDisplayURL() { | 544 bool TabContents::ShouldDisplayURL() { |
| 547 // Don't hide the url in view source mode and with interstitials. | 545 // Don't hide the url in view source mode and with interstitials. |
| 548 NavigationEntry* entry = controller_.GetActiveEntry(); | 546 NavigationEntry* entry = controller_.GetActiveEntry(); |
| 549 if (entry && (entry->IsViewSourceMode() || | 547 if (entry && (entry->IsViewSourceMode() || |
| 550 entry->page_type() == INTERSTITIAL_PAGE)) { | 548 entry->page_type() == INTERSTITIAL_PAGE)) { |
| 551 return true; | 549 return true; |
| 552 } | 550 } |
| 553 | 551 |
| 554 // We always display the URL for non-WebUI URLs to prevent spoofing. | 552 // We always display the URL for non-WebUI URLs to prevent spoofing. |
| 555 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url())) | 553 if (entry && !WebUIFactory::HasWebUIScheme(entry->url())) |
| 556 return true; | 554 return true; |
| 557 | 555 |
| 558 WebUI* web_ui = GetWebUIForCurrentState(); | 556 WebUI* web_ui = GetWebUIForCurrentState(); |
| 559 if (web_ui) | 557 if (web_ui) |
| 560 return !web_ui->should_hide_url(); | 558 return !web_ui->should_hide_url(); |
| 561 return true; | 559 return true; |
| 562 } | 560 } |
| 563 | 561 |
| 564 SkBitmap TabContents::GetFavicon() const { | 562 SkBitmap TabContents::GetFavicon() const { |
| 565 // Like GetTitle(), we also want to use the favicon for the last committed | 563 // Like GetTitle(), we also want to use the favicon for the last committed |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 return false; // Unable to create the desired render view host. | 706 return false; // Unable to create the desired render view host. |
| 709 | 707 |
| 710 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { | 708 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { |
| 711 dest_render_view_host->EnablePreferredSizeChangedMode( | 709 dest_render_view_host->EnablePreferredSizeChangedMode( |
| 712 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); | 710 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
| 713 } | 711 } |
| 714 | 712 |
| 715 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 713 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
| 716 // Double check that here. | 714 // Double check that here. |
| 717 int enabled_bindings = dest_render_view_host->enabled_bindings(); | 715 int enabled_bindings = dest_render_view_host->enabled_bindings(); |
| 718 bool is_allowed_in_web_ui_renderer = content::GetContentClient()-> | 716 bool is_allowed_in_web_ui_renderer = |
| 719 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(), | 717 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url()); |
| 720 entry.url()); | |
| 721 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) || | 718 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) || |
| 722 is_allowed_in_web_ui_renderer); | 719 is_allowed_in_web_ui_renderer); |
| 723 | 720 |
| 724 // Tell DevTools agent that it is attached prior to the navigation. | 721 // Tell DevTools agent that it is attached prior to the navigation. |
| 725 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 722 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
| 726 if (devtools_manager) { // NULL in unit tests. | 723 if (devtools_manager) { // NULL in unit tests. |
| 727 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), | 724 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), |
| 728 dest_render_view_host, | 725 dest_render_view_host, |
| 729 entry.url()); | 726 entry.url()); |
| 730 } | 727 } |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 // | 1591 // |
| 1595 // - Normal state with no load: committed nav entry + no pending nav entry: | 1592 // - Normal state with no load: committed nav entry + no pending nav entry: |
| 1596 // -> Use committed Web UI. | 1593 // -> Use committed Web UI. |
| 1597 if (controller_.pending_entry() && | 1594 if (controller_.pending_entry() && |
| 1598 (controller_.GetLastCommittedEntry() || | 1595 (controller_.GetLastCommittedEntry() || |
| 1599 render_manager_.pending_web_ui())) | 1596 render_manager_.pending_web_ui())) |
| 1600 return render_manager_.pending_web_ui(); | 1597 return render_manager_.pending_web_ui(); |
| 1601 return render_manager_.web_ui(); | 1598 return render_manager_.web_ui(); |
| 1602 } | 1599 } |
| 1603 | 1600 |
| 1604 WebUI::TypeID TabContents::GetWebUITypeForCurrentState() { | |
| 1605 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL()); | |
| 1606 } | |
| 1607 | |
| 1608 void TabContents::DidNavigateMainFramePostCommit( | 1601 void TabContents::DidNavigateMainFramePostCommit( |
| 1609 const NavigationController::LoadCommittedDetails& details, | 1602 const NavigationController::LoadCommittedDetails& details, |
| 1610 const ViewHostMsg_FrameNavigate_Params& params) { | 1603 const ViewHostMsg_FrameNavigate_Params& params) { |
| 1611 if (opener_web_ui_type_ != WebUI::kNoWebUI) { | 1604 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) { |
| 1612 // If this is a window.open navigation, use the same WebUI as the renderer | 1605 // If this is a window.open navigation, use the same WebUI as the renderer |
| 1613 // that opened the window, as long as both renderers have the same | 1606 // that opened the window, as long as both renderers have the same |
| 1614 // privileges. | 1607 // privileges. |
| 1615 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { | 1608 if (opener_web_ui_type_ == |
| 1616 WebUI* web_ui = content::GetContentClient()->browser()-> | 1609 WebUIFactory::GetWebUIType(profile(), GetURL())) { |
| 1617 GetWebUIFactory()->CreateWebUIForURL(this, GetURL()); | 1610 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL()); |
| 1618 // web_ui might be NULL if the URL refers to a non-existent extension. | 1611 // web_ui might be NULL if the URL refers to a non-existent extension. |
| 1619 if (web_ui) { | 1612 if (web_ui) { |
| 1620 render_manager_.SetWebUIPostCommit(web_ui); | 1613 render_manager_.SetWebUIPostCommit(web_ui); |
| 1621 web_ui->RenderViewCreated(render_view_host()); | 1614 web_ui->RenderViewCreated(render_view_host()); |
| 1622 } | 1615 } |
| 1623 } | 1616 } |
| 1624 opener_web_ui_type_ = WebUI::kNoWebUI; | 1617 opener_web_ui_type_ = WebUIFactory::kNoWebUI; |
| 1625 } | 1618 } |
| 1626 | 1619 |
| 1627 if (details.is_user_initiated_main_frame_load()) { | 1620 if (details.is_user_initiated_main_frame_load()) { |
| 1628 // Clear the status bubble. This is a workaround for a bug where WebKit | 1621 // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1629 // doesn't let us know that the cursor left an element during a | 1622 // doesn't let us know that the cursor left an element during a |
| 1630 // transition (this is also why the mouse cursor remains as a hand after | 1623 // transition (this is also why the mouse cursor remains as a hand after |
| 1631 // clicking on a link); see bugs 1184641 and 980803. We don't want to | 1624 // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1632 // clear the bubble when a user navigates to a named anchor in the same | 1625 // clear the bubble when a user navigates to a named anchor in the same |
| 1633 // page. | 1626 // page. |
| 1634 UpdateTargetURL(details.entry->page_id(), GURL()); | 1627 UpdateTargetURL(details.entry->page_id(), GURL()); |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 NotificationService::current()->Notify( | 1987 NotificationService::current()->Notify( |
| 1995 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, | 1988 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 1996 Source<TabContents>(this), | 1989 Source<TabContents>(this), |
| 1997 Details<RenderViewHost>(render_view_host)); | 1990 Details<RenderViewHost>(render_view_host)); |
| 1998 NavigationEntry* entry = controller_.GetActiveEntry(); | 1991 NavigationEntry* entry = controller_.GetActiveEntry(); |
| 1999 if (!entry) | 1992 if (!entry) |
| 2000 return; | 1993 return; |
| 2001 | 1994 |
| 2002 // When we're creating views, we're still doing initial setup, so we always | 1995 // When we're creating views, we're still doing initial setup, so we always |
| 2003 // use the pending Web UI rather than any possibly existing committed one. | 1996 // use the pending Web UI rather than any possibly existing committed one. |
| 2004 if (render_manager_.pending_web_ui()) | 1997 if (render_manager_.pending_web_ui()) { |
| 2005 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); | 1998 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
| 1999 } |
| 2006 | 2000 |
| 2007 if (entry->IsViewSourceMode()) { | 2001 if (entry->IsViewSourceMode()) { |
| 2008 // Put the renderer in view source mode. | 2002 // Put the renderer in view source mode. |
| 2009 render_view_host->Send( | 2003 render_view_host->Send( |
| 2010 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); | 2004 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); |
| 2011 } | 2005 } |
| 2012 | 2006 |
| 2013 view()->RenderViewCreated(render_view_host); | 2007 view()->RenderViewCreated(render_view_host); |
| 2014 } | 2008 } |
| 2015 | 2009 |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2570 | 2564 |
| 2571 void TabContents::NotifySwappedFromRenderManager() { | 2565 void TabContents::NotifySwappedFromRenderManager() { |
| 2572 NotifySwapped(); | 2566 NotifySwapped(); |
| 2573 } | 2567 } |
| 2574 | 2568 |
| 2575 NavigationController& TabContents::GetControllerForRenderManager() { | 2569 NavigationController& TabContents::GetControllerForRenderManager() { |
| 2576 return controller(); | 2570 return controller(); |
| 2577 } | 2571 } |
| 2578 | 2572 |
| 2579 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { | 2573 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { |
| 2580 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url); | 2574 return WebUIFactory::CreateWebUIForURL(this, url); |
| 2581 } | 2575 } |
| 2582 | 2576 |
| 2583 NavigationEntry* | 2577 NavigationEntry* |
| 2584 TabContents::GetLastCommittedNavigationEntryForRenderManager() { | 2578 TabContents::GetLastCommittedNavigationEntryForRenderManager() { |
| 2585 return controller_.GetLastCommittedEntry(); | 2579 return controller_.GetLastCommittedEntry(); |
| 2586 } | 2580 } |
| 2587 | 2581 |
| 2588 bool TabContents::CreateRenderViewForRenderManager( | 2582 bool TabContents::CreateRenderViewForRenderManager( |
| 2589 RenderViewHost* render_view_host) { | 2583 RenderViewHost* render_view_host) { |
| 2590 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); | 2584 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2757 | 2751 |
| 2758 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2752 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2759 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2753 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2760 rwh_view->SetSize(view()->GetContainerSize()); | 2754 rwh_view->SetSize(view()->GetContainerSize()); |
| 2761 } | 2755 } |
| 2762 | 2756 |
| 2763 void TabContents::OnOnlineStateChanged(bool online) { | 2757 void TabContents::OnOnlineStateChanged(bool online) { |
| 2764 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2758 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2765 render_view_host()->routing_id(), online)); | 2759 render_view_host()->routing_id(), online)); |
| 2766 } | 2760 } |
| OLD | NEW |