| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 is_showing_before_unload_dialog_(false), | 340 is_showing_before_unload_dialog_(false), |
| 341 last_active_time_(base::TimeTicks::Now()), | 341 last_active_time_(base::TimeTicks::Now()), |
| 342 closed_by_user_gesture_(false), | 342 closed_by_user_gesture_(false), |
| 343 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), | 343 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
| 344 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), | 344 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
| 345 totalPinchGestureAmount_(0), | 345 totalPinchGestureAmount_(0), |
| 346 currentPinchZoomStepDelta_(0), | 346 currentPinchZoomStepDelta_(0), |
| 347 render_view_message_source_(NULL), | 347 render_view_message_source_(NULL), |
| 348 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), | 348 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
| 349 is_subframe_(false), | 349 is_subframe_(false), |
| 350 overscroll_content_disabled_(false), |
| 350 last_dialog_suppressed_(false) { | 351 last_dialog_suppressed_(false) { |
| 351 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 352 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 352 g_created_callbacks.Get().at(i).Run(this); | 353 g_created_callbacks.Get().at(i).Run(this); |
| 353 frame_tree_.SetFrameRemoveListener( | 354 frame_tree_.SetFrameRemoveListener( |
| 354 base::Bind(&WebContentsImpl::OnFrameRemoved, | 355 base::Bind(&WebContentsImpl::OnFrameRemoved, |
| 355 base::Unretained(this))); | 356 base::Unretained(this))); |
| 356 } | 357 } |
| 357 | 358 |
| 358 WebContentsImpl::~WebContentsImpl() { | 359 WebContentsImpl::~WebContentsImpl() { |
| 359 is_being_destroyed_ = true; | 360 is_being_destroyed_ = true; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 // TODO(cbentzel): remove this debugging code? | 607 // TODO(cbentzel): remove this debugging code? |
| 607 if (delegate == delegate_) | 608 if (delegate == delegate_) |
| 608 return; | 609 return; |
| 609 if (delegate_) | 610 if (delegate_) |
| 610 delegate_->Detach(this); | 611 delegate_->Detach(this); |
| 611 delegate_ = delegate; | 612 delegate_ = delegate; |
| 612 if (delegate_) { | 613 if (delegate_) { |
| 613 delegate_->Attach(this); | 614 delegate_->Attach(this); |
| 614 // Ensure the visible RVH reflects the new delegate's preferences. | 615 // Ensure the visible RVH reflects the new delegate's preferences. |
| 615 if (view_) | 616 if (view_) |
| 616 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent()); | 617 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 617 } | 618 } |
| 618 } | 619 } |
| 619 | 620 |
| 620 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { | 621 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { |
| 621 RenderViewHostImpl* host = GetRenderManager()->current_host(); | 622 RenderViewHostImpl* host = GetRenderManager()->current_host(); |
| 622 return host ? host->GetProcess() : NULL; | 623 return host ? host->GetProcess() : NULL; |
| 623 } | 624 } |
| 624 | 625 |
| 625 RenderFrameHost* WebContentsImpl::GetMainFrame() { | 626 RenderFrameHost* WebContentsImpl::GetMainFrame() { |
| 626 return frame_tree_.root()->current_frame_host(); | 627 return frame_tree_.root()->current_frame_host(); |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 const gfx::Rect& anchor_in_root_view) { | 1692 const gfx::Rect& anchor_in_root_view) { |
| 1692 if (delegate_) | 1693 if (delegate_) |
| 1693 delegate_->MoveValidationMessage(this, anchor_in_root_view); | 1694 delegate_->MoveValidationMessage(this, anchor_in_root_view); |
| 1694 } | 1695 } |
| 1695 | 1696 |
| 1696 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { | 1697 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { |
| 1697 if (browser_plugin_embedder_) | 1698 if (browser_plugin_embedder_) |
| 1698 browser_plugin_embedder_->DidSendScreenRects(); | 1699 browser_plugin_embedder_->DidSendScreenRects(); |
| 1699 } | 1700 } |
| 1700 | 1701 |
| 1702 void WebContentsImpl::OnSetTouchEventEmulationEnabled(bool enabled) { |
| 1703 // Disable overscroll when touch emulation is on. See crbug.com/369938. |
| 1704 overscroll_content_disabled_ = enabled; |
| 1705 if (view_) |
| 1706 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 1707 } |
| 1708 |
| 1701 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { | 1709 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
| 1702 const gfx::Size old_size = GetPreferredSize(); | 1710 const gfx::Size old_size = GetPreferredSize(); |
| 1703 preferred_size_ = pref_size; | 1711 preferred_size_ = pref_size; |
| 1704 OnPreferredSizeChanged(old_size); | 1712 OnPreferredSizeChanged(old_size); |
| 1705 } | 1713 } |
| 1706 | 1714 |
| 1707 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { | 1715 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { |
| 1708 if (delegate_) | 1716 if (delegate_) |
| 1709 delegate_->ResizeDueToAutoResize(this, new_size); | 1717 delegate_->ResizeDueToAutoResize(this, new_size); |
| 1710 } | 1718 } |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 // displayed insecure content. | 2457 // displayed insecure content. |
| 2450 displayed_insecure_content_ = false; | 2458 displayed_insecure_content_ = false; |
| 2451 SSLManager::NotifySSLInternalStateChanged( | 2459 SSLManager::NotifySSLInternalStateChanged( |
| 2452 GetController().GetBrowserContext()); | 2460 GetController().GetBrowserContext()); |
| 2453 } | 2461 } |
| 2454 | 2462 |
| 2455 // Notify observers about navigation. | 2463 // Notify observers about navigation. |
| 2456 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2464 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2457 DidNavigateMainFrame(details, params)); | 2465 DidNavigateMainFrame(details, params)); |
| 2458 | 2466 |
| 2459 if (delegate_) { | 2467 if (delegate_) |
| 2460 delegate_->DidNavigateMainFramePostCommit(this); | 2468 delegate_->DidNavigateMainFramePostCommit(this); |
| 2461 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent()); | 2469 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 2462 } | |
| 2463 } | 2470 } |
| 2464 | 2471 |
| 2465 void WebContentsImpl::DidNavigateAnyFramePostCommit( | 2472 void WebContentsImpl::DidNavigateAnyFramePostCommit( |
| 2466 RenderFrameHostImpl* render_frame_host, | 2473 RenderFrameHostImpl* render_frame_host, |
| 2467 const LoadCommittedDetails& details, | 2474 const LoadCommittedDetails& details, |
| 2468 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | 2475 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 2469 // Now that something has committed, we don't need to track whether the | 2476 // Now that something has committed, we don't need to track whether the |
| 2470 // initial page has been accessed. | 2477 // initial page has been accessed. |
| 2471 has_accessed_initial_document_ = false; | 2478 has_accessed_initial_document_ = false; |
| 2472 | 2479 |
| 2473 // If we navigate off the page, close all JavaScript dialogs. | 2480 // If we navigate off the page, close all JavaScript dialogs. |
| 2474 if (dialog_manager_ && !details.is_in_page) | 2481 if (dialog_manager_ && !details.is_in_page) |
| 2475 dialog_manager_->CancelActiveAndPendingDialogs(this); | 2482 dialog_manager_->CancelActiveAndPendingDialogs(this); |
| 2476 | 2483 |
| 2477 // Notify observers about navigation. | 2484 // Notify observers about navigation. |
| 2478 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 2485 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2479 DidNavigateAnyFrame(details, params)); | 2486 DidNavigateAnyFrame(details, params)); |
| 2480 } | 2487 } |
| 2481 | 2488 |
| 2482 void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) { | 2489 void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) { |
| 2483 contents_mime_type_ = mime_type; | 2490 contents_mime_type_ = mime_type; |
| 2484 } | 2491 } |
| 2485 | 2492 |
| 2486 bool WebContentsImpl::CanOverscrollContent() const { | 2493 bool WebContentsImpl::CanOverscrollContent() const { |
| 2494 if (overscroll_content_disabled_) |
| 2495 return false; |
| 2496 |
| 2487 if (delegate_) | 2497 if (delegate_) |
| 2488 return delegate_->CanOverscrollContent(); | 2498 return delegate_->CanOverscrollContent(); |
| 2489 | 2499 |
| 2490 return false; | 2500 return false; |
| 2491 } | 2501 } |
| 2492 | 2502 |
| 2493 void WebContentsImpl::OnDidLoadResourceFromMemoryCache( | 2503 void WebContentsImpl::OnDidLoadResourceFromMemoryCache( |
| 2494 const GURL& url, | 2504 const GURL& url, |
| 2495 const std::string& security_info, | 2505 const std::string& security_info, |
| 2496 const std::string& http_method, | 2506 const std::string& http_method, |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3288 } | 3298 } |
| 3289 | 3299 |
| 3290 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 3300 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
| 3291 // Don't send notifications if we are just creating a swapped-out RVH for | 3301 // Don't send notifications if we are just creating a swapped-out RVH for |
| 3292 // the opener chain. These won't be used for view-source or WebUI, so it's | 3302 // the opener chain. These won't be used for view-source or WebUI, so it's |
| 3293 // ok to return early. | 3303 // ok to return early. |
| 3294 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut()) | 3304 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut()) |
| 3295 return; | 3305 return; |
| 3296 | 3306 |
| 3297 if (delegate_) | 3307 if (delegate_) |
| 3298 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent()); | 3308 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 3299 | 3309 |
| 3300 NotificationService::current()->Notify( | 3310 NotificationService::current()->Notify( |
| 3301 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, | 3311 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 3302 Source<WebContents>(this), | 3312 Source<WebContents>(this), |
| 3303 Details<RenderViewHost>(render_view_host)); | 3313 Details<RenderViewHost>(render_view_host)); |
| 3304 | 3314 |
| 3305 // When we're creating views, we're still doing initial setup, so we always | 3315 // When we're creating views, we're still doing initial setup, so we always |
| 3306 // use the pending Web UI rather than any possibly existing committed one. | 3316 // use the pending Web UI rather than any possibly existing committed one. |
| 3307 if (GetRenderManager()->pending_web_ui()) | 3317 if (GetRenderManager()->pending_web_ui()) |
| 3308 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host); | 3318 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3790 if (dialog_manager_) | 3800 if (dialog_manager_) |
| 3791 dialog_manager_->CancelActiveAndPendingDialogs(this); | 3801 dialog_manager_->CancelActiveAndPendingDialogs(this); |
| 3792 } | 3802 } |
| 3793 | 3803 |
| 3794 void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host, | 3804 void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host, |
| 3795 RenderViewHost* new_host) { | 3805 RenderViewHost* new_host) { |
| 3796 NotifySwapped(old_host, new_host); | 3806 NotifySwapped(old_host, new_host); |
| 3797 | 3807 |
| 3798 // Make sure the visible RVH reflects the new delegate's preferences. | 3808 // Make sure the visible RVH reflects the new delegate's preferences. |
| 3799 if (delegate_) | 3809 if (delegate_) |
| 3800 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent()); | 3810 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 3801 | 3811 |
| 3802 view_->RenderViewSwappedIn(new_host); | 3812 view_->RenderViewSwappedIn(new_host); |
| 3803 } | 3813 } |
| 3804 | 3814 |
| 3805 int WebContentsImpl::CreateOpenerRenderViewsForRenderManager( | 3815 int WebContentsImpl::CreateOpenerRenderViewsForRenderManager( |
| 3806 SiteInstance* instance) { | 3816 SiteInstance* instance) { |
| 3807 if (!opener_) | 3817 if (!opener_) |
| 3808 return MSG_ROUTING_NONE; | 3818 return MSG_ROUTING_NONE; |
| 3809 | 3819 |
| 3810 // Recursively create RenderViews for anything else in the opener chain. | 3820 // Recursively create RenderViews for anything else in the opener chain. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4050 | 4060 |
| 4051 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 4061 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 4052 if (!delegate_) | 4062 if (!delegate_) |
| 4053 return; | 4063 return; |
| 4054 const gfx::Size new_size = GetPreferredSize(); | 4064 const gfx::Size new_size = GetPreferredSize(); |
| 4055 if (new_size != old_size) | 4065 if (new_size != old_size) |
| 4056 delegate_->UpdatePreferredSize(this, new_size); | 4066 delegate_->UpdatePreferredSize(this, new_size); |
| 4057 } | 4067 } |
| 4058 | 4068 |
| 4059 } // namespace content | 4069 } // namespace content |
| OLD | NEW |