| OLD | NEW |
| 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 "content/public/renderer/render_view.h" |
| 9 #include "extensions/common/extension_messages.h" |
| 10 #include "extensions/renderer/script_context.h" |
| 8 #include "third_party/WebKit/public/platform/WebCString.h" | 11 #include "third_party/WebKit/public/platform/WebCString.h" |
| 9 #include "third_party/WebKit/public/platform/WebURL.h" | 12 #include "third_party/WebKit/public/platform/WebURL.h" |
| 10 #include "third_party/WebKit/public/web/WebBlob.h" | 13 #include "third_party/WebKit/public/web/WebBlob.h" |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 | 16 |
| 14 // Expects a single Blob argument. Returns the Blob's UUID. | 17 // Expects a single Blob argument. Returns the Blob's UUID. |
| 15 void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) { | 18 void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 16 DCHECK_EQ(1, args.Length()); | 19 DCHECK_EQ(1, args.Length()); |
| 17 blink::WebBlob blob = blink::WebBlob::fromV8Value(args[0]); | 20 blink::WebBlob blob = blink::WebBlob::fromV8Value(args[0]); |
| 18 args.GetReturnValue().Set( | 21 args.GetReturnValue().Set( |
| 19 v8::String::NewFromUtf8(args.GetIsolate(), blob.uuid().utf8().data())); | 22 v8::String::NewFromUtf8(args.GetIsolate(), blob.uuid().utf8().data())); |
| 20 } | 23 } |
| 21 | 24 |
| 25 // Take ownership of a Blob created on the browser process. Expects the Blob's |
| 26 // UUID, type, and size as arguments. Returns the Blob we just took to |
| 27 // Javascript. |
| 28 void TakeBrowserProcessBlob(extensions::ScriptContext* context, |
| 29 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 30 DCHECK_EQ(3, args.Length()); |
| 31 DCHECK(args[0]->IsString()); |
| 32 DCHECK(args[1]->IsString()); |
| 33 DCHECK(args[2]->IsInt32()); |
| 34 std::string uuid(*v8::String::Utf8Value(args[0]->ToString())); |
| 35 std::string type(*v8::String::Utf8Value(args[1]->ToString())); |
| 36 blink::WebBlob blob = blink::WebBlob::createFromUUID( |
| 37 blink::WebString::fromUTF8(uuid), blink::WebString::fromUTF8(type), |
| 38 args[2]->Int32Value()); |
| 39 args.GetReturnValue().Set(blob.toV8Value()); |
| 40 |
| 41 context->GetRenderView()->Send(new ExtensionHostMsg_BlobOwnershipTaken( |
| 42 context->GetRenderView()->GetRoutingID(), uuid)); |
| 43 } |
| 44 |
| 22 } // namespace | 45 } // namespace |
| 23 | 46 |
| 24 namespace extensions { | 47 namespace extensions { |
| 25 | 48 |
| 26 BlobNativeHandler::BlobNativeHandler(ScriptContext* context) | 49 BlobNativeHandler::BlobNativeHandler(ScriptContext* context) |
| 27 : ObjectBackedNativeHandler(context) { | 50 : ObjectBackedNativeHandler(context) { |
| 28 RouteFunction("GetBlobUuid", base::Bind(&GetBlobUuid)); | 51 RouteFunction("GetBlobUuid", base::Bind(&GetBlobUuid)); |
| 52 RouteFunction("TakeBrowserProcessBlob", |
| 53 base::Bind(&TakeBrowserProcessBlob, context)); |
| 29 } | 54 } |
| 30 | 55 |
| 31 } // namespace extensions | 56 } // namespace extensions |
| OLD | NEW |