summaryrefslogtreecommitdiff
path: root/android_webview/browser
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2014-06-25 10:30:53 +0100
committerTorne (Richard Coles) <torne@google.com>2014-06-25 10:30:53 +0100
commit6d86b77056ed63eb6871182f42a9fd5f07550f90 (patch)
tree4bd56255660f52e406fbd45083c006cd6ddb2877 /android_webview/browser
parente9f930807da3850e29ecc641d2becc0403b5709c (diff)
downloadchromium_org-6d86b77056ed63eb6871182f42a9fd5f07550f90.tar.gz
Merge from Chromium at DEPS revision 278856
This commit was generated by merge_to_master.py. Change-Id: If3807744d3e5d3ee84b897bd2d099a2b7ed2e7a3
Diffstat (limited to 'android_webview/browser')
-rw-r--r--android_webview/browser/aw_contents_io_thread_client.h4
-rw-r--r--android_webview/browser/aw_request_interceptor.cc24
-rw-r--r--android_webview/browser/aw_request_interceptor.h4
-rw-r--r--android_webview/browser/aw_web_resource_response.cc (renamed from android_webview/browser/intercepted_request_data.cc)44
-rw-r--r--android_webview/browser/aw_web_resource_response.h (renamed from android_webview/browser/intercepted_request_data.h)27
-rw-r--r--android_webview/browser/net/android_stream_reader_url_request_job.cc4
-rw-r--r--android_webview/browser/net/android_stream_reader_url_request_job.h4
-rw-r--r--android_webview/browser/net/android_stream_reader_url_request_job_unittest.cc64
8 files changed, 137 insertions, 38 deletions
diff --git a/android_webview/browser/aw_contents_io_thread_client.h b/android_webview/browser/aw_contents_io_thread_client.h
index 0ac29fcb46..cb8bc26d19 100644
--- a/android_webview/browser/aw_contents_io_thread_client.h
+++ b/android_webview/browser/aw_contents_io_thread_client.h
@@ -17,7 +17,7 @@ class URLRequest;
namespace android_webview {
-class InterceptedRequestData;
+class AwWebResourceResponse;
// This class provides a means of calling Java methods on an instance that has
// a 1:1 relationship with a WebContents instance directly from the IO thread.
@@ -68,7 +68,7 @@ class AwContentsIoThreadClient {
int child_render_frame_id);
// This method is called on the IO thread only.
- virtual scoped_ptr<InterceptedRequestData> ShouldInterceptRequest(
+ virtual scoped_ptr<AwWebResourceResponse> ShouldInterceptRequest(
const GURL& location,
const net::URLRequest* request) = 0;
diff --git a/android_webview/browser/aw_request_interceptor.cc b/android_webview/browser/aw_request_interceptor.cc
index a53061b684..381a8ab03c 100644
--- a/android_webview/browser/aw_request_interceptor.cc
+++ b/android_webview/browser/aw_request_interceptor.cc
@@ -5,7 +5,7 @@
#include "android_webview/browser/aw_request_interceptor.h"
#include "android_webview/browser/aw_contents_io_thread_client.h"
-#include "android_webview/browser/intercepted_request_data.h"
+#include "android_webview/browser/aw_web_resource_response.h"
#include "base/android/jni_string.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_thread.h"
@@ -34,21 +34,21 @@ AwRequestInterceptor::AwRequestInterceptor() {
AwRequestInterceptor::~AwRequestInterceptor() {
}
-scoped_ptr<InterceptedRequestData>
-AwRequestInterceptor::QueryForInterceptedRequestData(
+scoped_ptr<AwWebResourceResponse>
+AwRequestInterceptor::QueryForAwWebResourceResponse(
const GURL& location,
net::URLRequest* request) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
int render_process_id, render_frame_id;
if (!ResourceRequestInfo::GetRenderFrameForRequest(
request, &render_process_id, &render_frame_id))
- return scoped_ptr<InterceptedRequestData>();
+ return scoped_ptr<AwWebResourceResponse>();
scoped_ptr<AwContentsIoThreadClient> io_thread_client =
AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
if (!io_thread_client.get())
- return scoped_ptr<InterceptedRequestData>();
+ return scoped_ptr<AwWebResourceResponse>();
return io_thread_client->ShouldInterceptRequest(location, request).Pass();
}
@@ -58,7 +58,7 @@ net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest(
net::NetworkDelegate* network_delegate) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // See if we've already found out the intercepted_request_data for this
+ // See if we've already found out the aw_web_resource_response for this
// request.
// This is done not only for efficiency reasons, but also for correctness
// as it is possible for the Interceptor chain to be invoked more than once
@@ -70,15 +70,15 @@ net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest(
request->SetUserData(kRequestAlreadyQueriedDataKey,
new base::SupportsUserData::Data());
- scoped_ptr<InterceptedRequestData> intercepted_request_data =
- QueryForInterceptedRequestData(request->url(), request);
+ scoped_ptr<AwWebResourceResponse> aw_web_resource_response =
+ QueryForAwWebResourceResponse(request->url(), request);
- if (!intercepted_request_data)
+ if (!aw_web_resource_response)
return NULL;
- // The newly created job will own the InterceptedRequestData.
- return InterceptedRequestData::CreateJobFor(
- intercepted_request_data.Pass(), request, network_delegate);
+ // The newly created job will own the AwWebResourceResponse.
+ return AwWebResourceResponse::CreateJobFor(
+ aw_web_resource_response.Pass(), request, network_delegate);
}
} // namespace android_webview
diff --git a/android_webview/browser/aw_request_interceptor.h b/android_webview/browser/aw_request_interceptor.h
index b83ab32e23..813abbe8f4 100644
--- a/android_webview/browser/aw_request_interceptor.h
+++ b/android_webview/browser/aw_request_interceptor.h
@@ -19,7 +19,7 @@ class NetworkDelegate;
namespace android_webview {
-class InterceptedRequestData;
+class AwWebResourceResponse;
// This class allows the Java-side embedder to substitute the default
// URLRequest of a given request for an alternative job that will read data
@@ -35,7 +35,7 @@ class AwRequestInterceptor : public net::URLRequestInterceptor {
net::NetworkDelegate* network_delegate) const OVERRIDE;
private:
- scoped_ptr<InterceptedRequestData> QueryForInterceptedRequestData(
+ scoped_ptr<AwWebResourceResponse> QueryForAwWebResourceResponse(
const GURL& location,
net::URLRequest* request) const;
diff --git a/android_webview/browser/intercepted_request_data.cc b/android_webview/browser/aw_web_resource_response.cc
index 6e25ce1447..412d9c2a04 100644
--- a/android_webview/browser/intercepted_request_data.cc
+++ b/android_webview/browser/aw_web_resource_response.cc
@@ -1,11 +1,13 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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.
-#include "android_webview/browser/intercepted_request_data.h"
+#include "android_webview/browser/aw_web_resource_response.h"
#include "android_webview/browser/input_stream.h"
#include "android_webview/browser/net/android_stream_reader_url_request_job.h"
+#include "base/strings/string_number_conversions.h"
+#include "net/http/http_response_headers.h"
namespace android_webview {
@@ -15,14 +17,14 @@ class StreamReaderJobDelegateImpl
: public AndroidStreamReaderURLRequestJob::Delegate {
public:
StreamReaderJobDelegateImpl(
- scoped_ptr<InterceptedRequestData> intercepted_request_data)
- : intercepted_request_data_(intercepted_request_data.Pass()) {
- DCHECK(intercepted_request_data_);
+ scoped_ptr<AwWebResourceResponse> aw_web_resource_response)
+ : aw_web_resource_response_(aw_web_resource_response.Pass()) {
+ DCHECK(aw_web_resource_response_);
}
virtual scoped_ptr<InputStream> OpenInputStream(JNIEnv* env,
const GURL& url) OVERRIDE {
- return intercepted_request_data_->GetInputStream(env).Pass();
+ return aw_web_resource_response_->GetInputStream(env).Pass();
}
virtual void OnInputStreamOpenFailed(net::URLRequest* request,
@@ -34,28 +36,44 @@ class StreamReaderJobDelegateImpl
net::URLRequest* request,
android_webview::InputStream* stream,
std::string* mime_type) OVERRIDE {
- return intercepted_request_data_->GetMimeType(env, mime_type);
+ return aw_web_resource_response_->GetMimeType(env, mime_type);
}
virtual bool GetCharset(JNIEnv* env,
net::URLRequest* request,
android_webview::InputStream* stream,
std::string* charset) OVERRIDE {
- return intercepted_request_data_->GetCharset(env, charset);
+ return aw_web_resource_response_->GetCharset(env, charset);
+ }
+
+ virtual void AppendResponseHeaders(
+ JNIEnv* env,
+ net::HttpResponseHeaders* headers) OVERRIDE {
+ int status_code;
+ std::string reason_phrase;
+ if (aw_web_resource_response_->GetStatusInfo(
+ env, &status_code, &reason_phrase)) {
+ std::string status_line("HTTP/1.1 ");
+ status_line.append(base::IntToString(status_code));
+ status_line.append(" ");
+ status_line.append(reason_phrase);
+ headers->ReplaceStatusLine(status_line);
+ }
+ aw_web_resource_response_->GetResponseHeaders(env, headers);
}
private:
- scoped_ptr<InterceptedRequestData> intercepted_request_data_;
+ scoped_ptr<AwWebResourceResponse> aw_web_resource_response_;
};
} // namespace
// static
-net::URLRequestJob* InterceptedRequestData::CreateJobFor(
- scoped_ptr<InterceptedRequestData> intercepted_request_data,
+net::URLRequestJob* AwWebResourceResponse::CreateJobFor(
+ scoped_ptr<AwWebResourceResponse> aw_web_resource_response,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) {
- DCHECK(intercepted_request_data);
+ DCHECK(aw_web_resource_response);
DCHECK(request);
DCHECK(network_delegate);
@@ -63,7 +81,7 @@ net::URLRequestJob* InterceptedRequestData::CreateJobFor(
request,
network_delegate,
make_scoped_ptr(
- new StreamReaderJobDelegateImpl(intercepted_request_data.Pass()))
+ new StreamReaderJobDelegateImpl(aw_web_resource_response.Pass()))
.PassAs<AndroidStreamReaderURLRequestJob::Delegate>());
}
diff --git a/android_webview/browser/intercepted_request_data.h b/android_webview/browser/aw_web_resource_response.h
index acf031d338..34963606ff 100644
--- a/android_webview/browser/intercepted_request_data.h
+++ b/android_webview/browser/aw_web_resource_response.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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.
@@ -11,9 +11,10 @@
#include "base/memory/scoped_ptr.h"
namespace net {
+class HttpResponseHeaders;
+class NetworkDelegate;
class URLRequest;
class URLRequestJob;
-class NetworkDelegate;
}
namespace android_webview {
@@ -22,28 +23,36 @@ class InputStream;
// This class represents the Java-side data that is to be used to complete a
// particular URLRequest.
-class InterceptedRequestData {
+class AwWebResourceResponse {
public:
- virtual ~InterceptedRequestData() {}
+ virtual ~AwWebResourceResponse() {}
virtual scoped_ptr<InputStream> GetInputStream(JNIEnv* env) const = 0;
virtual bool GetMimeType(JNIEnv* env, std::string* mime_type) const = 0;
virtual bool GetCharset(JNIEnv* env, std::string* charset) const = 0;
+ virtual bool GetStatusInfo(JNIEnv* env,
+ int* status_code,
+ std::string* reason_phrase) const = 0;
+ // If true is returned then |headers| contain the headers, if false is
+ // returned |headers| were not updated.
+ virtual bool GetResponseHeaders(
+ JNIEnv* env,
+ net::HttpResponseHeaders* headers) const = 0;
// This creates a URLRequestJob for the |request| wich will read data from
- // the |intercepted_request_data| structure (instead of going to the network
+ // the |aw_web_resource_response| structure (instead of going to the network
// or to the cache).
- // The newly created job takes ownership of |intercepted_request_data|.
+ // The newly created job takes ownership of |aw_web_resource_response|.
static net::URLRequestJob* CreateJobFor(
- scoped_ptr<InterceptedRequestData> intercepted_request_data,
+ scoped_ptr<AwWebResourceResponse> aw_web_resource_response,
net::URLRequest* request,
net::NetworkDelegate* network_delegate);
protected:
- InterceptedRequestData() {}
+ AwWebResourceResponse() {}
private:
- DISALLOW_COPY_AND_ASSIGN(InterceptedRequestData);
+ DISALLOW_COPY_AND_ASSIGN(AwWebResourceResponse);
};
} // namespace android_webview
diff --git a/android_webview/browser/net/android_stream_reader_url_request_job.cc b/android_webview/browser/net/android_stream_reader_url_request_job.cc
index d7b407ecc7..5af452eb80 100644
--- a/android_webview/browser/net/android_stream_reader_url_request_job.cc
+++ b/android_webview/browser/net/android_stream_reader_url_request_job.cc
@@ -324,6 +324,10 @@ void AndroidStreamReaderURLRequestJob::HeadersComplete(
}
}
+ JNIEnv* env = AttachCurrentThread();
+ DCHECK(env);
+ delegate_->AppendResponseHeaders(env, headers);
+
// Indicate that the response had been obtained via shouldInterceptRequest.
headers->AddHeader(kResponseHeaderViaShouldInterceptRequest);
diff --git a/android_webview/browser/net/android_stream_reader_url_request_job.h b/android_webview/browser/net/android_stream_reader_url_request_job.h
index c516b760f3..b7d6a621c8 100644
--- a/android_webview/browser/net/android_stream_reader_url_request_job.h
+++ b/android_webview/browser/net/android_stream_reader_url_request_job.h
@@ -26,6 +26,7 @@ class TaskRunner;
}
namespace net {
+class HttpResponseHeaders;
class HttpResponseInfo;
class URLRequest;
}
@@ -66,6 +67,9 @@ class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
android_webview::InputStream* stream,
std::string* charset) = 0;
+ virtual void AppendResponseHeaders(JNIEnv* env,
+ net::HttpResponseHeaders* headers) = 0;
+
virtual ~Delegate() {}
};
diff --git a/android_webview/browser/net/android_stream_reader_url_request_job_unittest.cc b/android_webview/browser/net/android_stream_reader_url_request_job_unittest.cc
index f09b5c5343..e419dd1dfd 100644
--- a/android_webview/browser/net/android_stream_reader_url_request_job_unittest.cc
+++ b/android_webview/browser/net/android_stream_reader_url_request_job_unittest.cc
@@ -12,6 +12,7 @@
#include "base/strings/stringprintf.h"
#include "net/base/request_priority.h"
#include "net/http/http_byte_range.h"
+#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_test_util.h"
@@ -93,6 +94,12 @@ class StreamReaderDelegate :
std::string* charset) OVERRIDE {
return false;
}
+
+ virtual void AppendResponseHeaders(
+ JNIEnv* env,
+ net::HttpResponseHeaders* headers) OVERRIDE {
+ // no-op
+ }
};
class NullStreamReaderDelegate : public StreamReaderDelegate {
@@ -106,6 +113,34 @@ class NullStreamReaderDelegate : public StreamReaderDelegate {
}
};
+class HeaderAlteringStreamReaderDelegate : public NullStreamReaderDelegate {
+ public:
+ HeaderAlteringStreamReaderDelegate() {}
+
+ virtual void AppendResponseHeaders(
+ JNIEnv* env,
+ net::HttpResponseHeaders* headers) OVERRIDE {
+ headers->ReplaceStatusLine(kStatusLine);
+ std::string headerLine(kCustomHeaderName);
+ headerLine.append(": ");
+ headerLine.append(kCustomHeaderValue);
+ headers->AddHeader(headerLine);
+ }
+
+ static const int kResponseCode;
+ static const char* kStatusLine;
+ static const char* kCustomHeaderName;
+ static const char* kCustomHeaderValue;
+};
+
+const int HeaderAlteringStreamReaderDelegate::kResponseCode = 401;
+const char* HeaderAlteringStreamReaderDelegate::kStatusLine =
+ "HTTP/1.1 401 Gone";
+const char* HeaderAlteringStreamReaderDelegate::kCustomHeaderName =
+ "X-Test-Header";
+const char* HeaderAlteringStreamReaderDelegate::kCustomHeaderValue =
+ "TestHeaderValue";
+
class MockInputStreamReader : public InputStreamReader {
public:
MockInputStreamReader() : InputStreamReader(new NotImplInputStream()) {}
@@ -245,6 +280,35 @@ TEST_F(AndroidStreamReaderURLRequestJobTest, ReadWithNullStream) {
EXPECT_EQ(404, req_->GetResponseCode());
}
+TEST_F(AndroidStreamReaderURLRequestJobTest, ModifyHeadersAndStatus) {
+ SetUpTestJob(scoped_ptr<InputStreamReader>(),
+ make_scoped_ptr(new HeaderAlteringStreamReaderDelegate())
+ .PassAs<AndroidStreamReaderURLRequestJob::Delegate>());
+ req_->Start();
+
+ // The TestDelegate will quit the message loop on request completion.
+ base::MessageLoop::current()->Run();
+
+ // The request_failed() method is named confusingly but all it checks is
+ // whether the request got as far as calling NotifyHeadersComplete.
+ EXPECT_FALSE(url_request_delegate_.request_failed());
+ EXPECT_EQ(1, network_delegate_.completed_requests());
+ // A null input stream shouldn't result in an error. See crbug.com/180950.
+ EXPECT_EQ(0, network_delegate_.error_count());
+ EXPECT_EQ(HeaderAlteringStreamReaderDelegate::kResponseCode,
+ req_->GetResponseCode());
+ EXPECT_EQ(HeaderAlteringStreamReaderDelegate::kStatusLine,
+ req_->response_headers()->GetStatusLine());
+ EXPECT_TRUE(req_->response_headers()->HasHeader(
+ HeaderAlteringStreamReaderDelegate::kCustomHeaderName));
+ std::string header_value;
+ EXPECT_TRUE(req_->response_headers()->EnumerateHeader(
+ NULL, HeaderAlteringStreamReaderDelegate::kCustomHeaderName,
+ &header_value));
+ EXPECT_EQ(HeaderAlteringStreamReaderDelegate::kCustomHeaderValue,
+ header_value);
+}
+
TEST_F(AndroidStreamReaderURLRequestJobTest, ReadPartOfStream) {
const int bytes_available = 128;
const int offset = 32;