Bug 546573 - EnsureInnerWindow from wrappers. r=jst sr=bzbarsky

This commit is contained in:
Blake Kaplan 2010-07-20 21:05:11 -07:00
parent 8ddb90ded3
commit 45243e880e
9 changed files with 66 additions and 11 deletions

View File

@ -1,4 +1,4 @@
var expected = ["TabOpen", "onLocationChange", "onStateChange", "onLinkIconAvailable"];
var expected = ["TabOpen", "onStateChange", "onLocationChange", "onLinkIconAvailable"];
var actual = [];
var tabIndex = -1;
__defineGetter__("tab", function () gBrowser.tabs[tabIndex]);

View File

@ -80,6 +80,13 @@ var focusableElements = [
"<iframe src=\"about:blank\" tabindex=\"1\"></iframe>",
"<iframe src=\"about:blank\" contenteditable=\"true\"></iframe>",
"<iframe></iframe>",
"<iframe tabindex=\"-1\"></iframe>",
"<iframe tabindex=\"0\"></iframe>",
"<iframe tabindex=\"0\" disabled></iframe>",
"<iframe tabindex=\"1\"></iframe>",
"<iframe disabled></iframe>",
"<img tabindex=\"-1\">",
"<img tabindex=\"0\">",
"<img tabindex=\"0\" disabled>",
@ -179,13 +186,6 @@ var nonFocusableElements = [
"<div tabindex=\"0\" disabled></div>",
"<div disabled></div>",
"<iframe></iframe>",
"<iframe tabindex=\"-1\"></iframe>",
"<iframe tabindex=\"0\"></iframe>",
"<iframe tabindex=\"0\" disabled></iframe>",
"<iframe tabindex=\"1\"></iframe>",
"<iframe disabled></iframe>",
"<img>",
"<img disabled>",
"<img contenteditable=\"true\">",
@ -280,12 +280,19 @@ var focusableInContentEditable = [
"<embed contenteditable=\"true\">",
"<iframe src=\"about:blank\"></iframe>",
"<iframe></iframe>",
"<iframe src=\"about:blank\" disabled></iframe>",
"<iframe disabled></iframe>",
"<iframe src=\"about:blank\" tabindex=\"-1\"></iframe>",
"<iframe tabindex=\"-1\"></iframe>",
"<iframe src=\"about:blank\" tabindex=\"0\"></iframe>",
"<iframe tabindex=\"0\"></iframe>",
"<iframe src=\"about:blank\" tabindex=\"0\" disabled></iframe>",
"<iframe tabindex=\"0\" disabled></iframe>",
"<iframe src=\"about:blank\" tabindex=\"1\"></iframe>",
"<iframe tabindex=\"1\"></iframe>",
"<iframe src=\"about:blank\" contenteditable=\"true\"></iframe>",
"<iframe contenteditable=\"true\"></iframe>",
"<img tabindex=\"-1\">",
"<img tabindex=\"0\">",

View File

@ -120,6 +120,7 @@
"<body>test1</body></html>";
gExpected = [{type: "pagehide", persisted: true},
{type: "load", title: "test1"},
{type: "pageshow", title: "test1", persisted: false}];
gBrowser.loadURI(test1Doc);

View File

@ -240,7 +240,7 @@ function pageEventListener(event) {
try {
dump("TEST: eventListener received a " + event.type + " event for page " +
event.originalTarget.title + ", persisted=" + event.persisted + "\n");
}catch(e) {
} catch(e) {
// Ignore any exception.
}
@ -293,8 +293,8 @@ function pageEventListener(event) {
if (typeof(expected.persisted) != "undefined") {
is(event.persisted, expected.persisted,
"The persisted property of the " + event.type + "event on page " +
event.originalTarget.title + " had an unexpected value");
"The persisted property of the " + event.type + " event on page " +
event.originalTarget.location + " had an unexpected value");
}
// If we're out of expected events, let doPageNavigation() return.

View File

@ -412,6 +412,8 @@ WrapObject(JSContext *cx, JSObject *parent, jsval *vp, XPCWrappedNative* wn)
return JS_TRUE;
}
CheckWindow(wn);
// The parent must be the inner global object for its scope.
parent = JS_GetGlobalForObject(cx, parent);
OBJ_TO_INNER_OBJECT(cx, parent);

View File

@ -1069,6 +1069,8 @@ JSObject *
XPCNativeWrapper::GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper,
JSObject *scope, nsIPrincipal *aObjectPrincipal)
{
CheckWindow(wrapper);
if (aObjectPrincipal) {
nsIScriptSecurityManager *ssm = GetSecurityManager();

View File

@ -324,6 +324,12 @@ WrapObject(JSContext *cx, JSObject *scope, jsval v, jsval *vp)
return ThrowException(NS_ERROR_FAILURE, cx);
}
XPCWrappedNative *wn =
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, objToWrap);
if (wn) {
CheckWindow(wn);
}
JSObject *wrapperObj =
JS_NewObjectWithGivenProto(cx, js::Jsvalify(&SJOWClass), nsnull, scope);

View File

@ -42,6 +42,7 @@
#include "XPCWrapper.h"
#include "XPCNativeWrapper.h"
#include "nsPIDOMWindow.h"
namespace XPCWrapper {
@ -189,6 +190,35 @@ static js::Class IteratorClass = {
}
};
void
CheckWindow(XPCWrappedNative *wn)
{
JSClass *clasp = wn->GetFlatJSObject()->getJSClass();
// Censor objects that can't be windows.
switch (clasp->name[0]) {
case 'C': // ChromeWindow?
if (clasp->name[1] != 'h') {
return;
}
break;
case 'M': // ModalContentWindow
break;
case 'W': // Window
break;
default:
return;
}
nsCOMPtr<nsPIDOMWindow> pwin(do_QueryWrappedNative(wn));
if (!pwin || pwin->IsInnerWindow()) {
return;
}
pwin->EnsureInnerWindow();
}
JSBool
RewrapObject(JSContext *cx, JSObject *scope, JSObject *obj, WrapperType hint,
jsval *vp)

View File

@ -444,6 +444,13 @@ WrapFunction(JSContext *cx, JSObject *wrapperObj, JSObject *funobj, jsval *v,
: XPCCrossOriginWrapper::WrapFunction(cx, wrapperObj, funobj, v);
}
/**
* Given a JSObject that might represent a Window object, ensures that the
* window object has an inner window.
*/
void
CheckWindow(XPCWrappedNative *wn);
/**
* Given a potentially-wrapped object, creates a wrapper for it.
*/