15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// found in the LICENSE file. 45f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// TODO: Need to deal with NPAPI's NPSavedData. 65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// I haven't seen plugins use it yet. 75f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#ifndef CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#define CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ 105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <map> 125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <stack> 135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <string> 145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <vector> 155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/basictypes.h" 175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/files/file_path.h" 185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/memory/ref_counted.h" 195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "third_party/npapi/bindings/npapi.h" 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "third_party/npapi/bindings/nphostapi.h" 215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/gfx/native_widget_types.h" 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/gfx/point.h" 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/gfx/rect.h" 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "url/gurl.h" 255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace base { 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class MessageLoop; 285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace content { 315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class PluginLib; 335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class PluginHost; 345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class PluginStream; 355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class PluginStreamUrl; 365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class WebPlugin; 375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class WebPluginResourceClient; 385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_MACOSX) 405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class ScopedCurrentPluginEvent; 415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// A PluginInstance is an active, running instance of a Plugin. 445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// A single plugin may have many PluginInstances. 455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { 465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) public: 475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Create a new instance of a plugin. The PluginInstance 485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // will hold a reference to the plugin. 495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PluginInstance(PluginLib* plugin, const std::string &mime_type); 505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Activates the instance by calling NPP_New. 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // This should be called after our instance is all 535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // setup from the host side and we are ready to receive 545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // requests from the plugin. We must not call any 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // functions on the plugin instance until start has 565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // been called. 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // 585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // url: The instance URL. 595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // param_names: the list of names of attributes passed via the 605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // element. 615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // param_values: the list of values corresponding to param_names 625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // param_count: number of attributes 635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // load_manually: if true indicates that the plugin data would be passed 645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // from webkit. if false indicates that the plugin should 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // download the data. 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // This also controls whether the plugin is instantiated as 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // a full page plugin (NP_FULL) or embedded (NP_EMBED) 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // 695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool Start(const GURL& url, 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) char** const param_names, 715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) char** const param_values, 725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int param_count, 735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool load_manually); 745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // NPAPI's instance identifier for this instance 765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPP npp() { return npp_; } 775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Get/Set for the instance's window handle. 795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gfx::PluginWindowHandle window_handle() const { return window_handle_; } 805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_window_handle(gfx::PluginWindowHandle value) { 815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) window_handle_ = value; 825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Get/Set whether this instance is in Windowless mode. 855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Default is false. 865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool windowless() { return windowless_; } 875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_windowless(bool value) { windowless_ = value; } 885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Get/Set whether this instance is transparent. This only applies to 905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // windowless plugins. Transparent plugins require that webkit paint the 915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // background. 925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Default is true for all plugins other than Flash. For Flash, we default to 935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // opaque since it always tells us if it's transparent during NPP_New. 945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool transparent() { return transparent_; } 955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_transparent(bool value) { transparent_ = value; } 965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Get/Set the WebPlugin associated with this instance 985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) WebPlugin* webplugin() { return webplugin_; } 995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_web_plugin(WebPlugin* webplugin) { 1005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) webplugin_ = webplugin; 1015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Get the mimeType for this plugin stream 1045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const std::string &mime_type() { return mime_type_; } 1055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PluginLib* plugin_lib() { return plugin_.get(); } 1075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_MACOSX) 1095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Get/Set the Mac NPAPI drawing and event models 1105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPDrawingModel drawing_model() { return drawing_model_; } 1115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_drawing_model(NPDrawingModel value) { drawing_model_ = value; } 1125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPEventModel event_model() { return event_model_; } 1135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_event_model(NPEventModel value) { event_model_ = value; } 1145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Updates the instance's tracking of the location of the plugin location 1155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // relative to the upper left of the screen. 1165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_plugin_origin(const gfx::Point& origin) { plugin_origin_ = origin; } 1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Updates the instance's tracking of the frame of the containing window 1185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // relative to the upper left of the screen. 1195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_window_frame(const gfx::Rect& frame) { 1205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) containing_window_frame_ = frame; 1215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 1235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Creates a stream for sending an URL. If notify_id is non-zero, it will 1255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // send a notification to the plugin when the stream is complete; otherwise it 1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // will not. Set object_url to true if the load is for the object tag's url, 1275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // or false if it's for a url that the plugin fetched through 1285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // NPN_GetUrl[Notify]. 1295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PluginStreamUrl* CreateStream(unsigned long resource_id, 1305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const GURL& url, 1315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const std::string& mime_type, 1325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int notify_id); 1335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // For each instance, we track all streams. When the 1355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // instance closes, all remaining streams are also 1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // closed. All streams associated with this instance 1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // should call AddStream so that they can be cleaned 1385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // up when the instance shuts down. 1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void AddStream(PluginStream* stream); 1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // This is called when a stream is closed. We remove the stream from the 1425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // list, which releases the reference maintained to the stream. 1435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void RemoveStream(PluginStream* stream); 1445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Closes all open streams on this instance. 1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void CloseStreams(); 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Returns the WebPluginResourceClient object for a stream that has become 1495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // seekable. 1505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) WebPluginResourceClient* GetRangeRequest(int id); 1515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Have the plugin create its script object. 1535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPObject* GetPluginScriptableObject(); 1545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Returns the form value of this instance. 1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool GetFormValue(base::string16* value); 1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // WebViewDelegate methods that we implement. This is for handling 1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // callbacks during getURLNotify. 1605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void DidFinishLoadWithReason(const GURL& url, NPReason reason, int notify_id); 1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // If true, send the Mozilla user agent instead of Chrome's to the plugin. 1635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool use_mozilla_user_agent() { return use_mozilla_user_agent_; } 1645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_use_mozilla_user_agent() { use_mozilla_user_agent_ = true; } 1655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // If the plugin instance is backed by a texture, return its ID in the 1675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // compositor's namespace. Otherwise return 0. Returns 0 by default. 1685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) unsigned GetBackingTextureId(); 1695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Helper that implements NPN_PluginThreadAsyncCall semantics 1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void PluginThreadAsyncCall(void (*func)(void *), 1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void* userData); 1735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) uint32 ScheduleTimer(uint32 interval, 1755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPBool repeat, 1765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void (*func)(NPP id, uint32 timer_id)); 1775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void UnscheduleTimer(uint32 timer_id); 1795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool ConvertPoint(double source_x, double source_y, 1815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPCoordinateSpace source_space, 1825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) double* dest_x, double* dest_y, 1835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPCoordinateSpace dest_space); 1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPError PopUpContextMenu(NPMenu* menu); 1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // 1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // NPAPI methods for calling the Plugin Instance 1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // 1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPError NPP_New(unsigned short, short, char *[], char *[]); 1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPError NPP_SetWindow(NPWindow*); 1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPError NPP_NewStream(NPMIMEType, NPStream*, NPBool, unsigned short*); 1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPError NPP_DestroyStream(NPStream*, NPReason); 1945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int NPP_WriteReady(NPStream*); 1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int NPP_Write(NPStream*, int, int, void*); 1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void NPP_StreamAsFile(NPStream*, const char*); 1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void NPP_URLNotify(const char*, NPReason, void*); 1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPError NPP_GetValue(NPPVariable, void*); 1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPError NPP_SetValue(NPNVariable, void*); 2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) short NPP_HandleEvent(void*); 2015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void NPP_Destroy(); 2025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool NPP_Print(NPPrint* platform_print); 2035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void NPP_URLRedirectNotify(const char* url, int32_t status, 2045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void* notify_data); 2055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void SendJavaScriptStream(const GURL& url, 2075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const std::string& result, 2085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool success, 2095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int notify_id); 2105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void DidReceiveManualResponse(const GURL& url, 2125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const std::string& mime_type, 2135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const std::string& headers, 2145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) uint32 expected_length, 2155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) uint32 last_modified); 2165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void DidReceiveManualData(const char* buffer, int length); 2175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void DidFinishManualLoading(); 2185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void DidManualLoadFail(); 2195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void PushPopupsEnabledState(bool enabled); 2215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void PopPopupsEnabledState(); 2225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool popups_allowed() const { 2245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return popups_enabled_stack_.empty() ? false : popups_enabled_stack_.top(); 2255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 2265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Initiates byte range reads for plugins. 2285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void RequestRead(NPStream* stream, NPByteRange* range_list); 2295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Handles GetURL/GetURLNotify/PostURL/PostURLNotify requests initiated 2315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // by plugins. 2325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void RequestURL(const char* url, 2335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const char* method, 2345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const char* target, 2355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const char* buf, 2365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) unsigned int len, 2375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool notify, 2385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void* notify_data); 2395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Handles NPN_URLRedirectResponse calls issued by plugins in response to 2415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // HTTP URL redirect notifications. 2425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void URLRedirectResponse(bool allow, void* notify_data); 2435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool handles_url_redirects() const { return handles_url_redirects_; } 2455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) private: 2475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) friend class base::RefCountedThreadSafe<PluginInstance>; 2485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_MACOSX) 2505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) friend class ScopedCurrentPluginEvent; 2515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Sets the event that the plugin is currently handling. The object is not 2525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // owned or copied, so the caller must call this again with NULL before the 2535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // event pointer becomes invalid. Clients use ScopedCurrentPluginEvent rather 2545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // than calling this directly. 2555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void set_currently_handled_event(NPCocoaEvent* event) { 2565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) currently_handled_event_ = event; 2575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 2585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 2595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ~PluginInstance(); 2615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void OnPluginThreadAsyncCall(void (*func)(void *), void* userData); 2625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void OnTimerCall(void (*func)(NPP id, uint32 timer_id), 2635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NPP id, uint32 timer_id); 2645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool IsValidStream(const NPStream* stream); 2655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void GetNotifyData(int notify_id, bool* notify, void** notify_data); 2665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // This is a hack to get the real player plugin to work with chrome 2685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // The real player plugin dll(nppl3260) when loaded by firefox is loaded via 2695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the NS COM API which is analogous to win32 COM. So the NPAPI functions in 2705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the plugin are invoked via an interface by firefox. The plugin instance 2715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // handle which is passed to every NPAPI method is owned by the real player 2725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // plugin, i.e. it expects the ndata member to point to a structure which 2735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // it knows about. Eventually it dereferences this structure and compares 2745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // a member variable at offset 0x24(Version 6.0.11.2888) /2D (Version 2755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // 6.0.11.3088) with 0 and on failing this check, takes a different code 2765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // path which causes a crash. Safari and Opera work with version 6.0.11.2888 2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // by chance as their ndata structure contains a 0 at the location which real 2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // 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 280 // which is passed in the ndata member. This magic number works correctly on 281 // Vista with UAC on or off :(. 282 // NOTE: Please dont change the ordering of the member variables 283 // New members should be added after this padding array. 284 // TODO(iyengar) : Disassemble the Realplayer ndata structure and look into 285 // 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. 287 uint8 zero_padding_[96]; 288 scoped_refptr<PluginLib> plugin_; 289 NPP npp_; 290 scoped_refptr<PluginHost> host_; 291 NPPluginFuncs* npp_functions_; 292 std::vector<scoped_refptr<PluginStream> > open_streams_; 293 gfx::PluginWindowHandle window_handle_; 294 bool windowless_; 295 bool transparent_; 296 WebPlugin* webplugin_; 297 std::string mime_type_; 298 GURL get_url_; 299 intptr_t get_notify_data_; 300 bool use_mozilla_user_agent_; 301#if defined(OS_MACOSX) 302 NPDrawingModel drawing_model_; 303 NPEventModel event_model_; 304 gfx::Point plugin_origin_; 305 gfx::Rect containing_window_frame_; 306 NPCocoaEvent* currently_handled_event_; // weak 307#endif 308 base::MessageLoop* message_loop_; 309 scoped_refptr<PluginStreamUrl> plugin_data_stream_; 310 311 // 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. 313 bool load_manually_; 314 315 // Stack indicating if popups are to be enabled for the outgoing 316 // NPN_GetURL/NPN_GetURLNotify calls. 317 std::stack<bool> popups_enabled_stack_; 318 319 // True if in CloseStreams(). 320 bool in_close_streams_; 321 322 // 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. 324 std::vector<base::FilePath> files_created_; 325 326 // Next unusued timer id. 327 uint32 next_timer_id_; 328 329 // Map of timer id to settings for timer. 330 struct TimerInfo { 331 uint32 interval; 332 bool repeat; 333 }; 334 typedef std::map<uint32, TimerInfo> TimerMap; 335 TimerMap timers_; 336 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); 353}; 354 355#if defined(OS_MACOSX) 356// Helper to simplify correct usage of set_currently_handled_event. 357// Instantiating will set |instance|'s currently handled to |event| for the 358// lifetime of the object, then NULL when it goes out of scope. 359class ScopedCurrentPluginEvent { 360 public: 361 ScopedCurrentPluginEvent(PluginInstance* instance, NPCocoaEvent* event); 362 ~ScopedCurrentPluginEvent(); 363 364 private: 365 scoped_refptr<PluginInstance> instance_; 366 DISALLOW_COPY_AND_ASSIGN(ScopedCurrentPluginEvent); 367}; 368#endif 369 370} // namespace content 371 372#endif // CONTENT_CHILD_NPAPI_PLUGIN_INSTANCE_H_ 373