blob: e047d96b739e6902de7b631716040ba6278b21f5 [file] [log] [blame]
[email protected]701a94e2014-04-17 04:37:371// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]4d6f38f2013-06-18 11:09:582// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]701a94e2014-04-17 04:37:375#include "extensions/renderer/blob_native_handler.h"
[email protected]4d6f38f2013-06-18 11:09:586
7#include "base/bind.h"
yukishiino42bd05a22015-06-15 08:17:088#include "extensions/renderer/script_context.h"
[email protected]4d6f38f2013-06-18 11:09:589#include "third_party/WebKit/public/platform/WebURL.h"
10#include "third_party/WebKit/public/web/WebBlob.h"
11
12namespace {
13
[email protected]4084ef92013-11-22 22:30:1614// Expects a single Blob argument. Returns the Blob's UUID.
15void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) {
rdevlin.cronin415b73b2015-11-13 01:14:4716 CHECK_EQ(1, args.Length());
Blink Reformat1c4d759e2017-04-09 16:34:5417 blink::WebBlob blob = blink::WebBlob::FromV8Value(args[0]);
[email protected]9c47471e2013-11-28 14:41:2118 args.GetReturnValue().Set(
Blink Reformat1c4d759e2017-04-09 16:34:5419 v8::String::NewFromUtf8(args.GetIsolate(), blob.Uuid().Utf8().data()));
[email protected]4d6f38f2013-06-18 11:09:5820}
21
yukishiino42bd05a22015-06-15 08:17:0822} // namespace
23
24namespace extensions {
25
26BlobNativeHandler::BlobNativeHandler(ScriptContext* context)
Devlin Cronind9ea8342018-01-27 06:00:0427 : ObjectBackedNativeHandler(context) {}
28
29void BlobNativeHandler::AddRoutes() {
30 RouteHandlerFunction("GetBlobUuid", base::Bind(&GetBlobUuid));
31 RouteHandlerFunction("TakeBrowserProcessBlob",
32 base::Bind(&BlobNativeHandler::TakeBrowserProcessBlob,
33 base::Unretained(this)));
yukishiino42bd05a22015-06-15 08:17:0834}
35
[email protected]c0b5eb02014-06-02 17:28:1036// Take ownership of a Blob created on the browser process. Expects the Blob's
37// UUID, type, and size as arguments. Returns the Blob we just took to
38// Javascript. The Blob reference in the browser process is dropped through
39// a separate flow to avoid leaking Blobs if the script context is destroyed.
yukishiino42bd05a22015-06-15 08:17:0840void BlobNativeHandler::TakeBrowserProcessBlob(
41 const v8::FunctionCallbackInfo<v8::Value>& args) {
rdevlin.cronin415b73b2015-11-13 01:14:4742 CHECK_EQ(3, args.Length());
43 CHECK(args[0]->IsString());
44 CHECK(args[1]->IsString());
45 CHECK(args[2]->IsInt32());
Adam Klein686c0e52018-01-17 23:42:3346 v8::Isolate* isolate = args.GetIsolate();
47 std::string uuid(*v8::String::Utf8Value(isolate, args[0]));
48 std::string type(*v8::String::Utf8Value(isolate, args[1]));
Blink Reformat1c4d759e2017-04-09 16:34:5449 blink::WebBlob blob = blink::WebBlob::CreateFromUUID(
50 blink::WebString::FromUTF8(uuid), blink::WebString::FromUTF8(type),
51 args[2]->Int32Value());
52 args.GetReturnValue().Set(
Adam Klein686c0e52018-01-17 23:42:3353 blob.ToV8Value(context()->v8_context()->Global(), isolate));
[email protected]4d6f38f2013-06-18 11:09:5854}
55
56} // namespace extensions