зеркало из https://github.com/mozilla/pjs.git
Followup changes to bzabarsky's review for bug 296639. Reviews pending, a=drivers@mozilla.org
This commit is contained in:
Родитель
5f41f1a8d3
Коммит
0d8b79a0bf
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -188,17 +188,14 @@ GetDocumentOuterWindow(nsIDocument *aDocument)
|
|||
}
|
||||
|
||||
static nsIDocument *
|
||||
GetInnerDocument(nsISupports *aWindow)
|
||||
GetDocumentFromWindow(nsIDOMWindow *aWindow)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aWindow);
|
||||
nsPIDOMWindow *innerWin;
|
||||
nsIDocument *doc = nsnull;
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
|
||||
if (win && (innerWin = win->GetCurrentInnerWindow())) {
|
||||
nsCOMPtr<nsIDocument> tmp =
|
||||
do_QueryInterface(innerWin->GetExtantDocument());
|
||||
|
||||
doc = tmp;
|
||||
if (win) {
|
||||
doc = do_QueryInterface(win->GetExtantDocument());
|
||||
}
|
||||
|
||||
return doc;
|
||||
|
@ -830,7 +827,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
|
|||
if (focusedWindow) {
|
||||
focusedWindow->Focus();
|
||||
|
||||
nsCOMPtr<nsIDocument> document = GetInnerDocument(focusedWindow);
|
||||
nsCOMPtr<nsIDocument> document = GetDocumentFromWindow(focusedWindow);
|
||||
|
||||
if (document) {
|
||||
nsIPresShell *shell = document->GetShellAt(0);
|
||||
|
@ -1637,7 +1634,7 @@ nsEventStateManager::ChangeTextSize(PRInt32 change)
|
|||
rootWindow->GetContent(getter_AddRefs(contentWindow));
|
||||
if(!contentWindow) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDocument *doc = GetInnerDocument(contentWindow);
|
||||
nsIDocument *doc = GetDocumentFromWindow(contentWindow);
|
||||
if(!doc) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIPresShell *presShell = doc->GetShellAt(0);
|
||||
|
|
|
@ -3436,16 +3436,16 @@ nsGenericHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
|
|||
nsCOMPtr<nsIDocShell> doc_shell;
|
||||
mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> win(do_GetInterface(doc_shell));
|
||||
nsCOMPtr<nsPIDOMWindow> piwin(do_QueryInterface(win));
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_GetInterface(doc_shell));
|
||||
|
||||
if (piwin && piwin->IsInnerWindow()) {
|
||||
// We got an inner window here somehow, this just should not happen.
|
||||
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
if (!win) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return CallQueryInterface(piwin->GetOuterWindow(), aContentWindow);
|
||||
NS_ASSERTION(win->IsOuterWindow(),
|
||||
"Uh, this window should always be an outer window!");
|
||||
|
||||
return CallQueryInterface(win, aContentWindow);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
#include "nsIDOMComment.h"
|
||||
#include "nsIDOMDOMImplementation.h"
|
||||
#include "nsIDOMDocumentType.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMHTMLFormElement.h"
|
||||
#include "nsDOMString.h"
|
||||
#include "nsIStreamListener.h"
|
||||
|
@ -1915,7 +1915,7 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
|
|||
nsCOMPtr<nsIDOMDocument> kungFuDeathGrip =
|
||||
do_QueryInterface((nsIHTMLDocument*)this);
|
||||
|
||||
rv = mScriptGlobalObject->SetNewDocument(kungFuDeathGrip, PR_FALSE,
|
||||
rv = mScriptGlobalObject->SetNewDocument((nsDocument *)this, PR_FALSE,
|
||||
PR_FALSE);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -2774,7 +2774,7 @@ nsHTMLDocument::GetSelection(nsAString& aReturn)
|
|||
consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get());
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(mScriptGlobalObject));
|
||||
nsIDOMWindow *window = GetWindow();
|
||||
NS_ENSURE_TRUE(window, NS_OK);
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
|
@ -3522,7 +3522,7 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
|
|||
if (!editSession)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(mScriptGlobalObject));
|
||||
nsIDOMWindow *window = GetWindow();
|
||||
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||
|
||||
if (aDesignMode.LowerCaseEqualsLiteral("on") && !mEditingIsOn) {
|
||||
|
@ -3837,7 +3837,7 @@ nsHTMLDocument::ExecCommand(const nsAString & commandID,
|
|||
if (!cmdMgr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mScriptGlobalObject);
|
||||
nsIDOMWindow *window = GetWindow();
|
||||
if (!window)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -3908,7 +3908,7 @@ nsHTMLDocument::QueryCommandEnabled(const nsAString & commandID,
|
|||
if (!cmdMgr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mScriptGlobalObject);
|
||||
nsIDOMWindow *window = GetWindow();
|
||||
if (!window)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -3939,7 +3939,7 @@ nsHTMLDocument::QueryCommandIndeterm(const nsAString & commandID,
|
|||
if (!cmdMgr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mScriptGlobalObject);
|
||||
nsIDOMWindow *window = GetWindow();
|
||||
if (!window)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -3981,7 +3981,7 @@ nsHTMLDocument::QueryCommandState(const nsAString & commandID, PRBool *_retval)
|
|||
if (!cmdMgr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mScriptGlobalObject);
|
||||
nsIDOMWindow *window = GetWindow();
|
||||
if (!window)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -4071,7 +4071,7 @@ nsHTMLDocument::QueryCommandValue(const nsAString & commandID,
|
|||
if (!cmdMgr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mScriptGlobalObject);
|
||||
nsIDOMWindow *window = GetWindow();
|
||||
if (!window)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
|
|
@ -141,7 +141,8 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLPrototypeBinding* aBinding,
|
|||
// concrete base class. We need to alter the object so that our concrete class is interposed
|
||||
// between the object and its base class. We become the new base class of the object, and the
|
||||
// object's old base class becomes the new class' base class.
|
||||
rv = aBinding->InitClass(mClassName, aContext, (void *) object, aTargetClassObject);
|
||||
rv = aBinding->InitClass(mClassName, jscontext, global, object,
|
||||
aTargetClassObject);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
@ -172,10 +173,12 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding)
|
|||
|
||||
nsIScriptContext *context = globalObject->GetContext();
|
||||
NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY);
|
||||
JSObject *global = globalObject->GetGlobalJSObject();
|
||||
|
||||
void* classObject;
|
||||
nsresult rv = aBinding->InitClass(mClassName, context,
|
||||
globalObject->GetGlobalJSObject(),
|
||||
nsresult rv = aBinding->InitClass(mClassName,
|
||||
(JSContext *)context->GetNativeContext(),
|
||||
global, global,
|
||||
&classObject);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
|
|
@ -734,23 +734,16 @@ nsXBLPrototypeBinding::GetImmediateChild(nsIAtom* aTag)
|
|||
|
||||
nsresult
|
||||
nsXBLPrototypeBinding::InitClass(const nsCString& aClassName,
|
||||
nsIScriptContext * aContext,
|
||||
void * aScriptObject, void ** aClassObject)
|
||||
JSContext * aContext, JSObject * aGlobal,
|
||||
JSObject * aScriptObject,
|
||||
void ** aClassObject)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aClassObject);
|
||||
|
||||
*aClassObject = nsnull;
|
||||
|
||||
JSContext* cx = (JSContext*)aContext->GetNativeContext();
|
||||
JSObject* scriptObject = (JSObject*) aScriptObject;
|
||||
JSObject* tmp, *global = scriptObject;
|
||||
|
||||
while ((tmp = ::JS_GetParent(cx, global))) {
|
||||
global = tmp;
|
||||
}
|
||||
|
||||
return nsXBLBinding::DoInitJSClass(cx, global, scriptObject, aClassName,
|
||||
aClassObject);
|
||||
return nsXBLBinding::DoInitJSClass(aContext, aGlobal, aScriptObject,
|
||||
aClassName, aClassObject);
|
||||
}
|
||||
|
||||
nsIContent*
|
||||
|
|
|
@ -97,8 +97,10 @@ public:
|
|||
nsXBLProtoImplAnonymousMethod* GetDestructor();
|
||||
nsresult SetDestructor(nsXBLProtoImplAnonymousMethod* aDestructor);
|
||||
|
||||
nsresult InitClass(const nsCString& aClassName, nsIScriptContext * aContext, void * aScriptObject, void ** aClassObject);
|
||||
|
||||
nsresult InitClass(const nsCString& aClassName, JSContext * aContext,
|
||||
JSObject * aGlobal, JSObject * aScriptObject,
|
||||
void ** aClassObject);
|
||||
|
||||
nsresult ConstructInterfaceTable(const nsAString& aImpls);
|
||||
|
||||
void SetImplementation(nsXBLProtoImpl* aImpl) { mImplementation = aImpl; }
|
||||
|
|
|
@ -404,10 +404,13 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver,
|
|||
// if the focused window was found get our script global object from
|
||||
// that.
|
||||
if (focusedWin) {
|
||||
NS_ASSERTION(isXULKey, "We should only use the focused window for "
|
||||
"XUL key handlers!");
|
||||
nsCOMPtr<nsPIDOMWindow> piWin(do_QueryInterface(focusedWin));
|
||||
|
||||
if (piWin && piWin->GetCurrentInnerWindow()) {
|
||||
if (piWin) {
|
||||
piWin = piWin->GetCurrentInnerWindow();
|
||||
NS_ENSURE_TRUE(piWin, NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
boundGlobal = do_QueryInterface(piWin->GetPrivateRoot());
|
||||
|
|
|
@ -100,9 +100,23 @@ public:
|
|||
|
||||
PRBool HasMutationListeners(PRUint32 aMutationEventType) const
|
||||
{
|
||||
const nsPIDOMWindow *win = GetCurrentInnerWindow();
|
||||
const nsPIDOMWindow *win;
|
||||
|
||||
if (IsOuterWindow()) {
|
||||
win = GetCurrentInnerWindow();
|
||||
|
||||
if (!win) {
|
||||
NS_ERROR("No current inner window available!");
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
} else {
|
||||
if (!mOuterWindow) {
|
||||
NS_ERROR("HasMutationListeners() called on orphan inner window!");
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!win) {
|
||||
win = this;
|
||||
}
|
||||
|
||||
|
@ -111,9 +125,23 @@ public:
|
|||
|
||||
void SetMutationListeners(PRUint32 aType)
|
||||
{
|
||||
nsPIDOMWindow *win = GetCurrentInnerWindow();
|
||||
nsPIDOMWindow *win;
|
||||
|
||||
if (IsOuterWindow()) {
|
||||
win = GetCurrentInnerWindow();
|
||||
|
||||
if (!win) {
|
||||
NS_ERROR("No inner window available to set mutation bits on!");
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!mOuterWindow) {
|
||||
NS_ERROR("HasMutationListeners() called on orphan inner window!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!win) {
|
||||
win = this;
|
||||
}
|
||||
|
||||
|
@ -133,20 +161,31 @@ public:
|
|||
// one doesn't for security reasons.
|
||||
nsIDOMElement* GetFrameElementInternal() const
|
||||
{
|
||||
if (IsInnerWindow()) {
|
||||
if (mOuterWindow) {
|
||||
return mOuterWindow->GetFrameElementInternal();
|
||||
}
|
||||
|
||||
NS_ASSERTION(!IsInnerWindow(),
|
||||
"GetFrameElementInternal() called on orphan inner window");
|
||||
|
||||
return mFrameElement;
|
||||
}
|
||||
|
||||
void SetFrameElementInternal(nsIDOMElement *aFrameElement)
|
||||
{
|
||||
if (IsInnerWindow()) {
|
||||
mOuterWindow->SetFrameElementInternal(aFrameElement);
|
||||
if (IsOuterWindow()) {
|
||||
mFrameElement = aFrameElement;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mFrameElement = aFrameElement;
|
||||
if (!mOuterWindow) {
|
||||
NS_ERROR("frameElement set on inner window with no outer!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mOuterWindow->SetFrameElementInternal(aFrameElement);
|
||||
}
|
||||
|
||||
PRBool IsLoadingOrRunningTimeout() const
|
||||
|
@ -163,9 +202,23 @@ public:
|
|||
// Check whether a document is currently loading
|
||||
PRBool IsLoading() const
|
||||
{
|
||||
const nsPIDOMWindow *win = GetCurrentInnerWindow();
|
||||
const nsPIDOMWindow *win;
|
||||
|
||||
if (IsOuterWindow()) {
|
||||
win = GetCurrentInnerWindow();
|
||||
|
||||
if (!win) {
|
||||
NS_ERROR("No current inner window available!");
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
} else {
|
||||
if (!mOuterWindow) {
|
||||
NS_ERROR("IsLoading() called on orphan inner window!");
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!win) {
|
||||
win = this;
|
||||
}
|
||||
|
||||
|
@ -174,9 +227,23 @@ public:
|
|||
|
||||
PRBool IsHandlingResizeEvent() const
|
||||
{
|
||||
const nsPIDOMWindow *win = GetCurrentInnerWindow();
|
||||
const nsPIDOMWindow *win;
|
||||
|
||||
if (IsOuterWindow()) {
|
||||
win = GetCurrentInnerWindow();
|
||||
|
||||
if (!win) {
|
||||
NS_ERROR("No current inner window available!");
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
} else {
|
||||
if (!mOuterWindow) {
|
||||
NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!");
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (!win) {
|
||||
win = this;
|
||||
}
|
||||
|
||||
|
@ -200,7 +267,7 @@ public:
|
|||
|
||||
nsPIDOMWindow *GetOuterWindow()
|
||||
{
|
||||
return mOuterWindow ? mOuterWindow : this;
|
||||
return mIsInnerWindow ? mOuterWindow : this;
|
||||
}
|
||||
|
||||
nsPIDOMWindow *GetCurrentInnerWindow() const
|
||||
|
@ -210,7 +277,7 @@ public:
|
|||
|
||||
PRBool IsInnerWindow() const
|
||||
{
|
||||
return mOuterWindow != nsnull;
|
||||
return mIsInnerWindow;
|
||||
}
|
||||
|
||||
PRBool IsOuterWindow() const
|
||||
|
@ -219,10 +286,15 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
// The nsPIDOMWindow constructor. The aOuterWindow argument should
|
||||
// be null if and only if the created window itself is an outer
|
||||
// window. In all other cases aOuterWindow should be the outer
|
||||
// window for the inner window that is being created.
|
||||
nsPIDOMWindow(nsPIDOMWindow *aOuterWindow)
|
||||
: mFrameElement(nsnull), mRunningTimeout(nsnull), mMutationBits(0),
|
||||
mIsDocumentLoaded(PR_FALSE), mIsHandlingResizeEvent(PR_FALSE),
|
||||
mInnerWindow(nsnull), mOuterWindow(aOuterWindow)
|
||||
mIsInnerWindow(aOuterWindow != nsnull), mInnerWindow(nsnull),
|
||||
mOuterWindow(aOuterWindow)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -243,6 +315,7 @@ protected:
|
|||
|
||||
PRPackedBool mIsDocumentLoaded;
|
||||
PRPackedBool mIsHandlingResizeEvent;
|
||||
PRPackedBool mIsInnerWindow;
|
||||
|
||||
// And these are the references between inner and outer windows.
|
||||
nsPIDOMWindow *mInnerWindow;
|
||||
|
|
|
@ -337,7 +337,10 @@ public:
|
|||
virtual void SetGCOnDestruction(PRBool aGCOnDestruction) = 0;
|
||||
|
||||
/**
|
||||
* Initialize DOM classes on aGlobalObj
|
||||
* Initialize DOM classes on aGlobalObj, always call
|
||||
* WillInitializeContext() before calling InitContext(), and always
|
||||
* call DidInitializeContext() when a context is fully
|
||||
* (successfully) initialized.
|
||||
*/
|
||||
virtual nsresult InitClasses(JSObject *aGlobalObj) = 0;
|
||||
|
||||
|
|
|
@ -394,6 +394,18 @@ static const char kDOMStringBundleURL[] =
|
|||
// NOTE: DEFAULT_SCRIPTABLE_FLAGS and DOM_DEFAULT_SCRIPTABLE_FLAGS
|
||||
// are defined in nsIDOMClassInfo.h.
|
||||
|
||||
#define WINDOW_SCRIPTABLE_FLAGS \
|
||||
(nsIXPCScriptable::WANT_GETPROPERTY | \
|
||||
nsIXPCScriptable::WANT_SETPROPERTY | \
|
||||
nsIXPCScriptable::WANT_PRECREATE | \
|
||||
nsIXPCScriptable::WANT_FINALIZE | \
|
||||
nsIXPCScriptable::WANT_ADDPROPERTY | \
|
||||
nsIXPCScriptable::WANT_DELPROPERTY | \
|
||||
nsIXPCScriptable::WANT_ENUMERATE | \
|
||||
nsIXPCScriptable::WANT_EQUALITY | \
|
||||
nsIXPCScriptable::WANT_OUTER_OBJECT | \
|
||||
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
|
||||
|
||||
#define NODE_SCRIPTABLE_FLAGS \
|
||||
((DOM_DEFAULT_SCRIPTABLE_FLAGS | \
|
||||
nsIXPCScriptable::WANT_PRECREATE | \
|
||||
|
@ -480,16 +492,7 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
|||
|
||||
NS_DEFINE_CLASSINFO_DATA(Window, nsWindowSH,
|
||||
DEFAULT_SCRIPTABLE_FLAGS |
|
||||
nsIXPCScriptable::WANT_GETPROPERTY |
|
||||
nsIXPCScriptable::WANT_SETPROPERTY |
|
||||
nsIXPCScriptable::WANT_PRECREATE |
|
||||
nsIXPCScriptable::WANT_FINALIZE |
|
||||
nsIXPCScriptable::WANT_ADDPROPERTY |
|
||||
nsIXPCScriptable::WANT_DELPROPERTY |
|
||||
nsIXPCScriptable::WANT_ENUMERATE |
|
||||
nsIXPCScriptable::WANT_EQUALITY |
|
||||
nsIXPCScriptable::WANT_OUTER_OBJECT |
|
||||
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
|
||||
WINDOW_SCRIPTABLE_FLAGS)
|
||||
|
||||
// Don't allow modifications to Location.prototype
|
||||
NS_DEFINE_CLASSINFO_DATA(Location, nsLocationSH,
|
||||
|
@ -789,15 +792,7 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
|||
// DOM Chrome Window class.
|
||||
NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsWindowSH,
|
||||
DEFAULT_SCRIPTABLE_FLAGS |
|
||||
nsIXPCScriptable::WANT_GETPROPERTY |
|
||||
nsIXPCScriptable::WANT_SETPROPERTY |
|
||||
nsIXPCScriptable::WANT_NEWRESOLVE |
|
||||
nsIXPCScriptable::WANT_PRECREATE |
|
||||
nsIXPCScriptable::WANT_FINALIZE |
|
||||
nsIXPCScriptable::WANT_ADDPROPERTY |
|
||||
nsIXPCScriptable::WANT_DELPROPERTY |
|
||||
nsIXPCScriptable::WANT_ENUMERATE |
|
||||
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
|
||||
WINDOW_SCRIPTABLE_FLAGS)
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(CSSRGBColor, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
|
@ -1305,9 +1300,8 @@ nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
|
|||
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
|
||||
nsresult rv = sXPConnect->WrapNative(cx, scope, native, aIID,
|
||||
getter_AddRefs(holder));
|
||||
nsresult rv = sXPConnect->WrapNative(cx, GetGlobalJSObject(cx, scope),
|
||||
native, aIID, getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
JSObject* obj = nsnull;
|
||||
|
@ -3158,8 +3152,8 @@ nsDOMClassInfo::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
|
||||
if ((mode_type == JSACC_WATCH ||
|
||||
mode_type == JSACC_PROTO ||
|
||||
mode_type == JSACC_PARENT)
|
||||
&& sSecMan) {
|
||||
mode_type == JSACC_PARENT) &&
|
||||
sSecMan) {
|
||||
|
||||
JSObject *real_obj = nsnull;
|
||||
nsresult rv = wrapper->GetJSObject(&real_obj);
|
||||
|
@ -3683,8 +3677,7 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
|
|||
|
||||
if (result) {
|
||||
jsval v;
|
||||
nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), result,
|
||||
NS_GET_IID(nsISupports), &v);
|
||||
nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), &v);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(jsstr),
|
||||
|
@ -3863,7 +3856,14 @@ nsWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
// child frame, wrap the child frame without doing a security
|
||||
// check and return.
|
||||
|
||||
rv = WrapNative(cx, obj, frame, NS_GET_IID(nsIDOMWindow), vp);
|
||||
nsGlobalWindow *frameWin = (nsGlobalWindow *)frame.get();
|
||||
nsGlobalWindow *frameInnerWin =
|
||||
frameWin->GetCurrentInnerWindowInternal();
|
||||
|
||||
NS_ASSERTION(frameInnerWin, "No inner window in frame window!");
|
||||
|
||||
rv = WrapNative(cx, frameInnerWin->GetGlobalJSObject(), frame,
|
||||
NS_GET_IID(nsIDOMWindow), vp);
|
||||
}
|
||||
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
|
@ -4111,7 +4111,7 @@ nsWindowSH::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
JSObject *innerObj;
|
||||
if (innerWin && (innerObj = innerWin->GetGlobalJSObject())) {
|
||||
#ifdef DEBUG_SH_FORWARDING
|
||||
printf(" --- Forwarding add to inner window %p\n", (void *)innerWin);
|
||||
printf(" --- Forwarding del to inner window %p\n", (void *)innerWin);
|
||||
#endif
|
||||
|
||||
// Forward the del to the inner object
|
||||
|
@ -4194,8 +4194,8 @@ BaseStubConstructor(const nsGlobalNameStruct *name_struct, JSContext *cx,
|
|||
return rv;
|
||||
}
|
||||
|
||||
rv = nsDOMGenericSH::WrapNative(cx, GetGlobalJSObject(cx, obj), native,
|
||||
NS_GET_IID(nsISupports), rval);
|
||||
rv = nsDOMGenericSH::WrapNative(cx, obj, native, NS_GET_IID(nsISupports),
|
||||
rval);
|
||||
|
||||
return NS_SUCCEEDED(rv) ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
|
@ -4918,7 +4918,7 @@ NS_DOMClassInfo_PreserveWrapper(nsIXPConnectWrappedNative *aWrapper)
|
|||
|
||||
// static
|
||||
nsresult
|
||||
nsWindowSH::GlobalResolve(nsIScriptGlobalObject *global, JSContext *cx,
|
||||
nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
||||
JSObject *obj, JSString *str, PRUint32 flags,
|
||||
PRBool *did_resolve)
|
||||
{
|
||||
|
@ -5239,7 +5239,18 @@ nsWindowSH::GlobalResolve(nsIScriptGlobalObject *global, JSContext *cx,
|
|||
|
||||
prop_val = OBJECT_TO_JSVAL(prop_obj);
|
||||
} else {
|
||||
rv = WrapNative(cx, obj, native, NS_GET_IID(nsISupports), &prop_val);
|
||||
JSObject *scope;
|
||||
|
||||
if (aWin->IsOuterWindow()) {
|
||||
nsGlobalWindow *inner = aWin->GetCurrentInnerWindowInternal();
|
||||
NS_ENSURE_TRUE(inner, NS_ERROR_UNEXPECTED);
|
||||
|
||||
scope = inner->GetGlobalJSObject();
|
||||
} else {
|
||||
scope = aWin->GetGlobalJSObject();
|
||||
}
|
||||
|
||||
rv = WrapNative(cx, scope, native, NS_GET_IID(nsISupports), &prop_val);
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -5258,7 +5269,7 @@ nsWindowSH::GlobalResolve(nsIScriptGlobalObject *global, JSContext *cx,
|
|||
do_CreateInstance(name_struct->mCID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsIScriptContext *context = global->GetContext();
|
||||
nsIScriptContext *context = aWin->GetContext();
|
||||
NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
|
||||
|
||||
rv = nameset->InitializeNameSet(context);
|
||||
|
@ -5310,9 +5321,9 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
// GetDocument() on the outer window. This will create a
|
||||
// synthetic about:blank document, and an inner window which may
|
||||
// be reused by the actual document being loaded into this outer
|
||||
// window. This way properties defined on the window while the
|
||||
// document before the document load stated will be visible to
|
||||
// the document once it's loaded, assuming same origin etc.
|
||||
// window. This way properties defined on the window before the
|
||||
// document load started will be visible to the document once
|
||||
// it's loaded, assuming same origin etc.
|
||||
nsIScriptContext *scx = win->GetContextInternal();
|
||||
|
||||
if (scx && scx->IsContextInitialized()) {
|
||||
|
@ -5321,6 +5332,10 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
|
||||
// Grab the new inner window.
|
||||
innerWin = win->GetCurrentInnerWindowInternal();
|
||||
|
||||
if (!innerWin) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5602,12 +5617,11 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
}
|
||||
|
||||
if (!scope) {
|
||||
scope = obj;
|
||||
wrapper->GetJSObject(&scope);
|
||||
}
|
||||
|
||||
jsval v;
|
||||
rv = WrapNative(cx, GetGlobalJSObject(cx, scope), location,
|
||||
NS_GET_IID(nsIDOMLocation), &v);
|
||||
rv = WrapNative(cx, scope, location, NS_GET_IID(nsIDOMLocation), &v);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
sDoSecurityCheckInAddProperty = PR_FALSE;
|
||||
|
@ -5677,13 +5691,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
rv = WrapNative(cx, obj, document, NS_GET_IID(nsIDOMDocument), &v);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str), v, nsnull,
|
||||
nsnull, JSPROP_READONLY | JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*objp = obj;
|
||||
// The PostCreate hook for the document will handle defining the
|
||||
// property *objp = obj;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -5691,6 +5700,7 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
if (id == sWindow_id) {
|
||||
// window should *always* be the outer window object.
|
||||
win = win->GetOuterWindowInternal();
|
||||
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str),
|
||||
|
@ -5763,9 +5773,15 @@ nsWindowSH::Equality(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
|||
|
||||
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
|
||||
|
||||
NS_ASSERTION(win->IsOuterWindow(),
|
||||
"Inner window detected in Equality hook!");
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> other = do_QueryWrappedNative(other_wrapper);
|
||||
|
||||
if (other) {
|
||||
NS_ASSERTION(other->IsOuterWindow(),
|
||||
"Inner window detected in Equality hook!");
|
||||
|
||||
*bp = win->GetOuterWindow() == other->GetOuterWindow();
|
||||
}
|
||||
|
||||
|
@ -5776,10 +5792,22 @@ NS_IMETHODIMP
|
|||
nsWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, JSObject * *_retval)
|
||||
{
|
||||
nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper);
|
||||
nsGlobalWindow *win =
|
||||
nsGlobalWindow::FromWrapper(wrapper)->GetOuterWindowInternal();
|
||||
|
||||
// Always return the outer window.
|
||||
*_retval = win->GetOuterWindowInternal()->GetGlobalJSObject();
|
||||
if (win) {
|
||||
// Return the outer window.
|
||||
|
||||
*_retval = win->GetGlobalJSObject();
|
||||
} else {
|
||||
// If we no longer have an outer window. No code should ever be
|
||||
// running on a window w/o an outer, which means this hook should
|
||||
// never be called when we have no outer. But just in case, return
|
||||
// null to prevent leaking an inner window to code in a different
|
||||
// window.
|
||||
|
||||
*_retval = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -5839,8 +5867,6 @@ NS_IMETHODIMP
|
|||
nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
||||
JSObject **parentObj)
|
||||
{
|
||||
// XXXjst: Add code that asserts the the scope is an inner window
|
||||
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(nativeObj));
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
|
||||
|
@ -6401,8 +6427,7 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (array_item) {
|
||||
rv = WrapNative(cx, GetGlobalJSObject(cx, obj), array_item,
|
||||
NS_GET_IID(nsISupports), vp);
|
||||
rv = WrapNative(cx, obj, array_item, NS_GET_IID(nsISupports), vp);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = NS_SUCCESS_I_DID_SOMETHING;
|
||||
|
@ -6440,8 +6465,7 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (item) {
|
||||
rv = WrapNative(cx, GetGlobalJSObject(cx, obj), item,
|
||||
NS_GET_IID(nsISupports), vp);
|
||||
rv = WrapNative(cx, obj, item, NS_GET_IID(nsISupports), vp);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = NS_SUCCESS_I_DID_SOMETHING;
|
||||
|
@ -6701,8 +6725,7 @@ nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
|
||||
jsval v;
|
||||
|
||||
rv = WrapNative(cx, GetGlobalJSObject(cx, obj), location,
|
||||
NS_GET_IID(nsIDOMLocation), &v);
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), &v);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
sDoSecurityCheckInAddProperty = PR_FALSE;
|
||||
|
@ -6809,8 +6832,7 @@ nsDocumentSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
rv = location->SetHref(nsDependentJSString(val));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = WrapNative(cx, GetGlobalJSObject(cx, obj), location,
|
||||
NS_GET_IID(nsIDOMLocation), vp);
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp);
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
}
|
||||
|
@ -6854,8 +6876,7 @@ nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
if (SameCOMIdentity(doc, currentDoc)) {
|
||||
jsval winVal;
|
||||
|
||||
nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), win,
|
||||
NS_GET_IID(nsIDOMWindow), &winVal);
|
||||
nsresult rv = WrapNative(cx, obj, win, NS_GET_IID(nsIDOMWindow), &winVal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(doc_str, "document");
|
||||
|
@ -6956,8 +6977,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
rv = WrapNative(cx, GetGlobalJSObject(cx, obj), retval,
|
||||
NS_GET_IID(nsIDOMDocument), rval);
|
||||
rv = WrapNative(cx, obj, retval, NS_GET_IID(nsIDOMDocument), rval);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to wrap native!");
|
||||
|
||||
return NS_SUCCEEDED(rv);
|
||||
|
@ -7701,8 +7721,7 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
|||
if (result) {
|
||||
// Wrap result, result can be either an element or a list of
|
||||
// elements
|
||||
nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), result,
|
||||
NS_GET_IID(nsISupports), vp);
|
||||
nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp);
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
|
||||
|
@ -7716,8 +7735,7 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
|||
form->GetElementAt(n, getter_AddRefs(control));
|
||||
|
||||
if (control) {
|
||||
nsresult rv = WrapNative(cx, GetGlobalJSObject(cx, obj), control,
|
||||
NS_GET_IID(nsISupports), vp);
|
||||
nsresult rv = WrapNative(cx, obj, control, NS_GET_IID(nsISupports), vp);
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
}
|
||||
|
@ -7822,8 +7840,7 @@ nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
|||
|
||||
options->Item(n, getter_AddRefs(node));
|
||||
|
||||
rv = WrapNative(cx, GetGlobalJSObject(cx, obj), node,
|
||||
NS_GET_IID(nsIDOMNode), vp);
|
||||
rv = WrapNative(cx, obj, node, NS_GET_IID(nsIDOMNode), vp);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
|
@ -8417,8 +8434,7 @@ nsHTMLPluginObjElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = sXPConnect->WrapNative(cx, GetGlobalJSObject(cx, obj), pi, *iid,
|
||||
getter_AddRefs(holder));
|
||||
rv = sXPConnect->WrapNative(cx, obj, pi, *iid, getter_AddRefs(holder));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
JSObject* ifaceObj;
|
||||
|
|
|
@ -53,6 +53,7 @@ class nsIDOMNode;
|
|||
class nsIDOMNodeList;
|
||||
class nsIDOMDocument;
|
||||
class nsIHTMLDocument;
|
||||
class nsGlobalWindow;
|
||||
|
||||
struct nsDOMClassInfoData;
|
||||
|
||||
|
@ -412,7 +413,7 @@ protected:
|
|||
{
|
||||
}
|
||||
|
||||
static nsresult GlobalResolve(nsIScriptGlobalObject *aGlobal, JSContext *cx,
|
||||
static nsresult GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
||||
JSObject *obj, JSString *str, PRUint32 flags,
|
||||
PRBool *did_resolve);
|
||||
|
||||
|
|
|
@ -409,13 +409,13 @@ nsFocusController::GetControllerForCommand(const char * aCommand,
|
|||
*_retval = nsnull;
|
||||
|
||||
nsCOMPtr<nsIControllers> controllers;
|
||||
nsCOMPtr<nsIController> controller;
|
||||
|
||||
GetControllers(getter_AddRefs(controllers));
|
||||
if(controllers) {
|
||||
nsCOMPtr<nsIController> controller;
|
||||
controllers->GetControllerForCommand(aCommand, getter_AddRefs(controller));
|
||||
if(controller) {
|
||||
*_retval = controller;
|
||||
NS_ADDREF(*_retval);
|
||||
controller.swap(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -441,12 +441,10 @@ nsFocusController::GetControllerForCommand(const char * aCommand,
|
|||
nsCOMPtr<nsIControllers> controllers2;
|
||||
domWindow->GetControllers(getter_AddRefs(controllers2));
|
||||
if(controllers2) {
|
||||
nsCOMPtr<nsIController> controller;
|
||||
controllers2->GetControllerForCommand(aCommand,
|
||||
getter_AddRefs(controller));
|
||||
if(controller) {
|
||||
*_retval = controller;
|
||||
NS_ADDREF(*_retval);
|
||||
controller.swap(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -118,6 +118,15 @@ class WindowStateHolder;
|
|||
// doing. Security wise this is very sensitive code. --
|
||||
// jst@netscape.com
|
||||
|
||||
// nsGlobalWindow inherits PRCList for maintaining a list of all inner
|
||||
// widows still in memory for any given outer window. This list is
|
||||
// needed to ensure that mOuterWindow doesn't end up dangling. The
|
||||
// nature of PRCList means that the window itself is always in the
|
||||
// list, and an outer window's list will also contain all inner window
|
||||
// objects that are still in memory (and in reality all inner window
|
||||
// object's lists also contain its outer and all other inner windows
|
||||
// belonging to the same outer window, but that's an unimportant
|
||||
// side effect of inheriting PRCList).
|
||||
|
||||
class nsGlobalWindow : public nsPIDOMWindow,
|
||||
public nsIScriptGlobalObject,
|
||||
|
@ -231,7 +240,7 @@ public:
|
|||
|
||||
nsIScriptContext *GetContextInternal()
|
||||
{
|
||||
if (IsInnerWindow()) {
|
||||
if (mOuterWindow) {
|
||||
return GetOuterWindowInternal()->mContext;
|
||||
}
|
||||
|
||||
|
@ -250,7 +259,11 @@ public:
|
|||
|
||||
nsIDocShell *GetDocShellInternal()
|
||||
{
|
||||
return GetOuterWindowInternal()->mDocShell;
|
||||
if (mOuterWindow) {
|
||||
return GetOuterWindowInternal()->mDocShell;
|
||||
}
|
||||
|
||||
return mDocShell;
|
||||
}
|
||||
|
||||
static void ShutDown();
|
||||
|
@ -275,11 +288,21 @@ protected:
|
|||
// popup tracking
|
||||
PRBool IsPopupSpamWindow()
|
||||
{
|
||||
if (IsInnerWindow() && !mOuterWindow) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return GetOuterWindowInternal()->mIsPopupSpam;
|
||||
}
|
||||
|
||||
void SetPopupSpamWindow(PRBool aPopup)
|
||||
{
|
||||
if (IsInnerWindow() && !mOuterWindow) {
|
||||
NS_ERROR("SetPopupSpamWindow() called on inner window w/o an outer!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GetOuterWindowInternal()->mIsPopupSpam = aPopup;
|
||||
}
|
||||
|
||||
|
@ -377,7 +400,6 @@ protected:
|
|||
nsCOMPtr<nsIScriptContext> mContext;
|
||||
nsCOMPtr<nsIDOMWindowInternal> mOpener;
|
||||
nsCOMPtr<nsIControllers> mControllers;
|
||||
JSObject* mJSObject;
|
||||
JSObject* mArguments;
|
||||
nsRefPtr<nsNavigator> mNavigator;
|
||||
nsRefPtr<nsScreen> mScreen;
|
||||
|
@ -391,10 +413,6 @@ protected:
|
|||
nsRefPtr<nsBarProp> mStatusbar;
|
||||
nsRefPtr<nsBarProp> mScrollbars;
|
||||
nsCOMPtr<nsIWeakReference> mWindowUtils;
|
||||
nsTimeout* mTimeouts;
|
||||
nsTimeout** mTimeoutInsertionPoint;
|
||||
PRUint32 mTimeoutPublicIdCounter;
|
||||
PRUint32 mTimeoutFiringDepth;
|
||||
nsString mStatus;
|
||||
nsString mDefaultStatus;
|
||||
|
||||
|
@ -405,11 +423,16 @@ protected:
|
|||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> mInnerWindowHolder;
|
||||
|
||||
// This member variable is used only on the inner window.
|
||||
// These member variable are used only on inner windows.
|
||||
nsCOMPtr<nsIEventListenerManager> mListenerManager;
|
||||
nsTimeout* mTimeouts;
|
||||
nsTimeout** mTimeoutInsertionPoint;
|
||||
PRUint32 mTimeoutPublicIdCounter;
|
||||
PRUint32 mTimeoutFiringDepth;
|
||||
|
||||
// This member variable is used on both inner and the outer windows.
|
||||
// These member variables are used on both inner and the outer windows.
|
||||
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
|
||||
JSObject* mJSObject;
|
||||
|
||||
friend class nsDOMScriptableHelper;
|
||||
friend class nsDOMWindowUtils;
|
||||
|
|
|
@ -53,6 +53,7 @@ REQUIRES = xpcom \
|
|||
string \
|
||||
js \
|
||||
dom \
|
||||
layout \
|
||||
necko \
|
||||
caps \
|
||||
widget \
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsIWindowMediator.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIJSConsoleService.h"
|
||||
#include "nsIConsoleService.h"
|
||||
|
@ -147,7 +147,16 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSObject *globalJSObject = global->GetGlobalJSObject();
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
|
||||
nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
|
||||
|
||||
if (!innerWin) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> innerGlobal = do_QueryInterface(innerWin);
|
||||
|
||||
JSObject *globalJSObject = innerGlobal->GetGlobalJSObject();
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(global, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
|
@ -109,6 +109,14 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsPrompt, nsIPrompt, nsIAuthPrompt)
|
|||
nsPrompt::nsPrompt(nsIDOMWindow *aParent)
|
||||
: mParent(aParent)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(aParent));
|
||||
|
||||
NS_ASSERTION(!win || win->IsOuterWindow(),
|
||||
"Inner window passed as nsPrompt parent!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -1098,10 +1098,24 @@ XPC_NW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSObject *other = JSVAL_TO_OBJECT(v);
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
|
||||
*bp = (obj == other ||
|
||||
GetIdentityObject(cx, obj) == GetIdentityObject(cx, other));
|
||||
if (wrappedNative && wrappedNative->IsValid() &&
|
||||
NATIVE_HAS_FLAG(wrappedNative, WantEquality)) {
|
||||
// Forward the call to the wrapped native's Equality() hook.
|
||||
nsresult rv = wrappedNative->GetScriptableCallback()->
|
||||
Equality(wrappedNative, cx, obj, v, bp);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return ThrowException(rv, cx);
|
||||
}
|
||||
} else {
|
||||
JSObject *other = JSVAL_TO_OBJECT(v);
|
||||
|
||||
*bp = (obj == other ||
|
||||
GetIdentityObject(cx, obj) == GetIdentityObject(cx, other));
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
|
|
@ -2718,10 +2718,9 @@ static void CheckForFocus(nsPIDOMWindow* aOurWindow,
|
|||
}
|
||||
|
||||
while (curDoc) {
|
||||
nsCOMPtr<nsPIDOMWindow> curWin =
|
||||
do_QueryInterface(curDoc->GetScriptGlobalObject());
|
||||
nsPIDOMWindow *curWin = curDoc->GetWindow();
|
||||
|
||||
if (!curWin || curWin->GetOuterWindow() == ourWin)
|
||||
if (!curWin || curWin == ourWin)
|
||||
break;
|
||||
|
||||
curDoc = curDoc->GetParentDocument();
|
||||
|
@ -4362,15 +4361,14 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
|
|||
}
|
||||
// Selection is at anchor.
|
||||
// Now focus the document itself if focus is on an element within it.
|
||||
nsCOMPtr<nsPIDOMWindow> win =
|
||||
do_QueryInterface(mDocument->GetScriptGlobalObject());
|
||||
nsPIDOMWindow *win = mDocument->GetWindow();
|
||||
|
||||
if (win) {
|
||||
nsCOMPtr<nsIFocusController> focusController = win->GetRootFocusController();
|
||||
if (focusController) {
|
||||
nsCOMPtr<nsIDOMWindowInternal> focusedWin;
|
||||
focusController->GetFocusedWindow(getter_AddRefs(focusedWin));
|
||||
if (SameCOMIdentity(win->GetOuterWindow(), focusedWin)) {
|
||||
if (SameCOMIdentity(win, focusedWin)) {
|
||||
esm->ChangeFocusWith(nsnull, nsIEventStateManager::eEventFocusedByApplication);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2158,7 +2158,7 @@ nsObjectFrame::NotifyContentObjectWrapper()
|
|||
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
||||
nsContentUtils::XPConnect()->
|
||||
GetWrappedNativeOfNativeObject(cx, ::JS_GetGlobalObject(cx), mContent,
|
||||
GetWrappedNativeOfNativeObject(cx, sgo->GetGlobalJSObject(), mContent,
|
||||
NS_GET_IID(nsISupports),
|
||||
getter_AddRefs(wrapper));
|
||||
|
||||
|
|
|
@ -1335,6 +1335,9 @@ _getwindowobject(NPP npp)
|
|||
JSContext *cx = GetJSContextFromNPP(npp);
|
||||
NS_ENSURE_TRUE(cx, nsnull);
|
||||
|
||||
// Using ::JS_GetGlobalObject(cx) is ok here since the window we
|
||||
// want to return here is the outer window, *not* the inner (since
|
||||
// we don't know what the plugin will do with it).
|
||||
return nsJSObjWrapper::GetNewOrUsed(npp, cx, ::JS_GetGlobalObject(cx));
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIDirectoryService.h"
|
||||
|
@ -781,8 +782,9 @@ nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow)
|
|||
rv = mOwner->GetDocument(getter_AddRefs(document));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && document) {
|
||||
nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
|
||||
nsPIDOMWindow *win = document->GetWindow();
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(win);
|
||||
if(global) {
|
||||
*outJSWindow = global->GetGlobalJSObject();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIChannel.h"
|
||||
|
@ -353,8 +353,9 @@ nsSecureBrowserUIImpl::Notify(nsIContent* formNode,
|
|||
|
||||
nsIURI *formURL = document->GetBaseURI();
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> postingWindow(do_QueryInterface(document->GetScriptGlobalObject()));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> postingWindow =
|
||||
do_QueryInterface(document->GetWindow());
|
||||
|
||||
PRBool isChild;
|
||||
IsChildOfDomWindow(mWindow, postingWindow, &isChild);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче