Commit e61cc054 authored by Gijs Kruitbosch's avatar Gijs Kruitbosch
Browse files

Bug 1493634 - make docshell responsible for outer window IDs, r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D7702

--HG--
extra : moz-landing-system : lando
parent 3ef88382
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -313,6 +313,7 @@ DecreasePrivateDocShellCount()

nsDocShell::nsDocShell()
  : nsDocLoader()
  , mContentWindowID(NextWindowID())
  , mForcedCharset(nullptr)
  , mParentCharset(nullptr)
  , mTreeOwner(nullptr)
@@ -1286,6 +1287,13 @@ nsDocShell::GetContentViewer(nsIContentViewer** aContentViewer)
  return NS_OK;
}

NS_IMETHODIMP
nsDocShell::GetOuterWindowID(uint64_t *aWindowID)
{
  *aWindowID = mContentWindowID;
  return NS_OK;
}

NS_IMETHODIMP
nsDocShell::SetChromeEventHandler(EventTarget* aChromeEventHandler)
{
@@ -12726,11 +12734,9 @@ nsDocShell::EnsureScriptEnvironment()

  // If our window is modal and we're not opened as chrome, make
  // this window a modal content window.
  mScriptGlobal = NS_NewScriptGlobalObject(mItemType == typeChrome);
  mScriptGlobal = nsGlobalWindowOuter::Create(this, mItemType == typeChrome);
  MOZ_ASSERT(mScriptGlobal);

  mScriptGlobal->SetDocShell(this);

  // Ensure the script object is set up to run script.
  return mScriptGlobal->EnsureScriptEnvironment();
}
+1 −0
Original line number Diff line number Diff line
@@ -936,6 +936,7 @@ private: // data members
  nsCOMPtr<nsIMutableArray> mRefreshURIList;
  nsCOMPtr<nsIMutableArray> mSavedRefreshURIList;
  nsCOMPtr<nsIDOMStorageManager> mSessionStorageManager;
  uint64_t mContentWindowID;
  nsCOMPtr<nsIContentViewer> mContentViewer;
  nsCOMPtr<nsIWidget> mParentWidget;
  RefPtr<mozilla::dom::ChildSHistory> mSessionHistory;
+5 −0
Original line number Diff line number Diff line
@@ -265,6 +265,11 @@ interface nsIDocShell : nsIDocShellTreeItem
   */
  readonly attribute nsIContentViewer contentViewer;

  /**
   * Get the id of the outer window that is or will be in this docshell.
   */
  [infallible] readonly attribute unsigned long long outerWindowID;

  /**
   * This attribute allows chrome to tie in to handle DOM events that may
   * be of interest to chrome.
+8 −16
Original line number Diff line number Diff line
@@ -812,8 +812,8 @@ NewOuterWindowProxy(JSContext *cx, JS::Handle<JSObject*> global, bool isChrome)
//***    nsGlobalWindowOuter: Object Management
//*****************************************************************************

nsGlobalWindowOuter::nsGlobalWindowOuter()
  : nsPIDOMWindowOuter(),
nsGlobalWindowOuter::nsGlobalWindowOuter(uint64_t aWindowID)
  : nsPIDOMWindowOuter(aWindowID),
    mIdleFuzzFactor(0),
    mIdleCallbackIndex(-1),
    mCurrentlyIdle(false),
@@ -7661,12 +7661,14 @@ nsPIDOMWindowOuter::TabGroup()
}

/* static */ already_AddRefed<nsGlobalWindowOuter>
nsGlobalWindowOuter::Create(bool aIsChrome)
nsGlobalWindowOuter::Create(nsIDocShell* aDocShell, bool aIsChrome)
{
  RefPtr<nsGlobalWindowOuter> window = new nsGlobalWindowOuter();
  uint64_t outerWindowID = aDocShell->GetOuterWindowID();
  RefPtr<nsGlobalWindowOuter> window = new nsGlobalWindowOuter(outerWindowID);
  if (aIsChrome) {
    window->mIsChrome = true;
  }
  window->SetDocShell(aDocShell);

  window->InitWasOffline();
  return window.forget();
@@ -7715,15 +7717,7 @@ nsPIDOMWindowOuter::GetDocGroup() const
  return nullptr;
}

// XXX: Can we define this in a header instead of here?
namespace mozilla {
namespace dom {
extern uint64_t
NextWindowID();
} // namespace dom
} // namespace mozilla

nsPIDOMWindowOuter::nsPIDOMWindowOuter()
nsPIDOMWindowOuter::nsPIDOMWindowOuter(uint64_t aWindowID)
  : mFrameElement(nullptr)
  , mDocShell(nullptr)
  , mModalStateDepth(0)
@@ -7738,9 +7732,7 @@ nsPIDOMWindowOuter::nsPIDOMWindowOuter()
  , mDesktopModeViewport(false)
  , mIsRootOuterWindow(false)
  , mInnerWindow(nullptr)
  ,
  // Make sure no actual window ends up with mWindowID == 0
  mWindowID(NextWindowID())
  , mWindowID(aWindowID)
  , mMarkedCCGeneration(0)
  , mServiceWorkersTestingEnabled(false)
  , mLargeAllocStatus(LargeAllocStatus::NONE)
+5 −10
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ public:
    return (nsGlobalWindowOuter *)(mozilla::dom::EventTarget *)supports;
  }

  static already_AddRefed<nsGlobalWindowOuter> Create(bool aIsChrome);
  static already_AddRefed<nsGlobalWindowOuter> Create(nsIDocShell* aDocShell, bool aIsChrome);

  // public methods
  nsPIDOMWindowOuter* GetPrivateParent();
@@ -320,7 +320,6 @@ public:
  // Outer windows only.
  bool WouldReuseInnerWindow(nsIDocument* aNewDocument);

  void SetDocShell(nsIDocShell* aDocShell);
  void DetachFromDocShell();

  virtual nsresult SetNewDocument(nsIDocument *aDocument,
@@ -581,7 +580,6 @@ public:

  nsresult GetPrompter(nsIPrompt** aPrompt) override;
protected:
  explicit nsGlobalWindowOuter();
  nsPIDOMWindowOuter* GetOpenerWindowOuter();
  // Initializes the mWasOffline member variable
  void InitWasOffline();
@@ -831,6 +829,8 @@ protected:
                 nsPIDOMWindowOuter** _retval) override;

private:
  explicit nsGlobalWindowOuter(uint64_t aWindowID);

  /**
   * @param aUrl the URL we intend to load into the window.  If aNavigate is
   *        true, we'll actually load this URL into the window. Otherwise,
@@ -1047,6 +1047,8 @@ private:
                              SecureContextFlags aFlags =
                                SecureContextFlags::eDefault);

  void SetDocShell(nsIDocShell* aDocShell);

  // nsPIDOMWindow{Inner,Outer} should be able to see these helper methods.
  friend class nsPIDOMWindowInner;
  friend class nsPIDOMWindowOuter;
@@ -1258,11 +1260,4 @@ nsGlobalWindowOuter::MaybeClearInnerWindow(nsGlobalWindowInner* aExpectedInner)
  }
}

/* factory function */
inline already_AddRefed<nsGlobalWindowOuter>
NS_NewScriptGlobalObject(bool aIsChrome)
{
  return nsGlobalWindowOuter::Create(aIsChrome);
}

#endif /* nsGlobalWindowOuter_h___ */
Loading