diff options
author | stoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-13 17:10:51 +0000 |
---|---|---|
committer | stoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-13 17:10:51 +0000 |
commit | 27ad98351b503a436de21c76c2e7944451b620a3 (patch) | |
tree | 9b05bf03bd09cf66243e3284d5a6e0192a8fe907 /chrome_frame | |
parent | 5caf9b2b71c331b883c3760dd4f31855b7ca2d13 (diff) | |
download | chromium_src-27ad98351b503a436de21c76c2e7944451b620a3.zip chromium_src-27ad98351b503a436de21c76c2e7944451b620a3.tar.gz chromium_src-27ad98351b503a436de21c76c2e7944451b620a3.tar.bz2 |
Preparation CL for executing READ and COOKIE network requests from the background thread.
Review URL: http://codereview.chromium.org/1520033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r-- | chrome_frame/chrome_frame_automation.cc | 64 | ||||
-rw-r--r-- | chrome_frame/chrome_frame_automation.h | 7 | ||||
-rw-r--r-- | chrome_frame/chrome_frame_npapi.cc | 157 | ||||
-rw-r--r-- | chrome_frame/chrome_frame_npapi.h | 18 | ||||
-rw-r--r-- | chrome_frame/np_utils.cc | 102 | ||||
-rw-r--r-- | chrome_frame/np_utils.h | 10 | ||||
-rw-r--r-- | chrome_frame/npapi_url_request.cc | 66 | ||||
-rw-r--r-- | chrome_frame/npapi_url_request.h | 6 | ||||
-rw-r--r-- | chrome_frame/plugin_url_request.h | 40 | ||||
-rw-r--r-- | chrome_frame/test/url_request_test.cc | 2 | ||||
-rw-r--r-- | chrome_frame/urlmon_url_request.cc | 28 | ||||
-rw-r--r-- | chrome_frame/urlmon_url_request.h | 12 |
12 files changed, 250 insertions, 262 deletions
diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc index aa88def..2fc968d 100644 --- a/chrome_frame/chrome_frame_automation.cc +++ b/chrome_frame/chrome_frame_automation.cc @@ -458,6 +458,7 @@ ChromeFrameAutomationClient::ChromeFrameAutomationClient() tab_handle_(-1), external_tab_cookie_(0), url_fetcher_(NULL), + url_fetcher_flags_(PluginUrlRequestManager::NOT_THREADSAFE), navigate_after_initialization_(false) { } @@ -984,65 +985,68 @@ bool ChromeFrameAutomationClient::ProcessUrlRequestMessage(TabProxy* tab, const IPC::Message& msg, bool ui_thread) { // Either directly call appropriate url_fetcher function // or postpone call to the UI thread. - bool invoke = ui_thread || thread_safe_url_fetcher_; uint16 msg_type = msg.type(); switch (msg_type) { default: return false; case AutomationMsg_RequestStart::ID: - if (invoke) + if (ui_thread || (url_fetcher_flags_ & + PluginUrlRequestManager::START_REQUEST_THREADSAFE)) { AutomationMsg_RequestStart::Dispatch(&msg, url_fetcher_, &PluginUrlRequestManager::StartUrlRequest); + return true; + } break; case AutomationMsg_RequestRead::ID: - if (invoke) + if (ui_thread || (url_fetcher_flags_ & + PluginUrlRequestManager::READ_REQUEST_THREADSAFE)) { AutomationMsg_RequestRead::Dispatch(&msg, url_fetcher_, &PluginUrlRequestManager::ReadUrlRequest); + return true; + } break; case AutomationMsg_RequestEnd::ID: - if (invoke) + if (ui_thread || (url_fetcher_flags_ & + PluginUrlRequestManager::STOP_REQUEST_THREADSAFE)) { AutomationMsg_RequestEnd::Dispatch(&msg, url_fetcher_, &PluginUrlRequestManager::EndUrlRequest); + return true; + } break; case AutomationMsg_DownloadRequestInHost::ID: - if (invoke) + if (ui_thread || (url_fetcher_flags_ & + PluginUrlRequestManager::DOWNLOAD_REQUEST_THREADSAFE)) { AutomationMsg_DownloadRequestInHost::Dispatch(&msg, url_fetcher_, &PluginUrlRequestManager::DownloadUrlRequestInHost); + return true; + } break; - case AutomationMsg_GetCookiesFromHost::ID: { - if (invoke) { - // If the PluginUrlRequestManager does not handle the GetCookies - // request then fall through to the original handling which sends - // the request to the delegate. - invoke = AutomationMsg_GetCookiesFromHost::Dispatch(&msg, url_fetcher_, + case AutomationMsg_GetCookiesFromHost::ID: + if (ui_thread || (url_fetcher_flags_ & + PluginUrlRequestManager::COOKIE_REQUEST_THREADSAFE)) { + AutomationMsg_GetCookiesFromHost::Dispatch(&msg, url_fetcher_, &PluginUrlRequestManager::GetCookiesFromHost); + return true; } break; - } - case AutomationMsg_SetCookieAsync::ID: { - if (invoke) { - // If the PluginUrlRequestManager does not handle the SetCookies - // request then fall through to the original handling which sends - // the request to the delegate. - invoke = AutomationMsg_SetCookieAsync::Dispatch(&msg, url_fetcher_, + case AutomationMsg_SetCookieAsync::ID: + if (ui_thread || (url_fetcher_flags_ & + PluginUrlRequestManager::COOKIE_REQUEST_THREADSAFE)) { + AutomationMsg_SetCookieAsync::Dispatch(&msg, url_fetcher_, &PluginUrlRequestManager::SetCookiesInHost); + return true; } break; - } - } - - if (!invoke) { - PostTask(FROM_HERE, NewRunnableMethod(this, - &ChromeFrameAutomationClient::ProcessUrlRequestMessage, - tab, msg, true)); } + PostTask(FROM_HERE, NewRunnableMethod(this, + &ChromeFrameAutomationClient::ProcessUrlRequestMessage, tab, msg, true)); return true; } @@ -1309,10 +1313,8 @@ void ChromeFrameAutomationClient::OnResponseEnd(int request_id, request_id, status)); } -bool ChromeFrameAutomationClient::SendIPCMessage(IPC::Message* msg) { - if (automation_server_) - return automation_server_->Send(msg); - return false; +void ChromeFrameAutomationClient::OnCookiesRetrieved(bool success, + const GURL& url, const std::string& cookie_string, int cookie_id) { + automation_server_->Send(new AutomationMsg_GetCookiesHostResponse(0, + tab_->handle(), success, url, cookie_string, cookie_id)); } - - diff --git a/chrome_frame/chrome_frame_automation.h b/chrome_frame/chrome_frame_automation.h index 2387a12..01a64ac 100644 --- a/chrome_frame/chrome_frame_automation.h +++ b/chrome_frame/chrome_frame_automation.h @@ -347,7 +347,7 @@ class ChromeFrameAutomationClient // When host network stack is used, this object is in charge of // handling network requests. PluginUrlRequestManager* url_fetcher_; - bool thread_safe_url_fetcher_; + PluginUrlRequestManager::ThreadSafeFlags url_fetcher_flags_; bool ProcessUrlRequestMessage(TabProxy* tab, const IPC::Message& msg, bool ui_thread); @@ -359,13 +359,14 @@ class ChromeFrameAutomationClient const std::string& redirect_url, int redirect_status); virtual void OnReadComplete(int request_id, const std::string& data); virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); - virtual bool SendIPCMessage(IPC::Message* msg); + virtual void OnCookiesRetrieved(bool success, const GURL& url, + const std::string& cookie_string, int cookie_id); public: void SetUrlFetcher(PluginUrlRequestManager* url_fetcher) { DCHECK(url_fetcher != NULL); url_fetcher_ = url_fetcher; - thread_safe_url_fetcher_ = url_fetcher->IsThreadSafe(); + url_fetcher_flags_ = url_fetcher->GetThreadSafeFlags(); url_fetcher_->set_delegate(this); } }; diff --git a/chrome_frame/chrome_frame_npapi.cc b/chrome_frame/chrome_frame_npapi.cc index ce1e654..5ae267a 100644 --- a/chrome_frame/chrome_frame_npapi.cc +++ b/chrome_frame/chrome_frame_npapi.cc @@ -15,12 +15,6 @@ #include "chrome_frame/scoped_ns_ptr_win.h" #include "chrome_frame/utils.h" -#include "third_party/xulrunner-sdk/win/include/xpcom/nsXPCOM.h" -#include "third_party/xulrunner-sdk/win/include/necko/nsICookieService.h" -#include "third_party/xulrunner-sdk/win/include/necko/nsIIOService.h" -#include "third_party/xulrunner-sdk/win/sdk/include/nsIURI.h" -#include "third_party/xulrunner-sdk/win/sdk/include/nsStringAPI.h" - MessageLoop* ChromeFrameNPAPI::message_loop_ = NULL; int ChromeFrameNPAPI::instance_count_ = 0; @@ -119,18 +113,6 @@ static const char kPluginChromeFunctionsAutomatedAttribute[] = // If chrome network stack is to be used static const char kPluginUseChromeNetwork[] = "usechromenetwork"; -static const char kMozillaIOServiceContractID[] = - "@mozilla.org/network/io-service;1"; - -static const char kMozillaCookieServiceContractID[] = - "@mozilla.org/cookieService;1"; - -namespace { -nsIID IID_nsIIOService = NS_IIOSERVICE_IID; -nsIID IID_nsICookieService = NS_ICOOKIESERVICE_IID; -nsIID IID_nsIUri = NS_IURI_IID; -} // namespace - // ChromeFrameNPAPI member defines. // TODO(tommi): remove ignore_setfocus_ since that's not how focus is @@ -503,64 +485,6 @@ void ChromeFrameNPAPI::OnOpenURL(int tab_handle, npapi::GetURLNotify(instance_, url.spec().c_str(), target.c_str(), NULL); } -void ChromeFrameNPAPI::OnSetCookieAsync(int tab_handle, const GURL& url, - const std::string& cookie) { - // Use the newer NPAPI way if available - if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { - npapi::SetValueForURL(instance_, NPNURLVCookie, url.spec().c_str(), - cookie.c_str(), cookie.length()); - } else { - DLOG(INFO) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO."; - DLOG(INFO) << "Attempting to set cookie using XPCOM cookie service"; - if (SetCookiesUsingXPCOMCookieService(url, cookie)) { - DLOG(INFO) << "Successfully set cookies using XPCOM cookie service"; - DLOG(INFO) << cookie.c_str(); - } else { - NOTREACHED() << "Failed to set cookies for host"; - } - } -} - -void ChromeFrameNPAPI::OnGetCookiesFromHost(int tab_handle, const GURL& url, - int cookie_id) { - std::string cookie_string; - bool success = true; - - if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { - char* cookies = NULL; - unsigned int cookie_length = 0; - NPError ret = npapi::GetValueForURL(instance_, NPNURLVCookie, - url.spec().c_str(), &cookies, - &cookie_length); - if (ret == NPERR_NO_ERROR) { - DLOG(INFO) << "Obtained cookies:" << cookies << " from host"; - cookie_string.append(cookies, cookie_length); - npapi::MemFree(cookies); - } else { - success = false; - } - } else { - DLOG(INFO) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO."; - DLOG(INFO) << "Attempting to read cookie using XPCOM cookie service"; - if (GetCookiesUsingXPCOMCookieService(url, &cookie_string)) { - DLOG(INFO) << "Successfully read cookies using XPCOM cookie service"; - DLOG(INFO) << cookie_string.c_str(); - } else { - success = false; - } - } - - if (!success) - DLOG(INFO) << "Failed to return cookies for url:" << url.spec().c_str(); - - if (automation_client_->automation_server()) { - automation_client_->automation_server()->Send( - new AutomationMsg_GetCookiesHostResponse(0, tab_handle, success, - url, cookie_string, - cookie_id)); - } -} - bool ChromeFrameNPAPI::HasMethod(NPObject* obj, NPIdentifier name) { for (int i = 0; i < arraysize(plugin_methods_); ++i) { if (name == plugin_method_identifiers_[i]) @@ -1517,84 +1441,3 @@ int32 ChromeFrameNPAPI::Write(NPStream* stream, int32 offset, int32 len, NPError ChromeFrameNPAPI::DestroyStream(NPStream* stream, NPReason reason) { return url_fetcher_.DestroyStream(stream, reason); } - -bool ChromeFrameNPAPI::GetXPCOMCookieServiceAndURI(const GURL&url, - nsICookieService** cookie_service, nsIURI** uri) { - DCHECK(cookie_service); - DCHECK(uri); - - ScopedNsPtr<nsIServiceManager> service_manager; - NPError nperr = npapi::GetValue(instance_, NPNVserviceManager, - service_manager.Receive()); - if (nperr != NPERR_NO_ERROR || !service_manager.get()) - return false; - - ScopedNsPtr<nsIIOService, &IID_nsIIOService> io_service; - service_manager->GetServiceByContractID( - kMozillaIOServiceContractID, nsIIOService::GetIID(), - reinterpret_cast<void**>(io_service.Receive())); - if (!io_service.get()) { - NOTREACHED() << "Failed to get nsIIOService"; - return false; - } - - ScopedNsPtr<nsICookieService, &IID_nsICookieService> nsi_cookie_service; - service_manager->GetServiceByContractID( - kMozillaCookieServiceContractID, nsICookieService::GetIID(), - reinterpret_cast<void**>(nsi_cookie_service.Receive())); - if (!io_service.get()) { - NOTREACHED() << "Failed to get nsICookieService"; - return false; - } - - nsCString url_string; - url_string.Assign(url.spec().c_str()); - - ScopedNsPtr<nsIURI, &IID_nsIUri> nsi_uri; - io_service->NewURI(url_string, NULL, NULL, nsi_uri.Receive()); - if (!nsi_uri.get()) { - NOTREACHED() << "Failed to covert url to nsIURI"; - return false; - } - - *cookie_service = nsi_cookie_service.Detach(); - *uri = nsi_uri.Detach(); - return true; -} - -bool ChromeFrameNPAPI::GetCookiesUsingXPCOMCookieService( - const GURL& url, std::string* cookie_string) { - DCHECK(cookie_string); - - ScopedNsPtr<nsICookieService, &IID_nsICookieService> cookie_service; - ScopedNsPtr<nsIURI, &IID_nsIUri> uri; - - if (!GetXPCOMCookieServiceAndURI(url, cookie_service.Receive(), - uri.Receive())) - return false; - - nsCString cookie_value; - nsresult ret = cookie_service->GetCookieString(uri, NULL, - getter_Copies(cookie_value)); - if (NS_SUCCEEDED(ret)) { - *cookie_string = cookie_value.get(); - } - return NS_SUCCEEDED(ret); -} - -bool ChromeFrameNPAPI::SetCookiesUsingXPCOMCookieService( - const GURL& url, const std::string& cookie_string) { - ScopedNsPtr<nsICookieService, &IID_nsICookieService> cookie_service; - ScopedNsPtr<nsIURI, &IID_nsIUri> uri; - - if (!GetXPCOMCookieServiceAndURI(url, cookie_service.Receive(), - uri.Receive())) { - return false; - } - - nsCString cookie_value; - nsresult ret = cookie_service->SetCookieString(uri, NULL, - cookie_string.c_str(), NULL); - return NS_SUCCEEDED(ret); -} - diff --git a/chrome_frame/chrome_frame_npapi.h b/chrome_frame/chrome_frame_npapi.h index e7e9fc4..76f1e1e 100644 --- a/chrome_frame/chrome_frame_npapi.h +++ b/chrome_frame/chrome_frame_npapi.h @@ -138,12 +138,6 @@ END_MSG_MAP() const std::string& message, const std::string& origin, const std::string& target); - virtual void OnSetCookieAsync(int tab_handle, const GURL& url, - const std::string& cookie); - - virtual void OnGetCookiesFromHost(int tab_handle, const GURL& url, - int cookie_id); - // ChromeFrameDelegate overrides virtual void OnLoadFailed(int error_code, const std::string& url); virtual void OnAutomationServerReady(); @@ -291,18 +285,6 @@ END_MSG_MAP() static LRESULT CALLBACK DropKillFocusHook(int code, WPARAM wparam, LPARAM lparam); // NO_LINT - // Helper functions to set and get cookies using the XPCOM cookie service - // interfaces. This would only work in Firefox. - bool SetCookiesUsingXPCOMCookieService(const GURL& url, - const std::string& cookie); - bool GetCookiesUsingXPCOMCookieService(const GURL& url, - std::string* cookie_string); - // Helper function to return the XPCOM nsICookieService interface and - // nsIURI interface representing the url passed in. - bool GetXPCOMCookieServiceAndURI(const GURL& url, - nsICookieService** cookie_service, - nsIURI** uri); - // The plugins opaque instance handle NPP instance_; diff --git a/chrome_frame/np_utils.cc b/chrome_frame/np_utils.cc index 60beb1b..2549504 100644 --- a/chrome_frame/np_utils.cc +++ b/chrome_frame/np_utils.cc @@ -2,9 +2,75 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#define NO_NSPR_10_SUPPORT #include "chrome_frame/np_utils.h" #include "chrome_frame/np_browser_functions.h" +#include "chrome_frame/ns_associate_iid_win.h" +#include "chrome_frame/scoped_ns_ptr_win.h" + +#include "third_party/xulrunner-sdk/win/include/xpcom/nsXPCOM.h" +#include "third_party/xulrunner-sdk/win/include/xpcom/nsIServiceManager.h" +#include "third_party/xulrunner-sdk/win/include/necko/nsICookieService.h" +#include "third_party/xulrunner-sdk/win/include/necko/nsIIOService.h" +#include "third_party/xulrunner-sdk/win/sdk/include/nsIURI.h" +#include "third_party/xulrunner-sdk/win/sdk/include/nsStringAPI.h" + +ASSOCIATE_IID(NS_ISERVICEMANAGER_IID_STR, nsIServiceManager); +namespace { +nsIID IID_nsIIOService = NS_IIOSERVICE_IID; +nsIID IID_nsICookieService = NS_ICOOKIESERVICE_IID; +nsIID IID_nsIUri = NS_IURI_IID; +const char kMozillaIOServiceContractID[] = "@mozilla.org/network/io-service;1"; +const char kMozillaCookieServiceContractID[] = "@mozilla.org/cookieService;1"; + +bool GetXPCOMCookieServiceAndURI(NPP instance, const std::string& url, + nsICookieService** cookie_service, nsIURI** uri) { + DCHECK(cookie_service); + DCHECK(uri); + + ScopedNsPtr<nsIServiceManager> service_manager; + NPError nperr = npapi::GetValue(instance, NPNVserviceManager, + service_manager.Receive()); + if (nperr != NPERR_NO_ERROR || !service_manager.get()) + return false; + + ScopedNsPtr<nsIIOService, &IID_nsIIOService> io_service; + service_manager->GetServiceByContractID( + kMozillaIOServiceContractID, nsIIOService::GetIID(), + reinterpret_cast<void**>(io_service.Receive())); + if (!io_service.get()) { + NOTREACHED() << "Failed to get nsIIOService"; + return false; + } + + ScopedNsPtr<nsICookieService, &IID_nsICookieService> nsi_cookie_service; + service_manager->GetServiceByContractID( + kMozillaCookieServiceContractID, nsICookieService::GetIID(), + reinterpret_cast<void**>(nsi_cookie_service.Receive())); + if (!io_service.get()) { + NOTREACHED() << "Failed to get nsICookieService"; + return false; + } + + nsCString url_string; + url_string.Assign(url.c_str()); + + ScopedNsPtr<nsIURI, &IID_nsIUri> nsi_uri; + io_service->NewURI(url_string, NULL, NULL, nsi_uri.Receive()); + if (!nsi_uri.get()) { + NOTREACHED() << "Failed to covert url to nsIURI"; + return false; + } + + *cookie_service = nsi_cookie_service.Detach(); + *uri = nsi_uri.Detach(); + return true; +} + +} // namespace + + namespace np_utils { @@ -41,4 +107,40 @@ std::string GetLocation(NPP instance, NPObject* window) { return result; } +bool GetCookiesUsingXPCOMCookieService(NPP instance, const std::string& url, + std::string* cookie_string) { + DCHECK(cookie_string); + + ScopedNsPtr<nsICookieService, &IID_nsICookieService> cookie_service; + ScopedNsPtr<nsIURI, &IID_nsIUri> uri; + + if (!GetXPCOMCookieServiceAndURI(instance, url, cookie_service.Receive(), + uri.Receive())) + return false; + + nsCString cookie_value; + nsresult ret = cookie_service->GetCookieString(uri, NULL, + getter_Copies(cookie_value)); + if (NS_SUCCEEDED(ret)) { + *cookie_string = cookie_value.get(); + } + return NS_SUCCEEDED(ret); +} + +bool SetCookiesUsingXPCOMCookieService(NPP instance, const std::string& url, + const std::string& cookie_string) { + ScopedNsPtr<nsICookieService, &IID_nsICookieService> cookie_service; + ScopedNsPtr<nsIURI, &IID_nsIUri> uri; + + if (!GetXPCOMCookieServiceAndURI(instance, url, cookie_service.Receive(), + uri.Receive())) { + return false; + } + + nsCString cookie_value; + nsresult ret = cookie_service->SetCookieString(uri, NULL, + cookie_string.c_str(), NULL); + return NS_SUCCEEDED(ret); +} + } // namespace np_utils diff --git a/chrome_frame/np_utils.h b/chrome_frame/np_utils.h index f2aa387..484497b 100644 --- a/chrome_frame/np_utils.h +++ b/chrome_frame/np_utils.h @@ -8,13 +8,15 @@ #include <string> #include "base/basictypes.h" -#include "third_party/WebKit/WebCore/bridge/npapi.h" -#include "third_party/WebKit/WebCore/plugins/npfunctions.h" +#include "chrome_frame/np_browser_functions.h" namespace np_utils { std::string GetLocation(NPP instance, NPObject* window); - +bool GetCookiesUsingXPCOMCookieService(NPP instance, const std::string& url, + std::string* cookie_string); +bool SetCookiesUsingXPCOMCookieService(NPP instance, const std::string& url, + const std::string& cookie_string); } // namespace np_utils -#endif // CHROME_FRAME_NP_UTILS_H_
\ No newline at end of file +#endif // CHROME_FRAME_NP_UTILS_H_ diff --git a/chrome_frame/npapi_url_request.cc b/chrome_frame/npapi_url_request.cc index 235caf5..7f7faf7 100644 --- a/chrome_frame/npapi_url_request.cc +++ b/chrome_frame/npapi_url_request.cc @@ -6,6 +6,7 @@ #include "base/string_util.h" #include "chrome_frame/np_browser_functions.h" +#include "chrome_frame/np_utils.h" #include "net/base/net_errors.h" class NPAPIUrlRequest : public PluginUrlRequest { @@ -191,8 +192,9 @@ NPAPIUrlRequestManager::~NPAPIUrlRequestManager() { } // PluginUrlRequestManager implementation -bool NPAPIUrlRequestManager::IsThreadSafe() { - return false; +PluginUrlRequestManager::ThreadSafeFlags + NPAPIUrlRequestManager::GetThreadSafeFlags() { + return PluginUrlRequestManager::NOT_THREADSAFE; } void NPAPIUrlRequestManager::StartRequest(int request_id, @@ -244,6 +246,60 @@ void NPAPIUrlRequestManager::StopAll() { } } +void NPAPIUrlRequestManager::SetCookiesForUrl(const GURL& url, + const std::string& cookie) { + // Use the newer NPAPI way if available + if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { + npapi::SetValueForURL(instance_, NPNURLVCookie, url.spec().c_str(), + cookie.c_str(), cookie.length()); + } else { + DLOG(INFO) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO."; + DLOG(INFO) << "Attempting to set cookie using XPCOM cookie service"; + if (np_utils::SetCookiesUsingXPCOMCookieService(instance_, url.spec(), + cookie)) { + DLOG(INFO) << "Successfully set cookies using XPCOM cookie service"; + DLOG(INFO) << cookie.c_str(); + } else { + NOTREACHED() << "Failed to set cookies for host"; + } + } +} + +void NPAPIUrlRequestManager::GetCookiesForUrl(const GURL& url, int cookie_id) { + std::string cookie_string; + bool success = true; + + if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { + char* cookies = NULL; + unsigned int cookie_length = 0; + NPError ret = npapi::GetValueForURL(instance_, NPNURLVCookie, + url.spec().c_str(), &cookies, + &cookie_length); + if (ret == NPERR_NO_ERROR) { + DLOG(INFO) << "Obtained cookies:" << cookies << " from host"; + cookie_string.append(cookies, cookie_length); + npapi::MemFree(cookies); + } else { + success = false; + } + } else { + DLOG(INFO) << "Host does not support NPVERS_HAS_URL_AND_AUTH_INFO."; + DLOG(INFO) << "Attempting to read cookie using XPCOM cookie service"; + if (np_utils::GetCookiesUsingXPCOMCookieService(instance_, url.spec(), + &cookie_string)) { + DLOG(INFO) << "Successfully read cookies using XPCOM cookie service"; + DLOG(INFO) << cookie_string.c_str(); + } else { + success = false; + } + } + + if (!success) + DLOG(INFO) << "Failed to return cookies for url:" << url.spec().c_str(); + + OnCookiesRetrieved(success, url, cookie_string, cookie_id); +} + // PluginRequestDelegate implementation. // Callbacks from NPAPIUrlRequest. Simply forward to the delegate. void NPAPIUrlRequestManager::OnResponseStarted(int request_id, @@ -272,6 +328,11 @@ void NPAPIUrlRequestManager::OnResponseEnd(int request_id, delegate_->OnResponseEnd(request_id, status); } +void NPAPIUrlRequestManager::OnCookiesRetrieved(bool success, const GURL& url, + const std::string& cookie_string, int cookie_id) { + delegate_->OnCookiesRetrieved(success, url, cookie_string, cookie_id); +} + // Notifications from browser. Find the NPAPIUrlRequest and forward to it. NPError NPAPIUrlRequestManager::NewStream(NPMIMEType type, NPStream* stream, @@ -331,4 +392,3 @@ scoped_refptr<NPAPIUrlRequest> NPAPIUrlRequestManager::LookupRequest( return index->second; return NULL; } - diff --git a/chrome_frame/npapi_url_request.h b/chrome_frame/npapi_url_request.h index a059176..022c048 100644 --- a/chrome_frame/npapi_url_request.h +++ b/chrome_frame/npapi_url_request.h @@ -34,7 +34,7 @@ class NPAPIUrlRequestManager : public PluginUrlRequestManager, private: // PluginUrlRequestManager implementation. Called from AutomationClient. - virtual bool IsThreadSafe(); + virtual PluginUrlRequestManager::ThreadSafeFlags GetThreadSafeFlags(); virtual void StartRequest(int request_id, const IPC::AutomationURLRequest& request_info); virtual void ReadRequest(int request_id, int bytes_to_read); @@ -43,6 +43,8 @@ class NPAPIUrlRequestManager : public PluginUrlRequestManager, // Not yet implemented. } virtual void StopAll(); + virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie); + virtual void GetCookiesForUrl(const GURL& url, int cookie_id); // Outstanding requests map. typedef std::map<int, scoped_refptr<NPAPIUrlRequest> > RequestMap; @@ -56,6 +58,8 @@ class NPAPIUrlRequestManager : public PluginUrlRequestManager, const std::string& redirect_url, int redirect_status); virtual void OnReadComplete(int request_id, const std::string& data); virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); + virtual void OnCookiesRetrieved(bool success, const GURL& url, + const std::string& cookie_string, int cookie_id); static inline NPAPIUrlRequest* RequestFromNotifyData(void* notify_data) { return reinterpret_cast<NPAPIUrlRequest*>(notify_data); diff --git a/chrome_frame/plugin_url_request.h b/chrome_frame/plugin_url_request.h index aea4fa8..60e73d4 100644 --- a/chrome_frame/plugin_url_request.h +++ b/chrome_frame/plugin_url_request.h @@ -32,9 +32,9 @@ class DECLSPEC_NOVTABLE PluginUrlRequestDelegate { // NOLINT virtual void AddPrivacyDataForUrl(const std::string& url, const std::string& policy_ref, int32 flags) {} - virtual bool SendIPCMessage(IPC::Message* message) { - return false; - } + virtual void OnCookiesRetrieved(bool success, const GURL& url, + const std::string& cookie_string, + int cookie_id) = 0; protected: PluginUrlRequestDelegate() {} ~PluginUrlRequestDelegate() {} @@ -53,7 +53,15 @@ class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT delegate_ = delegate; } - virtual bool IsThreadSafe() = 0; + enum ThreadSafeFlags { + NOT_THREADSAFE = 0x00, + START_REQUEST_THREADSAFE = 0x01, + STOP_REQUEST_THREADSAFE = 0x02, + READ_REQUEST_THREADSAFE = 0x04, + DOWNLOAD_REQUEST_THREADSAFE = 0x08, + COOKIE_REQUEST_THREADSAFE = 0x10 + }; + virtual ThreadSafeFlags GetThreadSafeFlags() = 0; // These are called directly from Automation Client when network related // automation messages are received from Chrome. @@ -80,14 +88,13 @@ class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT StopAll(); } - bool GetCookiesFromHost(int tab_handle, const GURL& url, - int cookie_id) { - return GetCookiesForUrl(tab_handle, url, cookie_id); + void GetCookiesFromHost(int tab_handle, const GURL& url, int cookie_id) { + GetCookiesForUrl(url, cookie_id); } - bool SetCookiesInHost(int tab_handle, const GURL& url, + void SetCookiesInHost(int tab_handle, const GURL& url, const std::string& cookie) { - return SetCookiesForUrl(tab_handle, url, cookie); + SetCookiesForUrl(url, cookie); } protected: @@ -101,19 +108,8 @@ class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT virtual void EndRequest(int request_id) = 0; virtual void DownloadRequestInHost(int request_id) = 0; virtual void StopAll() = 0; - - // The default handling for these functions which get and set cookies - // is to return false, which basically ensures that the default handling - // of processing the corresponding cookie IPCs occurs in the UI thread. - virtual bool GetCookiesForUrl(int tab_handle, const GURL& url, - int cookie_id) { - return false; - } - - virtual bool SetCookiesForUrl(int tab_handle, const GURL& url, - const std::string& cookie) { - return false; - } + virtual void GetCookiesForUrl(const GURL& url, int cookie_id) = 0; + virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie) = 0; }; // Used as base class. Holds Url request properties (url, method, referrer..) diff --git a/chrome_frame/test/url_request_test.cc b/chrome_frame/test/url_request_test.cc index 5be343f9..35f0f81 100644 --- a/chrome_frame/test/url_request_test.cc +++ b/chrome_frame/test/url_request_test.cc @@ -96,6 +96,8 @@ class MockUrlDelegate : public PluginUrlRequestDelegate { MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); MOCK_METHOD2(OnResponseEnd, void(int request_id, const URLRequestStatus& status)); + MOCK_METHOD4(OnCookiesRetrieved, void(bool success, const GURL& url, + const std::string& cookie, int cookie_id)); static bool ImplementsThreadSafeReferenceCounting() { return false; diff --git a/chrome_frame/urlmon_url_request.cc b/chrome_frame/urlmon_url_request.cc index e3cc03b..cc0c872 100644 --- a/chrome_frame/urlmon_url_request.cc +++ b/chrome_frame/urlmon_url_request.cc @@ -936,8 +936,9 @@ net::Error UrlmonUrlRequest::HresultToNetError(HRESULT hr) { } -bool UrlmonUrlRequestManager::IsThreadSafe() { - return false; +PluginUrlRequestManager::ThreadSafeFlags + UrlmonUrlRequestManager::GetThreadSafeFlags() { + return PluginUrlRequestManager::NOT_THREADSAFE; } void UrlmonUrlRequestManager::SetInfoForUrl(const std::wstring& url, @@ -1013,9 +1014,7 @@ void UrlmonUrlRequestManager::DownloadRequestInHost(int request_id) { } } -bool UrlmonUrlRequestManager::GetCookiesForUrl(int tab_handle, - const GURL& url, - int cookie_id) { +void UrlmonUrlRequestManager::GetCookiesForUrl(const GURL& url, int cookie_id) { DWORD cookie_size = 0; bool success = true; std::string cookie_string; @@ -1040,22 +1039,14 @@ bool UrlmonUrlRequestManager::GetCookiesForUrl(int tab_handle, DLOG(INFO) << "InternetGetCookie failed. Error: " << error; } - if (delegate_) { - delegate_->SendIPCMessage( - new AutomationMsg_GetCookiesHostResponse(0, tab_handle, success, - url, cookie_string, - cookie_id)); - } - + OnCookiesRetrieved(success, url, cookie_string, cookie_id); if (!success && !error) cookie_action = COOKIEACTION_SUPPRESS; AddPrivacyDataForUrl(url.spec(), "", cookie_action); - return true; } -bool UrlmonUrlRequestManager::SetCookiesForUrl(int tab_handle, - const GURL& url, +void UrlmonUrlRequestManager::SetCookiesForUrl(const GURL& url, const std::string& cookie) { std::string name; std::string data; @@ -1087,7 +1078,6 @@ bool UrlmonUrlRequestManager::SetCookiesForUrl(int tab_handle, int32 cookie_action = MapCookieStateToCookieAction(cookie_state); AddPrivacyDataForUrl(url.spec(), "", cookie_action); - return true; } void UrlmonUrlRequestManager::EndRequest(int request_id) { @@ -1147,6 +1137,11 @@ void UrlmonUrlRequestManager::OnResponseEnd(int request_id, --calling_delegate_; } +void UrlmonUrlRequestManager::OnCookiesRetrieved(bool success, const GURL& url, + const std::string& cookie_string, int cookie_id) { + delegate_->OnCookiesRetrieved(success, url, cookie_string, cookie_id); +} + scoped_refptr<UrlmonUrlRequest> UrlmonUrlRequestManager::LookupRequest( int request_id) { RequestMap::iterator it = request_map_.find(request_id); @@ -1191,4 +1186,3 @@ void UrlmonUrlRequestManager::AddPrivacyDataForUrl( 0); } } - diff --git a/chrome_frame/urlmon_url_request.h b/chrome_frame/urlmon_url_request.h index 7e45123..0b8898e 100644 --- a/chrome_frame/urlmon_url_request.h +++ b/chrome_frame/urlmon_url_request.h @@ -78,18 +78,15 @@ class UrlmonUrlRequestManager void Release() {} // PluginUrlRequestManager implementation. - virtual bool IsThreadSafe(); + virtual PluginUrlRequestManager::ThreadSafeFlags GetThreadSafeFlags(); virtual void StartRequest(int request_id, const IPC::AutomationURLRequest& request_info); virtual void ReadRequest(int request_id, int bytes_to_read); virtual void EndRequest(int request_id); virtual void DownloadRequestInHost(int request_id); virtual void StopAll(); - - virtual bool GetCookiesForUrl(int tab_handle, const GURL& url, - int cookie_id); - virtual bool SetCookiesForUrl(int tab_handle, const GURL& url, - const std::string& cookie); + virtual void GetCookiesForUrl(const GURL& url, int cookie_id); + virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie); // PluginUrlRequestDelegate implementation virtual void OnResponseStarted(int request_id, const char* mime_type, @@ -99,6 +96,9 @@ class UrlmonUrlRequestManager int redirect_status); virtual void OnReadComplete(int request_id, const std::string& data); virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); + virtual void OnCookiesRetrieved(bool success, const GURL& url, + const std::string& cookie_string, + int cookie_id); // Map for (request_id <-> UrlmonUrlRequest) typedef std::map<int, scoped_refptr<UrlmonUrlRequest> > RequestMap; |