Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/android/content_view_impl.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/scoped_java_ref.h" | |
| 9 | |
| 10 // TODO(jrg): content_view_jni.h is generated by | |
| 11 // base/android/jni_generator/jni_generator.py from ContentView.java. | |
| 12 // But the script doesn't know about the content namespace. Fix gyp | |
| 13 // rules to define a namespace variable; fix jni_generator.gypi to | |
| 14 // pass namespace to the script; fix the script to apply namespace on | |
| 15 // generation. | |
| 16 // Until that is done, we must wrap this in the content namespace, | |
| 17 // since otherwise the class ContentView is referenced in the | |
| 18 // generated header without the proper namespace. b/6597416 | |
| 19 namespace content { | |
| 20 #include "jni/content_view_jni.h" | |
| 21 }; | |
| 22 | |
| 23 using base::android::GetClass; | |
| 24 using base::android::HasField; | |
| 25 | |
| 26 namespace { | |
| 27 jfieldID g_native_content_view; | |
| 28 } // namespace | |
| 29 | |
| 30 | |
| 31 namespace content { | |
| 32 | |
| 33 // ---------------------------------------------------------------------------- | |
| 34 // Implementation of static ContentView public interfaces | |
| 35 | |
| 36 ContentView* ContentView::Create(JNIEnv* env, jobject obj) { | |
| 37 return new ContentViewImpl(env, obj); | |
| 38 } | |
| 39 | |
| 40 ContentView* ContentView::GetNativeContentView(JNIEnv* env, jobject obj) { | |
| 41 return reinterpret_cast<ContentView*>( | |
| 42 env->GetIntField(obj, g_native_content_view)); | |
| 43 } | |
| 44 | |
| 45 // ---------------------------------------------------------------------------- | |
| 46 | |
| 47 ContentViewImpl::ContentViewImpl(JNIEnv* env, jobject obj) { | |
| 48 } | |
| 49 | |
| 50 ContentViewImpl::~ContentViewImpl() { | |
| 51 } | |
| 52 | |
| 53 void ContentViewImpl::Destroy(JNIEnv* env, jobject obj) { | |
| 54 delete this; | |
| 55 } | |
| 56 | |
| 57 void ContentViewImpl::Observe(int type, | |
| 58 const content::NotificationSource& source, | |
| 59 const content::NotificationDetails& details) OVERRIDE { | |
|
jam
2012/06/08 23:45:09
nit: override is only in the header. also brace br
| |
| 60 // TODO(jrg) | |
| 61 } | |
| 62 | |
| 63 // ---------------------------------------------------------------------------- | |
| 64 // Native JNI methods | |
| 65 // ---------------------------------------------------------------------------- | |
| 66 | |
| 67 // This is called for each ContentView. | |
| 68 // TODO(jrg): add extra args (e.g. hardware_accelerated, | |
| 69 // native_web_contents) once other pieces are upstreamed. | |
| 70 static jint Init(JNIEnv* env, jobject obj) { | |
| 71 ContentView* view = ContentView::Create(env, obj); | |
| 72 return reinterpret_cast<jint>(view); | |
| 73 } | |
| 74 | |
| 75 // ---------------------------------------------------------------------------- | |
| 76 | |
| 77 bool RegisterContentView(JNIEnv* env) { | |
| 78 if (!base::android::HasClass(env, kContentViewClassPath)) { | |
| 79 DLOG(ERROR) << "Unable to find class ContentView!"; | |
| 80 return false; | |
| 81 } | |
| 82 ScopedJavaLocalRef<jclass> clazz = GetClass(env, kContentViewClassPath); | |
| 83 if (!HasField(env, clazz, "mNativeContentView", "I")) { | |
| 84 DLOG(ERROR) << "Unable to find ContentView.mNativeContentView!"; | |
| 85 return false; | |
| 86 } | |
| 87 g_native_content_view = GetFieldID(env, clazz, "mNativeContentView", "I"); | |
| 88 | |
| 89 return RegisterNativesImpl(env) >= 0; | |
| 90 } | |
| 91 | |
| 92 }; // namespace content | |
| OLD | NEW |