Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3586)

Unified Diff: chrome/browser/automation/automation_resource_message_filter.cc

Issue 3187013: Merge 54867 - ChromeFrame currently overrides the request context for interce... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/automation/automation_resource_message_filter.cc
===================================================================
--- chrome/browser/automation/automation_resource_message_filter.cc (revision 56788)
+++ chrome/browser/automation/automation_resource_message_filter.cc (working copy)
@@ -18,7 +18,6 @@
#include "chrome/browser/chrome_thread.h"
#include "chrome/test/automation/automation_messages.h"
#include "googleurl/src/gurl.h"
-#include "net/base/cookie_store.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_filter.h"
@@ -33,6 +32,57 @@
int AutomationResourceMessageFilter::unique_request_id_ = 1;
int AutomationResourceMessageFilter::next_completion_callback_id_ = 0;
+// CookieStore specialization to enable fetching and setting cookies over the
+// automation channel. This cookie store is transient i.e. it maintains cookies
+// for the duration of the current request to set or get cookies from the
+// renderer.
+class AutomationCookieStore : public net::CookieStore {
+ public:
+ AutomationCookieStore(AutomationResourceMessageFilter* automation_client,
+ int tab_handle)
+ : automation_client_(automation_client),
+ tab_handle_(tab_handle) {
+ }
+
+ virtual ~AutomationCookieStore() {
+ DLOG(INFO) << "In " << __FUNCTION__;
+ }
+
+ // CookieStore implementation.
+ virtual bool SetCookieWithOptions(const GURL& url,
+ const std::string& cookie_line,
+ const net::CookieOptions& options) {
+ // The cookie_string_ is available only once, i.e. once it is read by
+ // it is invalidated.
+ cookie_string_ = cookie_line;
+ return true;
+ }
+
+ virtual std::string GetCookiesWithOptions(const GURL& url,
+ const net::CookieOptions& options) {
+ return cookie_string_;
+ }
+
+ virtual void DeleteCookie(const GURL& url,
+ const std::string& cookie_name) {
+ NOTREACHED() << "Should not get called for an automation profile";
+ }
+
+ virtual net::CookieMonster* GetCookieMonster() {
+ NOTREACHED() << "Should not get called for an automation profile";
+ return NULL;
+ }
+
+ protected:
+ scoped_refptr<AutomationResourceMessageFilter> automation_client_;
+ int tab_handle_;
+ std::string cookie_string_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AutomationCookieStore);
+};
+
+
AutomationResourceMessageFilter::AutomationResourceMessageFilter()
: channel_(NULL) {
// Ensure that an instance of the callback map is created.
@@ -210,16 +260,22 @@
int renderer_pid, int renderer_id,
int tab_handle, AutomationResourceMessageFilter* filter,
bool pending_view) {
+ RendererId renderer_key(renderer_pid, renderer_id);
+
+ scoped_refptr<net::CookieStore> cookie_store =
+ new AutomationCookieStore(filter, tab_handle);
+
RenderViewMap::iterator automation_details_iter(
- filtered_render_views_.Get().find(RendererId(renderer_pid,
- renderer_id)));
+ filtered_render_views_.Get().find(renderer_key));
if (automation_details_iter != filtered_render_views_.Get().end()) {
DCHECK(automation_details_iter->second.ref_count > 0);
automation_details_iter->second.ref_count++;
} else {
- filtered_render_views_.Get()[RendererId(renderer_pid, renderer_id)] =
+ filtered_render_views_.Get()[renderer_key] =
AutomationDetails(tab_handle, filter, pending_view);
}
+
+ filtered_render_views_.Get()[renderer_key].set_cookie_store(cookie_store);
}
// static
@@ -247,9 +303,10 @@
AutomationResourceMessageFilter* filter) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ RendererId renderer_key(renderer_pid, renderer_id);
+
RenderViewMap::iterator automation_details_iter(
- filtered_render_views_.Get().find(RendererId(renderer_pid,
- renderer_id)));
+ filtered_render_views_.Get().find(renderer_key));
if (automation_details_iter == filtered_render_views_.Get().end()) {
NOTREACHED() << "Failed to find pending view for renderer pid:"
@@ -261,13 +318,18 @@
DCHECK(automation_details_iter->second.is_pending_render_view);
+ scoped_refptr<net::CookieStore> cookie_store =
+ new AutomationCookieStore(filter, tab_handle);
+
AutomationResourceMessageFilter* old_filter =
automation_details_iter->second.filter;
DCHECK(old_filter != NULL);
- filtered_render_views_.Get()[RendererId(renderer_pid, renderer_id)] =
+ filtered_render_views_.Get()[renderer_key] =
AutomationDetails(tab_handle, filter, false);
+ filtered_render_views_.Get()[renderer_key].set_cookie_store(cookie_store);
+
ResumeJobsForPendingView(tab_handle, old_filter, filter);
return true;
}
@@ -333,42 +395,42 @@
}
}
-void AutomationResourceMessageFilter::GetCookiesForUrl(
- int tab_handle, const GURL& url, net::CompletionCallback* callback,
- net::CookieStore* cookie_store) {
- DCHECK(callback != NULL);
- DCHECK(cookie_store != NULL);
-
+bool AutomationResourceMessageFilter::GetCookiesForUrl(
+ const GURL& url, net::CompletionCallback* callback) {
GetCookiesCompletion* get_cookies_callback =
static_cast<GetCookiesCompletion*>(callback);
+ RendererId renderer_key(get_cookies_callback->render_process_id(),
+ get_cookies_callback->render_view_id());
+
RenderViewMap::iterator automation_details_iter(
- filtered_render_views_.Get().find(RendererId(
- get_cookies_callback->render_process_id(),
- get_cookies_callback->render_view_id())));
+ filtered_render_views_.Get().find(renderer_key));
+
if (automation_details_iter == filtered_render_views_.Get().end()) {
- OnGetCookiesHostResponseInternal(tab_handle, false, url, "", callback,
- cookie_store);
- return;
+ return false;
}
DCHECK(automation_details_iter->second.filter != NULL);
+ DCHECK(automation_details_iter->second.cookie_store_.get() != NULL);
int completion_callback_id = GetNextCompletionCallbackId();
DCHECK(!ContainsKey(completion_callback_map_.Get(), completion_callback_id));
CookieCompletionInfo cookie_info;
cookie_info.completion_callback = callback;
- cookie_info.cookie_store = cookie_store;
+ cookie_info.cookie_store = automation_details_iter->second.cookie_store_;
completion_callback_map_.Get()[completion_callback_id] = cookie_info;
+ DCHECK(automation_details_iter->second.filter != NULL);
+
if (automation_details_iter->second.filter) {
automation_details_iter->second.filter->Send(
new AutomationMsg_GetCookiesFromHost(
0, automation_details_iter->second.tab_handle, url,
completion_callback_id));
}
+ return true;
}
void AutomationResourceMessageFilter::OnGetCookiesHostResponse(
@@ -378,6 +440,7 @@
completion_callback_map_.Get().find(cookie_id);
if (index != completion_callback_map_.Get().end()) {
net::CompletionCallback* callback = index->second.completion_callback;
+
scoped_refptr<net::CookieStore> cookie_store = index->second.cookie_store;
DCHECK(callback != NULL);
@@ -399,6 +462,11 @@
DCHECK(callback);
DCHECK(cookie_store);
+ GetCookiesCompletion* get_cookies_callback =
+ static_cast<GetCookiesCompletion*>(callback);
+
+ get_cookies_callback->set_cookie_store(cookie_store);
+
// Set the cookie in the cookie store so that the callback can read it.
cookie_store->SetCookieWithOptions(url, cookies, net::CookieOptions());
@@ -410,8 +478,8 @@
cookie_store->SetCookieWithOptions(url, "", net::CookieOptions());
}
-void AutomationResourceMessageFilter::SetCookiesForUrl(
- int tab_handle, const GURL&url, const std::string& cookie_line,
+bool AutomationResourceMessageFilter::SetCookiesForUrl(
+ const GURL& url, const std::string& cookie_line,
net::CompletionCallback* callback) {
SetCookieCompletion* set_cookies_callback =
static_cast<SetCookieCompletion*>(callback);
@@ -421,14 +489,19 @@
set_cookies_callback->render_process_id(),
set_cookies_callback->render_view_id())));
- if (automation_details_iter != filtered_render_views_.Get().end()) {
- DCHECK(automation_details_iter->second.filter != NULL);
+ if (automation_details_iter == filtered_render_views_.Get().end()) {
+ return false;
+ }
- if (automation_details_iter->second.filter) {
- automation_details_iter->second.filter->Send(
- new AutomationMsg_SetCookieAsync(0, tab_handle, url, cookie_line));
- }
+ DCHECK(automation_details_iter->second.filter != NULL);
+
+ if (automation_details_iter->second.filter) {
+ automation_details_iter->second.filter->Send(
+ new AutomationMsg_SetCookieAsync(
+ 0, automation_details_iter->second.tab_handle, url, cookie_line));
}
+
+ return true;
}
// static
« no previous file with comments | « chrome/browser/automation/automation_resource_message_filter.h ('k') | chrome/browser/background_contents_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698