OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO: Need to deal with NPAPI's NPSavedData. | 5 // TODO: Need to deal with NPAPI's NPSavedData. |
6 // I haven't seen plugins use it yet. | 6 // I haven't seen plugins use it yet. |
7 | 7 |
8 #ifndef CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ | 8 #ifndef CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ |
9 #define CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ | 9 #define CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
28 } | 28 } |
29 | 29 |
30 namespace content { | 30 namespace content { |
31 | 31 |
32 class PluginLib; | 32 class PluginLib; |
33 class PluginHost; | 33 class PluginHost; |
34 class PluginStream; | |
35 class PluginStreamUrl; | |
36 class WebPlugin; | 34 class WebPlugin; |
37 class WebPluginResourceClient; | 35 class WebPluginResourceClient; |
38 | 36 |
39 #if defined(OS_MACOSX) | 37 #if defined(OS_MACOSX) |
40 class ScopedCurrentPluginEvent; | 38 class ScopedCurrentPluginEvent; |
41 #endif | 39 #endif |
42 | 40 |
43 // A PluginInstance is an active, running instance of a Plugin. | 41 // A PluginInstance is an active, running instance of a Plugin. |
44 // A single plugin may have many PluginInstances. | 42 // A single plugin may have many PluginInstances. |
45 class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { | 43 class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // Updates the instance's tracking of the location of the plugin location | 112 // Updates the instance's tracking of the location of the plugin location |
115 // relative to the upper left of the screen. | 113 // relative to the upper left of the screen. |
116 void set_plugin_origin(const gfx::Point& origin) { plugin_origin_ = origin; } | 114 void set_plugin_origin(const gfx::Point& origin) { plugin_origin_ = origin; } |
117 // Updates the instance's tracking of the frame of the containing window | 115 // Updates the instance's tracking of the frame of the containing window |
118 // relative to the upper left of the screen. | 116 // relative to the upper left of the screen. |
119 void set_window_frame(const gfx::Rect& frame) { | 117 void set_window_frame(const gfx::Rect& frame) { |
120 containing_window_frame_ = frame; | 118 containing_window_frame_ = frame; |
121 } | 119 } |
122 #endif | 120 #endif |
123 | 121 |
124 // Creates a stream for sending an URL. If notify_id is non-zero, it will | |
125 // send a notification to the plugin when the stream is complete; otherwise it | |
126 // will not. Set object_url to true if the load is for the object tag's url, | |
127 // or false if it's for a url that the plugin fetched through | |
128 // NPN_GetUrl[Notify]. | |
129 PluginStreamUrl* CreateStream(unsigned long resource_id, | |
130 const GURL& url, | |
131 const std::string& mime_type, | |
132 int notify_id); | |
133 | |
134 // For each instance, we track all streams. When the | |
135 // instance closes, all remaining streams are also | |
136 // closed. All streams associated with this instance | |
137 // should call AddStream so that they can be cleaned | |
138 // up when the instance shuts down. | |
139 void AddStream(PluginStream* stream); | |
140 | |
141 // This is called when a stream is closed. We remove the stream from the | |
142 // list, which releases the reference maintained to the stream. | |
143 void RemoveStream(PluginStream* stream); | |
144 | |
145 // Closes all open streams on this instance. | |
146 void CloseStreams(); | |
147 | |
148 // Returns the WebPluginResourceClient object for a stream that has become | 122 // Returns the WebPluginResourceClient object for a stream that has become |
149 // seekable. | 123 // seekable. |
150 WebPluginResourceClient* GetRangeRequest(int id); | 124 WebPluginResourceClient* GetRangeRequest(int id); |
151 | 125 |
152 // Have the plugin create its script object. | 126 // Have the plugin create its script object. |
153 NPObject* GetPluginScriptableObject(); | 127 NPObject* GetPluginScriptableObject(); |
154 | 128 |
155 // Returns the form value of this instance. | 129 // Returns the form value of this instance. |
156 bool GetFormValue(base::string16* value); | 130 bool GetFormValue(base::string16* value); |
157 | 131 |
158 // WebViewDelegate methods that we implement. This is for handling | |
159 // callbacks during getURLNotify. | |
160 void DidFinishLoadWithReason(const GURL& url, NPReason reason, int notify_id); | |
161 | |
162 // If true, send the Mozilla user agent instead of Chrome's to the plugin. | 132 // If true, send the Mozilla user agent instead of Chrome's to the plugin. |
163 bool use_mozilla_user_agent() { return use_mozilla_user_agent_; } | 133 bool use_mozilla_user_agent() { return use_mozilla_user_agent_; } |
164 void set_use_mozilla_user_agent() { use_mozilla_user_agent_ = true; } | 134 void set_use_mozilla_user_agent() { use_mozilla_user_agent_ = true; } |
165 | 135 |
166 // If the plugin instance is backed by a texture, return its ID in the | 136 // If the plugin instance is backed by a texture, return its ID in the |
167 // compositor's namespace. Otherwise return 0. Returns 0 by default. | 137 // compositor's namespace. Otherwise return 0. Returns 0 by default. |
168 unsigned GetBackingTextureId(); | 138 unsigned GetBackingTextureId(); |
169 | 139 |
170 // Helper that implements NPN_PluginThreadAsyncCall semantics | 140 // Helper that implements NPN_PluginThreadAsyncCall semantics |
171 void PluginThreadAsyncCall(void (*func)(void *), | 141 void PluginThreadAsyncCall(void (*func)(void *), |
(...skipping 26 matching lines...) Expand all Loading... |
198 NPError NPP_GetValue(NPPVariable, void*); | 168 NPError NPP_GetValue(NPPVariable, void*); |
199 NPError NPP_SetValue(NPNVariable, void*); | 169 NPError NPP_SetValue(NPNVariable, void*); |
200 short NPP_HandleEvent(void*); | 170 short NPP_HandleEvent(void*); |
201 void NPP_Destroy(); | 171 void NPP_Destroy(); |
202 bool NPP_Print(NPPrint* platform_print); | 172 bool NPP_Print(NPPrint* platform_print); |
203 void NPP_URLRedirectNotify(const char* url, int32_t status, | 173 void NPP_URLRedirectNotify(const char* url, int32_t status, |
204 void* notify_data); | 174 void* notify_data); |
205 | 175 |
206 void SendJavaScriptStream(const GURL& url, | 176 void SendJavaScriptStream(const GURL& url, |
207 const std::string& result, | 177 const std::string& result, |
208 bool success, | 178 bool success); |
209 int notify_id); | |
210 | |
211 void DidReceiveManualResponse(const GURL& url, | |
212 const std::string& mime_type, | |
213 const std::string& headers, | |
214 uint32 expected_length, | |
215 uint32 last_modified); | |
216 void DidReceiveManualData(const char* buffer, int length); | |
217 void DidFinishManualLoading(); | |
218 void DidManualLoadFail(); | |
219 | 179 |
220 void PushPopupsEnabledState(bool enabled); | 180 void PushPopupsEnabledState(bool enabled); |
221 void PopPopupsEnabledState(); | 181 void PopPopupsEnabledState(); |
222 | 182 |
223 bool popups_allowed() const { | 183 bool popups_allowed() const { |
224 return popups_enabled_stack_.empty() ? false : popups_enabled_stack_.top(); | 184 return popups_enabled_stack_.empty() ? false : popups_enabled_stack_.top(); |
225 } | 185 } |
226 | 186 |
227 // Initiates byte range reads for plugins. | |
228 void RequestRead(NPStream* stream, NPByteRange* range_list); | |
229 | |
230 // Handles GetURL/GetURLNotify/PostURL/PostURLNotify requests initiated | |
231 // by plugins. | |
232 void RequestURL(const char* url, | |
233 const char* method, | |
234 const char* target, | |
235 const char* buf, | |
236 unsigned int len, | |
237 bool notify, | |
238 void* notify_data); | |
239 | |
240 // Handles NPN_URLRedirectResponse calls issued by plugins in response to | |
241 // HTTP URL redirect notifications. | |
242 void URLRedirectResponse(bool allow, void* notify_data); | |
243 | |
244 bool handles_url_redirects() const { return handles_url_redirects_; } | |
245 | |
246 private: | 187 private: |
247 friend class base::RefCountedThreadSafe<PluginInstance>; | 188 friend class base::RefCountedThreadSafe<PluginInstance>; |
248 | 189 |
249 #if defined(OS_MACOSX) | 190 #if defined(OS_MACOSX) |
250 friend class ScopedCurrentPluginEvent; | 191 friend class ScopedCurrentPluginEvent; |
251 // Sets the event that the plugin is currently handling. The object is not | 192 // Sets the event that the plugin is currently handling. The object is not |
252 // owned or copied, so the caller must call this again with NULL before the | 193 // owned or copied, so the caller must call this again with NULL before the |
253 // event pointer becomes invalid. Clients use ScopedCurrentPluginEvent rather | 194 // event pointer becomes invalid. Clients use ScopedCurrentPluginEvent rather |
254 // than calling this directly. | 195 // than calling this directly. |
255 void set_currently_handled_event(NPCocoaEvent* event) { | 196 void set_currently_handled_event(NPCocoaEvent* event) { |
256 currently_handled_event_ = event; | 197 currently_handled_event_ = event; |
257 } | 198 } |
258 #endif | 199 #endif |
259 | 200 |
260 ~PluginInstance(); | 201 ~PluginInstance(); |
261 void OnPluginThreadAsyncCall(void (*func)(void *), void* userData); | 202 void OnPluginThreadAsyncCall(void (*func)(void *), void* userData); |
262 void OnTimerCall(void (*func)(NPP id, uint32 timer_id), | 203 void OnTimerCall(void (*func)(NPP id, uint32 timer_id), |
263 NPP id, uint32 timer_id); | 204 NPP id, uint32 timer_id); |
264 bool IsValidStream(const NPStream* stream); | |
265 void GetNotifyData(int notify_id, bool* notify, void** notify_data); | |
266 | 205 |
267 // This is a hack to get the real player plugin to work with chrome | 206 // This is a hack to get the real player plugin to work with chrome |
268 // The real player plugin dll(nppl3260) when loaded by firefox is loaded via | 207 // The real player plugin dll(nppl3260) when loaded by firefox is loaded via |
269 // the NS COM API which is analogous to win32 COM. So the NPAPI functions in | 208 // the NS COM API which is analogous to win32 COM. So the NPAPI functions in |
270 // the plugin are invoked via an interface by firefox. The plugin instance | 209 // the plugin are invoked via an interface by firefox. The plugin instance |
271 // handle which is passed to every NPAPI method is owned by the real player | 210 // handle which is passed to every NPAPI method is owned by the real player |
272 // plugin, i.e. it expects the ndata member to point to a structure which | 211 // plugin, i.e. it expects the ndata member to point to a structure which |
273 // it knows about. Eventually it dereferences this structure and compares | 212 // it knows about. Eventually it dereferences this structure and compares |
274 // a member variable at offset 0x24(Version 6.0.11.2888) /2D (Version | 213 // a member variable at offset 0x24(Version 6.0.11.2888) /2D (Version |
275 // 6.0.11.3088) with 0 and on failing this check, takes a different code | 214 // 6.0.11.3088) with 0 and on failing this check, takes a different code |
276 // path which causes a crash. Safari and Opera work with version 6.0.11.2888 | 215 // path which causes a crash. Safari and Opera work with version 6.0.11.2888 |
277 // by chance as their ndata structure contains a 0 at the location which real | 216 // by chance as their ndata structure contains a 0 at the location which real |
278 // player checks:(. They crash with version 6.0.11.3088 as well. The | 217 // player checks:(. They crash with version 6.0.11.3088 as well. The |
279 // following member just adds a 96 byte padding to our PluginInstance class | 218 // following member just adds a 96 byte padding to our PluginInstance class |
280 // which is passed in the ndata member. This magic number works correctly on | 219 // which is passed in the ndata member. This magic number works correctly on |
281 // Vista with UAC on or off :(. | 220 // Vista with UAC on or off :(. |
282 // NOTE: Please dont change the ordering of the member variables | 221 // NOTE: Please dont change the ordering of the member variables |
283 // New members should be added after this padding array. | 222 // New members should be added after this padding array. |
284 // TODO(iyengar) : Disassemble the Realplayer ndata structure and look into | 223 // TODO(iyengar) : Disassemble the Realplayer ndata structure and look into |
285 // the possiblity of conforming to it (http://b/issue?id=936667). We | 224 // the possiblity of conforming to it (http://b/issue?id=936667). We |
286 // could also log a bug with Real, which would save the effort. | 225 // could also log a bug with Real, which would save the effort. |
287 uint8 zero_padding_[96]; | 226 uint8 zero_padding_[96]; |
288 scoped_refptr<PluginLib> plugin_; | 227 scoped_refptr<PluginLib> plugin_; |
289 NPP npp_; | 228 NPP npp_; |
290 scoped_refptr<PluginHost> host_; | 229 scoped_refptr<PluginHost> host_; |
291 NPPluginFuncs* npp_functions_; | 230 NPPluginFuncs* npp_functions_; |
292 std::vector<scoped_refptr<PluginStream> > open_streams_; | |
293 gfx::PluginWindowHandle window_handle_; | 231 gfx::PluginWindowHandle window_handle_; |
294 bool windowless_; | 232 bool windowless_; |
295 bool transparent_; | 233 bool transparent_; |
296 WebPlugin* webplugin_; | 234 WebPlugin* webplugin_; |
297 std::string mime_type_; | 235 std::string mime_type_; |
298 GURL get_url_; | |
299 intptr_t get_notify_data_; | |
300 bool use_mozilla_user_agent_; | 236 bool use_mozilla_user_agent_; |
301 #if defined(OS_MACOSX) | 237 #if defined(OS_MACOSX) |
302 NPDrawingModel drawing_model_; | 238 NPDrawingModel drawing_model_; |
303 NPEventModel event_model_; | 239 NPEventModel event_model_; |
304 gfx::Point plugin_origin_; | 240 gfx::Point plugin_origin_; |
305 gfx::Rect containing_window_frame_; | 241 gfx::Rect containing_window_frame_; |
306 NPCocoaEvent* currently_handled_event_; // weak | 242 NPCocoaEvent* currently_handled_event_; // weak |
307 #endif | 243 #endif |
308 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 244 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
309 scoped_refptr<PluginStreamUrl> plugin_data_stream_; | |
310 | 245 |
311 // This flag if true indicates that the plugin data would be passed from | 246 // This flag if true indicates that the plugin data would be passed from |
312 // webkit. if false indicates that the plugin should download the data. | 247 // webkit. if false indicates that the plugin should download the data. |
313 bool load_manually_; | 248 bool load_manually_; |
314 | 249 |
315 // Stack indicating if popups are to be enabled for the outgoing | 250 // Stack indicating if popups are to be enabled for the outgoing |
316 // NPN_GetURL/NPN_GetURLNotify calls. | 251 // NPN_GetURL/NPN_GetURLNotify calls. |
317 std::stack<bool> popups_enabled_stack_; | 252 std::stack<bool> popups_enabled_stack_; |
318 | 253 |
319 // True if in CloseStreams(). | |
320 bool in_close_streams_; | |
321 | |
322 // List of files created for the current plugin instance. File names are | 254 // List of files created for the current plugin instance. File names are |
323 // added to the list every time the NPP_StreamAsFile function is called. | 255 // added to the list every time the NPP_StreamAsFile function is called. |
324 std::vector<base::FilePath> files_created_; | 256 std::vector<base::FilePath> files_created_; |
325 | 257 |
326 // Next unusued timer id. | 258 // Next unusued timer id. |
327 uint32 next_timer_id_; | 259 uint32 next_timer_id_; |
328 | 260 |
329 // Map of timer id to settings for timer. | 261 // Map of timer id to settings for timer. |
330 struct TimerInfo { | 262 struct TimerInfo { |
331 uint32 interval; | 263 uint32 interval; |
332 bool repeat; | 264 bool repeat; |
333 }; | 265 }; |
334 typedef std::map<uint32, TimerInfo> TimerMap; | 266 typedef std::map<uint32, TimerInfo> TimerMap; |
335 TimerMap timers_; | 267 TimerMap timers_; |
336 | 268 |
337 // Tracks pending GET/POST requests so that the plugin-given data doesn't | |
338 // cross process boundaries to an untrusted process. | |
339 typedef std::map<int, void*> PendingRequestMap; | |
340 PendingRequestMap pending_requests_; | |
341 int next_notify_id_; | |
342 | |
343 // Used to track pending range requests so that when WebPlugin replies to us | |
344 // we can match the reply to the stream. | |
345 typedef std::map<int, scoped_refptr<PluginStream> > PendingRangeRequestMap; | |
346 PendingRangeRequestMap pending_range_requests_; | |
347 int next_range_request_id_; | |
348 // The plugin handles the NPAPI URL redirect notification API. | |
349 // See here https://wiki.mozilla.org/NPAPI:HTTPRedirectHandling | |
350 bool handles_url_redirects_; | |
351 | |
352 DISALLOW_COPY_AND_ASSIGN(PluginInstance); | 269 DISALLOW_COPY_AND_ASSIGN(PluginInstance); |
353 }; | 270 }; |
354 | 271 |
355 #if defined(OS_MACOSX) | 272 #if defined(OS_MACOSX) |
356 // Helper to simplify correct usage of set_currently_handled_event. | 273 // Helper to simplify correct usage of set_currently_handled_event. |
357 // Instantiating will set |instance|'s currently handled to |event| for the | 274 // Instantiating will set |instance|'s currently handled to |event| for the |
358 // lifetime of the object, then NULL when it goes out of scope. | 275 // lifetime of the object, then NULL when it goes out of scope. |
359 class ScopedCurrentPluginEvent { | 276 class ScopedCurrentPluginEvent { |
360 public: | 277 public: |
361 ScopedCurrentPluginEvent(PluginInstance* instance, NPCocoaEvent* event); | 278 ScopedCurrentPluginEvent(PluginInstance* instance, NPCocoaEvent* event); |
362 ~ScopedCurrentPluginEvent(); | 279 ~ScopedCurrentPluginEvent(); |
363 | 280 |
364 private: | 281 private: |
365 scoped_refptr<PluginInstance> instance_; | 282 scoped_refptr<PluginInstance> instance_; |
366 DISALLOW_COPY_AND_ASSIGN(ScopedCurrentPluginEvent); | 283 DISALLOW_COPY_AND_ASSIGN(ScopedCurrentPluginEvent); |
367 }; | 284 }; |
368 #endif | 285 #endif |
369 | 286 |
370 } // namespace content | 287 } // namespace content |
371 | 288 |
372 #endif // CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ | 289 #endif // CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ |
OLD | NEW |