| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame_host/render_widget_host_view_child_frame.h" | 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 begin_frame_source_(nullptr), | 62 begin_frame_source_(nullptr), |
| 63 weak_factory_(this) { | 63 weak_factory_(this) { |
| 64 id_allocator_.reset(new cc::SurfaceIdAllocator()); | 64 id_allocator_.reset(new cc::SurfaceIdAllocator()); |
| 65 auto* manager = GetSurfaceManager(); | 65 auto* manager = GetSurfaceManager(); |
| 66 manager->RegisterFrameSinkId(frame_sink_id_); | 66 manager->RegisterFrameSinkId(frame_sink_id_); |
| 67 surface_factory_ = | 67 surface_factory_ = |
| 68 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); | 68 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { | 71 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { |
| 72 if (!local_frame_id_.is_null()) | 72 if (local_frame_id_.is_valid()) |
| 73 surface_factory_->Destroy(local_frame_id_); | 73 surface_factory_->Destroy(local_frame_id_); |
| 74 | 74 |
| 75 if (GetSurfaceManager()) | 75 if (GetSurfaceManager()) |
| 76 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); | 76 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void RenderWidgetHostViewChildFrame::Init() { | 79 void RenderWidgetHostViewChildFrame::Init() { |
| 80 RegisterFrameSinkId(); | 80 RegisterFrameSinkId(); |
| 81 host_->SetView(this); | 81 host_->SetView(this); |
| 82 GetTextInputManager(); | 82 GetTextInputManager(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( | 85 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( |
| 86 CrossProcessFrameConnector* frame_connector) { | 86 CrossProcessFrameConnector* frame_connector) { |
| 87 if (frame_connector_ == frame_connector) | 87 if (frame_connector_ == frame_connector) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 if (frame_connector_) { | 90 if (frame_connector_) { |
| 91 if (!parent_frame_sink_id_.is_null()) { | 91 if (parent_frame_sink_id_.is_valid()) { |
| 92 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, | 92 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 93 frame_sink_id_); | 93 frame_sink_id_); |
| 94 } | 94 } |
| 95 // Unregister the client here, as it is not guaranteed in tests that the | 95 // Unregister the client here, as it is not guaranteed in tests that the |
| 96 // destructor will be called. | 96 // destructor will be called. |
| 97 GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_); | 97 GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 98 | 98 |
| 99 parent_frame_sink_id_ = cc::FrameSinkId(); | 99 parent_frame_sink_id_ = cc::FrameSinkId(); |
| 100 | 100 |
| 101 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it | 101 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it |
| 102 // won't be able to walk up the frame tree anymore. Clean up anything that | 102 // won't be able to walk up the frame tree anymore. Clean up anything that |
| 103 // needs to be done through the CrossProcessFrameConnector before it's gone. | 103 // needs to be done through the CrossProcessFrameConnector before it's gone. |
| 104 | 104 |
| 105 // Unlocks the mouse if this RenderWidgetHostView holds the lock. | 105 // Unlocks the mouse if this RenderWidgetHostView holds the lock. |
| 106 UnlockMouse(); | 106 UnlockMouse(); |
| 107 } | 107 } |
| 108 frame_connector_ = frame_connector; | 108 frame_connector_ = frame_connector; |
| 109 if (frame_connector_) { | 109 if (frame_connector_) { |
| 110 GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 110 GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 111 RenderWidgetHostViewBase* parent_view = | 111 RenderWidgetHostViewBase* parent_view = |
| 112 frame_connector_->GetParentRenderWidgetHostView(); | 112 frame_connector_->GetParentRenderWidgetHostView(); |
| 113 if (parent_view) { | 113 if (parent_view) { |
| 114 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); | 114 parent_frame_sink_id_ = parent_view->GetFrameSinkId(); |
| 115 DCHECK(!parent_frame_sink_id_.is_null()); | 115 DCHECK(parent_frame_sink_id_.is_valid()); |
| 116 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, | 116 GetSurfaceManager()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 117 frame_sink_id_); | 117 frame_sink_id_); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 void RenderWidgetHostViewChildFrame::InitAsChild( | 122 void RenderWidgetHostViewChildFrame::InitAsChild( |
| 123 gfx::NativeView parent_view) { | 123 gfx::NativeView parent_view) { |
| 124 NOTREACHED(); | 124 NOTREACHED(); |
| 125 } | 125 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 144 void RenderWidgetHostViewChildFrame::Focus() { | 144 void RenderWidgetHostViewChildFrame::Focus() { |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool RenderWidgetHostViewChildFrame::HasFocus() const { | 147 bool RenderWidgetHostViewChildFrame::HasFocus() const { |
| 148 if (frame_connector_) | 148 if (frame_connector_) |
| 149 return frame_connector_->HasFocus(); | 149 return frame_connector_->HasFocus(); |
| 150 return false; | 150 return false; |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { | 153 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { |
| 154 return !local_frame_id_.is_null(); | 154 return local_frame_id_.is_valid(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void RenderWidgetHostViewChildFrame::Show() { | 157 void RenderWidgetHostViewChildFrame::Show() { |
| 158 if (!host_->is_hidden()) | 158 if (!host_->is_hidden()) |
| 159 return; | 159 return; |
| 160 host_->WasShown(ui::LatencyInfo()); | 160 host_->WasShown(ui::LatencyInfo()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void RenderWidgetHostViewChildFrame::Hide() { | 163 void RenderWidgetHostViewChildFrame::Hide() { |
| 164 if (host_->is_hidden()) | 164 if (host_->is_hidden()) |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 ClearCompositorSurfaceIfNecessary(); | 393 ClearCompositorSurfaceIfNecessary(); |
| 394 // If the renderer changed its frame sink, reset the surface factory to | 394 // If the renderer changed its frame sink, reset the surface factory to |
| 395 // avoid returning stale resources. | 395 // avoid returning stale resources. |
| 396 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) | 396 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) |
| 397 surface_factory_->Reset(); | 397 surface_factory_->Reset(); |
| 398 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | 398 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 399 current_surface_size_ = frame_size; | 399 current_surface_size_ = frame_size; |
| 400 current_surface_scale_factor_ = scale_factor; | 400 current_surface_scale_factor_ = scale_factor; |
| 401 } | 401 } |
| 402 | 402 |
| 403 if (local_frame_id_.is_null()) { | 403 if (!local_frame_id_.is_valid()) { |
| 404 local_frame_id_ = id_allocator_->GenerateId(); | 404 local_frame_id_ = id_allocator_->GenerateId(); |
| 405 surface_factory_->Create(local_frame_id_); | 405 surface_factory_->Create(local_frame_id_); |
| 406 | 406 |
| 407 cc::SurfaceSequence sequence = | 407 cc::SurfaceSequence sequence = |
| 408 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 408 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
| 409 // The renderer process will satisfy this dependency when it creates a | 409 // The renderer process will satisfy this dependency when it creates a |
| 410 // SurfaceLayer. | 410 // SurfaceLayer. |
| 411 cc::SurfaceManager* manager = GetSurfaceManager(); | 411 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 412 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) | 412 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) |
| 413 ->AddDestructionDependency(sequence); | 413 ->AddDestructionDependency(sequence); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 524 |
| 525 return frame_connector_->TransformPointToRootCoordSpace( | 525 return frame_connector_->TransformPointToRootCoordSpace( |
| 526 point, cc::SurfaceId(frame_sink_id_, local_frame_id_)); | 526 point, cc::SurfaceId(frame_sink_id_, local_frame_id_)); |
| 527 } | 527 } |
| 528 | 528 |
| 529 bool RenderWidgetHostViewChildFrame::TransformPointToLocalCoordSpace( | 529 bool RenderWidgetHostViewChildFrame::TransformPointToLocalCoordSpace( |
| 530 const gfx::Point& point, | 530 const gfx::Point& point, |
| 531 const cc::SurfaceId& original_surface, | 531 const cc::SurfaceId& original_surface, |
| 532 gfx::Point* transformed_point) { | 532 gfx::Point* transformed_point) { |
| 533 *transformed_point = point; | 533 *transformed_point = point; |
| 534 if (!frame_connector_ || local_frame_id_.is_null()) | 534 if (!frame_connector_ || !local_frame_id_.is_valid()) |
| 535 return false; | 535 return false; |
| 536 | 536 |
| 537 return frame_connector_->TransformPointToLocalCoordSpace( | 537 return frame_connector_->TransformPointToLocalCoordSpace( |
| 538 point, original_surface, cc::SurfaceId(frame_sink_id_, local_frame_id_), | 538 point, original_surface, cc::SurfaceId(frame_sink_id_, local_frame_id_), |
| 539 transformed_point); | 539 transformed_point); |
| 540 } | 540 } |
| 541 | 541 |
| 542 bool RenderWidgetHostViewChildFrame::TransformPointToCoordSpaceForView( | 542 bool RenderWidgetHostViewChildFrame::TransformPointToCoordSpaceForView( |
| 543 const gfx::Point& point, | 543 const gfx::Point& point, |
| 544 RenderWidgetHostViewBase* target_view, | 544 RenderWidgetHostViewBase* target_view, |
| 545 gfx::Point* transformed_point) { | 545 gfx::Point* transformed_point) { |
| 546 if (!frame_connector_ || local_frame_id_.is_null() || target_view == this) | 546 if (!frame_connector_ || !local_frame_id_.is_valid() || target_view == this) |
| 547 return false; | 547 return false; |
| 548 | 548 |
| 549 return frame_connector_->TransformPointToCoordSpaceForView( | 549 return frame_connector_->TransformPointToCoordSpaceForView( |
| 550 point, target_view, cc::SurfaceId(frame_sink_id_, local_frame_id_), | 550 point, target_view, cc::SurfaceId(frame_sink_id_, local_frame_id_), |
| 551 transformed_point); | 551 transformed_point); |
| 552 } | 552 } |
| 553 | 553 |
| 554 bool RenderWidgetHostViewChildFrame::IsRenderWidgetHostViewChildFrame() { | 554 bool RenderWidgetHostViewChildFrame::IsRenderWidgetHostViewChildFrame() { |
| 555 return true; | 555 return true; |
| 556 } | 556 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 } | 719 } |
| 720 | 720 |
| 721 BrowserAccessibilityManager* | 721 BrowserAccessibilityManager* |
| 722 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( | 722 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( |
| 723 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { | 723 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { |
| 724 return BrowserAccessibilityManager::Create( | 724 return BrowserAccessibilityManager::Create( |
| 725 BrowserAccessibilityManager::GetEmptyDocument(), delegate); | 725 BrowserAccessibilityManager::GetEmptyDocument(), delegate); |
| 726 } | 726 } |
| 727 | 727 |
| 728 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { | 728 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { |
| 729 if (!local_frame_id_.is_null()) | 729 if (local_frame_id_.is_valid()) |
| 730 surface_factory_->Destroy(local_frame_id_); | 730 surface_factory_->Destroy(local_frame_id_); |
| 731 local_frame_id_ = cc::LocalFrameId(); | 731 local_frame_id_ = cc::LocalFrameId(); |
| 732 } | 732 } |
| 733 | 733 |
| 734 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { | 734 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { |
| 735 return true; | 735 return true; |
| 736 } | 736 } |
| 737 | 737 |
| 738 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { | 738 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { |
| 739 return cc::SurfaceId(frame_sink_id_, local_frame_id_); | 739 return cc::SurfaceId(frame_sink_id_, local_frame_id_); |
| 740 }; | 740 }; |
| 741 | 741 |
| 742 } // namespace content | 742 } // namespace content |
| OLD | NEW |