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

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

Issue 1964483002: Revert of [Extensions] Update more bindings and allow for multiple feature access (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 "extensions/renderer/script_context.h" 8 #include "extensions/renderer/script_context.h"
9 #include "third_party/WebKit/public/platform/WebURL.h" 9 #include "third_party/WebKit/public/platform/WebURL.h"
10 #include "third_party/WebKit/public/web/WebBlob.h" 10 #include "third_party/WebKit/public/web/WebBlob.h"
11 11
12 namespace { 12 namespace {
13 13
14 // Expects a single Blob argument. Returns the Blob's UUID. 14 // Expects a single Blob argument. Returns the Blob's UUID.
15 void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) { 15 void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) {
16 CHECK_EQ(1, args.Length()); 16 CHECK_EQ(1, args.Length());
17 blink::WebBlob blob = blink::WebBlob::fromV8Value(args[0]); 17 blink::WebBlob blob = blink::WebBlob::fromV8Value(args[0]);
18 args.GetReturnValue().Set( 18 args.GetReturnValue().Set(
19 v8::String::NewFromUtf8(args.GetIsolate(), blob.uuid().utf8().data())); 19 v8::String::NewFromUtf8(args.GetIsolate(), blob.uuid().utf8().data()));
20 } 20 }
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace extensions { 24 namespace extensions {
25 25
26 BlobNativeHandler::BlobNativeHandler(ScriptContext* context) 26 BlobNativeHandler::BlobNativeHandler(ScriptContext* context)
27 : ObjectBackedNativeHandler(context) { 27 : ObjectBackedNativeHandler(context) {
28 RouteFunction("GetBlobUuid", 28 RouteFunction("GetBlobUuid", base::Bind(&GetBlobUuid));
29 std::vector<std::string>({"feedbackPrivate", "mediaGalleries"}),
30 base::Bind(&GetBlobUuid));
31 RouteFunction("TakeBrowserProcessBlob", 29 RouteFunction("TakeBrowserProcessBlob",
32 std::vector<std::string>({"printerProvider", "mediaGalleries"}),
33 base::Bind(&BlobNativeHandler::TakeBrowserProcessBlob, 30 base::Bind(&BlobNativeHandler::TakeBrowserProcessBlob,
34 base::Unretained(this))); 31 base::Unretained(this)));
35 } 32 }
36 33
37 // Take ownership of a Blob created on the browser process. Expects the Blob's 34 // Take ownership of a Blob created on the browser process. Expects the Blob's
38 // UUID, type, and size as arguments. Returns the Blob we just took to 35 // UUID, type, and size as arguments. Returns the Blob we just took to
39 // Javascript. The Blob reference in the browser process is dropped through 36 // Javascript. The Blob reference in the browser process is dropped through
40 // a separate flow to avoid leaking Blobs if the script context is destroyed. 37 // a separate flow to avoid leaking Blobs if the script context is destroyed.
41 void BlobNativeHandler::TakeBrowserProcessBlob( 38 void BlobNativeHandler::TakeBrowserProcessBlob(
42 const v8::FunctionCallbackInfo<v8::Value>& args) { 39 const v8::FunctionCallbackInfo<v8::Value>& args) {
43 CHECK_EQ(3, args.Length()); 40 CHECK_EQ(3, args.Length());
44 CHECK(args[0]->IsString()); 41 CHECK(args[0]->IsString());
45 CHECK(args[1]->IsString()); 42 CHECK(args[1]->IsString());
46 CHECK(args[2]->IsInt32()); 43 CHECK(args[2]->IsInt32());
47 std::string uuid(*v8::String::Utf8Value(args[0])); 44 std::string uuid(*v8::String::Utf8Value(args[0]));
48 std::string type(*v8::String::Utf8Value(args[1])); 45 std::string type(*v8::String::Utf8Value(args[1]));
49 blink::WebBlob blob = 46 blink::WebBlob blob =
50 blink::WebBlob::createFromUUID(blink::WebString::fromUTF8(uuid), 47 blink::WebBlob::createFromUUID(blink::WebString::fromUTF8(uuid),
51 blink::WebString::fromUTF8(type), 48 blink::WebString::fromUTF8(type),
52 args[2]->Int32Value()); 49 args[2]->Int32Value());
53 args.GetReturnValue().Set(blob.toV8Value( 50 args.GetReturnValue().Set(blob.toV8Value(
54 context()->v8_context()->Global(), args.GetIsolate())); 51 context()->v8_context()->Global(), args.GetIsolate()));
55 } 52 }
56 53
57 } // namespace extensions 54 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/app_window_custom_bindings.cc ('k') | extensions/renderer/context_menus_custom_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698