summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-27 05:00:24 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-27 05:00:24 +0000
commitebee0c4eaaccd4a0562d5ae30ffdb4ee9f537186 (patch)
tree60633c866a3f6a49cda066867ee7fb1ceecad9af /chrome/browser/automation
parent85357c2f13952989b0a867e589896446675e2151 (diff)
downloadchromium_src-ebee0c4eaaccd4a0562d5ae30ffdb4ee9f537186.zip
chromium_src-ebee0c4eaaccd4a0562d5ae30ffdb4ee9f537186.tar.gz
chromium_src-ebee0c4eaaccd4a0562d5ae30ffdb4ee9f537186.tar.bz2
ChromeFrame cookie requests would incorrectly get routed to the first host browser connected to the renderer. This basically
meant that if the browser process exited then other popups could not query cookies from the host. Part of the fix for http://b/issue?id=2277519 Bug=2277519 Review URL: http://codereview.chromium.org/3066004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_profile_impl.cc29
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.cc97
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.h19
3 files changed, 92 insertions, 53 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.cc b/chrome/browser/automation/automation_profile_impl.cc
index 751019a..0b14c7e 100644
--- a/chrome/browser/automation/automation_profile_impl.cc
+++ b/chrome/browser/automation/automation_profile_impl.cc
@@ -97,16 +97,6 @@ class AutomationCookieStore : public net::CookieStore {
}
protected:
- void SendIPCMessageOnIOThread(IPC::Message* m) {
- if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- automation_client_->Send(m);
- } else {
- Task* task = NewRunnableMethod(this,
- &AutomationCookieStore::SendIPCMessageOnIOThread, m);
- ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, task);
- }
- }
-
net::CookieStore* original_cookie_store_;
scoped_refptr<AutomationResourceMessageFilter> automation_client_;
int tab_handle_;
@@ -130,23 +120,20 @@ class AutomationCookiePolicy : public net::CookiePolicy {
net::CompletionCallback* callback) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- if (automation_client_.get()) {
- automation_client_->GetCookiesForUrl(tab_handle_, url, callback,
- cookie_store_.get());
- return net::ERR_IO_PENDING;
- }
- return net::ERR_ACCESS_DENIED;
+ AutomationResourceMessageFilter::GetCookiesForUrl(tab_handle_, url,
+ callback,
+ cookie_store_.get());
+ return net::ERR_IO_PENDING;
}
virtual int CanSetCookie(const GURL& url,
const GURL& first_party_for_cookies,
const std::string& cookie_line,
net::CompletionCallback* callback) {
- if (automation_client_.get()) {
- automation_client_->Send(new AutomationMsg_SetCookieAsync(0,
- tab_handle_, url, cookie_line));
- }
- return net::ERR_ACCESS_DENIED;
+ AutomationResourceMessageFilter::SetCookiesForUrl(tab_handle_, url,
+ cookie_line,
+ callback);
+ return net::ERR_IO_PENDING;
}
private:
diff --git a/chrome/browser/automation/automation_resource_message_filter.cc b/chrome/browser/automation/automation_resource_message_filter.cc
index 3b92a6f..d1c3cf5 100644
--- a/chrome/browser/automation/automation_resource_message_filter.cc
+++ b/chrome/browser/automation/automation_resource_message_filter.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/net/url_request_slow_download_job.h"
#include "chrome/browser/net/url_request_slow_http_job.h"
+#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/test/automation/automation_messages.h"
@@ -21,14 +22,24 @@
#include "net/base/net_errors.h"
#include "net/url_request/url_request_filter.h"
-AutomationResourceMessageFilter::RenderViewMap
- AutomationResourceMessageFilter::filtered_render_views_;
+base::LazyInstance<AutomationResourceMessageFilter::RenderViewMap>
+ AutomationResourceMessageFilter::filtered_render_views_(
+ base::LINKER_INITIALIZED);
+
+base::LazyInstance<AutomationResourceMessageFilter::CompletionCallbackMap>
+ AutomationResourceMessageFilter::completion_callback_map_(
+ base::LINKER_INITIALIZED);
int AutomationResourceMessageFilter::unique_request_id_ = 1;
+int AutomationResourceMessageFilter::next_completion_callback_id_ = 0;
AutomationResourceMessageFilter::AutomationResourceMessageFilter()
- : channel_(NULL),
- next_completion_callback_id_(0) {
+ : channel_(NULL) {
+ // Ensure that an instance of the callback map is created.
+ completion_callback_map_.Get();
+ // Ensure that an instance of the render view map is created.
+ filtered_render_views_.Get();
+
ChromeThread::PostTask(
ChromeThread::IO, FROM_HERE,
NewRunnableFunction(
@@ -59,11 +70,11 @@ void AutomationResourceMessageFilter::OnChannelClosing() {
// Only erase RenderViews which are associated with this
// AutomationResourceMessageFilter instance.
- RenderViewMap::iterator index = filtered_render_views_.begin();
- while (index != filtered_render_views_.end()) {
+ RenderViewMap::iterator index = filtered_render_views_.Get().begin();
+ while (index != filtered_render_views_.Get().end()) {
const AutomationDetails& details = (*index).second;
if (details.filter.get() == this) {
- filtered_render_views_.erase(index++);
+ filtered_render_views_.Get().erase(index++);
} else {
index++;
}
@@ -200,12 +211,13 @@ void AutomationResourceMessageFilter::RegisterRenderViewInIOThread(
int tab_handle, AutomationResourceMessageFilter* filter,
bool pending_view) {
RenderViewMap::iterator automation_details_iter(
- filtered_render_views_.find(RendererId(renderer_pid, renderer_id)));
- if (automation_details_iter != filtered_render_views_.end()) {
+ filtered_render_views_.Get().find(RendererId(renderer_pid,
+ renderer_id)));
+ 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_[RendererId(renderer_pid, renderer_id)] =
+ filtered_render_views_.Get()[RendererId(renderer_pid, renderer_id)] =
AutomationDetails(tab_handle, filter, pending_view);
}
}
@@ -214,9 +226,10 @@ void AutomationResourceMessageFilter::RegisterRenderViewInIOThread(
void AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread(
int renderer_pid, int renderer_id) {
RenderViewMap::iterator automation_details_iter(
- filtered_render_views_.find(RendererId(renderer_pid, renderer_id)));
+ filtered_render_views_.Get().find(RendererId(renderer_pid,
+ renderer_id)));
- if (automation_details_iter == filtered_render_views_.end()) {
+ if (automation_details_iter == filtered_render_views_.Get().end()) {
LOG(INFO) << "UnRegisterRenderViewInIOThread: already unregistered";
return;
}
@@ -224,7 +237,7 @@ void AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread(
automation_details_iter->second.ref_count--;
if (automation_details_iter->second.ref_count <= 0) {
- filtered_render_views_.erase(RendererId(renderer_pid, renderer_id));
+ filtered_render_views_.Get().erase(RendererId(renderer_pid, renderer_id));
}
}
@@ -235,9 +248,10 @@ bool AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread(
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
RenderViewMap::iterator automation_details_iter(
- filtered_render_views_.find(RendererId(renderer_pid, renderer_id)));
+ filtered_render_views_.Get().find(RendererId(renderer_pid,
+ renderer_id)));
- if (automation_details_iter == filtered_render_views_.end()) {
+ if (automation_details_iter == filtered_render_views_.Get().end()) {
NOTREACHED() << "Failed to find pending view for renderer pid:"
<< renderer_pid
<< ", render view id:"
@@ -251,7 +265,7 @@ bool AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread(
automation_details_iter->second.filter;
DCHECK(old_filter != NULL);
- filtered_render_views_[RendererId(renderer_pid, renderer_id)] =
+ filtered_render_views_.Get()[RendererId(renderer_pid, renderer_id)] =
AutomationDetails(tab_handle, filter, false);
ResumeJobsForPendingView(tab_handle, old_filter, filter);
@@ -261,9 +275,9 @@ bool AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread(
bool AutomationResourceMessageFilter::LookupRegisteredRenderView(
int renderer_pid, int renderer_id, AutomationDetails* details) {
bool found = false;
- RenderViewMap::iterator it = filtered_render_views_.find(RendererId(
+ RenderViewMap::iterator it = filtered_render_views_.Get().find(RendererId(
renderer_pid, renderer_id));
- if (it != filtered_render_views_.end()) {
+ if (it != filtered_render_views_.Get().end()) {
found = true;
if (details)
*details = it->second;
@@ -325,32 +339,46 @@ void AutomationResourceMessageFilter::GetCookiesForUrl(
DCHECK(callback != NULL);
DCHECK(cookie_store != NULL);
+ GetCookiesCompletion* get_cookies_callback =
+ static_cast<GetCookiesCompletion*>(callback);
+
+ RenderViewMap::iterator automation_details_iter(
+ filtered_render_views_.Get().find(RendererId(
+ get_cookies_callback->render_process_id(),
+ get_cookies_callback->render_view_id())));
+
+ DCHECK(automation_details_iter->second.filter != NULL);
+
int completion_callback_id = GetNextCompletionCallbackId();
- DCHECK(!ContainsKey(completion_callback_map_, completion_callback_id));
+ DCHECK(!ContainsKey(completion_callback_map_.Get(), completion_callback_id));
CookieCompletionInfo cookie_info;
cookie_info.completion_callback = callback;
cookie_info.cookie_store = cookie_store;
- completion_callback_map_[completion_callback_id] = cookie_info;
+ completion_callback_map_.Get()[completion_callback_id] = cookie_info;
- Send(new AutomationMsg_GetCookiesFromHost(0, tab_handle, url,
- completion_callback_id));
+ 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));
+ }
}
void AutomationResourceMessageFilter::OnGetCookiesHostResponse(
int tab_handle, bool success, const GURL& url, const std::string& cookies,
int cookie_id) {
CompletionCallbackMap::iterator index =
- completion_callback_map_.find(cookie_id);
- if (index != completion_callback_map_.end()) {
+ 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);
DCHECK(cookie_store.get() != NULL);
- completion_callback_map_.erase(index);
+ completion_callback_map_.Get().erase(index);
// Set the cookie in the cookie store so that the callback can read it.
cookie_store->SetCookieWithOptions(url, cookies, net::CookieOptions());
@@ -367,6 +395,25 @@ void AutomationResourceMessageFilter::OnGetCookiesHostResponse(
}
}
+void AutomationResourceMessageFilter::SetCookiesForUrl(
+ int tab_handle, const GURL&url, const std::string& cookie_line,
+ net::CompletionCallback* callback) {
+ SetCookieCompletion* set_cookies_callback =
+ static_cast<SetCookieCompletion*>(callback);
+
+ RenderViewMap::iterator automation_details_iter(
+ filtered_render_views_.Get().find(RendererId(
+ set_cookies_callback->render_process_id(),
+ set_cookies_callback->render_view_id())));
+
+ DCHECK(automation_details_iter->second.filter != NULL);
+
+ if (automation_details_iter->second.filter) {
+ automation_details_iter->second.filter->Send(
+ new AutomationMsg_SetCookieAsync(0, tab_handle, url, cookie_line));
+ }
+}
+
// static
void AutomationResourceMessageFilter::ResumeJobsForPendingView(
int tab_handle,
diff --git a/chrome/browser/automation/automation_resource_message_filter.h b/chrome/browser/automation/automation_resource_message_filter.h
index d1dd067..a2acba8 100644
--- a/chrome/browser/automation/automation_resource_message_filter.h
+++ b/chrome/browser/automation/automation_resource_message_filter.h
@@ -9,6 +9,7 @@
#include <map>
#include "base/atomicops.h"
+#include "base/lazy_instance.h"
#include "base/lock.h"
#include "base/platform_thread.h"
#include "ipc/ipc_channel_proxy.h"
@@ -100,9 +101,9 @@ class AutomationResourceMessageFilter
// Retrieves cookies for the url passed in from the external host. The
// callback passed in is notified on success or failure asynchronously.
- void GetCookiesForUrl(int tab_handle, const GURL& url,
- net::CompletionCallback* callback,
- net::CookieStore* cookie_store);
+ static void GetCookiesForUrl(int tab_handle, const GURL& url,
+ net::CompletionCallback* callback,
+ net::CookieStore* cookie_store);
// This function gets invoked when we receive a response from the external
// host for the cookie request sent in GetCookiesForUrl above. It sets the
@@ -112,6 +113,10 @@ class AutomationResourceMessageFilter
void OnGetCookiesHostResponse(int tab_handle, bool success, const GURL& url,
const std::string& cookies, int cookie_id);
+ // Set cookies in the external host.
+ static void SetCookiesForUrl(int tab_handle, const GURL&url,
+ const std::string& cookie_line, net::CompletionCallback* callback);
+
protected:
// Retrieves the automation request id for the passed in chrome request
// id and returns it in the automation_request_id parameter.
@@ -139,7 +144,7 @@ class AutomationResourceMessageFilter
AutomationResourceMessageFilter* old_filter,
AutomationResourceMessageFilter* new_filter);
- int GetNextCompletionCallbackId() {
+ static int GetNextCompletionCallbackId() {
return ++next_completion_callback_id_;
}
@@ -175,7 +180,7 @@ class AutomationResourceMessageFilter
RequestMap pending_request_map_;
// Map of render views interested in diverting url requests over automation.
- static RenderViewMap filtered_render_views_;
+ static base::LazyInstance<RenderViewMap> filtered_render_views_;
// Contains information used for completing the request to read cookies from
// the host coming in from the renderer.
@@ -190,11 +195,11 @@ class AutomationResourceMessageFilter
// cookies from the host and is removed when we receive a response from the
// host. Please see the OnGetCookiesHostResponse function.
typedef std::map<int, CookieCompletionInfo> CompletionCallbackMap;
- CompletionCallbackMap completion_callback_map_;
+ static base::LazyInstance<CompletionCallbackMap> completion_callback_map_;
// Contains the id of the next completion callback. This is passed to the the
// external host as a cookie referring to the completion callback.
- int next_completion_callback_id_;
+ static int next_completion_callback_id_;
DISALLOW_COPY_AND_ASSIGN(AutomationResourceMessageFilter);
};