dom/plugins/base/nsPluginHost.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsPluginHost_h_
michael@0 7 #define nsPluginHost_h_
michael@0 8
michael@0 9 #include "nsIPluginHost.h"
michael@0 10 #include "nsIObserver.h"
michael@0 11 #include "nsCOMPtr.h"
michael@0 12 #include "prlink.h"
michael@0 13 #include "prclist.h"
michael@0 14 #include "npapi.h"
michael@0 15 #include "nsIPluginTag.h"
michael@0 16 #include "nsPluginsDir.h"
michael@0 17 #include "nsPluginDirServiceProvider.h"
michael@0 18 #include "nsAutoPtr.h"
michael@0 19 #include "nsWeakPtr.h"
michael@0 20 #include "nsIPrompt.h"
michael@0 21 #include "nsWeakReference.h"
michael@0 22 #include "MainThreadUtils.h"
michael@0 23 #include "nsTArray.h"
michael@0 24 #include "nsTObserverArray.h"
michael@0 25 #include "nsITimer.h"
michael@0 26 #include "nsPluginTags.h"
michael@0 27 #include "nsPluginPlayPreviewInfo.h"
michael@0 28 #include "nsIEffectiveTLDService.h"
michael@0 29 #include "nsIIDNService.h"
michael@0 30 #include "nsCRT.h"
michael@0 31
michael@0 32 class nsNPAPIPlugin;
michael@0 33 class nsIComponentManager;
michael@0 34 class nsIFile;
michael@0 35 class nsIChannel;
michael@0 36 class nsPluginNativeWindow;
michael@0 37 class nsObjectLoadingContent;
michael@0 38 class nsPluginInstanceOwner;
michael@0 39 class nsNPAPIPluginInstance;
michael@0 40 class nsNPAPIPluginStreamListener;
michael@0 41 class nsIPluginInstanceOwner;
michael@0 42 class nsIInputStream;
michael@0 43 class nsIStreamListener;
michael@0 44
michael@0 45 class nsInvalidPluginTag : public nsISupports
michael@0 46 {
michael@0 47 public:
michael@0 48 nsInvalidPluginTag(const char* aFullPath, int64_t aLastModifiedTime = 0);
michael@0 49 virtual ~nsInvalidPluginTag();
michael@0 50
michael@0 51 NS_DECL_ISUPPORTS
michael@0 52
michael@0 53 nsCString mFullPath;
michael@0 54 int64_t mLastModifiedTime;
michael@0 55 bool mSeen;
michael@0 56
michael@0 57 nsRefPtr<nsInvalidPluginTag> mPrev;
michael@0 58 nsRefPtr<nsInvalidPluginTag> mNext;
michael@0 59 };
michael@0 60
michael@0 61 class nsPluginHost : public nsIPluginHost,
michael@0 62 public nsIObserver,
michael@0 63 public nsITimerCallback,
michael@0 64 public nsSupportsWeakReference
michael@0 65 {
michael@0 66 public:
michael@0 67 nsPluginHost();
michael@0 68 virtual ~nsPluginHost();
michael@0 69
michael@0 70 static already_AddRefed<nsPluginHost> GetInst();
michael@0 71
michael@0 72 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
michael@0 73
michael@0 74 NS_DECL_ISUPPORTS
michael@0 75 NS_DECL_NSIPLUGINHOST
michael@0 76 NS_DECL_NSIOBSERVER
michael@0 77 NS_DECL_NSITIMERCALLBACK
michael@0 78
michael@0 79 nsresult Init();
michael@0 80 nsresult LoadPlugins();
michael@0 81 nsresult UnloadPlugins();
michael@0 82
michael@0 83 nsresult SetUpPluginInstance(const char *aMimeType,
michael@0 84 nsIURI *aURL,
michael@0 85 nsPluginInstanceOwner *aOwner);
michael@0 86 bool PluginExistsForType(const char* aMimeType);
michael@0 87
michael@0 88 nsresult IsPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
michael@0 89
michael@0 90 void GetPlugins(nsTArray<nsRefPtr<nsPluginTag> >& aPluginArray);
michael@0 91
michael@0 92 nsresult GetURL(nsISupports* pluginInst,
michael@0 93 const char* url,
michael@0 94 const char* target,
michael@0 95 nsNPAPIPluginStreamListener* streamListener,
michael@0 96 const char* altHost,
michael@0 97 const char* referrer,
michael@0 98 bool forceJSEnabled);
michael@0 99 nsresult PostURL(nsISupports* pluginInst,
michael@0 100 const char* url,
michael@0 101 uint32_t postDataLen,
michael@0 102 const char* postData,
michael@0 103 bool isFile,
michael@0 104 const char* target,
michael@0 105 nsNPAPIPluginStreamListener* streamListener,
michael@0 106 const char* altHost,
michael@0 107 const char* referrer,
michael@0 108 bool forceJSEnabled,
michael@0 109 uint32_t postHeadersLength,
michael@0 110 const char* postHeaders);
michael@0 111
michael@0 112 nsresult FindProxyForURL(const char* url, char* *result);
michael@0 113 nsresult UserAgent(const char **retstring);
michael@0 114 nsresult ParsePostBufferToFixHeaders(const char *inPostData, uint32_t inPostDataLen,
michael@0 115 char **outPostData, uint32_t *outPostDataLen);
michael@0 116 nsresult CreateTempFileToPost(const char *aPostDataURL, nsIFile **aTmpFile);
michael@0 117 nsresult NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow);
michael@0 118
michael@0 119 void AddIdleTimeTarget(nsIPluginInstanceOwner* objectFrame, bool isVisible);
michael@0 120 void RemoveIdleTimeTarget(nsIPluginInstanceOwner* objectFrame);
michael@0 121
michael@0 122 nsresult GetPluginName(nsNPAPIPluginInstance *aPluginInstance, const char** aPluginName);
michael@0 123 nsresult StopPluginInstance(nsNPAPIPluginInstance* aInstance);
michael@0 124 nsresult GetPluginTagForInstance(nsNPAPIPluginInstance *aPluginInstance, nsIPluginTag **aPluginTag);
michael@0 125
michael@0 126 nsresult
michael@0 127 NewPluginURLStream(const nsString& aURL,
michael@0 128 nsNPAPIPluginInstance *aInstance,
michael@0 129 nsNPAPIPluginStreamListener *aListener,
michael@0 130 nsIInputStream *aPostStream = nullptr,
michael@0 131 const char *aHeadersData = nullptr,
michael@0 132 uint32_t aHeadersDataLen = 0);
michael@0 133
michael@0 134 nsresult
michael@0 135 GetURLWithHeaders(nsNPAPIPluginInstance *pluginInst,
michael@0 136 const char* url,
michael@0 137 const char* target = nullptr,
michael@0 138 nsNPAPIPluginStreamListener* streamListener = nullptr,
michael@0 139 const char* altHost = nullptr,
michael@0 140 const char* referrer = nullptr,
michael@0 141 bool forceJSEnabled = false,
michael@0 142 uint32_t getHeadersLength = 0,
michael@0 143 const char* getHeaders = nullptr);
michael@0 144
michael@0 145 nsresult
michael@0 146 DoURLLoadSecurityCheck(nsNPAPIPluginInstance *aInstance,
michael@0 147 const char* aURL);
michael@0 148
michael@0 149 nsresult
michael@0 150 AddHeadersToChannel(const char *aHeadersData, uint32_t aHeadersDataLen,
michael@0 151 nsIChannel *aGenericChannel);
michael@0 152
michael@0 153 static nsresult GetPluginTempDir(nsIFile **aDir);
michael@0 154
michael@0 155 // Writes updated plugins settings to disk and unloads the plugin
michael@0 156 // if it is now disabled
michael@0 157 nsresult UpdatePluginInfo(nsPluginTag* aPluginTag);
michael@0 158
michael@0 159 // Helper that checks if a type is whitelisted in plugin.allowed_types.
michael@0 160 // Always returns true if plugin.allowed_types is not set
michael@0 161 static bool IsTypeWhitelisted(const char *aType);
michael@0 162
michael@0 163 // checks whether aTag is a "java" plugin tag (a tag for a plugin
michael@0 164 // that does Java)
michael@0 165 static bool IsJavaMIMEType(const char *aType);
michael@0 166
michael@0 167 static nsresult PostPluginUnloadEvent(PRLibrary* aLibrary);
michael@0 168
michael@0 169 void PluginCrashed(nsNPAPIPlugin* plugin,
michael@0 170 const nsAString& pluginDumpID,
michael@0 171 const nsAString& browserDumpID);
michael@0 172
michael@0 173 nsNPAPIPluginInstance *FindInstance(const char *mimetype);
michael@0 174 nsNPAPIPluginInstance *FindOldestStoppedInstance();
michael@0 175 uint32_t StoppedInstanceCount();
michael@0 176
michael@0 177 nsTArray< nsRefPtr<nsNPAPIPluginInstance> > *InstanceArray();
michael@0 178
michael@0 179 void DestroyRunningInstances(nsPluginTag* aPluginTag);
michael@0 180
michael@0 181 // Return the tag for |aLibrary| if found, nullptr if not.
michael@0 182 nsPluginTag* FindTagForLibrary(PRLibrary* aLibrary);
michael@0 183
michael@0 184 // The last argument should be false if we already have an in-flight stream
michael@0 185 // and don't need to set up a new stream.
michael@0 186 nsresult InstantiatePluginInstance(const char *aMimeType, nsIURI* aURL,
michael@0 187 nsObjectLoadingContent *aContent,
michael@0 188 nsPluginInstanceOwner** aOwner);
michael@0 189
michael@0 190 // Does not accept nullptr and should never fail.
michael@0 191 nsPluginTag* TagForPlugin(nsNPAPIPlugin* aPlugin);
michael@0 192
michael@0 193 nsresult GetPlugin(const char *aMimeType, nsNPAPIPlugin** aPlugin);
michael@0 194
michael@0 195 nsresult NewPluginStreamListener(nsIURI* aURL,
michael@0 196 nsNPAPIPluginInstance* aInstance,
michael@0 197 nsIStreamListener **aStreamListener);
michael@0 198
michael@0 199 private:
michael@0 200 nsresult
michael@0 201 TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsPluginInstanceOwner *aOwner);
michael@0 202
michael@0 203 nsPluginTag*
michael@0 204 FindPreferredPlugin(const InfallibleTArray<nsPluginTag*>& matches);
michael@0 205
michael@0 206 // Return an nsPluginTag for this type, if any. If aCheckEnabled is
michael@0 207 // true, only enabled plugins will be returned.
michael@0 208 nsPluginTag*
michael@0 209 FindPluginForType(const char* aMimeType, bool aCheckEnabled);
michael@0 210
michael@0 211 nsPluginTag*
michael@0 212 FindPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
michael@0 213
michael@0 214 nsresult
michael@0 215 FindStoppedPluginForURL(nsIURI* aURL, nsIPluginInstanceOwner *aOwner);
michael@0 216
michael@0 217 nsresult
michael@0 218 FindPlugins(bool aCreatePluginList, bool * aPluginsChanged);
michael@0 219
michael@0 220 // Registers or unregisters the given mime type with the category manager
michael@0 221 // (performs no checks - see UpdateCategoryManager)
michael@0 222 enum nsRegisterType { ePluginRegister, ePluginUnregister };
michael@0 223 void RegisterWithCategoryManager(nsCString &aMimeType, nsRegisterType aType);
michael@0 224
michael@0 225 nsresult
michael@0 226 ScanPluginsDirectory(nsIFile *pluginsDir,
michael@0 227 bool aCreatePluginList,
michael@0 228 bool *aPluginsChanged);
michael@0 229
michael@0 230 nsresult
michael@0 231 ScanPluginsDirectoryList(nsISimpleEnumerator *dirEnum,
michael@0 232 bool aCreatePluginList,
michael@0 233 bool *aPluginsChanged);
michael@0 234
michael@0 235 nsresult EnsurePluginLoaded(nsPluginTag* aPluginTag);
michael@0 236
michael@0 237 bool IsRunningPlugin(nsPluginTag * aPluginTag);
michael@0 238
michael@0 239 // Stores all plugins info into the registry
michael@0 240 nsresult WritePluginInfo();
michael@0 241
michael@0 242 // Loads all cached plugins info into mCachedPlugins
michael@0 243 nsresult ReadPluginInfo();
michael@0 244
michael@0 245 PRBool GhettoBlacklist(nsIFile *pluginFile);
michael@0 246
michael@0 247 // Given a file path, returns the plugins info from our cache
michael@0 248 // and removes it from the cache.
michael@0 249 void RemoveCachedPluginsInfo(const char *filePath,
michael@0 250 nsPluginTag **result);
michael@0 251
michael@0 252 // Checks to see if a tag object is in our list of live tags.
michael@0 253 bool IsLiveTag(nsIPluginTag* tag);
michael@0 254
michael@0 255 // Checks our list of live tags for an equivalent tag.
michael@0 256 nsPluginTag* HaveSamePlugin(const nsPluginTag * aPluginTag);
michael@0 257
michael@0 258 // Returns the first plugin at |path|
michael@0 259 nsPluginTag* FirstPluginWithPath(const nsCString& path);
michael@0 260
michael@0 261 nsresult EnsurePrivateDirServiceProvider();
michael@0 262
michael@0 263 void OnPluginInstanceDestroyed(nsPluginTag* aPluginTag);
michael@0 264
michael@0 265 nsRefPtr<nsPluginTag> mPlugins;
michael@0 266 nsRefPtr<nsPluginTag> mCachedPlugins;
michael@0 267 nsRefPtr<nsInvalidPluginTag> mInvalidPlugins;
michael@0 268 nsTArray< nsRefPtr<nsPluginPlayPreviewInfo> > mPlayPreviewMimeTypes;
michael@0 269 bool mPluginsLoaded;
michael@0 270
michael@0 271 // set by pref plugin.override_internal_types
michael@0 272 bool mOverrideInternalTypes;
michael@0 273
michael@0 274 // set by pref plugin.disable
michael@0 275 bool mPluginsDisabled;
michael@0 276 // set by pref plugins.click_to_play
michael@0 277 bool mPluginsClickToPlay;
michael@0 278
michael@0 279 // Any instances in this array will have valid plugin objects via GetPlugin().
michael@0 280 // When removing an instance it might not die - be sure to null out it's plugin.
michael@0 281 nsTArray< nsRefPtr<nsNPAPIPluginInstance> > mInstances;
michael@0 282
michael@0 283 nsCOMPtr<nsIFile> mPluginRegFile;
michael@0 284 #ifdef XP_WIN
michael@0 285 nsRefPtr<nsPluginDirServiceProvider> mPrivateDirServiceProvider;
michael@0 286 #endif
michael@0 287
michael@0 288 nsCOMPtr<nsIEffectiveTLDService> mTLDService;
michael@0 289 nsCOMPtr<nsIIDNService> mIDNService;
michael@0 290
michael@0 291 // Helpers for ClearSiteData and SiteHasData.
michael@0 292 nsresult NormalizeHostname(nsCString& host);
michael@0 293 nsresult EnumerateSiteData(const nsACString& domain,
michael@0 294 const InfallibleTArray<nsCString>& sites,
michael@0 295 InfallibleTArray<nsCString>& result,
michael@0 296 bool firstMatchOnly);
michael@0 297
michael@0 298 nsWeakPtr mCurrentDocument; // weak reference, we use it to id document only
michael@0 299
michael@0 300 static nsIFile *sPluginTempDir;
michael@0 301
michael@0 302 // We need to hold a global ptr to ourselves because we register for
michael@0 303 // two different CIDs for some reason...
michael@0 304 static nsPluginHost* sInst;
michael@0 305 };
michael@0 306
michael@0 307 class MOZ_STACK_CLASS PluginDestructionGuard : protected PRCList
michael@0 308 {
michael@0 309 public:
michael@0 310 PluginDestructionGuard(nsNPAPIPluginInstance *aInstance);
michael@0 311
michael@0 312 PluginDestructionGuard(NPP npp);
michael@0 313
michael@0 314 ~PluginDestructionGuard();
michael@0 315
michael@0 316 static bool DelayDestroy(nsNPAPIPluginInstance *aInstance);
michael@0 317
michael@0 318 protected:
michael@0 319 void Init()
michael@0 320 {
michael@0 321 NS_ASSERTION(NS_IsMainThread(), "Should be on the main thread");
michael@0 322
michael@0 323 mDelayedDestroy = false;
michael@0 324
michael@0 325 PR_INIT_CLIST(this);
michael@0 326 PR_INSERT_BEFORE(this, &sListHead);
michael@0 327 }
michael@0 328
michael@0 329 nsRefPtr<nsNPAPIPluginInstance> mInstance;
michael@0 330 bool mDelayedDestroy;
michael@0 331
michael@0 332 static PRCList sListHead;
michael@0 333 };
michael@0 334
michael@0 335 #endif // nsPluginHost_h_

mercurial