OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/client/core/contents/blimp_contents_impl.h" | 5 #include "blimp/client/core/contents/blimp_contents_impl.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/supports_user_data.h" | 8 #include "base/supports_user_data.h" |
| 9 #include "blimp/client/core/compositor/compositor_deps_provider.h" |
| 10 #include "blimp/client/core/render_widget/blimp_render_widget.h" |
9 #include "blimp/client/public/contents/blimp_contents_observer.h" | 11 #include "blimp/client/public/contents/blimp_contents_observer.h" |
| 12 #include "cc/proto/compositor_message.pb.h" |
10 | 13 |
11 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
12 #include "blimp/client/core/contents/android/blimp_contents_impl_android.h" | 15 #include "blimp/client/core/contents/android/blimp_contents_impl_android.h" |
13 #endif // OS_ANDROID | 16 #endif // OS_ANDROID |
14 | 17 |
15 namespace blimp { | 18 namespace blimp { |
16 namespace client { | 19 namespace client { |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
| 23 const int kDummyTabId = 0; |
| 24 |
20 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
21 const char kBlimpContentsImplAndroidKey[] = "blimp_contents_impl_android"; | 26 const char kBlimpContentsImplAndroidKey[] = "blimp_contents_impl_android"; |
22 #endif // OS_ANDROID | 27 #endif // OS_ANDROID |
23 } | 28 } |
24 | 29 |
25 BlimpContentsImpl::BlimpContentsImpl(int id) | 30 BlimpContentsImpl::BlimpContentsImpl( |
26 : navigation_controller_(this, nullptr), id_(id) {} | 31 int id, |
| 32 CompositorDepsProvider* compositor_deps_provider, |
| 33 RenderWidgetFeature* render_widget_feature) |
| 34 : id_(id), |
| 35 compositor_deps_provider_(compositor_deps_provider), |
| 36 render_widget_feature_(render_widget_feature), |
| 37 visible_(false), |
| 38 window_(gfx::kNullAcceleratedWidget), |
| 39 active_widget_(nullptr), |
| 40 navigation_controller_(this, nullptr) { |
| 41 render_widget_feature_->SetDelegate(kDummyTabId, this); |
| 42 } |
27 | 43 |
28 BlimpContentsImpl::~BlimpContentsImpl() { | 44 BlimpContentsImpl::~BlimpContentsImpl() { |
| 45 // Drop any references to the |window_| |
| 46 if (active_widget_) |
| 47 active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 48 window_ = gfx::kNullAcceleratedWidget; |
| 49 |
29 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, BlimpContentsDying()); | 50 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, BlimpContentsDying()); |
30 } | 51 } |
31 | 52 |
32 #if defined(OS_ANDROID) | 53 #if defined(OS_ANDROID) |
33 | 54 |
34 base::android::ScopedJavaLocalRef<jobject> | 55 base::android::ScopedJavaLocalRef<jobject> |
35 BlimpContentsImpl::GetJavaBlimpContentsImpl() { | 56 BlimpContentsImpl::GetJavaBlimpContentsImpl() { |
36 return GetBlimpContentsImplAndroid()->GetJavaObject(); | 57 return GetBlimpContentsImplAndroid()->GetJavaObject(); |
37 } | 58 } |
38 | 59 |
(...skipping 24 matching lines...) Expand all Loading... |
63 | 84 |
64 bool BlimpContentsImpl::HasObserver(BlimpContentsObserver* observer) { | 85 bool BlimpContentsImpl::HasObserver(BlimpContentsObserver* observer) { |
65 return observers_.HasObserver(observer); | 86 return observers_.HasObserver(observer); |
66 } | 87 } |
67 | 88 |
68 void BlimpContentsImpl::OnNavigationStateChanged() { | 89 void BlimpContentsImpl::OnNavigationStateChanged() { |
69 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, | 90 FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, |
70 OnNavigationStateChanged()); | 91 OnNavigationStateChanged()); |
71 } | 92 } |
72 | 93 |
| 94 void BlimpContentsImpl::SetVisible(bool visible) { |
| 95 visible_ = visible; |
| 96 if (active_widget_) |
| 97 active_widget_->SetVisible(visible); |
| 98 } |
| 99 |
| 100 void BlimpContentsImpl::SetAcceleratedWidget(gfx::AcceleratedWidget widget) { |
| 101 DCHECK(compositor_deps_provider_->use_direct_rendering()); |
| 102 |
| 103 // Drop any references to the current |window_| first. |
| 104 if (active_widget_) |
| 105 active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 106 |
| 107 window_ = widget; |
| 108 |
| 109 if (active_widget_) |
| 110 active_widget_->SetAcceleratedWidget(window_); |
| 111 } |
| 112 |
| 113 BlimpRenderWidget* BlimpContentsImpl::GetActiveWidget() const { |
| 114 return active_widget_; |
| 115 } |
| 116 |
| 117 void BlimpContentsImpl::SendWebGestureEvent( |
| 118 BlimpRenderWidget* render_widget, |
| 119 const blink::WebGestureEvent& gesture_event) { |
| 120 render_widget_feature_->SendWebGestureEvent( |
| 121 kDummyTabId, render_widget->GetId(), gesture_event); |
| 122 } |
| 123 |
| 124 void BlimpContentsImpl::SendCompositorMessage( |
| 125 BlimpRenderWidget* render_widget, |
| 126 const cc::proto::CompositorMessage& message) { |
| 127 render_widget_feature_->SendCompositorMessage( |
| 128 kDummyTabId, render_widget->GetId(), message); |
| 129 } |
| 130 |
| 131 void BlimpContentsImpl::CompositorDidCompleteSwapBuffers() { |
| 132 if (!did_complete_swap_buffers_.is_null()) |
| 133 did_complete_swap_buffers_.Run(); |
| 134 } |
| 135 |
| 136 BlimpRenderWidget* BlimpContentsImpl::GetWidgetForId(int render_widget_id) { |
| 137 RenderWidgetMap::const_iterator it = render_widgets_.find(render_widget_id); |
| 138 if (it == render_widgets_.end()) |
| 139 return nullptr; |
| 140 return it->second.get(); |
| 141 } |
| 142 |
| 143 std::unique_ptr<BlimpRenderWidget> BlimpContentsImpl::CreateBlimpRenderWidget( |
| 144 int32_t render_widget_id, |
| 145 CompositorDepsProvider* compositor_deps_provider, |
| 146 BlimpRenderWidgetDelegate* delegate) { |
| 147 return base::MakeUnique<BlimpRenderWidget>( |
| 148 render_widget_id, compositor_deps_provider, delegate); |
| 149 } |
| 150 |
| 151 void BlimpContentsImpl::OnRenderWidgetCreated(int render_widget_id) { |
| 152 CHECK(!GetWidgetForId(render_widget_id)); |
| 153 |
| 154 render_widgets_[render_widget_id] = CreateBlimpRenderWidget( |
| 155 render_widget_id, compositor_deps_provider_, this); |
| 156 } |
| 157 |
| 158 void BlimpContentsImpl::OnRenderWidgetInitialized(int render_widget_id) { |
| 159 if (active_widget_ && active_widget_->GetId() == render_widget_id) |
| 160 return; |
| 161 |
| 162 if (active_widget_) { |
| 163 VLOG(1) << "Hiding currently active compositor for render widget: " |
| 164 << active_widget_->GetId(); |
| 165 active_widget_->SetVisible(false); |
| 166 if (compositor_deps_provider_->use_direct_rendering()) |
| 167 active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 168 } |
| 169 |
| 170 active_widget_ = GetWidgetForId(render_widget_id); |
| 171 CHECK(active_widget_); |
| 172 |
| 173 active_widget_->SetVisible(visible_); |
| 174 if (compositor_deps_provider_->use_direct_rendering()) |
| 175 active_widget_->SetAcceleratedWidget(window_); |
| 176 } |
| 177 |
| 178 void BlimpContentsImpl::OnRenderWidgetDeleted(int render_widget_id) { |
| 179 RenderWidgetMap::const_iterator it = render_widgets_.find(render_widget_id); |
| 180 CHECK(it != render_widgets_.end()); |
| 181 |
| 182 // Reset the |active_widget_| if that is what we're destroying right now. |
| 183 if (active_widget_ == it->second.get()) |
| 184 active_widget_ = nullptr; |
| 185 |
| 186 render_widgets_.erase(it); |
| 187 } |
| 188 |
| 189 void BlimpContentsImpl::OnCompositorMessageReceived( |
| 190 int render_widget_id, |
| 191 std::unique_ptr<cc::proto::CompositorMessage> message) { |
| 192 BlimpRenderWidget* render_widget = GetWidgetForId(render_widget_id); |
| 193 CHECK(render_widget); |
| 194 |
| 195 render_widget->OnCompositorMessageReceived(std::move(message)); |
| 196 } |
| 197 |
73 } // namespace client | 198 } // namespace client |
74 } // namespace blimp | 199 } // namespace blimp |
OLD | NEW |