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