Chromium Code Reviews| Index: blimp/client/core/contents/blimp_contents_impl.cc |
| diff --git a/blimp/client/core/contents/blimp_contents_impl.cc b/blimp/client/core/contents/blimp_contents_impl.cc |
| index bfbbca356113bdd5f4e70743840be803cef4daf0..8845b5861fdb1249d6fd52df556434cb1a392f99 100644 |
| --- a/blimp/client/core/contents/blimp_contents_impl.cc |
| +++ b/blimp/client/core/contents/blimp_contents_impl.cc |
| @@ -6,7 +6,10 @@ |
| #include "base/memory/ptr_util.h" |
| #include "base/supports_user_data.h" |
| +#include "blimp/client/core/compositor/compositor_deps_provider.h" |
| +#include "blimp/client/core/render_widget/blimp_render_widget.h" |
| #include "blimp/client/public/contents/blimp_contents_observer.h" |
| +#include "cc/proto/compositor_message.pb.h" |
| #if defined(OS_ANDROID) |
| #include "blimp/client/core/contents/android/blimp_contents_impl_android.h" |
| @@ -17,15 +20,33 @@ namespace client { |
| namespace { |
| +const int kDummyTabId = 0; |
| + |
| #if defined(OS_ANDROID) |
| const char kBlimpContentsImplAndroidKey[] = "blimp_contents_impl_android"; |
| #endif // OS_ANDROID |
| } |
| -BlimpContentsImpl::BlimpContentsImpl(int id) |
| - : navigation_controller_(this, nullptr), id_(id) {} |
| +BlimpContentsImpl::BlimpContentsImpl( |
| + int id, |
| + CompositorDepsProvider* compositor_deps_provider, |
| + RenderWidgetFeature* render_widget_feature) |
| + : id_(id), |
| + compositor_deps_provider_(compositor_deps_provider), |
| + render_widget_feature_(render_widget_feature), |
| + visible_(false), |
| + window_(gfx::kNullAcceleratedWidget), |
| + active_widget_(nullptr), |
| + navigation_controller_(this, nullptr) { |
| + render_widget_feature_->SetDelegate(kDummyTabId, this); |
| +} |
| BlimpContentsImpl::~BlimpContentsImpl() { |
| + // Drop any references to the |window_| |
| + if (active_widget_) |
|
nyquist
2016/08/16 23:14:57
all the curlies
Khushal
2016/08/18 02:01:46
Done.
|
| + active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| + window_ = gfx::kNullAcceleratedWidget; |
| + |
| FOR_EACH_OBSERVER(BlimpContentsObserver, observers_, BlimpContentsDying()); |
| } |
| @@ -70,5 +91,109 @@ void BlimpContentsImpl::OnNavigationStateChanged() { |
| OnNavigationStateChanged()); |
| } |
| +void BlimpContentsImpl::SetVisible(bool visible) { |
| + visible_ = visible; |
| + if (active_widget_) |
| + active_widget_->SetVisible(visible); |
| +} |
| + |
| +void BlimpContentsImpl::SetAcceleratedWidget(gfx::AcceleratedWidget widget) { |
| + DCHECK(compositor_deps_provider_->use_internal_display()); |
| + |
| + // Drop any references to the current |window_| first. |
| + if (active_widget_) |
| + active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| + |
| + window_ = widget; |
| + |
| + if (active_widget_) |
| + active_widget_->SetAcceleratedWidget(window_); |
| +} |
| + |
| +BlimpRenderWidget* BlimpContentsImpl::GetActiveWidget() const { |
| + return active_widget_; |
| +} |
| + |
| +void BlimpContentsImpl::SendWebGestureEvent( |
| + BlimpRenderWidget* render_widget, |
| + const blink::WebGestureEvent& gesture_event) { |
| + render_widget_feature_->SendWebGestureEvent( |
| + kDummyTabId, render_widget->GetId(), gesture_event); |
| +} |
| + |
| +void BlimpContentsImpl::SendCompositorMessage( |
| + BlimpRenderWidget* render_widget, |
| + const cc::proto::CompositorMessage& message) { |
| + render_widget_feature_->SendCompositorMessage( |
| + kDummyTabId, render_widget->GetId(), message); |
| +} |
| + |
| +void BlimpContentsImpl::CompositorDidCompleteSwapBuffers() { |
| + if (!did_complete_swap_buffers_.is_null()) |
| + did_complete_swap_buffers_.Run(); |
| +} |
| + |
| +BlimpRenderWidget* BlimpContentsImpl::GetWidgetForId(int render_widget_id) { |
| + RenderWidgetMap::const_iterator it = render_widgets_.find(render_widget_id); |
| + if (it == render_widgets_.end()) |
| + return nullptr; |
| + return it->second.get(); |
| +} |
| + |
| +std::unique_ptr<BlimpRenderWidget> BlimpContentsImpl::CreateBlimpRenderWidget( |
| + int32_t render_widget_id, |
| + CompositorDepsProvider* compositor_deps_provider, |
| + BlimpRenderWidgetDelegate* delegate) { |
| + return base::MakeUnique<BlimpRenderWidget>( |
| + render_widget_id, compositor_deps_provider, delegate); |
| +} |
| + |
| +void BlimpContentsImpl::OnRenderWidgetCreated(int render_widget_id) { |
| + CHECK(!GetWidgetForId(render_widget_id)); |
| + |
| + render_widgets_[render_widget_id] = CreateBlimpRenderWidget( |
| + render_widget_id, compositor_deps_provider_, this); |
| +} |
| + |
| +void BlimpContentsImpl::OnRenderWidgetInitialized(int render_widget_id) { |
| + if (active_widget_ && active_widget_->GetId() == render_widget_id) |
| + return; |
| + |
| + if (active_widget_) { |
| + VLOG(1) << "Hiding currently active compositor for render widget: " |
| + << active_widget_->GetId(); |
| + active_widget_->SetVisible(false); |
| + if (compositor_deps_provider_->use_internal_display()) |
| + active_widget_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| + } |
| + |
| + active_widget_ = GetWidgetForId(render_widget_id); |
| + CHECK(active_widget_); |
| + |
| + active_widget_->SetVisible(visible_); |
| + if (compositor_deps_provider_->use_internal_display()) |
| + active_widget_->SetAcceleratedWidget(window_); |
| +} |
| + |
| +void BlimpContentsImpl::OnRenderWidgetDeleted(int render_widget_id) { |
| + RenderWidgetMap::const_iterator it = render_widgets_.find(render_widget_id); |
| + CHECK(it != render_widgets_.end()); |
| + |
| + // Reset the |active_widget_| if that is what we're destroying right now. |
| + if (active_widget_ == it->second.get()) |
| + active_widget_ = nullptr; |
| + |
| + render_widgets_.erase(it); |
| +} |
| + |
| +void BlimpContentsImpl::OnCompositorMessageReceived( |
| + int render_widget_id, |
| + std::unique_ptr<cc::proto::CompositorMessage> message) { |
| + BlimpRenderWidget* render_widget = GetWidgetForId(render_widget_id); |
| + CHECK(render_widget); |
| + |
| + render_widget->OnCompositorMessageReceived(std::move(message)); |
| +} |
| + |
| } // namespace client |
| } // namespace blimp |