| 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 <string> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 12 #include "content/public/renderer/v8_value_converter.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 PepperRequestNatives::PepperRequestNatives(ChromeV8Context* context) |
| 17 : ObjectBackedNativeHandler(context) { |
| 18 RouteFunction( |
| 19 "SendResponse", |
| 20 base::Bind(&PepperRequestNatives::SendResponse, base::Unretained(this))); |
| 21 } |
| 22 |
| 23 void PepperRequestNatives::SendResponse( |
| 24 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 25 DCHECK(args.Length() == 3); |
| 26 DCHECK(args[0]->IsInt32()); |
| 27 int request_id = args[0]->Int32Value(); |
| 28 bool success = true; |
| 29 std::string error; |
| 30 if (args[2]->IsString()) { |
| 31 error = *v8::String::Utf8Value(args[2]); |
| 32 success = false; |
| 33 } |
| 34 scoped_ptr<content::V8ValueConverter> converter( |
| 35 content::V8ValueConverter::create()); |
| 36 scoped_ptr<const base::Value> result( |
| 37 converter->FromV8Value(args[1], context()->v8_context())); |
| 38 if (!result) { |
| 39 result.reset(new base::ListValue); |
| 40 success = false; |
| 41 } |
| 42 const base::ListValue* result_list = NULL; |
| 43 if (!result->GetAsList(&result_list)) |
| 44 NOTREACHED(); |
| 45 context()->pepper_request_proxy()->OnResponseReceived( |
| 46 request_id, success, *result_list, error); |
| 47 } |
| 48 |
| 49 } // namespace extensions |
| OLD | NEW |