LCOV - code coverage report
Current view: directory - dom/plugins/base - nsPluginHost.h (source / functions) Found Hit Coverage
Test: app.info Lines: 15 1 6.7 %
Date: 2012-06-02 Functions: 5 2 40.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *  Josh Aas <josh@mozilla.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsPluginHost_h_
      40                 : #define nsPluginHost_h_
      41                 : 
      42                 : #include "nsIPluginHost.h"
      43                 : #include "nsIObserver.h"
      44                 : #include "nsCOMPtr.h"
      45                 : #include "prlink.h"
      46                 : #include "prclist.h"
      47                 : #include "npapi.h"
      48                 : #include "nsNPAPIPluginInstance.h"
      49                 : #include "nsIPluginTag.h"
      50                 : #include "nsPluginsDir.h"
      51                 : #include "nsPluginDirServiceProvider.h"
      52                 : #include "nsAutoPtr.h"
      53                 : #include "nsWeakPtr.h"
      54                 : #include "nsIPrompt.h"
      55                 : #include "nsISupportsArray.h"
      56                 : #include "nsIPrefBranch.h"
      57                 : #include "nsWeakReference.h"
      58                 : #include "nsThreadUtils.h"
      59                 : #include "nsTArray.h"
      60                 : #include "nsTObserverArray.h"
      61                 : #include "nsITimer.h"
      62                 : #include "nsPluginTags.h"
      63                 : #include "nsIEffectiveTLDService.h"
      64                 : #include "nsIIDNService.h"
      65                 : #include "nsCRT.h"
      66                 : 
      67                 : class nsNPAPIPlugin;
      68                 : class nsIComponentManager;
      69                 : class nsIFile;
      70                 : class nsIChannel;
      71                 : class nsPluginNativeWindow;
      72                 : class nsObjectLoadingContent;
      73                 : class nsPluginInstanceOwner;
      74                 : 
      75                 : #if defined(XP_MACOSX) && !defined(NP_NO_CARBON)
      76                 : #define MAC_CARBON_PLUGINS
      77                 : #endif
      78                 : 
      79                 : class nsInvalidPluginTag : public nsISupports
      80                 : {
      81                 : public:
      82                 :   nsInvalidPluginTag(const char* aFullPath, PRInt64 aLastModifiedTime = 0);
      83                 :   virtual ~nsInvalidPluginTag();
      84                 :   
      85                 :   NS_DECL_ISUPPORTS
      86                 :   
      87                 :   nsCString   mFullPath;
      88                 :   PRInt64     mLastModifiedTime;
      89                 :   bool        mSeen;
      90                 :   
      91                 :   nsRefPtr<nsInvalidPluginTag> mPrev;
      92                 :   nsRefPtr<nsInvalidPluginTag> mNext;
      93                 : };
      94                 : 
      95                 : class nsPluginHost : public nsIPluginHost,
      96                 :                      public nsIObserver,
      97                 :                      public nsITimerCallback,
      98                 :                      public nsSupportsWeakReference
      99                 : {
     100                 : public:
     101                 :   nsPluginHost();
     102                 :   virtual ~nsPluginHost();
     103                 : 
     104                 :   static nsPluginHost* GetInst();
     105                 : 
     106             692 :   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
     107                 : 
     108                 :   NS_DECL_ISUPPORTS
     109                 :   NS_DECL_NSIPLUGINHOST
     110                 :   NS_DECL_NSIOBSERVER
     111                 :   NS_DECL_NSITIMERCALLBACK
     112                 : 
     113                 :   nsresult Init();
     114                 :   nsresult Destroy();
     115                 :   nsresult LoadPlugins();
     116                 :   nsresult CreateListenerForChannel(nsIChannel* aChannel,
     117                 :                                     nsObjectLoadingContent* aContent,
     118                 :                                     nsIStreamListener** aListener);
     119                 :   nsresult SetUpPluginInstance(const char *aMimeType,
     120                 :                                nsIURI *aURL,
     121                 :                                nsIPluginInstanceOwner *aOwner);
     122                 :   nsresult IsPluginEnabledForType(const char* aMimeType);
     123                 :   nsresult IsPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
     124                 : 
     125                 :   nsresult GetPluginCount(PRUint32* aPluginCount);
     126                 :   nsresult GetPlugins(PRUint32 aPluginCount, nsIDOMPlugin** aPluginArray);
     127                 : 
     128                 :   nsresult GetURL(nsISupports* pluginInst,
     129                 :                   const char* url,
     130                 :                   const char* target,
     131                 :                   nsIPluginStreamListener* streamListener,
     132                 :                   const char* altHost,
     133                 :                   const char* referrer,
     134                 :                   bool forceJSEnabled);
     135                 :   nsresult PostURL(nsISupports* pluginInst,
     136                 :                    const char* url,
     137                 :                    PRUint32 postDataLen,
     138                 :                    const char* postData,
     139                 :                    bool isFile,
     140                 :                    const char* target,
     141                 :                    nsIPluginStreamListener* streamListener,
     142                 :                    const char* altHost,
     143                 :                    const char* referrer,
     144                 :                    bool forceJSEnabled,
     145                 :                    PRUint32 postHeadersLength,
     146                 :                    const char* postHeaders);
     147                 : 
     148                 :   nsresult FindProxyForURL(const char* url, char* *result);
     149                 :   nsresult UserAgent(const char **retstring);
     150                 :   nsresult ParsePostBufferToFixHeaders(const char *inPostData, PRUint32 inPostDataLen,
     151                 :                                        char **outPostData, PRUint32 *outPostDataLen);
     152                 :   nsresult CreateTempFileToPost(const char *aPostDataURL, nsIFile **aTmpFile);
     153                 :   nsresult NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow);
     154                 :   nsresult InstantiateDummyJavaPlugin(nsIPluginInstanceOwner *aOwner);
     155                 : 
     156                 :   void AddIdleTimeTarget(nsIPluginInstanceOwner* objectFrame, bool isVisible);
     157                 :   void RemoveIdleTimeTarget(nsIPluginInstanceOwner* objectFrame);
     158                 : 
     159                 :   nsresult GetPluginName(nsNPAPIPluginInstance *aPluginInstance, const char** aPluginName);
     160                 :   nsresult StopPluginInstance(nsNPAPIPluginInstance* aInstance);
     161                 :   nsresult HandleBadPlugin(PRLibrary* aLibrary, nsNPAPIPluginInstance *aInstance);
     162                 :   nsresult GetPluginTagForInstance(nsNPAPIPluginInstance *aPluginInstance, nsIPluginTag **aPluginTag);
     163                 : 
     164                 :   nsresult
     165                 :   NewPluginURLStream(const nsString& aURL, 
     166                 :                      nsNPAPIPluginInstance *aInstance, 
     167                 :                      nsIPluginStreamListener *aListener,
     168                 :                      nsIInputStream *aPostStream = nsnull,
     169                 :                      const char *aHeadersData = nsnull, 
     170                 :                      PRUint32 aHeadersDataLen = 0);
     171                 : 
     172                 :   nsresult
     173                 :   GetURLWithHeaders(nsNPAPIPluginInstance *pluginInst, 
     174                 :                     const char* url, 
     175                 :                     const char* target = NULL,
     176                 :                     nsIPluginStreamListener* streamListener = NULL,
     177                 :                     const char* altHost = NULL,
     178                 :                     const char* referrer = NULL,
     179                 :                     bool forceJSEnabled = false,
     180                 :                     PRUint32 getHeadersLength = 0, 
     181                 :                     const char* getHeaders = NULL);
     182                 : 
     183                 :   nsresult
     184                 :   DoURLLoadSecurityCheck(nsNPAPIPluginInstance *aInstance,
     185                 :                          const char* aURL);
     186                 : 
     187                 :   nsresult
     188                 :   AddHeadersToChannel(const char *aHeadersData, PRUint32 aHeadersDataLen, 
     189                 :                       nsIChannel *aGenericChannel);
     190                 : 
     191                 :   static nsresult GetPluginTempDir(nsIFile **aDir);
     192                 : 
     193                 :   // Writes updated plugins settings to disk and unloads the plugin
     194                 :   // if it is now disabled
     195                 :   nsresult UpdatePluginInfo(nsPluginTag* aPluginTag);
     196                 : 
     197                 :   // checks whether aTag is a "java" plugin tag (a tag for a plugin
     198                 :   // that does Java)
     199                 :   static bool IsJavaMIMEType(const char *aType);
     200                 : 
     201                 :   static nsresult GetPrompt(nsIPluginInstanceOwner *aOwner, nsIPrompt **aPrompt);
     202                 : 
     203                 :   static nsresult PostPluginUnloadEvent(PRLibrary* aLibrary);
     204                 : 
     205                 :   void PluginCrashed(nsNPAPIPlugin* plugin,
     206                 :                      const nsAString& pluginDumpID,
     207                 :                      const nsAString& browserDumpID);
     208                 : 
     209                 :   nsNPAPIPluginInstance *FindInstance(const char *mimetype);
     210                 :   nsNPAPIPluginInstance *FindOldestStoppedInstance();
     211                 :   PRUint32 StoppedInstanceCount();
     212                 : 
     213                 :   nsTArray< nsRefPtr<nsNPAPIPluginInstance> > *InstanceArray();
     214                 : 
     215                 :   void DestroyRunningInstances(nsISupportsArray* aReloadDocs, nsPluginTag* aPluginTag);
     216                 : 
     217                 :   // Return the tag for |aLibrary| if found, nsnull if not.
     218                 :   nsPluginTag* FindTagForLibrary(PRLibrary* aLibrary);
     219                 : 
     220                 :   // The last argument should be false if we already have an in-flight stream
     221                 :   // and don't need to set up a new stream.
     222                 :   nsresult InstantiateEmbeddedPlugin(const char *aMimeType, nsIURI* aURL,
     223                 :                                      nsObjectLoadingContent *aContent,
     224                 :                                      nsPluginInstanceOwner** aOwner);
     225                 : 
     226                 :   nsresult InstantiateFullPagePlugin(const char *aMimeType,
     227                 :                                      nsIURI* aURI,
     228                 :                                      nsObjectLoadingContent *aContent,
     229                 :                                      nsPluginInstanceOwner **aOwner,
     230                 :                                      nsIStreamListener **aStreamListener);
     231                 : 
     232                 :   // Does not accept NULL and should never fail.
     233                 :   nsPluginTag* TagForPlugin(nsNPAPIPlugin* aPlugin);
     234                 : 
     235                 :   nsresult GetPlugin(const char *aMimeType, nsNPAPIPlugin** aPlugin);
     236                 : 
     237                 : private:
     238                 :   nsresult
     239                 :   TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner);
     240                 : 
     241                 :   nsresult
     242                 :   NewEmbeddedPluginStreamListener(nsIURI* aURL, nsObjectLoadingContent *aContent,
     243                 :                                   nsNPAPIPluginInstance* aInstance,
     244                 :                                   nsIStreamListener** aListener);
     245                 : 
     246                 :   nsresult
     247                 :   NewEmbeddedPluginStream(nsIURI* aURL, nsObjectLoadingContent *aContent, nsNPAPIPluginInstance* aInstance);
     248                 : 
     249                 :   nsresult
     250                 :   NewFullPagePluginStream(nsIURI* aURI,
     251                 :                           nsNPAPIPluginInstance *aInstance,
     252                 :                           nsIStreamListener **aStreamListener);
     253                 : 
     254                 :   // Return an nsPluginTag for this type, if any.  If aCheckEnabled is
     255                 :   // true, only enabled plugins will be returned.
     256                 :   nsPluginTag*
     257                 :   FindPluginForType(const char* aMimeType, bool aCheckEnabled);
     258                 : 
     259                 :   nsPluginTag*
     260                 :   FindPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
     261                 : 
     262                 :   nsresult
     263                 :   FindStoppedPluginForURL(nsIURI* aURL, nsIPluginInstanceOwner *aOwner);
     264                 : 
     265                 :   nsresult
     266                 :   FindPlugins(bool aCreatePluginList, bool * aPluginsChanged);
     267                 : 
     268                 :   nsresult
     269                 :   ScanPluginsDirectory(nsIFile *pluginsDir,
     270                 :                        bool aCreatePluginList,
     271                 :                        bool *aPluginsChanged);
     272                 : 
     273                 :   nsresult
     274                 :   ScanPluginsDirectoryList(nsISimpleEnumerator *dirEnum,
     275                 :                            bool aCreatePluginList,
     276                 :                            bool *aPluginsChanged);
     277                 : 
     278                 :   nsresult EnsurePluginLoaded(nsPluginTag* plugin);
     279                 : 
     280                 :   bool IsRunningPlugin(nsPluginTag * plugin);
     281                 : 
     282                 :   // Stores all plugins info into the registry
     283                 :   nsresult WritePluginInfo();
     284                 : 
     285                 :   // Loads all cached plugins info into mCachedPlugins
     286                 :   nsresult ReadPluginInfo();
     287                 : 
     288                 :   // Given a file path, returns the plugins info from our cache
     289                 :   // and removes it from the cache.
     290                 :   void RemoveCachedPluginsInfo(const char *filePath,
     291                 :                                nsPluginTag **result);
     292                 : 
     293                 :   // Checks to see if a tag object is in our list of live tags.
     294                 :   bool IsLiveTag(nsIPluginTag* tag);
     295                 : 
     296                 :   // Checks our list of live tags for an equivalent tag.
     297                 :   nsPluginTag* HaveSamePlugin(nsPluginTag * aPluginTag);
     298                 : 
     299                 :   // checks if given plugin is a duplicate of what we already have
     300                 :   // in the plugin list but found in some different place
     301                 :   bool IsDuplicatePlugin(nsPluginTag * aPluginTag);
     302                 : 
     303                 :   nsresult EnsurePrivateDirServiceProvider();
     304                 : 
     305                 :   void OnPluginInstanceDestroyed(nsPluginTag* aPluginTag);
     306                 : 
     307                 :   nsRefPtr<nsPluginTag> mPlugins;
     308                 :   nsRefPtr<nsPluginTag> mCachedPlugins;
     309                 :   nsRefPtr<nsInvalidPluginTag> mInvalidPlugins;
     310                 :   bool mPluginsLoaded;
     311                 :   bool mDontShowBadPluginMessage;
     312                 :   bool mIsDestroyed;
     313                 : 
     314                 :   // set by pref plugin.override_internal_types
     315                 :   bool mOverrideInternalTypes;
     316                 : 
     317                 :   // set by pref plugin.disable
     318                 :   bool mPluginsDisabled;
     319                 : 
     320                 :   // Any instances in this array will have valid plugin objects via GetPlugin().
     321                 :   // When removing an instance it might not die - be sure to null out it's plugin.
     322                 :   nsTArray< nsRefPtr<nsNPAPIPluginInstance> > mInstances;
     323                 : 
     324                 :   nsCOMPtr<nsIFile> mPluginRegFile;
     325                 :   nsCOMPtr<nsIPrefBranch> mPrefService;
     326                 : #ifdef XP_WIN
     327                 :   nsRefPtr<nsPluginDirServiceProvider> mPrivateDirServiceProvider;
     328                 : #endif
     329                 : 
     330                 :   nsCOMPtr<nsIEffectiveTLDService> mTLDService;
     331                 :   nsCOMPtr<nsIIDNService> mIDNService;
     332                 : 
     333                 :   // Helpers for ClearSiteData and SiteHasData.
     334                 :   nsresult NormalizeHostname(nsCString& host);
     335                 :   nsresult EnumerateSiteData(const nsACString& domain,
     336                 :                              const nsTArray<nsCString>& sites,
     337                 :                              InfallibleTArray<nsCString>& result,
     338                 :                              bool firstMatchOnly);
     339                 : 
     340                 :   nsWeakPtr mCurrentDocument; // weak reference, we use it to id document only
     341                 : 
     342                 :   static nsIFile *sPluginTempDir;
     343                 : 
     344                 :   // We need to hold a global ptr to ourselves because we register for
     345                 :   // two different CIDs for some reason...
     346                 :   static nsPluginHost* sInst;
     347                 : 
     348                 : #ifdef MAC_CARBON_PLUGINS
     349                 :   nsCOMPtr<nsITimer> mVisiblePluginTimer;
     350                 :   nsTObserverArray<nsIPluginInstanceOwner*> mVisibleTimerTargets;
     351                 :   nsCOMPtr<nsITimer> mHiddenPluginTimer;
     352                 :   nsTObserverArray<nsIPluginInstanceOwner*> mHiddenTimerTargets;
     353                 : #endif
     354                 : };
     355                 : 
     356                 : class NS_STACK_CLASS PluginDestructionGuard : protected PRCList
     357                 : {
     358                 : public:
     359               0 :   PluginDestructionGuard(nsNPAPIPluginInstance *aInstance)
     360               0 :     : mInstance(aInstance)
     361                 :   {
     362               0 :     Init();
     363               0 :   }
     364                 : 
     365               0 :   PluginDestructionGuard(NPP npp)
     366               0 :     : mInstance(npp ? static_cast<nsNPAPIPluginInstance*>(npp->ndata) : nsnull)
     367                 :   {
     368               0 :     Init();
     369               0 :   }
     370                 : 
     371                 :   ~PluginDestructionGuard();
     372                 : 
     373                 :   static bool DelayDestroy(nsNPAPIPluginInstance *aInstance);
     374                 : 
     375                 : protected:
     376               0 :   void Init()
     377                 :   {
     378               0 :     NS_ASSERTION(NS_IsMainThread(), "Should be on the main thread");
     379                 : 
     380               0 :     mDelayedDestroy = false;
     381                 : 
     382               0 :     PR_INIT_CLIST(this);
     383               0 :     PR_INSERT_BEFORE(this, &sListHead);
     384               0 :   }
     385                 : 
     386                 :   nsRefPtr<nsNPAPIPluginInstance> mInstance;
     387                 :   bool mDelayedDestroy;
     388                 : 
     389                 :   static PRCList sListHead;
     390                 : };
     391                 : 
     392                 : #endif // nsPluginHost_h_

Generated by: LCOV version 1.7