Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8802)

Unified Diff: content/browser/android/content_view_impl.cc

Issue 10695124: Add support for triggering Android intents based on content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit fixes. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/android/content_view_impl.h ('k') | content/browser/renderer_host/render_view_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/android/content_view_impl.cc
diff --git a/content/browser/android/content_view_impl.cc b/content/browser/android/content_view_impl.cc
index f3f07e4be522f75ddcf6d428816763bb9c4d620d..ea5a9131d14183402a3edf37d4921da6cb53672c 100644
--- a/content/browser/android/content_view_impl.cc
+++ b/content/browser/android/content_view_impl.cc
@@ -13,10 +13,12 @@
#include "content/public/browser/web_contents.h"
#include "jni/content_view_jni.h"
+using base::android::AttachCurrentThread;
using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString;
using base::android::GetClass;
using base::android::HasField;
+using base::android::ScopedJavaLocalRef;
namespace {
jfieldID g_native_content_view;
@@ -24,6 +26,14 @@ jfieldID g_native_content_view;
namespace content {
+struct ContentViewImpl::JavaObject {
+ jweak obj;
+
+ ScopedJavaLocalRef<jobject> View(JNIEnv* env) {
+ return GetRealObject(env, obj);
+ }
+};
+
// ----------------------------------------------------------------------------
// Implementation of static ContentView public interfaces
@@ -45,9 +55,17 @@ ContentViewImpl::ContentViewImpl(JNIEnv* env, jobject obj,
tab_crashed_(false) {
DCHECK(web_contents) <<
"A ContentViewImpl should be created with a valid WebContents.";
+
+ InitJNI(env, obj);
}
ContentViewImpl::~ContentViewImpl() {
+ if (java_object_) {
+ JNIEnv* env = AttachCurrentThread();
+ env->DeleteWeakGlobalRef(java_object_->obj);
+ delete java_object_;
+ java_object_ = 0;
+ }
}
void ContentViewImpl::Destroy(JNIEnv* env, jobject obj) {
@@ -60,6 +78,11 @@ void ContentViewImpl::Observe(int type,
// TODO(jrg)
}
+void ContentViewImpl::InitJNI(JNIEnv* env, jobject obj) {
+ java_object_ = new JavaObject;
+ java_object_->obj = env->NewWeakGlobalRef(obj);
+}
+
// ----------------------------------------------------------------------------
// Methods called from Java via JNI
// ----------------------------------------------------------------------------
@@ -242,6 +265,15 @@ void ContentViewImpl::OnAcceleratedCompositingStateChange(
NOTIMPLEMENTED() << "not upstreamed yet";
}
+void ContentViewImpl::StartContentIntent(const GURL& content_url) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> jcontent_url =
+ ConvertUTF8ToJavaString(env, content_url.spec());
+ Java_ContentView_startContentIntent(env,
+ java_object_->View(env).obj(),
+ jcontent_url.obj());
+}
+
// --------------------------------------------------------------------------
// Methods called from Java via JNI
// --------------------------------------------------------------------------
« no previous file with comments | « content/browser/android/content_view_impl.h ('k') | content/browser/renderer_host/render_view_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698