diff options
Diffstat (limited to 'chrome/browser/plugin_process_host.cc')
-rw-r--r-- | chrome/browser/plugin_process_host.cc | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc index 0332015..323fa93 100644 --- a/chrome/browser/plugin_process_host.cc +++ b/chrome/browser/plugin_process_host.cc @@ -35,6 +35,7 @@ #include "chrome/common/render_messages.h" #include "chrome/common/win_util.h" #include "net/base/cookie_monster.h" +#include "net/proxy/proxy_service.h" #include "net/url_request/url_request.h" #include "sandbox/src/sandbox.h" @@ -294,6 +295,57 @@ void PluginDownloadUrlHelper::DownloadCompletedHelper(bool success) { delete this; } +// The following class is a helper to handle ProxyResolve IPC requests. +// It is responsible for initiating an asynchronous proxy resolve request, +// and will send out the IPC response on completion then delete itself. +// Should the PluginProcessHost be destroyed while a proxy resolve request +// is in progress, the request will not be canceled. However once it completes +// it will see that it has been revoked and delete itself. +// TODO(eroman): This could leak if ProxyService is deleted while request is +// outstanding. +class PluginResolveProxyHelper : RevocableStore::Revocable { + public: + // Create a helper that writes its response through |plugin_host|. + PluginResolveProxyHelper(PluginProcessHost* plugin_host) + : RevocableStore::Revocable(&plugin_host->revocable_store_), + plugin_host_(plugin_host), + reply_msg_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + this, &PluginResolveProxyHelper::OnProxyResolveCompleted)) { + } + + // Completion callback for ProxyService. + void OnProxyResolveCompleted(int result) { + if (!revoked()) { + PluginProcessHostMsg_ResolveProxy::WriteReplyParams( + reply_msg_, result, proxy_info_.GetAnnotatedProxyList()); + plugin_host_->Send(reply_msg_); + } + + delete this; + }; + + // Resolve the proxy for |url| using |proxy_service|. Write the response + // to |reply_msg|. + void Start(net::ProxyService* proxy_service, + const GURL& url, + IPC::Message* reply_msg) { + reply_msg_ = reply_msg; + int rv = proxy_service->ResolveProxy( + url, &proxy_info_, &callback_, NULL); + if (rv != net::ERR_IO_PENDING) + OnProxyResolveCompleted(rv); + } + + private: + // |plugin_host_| is only valid if !this->revoked(). + PluginProcessHost* plugin_host_; + IPC::Message* reply_msg_; + net::CompletionCallbackImpl<PluginResolveProxyHelper> callback_; + net::ProxyInfo proxy_info_; +}; + + PluginProcessHost::PluginProcessHost(PluginService* plugin_service) : process_(NULL), opening_channel_(false), @@ -524,6 +576,8 @@ void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies) + IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, + OnResolveProxy) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() @@ -665,6 +719,17 @@ void PluginProcessHost::OnGetCookies(uint32 request_context, *cookies = context->cookie_store()->GetCookies(url); } +void PluginProcessHost::OnResolveProxy(const GURL& url, + IPC::Message* reply_msg) { + // Use the default profile's proxy service. + net::ProxyService* proxy_service = + Profile::GetDefaultRequestContext()->proxy_service(); + + // Kick off a proxy resolve request; writes the response to |reply_msg| + // on completion. The helper's storage will be deleted on completion. + (new PluginResolveProxyHelper(this))->Start(proxy_service, url, reply_msg); +} + void PluginProcessHost::ReplyToRenderer( ResourceMessageFilter* renderer_message_filter, const std::wstring& channel, const std::wstring& plugin_path, |