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

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

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

Powered by Google App Engine
This is Rietveld 408576698