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

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

Issue 2931393003: [Content] Update V8ValueConverter::create to return a std::unique_ptr (Closed)
Patch Set: rebase Created 3 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/send_request_natives.h" 5 #include "extensions/renderer/send_request_natives.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/timer/elapsed_timer.h" 11 #include "base/timer/elapsed_timer.h"
12 #include "content/public/child/v8_value_converter.h" 12 #include "content/public/child/v8_value_converter.h"
13 #include "extensions/renderer/request_sender.h" 13 #include "extensions/renderer/request_sender.h"
14 #include "extensions/renderer/script_context.h" 14 #include "extensions/renderer/script_context.h"
15 15
16 using content::V8ValueConverter;
17
18 namespace extensions { 16 namespace extensions {
19 17
20 SendRequestNatives::SendRequestNatives(RequestSender* request_sender, 18 SendRequestNatives::SendRequestNatives(RequestSender* request_sender,
21 ScriptContext* context) 19 ScriptContext* context)
22 : ObjectBackedNativeHandler(context), request_sender_(request_sender) { 20 : ObjectBackedNativeHandler(context), request_sender_(request_sender) {
23 RouteFunction( 21 RouteFunction(
24 "StartRequest", 22 "StartRequest",
25 base::Bind(&SendRequestNatives::StartRequest, base::Unretained(this))); 23 base::Bind(&SendRequestNatives::StartRequest, base::Unretained(this)));
26 RouteFunction( 24 RouteFunction(
27 "GetGlobal", 25 "GetGlobal",
28 base::Bind(&SendRequestNatives::GetGlobal, base::Unretained(this))); 26 base::Bind(&SendRequestNatives::GetGlobal, base::Unretained(this)));
29 } 27 }
30 28
31 // Starts an API request to the browser, with an optional callback. The 29 // Starts an API request to the browser, with an optional callback. The
32 // callback will be dispatched to EventBindings::HandleResponse. 30 // callback will be dispatched to EventBindings::HandleResponse.
33 void SendRequestNatives::StartRequest( 31 void SendRequestNatives::StartRequest(
34 const v8::FunctionCallbackInfo<v8::Value>& args) { 32 const v8::FunctionCallbackInfo<v8::Value>& args) {
35 base::ElapsedTimer timer; 33 base::ElapsedTimer timer;
36 CHECK_EQ(5, args.Length()); 34 CHECK_EQ(5, args.Length());
37 std::string name = *v8::String::Utf8Value(args[0]); 35 std::string name = *v8::String::Utf8Value(args[0]);
38 bool has_callback = args[2]->BooleanValue(); 36 bool has_callback = args[2]->BooleanValue();
39 bool for_io_thread = args[3]->BooleanValue(); 37 bool for_io_thread = args[3]->BooleanValue();
40 bool preserve_null_in_objects = args[4]->BooleanValue(); 38 bool preserve_null_in_objects = args[4]->BooleanValue();
41 39
42 int request_id = request_sender_->GetNextRequestId(); 40 int request_id = request_sender_->GetNextRequestId();
43 args.GetReturnValue().Set(static_cast<int32_t>(request_id)); 41 args.GetReturnValue().Set(static_cast<int32_t>(request_id));
44 42
45 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 43 std::unique_ptr<content::V8ValueConverter> converter =
44 content::V8ValueConverter::Create();
46 45
47 // See http://crbug.com/149880. The context menus APIs relies on this, but 46 // See http://crbug.com/149880. The context menus APIs relies on this, but
48 // we shouldn't really be doing it (e.g. for the sake of the storage API). 47 // we shouldn't really be doing it (e.g. for the sake of the storage API).
49 converter->SetFunctionAllowed(true); 48 converter->SetFunctionAllowed(true);
50 49
51 // See http://crbug.com/694248. 50 // See http://crbug.com/694248.
52 converter->SetConvertNegativeZeroToInt(true); 51 converter->SetConvertNegativeZeroToInt(true);
53 52
54 if (!preserve_null_in_objects) 53 if (!preserve_null_in_objects)
55 converter->SetStripNullFromObjects(true); 54 converter->SetStripNullFromObjects(true);
(...skipping 25 matching lines...) Expand all
81 CHECK(args[0]->IsObject()); 80 CHECK(args[0]->IsObject());
82 v8::Local<v8::Context> v8_context = 81 v8::Local<v8::Context> v8_context =
83 v8::Local<v8::Object>::Cast(args[0])->CreationContext(); 82 v8::Local<v8::Object>::Cast(args[0])->CreationContext();
84 if (ContextCanAccessObject(context()->v8_context(), v8_context->Global(), 83 if (ContextCanAccessObject(context()->v8_context(), v8_context->Global(),
85 false)) { 84 false)) {
86 args.GetReturnValue().Set(v8_context->Global()); 85 args.GetReturnValue().Set(v8_context->Global());
87 } 86 }
88 } 87 }
89 88
90 } // namespace extensions 89 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_injection.cc ('k') | extensions/renderer/test_features_native_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698