Wed, 31 Dec 2014 06:09:35 +0100
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 | // vim:set et cin sw=2 sts=2: |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * A base class implementing nsIObjectLoadingContent for use by |
michael@0 | 9 | * various content nodes that want to provide plugin/document/image |
michael@0 | 10 | * loading functionality (eg <embed>, <object>, <applet>, etc). |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | #ifndef NSOBJECTLOADINGCONTENT_H_ |
michael@0 | 14 | #define NSOBJECTLOADINGCONTENT_H_ |
michael@0 | 15 | |
michael@0 | 16 | #include "mozilla/Attributes.h" |
michael@0 | 17 | #include "nsImageLoadingContent.h" |
michael@0 | 18 | #include "nsIStreamListener.h" |
michael@0 | 19 | #include "nsIChannelEventSink.h" |
michael@0 | 20 | #include "nsIObjectLoadingContent.h" |
michael@0 | 21 | #include "nsIRunnable.h" |
michael@0 | 22 | #include "nsIThreadInternal.h" |
michael@0 | 23 | #include "nsIFrame.h" |
michael@0 | 24 | #include "nsIFrameLoader.h" |
michael@0 | 25 | |
michael@0 | 26 | class nsAsyncInstantiateEvent; |
michael@0 | 27 | class nsStopPluginRunnable; |
michael@0 | 28 | class AutoSetInstantiatingToFalse; |
michael@0 | 29 | class nsObjectFrame; |
michael@0 | 30 | class nsFrameLoader; |
michael@0 | 31 | class nsXULElement; |
michael@0 | 32 | class nsPluginInstanceOwner; |
michael@0 | 33 | |
michael@0 | 34 | namespace mozilla { |
michael@0 | 35 | namespace dom { |
michael@0 | 36 | template<typename T> class Sequence; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | class nsObjectLoadingContent : public nsImageLoadingContent |
michael@0 | 41 | , public nsIStreamListener |
michael@0 | 42 | , public nsIFrameLoaderOwner |
michael@0 | 43 | , public nsIObjectLoadingContent |
michael@0 | 44 | , public nsIChannelEventSink |
michael@0 | 45 | { |
michael@0 | 46 | friend class AutoSetInstantiatingToFalse; |
michael@0 | 47 | friend class AutoSetLoadingToFalse; |
michael@0 | 48 | friend class CheckPluginStopEvent; |
michael@0 | 49 | friend class nsStopPluginRunnable; |
michael@0 | 50 | friend class nsAsyncInstantiateEvent; |
michael@0 | 51 | |
michael@0 | 52 | public: |
michael@0 | 53 | // This enum's values must be the same as the constants on |
michael@0 | 54 | // nsIObjectLoadingContent |
michael@0 | 55 | enum ObjectType { |
michael@0 | 56 | // Loading, type not yet known. We may be waiting for a channel to open. |
michael@0 | 57 | eType_Loading = TYPE_LOADING, |
michael@0 | 58 | // Content is a *non-svg* image |
michael@0 | 59 | eType_Image = TYPE_IMAGE, |
michael@0 | 60 | // Content is a plugin |
michael@0 | 61 | eType_Plugin = TYPE_PLUGIN, |
michael@0 | 62 | // Content is a subdocument, possibly SVG |
michael@0 | 63 | eType_Document = TYPE_DOCUMENT, |
michael@0 | 64 | // No content loaded (fallback). May be showing alternate content or |
michael@0 | 65 | // a custom error handler - *including* click-to-play dialogs |
michael@0 | 66 | eType_Null = TYPE_NULL |
michael@0 | 67 | }; |
michael@0 | 68 | enum FallbackType { |
michael@0 | 69 | // The content type is not supported (e.g. plugin not installed) |
michael@0 | 70 | eFallbackUnsupported = nsIObjectLoadingContent::PLUGIN_UNSUPPORTED, |
michael@0 | 71 | // Showing alternate content |
michael@0 | 72 | eFallbackAlternate = nsIObjectLoadingContent::PLUGIN_ALTERNATE, |
michael@0 | 73 | // The plugin exists, but is disabled |
michael@0 | 74 | eFallbackDisabled = nsIObjectLoadingContent::PLUGIN_DISABLED, |
michael@0 | 75 | // The plugin is blocklisted and disabled |
michael@0 | 76 | eFallbackBlocklisted = nsIObjectLoadingContent::PLUGIN_BLOCKLISTED, |
michael@0 | 77 | // The plugin is considered outdated, but not disabled |
michael@0 | 78 | eFallbackOutdated = nsIObjectLoadingContent::PLUGIN_OUTDATED, |
michael@0 | 79 | // The plugin has crashed |
michael@0 | 80 | eFallbackCrashed = nsIObjectLoadingContent::PLUGIN_CRASHED, |
michael@0 | 81 | // Suppressed by security policy |
michael@0 | 82 | eFallbackSuppressed = nsIObjectLoadingContent::PLUGIN_SUPPRESSED, |
michael@0 | 83 | // Blocked by content policy |
michael@0 | 84 | eFallbackUserDisabled = nsIObjectLoadingContent::PLUGIN_USER_DISABLED, |
michael@0 | 85 | /// ** All values >= eFallbackClickToPlay are plugin placeholder types |
michael@0 | 86 | /// that would be replaced by a real plugin if activated (PlayPlugin()) |
michael@0 | 87 | /// ** Furthermore, values >= eFallbackClickToPlay and |
michael@0 | 88 | /// <= eFallbackVulnerableNoUpdate are click-to-play types. |
michael@0 | 89 | // The plugin is disabled until the user clicks on it |
michael@0 | 90 | eFallbackClickToPlay = nsIObjectLoadingContent::PLUGIN_CLICK_TO_PLAY, |
michael@0 | 91 | // The plugin is vulnerable (update available) |
michael@0 | 92 | eFallbackVulnerableUpdatable = nsIObjectLoadingContent::PLUGIN_VULNERABLE_UPDATABLE, |
michael@0 | 93 | // The plugin is vulnerable (no update available) |
michael@0 | 94 | eFallbackVulnerableNoUpdate = nsIObjectLoadingContent::PLUGIN_VULNERABLE_NO_UPDATE, |
michael@0 | 95 | // The plugin is disabled and play preview content is displayed until |
michael@0 | 96 | // the extension code enables it by sending the MozPlayPlugin event |
michael@0 | 97 | eFallbackPlayPreview = nsIObjectLoadingContent::PLUGIN_PLAY_PREVIEW |
michael@0 | 98 | }; |
michael@0 | 99 | |
michael@0 | 100 | nsObjectLoadingContent(); |
michael@0 | 101 | virtual ~nsObjectLoadingContent(); |
michael@0 | 102 | |
michael@0 | 103 | NS_DECL_NSIREQUESTOBSERVER |
michael@0 | 104 | NS_DECL_NSISTREAMLISTENER |
michael@0 | 105 | NS_DECL_NSIFRAMELOADEROWNER |
michael@0 | 106 | NS_DECL_NSIOBJECTLOADINGCONTENT |
michael@0 | 107 | NS_DECL_NSICHANNELEVENTSINK |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * Object state. This is a bitmask of NS_EVENT_STATEs epresenting the |
michael@0 | 111 | * current state of the object. |
michael@0 | 112 | */ |
michael@0 | 113 | mozilla::EventStates ObjectState() const; |
michael@0 | 114 | |
michael@0 | 115 | ObjectType Type() const { return mType; } |
michael@0 | 116 | |
michael@0 | 117 | void SetIsNetworkCreated(bool aNetworkCreated) |
michael@0 | 118 | { |
michael@0 | 119 | mNetworkCreated = aNetworkCreated; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | /** |
michael@0 | 123 | * Immediately instantiate a plugin instance. This is a no-op if mType != |
michael@0 | 124 | * eType_Plugin or a plugin is already running. |
michael@0 | 125 | * |
michael@0 | 126 | * aIsLoading indicates that we are in the loading code, and we can bypass |
michael@0 | 127 | * the mIsLoading check. |
michael@0 | 128 | */ |
michael@0 | 129 | nsresult InstantiatePluginInstance(bool aIsLoading = false); |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Notify this class the document state has changed |
michael@0 | 133 | * Called by nsDocument so we may suspend plugins in inactive documents) |
michael@0 | 134 | */ |
michael@0 | 135 | void NotifyOwnerDocumentActivityChanged(); |
michael@0 | 136 | |
michael@0 | 137 | /** |
michael@0 | 138 | * When a plug-in is instantiated, it can create a scriptable |
michael@0 | 139 | * object that the page wants to interact with. We expose this |
michael@0 | 140 | * object by placing it on the prototype chain of our element, |
michael@0 | 141 | * between the element itself and its most-derived DOM prototype. |
michael@0 | 142 | * |
michael@0 | 143 | * SetupProtoChain handles actually inserting the plug-in |
michael@0 | 144 | * scriptable object into the proto chain if needed. |
michael@0 | 145 | * |
michael@0 | 146 | * DoNewResolve is a hook that allows us to find out when the web |
michael@0 | 147 | * page is looking up a property name on our object and make sure |
michael@0 | 148 | * that our plug-in, if any, is instantiated. |
michael@0 | 149 | */ |
michael@0 | 150 | // Helper for WebIDL node wrapping |
michael@0 | 151 | void SetupProtoChain(JSContext* aCx, JS::Handle<JSObject*> aObject); |
michael@0 | 152 | |
michael@0 | 153 | // Remove plugin from protochain |
michael@0 | 154 | void TeardownProtoChain(); |
michael@0 | 155 | |
michael@0 | 156 | // Helper for WebIDL newResolve |
michael@0 | 157 | bool DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject, |
michael@0 | 158 | JS::Handle<jsid> aId, |
michael@0 | 159 | JS::MutableHandle<JSPropertyDescriptor> aDesc); |
michael@0 | 160 | // Helper for WebIDL enumeration |
michael@0 | 161 | void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& /* unused */, |
michael@0 | 162 | mozilla::ErrorResult& aRv); |
michael@0 | 163 | |
michael@0 | 164 | // WebIDL API |
michael@0 | 165 | nsIDocument* GetContentDocument(); |
michael@0 | 166 | void GetActualType(nsAString& aType) const |
michael@0 | 167 | { |
michael@0 | 168 | CopyUTF8toUTF16(mContentType, aType); |
michael@0 | 169 | } |
michael@0 | 170 | uint32_t DisplayedType() const |
michael@0 | 171 | { |
michael@0 | 172 | return mType; |
michael@0 | 173 | } |
michael@0 | 174 | uint32_t GetContentTypeForMIMEType(const nsAString& aMIMEType) |
michael@0 | 175 | { |
michael@0 | 176 | return GetTypeOfContent(NS_ConvertUTF16toUTF8(aMIMEType)); |
michael@0 | 177 | } |
michael@0 | 178 | void PlayPlugin(mozilla::ErrorResult& aRv) |
michael@0 | 179 | { |
michael@0 | 180 | aRv = PlayPlugin(); |
michael@0 | 181 | } |
michael@0 | 182 | void Reload(bool aClearActivation, mozilla::ErrorResult& aRv) |
michael@0 | 183 | { |
michael@0 | 184 | aRv = Reload(aClearActivation); |
michael@0 | 185 | } |
michael@0 | 186 | bool Activated() const |
michael@0 | 187 | { |
michael@0 | 188 | return mActivated; |
michael@0 | 189 | } |
michael@0 | 190 | nsIURI* GetSrcURI() const |
michael@0 | 191 | { |
michael@0 | 192 | return mURI; |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | /** |
michael@0 | 196 | * The default state that this plugin would be without manual activation. |
michael@0 | 197 | * @returns PLUGIN_ACTIVE if the default state would be active. |
michael@0 | 198 | */ |
michael@0 | 199 | uint32_t DefaultFallbackType(); |
michael@0 | 200 | |
michael@0 | 201 | uint32_t PluginFallbackType() const |
michael@0 | 202 | { |
michael@0 | 203 | return mFallbackType; |
michael@0 | 204 | } |
michael@0 | 205 | bool HasRunningPlugin() const |
michael@0 | 206 | { |
michael@0 | 207 | return !!mInstanceOwner; |
michael@0 | 208 | } |
michael@0 | 209 | void CancelPlayPreview(mozilla::ErrorResult& aRv) |
michael@0 | 210 | { |
michael@0 | 211 | aRv = CancelPlayPreview(); |
michael@0 | 212 | } |
michael@0 | 213 | void SwapFrameLoaders(nsXULElement& aOtherOwner, mozilla::ErrorResult& aRv) |
michael@0 | 214 | { |
michael@0 | 215 | aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); |
michael@0 | 216 | } |
michael@0 | 217 | void LegacyCall(JSContext* aCx, JS::Handle<JS::Value> aThisVal, |
michael@0 | 218 | const mozilla::dom::Sequence<JS::Value>& aArguments, |
michael@0 | 219 | JS::MutableHandle<JS::Value> aRetval, |
michael@0 | 220 | mozilla::ErrorResult& aRv); |
michael@0 | 221 | |
michael@0 | 222 | protected: |
michael@0 | 223 | /** |
michael@0 | 224 | * Begins loading the object when called |
michael@0 | 225 | * |
michael@0 | 226 | * Attributes of |this| QI'd to nsIContent will be inspected, depending on |
michael@0 | 227 | * the node type. This function currently assumes it is a <applet>, |
michael@0 | 228 | * <object>, or <embed> tag. |
michael@0 | 229 | * |
michael@0 | 230 | * The instantiated plugin depends on: |
michael@0 | 231 | * - The URI (<embed src>, <object data>) |
michael@0 | 232 | * - The type 'hint' (type attribute) |
michael@0 | 233 | * - The mime type returned by opening the URI |
michael@0 | 234 | * - Enabled plugins claiming the ultimate mime type |
michael@0 | 235 | * - The capabilities returned by GetCapabilities |
michael@0 | 236 | * - The classid attribute, if eSupportClassID is among the capabilities |
michael@0 | 237 | * |
michael@0 | 238 | * If eAllowPluginSkipChannel is true, we may skip opening the URI if our |
michael@0 | 239 | * type hint points to a valid plugin, deferring that responsibility to the |
michael@0 | 240 | * plugin. |
michael@0 | 241 | * Similarly, if no URI is provided, but a type hint for a valid plugin is |
michael@0 | 242 | * present, that plugin will be instantiated |
michael@0 | 243 | * |
michael@0 | 244 | * Otherwise a request to that URI is made and the type sent by the server |
michael@0 | 245 | * is used to find a suitable handler, EXCEPT when: |
michael@0 | 246 | * - The type hint refers to a *supported* plugin, in which case that |
michael@0 | 247 | * plugin will be instantiated regardless of the server provided type |
michael@0 | 248 | * - The server returns a binary-stream type, and our type hint refers to |
michael@0 | 249 | * a valid non-document type, we will use the type hint |
michael@0 | 250 | * |
michael@0 | 251 | * @param aNotify If we should send notifications. If false, content |
michael@0 | 252 | * loading may be deferred while appropriate frames are |
michael@0 | 253 | * created |
michael@0 | 254 | * @param aForceLoad If we should reload this content (and re-attempt the |
michael@0 | 255 | * channel open) even if our parameters did not change |
michael@0 | 256 | */ |
michael@0 | 257 | nsresult LoadObject(bool aNotify, |
michael@0 | 258 | bool aForceLoad = false); |
michael@0 | 259 | |
michael@0 | 260 | enum Capabilities { |
michael@0 | 261 | eSupportImages = 1u << 0, // Images are supported (imgILoader) |
michael@0 | 262 | eSupportPlugins = 1u << 1, // Plugins are supported (nsIPluginHost) |
michael@0 | 263 | eSupportDocuments = 1u << 2, // Documents are supported |
michael@0 | 264 | // (nsIDocumentLoaderFactory) |
michael@0 | 265 | // This flag always includes SVG |
michael@0 | 266 | eSupportSVG = 1u << 3, // SVG is supported (image/svg+xml) |
michael@0 | 267 | eSupportClassID = 1u << 4, // The classid attribute is supported |
michael@0 | 268 | |
michael@0 | 269 | // If possible to get a *plugin* type from the type attribute *or* file |
michael@0 | 270 | // extension, we can use that type and begin loading the plugin before |
michael@0 | 271 | // opening a channel. |
michael@0 | 272 | // A side effect of this is if the channel fails, the plugin is still |
michael@0 | 273 | // running. |
michael@0 | 274 | eAllowPluginSkipChannel = 1u << 5 |
michael@0 | 275 | }; |
michael@0 | 276 | |
michael@0 | 277 | /** |
michael@0 | 278 | * Returns the list of capabilities this content node supports. This is a |
michael@0 | 279 | * bitmask consisting of flags from the Capabilities enum. |
michael@0 | 280 | * |
michael@0 | 281 | * The default implementation supports all types but not |
michael@0 | 282 | * eSupportClassID or eAllowPluginSkipChannel |
michael@0 | 283 | */ |
michael@0 | 284 | virtual uint32_t GetCapabilities() const; |
michael@0 | 285 | |
michael@0 | 286 | /** |
michael@0 | 287 | * Destroys all loaded documents/plugins and releases references |
michael@0 | 288 | */ |
michael@0 | 289 | void DestroyContent(); |
michael@0 | 290 | |
michael@0 | 291 | static void Traverse(nsObjectLoadingContent *tmp, |
michael@0 | 292 | nsCycleCollectionTraversalCallback &cb); |
michael@0 | 293 | |
michael@0 | 294 | void CreateStaticClone(nsObjectLoadingContent* aDest) const; |
michael@0 | 295 | |
michael@0 | 296 | void DoStopPlugin(nsPluginInstanceOwner* aInstanceOwner, bool aDelayedStop, |
michael@0 | 297 | bool aForcedReentry = false); |
michael@0 | 298 | |
michael@0 | 299 | nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, |
michael@0 | 300 | nsIContent* aBindingParent, |
michael@0 | 301 | bool aCompileEventHandler); |
michael@0 | 302 | void UnbindFromTree(bool aDeep = true, |
michael@0 | 303 | bool aNullParent = true); |
michael@0 | 304 | |
michael@0 | 305 | private: |
michael@0 | 306 | |
michael@0 | 307 | // Object parameter changes returned by UpdateObjectParameters |
michael@0 | 308 | enum ParameterUpdateFlags { |
michael@0 | 309 | eParamNoChange = 0, |
michael@0 | 310 | // Parameters that potentially affect the channel changed |
michael@0 | 311 | // - mOriginalURI, mOriginalContentType |
michael@0 | 312 | eParamChannelChanged = 1u << 0, |
michael@0 | 313 | // Parameters that affect displayed content changed |
michael@0 | 314 | // - mURI, mContentType, mType, mBaseURI |
michael@0 | 315 | eParamStateChanged = 1u << 1, |
michael@0 | 316 | // The effective content type changed, independant of object type. This |
michael@0 | 317 | // can happen when changing from Loading -> Final type, but doesn't |
michael@0 | 318 | // necessarily happen when changing between object types. E.g., if a PDF |
michael@0 | 319 | // handler was installed between the last load of this object and now, we |
michael@0 | 320 | // might change from eType_Document -> eType_Plugin without changing |
michael@0 | 321 | // ContentType |
michael@0 | 322 | eParamContentTypeChanged = 1u << 2 |
michael@0 | 323 | }; |
michael@0 | 324 | |
michael@0 | 325 | /** |
michael@0 | 326 | * Loads fallback content with the specified FallbackType |
michael@0 | 327 | * |
michael@0 | 328 | * @param aType FallbackType value for type of fallback we're loading |
michael@0 | 329 | * @param aNotify Send notifications and events. If false, caller is |
michael@0 | 330 | * responsible for doing so |
michael@0 | 331 | */ |
michael@0 | 332 | void LoadFallback(FallbackType aType, bool aNotify); |
michael@0 | 333 | |
michael@0 | 334 | /** |
michael@0 | 335 | * Internal version of LoadObject that should only be used by this class |
michael@0 | 336 | * aLoadingChannel is passed by the LoadObject call from OnStartRequest, |
michael@0 | 337 | * primarily for sanity-preservation |
michael@0 | 338 | */ |
michael@0 | 339 | nsresult LoadObject(bool aNotify, |
michael@0 | 340 | bool aForceLoad, |
michael@0 | 341 | nsIRequest *aLoadingChannel); |
michael@0 | 342 | |
michael@0 | 343 | /** |
michael@0 | 344 | * Introspects the object and sets the following member variables: |
michael@0 | 345 | * - mOriginalContentType : This is the type attribute on the element |
michael@0 | 346 | * - mOriginalURI : The src or data attribute on the element |
michael@0 | 347 | * - mURI : The final URI, considering mChannel if |
michael@0 | 348 | * mChannelLoaded is set |
michael@0 | 349 | * - mContentType : The final content type, considering mChannel if |
michael@0 | 350 | * mChannelLoaded is set |
michael@0 | 351 | * - mBaseURI : The object's base URI, which may be set by the |
michael@0 | 352 | * object (codebase attribute) |
michael@0 | 353 | * - mType : The type the object is determined to be based |
michael@0 | 354 | * on the above |
michael@0 | 355 | * |
michael@0 | 356 | * NOTE The class assumes that mType is the currently loaded type at various |
michael@0 | 357 | * points, so the caller of this function must take the appropriate |
michael@0 | 358 | * actions to ensure this |
michael@0 | 359 | * |
michael@0 | 360 | * NOTE This function does not perform security checks, only determining the |
michael@0 | 361 | * requested type and parameters of the object. |
michael@0 | 362 | * |
michael@0 | 363 | * @param aJavaURI Specify that the URI will be consumed by java, which |
michael@0 | 364 | * changes codebase parsing and URI construction. Used |
michael@0 | 365 | * internally. |
michael@0 | 366 | * |
michael@0 | 367 | * @return Returns a bitmask of ParameterUpdateFlags values |
michael@0 | 368 | */ |
michael@0 | 369 | ParameterUpdateFlags UpdateObjectParameters(bool aJavaURI = false); |
michael@0 | 370 | |
michael@0 | 371 | /** |
michael@0 | 372 | * Queue a CheckPluginStopEvent and track it in mPendingCheckPluginStopEvent |
michael@0 | 373 | */ |
michael@0 | 374 | void QueueCheckPluginStopEvent(); |
michael@0 | 375 | |
michael@0 | 376 | void NotifyContentObjectWrapper(); |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * Opens the channel pointed to by mURI into mChannel. |
michael@0 | 380 | */ |
michael@0 | 381 | nsresult OpenChannel(); |
michael@0 | 382 | |
michael@0 | 383 | /** |
michael@0 | 384 | * Closes and releases references to mChannel and, if opened, mFinalListener |
michael@0 | 385 | */ |
michael@0 | 386 | nsresult CloseChannel(); |
michael@0 | 387 | |
michael@0 | 388 | /** |
michael@0 | 389 | * If this object is allowed to play plugin content, or if it would display |
michael@0 | 390 | * click-to-play instead. |
michael@0 | 391 | * NOTE that this does not actually check if the object is a loadable plugin |
michael@0 | 392 | * NOTE This ignores the current activated state. The caller should check this if appropriate. |
michael@0 | 393 | */ |
michael@0 | 394 | bool ShouldPlay(FallbackType &aReason, bool aIgnoreCurrentType); |
michael@0 | 395 | |
michael@0 | 396 | /* |
michael@0 | 397 | * Helper to check if mBaseURI can be used by java as a codebase |
michael@0 | 398 | */ |
michael@0 | 399 | bool CheckJavaCodebase(); |
michael@0 | 400 | |
michael@0 | 401 | /** |
michael@0 | 402 | * Helper to check if our current URI passes policy |
michael@0 | 403 | * |
michael@0 | 404 | * @param aContentPolicy [out] The result of the content policy decision |
michael@0 | 405 | * |
michael@0 | 406 | * @return true if call succeeded and NS_CP_ACCEPTED(*aContentPolicy) |
michael@0 | 407 | */ |
michael@0 | 408 | bool CheckLoadPolicy(int16_t *aContentPolicy); |
michael@0 | 409 | |
michael@0 | 410 | /** |
michael@0 | 411 | * Helper to check if the object passes process policy. Assumes we have a |
michael@0 | 412 | * final determined type. |
michael@0 | 413 | * |
michael@0 | 414 | * @param aContentPolicy [out] The result of the content policy decision |
michael@0 | 415 | * |
michael@0 | 416 | * @return true if call succeeded and NS_CP_ACCEPTED(*aContentPolicy) |
michael@0 | 417 | */ |
michael@0 | 418 | bool CheckProcessPolicy(int16_t *aContentPolicy); |
michael@0 | 419 | |
michael@0 | 420 | /** |
michael@0 | 421 | * Checks whether the given type is a supported document type |
michael@0 | 422 | * |
michael@0 | 423 | * NOTE Does not take content policy or capabilities into account |
michael@0 | 424 | */ |
michael@0 | 425 | bool IsSupportedDocument(const nsCString& aType); |
michael@0 | 426 | |
michael@0 | 427 | /** |
michael@0 | 428 | * Gets the plugin instance and creates a plugin stream listener, assigning |
michael@0 | 429 | * it to mFinalListener |
michael@0 | 430 | */ |
michael@0 | 431 | bool MakePluginListener(); |
michael@0 | 432 | |
michael@0 | 433 | /** |
michael@0 | 434 | * Unloads all content and resets the object to a completely unloaded state |
michael@0 | 435 | * |
michael@0 | 436 | * NOTE Calls StopPluginInstance() and may spin the event loop |
michael@0 | 437 | * |
michael@0 | 438 | * @param aResetState Reset the object type to 'loading' and destroy channel |
michael@0 | 439 | * as well |
michael@0 | 440 | */ |
michael@0 | 441 | void UnloadObject(bool aResetState = true); |
michael@0 | 442 | |
michael@0 | 443 | /** |
michael@0 | 444 | * Notifies document observes about a new type/state of this object. |
michael@0 | 445 | * Triggers frame construction as needed. mType must be set correctly when |
michael@0 | 446 | * this method is called. This method is cheap if the type and state didn't |
michael@0 | 447 | * actually change. |
michael@0 | 448 | * |
michael@0 | 449 | * @param aSync If a synchronous frame construction is required. If false, |
michael@0 | 450 | * the construction may either be sync or async. |
michael@0 | 451 | * @param aNotify if false, only need to update the state of our element. |
michael@0 | 452 | */ |
michael@0 | 453 | void NotifyStateChanged(ObjectType aOldType, |
michael@0 | 454 | mozilla::EventStates aOldState, |
michael@0 | 455 | bool aSync, bool aNotify); |
michael@0 | 456 | |
michael@0 | 457 | /** |
michael@0 | 458 | * Returns a ObjectType value corresponding to the type of content we would |
michael@0 | 459 | * support the given MIME type as, taking capabilities and plugin state |
michael@0 | 460 | * into account |
michael@0 | 461 | * |
michael@0 | 462 | * NOTE this does not consider whether the content would be suppressed by |
michael@0 | 463 | * click-to-play or other content policy checks |
michael@0 | 464 | */ |
michael@0 | 465 | ObjectType GetTypeOfContent(const nsCString& aMIMEType); |
michael@0 | 466 | |
michael@0 | 467 | /** |
michael@0 | 468 | * Gets the frame that's associated with this content node. |
michael@0 | 469 | * Does not flush. |
michael@0 | 470 | */ |
michael@0 | 471 | nsObjectFrame* GetExistingFrame(); |
michael@0 | 472 | |
michael@0 | 473 | // Helper class for SetupProtoChain |
michael@0 | 474 | class SetupProtoChainRunner MOZ_FINAL : public nsIRunnable |
michael@0 | 475 | { |
michael@0 | 476 | public: |
michael@0 | 477 | NS_DECL_ISUPPORTS |
michael@0 | 478 | |
michael@0 | 479 | SetupProtoChainRunner(nsIScriptContext* scriptContext, |
michael@0 | 480 | nsObjectLoadingContent* aContent); |
michael@0 | 481 | |
michael@0 | 482 | NS_IMETHOD Run() MOZ_OVERRIDE; |
michael@0 | 483 | |
michael@0 | 484 | private: |
michael@0 | 485 | nsCOMPtr<nsIScriptContext> mContext; |
michael@0 | 486 | // We store an nsIObjectLoadingContent because we can |
michael@0 | 487 | // unambiguously refcount that. |
michael@0 | 488 | nsRefPtr<nsIObjectLoadingContent> mContent; |
michael@0 | 489 | }; |
michael@0 | 490 | |
michael@0 | 491 | // Utility getter for getting our nsNPAPIPluginInstance in a safe way. |
michael@0 | 492 | nsresult ScriptRequestPluginInstance(JSContext* aCx, |
michael@0 | 493 | nsNPAPIPluginInstance** aResult); |
michael@0 | 494 | |
michael@0 | 495 | // Utility method for getting our plugin JSObject |
michael@0 | 496 | static nsresult GetPluginJSObject(JSContext *cx, |
michael@0 | 497 | JS::Handle<JSObject*> obj, |
michael@0 | 498 | nsNPAPIPluginInstance *plugin_inst, |
michael@0 | 499 | JS::MutableHandle<JSObject*> plugin_obj, |
michael@0 | 500 | JS::MutableHandle<JSObject*> plugin_proto); |
michael@0 | 501 | |
michael@0 | 502 | // The final listener for mChannel (uriloader, pluginstreamlistener, etc.) |
michael@0 | 503 | nsCOMPtr<nsIStreamListener> mFinalListener; |
michael@0 | 504 | |
michael@0 | 505 | // Frame loader, for content documents we load. |
michael@0 | 506 | nsRefPtr<nsFrameLoader> mFrameLoader; |
michael@0 | 507 | |
michael@0 | 508 | // Track if we have a pending AsyncInstantiateEvent |
michael@0 | 509 | nsCOMPtr<nsIRunnable> mPendingInstantiateEvent; |
michael@0 | 510 | |
michael@0 | 511 | // Tracks if we have a pending CheckPluginStopEvent |
michael@0 | 512 | nsCOMPtr<nsIRunnable> mPendingCheckPluginStopEvent; |
michael@0 | 513 | |
michael@0 | 514 | // The content type of our current load target, updated by |
michael@0 | 515 | // UpdateObjectParameters(). Takes the channel's type into account once |
michael@0 | 516 | // opened. |
michael@0 | 517 | // |
michael@0 | 518 | // May change if a channel is opened, does not imply a loaded state |
michael@0 | 519 | nsCString mContentType; |
michael@0 | 520 | |
michael@0 | 521 | // The content type 'hint' provided by the element's type attribute. May |
michael@0 | 522 | // or may not be used as a final type |
michael@0 | 523 | nsCString mOriginalContentType; |
michael@0 | 524 | |
michael@0 | 525 | // The channel that's currently being loaded. If set, but mChannelLoaded is |
michael@0 | 526 | // false, has not yet reached OnStartRequest |
michael@0 | 527 | nsCOMPtr<nsIChannel> mChannel; |
michael@0 | 528 | |
michael@0 | 529 | // The URI of the current content. |
michael@0 | 530 | // May change as we open channels and encounter redirects - does not imply |
michael@0 | 531 | // a loaded type |
michael@0 | 532 | nsCOMPtr<nsIURI> mURI; |
michael@0 | 533 | |
michael@0 | 534 | // The original URI obtained from inspecting the element (codebase, and |
michael@0 | 535 | // src/data). May differ from mURI due to redirects |
michael@0 | 536 | nsCOMPtr<nsIURI> mOriginalURI; |
michael@0 | 537 | |
michael@0 | 538 | // The baseURI used for constructing mURI, and used by some plugins (java) |
michael@0 | 539 | // as a root for other resource requests. |
michael@0 | 540 | nsCOMPtr<nsIURI> mBaseURI; |
michael@0 | 541 | |
michael@0 | 542 | |
michael@0 | 543 | |
michael@0 | 544 | // Type of the currently-loaded content. |
michael@0 | 545 | ObjectType mType : 8; |
michael@0 | 546 | // The type of fallback content we're showing (see ObjectState()) |
michael@0 | 547 | FallbackType mFallbackType : 8; |
michael@0 | 548 | |
michael@0 | 549 | // If true, we have opened a channel as the listener and it has reached |
michael@0 | 550 | // OnStartRequest. Does not get set for channels that are passed directly to |
michael@0 | 551 | // the plugin listener. |
michael@0 | 552 | bool mChannelLoaded : 1; |
michael@0 | 553 | |
michael@0 | 554 | // Whether we are about to call instantiate on our frame. If we aren't, |
michael@0 | 555 | // SetFrame needs to asynchronously call Instantiate. |
michael@0 | 556 | bool mInstantiating : 1; |
michael@0 | 557 | |
michael@0 | 558 | // True when the object is created for an element which the parser has |
michael@0 | 559 | // created using NS_FROM_PARSER_NETWORK flag. If the element is modified, |
michael@0 | 560 | // it may lose the flag. |
michael@0 | 561 | bool mNetworkCreated : 1; |
michael@0 | 562 | |
michael@0 | 563 | // Used to keep track of whether or not a plugin has been explicitly |
michael@0 | 564 | // activated by PlayPlugin(). (see ShouldPlay()) |
michael@0 | 565 | bool mActivated : 1; |
michael@0 | 566 | |
michael@0 | 567 | // Used to keep track of whether or not a plugin is blocked by play-preview. |
michael@0 | 568 | bool mPlayPreviewCanceled : 1; |
michael@0 | 569 | |
michael@0 | 570 | // Protects DoStopPlugin from reentry (bug 724781). |
michael@0 | 571 | bool mIsStopping : 1; |
michael@0 | 572 | |
michael@0 | 573 | // Protects LoadObject from re-entry |
michael@0 | 574 | bool mIsLoading : 1; |
michael@0 | 575 | |
michael@0 | 576 | // For plugin stand-in types (click-to-play, play preview, ...) tracks |
michael@0 | 577 | // whether content js has tried to access the plugin script object. |
michael@0 | 578 | bool mScriptRequested : 1; |
michael@0 | 579 | |
michael@0 | 580 | nsWeakFrame mPrintFrame; |
michael@0 | 581 | |
michael@0 | 582 | nsRefPtr<nsPluginInstanceOwner> mInstanceOwner; |
michael@0 | 583 | }; |
michael@0 | 584 | |
michael@0 | 585 | #endif |