summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authoramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 16:58:06 +0000
committeramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 16:58:06 +0000
commit2e4633c5b2a040357659646b951b632bff3055f5 (patch)
treef4a4ab7e636963a940118157cbec5dd4cc7b4ad4 /chrome/common
parentdba526fa150d26deae1a10f54bc3b72ed36e5520 (diff)
downloadchromium_src-2e4633c5b2a040357659646b951b632bff3055f5.zip
chromium_src-2e4633c5b2a040357659646b951b632bff3055f5.tar.gz
chromium_src-2e4633c5b2a040357659646b951b632bff3055f5.tar.bz2
A prototype of resource loading through automation
In a test scenario where we need to load resources over automation, we intercept the URL reqeusts and serve them using automation IPCs. This resource loading can be enabled per tab created by automation. BUG=none TEST=none Review URL: http://codereview.chromium.org/145024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20267 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/ipc_message_utils.h53
-rw-r--r--chrome/common/net/url_request_intercept_job.cc23
-rw-r--r--chrome/common/net/url_request_intercept_job.h8
-rw-r--r--chrome/common/notification_type.h12
-rw-r--r--chrome/common/render_messages.h53
5 files changed, 84 insertions, 65 deletions
diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h
index 53c7974..c63eb6c 100644
--- a/chrome/common/ipc_message_utils.h
+++ b/chrome/common/ipc_message_utils.h
@@ -21,6 +21,7 @@
#include "chrome/common/ipc_sync_message.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/common/transport_dib.h"
+#include "net/url_request/url_request_status.h"
#include "webkit/glue/webcursor.h"
#include "webkit/glue/window_open_disposition.h"
@@ -943,6 +944,58 @@ struct ParamTraits<TransportDIB::Id> {
};
#endif
+// Traits for URLRequestStatus
+template <>
+struct ParamTraits<URLRequestStatus> {
+ typedef URLRequestStatus param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, static_cast<int>(p.status()));
+ WriteParam(m, p.os_error());
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int status, os_error;
+ if (!ReadParam(m, iter, &status) ||
+ !ReadParam(m, iter, &os_error))
+ return false;
+ r->set_status(static_cast<URLRequestStatus::Status>(status));
+ r->set_os_error(os_error);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ std::wstring status;
+ switch (p.status()) {
+ case URLRequestStatus::SUCCESS:
+ status = L"SUCCESS";
+ break;
+ case URLRequestStatus::IO_PENDING:
+ status = L"IO_PENDING ";
+ break;
+ case URLRequestStatus::HANDLED_EXTERNALLY:
+ status = L"HANDLED_EXTERNALLY";
+ break;
+ case URLRequestStatus::CANCELED:
+ status = L"CANCELED";
+ break;
+ case URLRequestStatus::FAILED:
+ status = L"FAILED";
+ break;
+ default:
+ status = L"UNKNOWN";
+ break;
+ }
+ if (p.status() == URLRequestStatus::FAILED)
+ l->append(L"(");
+
+ LogParam(status, l);
+
+ if (p.status() == URLRequestStatus::FAILED) {
+ l->append(L", ");
+ LogParam(p.os_error(), l);
+ l->append(L")");
+ }
+ }
+};
+
template <>
struct ParamTraits<Message> {
static void Write(Message* m, const Message& p) {
diff --git a/chrome/common/net/url_request_intercept_job.cc b/chrome/common/net/url_request_intercept_job.cc
index bb5dd8c..af1c8c7 100644
--- a/chrome/common/net/url_request_intercept_job.cc
+++ b/chrome/common/net/url_request_intercept_job.cc
@@ -101,10 +101,25 @@ bool URLRequestInterceptJob::GetCharset(std::string* charset) {
return request_->response_headers()->GetCharset(charset);
}
-bool URLRequestInterceptJob::GetContentEncoding(std::string* encoding_type) {
- // TODO(darin): what if there are multiple content encodings?
- return request_->response_headers()->EnumerateHeader(NULL, "Content-Encoding",
- encoding_type);
+bool URLRequestInterceptJob::GetContentEncodings(
+ std::vector<Filter::FilterType>* encoding_types) {
+ DCHECK(encoding_types->empty());
+ if (!request_->response_headers())
+ return false;
+
+ std::string encoding_type;
+ void* iter = NULL;
+ while (request_->response_headers()->EnumerateHeader(
+ &iter, "Content-Encoding", &encoding_type)) {
+ encoding_types->push_back(Filter::ConvertEncodingToType(encoding_type));
+ }
+
+ // Even if encoding types are empty, there is a chance that we need to add
+ // some decoding, as some proxies strip encoding completely. In such cases,
+ // we may need to add (for example) SDCH filtering (when the context suggests
+ // it is appropriate).
+ Filter::FixupEncodingTypes(*this, encoding_types);
+ return !encoding_types->empty();
}
void URLRequestInterceptJob::GetResponseInfo(net::HttpResponseInfo* info) {
diff --git a/chrome/common/net/url_request_intercept_job.h b/chrome/common/net/url_request_intercept_job.h
index 73f354d..07db154 100644
--- a/chrome/common/net/url_request_intercept_job.h
+++ b/chrome/common/net/url_request_intercept_job.h
@@ -35,18 +35,22 @@ class URLRequestInterceptJob
// URLRequestJob
virtual void Start();
virtual void Kill();
- virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
virtual bool GetMimeType(std::string* mime_type) const;
virtual bool GetCharset(std::string* charset);
virtual void GetResponseInfo(net::HttpResponseInfo* info);
virtual int GetResponseCode() const;
- virtual bool GetContentEncoding(std::string* encoding_type);
+ virtual bool GetContentEncodings(
+ std::vector<Filter::FilterType>* encoding_types);
virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
// NotificationObserver
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
+
+ protected:
+ virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
+
private:
void StartAsync();
void DetachPlugin();
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index f8e6a81..f222972 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -284,11 +284,11 @@ class NotificationType {
TAB_CONTENTS_DESTROYED,
// A RenderViewHost was created for a TabContents. The source is the
- // RenderViewHostManager who owns it, and the details is the RenderViewHost
- // pointer. Note that the source will be NULL in some cases for testing,
- // when there is no RVHManager.
+ // associated TabContents, and the details is the RenderViewHost
+ // pointer.
RENDER_VIEW_HOST_CREATED_FOR_TAB,
+
// Stuff inside the tabs ---------------------------------------------------
// This message is sent after a constrained window has been closed. The
@@ -329,6 +329,9 @@ class NotificationType {
// the RenderWidgetHost, the details are not used.
RENDER_WIDGET_HOST_DESTROYED,
+ // Sent from ~RenderViewHost. The source is the RenderViewHost.
+ RENDER_VIEW_HOST_DELETED,
+
// Indicates a RenderWidgetHost has been hidden or restored. The source is
// the RWH whose visibility changed, the details is a bool set to true if
// the new state is "visible."
@@ -592,9 +595,6 @@ class NotificationType {
// Debugging ---------------------------------------------------------------
- // Sent from ~RenderViewHost. The source is the RenderViewHost.
- RENDER_VIEW_HOST_DELETED,
-
// Count (must be last) ----------------------------------------------------
// Used to determine the number of notification types. Not valid as
// a type parameter when registering for or posting notifications.
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index b2fd1f9..829a8ed 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -25,7 +25,6 @@
#include "media/audio/audio_output.h"
#include "net/base/upload_data.h"
#include "net/http/http_response_headers.h"
-#include "net/url_request/url_request_status.h"
#include "webkit/glue/autofill_form.h"
#include "webkit/glue/context_menu.h"
#include "webkit/glue/form_data.h"
@@ -1246,58 +1245,6 @@ struct ParamTraits<ViewHostMsg_Resource_Request> {
}
};
-// Traits for URLRequestStatus
-template <>
-struct ParamTraits<URLRequestStatus> {
- typedef URLRequestStatus param_type;
- static void Write(Message* m, const param_type& p) {
- WriteParam(m, static_cast<int>(p.status()));
- WriteParam(m, p.os_error());
- }
- static bool Read(const Message* m, void** iter, param_type* r) {
- int status, os_error;
- if (!ReadParam(m, iter, &status) ||
- !ReadParam(m, iter, &os_error))
- return false;
- r->set_status(static_cast<URLRequestStatus::Status>(status));
- r->set_os_error(os_error);
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- std::wstring status;
- switch (p.status()) {
- case URLRequestStatus::SUCCESS:
- status = L"SUCCESS";
- break;
- case URLRequestStatus::IO_PENDING:
- status = L"IO_PENDING ";
- break;
- case URLRequestStatus::HANDLED_EXTERNALLY:
- status = L"HANDLED_EXTERNALLY";
- break;
- case URLRequestStatus::CANCELED:
- status = L"CANCELED";
- break;
- case URLRequestStatus::FAILED:
- status = L"FAILED";
- break;
- default:
- status = L"UNKNOWN";
- break;
- }
- if (p.status() == URLRequestStatus::FAILED)
- l->append(L"(");
-
- LogParam(status, l);
-
- if (p.status() == URLRequestStatus::FAILED) {
- l->append(L", ");
- LogParam(p.os_error(), l);
- l->append(L")");
- }
- }
-};
-
template <>
struct ParamTraits<scoped_refptr<net::HttpResponseHeaders> > {
typedef scoped_refptr<net::HttpResponseHeaders> param_type;