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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 #include "content/browser/renderer_host/render_view_host.h" | 75 #include "content/browser/renderer_host/render_view_host.h" |
76 #include "content/browser/renderer_host/render_widget_host_view.h" | 76 #include "content/browser/renderer_host/render_widget_host_view.h" |
77 #include "content/browser/renderer_host/resource_request_details.h" | 77 #include "content/browser/renderer_host/resource_request_details.h" |
78 #include "content/browser/site_instance.h" | 78 #include "content/browser/site_instance.h" |
79 #include "content/browser/tab_contents/interstitial_page.h" | 79 #include "content/browser/tab_contents/interstitial_page.h" |
80 #include "content/browser/tab_contents/navigation_entry.h" | 80 #include "content/browser/tab_contents/navigation_entry.h" |
81 #include "content/browser/tab_contents/provisional_load_details.h" | 81 #include "content/browser/tab_contents/provisional_load_details.h" |
82 #include "content/browser/tab_contents/tab_contents_delegate.h" | 82 #include "content/browser/tab_contents/tab_contents_delegate.h" |
83 #include "content/browser/tab_contents/tab_contents_observer.h" | 83 #include "content/browser/tab_contents/tab_contents_observer.h" |
84 #include "content/browser/tab_contents/tab_contents_view.h" | 84 #include "content/browser/tab_contents/tab_contents_view.h" |
85 #include "content/browser/webui/web_ui.h" | 85 #include "content/browser/webui/web_ui_register.h" |
| 86 #include "content/browser/webui/web_ui_source.h" |
86 #include "content/common/navigation_types.h" | 87 #include "content/common/navigation_types.h" |
87 #include "content/common/notification_service.h" | 88 #include "content/common/notification_service.h" |
88 #include "content/common/view_messages.h" | 89 #include "content/common/view_messages.h" |
89 #include "net/base/net_util.h" | 90 #include "net/base/net_util.h" |
90 #include "net/base/registry_controlled_domain.h" | 91 #include "net/base/registry_controlled_domain.h" |
91 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 92 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
92 #include "ui/base/resource/resource_bundle.h" | 93 #include "ui/base/resource/resource_bundle.h" |
93 #include "ui/gfx/codec/png_codec.h" | 94 #include "ui/gfx/codec/png_codec.h" |
94 #include "webkit/glue/password_form.h" | 95 #include "webkit/glue/password_form.h" |
95 #include "webkit/glue/webpreferences.h" | 96 #include "webkit/glue/webpreferences.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 displayed_insecure_content_(false), | 247 displayed_insecure_content_(false), |
247 extension_app_(NULL), | 248 extension_app_(NULL), |
248 capturing_contents_(false), | 249 capturing_contents_(false), |
249 is_being_destroyed_(false), | 250 is_being_destroyed_(false), |
250 notify_disconnection_(false), | 251 notify_disconnection_(false), |
251 #if defined(OS_WIN) | 252 #if defined(OS_WIN) |
252 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), | 253 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
253 #endif | 254 #endif |
254 suppress_javascript_messages_(false), | 255 suppress_javascript_messages_(false), |
255 is_showing_before_unload_dialog_(false), | 256 is_showing_before_unload_dialog_(false), |
256 opener_web_ui_type_(WebUIFactory::kNoWebUI), | 257 opener_web_ui_type_(WebUI::kNoWebUI), |
257 language_state_(&controller_), | 258 language_state_(&controller_), |
258 closed_by_user_gesture_(false), | 259 closed_by_user_gesture_(false), |
259 minimum_zoom_percent_( | 260 minimum_zoom_percent_( |
260 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), | 261 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), |
261 maximum_zoom_percent_( | 262 maximum_zoom_percent_( |
262 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), | 263 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), |
263 temporary_zoom_settings_(false), | 264 temporary_zoom_settings_(false), |
264 content_restrictions_(0) { | 265 content_restrictions_(0) { |
265 renderer_preferences_util::UpdateFromSystemSettings( | 266 renderer_preferences_util::UpdateFromSystemSettings( |
266 &renderer_preferences_, profile); | 267 &renderer_preferences_, profile); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 548 |
548 bool TabContents::ShouldDisplayURL() { | 549 bool TabContents::ShouldDisplayURL() { |
549 // Don't hide the url in view source mode and with interstitials. | 550 // Don't hide the url in view source mode and with interstitials. |
550 NavigationEntry* entry = controller_.GetActiveEntry(); | 551 NavigationEntry* entry = controller_.GetActiveEntry(); |
551 if (entry && (entry->IsViewSourceMode() || | 552 if (entry && (entry->IsViewSourceMode() || |
552 entry->page_type() == INTERSTITIAL_PAGE)) { | 553 entry->page_type() == INTERSTITIAL_PAGE)) { |
553 return true; | 554 return true; |
554 } | 555 } |
555 | 556 |
556 // We always display the URL for non-WebUI URLs to prevent spoofing. | 557 // We always display the URL for non-WebUI URLs to prevent spoofing. |
557 if (entry && !WebUIFactory::HasWebUIScheme(entry->url())) | 558 if (entry && !WebUIRegister::GetSource()->HasWebUIScheme(entry->url())) |
558 return true; | 559 return true; |
559 | 560 |
560 WebUI* web_ui = GetWebUIForCurrentState(); | 561 WebUI* web_ui = GetWebUIForCurrentState(); |
561 if (web_ui) | 562 if (web_ui) |
562 return !web_ui->should_hide_url(); | 563 return !web_ui->should_hide_url(); |
563 return true; | 564 return true; |
564 } | 565 } |
565 | 566 |
566 SkBitmap TabContents::GetFavicon() const { | 567 SkBitmap TabContents::GetFavicon() const { |
567 // Like GetTitle(), we also want to use the favicon for the last committed | 568 // Like GetTitle(), we also want to use the favicon for the last committed |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 725 |
725 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { | 726 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { |
726 dest_render_view_host->EnablePreferredSizeChangedMode( | 727 dest_render_view_host->EnablePreferredSizeChangedMode( |
727 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); | 728 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
728 } | 729 } |
729 | 730 |
730 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 731 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
731 // Double check that here. | 732 // Double check that here. |
732 int enabled_bindings = dest_render_view_host->enabled_bindings(); | 733 int enabled_bindings = dest_render_view_host->enabled_bindings(); |
733 bool is_allowed_in_web_ui_renderer = | 734 bool is_allowed_in_web_ui_renderer = |
734 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url()); | 735 WebUIRegister::GetSource()->IsURLAcceptableForWebUI(profile(), |
| 736 entry.url()); |
735 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) || | 737 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) || |
736 is_allowed_in_web_ui_renderer); | 738 is_allowed_in_web_ui_renderer); |
737 | 739 |
738 // Tell DevTools agent that it is attached prior to the navigation. | 740 // Tell DevTools agent that it is attached prior to the navigation. |
739 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 741 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
740 if (devtools_manager) { // NULL in unit tests. | 742 if (devtools_manager) { // NULL in unit tests. |
741 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), | 743 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), |
742 dest_render_view_host, | 744 dest_render_view_host, |
743 entry.url()); | 745 entry.url()); |
744 } | 746 } |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 // | 1602 // |
1601 // - Normal state with no load: committed nav entry + no pending nav entry: | 1603 // - Normal state with no load: committed nav entry + no pending nav entry: |
1602 // -> Use committed Web UI. | 1604 // -> Use committed Web UI. |
1603 if (controller_.pending_entry() && | 1605 if (controller_.pending_entry() && |
1604 (controller_.GetLastCommittedEntry() || | 1606 (controller_.GetLastCommittedEntry() || |
1605 render_manager_.pending_web_ui())) | 1607 render_manager_.pending_web_ui())) |
1606 return render_manager_.pending_web_ui(); | 1608 return render_manager_.pending_web_ui(); |
1607 return render_manager_.web_ui(); | 1609 return render_manager_.web_ui(); |
1608 } | 1610 } |
1609 | 1611 |
| 1612 WebUI::WebUITypeID TabContents::GetWebUITypeForCurrentState() { |
| 1613 return WebUIRegister::GetSource()->GetWebUIType(profile(), GetURL()); |
| 1614 } |
| 1615 |
1610 void TabContents::DidNavigateMainFramePostCommit( | 1616 void TabContents::DidNavigateMainFramePostCommit( |
1611 const NavigationController::LoadCommittedDetails& details, | 1617 const NavigationController::LoadCommittedDetails& details, |
1612 const ViewHostMsg_FrameNavigate_Params& params) { | 1618 const ViewHostMsg_FrameNavigate_Params& params) { |
1613 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) { | 1619 if (opener_web_ui_type_ != WebUI::kNoWebUI) { |
1614 // If this is a window.open navigation, use the same WebUI as the renderer | 1620 // 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 | 1621 // that opened the window, as long as both renderers have the same |
1616 // privileges. | 1622 // privileges. |
1617 if (opener_web_ui_type_ == | 1623 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { |
1618 WebUIFactory::GetWebUIType(profile(), GetURL())) { | 1624 WebUI* web_ui = WebUIRegister::GetSource()->CreateWebUIForURL(this, |
1619 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL()); | 1625 GetURL()); |
1620 // web_ui might be NULL if the URL refers to a non-existent extension. | 1626 // web_ui might be NULL if the URL refers to a non-existent extension. |
1621 if (web_ui) { | 1627 if (web_ui) { |
1622 render_manager_.SetWebUIPostCommit(web_ui); | 1628 render_manager_.SetWebUIPostCommit(web_ui); |
1623 web_ui->RenderViewCreated(render_view_host()); | 1629 web_ui->RenderViewCreated(render_view_host()); |
1624 } | 1630 } |
1625 } | 1631 } |
1626 opener_web_ui_type_ = WebUIFactory::kNoWebUI; | 1632 opener_web_ui_type_ = WebUI::kNoWebUI; |
1627 } | 1633 } |
1628 | 1634 |
1629 if (details.is_user_initiated_main_frame_load()) { | 1635 if (details.is_user_initiated_main_frame_load()) { |
1630 // Clear the status bubble. This is a workaround for a bug where WebKit | 1636 // 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 | 1637 // 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 | 1638 // 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 | 1639 // 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 | 1640 // clear the bubble when a user navigates to a named anchor in the same |
1635 // page. | 1641 // page. |
1636 UpdateTargetURL(details.entry->page_id(), GURL()); | 1642 UpdateTargetURL(details.entry->page_id(), GURL()); |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2590 | 2596 |
2591 void TabContents::NotifySwappedFromRenderManager() { | 2597 void TabContents::NotifySwappedFromRenderManager() { |
2592 NotifySwapped(); | 2598 NotifySwapped(); |
2593 } | 2599 } |
2594 | 2600 |
2595 NavigationController& TabContents::GetControllerForRenderManager() { | 2601 NavigationController& TabContents::GetControllerForRenderManager() { |
2596 return controller(); | 2602 return controller(); |
2597 } | 2603 } |
2598 | 2604 |
2599 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { | 2605 WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) { |
2600 return WebUIFactory::CreateWebUIForURL(this, url); | 2606 return WebUIRegister::GetSource()->CreateWebUIForURL(this, url); |
2601 } | 2607 } |
2602 | 2608 |
2603 NavigationEntry* | 2609 NavigationEntry* |
2604 TabContents::GetLastCommittedNavigationEntryForRenderManager() { | 2610 TabContents::GetLastCommittedNavigationEntryForRenderManager() { |
2605 return controller_.GetLastCommittedEntry(); | 2611 return controller_.GetLastCommittedEntry(); |
2606 } | 2612 } |
2607 | 2613 |
2608 bool TabContents::CreateRenderViewForRenderManager( | 2614 bool TabContents::CreateRenderViewForRenderManager( |
2609 RenderViewHost* render_view_host) { | 2615 RenderViewHost* render_view_host) { |
2610 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); | 2616 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2777 | 2783 |
2778 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2784 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
2779 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2785 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
2780 rwh_view->SetSize(view()->GetContainerSize()); | 2786 rwh_view->SetSize(view()->GetContainerSize()); |
2781 } | 2787 } |
2782 | 2788 |
2783 void TabContents::OnOnlineStateChanged(bool online) { | 2789 void TabContents::OnOnlineStateChanged(bool online) { |
2784 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2790 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
2785 render_view_host()->routing_id(), online)); | 2791 render_view_host()->routing_id(), online)); |
2786 } | 2792 } |
OLD | NEW |