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