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

This commit is contained in:
Blake Kaplan 2010-03-22 15:46:37 -07:00
parent e4b2f012b9
commit 24c04cbd78
6 changed files with 61 additions and 7 deletions

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

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

View File

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

View File

@ -311,6 +311,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, &SJOWClass.base, nsnull, scope);

View File

@ -42,6 +42,7 @@
#include "XPCWrapper.h"
#include "XPCNativeWrapper.h"
#include "nsPIDOMWindow.h"
namespace XPCWrapper {
@ -164,6 +165,35 @@ static JSClass IteratorClass = {
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
RewrapObject(JSContext *cx, JSObject *scope, JSObject *obj, WrapperType hint,
jsval *vp)

View File

@ -417,6 +417,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.
*/