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

Unified Diff: webkit/plugins/ppapi/url_request_info_util.cc

Issue 10913257: Convert url request info to new proxy API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 3 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
« no previous file with comments | « webkit/plugins/ppapi/url_request_info_util.h ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/url_request_info_util.cc
diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc b/webkit/plugins/ppapi/url_request_info_util.cc
similarity index 65%
rename from webkit/plugins/ppapi/ppb_url_request_info_impl.cc
rename to webkit/plugins/ppapi/url_request_info_util.cc
index 16f111884269a64254d4062271bbdef4e05a12ab..1361acb047bbad76ff5a9555120ba2531098aefb 100644
--- a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc
+++ b/webkit/plugins/ppapi/url_request_info_util.cc
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
+#include "webkit/plugins/ppapi/url_request_info_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_util.h"
#include "net/http/http_util.h"
+#include "ppapi/shared_impl/url_request_info_data.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
@@ -25,7 +26,7 @@
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
#include "webkit/plugins/ppapi/resource_helper.h"
-using ppapi::PPB_URLRequestInfo_Data;
+using ppapi::URLRequestInfoData;
using ppapi::Resource;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_FileRef_API;
@@ -41,42 +42,106 @@ namespace ppapi {
namespace {
-const int32_t kDefaultPrefetchBufferUpperThreshold = 100 * 1000 * 1000;
-const int32_t kDefaultPrefetchBufferLowerThreshold = 50 * 1000 * 1000;
+// Appends the file ref given the Resource pointer associated with it to the
+// given HTTP body, returning true on success.
+bool AppendFileRefToBody(
+ Resource* file_ref_resource,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time,
+ WebHTTPBody *http_body) {
+ // Get the underlying file ref impl.
+ if (!file_ref_resource)
+ return false;
+ PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API();
+ if (!file_ref_api)
+ return false;
+ const PPB_FileRef_Impl* file_ref =
+ static_cast<PPB_FileRef_Impl*>(file_ref_api);
-} // namespace
+ PluginDelegate* plugin_delegate =
+ ResourceHelper::GetPluginDelegate(file_ref_resource);
+ if (!plugin_delegate)
+ return false;
+ FilePath platform_path;
+ switch (file_ref->GetFileSystemType()) {
+ case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
+ case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
+ // TODO(kinuko): remove this sync IPC when we fully support
+ // AppendURLRange for FileSystem URL.
+ plugin_delegate->SyncGetFileSystemPlatformPath(
+ file_ref->GetFileSystemURL(), &platform_path);
+ break;
+ case PP_FILESYSTEMTYPE_EXTERNAL:
+ platform_path = file_ref->GetSystemPath();
+ break;
+ default:
+ NOTREACHED();
+ }
+ http_body->appendFileRange(
+ webkit_glue::FilePathToWebString(platform_path),
+ start_offset,
+ number_of_bytes,
+ expected_last_modified_time);
+ return true;
+}
-PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(
- PP_Instance instance,
- const PPB_URLRequestInfo_Data& data)
- : PPB_URLRequestInfo_Shared(::ppapi::OBJECT_IS_IMPL, instance, data) {
+// Checks that the request data is valid. Returns false on failure. Note that
+// method and header validation is done by the URL loader when the request is
+// opened, and any access errors are returned asynchronously.
+bool ValidateURLRequestData(const ::ppapi::URLRequestInfoData& data) {
+ if (data.prefetch_buffer_lower_threshold < 0 ||
+ data.prefetch_buffer_upper_threshold < 0 ||
+ data.prefetch_buffer_upper_threshold <=
+ data.prefetch_buffer_lower_threshold) {
+ return false;
+ }
+ return true;
}
-PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() {
+// Ensures that the file_ref members of the given request info data are
+// populated from the resource IDs. Returns true on success.
+bool EnsureFileRefObjectsPopulated(::ppapi::URLRequestInfoData* data) {
+ // Get the Resource objects for any file refs with only host resource (this
+ // is the state of the request as it comes off IPC).
+ for (size_t i = 0; i < data->body.size(); ++i) {
+ URLRequestInfoData::BodyItem& item = data->body[i];
+ if (item.is_file && !item.file_ref) {
+ EnterResourceNoLock<PPB_FileRef_API> enter(
+ item.file_ref_host_resource.host_resource(), false);
+ if (!enter.succeeded())
+ return false;
+ item.file_ref = enter.resource();
+ }
+ }
+ return true;
}
-bool PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame,
- WebURLRequest* dest) {
- // In the out-of-process case, we've received the PPB_URLRequestInfo_Data
+} // namespace
+
+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 (!ValidateData())
+ if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data))
return false;
dest->initialize();
dest->setTargetType(WebURLRequest::TargetIsObject);
dest->setURL(frame->document().completeURL(WebString::fromUTF8(
- data().url)));
- dest->setDownloadToFile(data().stream_to_file);
- dest->setReportUploadProgress(data().record_upload_progress);
+ data->url)));
+ dest->setDownloadToFile(data->stream_to_file);
+ dest->setReportUploadProgress(data->record_upload_progress);
- if (!data().method.empty())
- dest->setHTTPMethod(WebString::fromUTF8(data().method));
+ if (!data->method.empty())
+ dest->setHTTPMethod(WebString::fromUTF8(data->method));
dest->setFirstPartyForCookies(frame->document().firstPartyForCookies());
- const std::string& headers = data().headers;
+ const std::string& headers = data->headers;
if (!headers.empty()) {
net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r");
while (it.GetNext()) {
@@ -87,11 +152,11 @@ bool PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame,
}
// Append the upload data.
- if (!data().body.empty()) {
+ if (!data->body.empty()) {
WebHTTPBody http_body;
http_body.initialize();
- for (size_t i = 0; i < data().body.size(); ++i) {
- const PPB_URLRequestInfo_Data::BodyItem& item = data().body[i];
+ for (size_t i = 0; i < data->body.size(); ++i) {
+ const URLRequestInfoData::BodyItem& item = data->body[i];
if (item.is_file) {
if (!AppendFileRefToBody(item.file_ref,
item.start_offset,
@@ -110,99 +175,33 @@ bool PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame,
// Add the "Referer" header if there is a custom referrer. Such requests
// require universal access. For all other requests, "Referer" will be set
// after header security checks are done in AssociatedURLLoader.
- if (data().has_custom_referrer_url && !data().custom_referrer_url.empty()) {
- frame->setReferrerForRequest(*dest, GURL(data().custom_referrer_url));
- }
+ if (data->has_custom_referrer_url && !data->custom_referrer_url.empty())
+ frame->setReferrerForRequest(*dest, GURL(data->custom_referrer_url));
- if (data().has_custom_content_transfer_encoding &&
- !data().custom_content_transfer_encoding.empty()) {
+ if (data->has_custom_content_transfer_encoding &&
+ !data->custom_content_transfer_encoding.empty()) {
dest->addHTTPHeaderField(
WebString::fromUTF8("Content-Transfer-Encoding"),
- WebString::fromUTF8(data().custom_content_transfer_encoding));
+ WebString::fromUTF8(data->custom_content_transfer_encoding));
}
- if (data().has_custom_user_agent) {
+ if (data->has_custom_user_agent) {
dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl(
WebKit::WebReferrerPolicyDefault, // Ignored.
- WebString::fromUTF8(data().custom_user_agent)));
+ WebString::fromUTF8(data->custom_user_agent)));
}
return true;
}
-bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const {
+bool URLRequestRequiresUniversalAccess(
+ const ::ppapi::URLRequestInfoData& data) {
return
- data().has_custom_referrer_url ||
- data().has_custom_content_transfer_encoding ||
- data().has_custom_user_agent ||
- url_util::FindAndCompareScheme(data().url, "javascript", NULL);
-}
-
-bool PPB_URLRequestInfo_Impl::ValidateData() {
- if (data().prefetch_buffer_lower_threshold < 0 ||
- data().prefetch_buffer_upper_threshold < 0 ||
- data().prefetch_buffer_upper_threshold <=
- data().prefetch_buffer_lower_threshold) {
- return false;
- }
-
- // Get the Resource objects for any file refs with only host resource (this
- // is the state of the request as it comes off IPC).
- for (size_t i = 0; i < data().body.size(); ++i) {
- PPB_URLRequestInfo_Data::BodyItem& item = data().body[i];
- if (item.is_file && !item.file_ref) {
- EnterResourceNoLock<PPB_FileRef_API> enter(
- item.file_ref_host_resource.host_resource(), false);
- if (!enter.succeeded())
- return false;
- item.file_ref = enter.resource();
- }
- }
- return true;
-}
-
-bool PPB_URLRequestInfo_Impl::AppendFileRefToBody(
- Resource* file_ref_resource,
- int64_t start_offset,
- int64_t number_of_bytes,
- PP_Time expected_last_modified_time,
- WebHTTPBody *http_body) {
- // Get the underlying file ref impl.
- if (!file_ref_resource)
- return false;
- PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API();
- if (!file_ref_api)
- return false;
- const PPB_FileRef_Impl* file_ref =
- static_cast<PPB_FileRef_Impl*>(file_ref_api);
-
- PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
- if (!plugin_delegate)
- return false;
-
- FilePath platform_path;
- switch (file_ref->GetFileSystemType()) {
- case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
- case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
- // TODO(kinuko): remove this sync IPC when we fully support
- // AppendURLRange for FileSystem URL.
- plugin_delegate->SyncGetFileSystemPlatformPath(
- file_ref->GetFileSystemURL(), &platform_path);
- break;
- case PP_FILESYSTEMTYPE_EXTERNAL:
- platform_path = file_ref->GetSystemPath();
- break;
- default:
- NOTREACHED();
- }
- http_body->appendFileRange(
- webkit_glue::FilePathToWebString(platform_path),
- start_offset,
- number_of_bytes,
- expected_last_modified_time);
- return true;
+ data.has_custom_referrer_url ||
+ data.has_custom_content_transfer_encoding ||
+ data.has_custom_user_agent ||
+ url_util::FindAndCompareScheme(data.url, "javascript", NULL);
}
-
} // namespace ppapi
} // namespace webkit
« no previous file with comments | « webkit/plugins/ppapi/url_request_info_util.h ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698