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/intercepted_request_data_impl.h"
      6 
      7 #include "android_webview/native/input_stream_impl.h"
      8 #include "base/android/jni_android.h"
      9 #include "base/android/jni_string.h"
     10 #include "jni/InterceptedRequestData_jni.h"
     11 #include "net/url_request/url_request.h"
     12 #include "net/url_request/url_request_job.h"
     13 
     14 using base::android::ScopedJavaLocalRef;
     15 
     16 namespace android_webview {
     17 
     18 InterceptedRequestDataImpl::InterceptedRequestDataImpl(
     19     const base::android::JavaRef<jobject>& obj)
     20   : java_object_(obj) {
     21 }
     22 
     23 InterceptedRequestDataImpl::~InterceptedRequestDataImpl() {
     24 }
     25 
     26 scoped_ptr<InputStream>
     27 InterceptedRequestDataImpl::GetInputStream(JNIEnv* env) const {
     28   ScopedJavaLocalRef<jobject> jstream =
     29       Java_InterceptedRequestData_getData(env, java_object_.obj());
     30   if (jstream.is_null())
     31     return scoped_ptr<InputStream>();
     32   return make_scoped_ptr<InputStream>(new InputStreamImpl(jstream));
     33 }
     34 
     35 bool InterceptedRequestDataImpl::GetMimeType(JNIEnv* env,
     36                                              std::string* mime_type) const {
     37   ScopedJavaLocalRef<jstring> jstring_mime_type =
     38       Java_InterceptedRequestData_getMimeType(env, java_object_.obj());
     39   if (jstring_mime_type.is_null())
     40     return false;
     41   *mime_type = ConvertJavaStringToUTF8(jstring_mime_type);
     42   return true;
     43 }
     44 
     45 bool InterceptedRequestDataImpl::GetCharset(
     46     JNIEnv* env, std::string* charset) const {
     47   ScopedJavaLocalRef<jstring> jstring_charset =
     48       Java_InterceptedRequestData_getCharset(env, java_object_.obj());
     49   if (jstring_charset.is_null())
     50     return false;
     51   *charset = ConvertJavaStringToUTF8(jstring_charset);
     52   return true;
     53 }
     54 
     55 bool RegisterInterceptedRequestData(JNIEnv* env) {
     56   return RegisterNativesImpl(env);
     57 }
     58 
     59 } // namespace android_webview
     60