15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#ifndef CONTENT_RENDERER_PEPPER_PLUGIN_MODULE_H_ 6bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#define CONTENT_RENDERER_PEPPER_PLUGIN_MODULE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/native_library.h" 1858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch#include "base/process/process.h" 19bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "content/common/content_export.h" 20bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "content/public/common/pepper_plugin_info.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_bool.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_instance.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/ppb_core.h" 24a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "ppapi/c/private/ppb_instance_private.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/shared_impl/ppapi_permissions.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef void* NPIdentifier; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass GURL; 30d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base { 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath; 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ppapi { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CallbackTracker; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebKitForwarding; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ppapi 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 403240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdochnamespace IPC { 413240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdochstruct ChannelHandle; 423240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch} 433240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace blink { 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WebPluginContainer; 46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} // namespace blink 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdochnamespace content { 49558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochclass HostDispatcherWrapper; 5058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdochclass PepperPluginInstanceImpl; 51558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochclass PepperBroker; 52558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochclass RendererPpapiHostImpl; 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class RenderFrameImpl; 543240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdochstruct WebPluginInfo; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Represents one plugin library loaded into one renderer. This library may 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// have multiple instances. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 5958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch// Note: to get from a PP_Instance to a PepperPluginInstance*, use the 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ResourceTracker. 61a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass CONTENT_EXPORT PluginModule : public base::RefCounted<PluginModule>, 62a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch public base::SupportsWeakPtr<PluginModule> { 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 6458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch typedef std::set<PepperPluginInstanceImpl*> PluginInstanceSet; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // You must call one of the Init functions after the constructor to create a 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // module of the type you desire. 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The module lifetime delegate is a non-owning pointer that must outlive 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // all plugin modules. In practice it will be a global singleton that 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // tracks which modules are alive. 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PluginModule(const std::string& name, 7303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const std::string& version, 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& path, 75ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const ppapi::PpapiPermissions& perms); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the given class as being associated with this module. It will be 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // deleted when the module is destroyed. You can only set it once, subsequent 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // sets will assert. 80558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch void SetRendererPpapiHost(scoped_ptr<RendererPpapiHostImpl> host); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes this module as an internal plugin with the given entrypoints. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is used for "plugins" compiled into Chrome. Returns true on success. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // False means that the plugin can not be used. 8558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch bool InitAsInternalPlugin(const PepperPluginInfo::EntryPoints& entry_points); 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes this module using the given library path as the plugin. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true on success. False means that the plugin can not be used. 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool InitAsLibrary(const base::FilePath& path); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes this module for the given out of process proxy. This takes 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ownership of the given pointer, even in the failure case. 93558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch void InitAsProxied(HostDispatcherWrapper* host_dispatcher_wrapper); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // Creates a new module for an external plugin instance that will be using the 96a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // IPC proxy. We can't use the existing module, or new instances of the plugin 97a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // can't be created. 98a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch scoped_refptr<PluginModule> CreateModuleForExternalPluginInstance(); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 100a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // Initializes the external plugin module for the out of process proxy. 101a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // InitAsProxied must be called before calling InitAsProxiedExternalPlugin. 102a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // Returns a result code indicating whether the proxy started successfully or 103a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // there was an error. 104bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PP_ExternalPluginResult InitAsProxiedExternalPlugin( 10558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch PepperPluginInstanceImpl* instance); 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool IsProxied() const; 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the peer process ID if the plugin is running out of process; 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // returns |base::kNullProcessId| otherwise. 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::ProcessId GetPeerProcessId(); 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns the plugin child process ID if the plugin is running out of 114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // process. Returns 0 otherwise. This is the ID that the browser process uses 115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // to idetify the child process for the plugin. This isn't directly useful 116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // from our process (the renderer) except in messages to the browser to 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // disambiguate plugins. 118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int GetPluginChildId(); 119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const PPB_Core* GetCore(); 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns whether an interface is supported. This method can be called from 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the browser process and used for interface matching before plugin 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // registration. 12558e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // NOTE: those custom interfaces provided by ContentRendererClient will not be 12658e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch // considered when called on the browser process. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SupportsInterface(const char* name); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 129558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch RendererPpapiHostImpl* renderer_ppapi_host() { 130558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return renderer_ppapi_host_.get(); 131558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch } 132558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the module handle. This may be used before Init() is called (the 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // proxy needs this information to set itself up properly). 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Module pp_module() const { return pp_module_; } 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& name() const { return name_; } 13803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const std::string& version() const { return version_; } 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& path() const { return path_; } 140ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const ppapi::PpapiPermissions& permissions() const { return permissions_; } 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 142a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch PepperPluginInstanceImpl* CreateInstance(RenderFrameImpl* render_frame, 143a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch blink::WebPluginContainer* container, 144a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const GURL& plugin_url); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns "some" plugin instance associated with this module. This is not 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // guaranteed to be any one in particular. This is normally used to execute 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // callbacks up to the browser layer that are not inherently per-instance, 149fb250657ef40d7500f20882d5c9909c1013367d3Ben Murdoch // but the helper lives only on the plugin instance so we need one of them. 15058e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch PepperPluginInstanceImpl* GetSomeInstance() const; 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const PluginInstanceSet& GetAllInstances() const { return instances_; } 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Calls the plugin's GetInterface and returns the given interface pointer, 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which could be NULL. 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void* GetPluginInterface(const char* name) const; 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This module is associated with a set of instances. The PluginInstance 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // object declares its association with this module in its destructor and 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // releases us in its destructor. 16158e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch void InstanceCreated(PepperPluginInstanceImpl* instance); 16258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch void InstanceDeleted(PepperPluginInstanceImpl* instance); 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 164ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch scoped_refptr<ppapi::CallbackTracker> GetCallbackTracker(); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when running out of process and the plugin crashed. This will 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // release relevant resources and update all affected instances. 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void PluginCrashed(); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_in_destructor() const { return is_in_destructor_; } 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_crashed() const { return is_crashed_; } 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reserves the given instance is unique within the plugin, checking for 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // collisions. See PPB_Proxy_Private for more information. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The setter will set the callback which is set up when the proxy 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // initializes. The Reserve function will call the previously set callback if 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it exists to validate the ID. If the callback has not been set (such as 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for in-process plugins), the Reserve function will assume that the ID is 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // usable and will return true. 181a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch void SetReserveInstanceIDCallback(PP_Bool (*reserve)(PP_Module, PP_Instance)); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ReserveInstanceID(PP_Instance instance); 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These should only be called from the main thread. 185558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch void SetBroker(PepperBroker* broker); 186558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch PepperBroker* GetBroker(); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1883240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // Create a new HostDispatcher for proxying, hook it to the PluginModule, 1893240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // and perform other common initialization. 1903240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch RendererPpapiHostImpl* CreateOutOfProcessModule( 191a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RenderFrameImpl* render_frame, 1923240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch const base::FilePath& path, 1933240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch ppapi::PpapiPermissions permissions, 1943240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch const IPC::ChannelHandle& channel_handle, 1953240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch base::ProcessId plugin_pid, 1963240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch int plugin_child_id, 1973240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch bool is_external); 1983240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 19990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // In production we purposely leak the HostGlobals object but in unittest 20090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // code, this can interfere with subsequent tests. This deletes the 20190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // existing HostGlobals. A new one will be constructed when a PluginModule is 20290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // instantiated. 20390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void ResetHostGlobalsForTest(); 20490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2053240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // Attempts to create a PPAPI plugin for the given filepath. On success, it 2063240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // will return the newly-created module. 2073240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // 2083240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // There are two reasons for failure. The first is that the plugin isn't 2093240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // a PPAPI plugin. In this case, |*pepper_plugin_was_registered| will be set 2103240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // to false and the caller may want to fall back on creating an NPAPI plugin. 2113240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // the second is that the plugin failed to initialize. In this case, 2123240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // |*pepper_plugin_was_registered| will be set to true and the caller should 2133240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // not fall back on any other plugin types. 214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static scoped_refptr<PluginModule> Create(RenderFrameImpl* render_frame, 2153240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch const WebPluginInfo& webplugin_info, 2163240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch bool* pepper_plugin_was_registered); 2173240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 219bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch friend class base::RefCounted<PluginModule>; 220bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ~PluginModule(); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Calls the InitializeModule entrypoint. The entrypoint must have been 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // set and the plugin must not be out of process (we don't maintain 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // entrypoints in that case). 22458e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch bool InitializeModule(const PepperPluginInfo::EntryPoints& entry_points); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 226558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch scoped_ptr<RendererPpapiHostImpl> renderer_ppapi_host_; 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tracker for completion callbacks, used mainly to ensure that all callbacks 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // are properly aborted on module shutdown. 230ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch scoped_refptr<ppapi::CallbackTracker> callback_tracker_; 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Module pp_module_; 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True when we're running in the destructor. This allows us to write some 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // assertions. 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_in_destructor_; 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the plugin is running out-of-process and has crashed. 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_crashed_; 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Manages the out of process proxy interface. The presence of this 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // pointer indicates that the plugin is running out of process and that the 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // entry_points_ aren't valid. 244558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch scoped_ptr<HostDispatcherWrapper> host_dispatcher_wrapper_; 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Non-owning pointer to the broker for this plugin module, if one exists. 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // It is populated and cleared in the main thread. 248558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch PepperBroker* broker_; 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Holds a reference to the base::NativeLibrary handle if this PluginModule 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // instance wraps functions loaded from a library. Can be NULL. If 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |library_| is non-NULL, PluginModule will attempt to unload the library 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // during destruction. 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::NativeLibrary library_; 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Contains pointers to the entry points of the actual plugin implementation. 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These will be NULL for out-of-process plugins, which is indicated by the 258558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // presence of the host_dispatcher_wrapper_ value. 25958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch PepperPluginInfo::EntryPoints entry_points_; 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 26103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // The name, version, and file location of the module. 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string name_; 26303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const std::string version_; 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath path_; 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 266ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch ppapi::PpapiPermissions permissions_; 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Non-owning pointers to all instances associated with this module. When 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // there are no more instances, this object should be deleted. 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PluginInstanceSet instances_; 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Bool (*reserve_instance_id_)(PP_Module, PP_Instance); 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PluginModule); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 27758e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch} // namespace content 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 279bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#endif // CONTENT_RENDERER_PEPPER_PLUGIN_MODULE_H_ 280