diff options
author | dtrainor <dtrainor@chromium.org> | 2015-12-09 18:17:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-10 02:18:26 +0000 |
commit | 9ff61e93d8cb701dfa8c9caffa8a4dd477e9c3ef (patch) | |
tree | 0afe7408d37a977f7aa3ef4cc893f4cfbb539e02 /blimp | |
parent | f129b16fb7efb7541b79a6f557fce6c5193f6310 (diff) | |
download | chromium_src-9ff61e93d8cb701dfa8c9caffa8a4dd477e9c3ef.zip chromium_src-9ff61e93d8cb701dfa8c9caffa8a4dd477e9c3ef.tar.gz chromium_src-9ff61e93d8cb701dfa8c9caffa8a4dd477e9c3ef.tar.bz2 |
Create a ControlFeature for Blimp
Add a basic ControlFeature class for blimp to allow for passing resize
messages to the engine.
BUG=
Review URL: https://codereview.chromium.org/1496013004
Cr-Commit-Position: refs/heads/master@{#364259}
Diffstat (limited to 'blimp')
25 files changed, 402 insertions, 35 deletions
diff --git a/blimp/client/BUILD.gn b/blimp/client/BUILD.gn index ac1e0ac..3858bd3 100644 --- a/blimp/client/BUILD.gn +++ b/blimp/client/BUILD.gn @@ -30,6 +30,8 @@ component("blimp_client") { "session/navigation_feature.h", "session/render_widget_feature.cc", "session/render_widget_feature.h", + "session/tab_control_feature.cc", + "session/tab_control_feature.h", ] defines = [ "BLIMP_CLIENT_IMPLEMENTATION=1" ] @@ -62,6 +64,7 @@ source_set("unit_tests") { sources = [ "session/navigation_feature_unittest.cc", "session/render_widget_feature_unittest.cc", + "session/tab_control_feature_unittest.cc", ] deps = [ @@ -105,6 +108,7 @@ if (is_android) { "android/java/src/org/chromium/blimp/BlimpLibraryLoader.java", "android/java/src/org/chromium/blimp/BlimpView.java", "android/java/src/org/chromium/blimp/session/BlimpClientSession.java", + "android/java/src/org/chromium/blimp/session/TabControlFeature.java", "android/java/src/org/chromium/blimp/toolbar/Toolbar.java", ] @@ -189,6 +193,7 @@ if (is_android) { "android/java/src/org/chromium/blimp/BlimpRendererActivity.java", "android/java/src/org/chromium/blimp/BlimpView.java", "android/java/src/org/chromium/blimp/session/BlimpClientSession.java", + "android/java/src/org/chromium/blimp/session/TabControlFeature.java", "android/java/src/org/chromium/blimp/toolbar/Toolbar.java", "android/java/src/org/chromium/blimp/toolbar/UrlBar.java", ] @@ -236,6 +241,8 @@ if (is_android) { "compositor/blimp_compositor_android.h", "session/blimp_client_session_android.cc", "session/blimp_client_session_android.h", + "session/tab_control_feature_android.cc", + "session/tab_control_feature_android.h", ] libs = [ "android" ] diff --git a/blimp/client/android/blimp_jni_registrar.cc b/blimp/client/android/blimp_jni_registrar.cc index 26f6b02..185a5f3 100644 --- a/blimp/client/android/blimp_jni_registrar.cc +++ b/blimp/client/android/blimp_jni_registrar.cc @@ -9,6 +9,7 @@ #include "blimp/client/android/blimp_view.h" #include "blimp/client/android/toolbar.h" #include "blimp/client/session/blimp_client_session_android.h" +#include "blimp/client/session/tab_control_feature_android.h" namespace { @@ -18,6 +19,7 @@ base::android::RegistrationMethod kBlimpRegistrationMethods[] = { {"BlimpView", blimp::BlimpView::RegisterJni}, {"BlimpClientSessionAndroid", blimp::BlimpClientSessionAndroid::RegisterJni}, + {"TabControlFeatureAndroid", blimp::TabControlFeatureAndroid::RegisterJni}, }; } // namespace diff --git a/blimp/client/android/blimp_view.cc b/blimp/client/android/blimp_view.cc index 6abbfcc..3fdbe26 100644 --- a/blimp/client/android/blimp_view.cc +++ b/blimp/client/android/blimp_view.cc @@ -14,7 +14,6 @@ namespace blimp { -// static static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj, const JavaParamRef<jobject>& blimp_client_session, diff --git a/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java b/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java index 0558b96..6641c39 100644 --- a/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java +++ b/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java @@ -14,6 +14,7 @@ import org.chromium.blimp.auth.RetryingTokenSource; import org.chromium.blimp.auth.TokenSource; import org.chromium.blimp.auth.TokenSourceImpl; import org.chromium.blimp.session.BlimpClientSession; +import org.chromium.blimp.session.TabControlFeature; import org.chromium.blimp.toolbar.Toolbar; import org.chromium.ui.widget.Toast; @@ -30,6 +31,7 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade private BlimpView mBlimpView; private Toolbar mToolbar; private BlimpClientSession mBlimpClientSession; + private TabControlFeature mTabControlFeature; @Override protected void onCreate(Bundle savedInstanceState) { @@ -50,6 +52,11 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade @Override protected void onDestroy() { + if (mTabControlFeature != null) { + mTabControlFeature.destroy(); + mTabControlFeature = null; + } + if (mBlimpView != null) { mBlimpView.destroyRenderer(); mBlimpView = null; @@ -115,6 +122,8 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.initialize(mBlimpClientSession); + + mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpView); } // TokenSource.Callback implementation. diff --git a/blimp/client/android/java/src/org/chromium/blimp/session/BlimpClientSession.java b/blimp/client/android/java/src/org/chromium/blimp/session/BlimpClientSession.java index 3501c5f..cc93680 100644 --- a/blimp/client/android/java/src/org/chromium/blimp/session/BlimpClientSession.java +++ b/blimp/client/android/java/src/org/chromium/blimp/session/BlimpClientSession.java @@ -24,10 +24,10 @@ public class BlimpClientSession { * Destroys the native BlimpClientSession. This class should not be used after this is called. */ public void destroy() { - if (mNativeBlimpClientSessionAndroidPtr != 0) { - nativeDestroy(mNativeBlimpClientSessionAndroidPtr); - mNativeBlimpClientSessionAndroidPtr = 0; - } + if (mNativeBlimpClientSessionAndroidPtr == 0) return; + + nativeDestroy(mNativeBlimpClientSessionAndroidPtr); + mNativeBlimpClientSessionAndroidPtr = 0; } // Methods that are called by native via JNI. diff --git a/blimp/client/android/java/src/org/chromium/blimp/session/TabControlFeature.java b/blimp/client/android/java/src/org/chromium/blimp/session/TabControlFeature.java new file mode 100644 index 0000000..d9847af --- /dev/null +++ b/blimp/client/android/java/src/org/chromium/blimp/session/TabControlFeature.java @@ -0,0 +1,72 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.blimp.session; + +import android.view.View; + +import org.chromium.base.annotations.JNINamespace; + +/** + * A Java representation of the native ControlFeature class. Provides easy access for Java control + * UI to interact with the native content-lite feature proxy and talk to the engine. + */ +@JNINamespace("blimp") +public class TabControlFeature implements View.OnLayoutChangeListener { + private final float mDpToPx; + + private View mContentAreaView; + private long mNativeTabControlFeatureAndroidPtr; + + /** + * Creates an instance of a {@link TabControlFeature}. This will register with + * {@code contentAreaView} as a {@link android.view.View.OnLayoutChangeListener} and will + * unregister when {@link #destroy()} is called. + * @param blimpClientSession The {@link BlimpClientSession} that contains the content-lite + * features required by the native components of the + * {@link TabControlFeature}. + * @param contentAreaView A {@link View} that represents the content area of the screen. + * This is used to notify the engine of the correct size of the web + * content area. + */ + public TabControlFeature(BlimpClientSession blimpClientSession, View contentAreaView) { + mContentAreaView = contentAreaView; + mDpToPx = mContentAreaView.getContext().getResources().getDisplayMetrics().density; + mNativeTabControlFeatureAndroidPtr = nativeInit(blimpClientSession); + + // Push down the current size of the content area view. + nativeOnContentAreaSizeChanged(mNativeTabControlFeatureAndroidPtr, + mContentAreaView.getWidth(), mContentAreaView.getHeight(), mDpToPx); + } + + /** + * Tears down the native counterpart to this class and unregisters any {@link View} listeners. + * This class should not be used after this. + */ + public void destroy() { + if (mContentAreaView != null) { + mContentAreaView.removeOnLayoutChangeListener(this); + mContentAreaView = null; + } + + if (mNativeTabControlFeatureAndroidPtr != 0) { + nativeDestroy(mNativeTabControlFeatureAndroidPtr); + mNativeTabControlFeatureAndroidPtr = 0; + } + } + + // View.OnLayoutChangeListener implementation. + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, + int oldLeft, int oldTop, int oldRight, int oldBottom) { + if (mNativeTabControlFeatureAndroidPtr == 0) return; + nativeOnContentAreaSizeChanged(mNativeTabControlFeatureAndroidPtr, right - left, + bottom - top, mDpToPx); + } + + private native long nativeInit(BlimpClientSession blimpClientSession); + private native void nativeDestroy(long nativeTabControlFeatureAndroid); + private native void nativeOnContentAreaSizeChanged( + long nativeTabControlFeatureAndroid, int width, int height, float dpToPx); +}
\ No newline at end of file diff --git a/blimp/client/android/toolbar.cc b/blimp/client/android/toolbar.cc index 2de3b93..abb6962 100644 --- a/blimp/client/android/toolbar.cc +++ b/blimp/client/android/toolbar.cc @@ -5,9 +5,7 @@ #include "blimp/client/android/toolbar.h" #include "base/android/jni_string.h" -#include "base/lazy_instance.h" #include "blimp/client/session/blimp_client_session_android.h" -#include "blimp/net/null_blimp_message_processor.h" #include "jni/Toolbar_jni.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/android/java_bitmap.h" @@ -21,7 +19,6 @@ const int kDummyTabId = 0; } // namespace -// static static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj, const JavaParamRef<jobject>& blimp_client_session) { diff --git a/blimp/client/compositor/blimp_compositor.cc b/blimp/client/compositor/blimp_compositor.cc index 87d6a95..cc3b557 100644 --- a/blimp/client/compositor/blimp_compositor.cc +++ b/blimp/client/compositor/blimp_compositor.cc @@ -19,8 +19,6 @@ #include "blimp/client/compositor/test/dummy_layer_driver.h" #include "blimp/client/session/render_widget_feature.h" #include "blimp/common/compositor/blimp_task_graph_runner.h" -#include "blimp/net/blimp_message_multiplexer.h" -#include "blimp/net/null_blimp_message_processor.h" #include "cc/layers/layer.h" #include "cc/layers/layer_settings.h" #include "cc/output/output_surface.h" diff --git a/blimp/client/session/blimp_client_session.cc b/blimp/client/session/blimp_client_session.cc index 1db97f7..f0fcd39 100644 --- a/blimp/client/session/blimp_client_session.cc +++ b/blimp/client/session/blimp_client_session.cc @@ -6,15 +6,20 @@ #include "blimp/client/session/navigation_feature.h" #include "blimp/client/session/render_widget_feature.h" +#include "blimp/client/session/tab_control_feature.h" #include "blimp/net/browser_connection_handler.h" namespace blimp { BlimpClientSession::BlimpClientSession() : connection_handler_(new BrowserConnectionHandler), + tab_control_feature_(new TabControlFeature), navigation_feature_(new NavigationFeature), render_widget_feature_(new RenderWidgetFeature) { // Connect the features with the network layer. + tab_control_feature_->set_outgoing_message_processor( + connection_handler_->RegisterFeature(BlimpMessage::CONTROL, + tab_control_feature_.get())); navigation_feature_->set_outgoing_message_processor( connection_handler_->RegisterFeature(BlimpMessage::NAVIGATION, navigation_feature_.get())); @@ -32,6 +37,10 @@ BlimpClientSession::BlimpClientSession() BlimpClientSession::~BlimpClientSession() {} +TabControlFeature* BlimpClientSession::GetTabControlFeature() const { + return tab_control_feature_.get(); +} + NavigationFeature* BlimpClientSession::GetNavigationFeature() const { return navigation_feature_.get(); } diff --git a/blimp/client/session/blimp_client_session.h b/blimp/client/session/blimp_client_session.h index 9aa2001..da8e74a 100644 --- a/blimp/client/session/blimp_client_session.h +++ b/blimp/client/session/blimp_client_session.h @@ -14,6 +14,7 @@ namespace blimp { class BrowserConnectionHandler; class NavigationFeature; class RenderWidgetFeature; +class TabControlFeature; // BlimpClientSession represents a single active session of Blimp on the client // regardless of whether or not the client application is in the background or @@ -27,6 +28,7 @@ class BLIMP_CLIENT_EXPORT BlimpClientSession { public: BlimpClientSession(); + TabControlFeature* GetTabControlFeature() const; NavigationFeature* GetNavigationFeature() const; RenderWidgetFeature* GetRenderWidgetFeature() const; @@ -38,6 +40,7 @@ class BLIMP_CLIENT_EXPORT BlimpClientSession { // glue the feature-specific handlers to the actual network connection. scoped_ptr<BrowserConnectionHandler> connection_handler_; + scoped_ptr<TabControlFeature> tab_control_feature_; scoped_ptr<NavigationFeature> navigation_feature_; scoped_ptr<RenderWidgetFeature> render_widget_feature_; diff --git a/blimp/client/session/render_widget_feature_unittest.cc b/blimp/client/session/render_widget_feature_unittest.cc index 2359a22..3e7752d 100644 --- a/blimp/client/session/render_widget_feature_unittest.cc +++ b/blimp/client/session/render_widget_feature_unittest.cc @@ -17,10 +17,6 @@ #include "testing/gtest/include/gtest/gtest.h" using testing::_; -using testing::InvokeArgument; -using testing::Ref; -using testing::Return; -using testing::SaveArg; namespace blimp { diff --git a/blimp/client/session/tab_control_feature.cc b/blimp/client/session/tab_control_feature.cc new file mode 100644 index 0000000..15cbdd1 --- /dev/null +++ b/blimp/client/session/tab_control_feature.cc @@ -0,0 +1,45 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "blimp/client/session/tab_control_feature.h" + +#include "blimp/common/create_blimp_message.h" +#include "blimp/common/proto/blimp_message.pb.h" +#include "blimp/common/proto/control.pb.h" +#include "blimp/common/proto/size.pb.h" +#include "blimp/net/blimp_message_processor.h" +#include "ui/gfx/geometry/size.h" + +namespace blimp { + +TabControlFeature::TabControlFeature() {} + +TabControlFeature::~TabControlFeature() {} + +void TabControlFeature::set_outgoing_message_processor( + scoped_ptr<BlimpMessageProcessor> processor) { + outgoing_message_processor_ = std::move(processor); +} + +void TabControlFeature::SetSizeAndScale(const gfx::Size& size, + float device_pixel_ratio) { + SizeMessage* size_details; + scoped_ptr<BlimpMessage> message = CreateBlimpMessage(&size_details); + size_details->set_width(size.width()); + size_details->set_height(size.height()); + size_details->set_device_pixel_ratio(device_pixel_ratio); + + // TODO(dtrainor): Don't keep sending size events to the server. Wait for a + // CompletionCallback to return before sending future size updates. + outgoing_message_processor_->ProcessMessage(std::move(message), + net::CompletionCallback()); +} + +void TabControlFeature::ProcessMessage( + scoped_ptr<BlimpMessage> message, + const net::CompletionCallback& callback) { + NOTIMPLEMENTED(); +} + +} // namespace blimp diff --git a/blimp/client/session/tab_control_feature.h b/blimp/client/session/tab_control_feature.h new file mode 100644 index 0000000..166dec7 --- /dev/null +++ b/blimp/client/session/tab_control_feature.h @@ -0,0 +1,46 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BLIMP_CLIENT_SESSION_TAB_CONTROL_FEATURE_H_ +#define BLIMP_CLIENT_SESSION_TAB_CONTROL_FEATURE_H_ + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "blimp/client/blimp_client_export.h" +#include "blimp/net/blimp_message_processor.h" + +namespace gfx { +class Size; +} + +namespace blimp { + +class BLIMP_CLIENT_EXPORT TabControlFeature : public BlimpMessageProcessor { + public: + TabControlFeature(); + ~TabControlFeature() override; + + // Set the BlimpMessageProcessor that will be used to send + // BlimpMessage::CONTROL messages to the engine. + void set_outgoing_message_processor( + scoped_ptr<BlimpMessageProcessor> processor); + + // Pushes the current size and scale information to the engine, which will + // affect the web content display area for all tabs. + void SetSizeAndScale(const gfx::Size& size, float device_pixel_ratio); + + private: + // BlimpMessageProcessor implementation. + void ProcessMessage(scoped_ptr<BlimpMessage> message, + const net::CompletionCallback& callback) override; + + // Used to send BlimpMessage::CONTROL messages to the engine. + scoped_ptr<BlimpMessageProcessor> outgoing_message_processor_; + + DISALLOW_COPY_AND_ASSIGN(TabControlFeature); +}; + +} // namespace blimp + +#endif // BLIMP_CLIENT_SESSION_TAB_CONTROL_FEATURE_H_ diff --git a/blimp/client/session/tab_control_feature_android.cc b/blimp/client/session/tab_control_feature_android.cc new file mode 100644 index 0000000..20da386 --- /dev/null +++ b/blimp/client/session/tab_control_feature_android.cc @@ -0,0 +1,54 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "blimp/client/session/tab_control_feature_android.h" + +#include "blimp/client/session/blimp_client_session_android.h" +#include "blimp/client/session/tab_control_feature.h" +#include "jni/TabControlFeature_jni.h" +#include "ui/gfx/geometry/size.h" + +namespace blimp { + +static jlong Init(JNIEnv* env, + const JavaParamRef<jobject>& jobj, + const JavaParamRef<jobject>& blimp_client_session) { + BlimpClientSession* client_session = + BlimpClientSessionAndroid::FromJavaObject(env, + blimp_client_session.obj()); + + return reinterpret_cast<intptr_t>( + new TabControlFeatureAndroid(env, + jobj, + client_session->GetTabControlFeature())); +} + +// static +bool TabControlFeatureAndroid::RegisterJni(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +TabControlFeatureAndroid::TabControlFeatureAndroid( + JNIEnv* env, + const base::android::JavaParamRef<jobject>& jobj, + TabControlFeature* tab_control_feature) + : tab_control_feature_(tab_control_feature) { + java_obj_.Reset(env, jobj); +} + +TabControlFeatureAndroid::~TabControlFeatureAndroid() {} + +void TabControlFeatureAndroid::Destroy(JNIEnv* env, jobject jobj) { + delete this; +} + +void TabControlFeatureAndroid::OnContentAreaSizeChanged(JNIEnv* env, + jobject jobj, + jint width, + jint height, + jfloat dp_to_px) { + tab_control_feature_->SetSizeAndScale(gfx::Size(width, height), dp_to_px); +} + +} // namespace blimp diff --git a/blimp/client/session/tab_control_feature_android.h b/blimp/client/session/tab_control_feature_android.h new file mode 100644 index 0000000..81aa6c5 --- /dev/null +++ b/blimp/client/session/tab_control_feature_android.h @@ -0,0 +1,44 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BLIMP_CLIENT_SESSION_TAB_CONTROL_FEATURE_ANDROID_H_ +#define BLIMP_CLIENT_SESSION_TAB_CONTROL_FEATURE_ANDROID_H_ + +#include "base/android/jni_android.h" +#include "base/macros.h" + +namespace blimp { + +class TabControlFeature; + +class TabControlFeatureAndroid { + public: + static bool RegisterJni(JNIEnv* env); + + TabControlFeatureAndroid(JNIEnv* env, + const base::android::JavaParamRef<jobject>& jobj, + TabControlFeature* tab_control_feature); + + // Methods called from Java via JNI. + void Destroy(JNIEnv* env, jobject jobj); + void OnContentAreaSizeChanged(JNIEnv* env, + jobject jobj, + jint width, + jint height, + jfloat dp_to_px); + + private: + virtual ~TabControlFeatureAndroid(); + + TabControlFeature* tab_control_feature_; + + // Reference to the Java object which owns this class. + base::android::ScopedJavaGlobalRef<jobject> java_obj_; + + DISALLOW_COPY_AND_ASSIGN(TabControlFeatureAndroid); +}; + +} // namespace blimp + +#endif // BLIMP_CLIENT_SESSION_TAB_CONTROL_FEATURE_ANDROID_H_ diff --git a/blimp/client/session/tab_control_feature_unittest.cc b/blimp/client/session/tab_control_feature_unittest.cc new file mode 100644 index 0000000..d53bd97 --- /dev/null +++ b/blimp/client/session/tab_control_feature_unittest.cc @@ -0,0 +1,57 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "blimp/client/session/tab_control_feature.h" + +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "blimp/common/proto/blimp_message.pb.h" +#include "blimp/common/proto/control.pb.h" +#include "blimp/common/proto/size.pb.h" +#include "blimp/net/test_common.h" +#include "net/base/net_errors.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/geometry/size.h" + +using testing::_; + +namespace blimp { + +MATCHER_P3(EqualsSizeMessage, width, height, dp_to_px, "") { + return arg.control().type() == ControlMessage::SIZE && + arg.control().size().width() == width && + arg.control().size().height() == height && + arg.control().size().device_pixel_ratio() == dp_to_px; +} + +class TabControlFeatureTest : public testing::Test { + public: + TabControlFeatureTest() : out_processor_(nullptr) {} + + void SetUp() override { + out_processor_ = new MockBlimpMessageProcessor(); + feature_.set_outgoing_message_processor(make_scoped_ptr(out_processor_)); + } + + protected: + // This is a raw pointer to a class that is owned by the ControlFeature. + MockBlimpMessageProcessor* out_processor_; + + TabControlFeature feature_; +}; + +TEST_F(TabControlFeatureTest, CreatesCorrectSizeMessage) { + uint64_t width = 10; + uint64_t height = 15; + float dp_to_px = 1.23f; + + EXPECT_CALL( + *out_processor_, + MockableProcessMessage(EqualsSizeMessage(width, height, dp_to_px), _)) + .Times(1); + feature_.SetSizeAndScale(gfx::Size(width, height), 1.23f); +} + +} // namespace blimp diff --git a/blimp/common/create_blimp_message.cc b/blimp/common/create_blimp_message.cc index 6697fe0..e4f953a 100644 --- a/blimp/common/create_blimp_message.cc +++ b/blimp/common/create_blimp_message.cc @@ -8,8 +8,10 @@ #include "base/memory/scoped_ptr.h" #include "blimp/common/proto/blimp_message.pb.h" #include "blimp/common/proto/compositor.pb.h" +#include "blimp/common/proto/control.pb.h" #include "blimp/common/proto/input.pb.h" #include "blimp/common/proto/render_widget.pb.h" +#include "blimp/common/proto/size.pb.h" namespace blimp { @@ -62,6 +64,15 @@ scoped_ptr<BlimpMessage> CreateBlimpMessage( return output; } +scoped_ptr<BlimpMessage> CreateBlimpMessage(SizeMessage** size_message) { + DCHECK(size_message); + ControlMessage* control_message; + scoped_ptr<BlimpMessage> output = CreateBlimpMessage(&control_message); + control_message->set_type(ControlMessage::SIZE); + *size_message = control_message->mutable_size(); + return output; +} + scoped_ptr<BlimpMessage> CreateStartConnectionMessage( const std::string& client_token, int protocol_version) { diff --git a/blimp/common/create_blimp_message.h b/blimp/common/create_blimp_message.h index 22a508f..c6ac4db 100644 --- a/blimp/common/create_blimp_message.h +++ b/blimp/common/create_blimp_message.h @@ -18,6 +18,7 @@ class ControlMessage; class InputMessage; class NavigationMessage; class RenderWidgetMessage; +class SizeMessage; class StartConnectionMessage; // Suite of helper methods to simplify the repetitive task of creating @@ -50,6 +51,9 @@ BLIMP_COMMON_EXPORT scoped_ptr<BlimpMessage> CreateBlimpMessage( RenderWidgetMessage** render_widget_message, int target_tab_id); +BLIMP_COMMON_EXPORT scoped_ptr<BlimpMessage> CreateBlimpMessage( + SizeMessage** size_message); + BLIMP_COMMON_EXPORT scoped_ptr<BlimpMessage> CreateStartConnectionMessage( const std::string& client_token, int protocol_version); diff --git a/blimp/common/create_blimp_message_unittest.cc b/blimp/common/create_blimp_message_unittest.cc index 8414ed5..0c1760d 100644 --- a/blimp/common/create_blimp_message_unittest.cc +++ b/blimp/common/create_blimp_message_unittest.cc @@ -9,6 +9,7 @@ #include "blimp/common/proto/input.pb.h" #include "blimp/common/proto/navigation.pb.h" #include "blimp/common/proto/render_widget.pb.h" +#include "blimp/common/proto/size.pb.h" #include "testing/gtest/include/gtest/gtest.h" namespace blimp { @@ -59,6 +60,15 @@ TEST(CreateBlimpMessageTest, RenderWidgetMessage) { EXPECT_EQ(kTabId, message->target_tab_id()); } +TEST(CreateBlimpMessageTest, SizeMessage) { + SizeMessage* details = nullptr; + scoped_ptr<BlimpMessage> message = CreateBlimpMessage(&details); + EXPECT_NE(nullptr, details); + EXPECT_NE(nullptr, message); + EXPECT_EQ(ControlMessage::SIZE, message->mutable_control()->type()); + EXPECT_EQ(details, message->mutable_control()->mutable_size()); +} + TEST(CreateBlimpMessageTest, StartConnectionMessage) { const char* client_token = "token"; const int protocol_version = 1; diff --git a/blimp/common/proto/control.proto b/blimp/common/proto/control.proto index 1a909b6..8d29789 100644 --- a/blimp/common/proto/control.proto +++ b/blimp/common/proto/control.proto @@ -28,5 +28,6 @@ message ControlMessage { // Feature-specific messages follow. // Only one of these fields may be set per ControlMessage. - optional SizeMessage resize = 1000; + // TODO(kmarshall): use a 'oneof' union when it's supported in Chromium. + optional SizeMessage size = 1000; } diff --git a/blimp/common/proto/size.proto b/blimp/common/proto/size.proto index f6ba801..fc59b2d 100644 --- a/blimp/common/proto/size.proto +++ b/blimp/common/proto/size.proto @@ -13,5 +13,6 @@ package blimp; message SizeMessage { optional uint64 width = 1; optional uint64 height = 2; + optional float device_pixel_ratio = 3; } diff --git a/blimp/engine/browser/blimp_engine_session.cc b/blimp/engine/browser/blimp_engine_session.cc index aba826c..aa17d29a 100644 --- a/blimp/engine/browser/blimp_engine_session.cc +++ b/blimp/engine/browser/blimp_engine_session.cc @@ -41,6 +41,9 @@ namespace engine { namespace { const int kDummyTabId = 0; +const float kDefaultScaleFactor = 1.f; +const int kDefaultDisplayWidth = 800; +const int kDefaultDisplayHeight = 600; base::LazyInstance<blimp::NullBlimpMessageProcessor> g_blimp_message_processor = LAZY_INSTANCE_INITIALIZER; @@ -68,6 +71,9 @@ BlimpEngineSession::BlimpEngineSession( // TODO(dtrainor, haibinlu): Properly pull these from the BlimpMessageMux. render_widget_processor_(g_blimp_message_processor.Pointer(), g_blimp_message_processor.Pointer()) { + screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, + gfx::Size(kDefaultDisplayWidth, + kDefaultDisplayHeight)); render_widget_processor_.SetDelegate(kDummyTabId, this); } @@ -121,9 +127,13 @@ void BlimpEngineSession::CloseWebContents(const int target_tab_id) { web_contents_->Close(); } -void BlimpEngineSession::HandleResize(const gfx::Size& size) { - // TODO(dtrainor, haibinlu): Set the proper size on the WebContents/save for - // future WebContents objects. +void BlimpEngineSession::HandleResize(float device_pixel_ratio, + const gfx::Size& size) { + screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); + if (web_contents_ && web_contents_->GetRenderViewHost() && + web_contents_->GetRenderViewHost()->GetWidget()) { + web_contents_->GetRenderViewHost()->GetWidget()->WasResized(); + } } void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { @@ -198,8 +208,9 @@ void BlimpEngineSession::ProcessMessage( case ControlMessage::CLOSE_TAB: CloseWebContents(message->target_tab_id()); case ControlMessage::SIZE: - HandleResize(gfx::Size(message->control().resize().width(), - message->control().resize().height())); + HandleResize(message->control().size().device_pixel_ratio(), + gfx::Size(message->control().size().width(), + message->control().size().height())); break; default: NOTIMPLEMENTED(); diff --git a/blimp/engine/browser/blimp_engine_session.h b/blimp/engine/browser/blimp_engine_session.h index e834fe3..61f772b 100644 --- a/blimp/engine/browser/blimp_engine_session.h +++ b/blimp/engine/browser/blimp_engine_session.h @@ -74,7 +74,7 @@ class BlimpEngineSession // Creates a new WebContents, which will be indexed by |target_tab_id|. void CreateWebContents(const int target_tab_id); void CloseWebContents(const int target_tab_id); - void HandleResize(const gfx::Size& size); + void HandleResize(float device_pixel_ratio, const gfx::Size& size); // NavigationMessage handler methods. // Navigates the target tab to the |url|. diff --git a/blimp/engine/ui/blimp_screen.cc b/blimp/engine/ui/blimp_screen.cc index 0282967..0e38138 100644 --- a/blimp/engine/ui/blimp_screen.cc +++ b/blimp/engine/ui/blimp_screen.cc @@ -10,23 +10,17 @@ namespace engine { namespace { const int64 kDisplayId = 1; -const float kDefaultScale = 1.0f; const int kNumDisplays = 1; } // namespace -const int BlimpScreen::kDefaultDisplayWidth = 800; -const int BlimpScreen::kDefaultDisplayHeight = 600; - -BlimpScreen::BlimpScreen() : display_(kDisplayId) { - display_.SetScaleAndBounds( - kDefaultScale, gfx::Rect(kDefaultDisplayWidth, kDefaultDisplayHeight)); -} +BlimpScreen::BlimpScreen() : display_(kDisplayId) {} BlimpScreen::~BlimpScreen() {} -void BlimpScreen::UpdateDisplaySize(const gfx::Size& size) { - display_.SetScaleAndBounds(kDefaultScale, gfx::Rect(size)); +void BlimpScreen::UpdateDisplayScaleAndSize(float scale, + const gfx::Size& size) { + display_.SetScaleAndBounds(scale, gfx::Rect(size)); } gfx::Point BlimpScreen::GetCursorScreenPoint() { diff --git a/blimp/engine/ui/blimp_screen.h b/blimp/engine/ui/blimp_screen.h index 7901780..0e2e550 100644 --- a/blimp/engine/ui/blimp_screen.h +++ b/blimp/engine/ui/blimp_screen.h @@ -21,7 +21,7 @@ class BlimpScreen : public gfx::Screen { ~BlimpScreen() override; // Updates the size reported by the primary display. - void UpdateDisplaySize(const gfx::Size& size); + void UpdateDisplayScaleAndSize(float scale, const gfx::Size& size); // gfx::Screen implementation. gfx::Point GetCursorScreenPoint() override; @@ -36,9 +36,6 @@ class BlimpScreen : public gfx::Screen { void AddObserver(gfx::DisplayObserver* observer) override; void RemoveObserver(gfx::DisplayObserver* observer) override; - static const int kDefaultDisplayWidth; - static const int kDefaultDisplayHeight; - private: gfx::Display display_; |