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

Side by Side Diff: extensions/renderer/blob_native_handler.cc

Issue 250143002: Media Galleries API: Audio/Video attached pictures support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Create Blobs on browser-process, eliminating two IPC copies. Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/blob_native_handler.h" 5 #include "extensions/renderer/blob_native_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "third_party/WebKit/public/platform/Platform.h"
9 #include "third_party/WebKit/public/platform/WebBlobRegistry.h"
8 #include "third_party/WebKit/public/platform/WebCString.h" 10 #include "third_party/WebKit/public/platform/WebCString.h"
9 #include "third_party/WebKit/public/platform/WebURL.h" 11 #include "third_party/WebKit/public/platform/WebURL.h"
10 #include "third_party/WebKit/public/web/WebBlob.h" 12 #include "third_party/WebKit/public/web/WebBlob.h"
11 13
12 namespace { 14 namespace {
13 15
14 // Expects a single Blob argument. Returns the Blob's UUID. 16 // Expects a single Blob argument. Returns the Blob's UUID.
15 void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) { 17 void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) {
16 DCHECK_EQ(1, args.Length()); 18 DCHECK_EQ(1, args.Length());
17 blink::WebBlob blob = blink::WebBlob::fromV8Value(args[0]); 19 blink::WebBlob blob = blink::WebBlob::fromV8Value(args[0]);
18 args.GetReturnValue().Set( 20 args.GetReturnValue().Set(
19 v8::String::NewFromUtf8(args.GetIsolate(), blob.uuid().utf8().data())); 21 v8::String::NewFromUtf8(args.GetIsolate(), blob.uuid().utf8().data()));
20 } 22 }
21 23
24 // Take ownership of a Blob created on the browse process. Expects the Blob's
25 // UUID, type, and size as arguments.
26 void TakeBrowserProcessBlob(const v8::FunctionCallbackInfo<v8::Value>& args) {
27 DCHECK_EQ(3, args.Length());
28 DCHECK(args[0]->IsString());
29 DCHECK(args[1]->IsString());
30 DCHECK(args[2]->IsInt32());
31 std::string uuid(*v8::String::Utf8Value(args[0]->ToString()));
32 std::string type(*v8::String::Utf8Value(args[1]->ToString()));
33 blink::WebBlob blob = blink::WebBlob::createFromUUID(
34 blink::WebString::fromUTF8(uuid), blink::WebString::fromUTF8(type),
35 args[2]->Int32Value());
36 args.GetReturnValue().Set(blob.toV8Value());
37
38 // Need to decrement the refcount to compensate for the extra count left over
tommycli 2014/04/29 23:29:26 This is also janky, but necessary to keep the refc
michaeln 2014/05/01 21:27:35 This new case of creating a blob in the browser an
39 // from the construction process in the browser side.
40 blink::Platform::current()->blobRegistry()->removeBlobDataRef(
41 blink::WebString::fromUTF8(uuid));
42 }
43
22 } // namespace 44 } // namespace
23 45
24 namespace extensions { 46 namespace extensions {
25 47
26 BlobNativeHandler::BlobNativeHandler(ScriptContext* context) 48 BlobNativeHandler::BlobNativeHandler(ScriptContext* context)
27 : ObjectBackedNativeHandler(context) { 49 : ObjectBackedNativeHandler(context) {
28 RouteFunction("GetBlobUuid", base::Bind(&GetBlobUuid)); 50 RouteFunction("GetBlobUuid", base::Bind(&GetBlobUuid));
51 RouteFunction("TakeBrowserProcessBlob", base::Bind(&TakeBrowserProcessBlob));
29 } 52 }
30 53
31 } // namespace extensions 54 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698