Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/extensions/pepper_request_natives.h" | |
| 6 | |
| 7 #include "base/values.h" | |
|
yzshen1
2013/11/26 19:33:11
nit: please include what this file uses:
logging.h
Sam McNally
2013/11/27 23:40:26
Done.
| |
| 8 #include "chrome/renderer/extensions/chrome_v8_context.h" | |
| 9 #include "content/public/renderer/v8_value_converter.h" | |
| 10 | |
| 11 namespace extensions { | |
| 12 | |
| 13 PepperRequestNatives::PepperRequestNatives(ChromeV8Context* context) | |
| 14 : ObjectBackedNativeHandler(context) { | |
| 15 RouteFunction( | |
| 16 "SendResponse", | |
| 17 base::Bind(&PepperRequestNatives::SendResponse, base::Unretained(this))); | |
| 18 } | |
| 19 | |
| 20 void PepperRequestNatives::SendResponse( | |
| 21 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 22 DCHECK(args.Length() == 3); | |
| 23 DCHECK(args[0]->IsInt32()); | |
| 24 int request_id = args[0]->Int32Value(); | |
| 25 bool success = true; | |
| 26 std::string error; | |
| 27 if (args[2]->IsString()) { | |
| 28 error = *v8::String::Utf8Value(args[2]); | |
| 29 success = false; | |
| 30 } | |
| 31 scoped_ptr<content::V8ValueConverter> converter( | |
| 32 content::V8ValueConverter::create()); | |
| 33 scoped_ptr<const base::Value> result( | |
| 34 converter->FromV8Value(args[1], context()->v8_context())); | |
| 35 if (!result) { | |
| 36 result.reset(new base::ListValue); | |
| 37 success = false; | |
| 38 } | |
| 39 const base::ListValue* result_list = NULL; | |
| 40 if (!result->GetAsList(&result_list)) | |
| 41 NOTREACHED(); | |
| 42 context()->pepper_request_proxy()->OnResponse( | |
| 43 request_id, success, *result_list, error); | |
| 44 } | |
| 45 | |
| 46 } // namespace extensions | |
| OLD | NEW |