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

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

Issue 1174343003: blink:bindings: Passes the global context instead of |this| in JS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/app_runtime_custom_bindings.h" 5 #include "extensions/renderer/app_runtime_custom_bindings.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "extensions/renderer/script_context.h"
9 #include "third_party/WebKit/public/platform/WebCString.h" 10 #include "third_party/WebKit/public/platform/WebCString.h"
10 #include "third_party/WebKit/public/platform/WebString.h" 11 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebBlob.h" 12 #include "third_party/WebKit/public/web/WebBlob.h"
12 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 13 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
13 14
14 using blink::WebBlob; 15 using blink::WebBlob;
15 using blink::WebSerializedScriptValue; 16 using blink::WebSerializedScriptValue;
16 using blink::WebString; 17 using blink::WebString;
17 18
18 namespace { 19 namespace {
(...skipping 12 matching lines...) Expand all
31 void SerializeToString(const v8::FunctionCallbackInfo<v8::Value>& args) { 32 void SerializeToString(const v8::FunctionCallbackInfo<v8::Value>& args) {
32 DCHECK(args.Length() == 1); 33 DCHECK(args.Length() == 1);
33 WebSerializedScriptValue data = WebSerializedScriptValue::serialize(args[0]); 34 WebSerializedScriptValue data = WebSerializedScriptValue::serialize(args[0]);
34 WebString data_webstring = data.toString(); 35 WebString data_webstring = data.toString();
35 36
36 std::string v = std::string(data_webstring.utf8()); 37 std::string v = std::string(data_webstring.utf8());
37 args.GetReturnValue().Set( 38 args.GetReturnValue().Set(
38 v8::String::NewFromUtf8(args.GetIsolate(), v.c_str())); 39 v8::String::NewFromUtf8(args.GetIsolate(), v.c_str()));
39 } 40 }
40 41
41 void CreateBlob(const v8::FunctionCallbackInfo<v8::Value>& args) { 42 } // namespace
43
44 namespace extensions {
45
46 AppRuntimeCustomBindings::AppRuntimeCustomBindings(ScriptContext* context)
47 : ObjectBackedNativeHandler(context) {
48 RouteFunction("DeserializeString", base::Bind(&DeserializeString));
49 RouteFunction("SerializeToString", base::Bind(&SerializeToString));
50 RouteFunction("CreateBlob", base::Bind(&AppRuntimeCustomBindings::CreateBlob,
51 base::Unretained(this)));
52 }
53
54 void AppRuntimeCustomBindings::CreateBlob(
55 const v8::FunctionCallbackInfo<v8::Value>& args) {
42 DCHECK(args.Length() == 2); 56 DCHECK(args.Length() == 2);
43 DCHECK(args[0]->IsString()); 57 DCHECK(args[0]->IsString());
44 DCHECK(args[1]->IsNumber()); 58 DCHECK(args[1]->IsNumber());
45 59
46 std::string blob_file_path(*v8::String::Utf8Value(args[0])); 60 std::string blob_file_path(*v8::String::Utf8Value(args[0]));
47 std::string blob_length_string(*v8::String::Utf8Value(args[1])); 61 std::string blob_length_string(*v8::String::Utf8Value(args[1]));
48 int64 blob_length = 0; 62 int64 blob_length = 0;
49 DCHECK(base::StringToInt64(blob_length_string, &blob_length)); 63 DCHECK(base::StringToInt64(blob_length_string, &blob_length));
50 blink::WebBlob web_blob = 64 blink::WebBlob web_blob =
51 WebBlob::createFromFile(WebString::fromUTF8(blob_file_path), blob_length); 65 WebBlob::createFromFile(WebString::fromUTF8(blob_file_path), blob_length);
52 args.GetReturnValue().Set( 66 args.GetReturnValue().Set(
53 web_blob.toV8Value(args.Holder(), args.GetIsolate())); 67 web_blob.toV8Value(context()->v8_context()->Global(), args.GetIsolate()));
54 }
55
56 } // namespace
57
58 namespace extensions {
59
60 AppRuntimeCustomBindings::AppRuntimeCustomBindings(ScriptContext* context)
61 : ObjectBackedNativeHandler(context) {
62 RouteFunction("DeserializeString", base::Bind(&DeserializeString));
63 RouteFunction("SerializeToString", base::Bind(&SerializeToString));
64 RouteFunction("CreateBlob", base::Bind(&CreateBlob));
65 } 68 }
66 69
67 } // namespace extensions 70 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/app_runtime_custom_bindings.h ('k') | extensions/renderer/blob_native_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698