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 "base/memory/weak_ptr.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "content/renderer/pepper/host_resource_var.h" | 16 #include "content/renderer/pepper/host_resource_var.h" |
16 #include "ppapi/c/pp_instance.h" | 17 #include "ppapi/c/pp_instance.h" |
17 #include "ppapi/c/pp_var.h" | 18 #include "ppapi/c/pp_var.h" |
18 #include "v8/include/v8.h" | 19 #include "v8/include/v8.h" |
19 | 20 |
20 namespace IPC { | 21 namespace IPC { |
21 class Message; | 22 class Message; |
22 } | 23 } |
23 | 24 |
24 namespace ppapi { | 25 namespace ppapi { |
| 26 |
25 class ScopedPPVar; | 27 class ScopedPPVar; |
| 28 |
| 29 namespace proxy { |
| 30 struct CompletedBrowserResourceHosts; |
26 } | 31 } |
27 | 32 |
| 33 } // namespace ppapi |
| 34 |
28 namespace content { | 35 namespace content { |
29 | 36 |
30 // This class is responsible for converting V8 vars to Pepper resources. | 37 // This class is responsible for converting V8 vars to Pepper resources. |
31 class CONTENT_EXPORT ResourceConverter { | 38 class CONTENT_EXPORT ResourceConverter { |
32 public: | 39 public: |
33 virtual ~ResourceConverter(); | 40 virtual ~ResourceConverter(); |
34 | 41 |
35 // Reset the state of the resource converter. | 42 // Reset the state of the resource converter. |
36 virtual void Reset() = 0; | 43 virtual void Reset() = 0; |
37 | 44 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 void Flush(const base::Callback<void(bool)>& callback) override; | 79 void Flush(const base::Callback<void(bool)>& callback) override; |
73 bool FromV8Value(v8::Handle<v8::Object> val, | 80 bool FromV8Value(v8::Handle<v8::Object> val, |
74 v8::Handle<v8::Context> context, | 81 v8::Handle<v8::Context> context, |
75 PP_Var* result, | 82 PP_Var* result, |
76 bool* was_resource) override; | 83 bool* was_resource) override; |
77 bool ToV8Value(const PP_Var& var, | 84 bool ToV8Value(const PP_Var& var, |
78 v8::Handle<v8::Context> context, | 85 v8::Handle<v8::Context> context, |
79 v8::Handle<v8::Value>* result) override; | 86 v8::Handle<v8::Value>* result) override; |
80 | 87 |
81 private: | 88 private: |
| 89 typedef std::vector<scoped_refptr<HostResourceVar>> HostResourceVarVector; |
| 90 |
| 91 struct PendingConversion { |
| 92 PendingConversion(); |
| 93 ~PendingConversion(); |
| 94 int sequence_num; |
| 95 base::Callback<void(bool)> callback; |
| 96 HostResourceVarVector browser_vars; |
| 97 }; |
| 98 |
82 // Creates a resource var with the given |pending_renderer_id| and | 99 // Creates a resource var with the given |pending_renderer_id| and |
83 // |create_message| to be sent to the plugin. | 100 // |create_message| to be sent to the plugin. |
84 scoped_refptr<HostResourceVar> CreateResourceVar( | 101 scoped_refptr<HostResourceVar> CreateResourceVar( |
85 int pending_renderer_id, | 102 int pending_renderer_id, |
86 const IPC::Message& create_message); | 103 const IPC::Message& create_message); |
87 // Creates a resource var with the given |pending_renderer_id| and | 104 // Creates a resource var with the given |pending_renderer_id| and |
88 // |create_message| to be sent to the plugin. Also sends | 105 // |create_message| to be sent to the plugin. Also sends |
89 // |browser_host_create_message| to the browser, and asynchronously stores the | 106 // |browser_host_create_message| to the browser, and asynchronously stores the |
90 // resulting browser host ID in the newly created var. | 107 // resulting browser host ID in the newly created var. |
91 scoped_refptr<HostResourceVar> CreateResourceVarWithBrowserHost( | 108 scoped_refptr<HostResourceVar> CreateResourceVarWithBrowserHost( |
92 int pending_renderer_id, | 109 int pending_renderer_id, |
93 const IPC::Message& create_message, | 110 const IPC::Message& create_message, |
94 const IPC::Message& browser_host_create_message); | 111 const IPC::Message& browser_host_create_message); |
95 | 112 |
| 113 void FlushComplete(const ppapi::proxy::CompletedBrowserResourceHosts& hosts); |
| 114 |
96 // The instance this ResourceConverter is associated with. | 115 // The instance this ResourceConverter is associated with. |
97 PP_Instance instance_; | 116 PP_Instance instance_; |
98 | 117 |
99 // A list of the messages to create the browser hosts. This is a parallel | 118 // A list of the messages to create the browser hosts. This is a parallel |
100 // array to |browser_vars|. It is kept as a parallel array so that it can be | 119 // array to |browser_vars|. It is kept as a parallel array so that it can be |
101 // conveniently passed to |CreateBrowserResourceHosts|. | 120 // conveniently passed to |CreateBrowserResourceHosts|. |
102 std::vector<IPC::Message> browser_host_create_messages_; | 121 std::vector<IPC::Message> browser_host_create_messages_; |
103 // A list of the resource vars associated with browser hosts. | 122 HostResourceVarVector browser_vars_; |
104 std::vector<scoped_refptr<HostResourceVar> > browser_vars_; | 123 |
| 124 std::queue<PendingConversion> pending_conversions_; |
| 125 |
| 126 base::WeakPtrFactory<ResourceConverterImpl> weak_ptr_factory_; |
105 | 127 |
106 DISALLOW_COPY_AND_ASSIGN(ResourceConverterImpl); | 128 DISALLOW_COPY_AND_ASSIGN(ResourceConverterImpl); |
107 }; | 129 }; |
108 | 130 |
109 } // namespace content | 131 } // namespace content |
110 #endif // CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H | 132 #endif // CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H |
OLD | NEW |