Files
palemoon27/dom/base/nsObjectLoadingContent.h
T
roytam1 e3d7542d66 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1145326 - String#normalize form parameter might not be an atom. r=Waldo (291a9d9c3)
-  1156886 - Optimize toLowerCase and toUpperCase on ASCII characters. r=luke (6dad527a9)
- Bug 1102219 - Part 0: Combine WARNED_* slots in GlobalObject and turn it into a bitset. r=till (1496c25c4)
- Bug 1102219 - Part 1: Add `String.prototype.includes`; keep `String.prototype.contains` around as an alias with a (non-release builds only) warning. r=till (8502ce4c4)
- Bug 1102219 - Part 3: Replace more `String.prototype.contains` with `String.prototype.includes` in JS code. r=till (d2d3e3455)
- Bug 1102219 - followup for Part 0: Fix code alignment and argument name in GlobalObject.h. r=me (df2063dba)
- Bug 863515 - Expose hasContentOpener on nsITabParent. r=smaug. (0e1c18870)
- Bug 1157454 - Satisfy TSan by removing the unneeded mEarlyRv read in WebCryptoTask::CalculateResult() r=rbarnes (ba5fca0ae)
- Bug 1106087 - Recreate newly generated ECDH private keys with an CKA_EC_POINT attribute to support JWK and PKCS8 export r=rbarnes (07634e876)
- Bug 1158927 - Calls to CryptoKey::PrivateKeyToPkcs8() and ::PublicKeyToSpki() should check return values r=rbarnes (03787e2fb)
- Bug 1050175 - Add raw import/export for EC public keys to the WebCrypto API r=rbarnes,smaug (168a93425)
- Bug 968520 - Add mozilla::fallible to Fallible{Auto,}TArray::SetLength calls. r=froydnj (f85ec3e02)
- Bug 977586 - omit quotes in top-level strings logged via console.log(), and omit extra spaces when custom styles (%c) are used. r=past,baku (58391e3d0)
- Bug 1167423 - patch 1 - Handle return values of FallibleTArray functions in Console API, r=smaug (7e36592a4)
- Bug 1167423 - patch 2 - Handle return values of FallibleTArray functions in WebSocket, r=smaug (286dc7745)
- Bug 1167423 - patch 3 - Handle return values of FallibleTArray functions in MutationObserver, r=smaug (e4cc88cfb)
- Bug 1167423 - patch 4 - Handle return values of FallibleTArray functions in CanvasRenderingContext2D, r=smaug (d02bfff6c)
- Bug 1167423 - patch 5 - Handle return values of FallibleTArray functions in WebGL2Context, r=smaug (789aac4ea)
- Bug 1167423 - patch 6 - Handle return values of FallibleTArray functions in WebCryptTask, r=smaug (7ca60765a)
- Bug 968520 - Use FallibleTArray::TruncateLength instead of SetLength where possible. r=froydnj (bb8e960b4)
- Bug 1167423 - patch 7 - Handle return values of FallibleTArray functions in DataStore API, r=smaug (e207e7371)
- Bug 1167423 - patch 8 - Handle return values of FallibleTArray functions in HTMLInputElement, r=smaug (f87b9d4fb)
- Bug 1167423 - patch 9 - Handle return values of FallibleTArray functions in MediaSource, r=jya (9d2905c5a)
- Bug 1167423 - patch 10 - Handle return values of FallibleTArray functions in MobileMessage, r=smaug (6e8b7ce0f)
- Bug 1167418 - Check fallible AppendElements call in FontFaceSet. r=poiru (cd64d2b69)
- Bug 968520 - Add mozilla::fallible to FallibleTArray::AppendElements calls. r=froydnj (a16f43ea9)
- Bug 947854 part 2 - Avoid exiting fullscreen mode when exit from DOM fullscreen. r=smaug,dao (4fed384bc) (partly)
- Bug 947854 part 3 - Include testing MozExitedFullscreen event in existing chrome test. r=smaug (b463bf2e8)
- Bug 1105939 part 1 - Backout workaround from bug 740923. r=smichaud (08ae588b7)
- Bug 1105939 part 2 - Suppress windows animation when hiding chrome on OS X. r=smichaud (f1792f1e8)
- Bug 1105939 part 3 - Save and restore window collection behavior when showing/hiding window chrome. r=mstange (359c2d820)
- Bug 1105939 part 4 - Treat cocoa window without titlebar as fullscreen to avoid drawing rounded corners on it. r=mstange (40a921643)
- Bug 1105939 part 5 - Rename parameter aRequireTrust of SetFullScreenInternal to aFullscreenMode for increased clarity. r=smaug (650f229c3)
- Bug 1105939 part 6 - Add a method to nsIWidget for widget to distinguish between fullscreen mode and DOM fullscreen. r=roc (e1d03316d)
- Bug 1105939 part 7 - Use tranditional fullscreen on Mac for DOM fullscreen. r=smichaud (8e737b365)
- Bug 1164625 - Don't redraw the titlebar for unified toolbar height changes when the titlebar is under Gecko's control. r=smichaud (683c87ff4)
- Bug 1171210 - Add a telemetry probe for how long it takes to clear plugin cookies during sanitize. r=vladan (26cd118c5) (partly)
- Bug 1148012 - Add a run ID for plugins to differentiate subsequent runs of the same plugins. r=jimm. (dd89a0278)
- Bug 1148012 - Expose run ID through nsIObjectLoadingContent.idl. r=josh,smaug. (82080018e)
- Bug 1148012 - Send the run ID and plugin name along with the plugin-crashed observer notification. r=josh. (d0f26b99a)
- Bug 1152395: Ensure that NP_Shutdown respects async plugin init; r=jimm (6c94915e5)
- Bug 1146955 - Unify pluginID for GMP and runID for NPAPI plugins to use the same internal incrementor. r=jesup, mrbkap. (b5db7ac02)
- Bug 1146955 - Dispatch PluginCrashed event in content process on GMP crash for PeerConnection. r=jesup. (3eedefe8c)
- Bug 1123759: Set low integrity on NPAPI processes for Windows sandboxing policy level >= 2. r=bbondy, r=bsmedberg (bc795adba)
- bits of Bug 1008435 - Let the Gecko Profiler work with child processes. (7db2f4f82)
- Bug 1116188 - Add async ProfileGatherer as the mechanism for gathering profiles from subprocesses. r=bgirard,bz (23aed75ce)
- add ProcessHangMonitor.jsm as of Bug 1120650: add telemetry probe for slow script notices. (7501c04d7)
- Bug 1160142 - For e10s plugin hangs take the minidump of the browser process before we message the chrome UI about the hang. r=billm (557ae5892)
- Bug 1175975 - Null crash fix in ProcessHangMonitor (r=jimm) (52fce4c7c)
- Bug 1164543 - Add HasLocalInstance support (r=jimm) (572e9e17e)
- Bug 699860 - Removed useJSTransfer and deleteAllLike usage from ForgetAboutSite.jsm. r=paolo (e3f9013bc)
- Bug 1189967 - Add cmath to the wrapped STL headers. r=nfroyd Somehow, TimeStamp.cpp fails to build with MSVC 2015 without this. (692e3d17d)
- Bug 1249167 - Fix dependencies involving stdc++compat and clang-plugin. r=mshal (96af922d7)
- Bug 1248416 - add symbols for bad_function_call exception for C++ runtimes. r=nfroyd (fa28f7568)
- Bug 1228641. Add a polyfill of std::initializer_list. r=froydnj (5625de4ac)
- Bug 1163329 - Add a utility for expanding a tuple into a variadic argument list to MFBT. r=froydnj (ff41a27b7)
- Bug 1255540 - Properly run the clang-plugin tests. r=gps (bdf4d9ac4)
- Bug 1152759 - Regroup Performance Monitoring modules/components;r=yoric (cfdc3c13a)
- Bug 1151750 - about:performance now recapitulates alerts. r=mossop (e9d2a3a42)
- Bug 1150863 - added play and pause button to about:performance in addition to a dropdown list to select the refresh rate. r=Yoric (944b00cfc)
- Bug 1149486 - Extract a window title and window ID for PerformanceStats. r=mossop (c57e65841)
- fix getTop() (df8bdbc5c)
- Bug 1152950 - AddonWatcher should not inform the user at the first infraction. r=mossop (2cf902efe)
- Bug 1157471 - AddonWatcher console noise. r=yoric (44c67d528)
- Bug 1154239 - Rework PerformanceStats.jsm for modularity and asynchronicity. r=Mossop (4f9ba2236)
- Bug 1156264 - Activate/deactivate jank and CPOW monitoring separately (high-level). r=mossop (9fcb6ca88)
- Bug 1188616 - CPOW monitoring should use JS_Now instead of PR_IntervalNow. r=jandem (45cc23a05)
- Bug 1157870 - Performance Groups should have a unique ID (low-level). r=jandem (ead7d288e)
- Bug 1157870 - Performance Groups should have a unique ID (high-level). r=mossop (20c9fa6df)
- Bug 1157870 - Cross compilation fixup. (627c99d4c)
- Bug 1169890 - Check return values for CryptoBuffer.Assign() calls r=rbarnes (681f04148)
- Bug 1172785 - RTCCertificate implementation, r=rbarnes (c30068f20)
- Bug 1155898 - Expose fetch on JS sandbox. r=gabor, r=peterv (b965210af)
- Bug 1181262 - Disabling more code under --disable-webrtc, r=dholbert,bwc (0e93112cb)
- fix mispatch (f09b69b91)
- Bug 1172785 - RTCCertificate interfaces, r=peterv (9cbcbbffb)
- backport some profiler stuff (b7d68cafc)
- Bug 1137245 - ServiceWorkerManager should set WorkerPrivate::LoadInfo::mIndexedDBAllowed correctly. r=bent, bkelly (58ef4c286)
- Bug 1176434 - Enabling indexedDB for content JS sandboxes, r=bent (c891b518f)
- Bug 1158399 - Expose the [[DateValue]] field in Date objects only through a ClippedTime class that enforces prior TimeClip-ing on the given value. r=evilpie, r=bz, r=dhylands, r=mt, r=froydnj, r=khuey, r=baku, r=smaug Bug 1158399 - Ensure/assert that DateObject::setUTCTime never stores a non-TimeClip'd value in the reserved slot. r=evilpie (9c06bf765)
- Bug 861219 - Part 0: Make ClassSpec be able to delegate to another ClassSpec. r=bholley (85d88193e)
- Bug 861219 - Part 1: Make Date.prototype not be a Date object. r=bholley (19355939b)
- Bug 1177907 - Handle ObjectClassIs exception in date_toString. r=till (a2adb9c10)
2020-10-23 11:56:28 +08:00

640 lines
24 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* A base class implementing nsIObjectLoadingContent for use by
* various content nodes that want to provide plugin/document/image
* loading functionality (eg <embed>, <object>, <applet>, etc).
*/
#ifndef NSOBJECTLOADINGCONTENT_H_
#define NSOBJECTLOADINGCONTENT_H_
#include "mozilla/Attributes.h"
#include "nsImageLoadingContent.h"
#include "nsIStreamListener.h"
#include "nsIChannelEventSink.h"
#include "nsIObjectLoadingContent.h"
#include "nsIRunnable.h"
#include "nsIThreadInternal.h"
#include "nsIFrame.h"
#include "nsIFrameLoader.h"
class nsAsyncInstantiateEvent;
class nsStopPluginRunnable;
class AutoSetInstantiatingToFalse;
class nsPluginFrame;
class nsFrameLoader;
class nsXULElement;
class nsPluginInstanceOwner;
namespace mozilla {
namespace dom {
template<typename T> class Sequence;
struct MozPluginParameter;
} // namespace dom
} // namespace mozilla
class nsObjectLoadingContent : public nsImageLoadingContent
, public nsIStreamListener
, public nsIFrameLoaderOwner
, public nsIObjectLoadingContent
, public nsIChannelEventSink
{
friend class AutoSetInstantiatingToFalse;
friend class AutoSetLoadingToFalse;
friend class CheckPluginStopEvent;
friend class nsStopPluginRunnable;
friend class nsAsyncInstantiateEvent;
public:
// This enum's values must be the same as the constants on
// nsIObjectLoadingContent
enum ObjectType {
// Loading, type not yet known. We may be waiting for a channel to open.
eType_Loading = TYPE_LOADING,
// Content is a *non-svg* image
eType_Image = TYPE_IMAGE,
// Content is a plugin
eType_Plugin = TYPE_PLUGIN,
// Content is a subdocument, possibly SVG
eType_Document = TYPE_DOCUMENT,
// No content loaded (fallback). May be showing alternate content or
// a custom error handler - *including* click-to-play dialogs
eType_Null = TYPE_NULL
};
enum FallbackType {
// The content type is not supported (e.g. plugin not installed)
eFallbackUnsupported = nsIObjectLoadingContent::PLUGIN_UNSUPPORTED,
// Showing alternate content
eFallbackAlternate = nsIObjectLoadingContent::PLUGIN_ALTERNATE,
// The plugin exists, but is disabled
eFallbackDisabled = nsIObjectLoadingContent::PLUGIN_DISABLED,
// The plugin is blocklisted and disabled
eFallbackBlocklisted = nsIObjectLoadingContent::PLUGIN_BLOCKLISTED,
// The plugin is considered outdated, but not disabled
eFallbackOutdated = nsIObjectLoadingContent::PLUGIN_OUTDATED,
// The plugin has crashed
eFallbackCrashed = nsIObjectLoadingContent::PLUGIN_CRASHED,
// Suppressed by security policy
eFallbackSuppressed = nsIObjectLoadingContent::PLUGIN_SUPPRESSED,
// Blocked by content policy
eFallbackUserDisabled = nsIObjectLoadingContent::PLUGIN_USER_DISABLED,
/// ** All values >= eFallbackClickToPlay are plugin placeholder types
/// that would be replaced by a real plugin if activated (PlayPlugin())
/// ** Furthermore, values >= eFallbackClickToPlay and
/// <= eFallbackVulnerableNoUpdate are click-to-play types.
// The plugin is disabled until the user clicks on it
eFallbackClickToPlay = nsIObjectLoadingContent::PLUGIN_CLICK_TO_PLAY,
// The plugin is vulnerable (update available)
eFallbackVulnerableUpdatable = nsIObjectLoadingContent::PLUGIN_VULNERABLE_UPDATABLE,
// The plugin is vulnerable (no update available)
eFallbackVulnerableNoUpdate = nsIObjectLoadingContent::PLUGIN_VULNERABLE_NO_UPDATE,
// The plugin is disabled and play preview content is displayed until
// the extension code enables it by sending the MozPlayPlugin event
eFallbackPlayPreview = nsIObjectLoadingContent::PLUGIN_PLAY_PREVIEW
};
nsObjectLoadingContent();
virtual ~nsObjectLoadingContent();
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIFRAMELOADEROWNER
NS_DECL_NSIOBJECTLOADINGCONTENT
NS_DECL_NSICHANNELEVENTSINK
/**
* Object state. This is a bitmask of NS_EVENT_STATEs epresenting the
* current state of the object.
*/
mozilla::EventStates ObjectState() const;
ObjectType Type() const { return mType; }
void SetIsNetworkCreated(bool aNetworkCreated)
{
mNetworkCreated = aNetworkCreated;
}
/**
* When the object is loaded, the attributes and all nested <param>
* elements are cached as name:value string pairs to be passed as
* parameters when instantiating the plugin.
*
* Note: these cached values can be overriden for different quirk cases.
*/
// Returns the cached attributes array.
void GetPluginAttributes(nsTArray<mozilla::dom::MozPluginParameter>& aAttributes);
// Returns the cached <param> array.
void GetPluginParameters(nsTArray<mozilla::dom::MozPluginParameter>& aParameters);
/**
* Immediately instantiate a plugin instance. This is a no-op if mType !=
* eType_Plugin or a plugin is already running.
*
* aIsLoading indicates that we are in the loading code, and we can bypass
* the mIsLoading check.
*/
nsresult InstantiatePluginInstance(bool aIsLoading = false);
/**
* Notify this class the document state has changed
* Called by nsDocument so we may suspend plugins in inactive documents)
*/
void NotifyOwnerDocumentActivityChanged();
/**
* When a plug-in is instantiated, it can create a scriptable
* object that the page wants to interact with. We expose this
* object by placing it on the prototype chain of our element,
* between the element itself and its most-derived DOM prototype.
*
* SetupProtoChain handles actually inserting the plug-in
* scriptable object into the proto chain if needed.
*
* DoResolve is a hook that allows us to find out when the web
* page is looking up a property name on our object and make sure
* that our plug-in, if any, is instantiated.
*/
// Helper for WebIDL node wrapping
void SetupProtoChain(JSContext* aCx, JS::Handle<JSObject*> aObject);
// Remove plugin from protochain
void TeardownProtoChain();
// Helper for WebIDL NeedResolve
bool DoResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
JS::Handle<jsid> aId,
JS::MutableHandle<JSPropertyDescriptor> aDesc);
// The return value is whether DoResolve might end up resolving the given
// id. If in doubt, return true.
static bool MayResolve(jsid aId);
// Helper for WebIDL enumeration
void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& /* unused */,
mozilla::ErrorResult& aRv);
// WebIDL API
nsIDocument* GetContentDocument();
void GetActualType(nsAString& aType) const
{
CopyUTF8toUTF16(mContentType, aType);
}
uint32_t DisplayedType() const
{
return mType;
}
uint32_t GetContentTypeForMIMEType(const nsAString& aMIMEType)
{
return GetTypeOfContent(NS_ConvertUTF16toUTF8(aMIMEType));
}
void PlayPlugin(mozilla::ErrorResult& aRv)
{
aRv = PlayPlugin();
}
void Reload(bool aClearActivation, mozilla::ErrorResult& aRv)
{
aRv = Reload(aClearActivation);
}
bool Activated() const
{
return mActivated;
}
nsIURI* GetSrcURI() const
{
return mURI;
}
/**
* The default state that this plugin would be without manual activation.
* @returns PLUGIN_ACTIVE if the default state would be active.
*/
uint32_t DefaultFallbackType();
uint32_t PluginFallbackType() const
{
return mFallbackType;
}
bool HasRunningPlugin() const
{
return !!mInstanceOwner;
}
void CancelPlayPreview(mozilla::ErrorResult& aRv)
{
aRv = CancelPlayPreview();
}
void SwapFrameLoaders(nsXULElement& aOtherOwner, mozilla::ErrorResult& aRv)
{
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
}
void LegacyCall(JSContext* aCx, JS::Handle<JS::Value> aThisVal,
const mozilla::dom::Sequence<JS::Value>& aArguments,
JS::MutableHandle<JS::Value> aRetval,
mozilla::ErrorResult& aRv);
uint32_t GetRunID(mozilla::ErrorResult& aRv)
{
uint32_t runID;
nsresult rv = GetRunID(&runID);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return 0;
}
return runID;
}
protected:
/**
* Begins loading the object when called
*
* Attributes of |this| QI'd to nsIContent will be inspected, depending on
* the node type. This function currently assumes it is a <applet>,
* <object>, or <embed> tag.
*
* The instantiated plugin depends on:
* - The URI (<embed src>, <object data>)
* - The type 'hint' (type attribute)
* - The mime type returned by opening the URI
* - Enabled plugins claiming the ultimate mime type
* - The capabilities returned by GetCapabilities
* - The classid attribute, if eSupportClassID is among the capabilities
*
* If eAllowPluginSkipChannel is true, we may skip opening the URI if our
* type hint points to a valid plugin, deferring that responsibility to the
* plugin.
* Similarly, if no URI is provided, but a type hint for a valid plugin is
* present, that plugin will be instantiated
*
* Otherwise a request to that URI is made and the type sent by the server
* is used to find a suitable handler, EXCEPT when:
* - The type hint refers to a *supported* plugin, in which case that
* plugin will be instantiated regardless of the server provided type
* - The server returns a binary-stream type, and our type hint refers to
* a valid non-document type, we will use the type hint
*
* @param aNotify If we should send notifications. If false, content
* loading may be deferred while appropriate frames are
* created
* @param aForceLoad If we should reload this content (and re-attempt the
* channel open) even if our parameters did not change
*/
nsresult LoadObject(bool aNotify,
bool aForceLoad = false);
enum Capabilities {
eSupportImages = 1u << 0, // Images are supported (imgILoader)
eSupportPlugins = 1u << 1, // Plugins are supported (nsIPluginHost)
eSupportDocuments = 1u << 2, // Documents are supported
// (nsIDocumentLoaderFactory)
// This flag always includes SVG
eSupportSVG = 1u << 3, // SVG is supported (image/svg+xml)
eSupportClassID = 1u << 4, // The classid attribute is supported
// If possible to get a *plugin* type from the type attribute *or* file
// extension, we can use that type and begin loading the plugin before
// opening a channel.
// A side effect of this is if the channel fails, the plugin is still
// running.
eAllowPluginSkipChannel = 1u << 5
};
/**
* Returns the list of capabilities this content node supports. This is a
* bitmask consisting of flags from the Capabilities enum.
*
* The default implementation supports all types but not
* eSupportClassID or eAllowPluginSkipChannel
*/
virtual uint32_t GetCapabilities() const;
/**
* Destroys all loaded documents/plugins and releases references
*/
void DestroyContent();
static void Traverse(nsObjectLoadingContent *tmp,
nsCycleCollectionTraversalCallback &cb);
void CreateStaticClone(nsObjectLoadingContent* aDest) const;
void DoStopPlugin(nsPluginInstanceOwner* aInstanceOwner, bool aDelayedStop,
bool aForcedReentry = false);
nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandler);
void UnbindFromTree(bool aDeep = true,
bool aNullParent = true);
private:
// Object parameter changes returned by UpdateObjectParameters
enum ParameterUpdateFlags {
eParamNoChange = 0,
// Parameters that potentially affect the channel changed
// - mOriginalURI, mOriginalContentType
eParamChannelChanged = 1u << 0,
// Parameters that affect displayed content changed
// - mURI, mContentType, mType, mBaseURI
eParamStateChanged = 1u << 1,
// The effective content type changed, independant of object type. This
// can happen when changing from Loading -> Final type, but doesn't
// necessarily happen when changing between object types. E.g., if a PDF
// handler was installed between the last load of this object and now, we
// might change from eType_Document -> eType_Plugin without changing
// ContentType
eParamContentTypeChanged = 1u << 2
};
/**
* Getter for child <param> elements that are not nested in another plugin
* dom element.
* This is an internal helper function and should not be used directly for
* passing parameters to the plugin instance.
*
* See GetPluginParameters and GetPluginAttributes, which also handle
* quirk-overrides.
*
* @param aParameters The array containing pairs of name/value strings
* from nested <param> objects.
* @param aIgnoreCodebase Flag for ignoring the "codebase" param when
* building the array. This is useful when loading
* java.
*/
void GetNestedParams(nsTArray<mozilla::dom::MozPluginParameter>& aParameters,
bool aIgnoreCodebase);
void BuildParametersArray();
/**
* Loads fallback content with the specified FallbackType
*
* @param aType FallbackType value for type of fallback we're loading
* @param aNotify Send notifications and events. If false, caller is
* responsible for doing so
*/
void LoadFallback(FallbackType aType, bool aNotify);
/**
* Internal version of LoadObject that should only be used by this class
* aLoadingChannel is passed by the LoadObject call from OnStartRequest,
* primarily for sanity-preservation
*/
nsresult LoadObject(bool aNotify,
bool aForceLoad,
nsIRequest *aLoadingChannel);
/**
* Introspects the object and sets the following member variables:
* - mOriginalContentType : This is the type attribute on the element
* - mOriginalURI : The src or data attribute on the element
* - mURI : The final URI, considering mChannel if
* mChannelLoaded is set
* - mContentType : The final content type, considering mChannel if
* mChannelLoaded is set
* - mBaseURI : The object's base URI, which may be set by the
* object (codebase attribute)
* - mType : The type the object is determined to be based
* on the above
*
* NOTE The class assumes that mType is the currently loaded type at various
* points, so the caller of this function must take the appropriate
* actions to ensure this
*
* NOTE This function does not perform security checks, only determining the
* requested type and parameters of the object.
*
* @param aJavaURI Specify that the URI will be consumed by java, which
* changes codebase parsing and URI construction. Used
* internally.
*
* @return Returns a bitmask of ParameterUpdateFlags values
*/
ParameterUpdateFlags UpdateObjectParameters(bool aJavaURI = false);
/**
* Queue a CheckPluginStopEvent and track it in mPendingCheckPluginStopEvent
*/
void QueueCheckPluginStopEvent();
void NotifyContentObjectWrapper();
/**
* Opens the channel pointed to by mURI into mChannel.
*/
nsresult OpenChannel();
/**
* Closes and releases references to mChannel and, if opened, mFinalListener
*/
nsresult CloseChannel();
/**
* If this object is allowed to play plugin content, or if it would display
* click-to-play instead.
* NOTE that this does not actually check if the object is a loadable plugin
* NOTE This ignores the current activated state. The caller should check this if appropriate.
*/
bool ShouldPlay(FallbackType &aReason, bool aIgnoreCurrentType);
/*
* Helper to check if mBaseURI can be used by java as a codebase
*/
bool CheckJavaCodebase();
/**
* Helper to check if our current URI passes policy
*
* @param aContentPolicy [out] The result of the content policy decision
*
* @return true if call succeeded and NS_CP_ACCEPTED(*aContentPolicy)
*/
bool CheckLoadPolicy(int16_t *aContentPolicy);
/**
* Helper to check if the object passes process policy. Assumes we have a
* final determined type.
*
* @param aContentPolicy [out] The result of the content policy decision
*
* @return true if call succeeded and NS_CP_ACCEPTED(*aContentPolicy)
*/
bool CheckProcessPolicy(int16_t *aContentPolicy);
/**
* Checks whether the given type is a supported document type
*
* NOTE Does not take content policy or capabilities into account
*/
bool IsSupportedDocument(const nsCString& aType);
/**
* Gets the plugin instance and creates a plugin stream listener, assigning
* it to mFinalListener
*/
bool MakePluginListener();
/**
* Unloads all content and resets the object to a completely unloaded state
*
* NOTE Calls StopPluginInstance() and may spin the event loop
*
* @param aResetState Reset the object type to 'loading' and destroy channel
* as well
*/
void UnloadObject(bool aResetState = true);
/**
* Notifies document observes about a new type/state of this object.
* Triggers frame construction as needed. mType must be set correctly when
* this method is called. This method is cheap if the type and state didn't
* actually change.
*
* @param aSync If a synchronous frame construction is required. If false,
* the construction may either be sync or async.
* @param aNotify if false, only need to update the state of our element.
*/
void NotifyStateChanged(ObjectType aOldType,
mozilla::EventStates aOldState,
bool aSync, bool aNotify);
/**
* Returns a ObjectType value corresponding to the type of content we would
* support the given MIME type as, taking capabilities and plugin state
* into account
*
* NOTE this does not consider whether the content would be suppressed by
* click-to-play or other content policy checks
*/
ObjectType GetTypeOfContent(const nsCString& aMIMEType);
/**
* Gets the frame that's associated with this content node.
* Does not flush.
*/
nsPluginFrame* GetExistingFrame();
// Helper class for SetupProtoChain
class SetupProtoChainRunner final : public nsIRunnable
{
~SetupProtoChainRunner();
public:
NS_DECL_ISUPPORTS
explicit SetupProtoChainRunner(nsObjectLoadingContent* aContent);
NS_IMETHOD Run() override;
private:
// We store an nsIObjectLoadingContent because we can
// unambiguously refcount that.
nsRefPtr<nsIObjectLoadingContent> mContent;
};
// Utility getter for getting our nsNPAPIPluginInstance in a safe way.
nsresult ScriptRequestPluginInstance(JSContext* aCx,
nsNPAPIPluginInstance** aResult);
// Utility method for getting our plugin JSObject
static nsresult GetPluginJSObject(JSContext *cx,
JS::Handle<JSObject*> obj,
nsNPAPIPluginInstance *plugin_inst,
JS::MutableHandle<JSObject*> plugin_obj,
JS::MutableHandle<JSObject*> plugin_proto);
// The final listener for mChannel (uriloader, pluginstreamlistener, etc.)
nsCOMPtr<nsIStreamListener> mFinalListener;
// Frame loader, for content documents we load.
nsRefPtr<nsFrameLoader> mFrameLoader;
// Track if we have a pending AsyncInstantiateEvent
nsCOMPtr<nsIRunnable> mPendingInstantiateEvent;
// Tracks if we have a pending CheckPluginStopEvent
nsCOMPtr<nsIRunnable> mPendingCheckPluginStopEvent;
// The content type of our current load target, updated by
// UpdateObjectParameters(). Takes the channel's type into account once
// opened.
//
// May change if a channel is opened, does not imply a loaded state
nsCString mContentType;
// The content type 'hint' provided by the element's type attribute. May
// or may not be used as a final type
nsCString mOriginalContentType;
// The channel that's currently being loaded. If set, but mChannelLoaded is
// false, has not yet reached OnStartRequest
nsCOMPtr<nsIChannel> mChannel;
// The URI of the current content.
// May change as we open channels and encounter redirects - does not imply
// a loaded type
nsCOMPtr<nsIURI> mURI;
// The original URI obtained from inspecting the element (codebase, and
// src/data). May differ from mURI due to redirects
nsCOMPtr<nsIURI> mOriginalURI;
// The baseURI used for constructing mURI, and used by some plugins (java)
// as a root for other resource requests.
nsCOMPtr<nsIURI> mBaseURI;
// Type of the currently-loaded content.
ObjectType mType : 8;
// The type of fallback content we're showing (see ObjectState())
FallbackType mFallbackType : 8;
uint32_t mRunID;
bool mHasRunID;
// If true, we have opened a channel as the listener and it has reached
// OnStartRequest. Does not get set for channels that are passed directly to
// the plugin listener.
bool mChannelLoaded : 1;
// Whether we are about to call instantiate on our frame. If we aren't,
// SetFrame needs to asynchronously call Instantiate.
bool mInstantiating : 1;
// True when the object is created for an element which the parser has
// created using NS_FROM_PARSER_NETWORK flag. If the element is modified,
// it may lose the flag.
bool mNetworkCreated : 1;
// Used to keep track of whether or not a plugin has been explicitly
// activated by PlayPlugin(). (see ShouldPlay())
bool mActivated : 1;
// Used to keep track of whether or not a plugin is blocked by play-preview.
bool mPlayPreviewCanceled : 1;
// Protects DoStopPlugin from reentry (bug 724781).
bool mIsStopping : 1;
// Protects LoadObject from re-entry
bool mIsLoading : 1;
// For plugin stand-in types (click-to-play, play preview, ...) tracks
// whether content js has tried to access the plugin script object.
bool mScriptRequested : 1;
nsWeakFrame mPrintFrame;
nsRefPtr<nsPluginInstanceOwner> mInstanceOwner;
nsTArray<mozilla::dom::MozPluginParameter> mCachedAttributes;
nsTArray<mozilla::dom::MozPluginParameter> mCachedParameters;
};
#endif