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

This commit is contained in:
Blake Kaplan 2010-03-22 15:46:37 -07:00
Родитель bc6c304dbb
Коммит c24e32495b
6 изменённых файлов: 61 добавлений и 7 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -42,6 +42,7 @@
#include "XPCWrapper.h" #include "XPCWrapper.h"
#include "XPCNativeWrapper.h" #include "XPCNativeWrapper.h"
#include "nsPIDOMWindow.h"
namespace XPCWrapper { namespace XPCWrapper {
@ -164,6 +165,35 @@ static JSClass IteratorClass = {
JSCLASS_NO_OPTIONAL_MEMBERS JSCLASS_NO_OPTIONAL_MEMBERS
}; };
void
CheckWindow(XPCWrappedNative *wn)
{
JSClass *clasp = wn->GetFlatJSObject()->getClass();
// 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 JSBool
RewrapObject(JSContext *cx, JSObject *scope, JSObject *obj, WrapperType hint, RewrapObject(JSContext *cx, JSObject *scope, JSObject *obj, WrapperType hint,
jsval *vp) jsval *vp)

Просмотреть файл

@ -417,6 +417,13 @@ WrapFunction(JSContext *cx, JSObject *wrapperObj, JSObject *funobj, jsval *v,
: XPCCrossOriginWrapper::WrapFunction(cx, wrapperObj, funobj, 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. * Given a potentially-wrapped object, creates a wrapper for it.
*/ */