1 // Copyright (c) 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.
5 #ifndef CONTENT_RENDERER_PEPPER_V8_VAR_CONVERTER_H
6 #define CONTENT_RENDERER_PEPPER_V8_VAR_CONVERTER_H
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/compiler_specific.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "ppapi/c/pp_instance.h"
13 #include "ppapi/c/pp_var.h"
14 #include "v8/include/v8.h"
15 #include "content/common/content_export.h"
23 class ResourceConverter;
25 class CONTENT_EXPORT V8VarConverter {
27 explicit V8VarConverter(PP_Instance instance);
28 // Constructor for testing.
29 V8VarConverter(PP_Instance instance,
30 scoped_ptr<ResourceConverter> resource_converter);
33 // Converts the given PP_Var to a v8::Value. True is returned upon success.
34 bool ToV8Value(const PP_Var& var,
35 v8::Handle<v8::Context> context,
36 v8::Handle<v8::Value>* result);
38 // Converts the given v8::Value to a PP_Var. Every PP_Var in the reference
39 // graph in the result will have a refcount equal to the number of references
40 // to it in the graph. The root of the result will have one additional
41 // reference. The callback is run when conversion is complete with the
42 // resulting var and a bool indicating success or failure. Conversion is
43 // asynchronous because converting some resources may result in communication
44 // across IPC. |context| is guaranteed to only be used synchronously.
46 v8::Handle<v8::Value> val,
47 v8::Handle<v8::Context> context,
48 const base::Callback<void(const ppapi::ScopedPPVar&, bool)>& callback);
51 // The message loop to run the callback to |FromV8Value| from.
52 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
54 // The converter to use for converting V8 vars to resources.
55 scoped_ptr<ResourceConverter> resource_converter_;
57 DISALLOW_COPY_AND_ASSIGN(V8VarConverter);
60 } // namespace content
62 #endif // CONTENT_RENDERER_PEPPER_V8_VAR_CONVERTER_H