diff options
7 files changed, 92 insertions, 229 deletions
diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc index 17cc168..869850a 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc @@ -2704,13 +2704,46 @@ void PepperPluginInstanceImpl::Navigate( return; } - scoped_ptr<ppapi::URLRequestInfoData> completed_request( - new ppapi::URLRequestInfoData(request)); + ::ppapi::URLRequestInfoData completed_request = request; - std::string target_string(target); - CreateWebURLRequest(completed_request.Pass(), frame, - base::Bind(&PepperPluginInstanceImpl::DidCreateWebURLRequest, - AsWeakPtr(), target_string, from_user_action, callback)); + WebURLRequest web_request; + if (!CreateWebURLRequest(&completed_request, frame, &web_request)) { + base::MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED))); + return; + } + web_request.setFirstPartyForCookies(document.firstPartyForCookies()); + web_request.setHasUserGesture(from_user_action); + + GURL gurl(web_request.url()); + + int32_t rc = PP_ERROR_FAILED; + if (gurl.SchemeIs("javascript")) { + // In imitation of the NPAPI implementation, only |target_frame == frame| is + // allowed for security reasons. + WebFrame* target_frame = + frame->view()->findFrameByName(WebString::fromUTF8(target), frame); + if (target_frame != frame) { + rc = PP_ERROR_NOACCESS; + } else { + // TODO(viettrungluu): NPAPI sends the result back to the plugin -- do we + // need that? + WebString result = container_->executeScriptURL(gurl, from_user_action); + rc = result.isNull() ? PP_ERROR_FAILED : PP_OK; + } + } else { + // Only GETs and POSTs are supported. + if (web_request.httpMethod() != "GET" && + web_request.httpMethod() != "POST") { + rc = PP_ERROR_BADARGUMENT; + } else { + WebString target_str = WebString::fromUTF8(target); + container_->loadFrameRequest(web_request, target_str, false, NULL); + rc = PP_OK; + } + } + base::MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(callback, static_cast<int32_t>(rc))); } bool PepperPluginInstanceImpl::CanAccessMainFrame() const { @@ -2807,52 +2840,4 @@ void PepperPluginInstanceImpl::UnSetAndDeleteLockTargetAdapter() { } } -void PepperPluginInstanceImpl::DidCreateWebURLRequest( - const std::string& target, - bool from_user_action, - const base::Callback<void(int32_t)>& callback, - scoped_ptr<ppapi::URLRequestInfoData> data, - bool success, - scoped_ptr<WebURLRequest> web_request) { - WebDocument document = container_->element().document(); - WebFrame* frame = document.frame(); - if (!success || !frame) { - callback.Run(PP_ERROR_FAILED); - return; - } - - web_request->setFirstPartyForCookies(document.firstPartyForCookies()); - web_request->setHasUserGesture(from_user_action); - - GURL gurl(web_request->url()); - - int32_t rc = PP_ERROR_FAILED; - if (gurl.SchemeIs("javascript")) { - // In imitation of the NPAPI implementation, only |target_frame == frame| is - // allowed for security reasons. - WebFrame* target_frame = - frame->view()->findFrameByName(WebString::fromUTF8(target), frame); - if (target_frame != frame) { - rc = PP_ERROR_NOACCESS; - } else { - // TODO(viettrungluu): NPAPI sends the result back to the plugin -- do we - // need that? - WebString result = container_->executeScriptURL(gurl, from_user_action); - rc = result.isNull() ? PP_ERROR_FAILED : PP_OK; - } - } else { - // Only GETs and POSTs are supported. - if (web_request->httpMethod() != "GET" && - web_request->httpMethod() != "POST") { - rc = PP_ERROR_BADARGUMENT; - } else { - WebString target_str = WebString::fromUTF8(target); - container_->loadFrameRequest( - *web_request.release(), target_str, false, NULL); - rc = PP_OK; - } - } - callback.Run(rc); -} - } // namespace content diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.h b/content/renderer/pepper/pepper_plugin_instance_impl.h index da9bf1a..3f5b886 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.h +++ b/content/renderer/pepper/pepper_plugin_instance_impl.h @@ -49,7 +49,6 @@ #include "third_party/WebKit/public/platform/WebCanvas.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" -#include "third_party/WebKit/public/platform/WebURLRequest.h" #include "third_party/WebKit/public/platform/WebURLResponse.h" #include "third_party/WebKit/public/web/WebPlugin.h" #include "third_party/WebKit/public/web/WebUserGestureToken.h" @@ -648,14 +647,6 @@ class CONTENT_EXPORT PepperPluginInstanceImpl MouseLockDispatcher::LockTarget* GetOrCreateLockTargetAdapter(); void UnSetAndDeleteLockTargetAdapter(); - void DidCreateWebURLRequest( - const std::string& target, - bool from_user_action, - const base::Callback<void(int32_t)>& callback, - scoped_ptr<ppapi::URLRequestInfoData> data, - bool success, - scoped_ptr<WebKit::WebURLRequest> web_request); - PepperHelperImpl* helper_; RenderViewImpl* render_view_; scoped_refptr<PluginModule> module_; diff --git a/content/renderer/pepper/pepper_url_loader_host.cc b/content/renderer/pepper/pepper_url_loader_host.cc index 2d1fed1..8343f19 100644 --- a/content/renderer/pepper/pepper_url_loader_host.cc +++ b/content/renderer/pepper/pepper_url_loader_host.cc @@ -230,10 +230,9 @@ int32_t PepperURLLoaderHost::InternalOnHostMsgOpen( // Create a copy of the request data since CreateWebURLRequest will populate // the file refs. - scoped_ptr<ppapi::URLRequestInfoData> filled_in_request_data( - new ppapi::URLRequestInfoData(request_data)); + ppapi::URLRequestInfoData filled_in_request_data = request_data; - if (URLRequestRequiresUniversalAccess(*filled_in_request_data) && + if (URLRequestRequiresUniversalAccess(filled_in_request_data) && !has_universal_access_) { ppapi::PpapiGlobals::Get()->LogWithSource( pp_instance(), PP_LOGLEVEL_ERROR, std::string(), @@ -250,36 +249,10 @@ int32_t PepperURLLoaderHost::InternalOnHostMsgOpen( WebFrame* frame = GetFrame(); if (!frame) return PP_ERROR_FAILED; - - CreateWebURLRequest(filled_in_request_data.Pass(), frame, - base::Bind(&PepperURLLoaderHost::DidCreateWebURLRequest, - weak_factory_.GetWeakPtr())); - - // Although the request is technically pending, this is not a "Call" message - // so we don't return COMPLETIONPENDING. - return PP_OK; -} - -void PepperURLLoaderHost::DidCreateWebURLRequest( - scoped_ptr<ppapi::URLRequestInfoData> filled_in_request_data, - bool success, - scoped_ptr<WebURLRequest> web_request) { - WebFrame* frame = GetFrame(); - if (!success || !frame) { - SendUpdateToPlugin( - new PpapiPluginMsg_URLLoader_FinishedLoading(PP_ERROR_FAILED)); - return; - } - - // Ensure again that we're not in progress. - if (loader_.get()) { - NOTREACHED(); - SendUpdateToPlugin( - new PpapiPluginMsg_URLLoader_FinishedLoading(PP_ERROR_INPROGRESS)); - return; - } - - web_request->setRequestorProcessID(renderer_ppapi_host_->GetPluginPID()); + WebURLRequest web_request; + if (!CreateWebURLRequest(&filled_in_request_data, frame, &web_request)) + return PP_ERROR_FAILED; + web_request.setRequestorProcessID(renderer_ppapi_host_->GetPluginPID()); WebURLLoaderOptions options; if (has_universal_access_) { @@ -289,10 +262,10 @@ void PepperURLLoaderHost::DidCreateWebURLRequest( } else { // All other HTTP requests are untrusted. options.untrustedHTTP = true; - if (filled_in_request_data->allow_cross_origin_requests) { + if (filled_in_request_data.allow_cross_origin_requests) { // Allow cross-origin requests with access control. The request specifies // if credentials are to be sent. - options.allowCredentials = filled_in_request_data->allow_credentials; + options.allowCredentials = filled_in_request_data.allow_credentials; options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; } else { @@ -302,14 +275,16 @@ void PepperURLLoaderHost::DidCreateWebURLRequest( } loader_.reset(frame->createAssociatedURLLoader(options)); - if (!loader_.get()) { - SendUpdateToPlugin( - new PpapiPluginMsg_URLLoader_FinishedLoading(PP_ERROR_FAILED)); - } + if (!loader_.get()) + return PP_ERROR_FAILED; // Don't actually save the request until we know we're going to load. - request_data_ = *filled_in_request_data; - loader_->loadAsynchronously(*web_request, this); + request_data_ = filled_in_request_data; + loader_->loadAsynchronously(web_request, this); + + // Although the request is technically pending, this is not a "Call" message + // so we don't return COMPLETIONPENDING. + return PP_OK; } int32_t PepperURLLoaderHost::OnHostMsgSetDeferLoading( diff --git a/content/renderer/pepper/pepper_url_loader_host.h b/content/renderer/pepper/pepper_url_loader_host.h index 185458d..aa07411 100644 --- a/content/renderer/pepper/pepper_url_loader_host.h +++ b/content/renderer/pepper/pepper_url_loader_host.h @@ -15,7 +15,6 @@ #include "ppapi/shared_impl/url_request_info_data.h" #include "ppapi/shared_impl/url_response_info_data.h" #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" -#include "third_party/WebKit/public/platform/WebURLRequest.h" namespace WebKit { class WebFrame; @@ -72,11 +71,6 @@ class PepperURLLoaderHost const ppapi::URLRequestInfoData& request_data); int32_t InternalOnHostMsgOpen(ppapi::host::HostMessageContext* context, const ppapi::URLRequestInfoData& request_data); - void DidCreateWebURLRequest( - scoped_ptr<ppapi::URLRequestInfoData> filled_in_request_data, - bool success, - scoped_ptr<WebKit::WebURLRequest> web_request); - int32_t OnHostMsgSetDeferLoading(ppapi::host::HostMessageContext* context, bool defers_loading); int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); diff --git a/content/renderer/pepper/pepper_url_request_unittest.cc b/content/renderer/pepper/pepper_url_request_unittest.cc index fc13200..20e7f92 100644 --- a/content/renderer/pepper/pepper_url_request_unittest.cc +++ b/content/renderer/pepper/pepper_url_request_unittest.cc @@ -55,8 +55,7 @@ namespace content { class URLRequestInfoTest : public RenderViewTest { public: - URLRequestInfoTest() : pp_instance_(1234), - get_download_to_file_result_(false) { + URLRequestInfoTest() : pp_instance_(1234) { } virtual void SetUp() OVERRIDE { @@ -76,85 +75,35 @@ class URLRequestInfoTest : public RenderViewTest { } bool GetDownloadToFile() { - get_download_to_file_result_ = false; - - scoped_ptr<URLRequestInfoData> data( - new URLRequestInfoData(info_->GetData())); - CreateWebURLRequest(data.Pass(), GetMainFrame(), - base::Bind(&URLRequestInfoTest::GetDownloadToFileCallback, - base::Unretained(this))); - base::MessageLoop::current()->RunUntilIdle(); - - return get_download_to_file_result_; - } - - void GetDownloadToFileCallback(scoped_ptr<URLRequestInfoData> data, - bool success, - scoped_ptr<WebURLRequest> web_request) { - EXPECT_TRUE(success); - get_download_to_file_result_ = web_request->downloadToFile(); + WebURLRequest web_request; + URLRequestInfoData data = info_->GetData(); + if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) + return false; + return web_request.downloadToFile(); } WebCString GetURL() { - get_url_result_ = WebCString(); - - scoped_ptr<URLRequestInfoData> data( - new URLRequestInfoData(info_->GetData())); - CreateWebURLRequest(data.Pass(), GetMainFrame(), - base::Bind(&URLRequestInfoTest::GetURLCallback, - base::Unretained(this))); - base::MessageLoop::current()->RunUntilIdle(); - - return get_url_result_; - } - - void GetURLCallback(scoped_ptr<URLRequestInfoData> data, - bool success, - scoped_ptr<WebURLRequest> web_request) { - EXPECT_TRUE(success); - get_url_result_ = web_request->url().spec(); + WebURLRequest web_request; + URLRequestInfoData data = info_->GetData(); + if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) + return WebCString(); + return web_request.url().spec(); } WebString GetMethod() { - get_method_result_ = WebString(); - - scoped_ptr<URLRequestInfoData> data( - new URLRequestInfoData(info_->GetData())); - CreateWebURLRequest(data.Pass(), GetMainFrame(), - base::Bind(&URLRequestInfoTest::GetMethodCallback, - base::Unretained(this))); - base::MessageLoop::current()->RunUntilIdle(); - - return get_method_result_; - } - - void GetMethodCallback(scoped_ptr<URLRequestInfoData> data, - bool success, - scoped_ptr<WebURLRequest> web_request) { - EXPECT_TRUE(success); - get_method_result_ = web_request->httpMethod(); + WebURLRequest web_request; + URLRequestInfoData data = info_->GetData(); + if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) + return WebString(); + return web_request.httpMethod(); } WebString GetHeaderValue(const char* field) { - get_header_value_result_ = WebString(); - - scoped_ptr<URLRequestInfoData> data( - new URLRequestInfoData(info_->GetData())); - CreateWebURLRequest(data.Pass(), GetMainFrame(), - base::Bind(&URLRequestInfoTest::GetHeaderValueCallback, - base::Unretained(this), field)); - base::MessageLoop::current()->RunUntilIdle(); - - return get_header_value_result_; - } - - void GetHeaderValueCallback(const char* field, - scoped_ptr<URLRequestInfoData> data, - bool success, - scoped_ptr<WebURLRequest> web_request) { - EXPECT_TRUE(success); - get_header_value_result_ = web_request->httpHeaderField( - WebString::fromUTF8(field)); + WebURLRequest web_request; + URLRequestInfoData data = info_->GetData(); + if (!CreateWebURLRequest(&data, GetMainFrame(), &web_request)) + return WebString(); + return web_request.httpHeaderField(WebString::fromUTF8(field)); } bool SetBooleanProperty(PP_URLRequestProperty prop, bool b) { @@ -170,12 +119,6 @@ class URLRequestInfoTest : public RenderViewTest { ::ppapi::TestGlobals test_globals_; scoped_refptr<URLRequestInfoResource> info_; - - // Result fields for getting responses from asynchronous operations. - bool get_download_to_file_result_; - WebCString get_url_result_; - WebString get_method_result_; - WebString get_header_value_result_; }; TEST_F(URLRequestInfoTest, GetInterface) { diff --git a/content/renderer/pepper/url_request_info_util.cc b/content/renderer/pepper/url_request_info_util.cc index 8a471e3..1948e75 100644 --- a/content/renderer/pepper/url_request_info_util.cc +++ b/content/renderer/pepper/url_request_info_util.cc @@ -119,22 +119,14 @@ bool EnsureFileRefObjectsPopulated(::ppapi::URLRequestInfoData* data) { } // namespace -void CreateWebURLRequest( - scoped_ptr<ppapi::URLRequestInfoData> data, - WebFrame* frame, - CreateWebURLRequestCallback callback) { - scoped_ptr<WebURLRequest> dest(new WebURLRequest); - +bool CreateWebURLRequest(::ppapi::URLRequestInfoData* data, + WebFrame* frame, + WebURLRequest* dest) { // In the out-of-process case, we've received the URLRequestInfoData // from the untrusted plugin and done no validation on it. We need to be // sure it's not being malicious by checking everything for consistency. - if (!ValidateURLRequestData(*data) || - !EnsureFileRefObjectsPopulated(data.get())) { - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(callback, base::Passed(&data), false, base::Passed(&dest))); - return; - } + if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data)) + return false; dest->initialize(); dest->setTargetType(WebURLRequest::TargetIsObject); @@ -169,15 +161,8 @@ void CreateWebURLRequest( item.start_offset, item.number_of_bytes, item.expected_last_modified_time, - &http_body)) { - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(callback, - base::Passed(&data), - false, - base::Passed(&dest))); - return; - } + &http_body)) + return false; } else { DCHECK(!item.data.empty()); http_body.appendData(WebData(item.data)); @@ -206,9 +191,8 @@ void CreateWebURLRequest( WebString::fromUTF8(data->custom_user_agent), was_after_preconnect_request)); } - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(callback, base::Passed(&data), true, base::Passed(&dest))); + + return true; } bool URLRequestRequiresUniversalAccess( diff --git a/content/renderer/pepper/url_request_info_util.h b/content/renderer/pepper/url_request_info_util.h index 79636bc..4261535 100644 --- a/content/renderer/pepper/url_request_info_util.h +++ b/content/renderer/pepper/url_request_info_util.h @@ -5,9 +5,7 @@ #ifndef CONTENT_RENDERER_PEPPER_URL_REQUEST_INFO_UTIL_H_ #define CONTENT_RENDERER_PEPPER_URL_REQUEST_INFO_UTIL_H_ -#include "base/callback_forward.h" #include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" #include "content/common/content_export.h" namespace ppapi { @@ -21,20 +19,13 @@ class WebURLRequest; namespace content { -typedef base::Callback< - void(scoped_ptr<ppapi::URLRequestInfoData> data, - bool success, - scoped_ptr<WebKit::WebURLRequest> dest)> CreateWebURLRequestCallback; - -// Creates the WebKit URL request from the current request info. Invokes the -// callback with a bool of true on success, or false if the request is invalid -// (in which case the other callback argument may be partially initialized). -// Any upload files with only resource IDs (no file ref pointers) will be -// populated by this function on success. -CONTENT_EXPORT void CreateWebURLRequest( - scoped_ptr<ppapi::URLRequestInfoData> data, - WebKit::WebFrame* frame, - CreateWebURLRequestCallback callback); +// Creates the WebKit URL request from the current request info. Returns true +// on success, false if the request is invalid (in which case *dest may be +// partially initialized). Any upload files with only resource IDs (no file ref +// pointers) will be populated by this function on success. +CONTENT_EXPORT bool CreateWebURLRequest(::ppapi::URLRequestInfoData* data, + WebKit::WebFrame* frame, + WebKit::WebURLRequest* dest); // Returns true if universal access is required to use the given request. CONTENT_EXPORT bool URLRequestRequiresUniversalAccess( |