summaryrefslogtreecommitdiffstats
path: root/blimp
diff options
context:
space:
mode:
authordtrainor <dtrainor@chromium.org>2015-12-09 09:10:20 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-09 17:11:17 +0000
commitd4c87719b3f885c60db2e912fcfaca43c780f36d (patch)
treeb21f86985b4c3e2ba070ded702453ade83c1b92e /blimp
parent62b283acf539a42e6b698d000653675b0d796572 (diff)
downloadchromium_src-d4c87719b3f885c60db2e912fcfaca43c780f36d.zip
chromium_src-d4c87719b3f885c60db2e912fcfaca43c780f36d.tar.gz
chromium_src-d4c87719b3f885c60db2e912fcfaca43c780f36d.tar.bz2
Add a basic BlimpClientSession object.
Creates the native BlimpClientSession and the corresponding Java BlimpClientSession object for Android. This also ties in existing features into the BlimpClientSession and renames them accordingly. BUG=567788 Review URL: https://codereview.chromium.org/1491423002 Cr-Commit-Position: refs/heads/master@{#364091}
Diffstat (limited to 'blimp')
-rw-r--r--blimp/client/BUILD.gn6
-rw-r--r--blimp/client/android/blimp_jni_registrar.cc3
-rw-r--r--blimp/client/android/blimp_view.cc10
-rw-r--r--blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java14
-rw-r--r--blimp/client/android/java/src/org/chromium/blimp/BlimpView.java13
-rw-r--r--blimp/client/android/java/src/org/chromium/blimp/session/BlimpClientSession.java42
-rw-r--r--blimp/client/android/java/src/org/chromium/blimp/toolbar/Toolbar.java9
-rw-r--r--blimp/client/android/toolbar.cc13
-rw-r--r--blimp/client/session/blimp_client_session.cc16
-rw-r--r--blimp/client/session/blimp_client_session.h43
-rw-r--r--blimp/client/session/blimp_client_session_android.cc41
-rw-r--r--blimp/client/session/blimp_client_session_android.h36
-rw-r--r--blimp/net/browser_connection_handler.h1
13 files changed, 236 insertions, 11 deletions
diff --git a/blimp/client/BUILD.gn b/blimp/client/BUILD.gn
index 41e5ca0..376be60 100644
--- a/blimp/client/BUILD.gn
+++ b/blimp/client/BUILD.gn
@@ -28,6 +28,8 @@ component("blimp_client") {
"input/blimp_input_manager.h",
"navigation_message_processor.cc",
"navigation_message_processor.h",
+ "session/blimp_client_session.cc",
+ "session/blimp_client_session.h",
]
defines = [ "BLIMP_CLIENT_IMPLEMENTATION=1" ]
@@ -102,6 +104,7 @@ if (is_android) {
sources = [
"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/toolbar/Toolbar.java",
]
@@ -185,6 +188,7 @@ if (is_android) {
"android/java/src/org/chromium/blimp/BlimpLibraryLoader.java",
"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/toolbar/Toolbar.java",
"android/java/src/org/chromium/blimp/toolbar/UrlBar.java",
]
@@ -230,6 +234,8 @@ if (is_android) {
"android/toolbar.h",
"compositor/blimp_compositor_android.cc",
"compositor/blimp_compositor_android.h",
+ "session/blimp_client_session_android.cc",
+ "session/blimp_client_session_android.h",
]
libs = [ "android" ]
diff --git a/blimp/client/android/blimp_jni_registrar.cc b/blimp/client/android/blimp_jni_registrar.cc
index 0bdd121..26f6b02 100644
--- a/blimp/client/android/blimp_jni_registrar.cc
+++ b/blimp/client/android/blimp_jni_registrar.cc
@@ -8,6 +8,7 @@
#include "blimp/client/android/blimp_library_loader.h"
#include "blimp/client/android/blimp_view.h"
#include "blimp/client/android/toolbar.h"
+#include "blimp/client/session/blimp_client_session_android.h"
namespace {
@@ -15,6 +16,8 @@ base::android::RegistrationMethod kBlimpRegistrationMethods[] = {
{"BlimpLibraryLoader", blimp::RegisterBlimpLibraryLoaderJni},
{"Toolbar", blimp::Toolbar::RegisterJni},
{"BlimpView", blimp::BlimpView::RegisterJni},
+ {"BlimpClientSessionAndroid",
+ blimp::BlimpClientSessionAndroid::RegisterJni},
};
} // namespace
diff --git a/blimp/client/android/blimp_view.cc b/blimp/client/android/blimp_view.cc
index 79633f7..988c673 100644
--- a/blimp/client/android/blimp_view.cc
+++ b/blimp/client/android/blimp_view.cc
@@ -7,6 +7,7 @@
#include <android/native_window_jni.h>
#include "blimp/client/compositor/blimp_compositor_android.h"
+#include "blimp/client/session/blimp_client_session_android.h"
#include "jni/BlimpView_jni.h"
#include "ui/events/android/motion_event_android.h"
#include "ui/gfx/geometry/size.h"
@@ -16,11 +17,20 @@ namespace blimp {
// static
static jlong Init(JNIEnv* env,
const JavaParamRef<jobject>& jobj,
+ const JavaParamRef<jobject>& blimp_client_session,
jint real_width,
jint real_height,
jint width,
jint height,
jfloat dp_to_px) {
+ BlimpClientSession* client_session =
+ BlimpClientSessionAndroid::FromJavaObject(env,
+ blimp_client_session.obj());
+
+ // TODO(dtrainor): Pull the feature object from the BlimpClientSession and
+ // pass it through to the BlimpCompositor.
+ ALLOW_UNUSED_LOCAL(client_session);
+
return reinterpret_cast<intptr_t>(
new BlimpView(env, jobj, gfx::Size(real_width, real_height),
gfx::Size(width, height), dp_to_px));
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 da25011..0558b96 100644
--- a/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java
+++ b/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java
@@ -13,6 +13,7 @@ import org.chromium.base.library_loader.ProcessInitException;
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.toolbar.Toolbar;
import org.chromium.ui.widget.Toast;
@@ -28,6 +29,7 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade
private TokenSource mTokenSource;
private BlimpView mBlimpView;
private Toolbar mToolbar;
+ private BlimpClientSession mBlimpClientSession;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -63,6 +65,12 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade
mTokenSource = null;
}
+ // Destroy the BlimpClientSession last, as all other features may rely on it.
+ if (mBlimpClientSession != null) {
+ mBlimpClientSession.destroy();
+ mBlimpClientSession = null;
+ }
+
super.onDestroy();
}
@@ -100,11 +108,13 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade
setContentView(R.layout.blimp_main);
+ mBlimpClientSession = new BlimpClientSession();
+
mBlimpView = (BlimpView) findViewById(R.id.renderer);
- mBlimpView.initializeRenderer();
+ mBlimpView.initializeRenderer(mBlimpClientSession);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
- mToolbar.initialize();
+ mToolbar.initialize(mBlimpClientSession);
}
// TokenSource.Callback implementation.
diff --git a/blimp/client/android/java/src/org/chromium/blimp/BlimpView.java b/blimp/client/android/java/src/org/chromium/blimp/BlimpView.java
index d5fb577..c8b586b 100644
--- a/blimp/client/android/java/src/org/chromium/blimp/BlimpView.java
+++ b/blimp/client/android/java/src/org/chromium/blimp/BlimpView.java
@@ -15,6 +15,7 @@ import android.view.SurfaceView;
import android.view.WindowManager;
import org.chromium.base.annotations.JNINamespace;
+import org.chromium.blimp.session.BlimpClientSession;
/**
* A {@link View} that will visually represent the Blimp rendered content. This {@link View} starts
@@ -38,8 +39,10 @@ public class BlimpView extends SurfaceView implements SurfaceHolder.Callback2 {
/**
* Starts up rendering for this {@link View}. This will start up the native compositor and will
* display it's contents.
+ * @param blimpClientSession The {@link BlimpClientSession} that contains the content-lite
+ * features required by the native components of the compositor.
*/
- public void initializeRenderer() {
+ public void initializeRenderer(BlimpClientSession blimpClientSession) {
assert mNativeBlimpViewPtr == 0;
WindowManager windowManager =
@@ -52,8 +55,8 @@ public class BlimpView extends SurfaceView implements SurfaceHolder.Callback2 {
}
// TODO(dtrainor): Change 1.f to dpToPx once native fully supports dp.
float compositorDensity = 1.f;
- mNativeBlimpViewPtr = nativeInit(
- physicalSize.x, physicalSize.y, displaySize.x, displaySize.y, compositorDensity);
+ mNativeBlimpViewPtr = nativeInit(blimpClientSession, physicalSize.x, physicalSize.y,
+ displaySize.x, displaySize.y, compositorDensity);
getHolder().addCallback(this);
setVisibility(VISIBLE);
}
@@ -162,8 +165,8 @@ public class BlimpView extends SurfaceView implements SurfaceHolder.Callback2 {
}
// Native Methods
- private native long nativeInit(int physicalWidth, int physicalHeight, int displayWidth,
- int displayHeight, float dpToPixel);
+ private native long nativeInit(BlimpClientSession blimpClientSession, int physicalWidth,
+ int physicalHeight, int displayWidth, int displayHeight, float dpToPixel);
private native void nativeDestroy(long nativeBlimpView);
private native void nativeSetNeedsComposite(long nativeBlimpView);
private native void nativeOnSurfaceChanged(
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
new file mode 100644
index 0000000..3501c5f
--- /dev/null
+++ b/blimp/client/android/java/src/org/chromium/blimp/session/BlimpClientSession.java
@@ -0,0 +1,42 @@
+// 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 org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * The Java representation of a native BlimpClientSession. This is primarily used to provide access
+ * to the native session methods and to facilitate passing a BlimpClientSession object between Java
+ * classes with native counterparts.
+ */
+@JNINamespace("blimp")
+public class BlimpClientSession {
+ private long mNativeBlimpClientSessionAndroidPtr;
+
+ public BlimpClientSession() {
+ mNativeBlimpClientSessionAndroidPtr = nativeInit();
+ }
+
+ /**
+ * Destroys the native BlimpClientSession. This class should not be used after this is called.
+ */
+ public void destroy() {
+ if (mNativeBlimpClientSessionAndroidPtr != 0) {
+ nativeDestroy(mNativeBlimpClientSessionAndroidPtr);
+ mNativeBlimpClientSessionAndroidPtr = 0;
+ }
+ }
+
+ // Methods that are called by native via JNI.
+ @CalledByNative
+ private long getNativePtr() {
+ assert mNativeBlimpClientSessionAndroidPtr != 0;
+ return mNativeBlimpClientSessionAndroidPtr;
+ }
+
+ private native long nativeInit();
+ private native void nativeDestroy(long nativeBlimpClientSessionAndroid);
+} \ No newline at end of file
diff --git a/blimp/client/android/java/src/org/chromium/blimp/toolbar/Toolbar.java b/blimp/client/android/java/src/org/chromium/blimp/toolbar/Toolbar.java
index 9de79ea..fc00435c 100644
--- a/blimp/client/android/java/src/org/chromium/blimp/toolbar/Toolbar.java
+++ b/blimp/client/android/java/src/org/chromium/blimp/toolbar/Toolbar.java
@@ -16,6 +16,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.blimp.R;
+import org.chromium.blimp.session.BlimpClientSession;
/**
* A {@link View} that visually represents the Blimp toolbar, which lets users issue navigation
@@ -47,11 +48,13 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver,
/**
* To be called when the native library is loaded so that this class can initialize its native
* components.
+ * @param blimpClientSession The {@link BlimpClientSession} that contains the content-lite
+ * features required by the native components of the Toolbar.
*/
- public void initialize() {
+ public void initialize(BlimpClientSession blimpClientSession) {
assert mNativeToolbarPtr == 0;
- mNativeToolbarPtr = nativeInit();
+ mNativeToolbarPtr = nativeInit(blimpClientSession);
sendUrlTextInternal(mUrlToLoad);
}
@@ -151,7 +154,7 @@ public class Toolbar extends LinearLayout implements UrlBar.UrlBarObserver,
// TODO(dtrainor): Add a UI for the loading state.
}
- private native long nativeInit();
+ private native long nativeInit(BlimpClientSession blimpClientSession);
private native void nativeDestroy(long nativeToolbar);
private native void nativeOnUrlTextEntered(long nativeToolbar, String text);
private native void nativeOnReloadPressed(long nativeToolbar);
diff --git a/blimp/client/android/toolbar.cc b/blimp/client/android/toolbar.cc
index 27468e9..6d4539a 100644
--- a/blimp/client/android/toolbar.cc
+++ b/blimp/client/android/toolbar.cc
@@ -6,6 +6,7 @@
#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"
@@ -24,7 +25,17 @@ base::LazyInstance<blimp::NullBlimpMessageProcessor>
} // namespace
// static
-static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
+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());
+
+ // TODO(dtrainor): Pull the feature object from the BlimpClientSession and
+ // use it instead of the NavigationMessageProcessor.
+ ALLOW_UNUSED_LOCAL(client_session);
+
return reinterpret_cast<intptr_t>(new Toolbar(env, jobj));
}
diff --git a/blimp/client/session/blimp_client_session.cc b/blimp/client/session/blimp_client_session.cc
new file mode 100644
index 0000000..40a1a68
--- /dev/null
+++ b/blimp/client/session/blimp_client_session.cc
@@ -0,0 +1,16 @@
+// 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/blimp_client_session.h"
+
+#include "blimp/net/browser_connection_handler.h"
+
+namespace blimp {
+
+BlimpClientSession::BlimpClientSession()
+ : connection_handler_(new BrowserConnectionHandler) {}
+
+BlimpClientSession::~BlimpClientSession() {}
+
+} // namespace blimp
diff --git a/blimp/client/session/blimp_client_session.h b/blimp/client/session/blimp_client_session.h
new file mode 100644
index 0000000..d23f805
--- /dev/null
+++ b/blimp/client/session/blimp_client_session.h
@@ -0,0 +1,43 @@
+// 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_BLIMP_CLIENT_SESSION_H_
+#define BLIMP_CLIENT_SESSION_BLIMP_CLIENT_SESSION_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "blimp/client/blimp_client_export.h"
+
+namespace blimp {
+
+class BrowserConnectionHandler;
+
+// BlimpClientSession represents a single active session of Blimp on the client
+// regardless of whether or not the client application is in the background or
+// foreground. The only time this session is invalid is during initialization
+// and shutdown of this particular client process (or Activity on Android).
+//
+// This session glues together the feature proxy components and the network
+// layer. The network components must be interacted with on the IO thread. The
+// feature proxies must be interacted with on the UI thread.
+class BLIMP_CLIENT_EXPORT BlimpClientSession {
+ public:
+ BlimpClientSession();
+
+ // TODO(dtrainor): Add access to specific feature classes here.
+
+ protected:
+ virtual ~BlimpClientSession();
+
+ private:
+ // The BrowserConnectionHandler is here so that the BlimpClientSession can
+ // glue the feature-specific handlers to the actual network connection.
+ scoped_ptr<BrowserConnectionHandler> connection_handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlimpClientSession);
+};
+
+} // namespace blimp
+
+#endif // BLIMP_CLIENT_SESSION_BLIMP_CLIENT_SESSION_H_
diff --git a/blimp/client/session/blimp_client_session_android.cc b/blimp/client/session/blimp_client_session_android.cc
new file mode 100644
index 0000000..a877877
--- /dev/null
+++ b/blimp/client/session/blimp_client_session_android.cc
@@ -0,0 +1,41 @@
+// 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/blimp_client_session_android.h"
+
+#include "jni/BlimpClientSession_jni.h"
+
+namespace blimp {
+
+static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
+ return reinterpret_cast<intptr_t>(new BlimpClientSessionAndroid(env, jobj));
+}
+
+// static
+bool BlimpClientSessionAndroid::RegisterJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+// static
+BlimpClientSessionAndroid* BlimpClientSessionAndroid::FromJavaObject(
+ JNIEnv* env,
+ jobject jobj) {
+ return reinterpret_cast<BlimpClientSessionAndroid*>(
+ Java_BlimpClientSession_getNativePtr(env, jobj));
+}
+
+BlimpClientSessionAndroid::BlimpClientSessionAndroid(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& jobj)
+ : BlimpClientSession() {
+ java_obj_.Reset(env, jobj);
+}
+
+BlimpClientSessionAndroid::~BlimpClientSessionAndroid() {}
+
+void BlimpClientSessionAndroid::Destroy(JNIEnv* env, jobject jobj) {
+ delete this;
+}
+
+} // namespace blimp
diff --git a/blimp/client/session/blimp_client_session_android.h b/blimp/client/session/blimp_client_session_android.h
new file mode 100644
index 0000000..fe552bf
--- /dev/null
+++ b/blimp/client/session/blimp_client_session_android.h
@@ -0,0 +1,36 @@
+// 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_BLIMP_CLIENT_SESSION_ANDROID_H_
+#define BLIMP_CLIENT_SESSION_BLIMP_CLIENT_SESSION_ANDROID_H_
+
+#include "base/android/jni_android.h"
+#include "base/macros.h"
+#include "blimp/client/session/blimp_client_session.h"
+
+namespace blimp {
+
+class BlimpClientSessionAndroid : public BlimpClientSession {
+ public:
+ static bool RegisterJni(JNIEnv* env);
+ static BlimpClientSessionAndroid* FromJavaObject(JNIEnv* env, jobject jobj);
+
+ BlimpClientSessionAndroid(JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& jobj);
+
+ // Methods called from Java via JNI.
+ void Destroy(JNIEnv* env, jobject jobj);
+
+ private:
+ ~BlimpClientSessionAndroid() override;
+
+ // Reference to the Java object which owns this class.
+ base::android::ScopedJavaGlobalRef<jobject> java_obj_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlimpClientSessionAndroid);
+};
+
+} // namespace blimp
+
+#endif // BLIMP_CLIENT_SESSION_BLIMP_CLIENT_SESSION_ANDROID_H_
diff --git a/blimp/net/browser_connection_handler.h b/blimp/net/browser_connection_handler.h
index 03b2cd0..5a4b239 100644
--- a/blimp/net/browser_connection_handler.h
+++ b/blimp/net/browser_connection_handler.h
@@ -27,6 +27,7 @@ class BlimpMessageProcessor;
class BLIMP_NET_EXPORT BrowserConnectionHandler
: public ConnectionHandler,
public ConnectionErrorObserver {
+ public:
BrowserConnectionHandler();
~BrowserConnectionHandler() override;