| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H | 5 #ifndef CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H |
| 6 #define CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H | 6 #define CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/renderer/pepper/host_resource_var.h" | 15 #include "content/renderer/pepper/host_resource_var.h" |
| 16 #include "ppapi/c/pp_instance.h" | 16 #include "ppapi/c/pp_instance.h" |
| 17 #include "ppapi/c/pp_var.h" | 17 #include "ppapi/c/pp_var.h" |
| 18 #include "v8/include/v8.h" | 18 #include "v8/include/v8.h" |
| 19 | 19 |
| 20 namespace IPC { | 20 namespace IPC { |
| 21 class Message; | 21 class Message; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace ppapi { | 24 namespace ppapi { |
| 25 class ScopedPPVar; | 25 class ScopedPPVar; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 class RendererPpapiHost; | |
| 31 | |
| 32 // This class is responsible for converting V8 vars to Pepper resources. | 30 // This class is responsible for converting V8 vars to Pepper resources. |
| 33 class CONTENT_EXPORT ResourceConverter { | 31 class CONTENT_EXPORT ResourceConverter { |
| 34 public: | 32 public: |
| 35 virtual ~ResourceConverter(); | 33 virtual ~ResourceConverter(); |
| 36 | 34 |
| 37 // Reset the state of the resource converter. | 35 // Reset the state of the resource converter. |
| 38 virtual void Reset() = 0; | 36 virtual void Reset() = 0; |
| 39 | 37 |
| 40 // Returns true if Flush() needs to be called before using any vars created | 38 // Returns true if Flush() needs to be called before using any vars created |
| 41 // by the resource converter. | 39 // by the resource converter. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 58 // Attempts to convert a PP_Var to a V8 object. |var| must have type | 56 // Attempts to convert a PP_Var to a V8 object. |var| must have type |
| 59 // PP_VARTYPE_RESOURCE. On success, writes the resulting value to |result| and | 57 // PP_VARTYPE_RESOURCE. On success, writes the resulting value to |result| and |
| 60 // returns true. If an error occurs, returns false. | 58 // returns true. If an error occurs, returns false. |
| 61 virtual bool ToV8Value(const PP_Var& var, | 59 virtual bool ToV8Value(const PP_Var& var, |
| 62 v8::Handle<v8::Context> context, | 60 v8::Handle<v8::Context> context, |
| 63 v8::Handle<v8::Value>* result) = 0; | 61 v8::Handle<v8::Value>* result) = 0; |
| 64 }; | 62 }; |
| 65 | 63 |
| 66 class ResourceConverterImpl : public ResourceConverter { | 64 class ResourceConverterImpl : public ResourceConverter { |
| 67 public: | 65 public: |
| 68 ResourceConverterImpl(PP_Instance instance, RendererPpapiHost* host); | 66 explicit ResourceConverterImpl(PP_Instance instance); |
| 69 virtual ~ResourceConverterImpl(); | 67 virtual ~ResourceConverterImpl(); |
| 70 | 68 |
| 71 // ResourceConverter overrides. | 69 // ResourceConverter overrides. |
| 72 virtual void Reset() override; | 70 virtual void Reset() override; |
| 73 virtual bool NeedsFlush() override; | 71 virtual bool NeedsFlush() override; |
| 74 virtual void Flush(const base::Callback<void(bool)>& callback) override; | 72 virtual void Flush(const base::Callback<void(bool)>& callback) override; |
| 75 virtual bool FromV8Value(v8::Handle<v8::Object> val, | 73 virtual bool FromV8Value(v8::Handle<v8::Object> val, |
| 76 v8::Handle<v8::Context> context, | 74 v8::Handle<v8::Context> context, |
| 77 PP_Var* result, | 75 PP_Var* result, |
| 78 bool* was_resource) override; | 76 bool* was_resource) override; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 // |create_message| to be sent to the plugin. Also sends | 88 // |create_message| to be sent to the plugin. Also sends |
| 91 // |browser_host_create_message| to the browser, and asynchronously stores the | 89 // |browser_host_create_message| to the browser, and asynchronously stores the |
| 92 // resulting browser host ID in the newly created var. | 90 // resulting browser host ID in the newly created var. |
| 93 scoped_refptr<HostResourceVar> CreateResourceVarWithBrowserHost( | 91 scoped_refptr<HostResourceVar> CreateResourceVarWithBrowserHost( |
| 94 int pending_renderer_id, | 92 int pending_renderer_id, |
| 95 const IPC::Message& create_message, | 93 const IPC::Message& create_message, |
| 96 const IPC::Message& browser_host_create_message); | 94 const IPC::Message& browser_host_create_message); |
| 97 | 95 |
| 98 // The instance this ResourceConverter is associated with. | 96 // The instance this ResourceConverter is associated with. |
| 99 PP_Instance instance_; | 97 PP_Instance instance_; |
| 100 // The RendererPpapiHost to use to create browser hosts. | |
| 101 RendererPpapiHost* host_; | |
| 102 | 98 |
| 103 // A list of the messages to create the browser hosts. This is a parallel | 99 // A list of the messages to create the browser hosts. This is a parallel |
| 104 // array to |browser_vars|. It is kept as a parallel array so that it can be | 100 // array to |browser_vars|. It is kept as a parallel array so that it can be |
| 105 // conveniently passed to |CreateBrowserResourceHosts|. | 101 // conveniently passed to |CreateBrowserResourceHosts|. |
| 106 std::vector<IPC::Message> browser_host_create_messages_; | 102 std::vector<IPC::Message> browser_host_create_messages_; |
| 107 // A list of the resource vars associated with browser hosts. | 103 // A list of the resource vars associated with browser hosts. |
| 108 std::vector<scoped_refptr<HostResourceVar> > browser_vars_; | 104 std::vector<scoped_refptr<HostResourceVar> > browser_vars_; |
| 109 | 105 |
| 110 DISALLOW_COPY_AND_ASSIGN(ResourceConverterImpl); | 106 DISALLOW_COPY_AND_ASSIGN(ResourceConverterImpl); |
| 111 }; | 107 }; |
| 112 | 108 |
| 113 } // namespace content | 109 } // namespace content |
| 114 #endif // CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H | 110 #endif // CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H |
| OLD | NEW |