content/base/src/nsFrameLoader.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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 /*
michael@0 7 * Class for managing loading of a subframe (creation of the docshell,
michael@0 8 * handling of loads in it, recursion-checking).
michael@0 9 */
michael@0 10
michael@0 11 #ifndef nsFrameLoader_h_
michael@0 12 #define nsFrameLoader_h_
michael@0 13
michael@0 14 #include "nsIDocShell.h"
michael@0 15 #include "nsStringFwd.h"
michael@0 16 #include "nsIFrameLoader.h"
michael@0 17 #include "nsPoint.h"
michael@0 18 #include "nsSize.h"
michael@0 19 #include "nsIURI.h"
michael@0 20 #include "nsAutoPtr.h"
michael@0 21 #include "nsFrameMessageManager.h"
michael@0 22 #include "mozilla/dom/Element.h"
michael@0 23 #include "mozilla/Attributes.h"
michael@0 24 #include "FrameMetrics.h"
michael@0 25 #include "nsStubMutationObserver.h"
michael@0 26
michael@0 27 class nsIURI;
michael@0 28 class nsSubDocumentFrame;
michael@0 29 class nsView;
michael@0 30 class nsIInProcessContentFrameMessageManager;
michael@0 31 class AutoResetInShow;
michael@0 32 class nsITabParent;
michael@0 33 class nsIDocShellTreeItem;
michael@0 34 class nsIDocShellTreeOwner;
michael@0 35 class mozIApplication;
michael@0 36
michael@0 37 namespace mozilla {
michael@0 38 namespace dom {
michael@0 39 class ContentParent;
michael@0 40 class PBrowserParent;
michael@0 41 class TabParent;
michael@0 42 struct StructuredCloneData;
michael@0 43 }
michael@0 44
michael@0 45 namespace layout {
michael@0 46 class RenderFrameParent;
michael@0 47 }
michael@0 48 }
michael@0 49
michael@0 50 #if defined(MOZ_WIDGET_GTK)
michael@0 51 typedef struct _GtkWidget GtkWidget;
michael@0 52 #endif
michael@0 53 #ifdef MOZ_WIDGET_QT
michael@0 54 class QX11EmbedContainer;
michael@0 55 #endif
michael@0 56
michael@0 57 /**
michael@0 58 * Defines a target configuration for this <browser>'s content
michael@0 59 * document's view. If the content document's actual view
michael@0 60 * doesn't match this nsIContentView, then on paints its pixels
michael@0 61 * are transformed to compensate for the difference.
michael@0 62 *
michael@0 63 * Used to support asynchronous re-paints of content pixels; see
michael@0 64 * nsIContentView.
michael@0 65 */
michael@0 66 class nsContentView MOZ_FINAL : public nsIContentView
michael@0 67 {
michael@0 68 public:
michael@0 69 typedef mozilla::layers::FrameMetrics::ViewID ViewID;
michael@0 70 NS_DECL_ISUPPORTS
michael@0 71 NS_DECL_NSICONTENTVIEW
michael@0 72
michael@0 73 struct ViewConfig {
michael@0 74 ViewConfig()
michael@0 75 : mScrollOffset(0, 0)
michael@0 76 , mXScale(1.0)
michael@0 77 , mYScale(1.0)
michael@0 78 {}
michael@0 79
michael@0 80 // Default copy ctor and operator= are fine
michael@0 81
michael@0 82 bool operator==(const ViewConfig& aOther) const
michael@0 83 {
michael@0 84 return (mScrollOffset == aOther.mScrollOffset &&
michael@0 85 mXScale == aOther.mXScale &&
michael@0 86 mYScale == aOther.mYScale);
michael@0 87 }
michael@0 88
michael@0 89 // This is the scroll offset the <browser> user wishes or expects
michael@0 90 // its enclosed content document to have. "Scroll offset" here
michael@0 91 // means the document pixel at pixel (0,0) within the CSS
michael@0 92 // viewport. If the content document's actual scroll offset
michael@0 93 // doesn't match |mScrollOffset|, the difference is used to define
michael@0 94 // a translation transform when painting the content document.
michael@0 95 nsPoint mScrollOffset;
michael@0 96 // The scale at which the <browser> user wishes to paint its
michael@0 97 // enclosed content document. If content-document layers have a
michael@0 98 // lower or higher resolution than the desired scale, then the
michael@0 99 // ratio is used to define a scale transform when painting the
michael@0 100 // content document.
michael@0 101 float mXScale;
michael@0 102 float mYScale;
michael@0 103 };
michael@0 104
michael@0 105 nsContentView(nsFrameLoader* aFrameLoader, ViewID aScrollId, bool aIsRoot,
michael@0 106 ViewConfig aConfig = ViewConfig())
michael@0 107 : mViewportSize(0, 0)
michael@0 108 , mContentSize(0, 0)
michael@0 109 , mParentScaleX(1.0)
michael@0 110 , mParentScaleY(1.0)
michael@0 111 , mFrameLoader(aFrameLoader)
michael@0 112 , mScrollId(aScrollId)
michael@0 113 , mIsRoot(aIsRoot)
michael@0 114 , mConfig(aConfig)
michael@0 115 {}
michael@0 116
michael@0 117 bool IsRoot() const
michael@0 118 {
michael@0 119 return mIsRoot;
michael@0 120 }
michael@0 121
michael@0 122 ViewID GetId() const
michael@0 123 {
michael@0 124 return mScrollId;
michael@0 125 }
michael@0 126
michael@0 127 ViewConfig GetViewConfig() const
michael@0 128 {
michael@0 129 return mConfig;
michael@0 130 }
michael@0 131
michael@0 132 nsSize mViewportSize;
michael@0 133 nsSize mContentSize;
michael@0 134 float mParentScaleX;
michael@0 135 float mParentScaleY;
michael@0 136
michael@0 137 nsFrameLoader* mFrameLoader; // WEAK
michael@0 138
michael@0 139 private:
michael@0 140 nsresult Update(const ViewConfig& aConfig);
michael@0 141
michael@0 142 ViewID mScrollId;
michael@0 143 bool mIsRoot;
michael@0 144 ViewConfig mConfig;
michael@0 145 };
michael@0 146
michael@0 147
michael@0 148 class nsFrameLoader MOZ_FINAL : public nsIFrameLoader,
michael@0 149 public nsIContentViewManager,
michael@0 150 public nsStubMutationObserver,
michael@0 151 public mozilla::dom::ipc::MessageManagerCallback
michael@0 152 {
michael@0 153 friend class AutoResetInShow;
michael@0 154 typedef mozilla::dom::PBrowserParent PBrowserParent;
michael@0 155 typedef mozilla::dom::TabParent TabParent;
michael@0 156 typedef mozilla::layout::RenderFrameParent RenderFrameParent;
michael@0 157
michael@0 158 protected:
michael@0 159 nsFrameLoader(mozilla::dom::Element* aOwner, bool aNetworkCreated);
michael@0 160
michael@0 161 public:
michael@0 162 ~nsFrameLoader();
michael@0 163
michael@0 164 bool AsyncScrollEnabled() const
michael@0 165 {
michael@0 166 return !!(mRenderMode & RENDER_MODE_ASYNC_SCROLL);
michael@0 167 }
michael@0 168
michael@0 169 static nsFrameLoader* Create(mozilla::dom::Element* aOwner,
michael@0 170 bool aNetworkCreated);
michael@0 171
michael@0 172 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 173 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFrameLoader, nsIFrameLoader)
michael@0 174 NS_DECL_NSIFRAMELOADER
michael@0 175 NS_DECL_NSICONTENTVIEWMANAGER
michael@0 176 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
michael@0 177 NS_HIDDEN_(nsresult) CheckForRecursiveLoad(nsIURI* aURI);
michael@0 178 nsresult ReallyStartLoading();
michael@0 179 void Finalize();
michael@0 180 nsIDocShell* GetExistingDocShell() { return mDocShell; }
michael@0 181 mozilla::dom::EventTarget* GetTabChildGlobalAsEventTarget();
michael@0 182 nsresult CreateStaticClone(nsIFrameLoader* aDest);
michael@0 183
michael@0 184 /**
michael@0 185 * MessageManagerCallback methods that we override.
michael@0 186 */
michael@0 187 virtual bool DoLoadFrameScript(const nsAString& aURL,
michael@0 188 bool aRunInGlobalScope) MOZ_OVERRIDE;
michael@0 189 virtual bool DoSendAsyncMessage(JSContext* aCx,
michael@0 190 const nsAString& aMessage,
michael@0 191 const mozilla::dom::StructuredCloneData& aData,
michael@0 192 JS::Handle<JSObject *> aCpows,
michael@0 193 nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
michael@0 194 virtual bool CheckPermission(const nsAString& aPermission) MOZ_OVERRIDE;
michael@0 195 virtual bool CheckManifestURL(const nsAString& aManifestURL) MOZ_OVERRIDE;
michael@0 196 virtual bool CheckAppHasPermission(const nsAString& aPermission) MOZ_OVERRIDE;
michael@0 197
michael@0 198 /**
michael@0 199 * Called from the layout frame associated with this frame loader;
michael@0 200 * this notifies us to hook up with the widget and view.
michael@0 201 */
michael@0 202 bool Show(int32_t marginWidth, int32_t marginHeight,
michael@0 203 int32_t scrollbarPrefX, int32_t scrollbarPrefY,
michael@0 204 nsSubDocumentFrame* frame);
michael@0 205
michael@0 206 /**
michael@0 207 * Called when the margin properties of the containing frame are changed.
michael@0 208 */
michael@0 209 void MarginsChanged(uint32_t aMarginWidth, uint32_t aMarginHeight);
michael@0 210
michael@0 211 /**
michael@0 212 * Called from the layout frame associated with this frame loader, when
michael@0 213 * the frame is being torn down; this notifies us that out widget and view
michael@0 214 * are going away and we should unhook from them.
michael@0 215 */
michael@0 216 void Hide();
michael@0 217
michael@0 218 nsresult CloneForStatic(nsIFrameLoader* aOriginal);
michael@0 219
michael@0 220 // The guts of an nsIFrameLoaderOwner::SwapFrameLoader implementation. A
michael@0 221 // frame loader owner needs to call this, and pass in the two references to
michael@0 222 // nsRefPtrs for frame loaders that need to be swapped.
michael@0 223 nsresult SwapWithOtherLoader(nsFrameLoader* aOther,
michael@0 224 nsRefPtr<nsFrameLoader>& aFirstToSwap,
michael@0 225 nsRefPtr<nsFrameLoader>& aSecondToSwap);
michael@0 226
michael@0 227 // When IPC is enabled, destroy any associated child process.
michael@0 228 void DestroyChild();
michael@0 229
michael@0 230 /**
michael@0 231 * Return the primary frame for our owning content, or null if it
michael@0 232 * can't be found.
michael@0 233 */
michael@0 234 nsIFrame* GetPrimaryFrameOfOwningContent() const
michael@0 235 {
michael@0 236 return mOwnerContent ? mOwnerContent->GetPrimaryFrame() : nullptr;
michael@0 237 }
michael@0 238
michael@0 239 /**
michael@0 240 * Return the document that owns this, or null if we don't have
michael@0 241 * an owner.
michael@0 242 */
michael@0 243 nsIDocument* GetOwnerDoc() const
michael@0 244 { return mOwnerContent ? mOwnerContent->OwnerDoc() : nullptr; }
michael@0 245
michael@0 246 PBrowserParent* GetRemoteBrowser();
michael@0 247
michael@0 248 /**
michael@0 249 * The "current" render frame is the one on which the most recent
michael@0 250 * remote layer-tree transaction was executed. If no content has
michael@0 251 * been drawn yet, or the remote browser doesn't have any drawn
michael@0 252 * content for whatever reason, return nullptr. The returned render
michael@0 253 * frame has an associated shadow layer tree.
michael@0 254 *
michael@0 255 * Note that the returned render frame might not be a frame
michael@0 256 * constructed for this->GetURL(). This can happen, e.g., if the
michael@0 257 * <browser> was just navigated to a new URL, but hasn't painted the
michael@0 258 * new page yet. A render frame for the previous page may be
michael@0 259 * returned. (In-process <browser> behaves similarly, and this
michael@0 260 * behavior seems desirable.)
michael@0 261 */
michael@0 262 RenderFrameParent* GetCurrentRemoteFrame() const
michael@0 263 {
michael@0 264 return mCurrentRemoteFrame;
michael@0 265 }
michael@0 266
michael@0 267 /**
michael@0 268 * |aFrame| can be null. If non-null, it must be the remote frame
michael@0 269 * on which the most recent layer transaction completed for this's
michael@0 270 * <browser>.
michael@0 271 */
michael@0 272 void SetCurrentRemoteFrame(RenderFrameParent* aFrame)
michael@0 273 {
michael@0 274 mCurrentRemoteFrame = aFrame;
michael@0 275 }
michael@0 276 nsFrameMessageManager* GetFrameMessageManager() { return mMessageManager; }
michael@0 277
michael@0 278 mozilla::dom::Element* GetOwnerContent() { return mOwnerContent; }
michael@0 279 bool ShouldClipSubdocument() { return mClipSubdocument; }
michael@0 280
michael@0 281 bool ShouldClampScrollPosition() { return mClampScrollPosition; }
michael@0 282
michael@0 283 /**
michael@0 284 * Tell this FrameLoader to use a particular remote browser.
michael@0 285 *
michael@0 286 * This will assert if mRemoteBrowser or mCurrentRemoteFrame is non-null. In
michael@0 287 * practice, this means you can't have successfully run TryRemoteBrowser() on
michael@0 288 * this object, which means you can't have called ShowRemoteFrame() or
michael@0 289 * ReallyStartLoading().
michael@0 290 */
michael@0 291 void SetRemoteBrowser(nsITabParent* aTabParent);
michael@0 292
michael@0 293 /**
michael@0 294 * Stashes a detached view on the frame loader. We do this when we're
michael@0 295 * destroying the nsSubDocumentFrame. If the nsSubdocumentFrame is
michael@0 296 * being reframed we'll restore the detached view when it's recreated,
michael@0 297 * otherwise we'll discard the old presentation and set the detached
michael@0 298 * subdoc view to null. aContainerDoc is the document containing the
michael@0 299 * the subdoc frame. This enables us to detect when the containing
michael@0 300 * document has changed during reframe, so we can discard the presentation
michael@0 301 * in that case.
michael@0 302 */
michael@0 303 void SetDetachedSubdocView(nsView* aDetachedView,
michael@0 304 nsIDocument* aContainerDoc);
michael@0 305
michael@0 306 /**
michael@0 307 * Retrieves the detached view and the document containing the view,
michael@0 308 * as set by SetDetachedSubdocView().
michael@0 309 */
michael@0 310 nsView* GetDetachedSubdocView(nsIDocument** aContainerDoc) const;
michael@0 311
michael@0 312 /**
michael@0 313 * Applies a new set of sandbox flags. These are merged with the sandbox
michael@0 314 * flags from our owning content's owning document with a logical OR, this
michael@0 315 * ensures that we can only add restrictions and never remove them.
michael@0 316 */
michael@0 317 void ApplySandboxFlags(uint32_t sandboxFlags);
michael@0 318
michael@0 319 void GetURL(nsString& aURL);
michael@0 320
michael@0 321 private:
michael@0 322
michael@0 323 void SetOwnerContent(mozilla::dom::Element* aContent);
michael@0 324
michael@0 325 bool ShouldUseRemoteProcess();
michael@0 326
michael@0 327 /**
michael@0 328 * Is this a frameloader for a bona fide <iframe mozbrowser> or
michael@0 329 * <iframe mozapp>? (I.e., does the frame return true for
michael@0 330 * nsIMozBrowserFrame::GetReallyIsBrowserOrApp()?)
michael@0 331 */
michael@0 332 bool OwnerIsBrowserOrAppFrame();
michael@0 333
michael@0 334 /**
michael@0 335 * Is this a frameloader for a bona fide <iframe mozapp>? (I.e., does the
michael@0 336 * frame return true for nsIMozBrowserFrame::GetReallyIsApp()?)
michael@0 337 */
michael@0 338 bool OwnerIsAppFrame();
michael@0 339
michael@0 340 /**
michael@0 341 * Is this a frame loader for a bona fide <iframe mozbrowser>?
michael@0 342 */
michael@0 343 bool OwnerIsBrowserFrame();
michael@0 344
michael@0 345 /**
michael@0 346 * Get our owning element's app manifest URL, or return the empty string if
michael@0 347 * our owning element doesn't have an app manifest URL.
michael@0 348 */
michael@0 349 void GetOwnerAppManifestURL(nsAString& aOut);
michael@0 350
michael@0 351 /**
michael@0 352 * Get the app for our frame. This is the app whose manifest is returned by
michael@0 353 * GetOwnerAppManifestURL.
michael@0 354 */
michael@0 355 already_AddRefed<mozIApplication> GetOwnApp();
michael@0 356
michael@0 357 /**
michael@0 358 * Get the app which contains this frame. This is the app associated with
michael@0 359 * the frame element's principal.
michael@0 360 */
michael@0 361 already_AddRefed<mozIApplication> GetContainingApp();
michael@0 362
michael@0 363 /**
michael@0 364 * If we are an IPC frame, set mRemoteFrame. Otherwise, create and
michael@0 365 * initialize mDocShell.
michael@0 366 */
michael@0 367 nsresult MaybeCreateDocShell();
michael@0 368 nsresult EnsureMessageManager();
michael@0 369
michael@0 370 // Properly retrieves documentSize of any subdocument type.
michael@0 371 nsresult GetWindowDimensions(nsRect& aRect);
michael@0 372
michael@0 373 // Updates the subdocument position and size. This gets called only
michael@0 374 // when we have our own in-process DocShell.
michael@0 375 NS_HIDDEN_(nsresult) UpdateBaseWindowPositionAndSize(nsSubDocumentFrame *aIFrame);
michael@0 376 nsresult CheckURILoad(nsIURI* aURI);
michael@0 377 void FireErrorEvent();
michael@0 378 nsresult ReallyStartLoadingInternal();
michael@0 379
michael@0 380 // Return true if remote browser created; nothing else to do
michael@0 381 bool TryRemoteBrowser();
michael@0 382
michael@0 383 // Tell the remote browser that it's now "virtually visible"
michael@0 384 bool ShowRemoteFrame(const nsIntSize& size,
michael@0 385 nsSubDocumentFrame *aFrame = nullptr);
michael@0 386
michael@0 387 bool AddTreeItemToTreeOwner(nsIDocShellTreeItem* aItem,
michael@0 388 nsIDocShellTreeOwner* aOwner,
michael@0 389 int32_t aParentType,
michael@0 390 nsIDocShell* aParentNode);
michael@0 391
michael@0 392 nsIAtom* TypeAttrName() const {
michael@0 393 return mOwnerContent->IsXUL() ? nsGkAtoms::type : nsGkAtoms::mozframetype;
michael@0 394 }
michael@0 395
michael@0 396 // Update the permission manager's app-id refcount based on mOwnerContent's
michael@0 397 // own-or-containing-app.
michael@0 398 void ResetPermissionManagerStatus();
michael@0 399
michael@0 400 nsCOMPtr<nsIDocShell> mDocShell;
michael@0 401 nsCOMPtr<nsIURI> mURIToLoad;
michael@0 402 mozilla::dom::Element* mOwnerContent; // WEAK
michael@0 403
michael@0 404 // Note: this variable must be modified only by ResetPermissionManagerStatus()
michael@0 405 uint32_t mAppIdSentToPermissionManager;
michael@0 406
michael@0 407 public:
michael@0 408 // public because a callback needs these.
michael@0 409 nsRefPtr<nsFrameMessageManager> mMessageManager;
michael@0 410 nsCOMPtr<nsIInProcessContentFrameMessageManager> mChildMessageManager;
michael@0 411 private:
michael@0 412 // Stores the root view of the subdocument while the subdocument is being
michael@0 413 // reframed. Used to restore the presentation after reframing.
michael@0 414 nsView* mDetachedSubdocViews;
michael@0 415 // Stores the containing document of the frame corresponding to this
michael@0 416 // frame loader. This is reference is kept valid while the subframe's
michael@0 417 // presentation is detached and stored in mDetachedSubdocViews. This
michael@0 418 // enables us to detect whether the frame has moved documents during
michael@0 419 // a reframe, so that we know not to restore the presentation.
michael@0 420 nsCOMPtr<nsIDocument> mContainerDocWhileDetached;
michael@0 421
michael@0 422 bool mDepthTooGreat : 1;
michael@0 423 bool mIsTopLevelContent : 1;
michael@0 424 bool mDestroyCalled : 1;
michael@0 425 bool mNeedsAsyncDestroy : 1;
michael@0 426 bool mInSwap : 1;
michael@0 427 bool mInShow : 1;
michael@0 428 bool mHideCalled : 1;
michael@0 429 // True when the object is created for an element which the parser has
michael@0 430 // created using NS_FROM_PARSER_NETWORK flag. If the element is modified,
michael@0 431 // it may lose the flag.
michael@0 432 bool mNetworkCreated : 1;
michael@0 433
michael@0 434 bool mRemoteBrowserShown : 1;
michael@0 435 bool mRemoteFrame : 1;
michael@0 436 bool mClipSubdocument : 1;
michael@0 437 bool mClampScrollPosition : 1;
michael@0 438 bool mRemoteBrowserInitialized : 1;
michael@0 439 bool mObservingOwnerContent : 1;
michael@0 440
michael@0 441 // Backs nsIFrameLoader::{Get,Set}Visible. Visibility state here relates to
michael@0 442 // whether this frameloader's <iframe mozbrowser> is setVisible(true)'ed, and
michael@0 443 // doesn't necessarily correlate with docshell/document visibility.
michael@0 444 bool mVisible : 1;
michael@0 445
michael@0 446 // The ContentParent associated with mRemoteBrowser. This was added as a
michael@0 447 // strong ref in bug 545237, and we're not sure if we can get rid of it.
michael@0 448 nsRefPtr<mozilla::dom::ContentParent> mContentParent;
michael@0 449 RenderFrameParent* mCurrentRemoteFrame;
michael@0 450 TabParent* mRemoteBrowser;
michael@0 451 uint64_t mChildID;
michael@0 452
michael@0 453 // See nsIFrameLoader.idl. Short story, if !(mRenderMode &
michael@0 454 // RENDER_MODE_ASYNC_SCROLL), all the fields below are ignored in
michael@0 455 // favor of what content tells.
michael@0 456 uint32_t mRenderMode;
michael@0 457
michael@0 458 // See nsIFrameLoader.idl. EVENT_MODE_NORMAL_DISPATCH automatically
michael@0 459 // forwards some input events to out-of-process content.
michael@0 460 uint32_t mEventMode;
michael@0 461
michael@0 462 // Indicate if we have sent 'remote-browser-pending'.
michael@0 463 bool mPendingFrameSent;
michael@0 464 };
michael@0 465
michael@0 466 #endif

mercurial