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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 // If NeedsFlush() is true then Flush() must be called before any vars created | 42 // If NeedsFlush() is true then Flush() must be called before any vars created |
43 // by the ResourceConverter are valid. It handles creating any resource hosts | 43 // by the ResourceConverter are valid. It handles creating any resource hosts |
44 // that need to be created. |callback| will always be called asynchronously. | 44 // that need to be created. |callback| will always be called asynchronously. |
45 virtual void Flush(const base::Callback<void(bool)>& callback) = 0; | 45 virtual void Flush(const base::Callback<void(bool)>& callback) = 0; |
46 | 46 |
47 // Attempts to convert a V8 object to a PP_Var with type PP_VARTYPE_RESOURCE. | 47 // Attempts to convert a V8 object to a PP_Var with type PP_VARTYPE_RESOURCE. |
48 // On success, writes the resulting var to |result|, sets |was_resource| to | 48 // On success, writes the resulting var to |result|, sets |was_resource| to |
49 // true and returns true. If |val| is not a resource, sets |was_resource| to | 49 // true and returns true. If |val| is not a resource, sets |was_resource| to |
50 // false and returns true. If an error occurs, returns false. | 50 // false and returns true. If an error occurs, returns false. |
51 virtual bool FromV8Value(v8::Handle<v8::Object> val, | 51 virtual bool FromV8Value(v8::Local<v8::Object> val, |
52 v8::Handle<v8::Context> context, | 52 v8::Local<v8::Context> context, |
53 PP_Var* result, | 53 PP_Var* result, |
54 bool* was_resource) = 0; | 54 bool* was_resource) = 0; |
55 | 55 |
56 // 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 |
57 // 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 |
58 // returns true. If an error occurs, returns false. | 58 // returns true. If an error occurs, returns false. |
59 virtual bool ToV8Value(const PP_Var& var, | 59 virtual bool ToV8Value(const PP_Var& var, |
60 v8::Handle<v8::Context> context, | 60 v8::Local<v8::Context> context, |
61 v8::Handle<v8::Value>* result) = 0; | 61 v8::Local<v8::Value>* result) = 0; |
62 }; | 62 }; |
63 | 63 |
64 class ResourceConverterImpl : public ResourceConverter { | 64 class ResourceConverterImpl : public ResourceConverter { |
65 public: | 65 public: |
66 explicit ResourceConverterImpl(PP_Instance instance); | 66 explicit ResourceConverterImpl(PP_Instance instance); |
67 ~ResourceConverterImpl() override; | 67 ~ResourceConverterImpl() override; |
68 | 68 |
69 // ResourceConverter overrides. | 69 // ResourceConverter overrides. |
70 void Reset() override; | 70 void Reset() override; |
71 bool NeedsFlush() override; | 71 bool NeedsFlush() override; |
72 void Flush(const base::Callback<void(bool)>& callback) override; | 72 void Flush(const base::Callback<void(bool)>& callback) override; |
73 bool FromV8Value(v8::Handle<v8::Object> val, | 73 bool FromV8Value(v8::Local<v8::Object> val, |
74 v8::Handle<v8::Context> context, | 74 v8::Local<v8::Context> context, |
75 PP_Var* result, | 75 PP_Var* result, |
76 bool* was_resource) override; | 76 bool* was_resource) override; |
77 bool ToV8Value(const PP_Var& var, | 77 bool ToV8Value(const PP_Var& var, |
78 v8::Handle<v8::Context> context, | 78 v8::Local<v8::Context> context, |
79 v8::Handle<v8::Value>* result) override; | 79 v8::Local<v8::Value>* result) override; |
80 | 80 |
81 private: | 81 private: |
82 // Creates a resource var with the given |pending_renderer_id| and | 82 // Creates a resource var with the given |pending_renderer_id| and |
83 // |create_message| to be sent to the plugin. | 83 // |create_message| to be sent to the plugin. |
84 scoped_refptr<HostResourceVar> CreateResourceVar( | 84 scoped_refptr<HostResourceVar> CreateResourceVar( |
85 int pending_renderer_id, | 85 int pending_renderer_id, |
86 const IPC::Message& create_message); | 86 const IPC::Message& create_message); |
87 // Creates a resource var with the given |pending_renderer_id| and | 87 // Creates a resource var with the given |pending_renderer_id| and |
88 // |create_message| to be sent to the plugin. Also sends | 88 // |create_message| to be sent to the plugin. Also sends |
89 // |browser_host_create_message| to the browser, and asynchronously stores the | 89 // |browser_host_create_message| to the browser, and asynchronously stores the |
(...skipping 11 matching lines...) Expand all Loading... |
101 // conveniently passed to |CreateBrowserResourceHosts|. | 101 // conveniently passed to |CreateBrowserResourceHosts|. |
102 std::vector<IPC::Message> browser_host_create_messages_; | 102 std::vector<IPC::Message> browser_host_create_messages_; |
103 // A list of the resource vars associated with browser hosts. | 103 // A list of the resource vars associated with browser hosts. |
104 std::vector<scoped_refptr<HostResourceVar> > browser_vars_; | 104 std::vector<scoped_refptr<HostResourceVar> > browser_vars_; |
105 | 105 |
106 DISALLOW_COPY_AND_ASSIGN(ResourceConverterImpl); | 106 DISALLOW_COPY_AND_ASSIGN(ResourceConverterImpl); |
107 }; | 107 }; |
108 | 108 |
109 } // namespace content | 109 } // namespace content |
110 #endif // CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H_ | 110 #endif // CONTENT_RENDERER_PEPPER_RESOURCE_CONVERTER_H_ |
OLD | NEW |