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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/android/content_view_impl.h" 5 #include "content/browser/android/content_view_impl.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "content/browser/android/content_view_client.h" 10 #include "content/browser/android/content_view_client.h"
11 #include "content/browser/web_contents/navigation_controller_impl.h" 11 #include "content/browser/web_contents/navigation_controller_impl.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "jni/content_view_jni.h" 14 #include "jni/content_view_jni.h"
15 15
16 using base::android::AttachCurrentThread;
16 using base::android::ConvertUTF16ToJavaString; 17 using base::android::ConvertUTF16ToJavaString;
17 using base::android::ConvertUTF8ToJavaString; 18 using base::android::ConvertUTF8ToJavaString;
18 using base::android::GetClass; 19 using base::android::GetClass;
19 using base::android::HasField; 20 using base::android::HasField;
21 using base::android::ScopedJavaLocalRef;
20 22
21 namespace { 23 namespace {
22 jfieldID g_native_content_view; 24 jfieldID g_native_content_view;
23 } // namespace 25 } // namespace
24 26
25 namespace content { 27 namespace content {
26 28
29 struct ContentViewImpl::JavaObject {
30 jweak obj;
31
32 ScopedJavaLocalRef<jobject> View(JNIEnv* env) {
33 return GetRealObject(env, obj);
34 }
35 };
36
27 // ---------------------------------------------------------------------------- 37 // ----------------------------------------------------------------------------
28 // Implementation of static ContentView public interfaces 38 // Implementation of static ContentView public interfaces
29 39
30 ContentView* ContentView::Create(JNIEnv* env, jobject obj, 40 ContentView* ContentView::Create(JNIEnv* env, jobject obj,
31 WebContents* web_contents) { 41 WebContents* web_contents) {
32 return new ContentViewImpl(env, obj, web_contents); 42 return new ContentViewImpl(env, obj, web_contents);
33 } 43 }
34 44
35 ContentView* ContentView::GetNativeContentView(JNIEnv* env, jobject obj) { 45 ContentView* ContentView::GetNativeContentView(JNIEnv* env, jobject obj) {
36 return reinterpret_cast<ContentView*>( 46 return reinterpret_cast<ContentView*>(
37 env->GetIntField(obj, g_native_content_view)); 47 env->GetIntField(obj, g_native_content_view));
38 } 48 }
39 49
40 // ---------------------------------------------------------------------------- 50 // ----------------------------------------------------------------------------
41 51
42 ContentViewImpl::ContentViewImpl(JNIEnv* env, jobject obj, 52 ContentViewImpl::ContentViewImpl(JNIEnv* env, jobject obj,
43 WebContents* web_contents) 53 WebContents* web_contents)
44 : web_contents_(web_contents), 54 : web_contents_(web_contents),
45 tab_crashed_(false) { 55 tab_crashed_(false) {
46 DCHECK(web_contents) << 56 DCHECK(web_contents) <<
47 "A ContentViewImpl should be created with a valid WebContents."; 57 "A ContentViewImpl should be created with a valid WebContents.";
58
59 InitJNI(env, obj);
48 } 60 }
49 61
50 ContentViewImpl::~ContentViewImpl() { 62 ContentViewImpl::~ContentViewImpl() {
63 if (java_object_) {
64 JNIEnv* env = AttachCurrentThread();
65 env->DeleteWeakGlobalRef(java_object_->obj);
66 delete java_object_;
67 java_object_ = 0;
68 }
51 } 69 }
52 70
53 void ContentViewImpl::Destroy(JNIEnv* env, jobject obj) { 71 void ContentViewImpl::Destroy(JNIEnv* env, jobject obj) {
54 delete this; 72 delete this;
55 } 73 }
56 74
57 void ContentViewImpl::Observe(int type, 75 void ContentViewImpl::Observe(int type,
58 const NotificationSource& source, 76 const NotificationSource& source,
59 const NotificationDetails& details) { 77 const NotificationDetails& details) {
60 // TODO(jrg) 78 // TODO(jrg)
61 } 79 }
62 80
81 void ContentViewImpl::InitJNI(JNIEnv* env, jobject obj) {
82 java_object_ = new JavaObject;
83 java_object_->obj = env->NewWeakGlobalRef(obj);
84 }
85
63 // ---------------------------------------------------------------------------- 86 // ----------------------------------------------------------------------------
64 // Methods called from Java via JNI 87 // Methods called from Java via JNI
65 // ---------------------------------------------------------------------------- 88 // ----------------------------------------------------------------------------
66 89
67 void ContentViewImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, 90 void ContentViewImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env,
68 jobject, 91 jobject,
69 jstring jurl, 92 jstring jurl,
70 int page_transition) { 93 int page_transition) {
71 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); 94 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
72 95
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 int endy, 258 int endy,
236 base::i18n::TextDirection end_dir) { 259 base::i18n::TextDirection end_dir) {
237 NOTIMPLEMENTED() << "not upstreamed yet"; 260 NOTIMPLEMENTED() << "not upstreamed yet";
238 } 261 }
239 262
240 void ContentViewImpl::OnAcceleratedCompositingStateChange( 263 void ContentViewImpl::OnAcceleratedCompositingStateChange(
241 RenderWidgetHostViewAndroid* rwhva, bool activated, bool force) { 264 RenderWidgetHostViewAndroid* rwhva, bool activated, bool force) {
242 NOTIMPLEMENTED() << "not upstreamed yet"; 265 NOTIMPLEMENTED() << "not upstreamed yet";
243 } 266 }
244 267
268 void ContentViewImpl::StartContentIntent(const GURL& content_url) {
269 JNIEnv* env = AttachCurrentThread();
270 ScopedJavaLocalRef<jstring> jcontent_url =
271 ConvertUTF8ToJavaString(env, content_url.spec());
272 Java_ContentView_startContentIntent(env,
273 java_object_->View(env).obj(),
274 jcontent_url.obj());
275 }
276
245 // -------------------------------------------------------------------------- 277 // --------------------------------------------------------------------------
246 // Methods called from Java via JNI 278 // Methods called from Java via JNI
247 // -------------------------------------------------------------------------- 279 // --------------------------------------------------------------------------
248 280
249 // -------------------------------------------------------------------------- 281 // --------------------------------------------------------------------------
250 // Methods called from native code 282 // Methods called from native code
251 // -------------------------------------------------------------------------- 283 // --------------------------------------------------------------------------
252 284
253 gfx::Rect ContentViewImpl::GetBounds() const { 285 gfx::Rect ContentViewImpl::GetBounds() const {
254 NOTIMPLEMENTED() << "not upstreamed yet"; 286 NOTIMPLEMENTED() << "not upstreamed yet";
(...skipping 11 matching lines...) Expand all
266 if (!HasField(env, clazz, "mNativeContentView", "I")) { 298 if (!HasField(env, clazz, "mNativeContentView", "I")) {
267 DLOG(ERROR) << "Unable to find ContentView.mNativeContentView!"; 299 DLOG(ERROR) << "Unable to find ContentView.mNativeContentView!";
268 return false; 300 return false;
269 } 301 }
270 g_native_content_view = GetFieldID(env, clazz, "mNativeContentView", "I"); 302 g_native_content_view = GetFieldID(env, clazz, "mNativeContentView", "I");
271 303
272 return RegisterNativesImpl(env) >= 0; 304 return RegisterNativesImpl(env) >= 0;
273 } 305 }
274 306
275 } // namespace content 307 } // namespace content
OLDNEW
« 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