summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 22:21:10 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 22:21:10 +0000
commita7659318ed6c379ba782f61d8fb80e665d3a45d7 (patch)
treea6add177ad993709b6d3a3cca4f974cac1817044
parent8c3dc79bc13ba84f418d3c135e1bf296a3e29722 (diff)
downloadchromium_src-a7659318ed6c379ba782f61d8fb80e665d3a45d7.zip
chromium_src-a7659318ed6c379ba782f61d8fb80e665d3a45d7.tar.gz
chromium_src-a7659318ed6c379ba782f61d8fb80e665d3a45d7.tar.bz2
Added support for the URLRequestAutomationJob object which issues HTTP requests through automation to receive persistent cookies from the automation client. These cookies are passed in when the automation client notifies Chrome that a HTTP request was started.
The URLRequestAutomationJob object now informs Chrome whether an automation URL request was redirected. The ExternalTabContainer now handles the NEW_FOREGROUND_TAB and displays a popup window in response. This gets around an ASSERT. This fixes bug http://b/issue?id=2048046 Bug=2048046 Review URL: http://codereview.chromium.org/165350 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23233 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/url_request_automation_job.cc43
-rw-r--r--chrome/browser/automation/url_request_automation_job.h1
-rw-r--r--chrome/browser/external_tab_container.cc3
-rw-r--r--chrome/test/automation/automation_messages.h12
4 files changed, 44 insertions, 15 deletions
diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc
index 4b69cca..206d1c4 100644
--- a/chrome/browser/automation/url_request_automation_job.cc
+++ b/chrome/browser/automation/url_request_automation_job.cc
@@ -185,16 +185,14 @@ int URLRequestAutomationJob::GetResponseCode() const {
bool URLRequestAutomationJob::IsRedirectResponse(
GURL* location, int* http_status_code) {
- if (!request_->response_headers())
- return false;
+ static const int kHttpRedirectResponseCode = 301;
- std::string value;
- if (!request_->response_headers()->IsRedirect(&value))
- return false;
-
- *location = request_->url().Resolve(value);
- *http_status_code = request_->response_headers()->response_code();
- return true;
+ if (!redirect_url_.empty()) {
+ *http_status_code = kHttpRedirectResponseCode;
+ *location = GURL(redirect_url_);
+ return true;
+ }
+ return false;
}
int URLRequestAutomationJob::MayFilterMessage(const IPC::Message& message) {
@@ -231,6 +229,14 @@ void URLRequestAutomationJob::OnRequestStarted(
set_expected_content_size(response.content_length);
mime_type_ = response.mime_type;
+ redirect_url_ = response.redirect_url;
+
+ GURL url_for_cookies =
+ GURL(redirect_url_.empty() ? request_->url().spec().c_str() :
+ redirect_url_.c_str());
+
+ URLRequestContext* ctx = request_->context();
+
if (!response.headers.empty()) {
headers_ = new net::HttpResponseHeaders(response.headers);
@@ -246,19 +252,31 @@ void URLRequestAutomationJob::OnRequestStarted(
}
if (response_cookies.size()) {
- URLRequestContext* ctx = request_->context();
if (ctx && ctx->cookie_store() &&
ctx->cookie_policy()->CanSetCookie(
- request_->url(), request_->first_party_for_cookies())) {
+ url_for_cookies, request_->first_party_for_cookies())) {
net::CookieOptions options;
options.set_include_httponly();
- ctx->cookie_store()->SetCookiesWithOptions(request_->url(),
+ ctx->cookie_store()->SetCookiesWithOptions(url_for_cookies,
response_cookies,
options);
}
}
}
+ if (ctx && ctx->cookie_store() && !response.persistent_cookies.empty() &&
+ ctx->cookie_policy()->CanSetCookie(
+ url_for_cookies, request_->first_party_for_cookies())) {
+ StringTokenizer cookie_parser(response.persistent_cookies, ";");
+
+ while (cookie_parser.GetNext()) {
+ net::CookieOptions options;
+ ctx->cookie_store()->SetCookieWithOptions(url_for_cookies,
+ cookie_parser.token(),
+ options);
+ }
+ }
+
NotifyHeadersComplete();
}
@@ -358,4 +376,3 @@ void URLRequestAutomationJob::DisconnectFromMessageFilter() {
message_filter_ = NULL;
}
}
-
diff --git a/chrome/browser/automation/url_request_automation_job.h b/chrome/browser/automation/url_request_automation_job.h
index db61781..ade6d38 100644
--- a/chrome/browser/automation/url_request_automation_job.h
+++ b/chrome/browser/automation/url_request_automation_job.h
@@ -69,6 +69,7 @@ class URLRequestAutomationJob : public URLRequestJob {
std::string mime_type_;
scoped_refptr<net::HttpResponseHeaders> headers_;
+ std::string redirect_url_;
static int instance_count_;
diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc
index b5cead4..fb593c8 100644
--- a/chrome/browser/external_tab_container.cc
+++ b/chrome/browser/external_tab_container.cc
@@ -208,7 +208,8 @@ void ExternalTabContainer::AddNewContents(TabContents* source,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture) {
- if (disposition == NEW_POPUP || disposition == NEW_WINDOW) {
+ if (disposition == NEW_POPUP || disposition == NEW_WINDOW ||
+ disposition == NEW_FOREGROUND_TAB) {
Browser::BuildPopupWindowHelper(source, new_contents, initial_pos,
Browser::TYPE_POPUP,
tab_contents_->profile(), true);
diff --git a/chrome/test/automation/automation_messages.h b/chrome/test/automation/automation_messages.h
index f7f1762..5874c9a 100644
--- a/chrome/test/automation/automation_messages.h
+++ b/chrome/test/automation/automation_messages.h
@@ -272,6 +272,8 @@ struct AutomationURLResponse {
std::string headers;
int64 content_length;
base::Time last_modified;
+ std::string persistent_cookies;
+ std::string redirect_url;
};
// Traits for AutomationURLRequest structure to pack/unpack.
@@ -283,12 +285,16 @@ struct ParamTraits<AutomationURLResponse> {
WriteParam(m, p.headers);
WriteParam(m, p.content_length);
WriteParam(m, p.last_modified);
+ WriteParam(m, p.persistent_cookies);
+ WriteParam(m, p.redirect_url);
}
static bool Read(const Message* m, void** iter, param_type* p) {
return ReadParam(m, iter, &p->mime_type) &&
ReadParam(m, iter, &p->headers) &&
ReadParam(m, iter, &p->content_length) &&
- ReadParam(m, iter, &p->last_modified);
+ ReadParam(m, iter, &p->last_modified) &&
+ ReadParam(m, iter, &p->persistent_cookies) &&
+ ReadParam(m, iter, &p->redirect_url);
}
static void Log(const param_type& p, std::wstring* l) {
l->append(L"(");
@@ -299,6 +305,10 @@ struct ParamTraits<AutomationURLResponse> {
LogParam(p.content_length, l);
l->append(L", ");
LogParam(p.last_modified, l);
+ l->append(L", ");
+ LogParam(p.persistent_cookies, l);
+ l->append(L", ");
+ LogParam(p.redirect_url, l);
l->append(L")");
}
};