Home | History | Annotate | Download | only in native
      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 "android_webview/native/aw_resource.h"
      6 
      7 #include "base/android/jni_string.h"
      8 #include "base/android/scoped_java_ref.h"
      9 #include "jni/AwResource_jni.h"
     10 
     11 namespace android_webview {
     12 namespace AwResource {
     13 
     14 // These JNI functions are used by the Renderer but rely on Java data
     15 // structures that exist in the Browser. By virtue of the WebView running
     16 // in single process we can just reach over and use them. When WebView is
     17 // multi-process capable, we'll need to rethink these. See crbug.com/156062.
     18 
     19 std::string GetLoadErrorPageContent() {
     20   JNIEnv* env = base::android::AttachCurrentThread();
     21   ScopedJavaLocalRef<jstring> content =
     22       Java_AwResource_getLoadErrorPageContent(env);
     23   return base::android::ConvertJavaStringToUTF8(content);
     24 }
     25 
     26 std::string GetNoDomainPageContent() {
     27   JNIEnv* env = base::android::AttachCurrentThread();
     28   ScopedJavaLocalRef<jstring> content =
     29       Java_AwResource_getNoDomainPageContent(env);
     30   return base::android::ConvertJavaStringToUTF8(content);
     31 }
     32 
     33 std::string GetDefaultTextEncoding() {
     34   JNIEnv* env = base::android::AttachCurrentThread();
     35   ScopedJavaLocalRef<jstring> encoding =
     36       Java_AwResource_getDefaultTextEncoding(env);
     37   return base::android::ConvertJavaStringToUTF8(encoding);
     38 }
     39 
     40 bool RegisterAwResource(JNIEnv* env) {
     41   return RegisterNativesImpl(env) >= 0;
     42 }
     43 
     44 }  // namespace AwResource
     45 }  // namespace android_webview
     46