Commit 4128665d authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

Use existing BlobPtr when possible when converting blob to DataPipeGetter.

EncodedFormData already (optionally) contains a blink::BlobDataHandle,
so rather than looking up the same blob again by uuid just use that
handle if we have it. This should ensure no races are possible between a
blob being dereferenced (in blink) and the blob being converted into a
DataPipeGetter (as looking up the blob by UUID is an async operation).

Bug: 740744, 821878
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: Ic8464b778ec91d10fdbd7688e2b680b9464fe1dc
Reviewed-on: https://chromium-review.googlesource.com/964716
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543794}
parent ca8b8d58
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/WebKit/public/mojom/blob/blob.mojom.h" #include "third_party/WebKit/public/mojom/blob/blob.mojom.h"
#include "third_party/WebKit/public/mojom/blob/blob_registry.mojom.h"
#include "third_party/WebKit/public/platform/FilePathConversion.h" #include "third_party/WebKit/public/platform/FilePathConversion.h"
#include "third_party/WebKit/public/platform/Platform.h" #include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebData.h" #include "third_party/WebKit/public/platform/WebData.h"
...@@ -444,19 +443,12 @@ scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebURLRequest( ...@@ -444,19 +443,12 @@ scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebURLRequest(
return GetRequestBodyForWebHTTPBody(request.HttpBody()); return GetRequestBodyForWebHTTPBody(request.HttpBody());
} }
void GetBlobRegistry(blink::mojom::BlobRegistryRequest request) {
ChildThreadImpl::current()->GetConnector()->BindInterface(
mojom::kBrowserServiceName, std::move(request));
}
scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebHTTPBody( scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebHTTPBody(
const blink::WebHTTPBody& httpBody) { const blink::WebHTTPBody& httpBody) {
scoped_refptr<network::ResourceRequestBody> request_body = scoped_refptr<network::ResourceRequestBody> request_body =
new network::ResourceRequestBody(); new network::ResourceRequestBody();
size_t i = 0; size_t i = 0;
WebHTTPBody::Element element; WebHTTPBody::Element element;
// TODO(jam): cache this somewhere so we don't request it each time?
blink::mojom::BlobRegistryPtr blob_registry;
while (httpBody.ElementAt(i++, element)) { while (httpBody.ElementAt(i++, element)) {
switch (element.type) { switch (element.type) {
case WebHTTPBody::Element::kTypeData: case WebHTTPBody::Element::kTypeData:
...@@ -482,24 +474,10 @@ scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebHTTPBody( ...@@ -482,24 +474,10 @@ scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebHTTPBody(
break; break;
case WebHTTPBody::Element::kTypeBlob: { case WebHTTPBody::Element::kTypeBlob: {
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) { if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
if (!blob_registry.is_bound()) { DCHECK(element.optional_blob_handle.is_valid());
if (ChildThreadImpl::current()) { blink::mojom::BlobPtr blob_ptr(
ChildThreadImpl::current()->GetConnector()->BindInterface( blink::mojom::BlobPtrInfo(std::move(element.optional_blob_handle),
mojom::kBrowserServiceName, MakeRequest(&blob_registry)); blink::mojom::Blob::Version_));
} else {
// TODO(sammc): We should use per-frame / per-worker
// InterfaceProvider instead (crbug.com/734210).
blink::Platform::Current()
->MainThread()
->GetTaskRunner()
->PostTask(FROM_HERE,
base::BindOnce(&GetBlobRegistry,
MakeRequest(&blob_registry)));
}
}
blink::mojom::BlobPtr blob_ptr;
blob_registry->GetBlobFromUUID(MakeRequest(&blob_ptr),
element.blob_uuid.Utf8());
network::mojom::DataPipeGetterPtr data_pipe_getter_ptr; network::mojom::DataPipeGetterPtr data_pipe_getter_ptr;
// Object deletes itself. // Object deletes itself.
......
...@@ -86,6 +86,12 @@ bool WebHTTPBody::ElementAt(size_t index, Element& result) const { ...@@ -86,6 +86,12 @@ bool WebHTTPBody::ElementAt(size_t index, Element& result) const {
case FormDataElement::kEncodedBlob: case FormDataElement::kEncodedBlob:
result.type = Element::kTypeBlob; result.type = Element::kTypeBlob;
result.blob_uuid = element.blob_uuid_; result.blob_uuid = element.blob_uuid_;
if (element.optional_blob_data_handle_) {
result.optional_blob_handle =
element.optional_blob_data_handle_->CloneBlobPtr()
.PassInterface()
.PassHandle();
}
break; break;
case FormDataElement::kDataPipe: case FormDataElement::kDataPipe:
result.type = Element::kTypeDataPipe; result.type = Element::kTypeDataPipe;
......
...@@ -59,6 +59,7 @@ class WebHTTPBody { ...@@ -59,6 +59,7 @@ class WebHTTPBody {
long long file_length; // -1 means to the end of the file. long long file_length; // -1 means to the end of the file.
double modification_time; double modification_time;
WebString blob_uuid; WebString blob_uuid;
mojo::ScopedMessagePipeHandle optional_blob_handle;
// |data_pipe_getter| is a network::mojom::DataPipeGetterPtr. It's declared // |data_pipe_getter| is a network::mojom::DataPipeGetterPtr. It's declared
// as a generic ScopedMessagePipeHandle so it can be "cast" between Blink // as a generic ScopedMessagePipeHandle so it can be "cast" between Blink
// and non-Blink variant types. // and non-Blink variant types.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment