Commit f62bb24c authored by Johnny Stenback's avatar Johnny Stenback
Browse files

Merging with backout.

parents c3ec60f4 7dfc7675
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ public:
  virtual JSObject *GetGlobalJSObject();
  virtual void OnFinalize(PRUint32 aLangID, void *aScriptGlobal);
  virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
  virtual nsresult SetNewArguments(nsIArray *aArguments);

  // nsIScriptObjectPrincipal methods
  virtual nsIPrincipal* GetPrincipal();
@@ -392,6 +393,13 @@ nsXBLDocGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
    // We don't care...
}

nsresult
nsXBLDocGlobalObject::SetNewArguments(nsIArray *aArguments)
{
  NS_NOTREACHED("waaah!");
  return NS_ERROR_UNEXPECTED;
}

//----------------------------------------------------------------------
//
// nsIScriptObjectPrincipal methods
+8 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ public:
    // nsIScriptGlobalObject methods
    virtual void OnFinalize(PRUint32 aLangID, void *aGlobal);
    virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
    virtual nsresult SetNewArguments(nsIArray *aArguments);

    virtual void *GetScriptGlobal(PRUint32 lang);
    virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID);
@@ -808,6 +809,13 @@ nsXULPDGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
    // We don't care...
}

nsresult
nsXULPDGlobalObject::SetNewArguments(nsIArray *aArguments)
{
    NS_NOTREACHED("waaah!");
    return NS_ERROR_UNEXPECTED;
}

//----------------------------------------------------------------------
//
// nsIScriptObjectPrincipal methods
+3 −26
Original line number Diff line number Diff line
@@ -1376,7 +1376,6 @@ jsval nsDOMClassInfo::sToolbar_id = JSVAL_VOID;
jsval nsDOMClassInfo::sLocationbar_id     = JSVAL_VOID;
jsval nsDOMClassInfo::sPersonalbar_id     = JSVAL_VOID;
jsval nsDOMClassInfo::sStatusbar_id       = JSVAL_VOID;
jsval nsDOMClassInfo::sDialogArguments_id = JSVAL_VOID;
jsval nsDOMClassInfo::sDirectories_id     = JSVAL_VOID;
jsval nsDOMClassInfo::sControllers_id     = JSVAL_VOID;
jsval nsDOMClassInfo::sLength_id          = JSVAL_VOID;
@@ -1572,7 +1571,6 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
  SET_JSVAL_TO_STRING(sLocationbar_id,     cx, "locationbar");
  SET_JSVAL_TO_STRING(sPersonalbar_id,     cx, "personalbar");
  SET_JSVAL_TO_STRING(sStatusbar_id,       cx, "statusbar");
  SET_JSVAL_TO_STRING(sDialogArguments_id, cx, "dialogArguments");
  SET_JSVAL_TO_STRING(sDirectories_id,     cx, "directories");
  SET_JSVAL_TO_STRING(sControllers_id,     cx, "controllers");
  SET_JSVAL_TO_STRING(sLength_id,          cx, "length");
@@ -4324,7 +4322,6 @@ nsDOMClassInfo::ShutDown()
  sLocationbar_id     = JSVAL_VOID;
  sPersonalbar_id     = JSVAL_VOID;
  sStatusbar_id       = JSVAL_VOID;
  sDialogArguments_id = JSVAL_VOID;
  sDirectories_id     = JSVAL_VOID;
  sControllers_id     = JSVAL_VOID;
  sLength_id          = JSVAL_VOID;
@@ -6558,24 +6555,6 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
          return NS_OK;
        }
      }
    } else if (id == sDialogArguments_id &&
               mData == &sClassInfoData[eDOMClassInfo_ModalContentWindow_id]) {
      nsCOMPtr<nsIArray> args;
      ((nsGlobalModalWindow *)win)->GetDialogArguments(getter_AddRefs(args));

      nsIScriptContext *script_cx = win->GetContext();
      if (script_cx) {
        JSAutoSuspendRequest asr(cx);

        // Make nsJSContext::SetProperty()'s magic argument array
        // handling happen.
        rv = script_cx->SetProperty(obj, "dialogArguments", args);
        NS_ENSURE_SUCCESS(rv, rv);

        *objp = obj;
      }

      return NS_OK;
    }
  }

@@ -6592,7 +6571,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
  // binding a name) a new undefined property that's not already
  // defined on our prototype chain. This way we can access this
  // expando w/o ever getting back into XPConnect.
  if ((flags & JSRESOLVE_ASSIGNING) && !(flags & JSRESOLVE_WITH) &&
  if ((flags & JSRESOLVE_ASSIGNING) &&
      !(flags & JSRESOLVE_WITH) &&
      win->IsInnerWindow()) {
    JSObject *realObj;
    wrapper->GetJSObject(&realObj);
@@ -9494,10 +9474,7 @@ nsHTMLPluginObjElementSH::PostCreate(nsIXPConnectWrappedNative *wrapper,
                                     JSContext *cx, JSObject *obj)
{
  if (nsContentUtils::IsSafeToRunScript()) {
#ifdef DEBUG
    nsresult rv =
#endif
      SetupProtoChain(wrapper, cx, obj);
    nsresult rv = SetupProtoChain(wrapper, cx, obj);

    // If SetupProtoChain failed then we're in real trouble. We're about to fail
    // PostCreate but it's more than likely that we handed our (now invalid)
+0 −1
Original line number Diff line number Diff line
@@ -284,7 +284,6 @@ protected:
  static jsval sLocationbar_id;
  static jsval sPersonalbar_id;
  static jsval sStatusbar_id;
  static jsval sDialogArguments_id;
  static jsval sDirectories_id;
  static jsval sControllers_id;
  static jsval sLength_id;
+38 −104
Original line number Diff line number Diff line
@@ -895,7 +895,6 @@ nsGlobalWindow::CleanUp()
  }
  mArguments = nsnull;
  mArgumentsLast = nsnull;
  mArgumentsOrigin = nsnull;

  CleanupCachedXBLHandlers(this);

@@ -2025,12 +2024,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
      }

      if (mArguments) {
        newInnerWindow->DefineArgumentsProperty(mArguments);
        newInnerWindow->mArguments = mArguments;
        newInnerWindow->mArgumentsOrigin = mArgumentsOrigin;

        newInnerWindow->SetNewArguments(mArguments);
        mArguments = nsnull;
        mArgumentsOrigin = nsnull;
      }

      // Give the new inner window our chrome event handler (since it
@@ -2114,10 +2109,9 @@ nsGlobalWindow::SetDocShell(nsIDocShell* aDocShell)

    if (mArguments) { 
      // We got no new document after someone called
      // SetArguments(), drop our reference to the arguments.
      // SetNewArguments(), drop our reference to the arguments.
      mArguments = nsnull;
      mArgumentsLast = nsnull;
      mArgumentsOrigin = nsnull;
      // xxxmarkh - should we also drop mArgumentsLast?
    }

    PRUint32 st_ndx;
@@ -2370,52 +2364,41 @@ nsGlobalWindow::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
}

nsresult
nsGlobalWindow::SetArguments(nsIArray *aArguments, nsIPrincipal *aOrigin)
nsGlobalWindow::SetNewArguments(nsIArray *aArguments)
{
  FORWARD_TO_OUTER(SetArguments, (aArguments, aOrigin),
                   NS_ERROR_NOT_INITIALIZED);

  // Hold on to the arguments so that we can re-set them once the next
  // document is loaded.
  mArguments = aArguments;
  mArgumentsOrigin = aOrigin;

  if (!mIsModalContentWindow) {
    mArgumentsLast = aArguments;
  }

  nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal();
  FORWARD_TO_OUTER(SetNewArguments, (aArguments), NS_ERROR_NOT_INITIALIZED);

  return currentInner ?
    currentInner->DefineArgumentsProperty(aArguments) : NS_OK;
}

nsresult
nsGlobalWindow::DefineArgumentsProperty(nsIArray *aArguments)
{
  JSContext *cx;
  nsIScriptContext *ctx = GetOuterWindowInternal()->mContext;
  NS_ENSURE_TRUE(aArguments && ctx &&
                 (cx = (JSContext *)ctx->GetNativeContext()),
  NS_ENSURE_TRUE(aArguments && mContext &&
                 (cx = (JSContext *)mContext->GetNativeContext()),
                 NS_ERROR_NOT_INITIALIZED);

  if (mIsModalContentWindow) {
    // Modal content windows don't have an "arguments" property, they
    // have a "dialogArguments" property which is handled
    // separately. See nsWindowSH::NewResolve().
  // Note that currentInner may be non-null if someone's doing a
  // window.open with an existing window name.
  nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal();
  
    return NS_OK;
  }
  nsresult rv;

  if (currentInner) {
    PRUint32 langID;
    NS_STID_FOR_ID(langID) {
    void *glob = GetScriptGlobal(langID);
    ctx = GetScriptContext(langID);
      void *glob = currentInner->GetScriptGlobal(langID);
      nsIScriptContext *ctx = GetScriptContext(langID);
      if (glob && ctx) {
      nsresult rv = ctx->SetProperty(glob, "arguments", aArguments);
        if (mIsModalContentWindow) {
          rv = ctx->SetProperty(glob, "dialogArguments", aArguments);
        } else {
          rv = ctx->SetProperty(glob, "arguments", aArguments);
        }
        NS_ENSURE_SUCCESS(rv, rv);
      }
    }
  }

  // Hold on to the arguments so that we can re-set them once the next
  // document is loaded.
  mArguments = aArguments;
  mArgumentsLast = aArguments;

  return NS_OK;
}
@@ -6104,35 +6087,8 @@ nsGlobalWindow::ShowModalDialog(const nsAString& aURI, nsIVariant *aArgs,
  NS_ENSURE_SUCCESS(rv, rv);
  
  if (dlgWin) {
    nsCOMPtr<nsIPrincipal> subjectPrincipal;
    rv = nsContentUtils::GetSecurityManager()->
      GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
    if (NS_FAILED(rv)) {
      return rv;
    }

    PRBool canAccess = PR_TRUE;

    if (subjectPrincipal) {
      nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
        do_QueryInterface(dlgWin);
      nsCOMPtr<nsIPrincipal> dialogPrincipal;

      if (objPrincipal) {
        dialogPrincipal = objPrincipal->GetPrincipal();

        rv = subjectPrincipal->Subsumes(dialogPrincipal, &canAccess);
        NS_ENSURE_SUCCESS(rv, rv);
      } else {
        // Uh, not sure what kind of dialog this is. Prevent access to
        // be on the safe side...

        canAccess = PR_FALSE;
      }
    }

    if (canAccess) {
    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(dlgWin));

    nsPIDOMWindow *inner = win->GetCurrentInnerWindow();

    nsCOMPtr<nsIDOMModalContentWindow> dlgInner(do_QueryInterface(inner));
@@ -6141,7 +6097,6 @@ nsGlobalWindow::ShowModalDialog(const nsAString& aURI, nsIVariant *aArgs,
      dlgInner->GetReturnValue(aRetVal);
    }
  }
  }
  
  return NS_OK;
}
@@ -9068,14 +9023,7 @@ nsGlobalModalWindow::GetDialogArguments(nsIArray **aArguments)
  FORWARD_TO_INNER_MODAL_CONTENT_WINDOW(GetDialogArguments, (aArguments),
                                        NS_ERROR_NOT_INITIALIZED);

  PRBool subsumes = PR_FALSE;
  nsIPrincipal *self = GetPrincipal();
  if (self && NS_SUCCEEDED(self->Subsumes(mArgumentsOrigin, &subsumes)) &&
      subsumes) {
    NS_IF_ADDREF(*aArguments = mArguments);
  } else {
    *aArguments = nsnull;
  }
  *aArguments = mArguments;

  return NS_OK;
}
@@ -9100,20 +9048,6 @@ nsGlobalModalWindow::SetReturnValue(nsIVariant *aRetVal)
  return NS_OK;
}

nsresult
nsGlobalModalWindow::SetNewDocument(nsIDocument *aDocument,
                                    nsISupports *aState,
                                    PRBool aClearScopeHint)
{
  // If we're loading a new document into a modal dialog, clear the
  // return value that was set, if any, by the current document.
  if (aDocument) {
    mReturnValue = nsnull;
  }

  return nsGlobalWindow::SetNewDocument(aDocument, aState, aClearScopeHint);
}

//*****************************************************************************
// nsGlobalWindow: Creator Function (This should go away)
//*****************************************************************************
Loading