Commit e23ea875 authored by jst%mozilla.jstenback.com's avatar jst%mozilla.jstenback.com
Browse files

Followup changes to bzabarsky's review for bug 296639. Reviews pending, a=drivers@mozilla.org

parent 3c53c8ca
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ class nsIStyleSheet;
class nsIStyleRule;
class nsIViewManager;
class nsIScriptGlobalObject;
class nsPIDOMWindow;
class nsIDOMEvent;
class nsIDeviceContext;
class nsIParser;
@@ -472,6 +473,11 @@ public:
  virtual nsIScriptGlobalObject* GetScriptGlobalObject() const = 0;
  virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;

  /**
   * Return the window containing the document (the outer window).
   */
  virtual nsPIDOMWindow *GetWindow() = 0;

  /**
   * Get the script loader for this document
   */ 
+33 −3
Original line number Diff line number Diff line
@@ -697,6 +697,12 @@ NS_IMPL_RELEASE_USING_AGGREGATOR(nsXPathDocumentTearoff, mDocument)
  // NOTE! nsDocument::operator new() zeroes out all members, so don't
  // bother initializing members to 0.

nsDocument::nsDocument()
  : nsIDocument(),
    mVisible(PR_TRUE)
{
}

nsDocument::~nsDocument()
{
  mInDestructor = PR_TRUE;
@@ -2043,6 +2049,15 @@ nsDocument::GetScriptGlobalObject() const
void
nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
{
#ifdef DEBUG
  {
    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(aScriptGlobalObject));

    NS_ASSERTION(!win || win->IsInnerWindow(),
                 "Script global object must be an inner window!");
  }
#endif

  if (mScriptGlobalObject && !aScriptGlobalObject) {
    // We're detaching from the window.  We need to grab a pointer to
    // our layout history state now.
@@ -2057,6 +2072,18 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
  }
}

nsPIDOMWindow *
nsDocument::GetWindow()
{
  nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(GetScriptGlobalObject()));

  if (!win) {
    return nsnull;
  }

  return win->GetOuterWindow();
}

nsIScriptLoader *
nsDocument::GetScriptLoader()
{
@@ -3037,11 +3064,14 @@ nsDocument::GetDefaultView(nsIDOMAbstractView** aDefaultView)

  if (win) {
    // The default view is our outer window.
    if (!win->IsInnerWindow()) {
      return NS_ERROR_UNEXPECTED;
    nsPIDOMWindow *outer = win->GetOuterWindow();

    if (outer) {
      return CallQueryInterface(outer, aDefaultView);
    }

    return CallQueryInterface(win->GetOuterWindow(), aDefaultView);
    // Fall through here and return null in case our window no longer
    // has an outer window.
  }

  return NS_OK;
+6 −1
Original line number Diff line number Diff line
@@ -450,6 +450,11 @@ public:
  virtual nsIScriptGlobalObject* GetScriptGlobalObject() const;
  virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject);

  /**
   * Return the window containing the document (the outer window).
   */
  virtual nsPIDOMWindow *GetWindow();

  /**
   * Get the script loader for this document
   */
@@ -678,7 +683,7 @@ protected:
    return kNameSpaceID_None;
  };

  nsDocument() : nsIDocument(), mVisible(PR_TRUE) {}
  nsDocument();
  virtual ~nsDocument();

  nsCString mReferrer;
+3 −3
Original line number Diff line number Diff line
@@ -518,7 +518,7 @@ NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget)
  {
    nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aTarget);

    NS_ASSERTION(!win || win == win->GetOuterWindow(),
    NS_ASSERTION(!win || !win->IsInnerWindow(),
                 "Uh, inner window set as event target!");
  }
#endif
@@ -533,7 +533,7 @@ NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget)
  {
    nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aCurrentTarget);

    NS_ASSERTION(!win || win == win->GetOuterWindow(),
    NS_ASSERTION(!win || !win->IsInnerWindow(),
                 "Uh, inner window set as event target!");
  }
#endif
@@ -548,7 +548,7 @@ NS_METHOD nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget)
  {
    nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aOriginalTarget);

    NS_ASSERTION(!win || win == win->GetOuterWindow(),
    NS_ASSERTION(!win || !win->IsInnerWindow(),
                 "Uh, inner window set as event target!");
  }
#endif
+4 −1
Original line number Diff line number Diff line
@@ -1184,9 +1184,12 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject,
      scope = global->GetGlobalJSObject();
    }
  } else {
    nsCOMPtr<nsIDOMWindow> win(do_QueryInterface(aObject));
    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(aObject));
    nsCOMPtr<nsIScriptGlobalObject> global;
    if (win) {
      NS_ASSERTION(win->IsInnerWindow(),
                   "Event listener added to outer window!");

      nsCOMPtr<nsIDOMDocument> domdoc;
      win->GetDocument(getter_AddRefs(domdoc));
      doc = do_QueryInterface(domdoc);
Loading