Commit e9928ffd authored by ctzsm's avatar ctzsm Committed by Commit bot

[WebView] Replace AwContentsIoThreadClient, InputStream and AwWebResourceResponse

This CL:

1) Replaced AwContentsIoThreadClient with AwContentsIoThreadClientImpl
2) Replaced InputStream with InputStreamImpl
3) Replaced AwWebResourceResponse with AwWebResourceResponseImpl, and
   moved implementation into browser/net/.

Replacing them due to the merge of native/ and browser/

BUG=716604

Review-Url: https://codereview.chromium.org/2889193004
Cr-Commit-Position: refs/heads/master@{#473769}
parent a252bab6
...@@ -446,9 +446,8 @@ source_set("common") { ...@@ -446,9 +446,8 @@ source_set("common") {
"browser/aw_contents_background_thread_client.h", "browser/aw_contents_background_thread_client.h",
"browser/aw_contents_client_bridge.cc", "browser/aw_contents_client_bridge.cc",
"browser/aw_contents_client_bridge.h", "browser/aw_contents_client_bridge.h",
"browser/aw_contents_io_thread_client.cc",
"browser/aw_contents_io_thread_client.h", "browser/aw_contents_io_thread_client.h",
"browser/aw_contents_io_thread_client_impl.cc",
"browser/aw_contents_io_thread_client_impl.h",
"browser/aw_contents_lifecycle_notifier.cc", "browser/aw_contents_lifecycle_notifier.cc",
"browser/aw_contents_lifecycle_notifier.h", "browser/aw_contents_lifecycle_notifier.h",
"browser/aw_contents_statics.cc", "browser/aw_contents_statics.cc",
...@@ -521,8 +520,6 @@ source_set("common") { ...@@ -521,8 +520,6 @@ source_set("common") {
"browser/aw_web_contents_delegate.h", "browser/aw_web_contents_delegate.h",
"browser/aw_web_contents_view_delegate.cc", "browser/aw_web_contents_view_delegate.cc",
"browser/aw_web_contents_view_delegate.h", "browser/aw_web_contents_view_delegate.h",
"browser/aw_web_resource_response_impl.cc",
"browser/aw_web_resource_response_impl.h",
"browser/browser_view_renderer.cc", "browser/browser_view_renderer.cc",
"browser/browser_view_renderer.h", "browser/browser_view_renderer.h",
"browser/browser_view_renderer_client.h", "browser/browser_view_renderer_client.h",
...@@ -546,9 +543,8 @@ source_set("common") { ...@@ -546,9 +543,8 @@ source_set("common") {
"browser/hardware_renderer.h", "browser/hardware_renderer.h",
"browser/icon_helper.cc", "browser/icon_helper.cc",
"browser/icon_helper.h", "browser/icon_helper.h",
"browser/input_stream.cc",
"browser/input_stream.h", "browser/input_stream.h",
"browser/input_stream_impl.cc",
"browser/input_stream_impl.h",
"browser/java_browser_view_renderer_helper.cc", "browser/java_browser_view_renderer_helper.cc",
"browser/java_browser_view_renderer_helper.h", "browser/java_browser_view_renderer_helper.h",
"browser/net/android_stream_reader_url_request_job.cc", "browser/net/android_stream_reader_url_request_job.cc",
...@@ -571,6 +567,7 @@ source_set("common") { ...@@ -571,6 +567,7 @@ source_set("common") {
"browser/net/aw_url_request_job_factory.h", "browser/net/aw_url_request_job_factory.h",
"browser/net/aw_web_resource_request.cc", "browser/net/aw_web_resource_request.cc",
"browser/net/aw_web_resource_request.h", "browser/net/aw_web_resource_request.h",
"browser/net/aw_web_resource_response.cc",
"browser/net/aw_web_resource_response.h", "browser/net/aw_web_resource_response.h",
"browser/net/init_native_callback.cc", "browser/net/init_native_callback.cc",
"browser/net/init_native_callback.h", "browser/net/init_native_callback.h",
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <utility> #include <utility>
#include "android_webview/browser/input_stream_impl.h" #include "android_webview/browser/input_stream.h"
#include "android_webview/browser/net/android_stream_reader_url_request_job.h" #include "android_webview/browser/net/android_stream_reader_url_request_job.h"
#include "android_webview/browser/net/aw_url_request_job_factory.h" #include "android_webview/browser/net/aw_url_request_job_factory.h"
#include "android_webview/common/url_constants.h" #include "android_webview/common/url_constants.h"
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
using android_webview::AndroidStreamReaderURLRequestJob; using android_webview::AndroidStreamReaderURLRequestJob;
using android_webview::InputStream; using android_webview::InputStream;
using android_webview::InputStreamImpl; using android_webview::InputStream;
using base::android::AttachCurrentThread; using base::android::AttachCurrentThread;
using base::android::ClearException; using base::android::ClearException;
using base::android::ConvertUTF8ToJavaString; using base::android::ConvertUTF8ToJavaString;
...@@ -120,7 +120,7 @@ AndroidStreamReaderURLRequestJobDelegateImpl::OpenInputStream(JNIEnv* env, ...@@ -120,7 +120,7 @@ AndroidStreamReaderURLRequestJobDelegateImpl::OpenInputStream(JNIEnv* env,
DLOG(ERROR) << "Unable to open input stream for Android URL"; DLOG(ERROR) << "Unable to open input stream for Android URL";
return std::unique_ptr<InputStream>(); return std::unique_ptr<InputStream>();
} }
return base::MakeUnique<InputStreamImpl>(stream); return base::MakeUnique<InputStream>(stream);
} }
void AndroidStreamReaderURLRequestJobDelegateImpl::OnInputStreamOpenFailed( void AndroidStreamReaderURLRequestJobDelegateImpl::OnInputStreamOpenFailed(
...@@ -144,10 +144,9 @@ bool AndroidStreamReaderURLRequestJobDelegateImpl::GetMimeType( ...@@ -144,10 +144,9 @@ bool AndroidStreamReaderURLRequestJobDelegateImpl::GetMimeType(
// fail, as the mime type cannot be determined for all supported schemes. // fail, as the mime type cannot be determined for all supported schemes.
ScopedJavaLocalRef<jstring> url = ScopedJavaLocalRef<jstring> url =
ConvertUTF8ToJavaString(env, request->url().spec()); ConvertUTF8ToJavaString(env, request->url().spec());
const InputStreamImpl* stream_impl = InputStreamImpl::FromInputStream(stream);
ScopedJavaLocalRef<jstring> returned_type = ScopedJavaLocalRef<jstring> returned_type =
android_webview::Java_AndroidProtocolHandler_getMimeType( android_webview::Java_AndroidProtocolHandler_getMimeType(
env, stream_impl->jobj(), url); env, stream->jobj(), url);
if (returned_type.is_null()) if (returned_type.is_null())
return false; return false;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "android_webview/browser/aw_browser_context.h" #include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_browser_main_parts.h" #include "android_webview/browser/aw_browser_main_parts.h"
#include "android_webview/browser/aw_contents_client_bridge.h" #include "android_webview/browser/aw_contents_client_bridge.h"
#include "android_webview/browser/aw_contents_io_thread_client_impl.h" #include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_contents_lifecycle_notifier.h" #include "android_webview/browser/aw_contents_lifecycle_notifier.h"
#include "android_webview/browser/aw_gl_functor.h" #include "android_webview/browser/aw_gl_functor.h"
#include "android_webview/browser/aw_pdf_exporter.h" #include "android_webview/browser/aw_pdf_exporter.h"
...@@ -263,8 +263,7 @@ void AwContents::SetJavaPeers( ...@@ -263,8 +263,7 @@ void AwContents::SetJavaPeers(
AwContentsClientBridge::Associate(web_contents_.get(), AwContentsClientBridge::Associate(web_contents_.get(),
contents_client_bridge_.get()); contents_client_bridge_.get());
AwContentsIoThreadClientImpl::Associate(web_contents_.get(), AwContentsIoThreadClient::Associate(web_contents_.get(), io_thread_client);
io_thread_client);
InterceptNavigationDelegate::Associate( InterceptNavigationDelegate::Associate(
web_contents_.get(), base::MakeUnique<InterceptNavigationDelegate>( web_contents_.get(), base::MakeUnique<InterceptNavigationDelegate>(
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "android_webview/browser/aw_contents_io_thread_client_impl.h" #include "android_webview/browser/aw_contents_io_thread_client.h"
#include <map> #include <map>
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "android_webview/browser/aw_contents_background_thread_client.h" #include "android_webview/browser/aw_contents_background_thread_client.h"
#include "android_webview/browser/aw_web_resource_response_impl.h"
#include "android_webview/browser/net/aw_web_resource_request.h" #include "android_webview/browser/net/aw_web_resource_request.h"
#include "android_webview/browser/net/aw_web_resource_response.h"
#include "android_webview/common/devtools_instrumentation.h" #include "android_webview/common/devtools_instrumentation.h"
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
...@@ -191,7 +191,7 @@ void ClientMapEntryUpdater::WebContentsDestroyed() { ...@@ -191,7 +191,7 @@ void ClientMapEntryUpdater::WebContentsDestroyed() {
} // namespace } // namespace
// AwContentsIoThreadClientImpl ----------------------------------------------- // AwContentsIoThreadClient -----------------------------------------------
// static // static
std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID( std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID(
...@@ -206,9 +206,8 @@ std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID( ...@@ -206,9 +206,8 @@ std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID(
ScopedJavaLocalRef<jobject> java_delegate = ScopedJavaLocalRef<jobject> java_delegate =
client_data.io_thread_client.get(env); client_data.io_thread_client.get(env);
DCHECK(!client_data.pending_association || java_delegate.is_null()); DCHECK(!client_data.pending_association || java_delegate.is_null());
return std::unique_ptr<AwContentsIoThreadClient>( return std::unique_ptr<AwContentsIoThreadClient>(new AwContentsIoThreadClient(
new AwContentsIoThreadClientImpl(client_data.pending_association, client_data.pending_association, java_delegate));
java_delegate));
} }
std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID( std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID(
...@@ -222,9 +221,8 @@ std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID( ...@@ -222,9 +221,8 @@ std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID(
ScopedJavaLocalRef<jobject> java_delegate = ScopedJavaLocalRef<jobject> java_delegate =
client_data.io_thread_client.get(env); client_data.io_thread_client.get(env);
DCHECK(!client_data.pending_association || java_delegate.is_null()); DCHECK(!client_data.pending_association || java_delegate.is_null());
return std::unique_ptr<AwContentsIoThreadClient>( return std::unique_ptr<AwContentsIoThreadClient>(new AwContentsIoThreadClient(
new AwContentsIoThreadClientImpl(client_data.pending_association, client_data.pending_association, java_delegate));
java_delegate));
} }
// static // static
...@@ -244,7 +242,7 @@ void AwContentsIoThreadClient::SubFrameCreated(int render_process_id, ...@@ -244,7 +242,7 @@ void AwContentsIoThreadClient::SubFrameCreated(int render_process_id,
} }
// static // static
void AwContentsIoThreadClientImpl::RegisterPendingContents( void AwContentsIoThreadClient::RegisterPendingContents(
WebContents* web_contents) { WebContents* web_contents) {
IoThreadClientData client_data; IoThreadClientData client_data;
client_data.pending_association = true; client_data.pending_association = true;
...@@ -253,15 +251,15 @@ void AwContentsIoThreadClientImpl::RegisterPendingContents( ...@@ -253,15 +251,15 @@ void AwContentsIoThreadClientImpl::RegisterPendingContents(
} }
// static // static
void AwContentsIoThreadClientImpl::Associate(WebContents* web_contents, void AwContentsIoThreadClient::Associate(WebContents* web_contents,
const JavaRef<jobject>& jclient) { const JavaRef<jobject>& jclient) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
// The ClientMapEntryUpdater lifespan is tied to the WebContents. // The ClientMapEntryUpdater lifespan is tied to the WebContents.
new ClientMapEntryUpdater(env, web_contents, jclient.obj()); new ClientMapEntryUpdater(env, web_contents, jclient.obj());
} }
// static // static
void AwContentsIoThreadClientImpl::SetServiceWorkerIoThreadClient( void AwContentsIoThreadClient::SetServiceWorkerIoThreadClient(
const base::android::JavaRef<jobject>& jclient, const base::android::JavaRef<jobject>& jclient,
const base::android::JavaRef<jobject>& browser_context) { const base::android::JavaRef<jobject>& browser_context) {
// TODO: currently there is only one browser context so it is ok to // TODO: currently there is only one browser context so it is ok to
...@@ -281,23 +279,22 @@ AwContentsIoThreadClient::GetServiceWorkerIoThreadClient() { ...@@ -281,23 +279,22 @@ AwContentsIoThreadClient::GetServiceWorkerIoThreadClient() {
return std::unique_ptr<AwContentsIoThreadClient>(); return std::unique_ptr<AwContentsIoThreadClient>();
return std::unique_ptr<AwContentsIoThreadClient>( return std::unique_ptr<AwContentsIoThreadClient>(
new AwContentsIoThreadClientImpl(false, java_delegate)); new AwContentsIoThreadClient(false, java_delegate));
} }
AwContentsIoThreadClientImpl::AwContentsIoThreadClientImpl( AwContentsIoThreadClient::AwContentsIoThreadClient(bool pending_association,
bool pending_association, const JavaRef<jobject>& obj)
const JavaRef<jobject>& obj)
: pending_association_(pending_association), java_object_(obj) {} : pending_association_(pending_association), java_object_(obj) {}
AwContentsIoThreadClientImpl::~AwContentsIoThreadClientImpl() { AwContentsIoThreadClient::~AwContentsIoThreadClient() {
// explict, out-of-line destructor. // explict, out-of-line destructor.
} }
bool AwContentsIoThreadClientImpl::PendingAssociation() const { bool AwContentsIoThreadClient::PendingAssociation() const {
return pending_association_; return pending_association_;
} }
AwContentsIoThreadClient::CacheMode AwContentsIoThreadClientImpl::GetCacheMode() AwContentsIoThreadClient::CacheMode AwContentsIoThreadClient::GetCacheMode()
const { const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (java_object_.is_null()) if (java_object_.is_null())
...@@ -331,7 +328,7 @@ std::unique_ptr<AwWebResourceResponse> RunShouldInterceptRequest( ...@@ -331,7 +328,7 @@ std::unique_ptr<AwWebResourceResponse> RunShouldInterceptRequest(
java_web_resource_request.jheader_names, java_web_resource_request.jheader_names,
java_web_resource_request.jheader_values); java_web_resource_request.jheader_values);
return std::unique_ptr<AwWebResourceResponse>( return std::unique_ptr<AwWebResourceResponse>(
ret.is_null() ? nullptr : new AwWebResourceResponseImpl(ret)); ret.is_null() ? nullptr : new AwWebResourceResponse(ret));
} }
std::unique_ptr<AwWebResourceResponse> ReturnNull() { std::unique_ptr<AwWebResourceResponse> ReturnNull() {
...@@ -340,7 +337,7 @@ std::unique_ptr<AwWebResourceResponse> ReturnNull() { ...@@ -340,7 +337,7 @@ std::unique_ptr<AwWebResourceResponse> ReturnNull() {
} // namespace } // namespace
void AwContentsIoThreadClientImpl::ShouldInterceptRequestAsync( void AwContentsIoThreadClient::ShouldInterceptRequestAsync(
const net::URLRequest* request, const net::URLRequest* request,
const ShouldInterceptRequestResultCallback callback) { const ShouldInterceptRequestResultCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -361,7 +358,7 @@ void AwContentsIoThreadClientImpl::ShouldInterceptRequestAsync( ...@@ -361,7 +358,7 @@ void AwContentsIoThreadClientImpl::ShouldInterceptRequestAsync(
get_response, callback); get_response, callback);
} }
bool AwContentsIoThreadClientImpl::ShouldBlockContentUrls() const { bool AwContentsIoThreadClient::ShouldBlockContentUrls() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (java_object_.is_null()) if (java_object_.is_null())
return false; return false;
...@@ -371,7 +368,7 @@ bool AwContentsIoThreadClientImpl::ShouldBlockContentUrls() const { ...@@ -371,7 +368,7 @@ bool AwContentsIoThreadClientImpl::ShouldBlockContentUrls() const {
java_object_); java_object_);
} }
bool AwContentsIoThreadClientImpl::ShouldBlockFileUrls() const { bool AwContentsIoThreadClient::ShouldBlockFileUrls() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (java_object_.is_null()) if (java_object_.is_null())
return false; return false;
...@@ -380,7 +377,7 @@ bool AwContentsIoThreadClientImpl::ShouldBlockFileUrls() const { ...@@ -380,7 +377,7 @@ bool AwContentsIoThreadClientImpl::ShouldBlockFileUrls() const {
return Java_AwContentsIoThreadClient_shouldBlockFileUrls(env, java_object_); return Java_AwContentsIoThreadClient_shouldBlockFileUrls(env, java_object_);
} }
bool AwContentsIoThreadClientImpl::ShouldAcceptThirdPartyCookies() const { bool AwContentsIoThreadClient::ShouldAcceptThirdPartyCookies() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (java_object_.is_null()) if (java_object_.is_null())
return false; return false;
...@@ -390,7 +387,7 @@ bool AwContentsIoThreadClientImpl::ShouldAcceptThirdPartyCookies() const { ...@@ -390,7 +387,7 @@ bool AwContentsIoThreadClientImpl::ShouldAcceptThirdPartyCookies() const {
env, java_object_); env, java_object_);
} }
bool AwContentsIoThreadClientImpl::GetSafeBrowsingEnabled() const { bool AwContentsIoThreadClient::GetSafeBrowsingEnabled() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (java_object_.is_null()) if (java_object_.is_null())
return false; return false;
...@@ -400,7 +397,7 @@ bool AwContentsIoThreadClientImpl::GetSafeBrowsingEnabled() const { ...@@ -400,7 +397,7 @@ bool AwContentsIoThreadClientImpl::GetSafeBrowsingEnabled() const {
java_object_); java_object_);
} }
bool AwContentsIoThreadClientImpl::ShouldBlockNetworkLoads() const { bool AwContentsIoThreadClient::ShouldBlockNetworkLoads() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (java_object_.is_null()) if (java_object_.is_null())
return false; return false;
......
...@@ -10,7 +10,14 @@ ...@@ -10,7 +10,14 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/android/scoped_java_ref.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
namespace content {
class WebContents;
}
namespace net { namespace net {
class URLRequest; class URLRequest;
...@@ -46,15 +53,36 @@ class AwContentsIoThreadClient { ...@@ -46,15 +53,36 @@ class AwContentsIoThreadClient {
LOAD_CACHE_ONLY = 3, LOAD_CACHE_ONLY = 3,
}; };
virtual ~AwContentsIoThreadClient() {} // Called when AwContents is created before there is a Java client.
static void RegisterPendingContents(content::WebContents* web_contents);
// Associates the |jclient| instance (which must implement the
// AwContentsIoThreadClient Java interface) with the |web_contents|.
// This should be called at most once per |web_contents|.
static void Associate(content::WebContents* web_contents,
const base::android::JavaRef<jobject>& jclient);
// Sets the |jclient| java instance to which service worker related
// callbacks should be delegated.
static void SetServiceWorkerIoThreadClient(
const base::android::JavaRef<jobject>& jclient,
const base::android::JavaRef<jobject>& browser_context);
// Either |pending_associate| is true or |jclient| holds a non-null
// Java object.
AwContentsIoThreadClient(bool pending_associate,
const base::android::JavaRef<jobject>& jclient);
~AwContentsIoThreadClient();
// Implementation of AwContentsIoThreadClient.
// Returns whether this is a new pop up that is still waiting for association // Returns whether this is a new pop up that is still waiting for association
// with the java counter part. // with the java counter part.
virtual bool PendingAssociation() const = 0; bool PendingAssociation() const;
// Retrieve CacheMode setting value of this AwContents. // Retrieve CacheMode setting value of this AwContents.
// This method is called on the IO thread only. // This method is called on the IO thread only.
virtual CacheMode GetCacheMode() const = 0; CacheMode GetCacheMode() const;
// This will attempt to fetch the AwContentsIoThreadClient for the given // This will attempt to fetch the AwContentsIoThreadClient for the given
// |render_process_id|, |render_frame_id| pair. // |render_process_id|, |render_frame_id| pair.
...@@ -81,29 +109,36 @@ class AwContentsIoThreadClient { ...@@ -81,29 +109,36 @@ class AwContentsIoThreadClient {
// This method is called on the IO thread only. // This method is called on the IO thread only.
typedef base::Callback<void(std::unique_ptr<AwWebResourceResponse>)> typedef base::Callback<void(std::unique_ptr<AwWebResourceResponse>)>
ShouldInterceptRequestResultCallback; ShouldInterceptRequestResultCallback;
virtual void ShouldInterceptRequestAsync( void ShouldInterceptRequestAsync(
const net::URLRequest* request, const net::URLRequest* request,
const ShouldInterceptRequestResultCallback callback) = 0; const ShouldInterceptRequestResultCallback callback);
// Retrieve the AllowContentAccess setting value of this AwContents. // Retrieve the AllowContentAccess setting value of this AwContents.
// This method is called on the IO thread only. // This method is called on the IO thread only.
virtual bool ShouldBlockContentUrls() const = 0; bool ShouldBlockContentUrls() const;
// Retrieve the AllowFileAccess setting value of this AwContents. // Retrieve the AllowFileAccess setting value of this AwContents.
// This method is called on the IO thread only. // This method is called on the IO thread only.
virtual bool ShouldBlockFileUrls() const = 0; bool ShouldBlockFileUrls() const;
// Retrieve the BlockNetworkLoads setting value of this AwContents. // Retrieve the BlockNetworkLoads setting value of this AwContents.
// This method is called on the IO thread only. // This method is called on the IO thread only.
virtual bool ShouldBlockNetworkLoads() const = 0; bool ShouldBlockNetworkLoads() const;
// Retrieve the AcceptThirdPartyCookies setting value of this AwContents. // Retrieve the AcceptThirdPartyCookies setting value of this AwContents.
virtual bool ShouldAcceptThirdPartyCookies() const = 0; bool ShouldAcceptThirdPartyCookies() const;
// Retrieve the SafeBrowsingEnabled setting value of this AwContents. // Retrieve the SafeBrowsingEnabled setting value of this AwContents.
virtual bool GetSafeBrowsingEnabled() const = 0; bool GetSafeBrowsingEnabled() const;
private:
bool pending_association_;
base::android::ScopedJavaGlobalRef<jobject> java_object_;
base::android::ScopedJavaGlobalRef<jobject> bg_thread_client_object_;
DISALLOW_COPY_AND_ASSIGN(AwContentsIoThreadClient);
}; };
} // namespace android_webview } // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_ #endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_IMPL_H_
#define ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_IMPL_H_
#include <stdint.h>
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "base/android/scoped_java_ref.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
namespace content {
class WebContents;
}
namespace net {
class URLRequest;
}
namespace android_webview {
class AwContentsIoThreadClientImpl : public AwContentsIoThreadClient {
public:
// Called when AwContents is created before there is a Java client.
static void RegisterPendingContents(content::WebContents* web_contents);
// Associates the |jclient| instance (which must implement the
// AwContentsIoThreadClient Java interface) with the |web_contents|.
// This should be called at most once per |web_contents|.
static void Associate(content::WebContents* web_contents,
const base::android::JavaRef<jobject>& jclient);
// Sets the |jclient| java instance to which service worker related
// callbacks should be delegated.
static void SetServiceWorkerIoThreadClient(
const base::android::JavaRef<jobject>& jclient,
const base::android::JavaRef<jobject>& browser_context);
// Either |pending_associate| is true or |jclient| holds a non-null
// Java object.
AwContentsIoThreadClientImpl(bool pending_associate,
const base::android::JavaRef<jobject>& jclient);
~AwContentsIoThreadClientImpl() override;
// Implementation of AwContentsIoThreadClient.
bool PendingAssociation() const override;
CacheMode GetCacheMode() const override;
void ShouldInterceptRequestAsync(
const net::URLRequest* request,
const ShouldInterceptRequestResultCallback callback) override;
bool ShouldBlockContentUrls() const override;
bool ShouldBlockFileUrls() const override;
bool ShouldAcceptThirdPartyCookies() const override;
bool GetSafeBrowsingEnabled() const override;
bool ShouldBlockNetworkLoads() const override;
private:
bool pending_association_;
base::android::ScopedJavaGlobalRef<jobject> java_object_;
base::android::ScopedJavaGlobalRef<jobject> bg_thread_client_object_;
DISALLOW_COPY_AND_ASSIGN(AwContentsIoThreadClientImpl);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_AW_CONTENTS_IO_THREAD_CLIENT_IMPL_H_
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "android_webview/browser/address_parser.h" #include "android_webview/browser/address_parser.h"
#include "android_webview/browser/aw_browser_context.h" #include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_contents_io_thread_client_impl.h" #include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_safe_browsing_config_helper.h" #include "android_webview/browser/aw_safe_browsing_config_helper.h"
#include "android_webview/browser/net/aw_url_request_context_getter.h" #include "android_webview/browser/net/aw_url_request_context_getter.h"
#include "android_webview/common/aw_version_info_values.h" #include "android_webview/common/aw_version_info_values.h"
...@@ -95,8 +95,8 @@ void SetServiceWorkerIoThreadClient( ...@@ -95,8 +95,8 @@ void SetServiceWorkerIoThreadClient(
const JavaParamRef<jclass>&, const JavaParamRef<jclass>&,
const base::android::JavaParamRef<jobject>& io_thread_client, const base::android::JavaParamRef<jobject>& io_thread_client,
const base::android::JavaParamRef<jobject>& browser_context) { const base::android::JavaParamRef<jobject>& browser_context) {
AwContentsIoThreadClientImpl::SetServiceWorkerIoThreadClient(io_thread_client, AwContentsIoThreadClient::SetServiceWorkerIoThreadClient(io_thread_client,
browser_context); browser_context);
} }
// static // static
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "android_webview/browser/aw_web_contents_delegate.h" #include "android_webview/browser/aw_web_contents_delegate.h"
#include "android_webview/browser/aw_contents.h" #include "android_webview/browser/aw_contents.h"
#include "android_webview/browser/aw_contents_io_thread_client_impl.h" #include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_javascript_dialog_manager.h" #include "android_webview/browser/aw_javascript_dialog_manager.h"
#include "android_webview/browser/find_helper.h" #include "android_webview/browser/find_helper.h"
#include "android_webview/browser/permission/media_access_permission_request.h" #include "android_webview/browser/permission/media_access_permission_request.h"
...@@ -183,7 +183,7 @@ void AwWebContentsDelegate::WebContentsCreated( ...@@ -183,7 +183,7 @@ void AwWebContentsDelegate::WebContentsCreated(
const std::string& frame_name, const std::string& frame_name,
const GURL& target_url, const GURL& target_url,
content::WebContents* new_contents) { content::WebContents* new_contents) {
AwContentsIoThreadClientImpl::RegisterPendingContents(new_contents); AwContentsIoThreadClient::RegisterPendingContents(new_contents);
} }
void AwWebContentsDelegate::CloseContents(WebContents* source) { void AwWebContentsDelegate::CloseContents(WebContents* source) {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_NATIVE_INTERCEPTED_REQUEST_DATA_IMPL_H_
#define ANDROID_WEBVIEW_NATIVE_INTERCEPTED_REQUEST_DATA_IMPL_H_
#include <memory>
#include "android_webview/browser/net/aw_web_resource_response.h"
#include "base/android/scoped_java_ref.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
namespace net {
class HttpResponseHeaders;
}
namespace android_webview {
class InputStream;
class AwWebResourceResponseImpl : public AwWebResourceResponse {
public:
// It is expected that |obj| is an instance of the Java-side
// org.chromium.android_webview.AwWebResourceResponse class.
AwWebResourceResponseImpl(const base::android::JavaRef<jobject>& obj);
~AwWebResourceResponseImpl() override;
std::unique_ptr<InputStream> GetInputStream(JNIEnv* env) const override;
bool GetMimeType(JNIEnv* env, std::string* mime_type) const override;
bool GetCharset(JNIEnv* env, std::string* charset) const override;
bool GetStatusInfo(JNIEnv* env,
int* status_code,
std::string* reason_phrase) const override;
bool GetResponseHeaders(JNIEnv* env,
net::HttpResponseHeaders* headers) const override;
private:
base::android::ScopedJavaGlobalRef<jobject> java_object_;
DISALLOW_COPY_AND_ASSIGN(AwWebResourceResponseImpl);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_NATIVE_INTERCEPTED_REQUEST_DATA_IMPL_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "android_webview/browser/input_stream_impl.h" #include "android_webview/browser/input_stream.h"
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
// Disable "Warnings treated as errors" for input_stream_jni as it's a Java // Disable "Warnings treated as errors" for input_stream_jni as it's a Java
...@@ -27,30 +27,24 @@ const int kExceptionThrownStatusCode = -2; ...@@ -27,30 +27,24 @@ const int kExceptionThrownStatusCode = -2;
} }
// Maximum number of bytes to be read in a single read. // Maximum number of bytes to be read in a single read.
const int InputStreamImpl::kBufferSize = 4096; const int InputStream::kBufferSize = 4096;
// static
const InputStreamImpl* InputStreamImpl::FromInputStream(
const InputStream* input_stream) {
return static_cast<const InputStreamImpl*>(input_stream);
}
// TODO: Use unsafe version for all Java_InputStream methods in this file // TODO: Use unsafe version for all Java_InputStream methods in this file
// once BUG 157880 is fixed and implement graceful exception handling. // once BUG 157880 is fixed and implement graceful exception handling.
InputStreamImpl::InputStreamImpl() {} InputStream::InputStream() {}
InputStreamImpl::InputStreamImpl(const JavaRef<jobject>& stream) InputStream::InputStream(const JavaRef<jobject>& stream) : jobject_(stream) {
: jobject_(stream) {
DCHECK(!stream.is_null()); DCHECK(!stream.is_null());
} }
InputStreamImpl::~InputStreamImpl() { InputStream::~InputStream() {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
Java_InputStreamUtil_close(env, jobject_); if (jobject_.obj())
Java_InputStreamUtil_close(env, jobject_);
} }
bool InputStreamImpl::BytesAvailable(int* bytes_available) const { bool InputStream::BytesAvailable(int* bytes_available) const {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
int bytes = Java_InputStreamUtil_available(env, jobject_); int bytes = Java_InputStreamUtil_available(env, jobject_);
if (bytes == kExceptionThrownStatusCode) if (bytes == kExceptionThrownStatusCode)
...@@ -59,7 +53,7 @@ bool InputStreamImpl::BytesAvailable(int* bytes_available) const { ...@@ -59,7 +53,7 @@ bool InputStreamImpl::BytesAvailable(int* bytes_available) const {
return true; return true;
} }
bool InputStreamImpl::Skip(int64_t n, int64_t* bytes_skipped) { bool InputStream::Skip(int64_t n, int64_t* bytes_skipped) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
int bytes = Java_InputStreamUtil_skip(env, jobject_, n); int bytes = Java_InputStreamUtil_skip(env, jobject_, n);
if (bytes < 0) if (bytes < 0)
...@@ -70,7 +64,7 @@ bool InputStreamImpl::Skip(int64_t n, int64_t* bytes_skipped) { ...@@ -70,7 +64,7 @@ bool InputStreamImpl::Skip(int64_t n, int64_t* bytes_skipped) {
return true; return true;
} }
bool InputStreamImpl::Read(net::IOBuffer* dest, int length, int* bytes_read) { bool InputStream::Read(net::IOBuffer* dest, int length, int* bytes_read) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
if (!buffer_.obj()) { if (!buffer_.obj()) {
// Allocate transfer buffer. // Allocate transfer buffer.
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include <stdint.h> #include <stdint.h>
#include "base/android/scoped_java_ref.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
namespace net { namespace net {
class IOBuffer; class IOBuffer;
} }
...@@ -19,20 +23,29 @@ namespace android_webview { ...@@ -19,20 +23,29 @@ namespace android_webview {
// methods concurrently might have undefined results. // methods concurrently might have undefined results.
class InputStream { class InputStream {
public: public:
virtual ~InputStream() {} // Maximum size of |buffer_|.
static const int kBufferSize;
// |stream| should be an instance of the InputStream Java class.
// |stream| can't be null.
InputStream(const base::android::JavaRef<jobject>& stream);
virtual ~InputStream();
// Gets the underlying Java object. Guaranteed non-NULL.
const base::android::JavaRef<jobject>& jobj() const { return jobject_; }
// Sets |bytes_available| to the number of bytes that can be read (or skipped // Sets |bytes_available| to the number of bytes that can be read (or skipped
// over) from this input stream without blocking by the next caller of a // over) from this input stream without blocking by the next caller of a
// method for this input stream. // method for this input stream.
// Returns true if completed successfully or false if an exception was // Returns true if completed successfully or false if an exception was
// thrown. // thrown.
virtual bool BytesAvailable(int* bytes_available) const = 0; virtual bool BytesAvailable(int* bytes_available) const;
// Skips over and discards |n| bytes of data from this input stream. Sets // Skips over and discards |n| bytes of data from this input stream. Sets
// |bytes_skipped| to the number of of bytes skipped. // |bytes_skipped| to the number of of bytes skipped.
// Returns true if completed successfully or false if an exception was // Returns true if completed successfully or false if an exception was
// thrown. // thrown.
virtual bool Skip(int64_t n, int64_t* bytes_skipped) = 0; virtual bool Skip(int64_t n, int64_t* bytes_skipped);
// Reads at most |length| bytes into |dest|. Sets |bytes_read| to the total // Reads at most |length| bytes into |dest|. Sets |bytes_read| to the total
// number of bytes read into |dest| or 0 if there is no more data because the // number of bytes read into |dest| or 0 if there is no more data because the
...@@ -40,10 +53,17 @@ class InputStream { ...@@ -40,10 +53,17 @@ class InputStream {
// |dest| must be at least |length| in size. // |dest| must be at least |length| in size.
// Returns true if completed successfully or false if an exception was // Returns true if completed successfully or false if an exception was
// thrown. // thrown.
virtual bool Read(net::IOBuffer* dest, int length, int* bytes_read) = 0; virtual bool Read(net::IOBuffer* dest, int length, int* bytes_read);
protected: protected:
InputStream() {} // Parameterless constructor exposed for testing.
InputStream();
private:
base::android::ScopedJavaGlobalRef<jobject> jobject_;
base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
DISALLOW_COPY_AND_ASSIGN(InputStream);
}; };
} // namespace android_webview } // namespace android_webview
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_
#define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_
#include <stdint.h>
#include "android_webview/browser/input_stream.h"
#include "base/android/scoped_java_ref.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
namespace net {
class IOBuffer;
}
namespace android_webview {
class InputStreamImpl : public InputStream {
public:
// Maximum size of |buffer_|.
static const int kBufferSize;
static const InputStreamImpl* FromInputStream(
const InputStream* input_stream);
// |stream| should be an instance of the InputStream Java class.
// |stream| can't be null.
InputStreamImpl(const base::android::JavaRef<jobject>& stream);
~InputStreamImpl() override;
// Gets the underlying Java object. Guaranteed non-NULL.
const base::android::JavaRef<jobject>& jobj() const { return jobject_; }
// InputStream implementation.
bool BytesAvailable(int* bytes_available) const override;
bool Skip(int64_t n, int64_t* bytes_skipped) override;
bool Read(net::IOBuffer* dest, int length, int* bytes_read) override;
protected:
// Parameterless constructor exposed for testing.
InputStreamImpl();
private:
base::android::ScopedJavaGlobalRef<jobject> jobject_;
base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
DISALLOW_COPY_AND_ASSIGN(InputStreamImpl);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <memory> #include <memory>
#include "android_webview/browser/input_stream_impl.h" #include "android_webview/browser/input_stream.h"
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "jni/InputStreamUnittest_jni.h" #include "jni/InputStreamUnittest_jni.h"
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using android_webview::InputStream; using android_webview::InputStream;
using android_webview::InputStreamImpl;
using base::android::AttachCurrentThread; using base::android::AttachCurrentThread;
using base::android::ScopedJavaLocalRef; using base::android::ScopedJavaLocalRef;
using net::IOBuffer; using net::IOBuffer;
...@@ -48,7 +47,7 @@ class InputStreamTest : public Test { ...@@ -48,7 +47,7 @@ class InputStreamTest : public Test {
EXPECT_FALSE(counting_jstream.is_null()); EXPECT_FALSE(counting_jstream.is_null());
std::unique_ptr<InputStream> input_stream( std::unique_ptr<InputStream> input_stream(
new InputStreamImpl(counting_jstream)); new InputStream(counting_jstream));
scoped_refptr<IOBuffer> buffer = new IOBuffer(bytes_requested); scoped_refptr<IOBuffer> buffer = new IOBuffer(bytes_requested);
EXPECT_TRUE(input_stream->Read(buffer.get(), bytes_requested, bytes_read)); EXPECT_TRUE(input_stream->Read(buffer.get(), bytes_requested, bytes_read));
...@@ -63,7 +62,7 @@ TEST_F(InputStreamTest, ReadEmptyStream) { ...@@ -63,7 +62,7 @@ TEST_F(InputStreamTest, ReadEmptyStream) {
Java_InputStreamUnittest_getEmptyStream(env_); Java_InputStreamUnittest_getEmptyStream(env_);
EXPECT_FALSE(empty_jstream.is_null()); EXPECT_FALSE(empty_jstream.is_null());
std::unique_ptr<InputStream> input_stream(new InputStreamImpl(empty_jstream)); std::unique_ptr<InputStream> input_stream(new InputStream(empty_jstream));
const int bytes_requested = 10; const int bytes_requested = 10;
int bytes_read = 0; int bytes_read = 0;
scoped_refptr<IOBuffer> buffer = new IOBuffer(bytes_requested); scoped_refptr<IOBuffer> buffer = new IOBuffer(bytes_requested);
...@@ -87,7 +86,7 @@ TEST_F(InputStreamTest, ReadStreamCompletely) { ...@@ -87,7 +86,7 @@ TEST_F(InputStreamTest, ReadStreamCompletely) {
} }
TEST_F(InputStreamTest, TryReadMoreThanBuffer) { TEST_F(InputStreamTest, TryReadMoreThanBuffer) {
const int buffer_size = 3 * InputStreamImpl::kBufferSize; const int buffer_size = 3 * InputStream::kBufferSize;
int bytes_read = 0; int bytes_read = 0;
DoReadCountedStreamTest(buffer_size, buffer_size * 2, &bytes_read); DoReadCountedStreamTest(buffer_size, buffer_size * 2, &bytes_read);
EXPECT_EQ(buffer_size, bytes_read); EXPECT_EQ(buffer_size, bytes_read);
...@@ -105,14 +104,14 @@ TEST_F(InputStreamTest, CheckContentsReadCorrectly) { ...@@ -105,14 +104,14 @@ TEST_F(InputStreamTest, CheckContentsReadCorrectly) {
} }
TEST_F(InputStreamTest, ReadLargeStreamPartial) { TEST_F(InputStreamTest, ReadLargeStreamPartial) {
const int bytes_requested = 3 * InputStreamImpl::kBufferSize; const int bytes_requested = 3 * InputStream::kBufferSize;
int bytes_read = 0; int bytes_read = 0;
DoReadCountedStreamTest(bytes_requested + 32, bytes_requested, &bytes_read); DoReadCountedStreamTest(bytes_requested + 32, bytes_requested, &bytes_read);
EXPECT_EQ(bytes_requested, bytes_read); EXPECT_EQ(bytes_requested, bytes_read);
} }
TEST_F(InputStreamTest, ReadLargeStreamCompletely) { TEST_F(InputStreamTest, ReadLargeStreamCompletely) {
const int bytes_requested = 3 * InputStreamImpl::kBufferSize; const int bytes_requested = 3 * InputStream::kBufferSize;
int bytes_read = 0; int bytes_read = 0;
DoReadCountedStreamTest(bytes_requested, bytes_requested, &bytes_read); DoReadCountedStreamTest(bytes_requested, bytes_requested, &bytes_read);
EXPECT_EQ(bytes_requested, bytes_read); EXPECT_EQ(bytes_requested, bytes_read);
...@@ -123,7 +122,7 @@ TEST_F(InputStreamTest, DoesNotCrashWhenExceptionThrown) { ...@@ -123,7 +122,7 @@ TEST_F(InputStreamTest, DoesNotCrashWhenExceptionThrown) {
Java_InputStreamUnittest_getThrowingStream(env_); Java_InputStreamUnittest_getThrowingStream(env_);
EXPECT_FALSE(throw_jstream.is_null()); EXPECT_FALSE(throw_jstream.is_null());
std::unique_ptr<InputStream> input_stream(new InputStreamImpl(throw_jstream)); std::unique_ptr<InputStream> input_stream(new InputStream(throw_jstream));
int64_t bytes_skipped; int64_t bytes_skipped;
EXPECT_FALSE(input_stream->Skip(10, &bytes_skipped)); EXPECT_FALSE(input_stream->Skip(10, &bytes_skipped));
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "android_webview/browser/aw_web_resource_response_impl.h" #include "android_webview/browser/net/aw_web_resource_response.h"
#include "android_webview/browser/input_stream_impl.h" #include "android_webview/browser/input_stream.h"
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
...@@ -19,23 +19,23 @@ using base::android::AppendJavaStringArrayToStringVector; ...@@ -19,23 +19,23 @@ using base::android::AppendJavaStringArrayToStringVector;
namespace android_webview { namespace android_webview {
AwWebResourceResponseImpl::AwWebResourceResponseImpl( AwWebResourceResponse::AwWebResourceResponse(
const base::android::JavaRef<jobject>& obj) const base::android::JavaRef<jobject>& obj)
: java_object_(obj) {} : java_object_(obj) {}
AwWebResourceResponseImpl::~AwWebResourceResponseImpl() {} AwWebResourceResponse::~AwWebResourceResponse() {}
std::unique_ptr<InputStream> AwWebResourceResponseImpl::GetInputStream( std::unique_ptr<InputStream> AwWebResourceResponse::GetInputStream(
JNIEnv* env) const { JNIEnv* env) const {
ScopedJavaLocalRef<jobject> jstream = ScopedJavaLocalRef<jobject> jstream =
Java_AwWebResourceResponse_getData(env, java_object_); Java_AwWebResourceResponse_getData(env, java_object_);
if (jstream.is_null()) if (jstream.is_null())
return std::unique_ptr<InputStream>(); return std::unique_ptr<InputStream>();
return base::MakeUnique<InputStreamImpl>(jstream); return base::MakeUnique<InputStream>(jstream);
} }
bool AwWebResourceResponseImpl::GetMimeType(JNIEnv* env, bool AwWebResourceResponse::GetMimeType(JNIEnv* env,
std::string* mime_type) const { std::string* mime_type) const {
ScopedJavaLocalRef<jstring> jstring_mime_type = ScopedJavaLocalRef<jstring> jstring_mime_type =
Java_AwWebResourceResponse_getMimeType(env, java_object_); Java_AwWebResourceResponse_getMimeType(env, java_object_);
if (jstring_mime_type.is_null()) if (jstring_mime_type.is_null())
...@@ -44,8 +44,8 @@ bool AwWebResourceResponseImpl::GetMimeType(JNIEnv* env, ...@@ -44,8 +44,8 @@ bool AwWebResourceResponseImpl::GetMimeType(JNIEnv* env,
return true; return true;
} }
bool AwWebResourceResponseImpl::GetCharset(JNIEnv* env, bool AwWebResourceResponse::GetCharset(JNIEnv* env,
std::string* charset) const { std::string* charset) const {
ScopedJavaLocalRef<jstring> jstring_charset = ScopedJavaLocalRef<jstring> jstring_charset =
Java_AwWebResourceResponse_getCharset(env, java_object_); Java_AwWebResourceResponse_getCharset(env, java_object_);
if (jstring_charset.is_null()) if (jstring_charset.is_null())
...@@ -54,10 +54,9 @@ bool AwWebResourceResponseImpl::GetCharset(JNIEnv* env, ...@@ -54,10 +54,9 @@ bool AwWebResourceResponseImpl::GetCharset(JNIEnv* env,
return true; return true;
} }
bool AwWebResourceResponseImpl::GetStatusInfo( bool AwWebResourceResponse::GetStatusInfo(JNIEnv* env,
JNIEnv* env, int* status_code,
int* status_code, std::string* reason_phrase) const {
std::string* reason_phrase) const {
int status = Java_AwWebResourceResponse_getStatusCode(env, java_object_); int status = Java_AwWebResourceResponse_getStatusCode(env, java_object_);
ScopedJavaLocalRef<jstring> jstring_reason_phrase = ScopedJavaLocalRef<jstring> jstring_reason_phrase =
Java_AwWebResourceResponse_getReasonPhrase(env, java_object_); Java_AwWebResourceResponse_getReasonPhrase(env, java_object_);
...@@ -68,7 +67,7 @@ bool AwWebResourceResponseImpl::GetStatusInfo( ...@@ -68,7 +67,7 @@ bool AwWebResourceResponseImpl::GetStatusInfo(
return true; return true;
} }
bool AwWebResourceResponseImpl::GetResponseHeaders( bool AwWebResourceResponse::GetResponseHeaders(
JNIEnv* env, JNIEnv* env,
net::HttpResponseHeaders* headers) const { net::HttpResponseHeaders* headers) const {
ScopedJavaLocalRef<jobjectArray> jstringArray_headerNames = ScopedJavaLocalRef<jobjectArray> jstringArray_headerNames =
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <string> #include <string>
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
namespace net { namespace net {
...@@ -24,24 +26,26 @@ class InputStream; ...@@ -24,24 +26,26 @@ class InputStream;
// particular URLRequest. // particular URLRequest.
class AwWebResourceResponse { class AwWebResourceResponse {
public: public:
virtual ~AwWebResourceResponse() {} // It is expected that |obj| is an instance of the Java-side
// org.chromium.android_webview.AwWebResourceResponse class.
virtual std::unique_ptr<InputStream> GetInputStream(JNIEnv* env) const = 0; AwWebResourceResponse(const base::android::JavaRef<jobject>& obj);
virtual bool GetMimeType(JNIEnv* env, std::string* mime_type) const = 0; ~AwWebResourceResponse();
virtual bool GetCharset(JNIEnv* env, std::string* charset) const = 0;
virtual bool GetStatusInfo(JNIEnv* env, std::unique_ptr<InputStream> GetInputStream(JNIEnv* env) const;
int* status_code, bool GetMimeType(JNIEnv* env, std::string* mime_type) const;
std::string* reason_phrase) const = 0; bool GetCharset(JNIEnv* env, std::string* charset) const;
bool GetStatusInfo(JNIEnv* env,
int* status_code,
std::string* reason_phrase) const;
// If true is returned then |headers| contain the headers, if false is // If true is returned then |headers| contain the headers, if false is
// returned |headers| were not updated. // returned |headers| were not updated.
virtual bool GetResponseHeaders( bool GetResponseHeaders(JNIEnv* env, net::HttpResponseHeaders* headers) const;
JNIEnv* env,
net::HttpResponseHeaders* headers) const = 0;
protected:
AwWebResourceResponse() {}
private: private:
AwWebResourceResponse();
base::android::ScopedJavaGlobalRef<jobject> java_object_;
DISALLOW_COPY_AND_ASSIGN(AwWebResourceResponse); DISALLOW_COPY_AND_ASSIGN(AwWebResourceResponse);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment