Skip to content

Commit

Permalink
Backed out changeset 6d5c859c452d due to bug 631225
Browse files Browse the repository at this point in the history
--HG--
branch : GECKO20b11_2011020209_RELBRANCH
  • Loading branch information
LegNeato committed Feb 3, 2011
1 parent 6c6a7ce commit 45bbc3e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 106 deletions.
6 changes: 1 addition & 5 deletions dom/tests/mochitest/whatwg/postMessage_chrome_helper.html
Expand Up @@ -12,11 +12,7 @@
respond("path-is-set");
} else {
// Content cannot post to chrome without privileges
try {
window.parent.postMessage("SHOULD NOT GET THIS!", "*");
}
catch (ex) {
}
window.parent.postMessage("SHOULD NOT GET THIS!", "*");

var msg = "post-to-content-response";

Expand Down
17 changes: 16 additions & 1 deletion dom/tests/mochitest/whatwg/test_bug500328.html
Expand Up @@ -128,6 +128,20 @@
return sh;
}

function getChromeWin(theWindow)
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const Ci = Components.interfaces;
return theWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow);
}

function getSHTitle(sh, offset)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Expand Down Expand Up @@ -391,7 +405,8 @@
popstateExpected("Didn't get popstate after opening window.");

popup.history.pushState(null, "title 0");
ok(SpecialPowers.isBackButtonEnabled(popup),
ok(!getChromeWin(popup).document
.getElementById("Browser:Back").hasAttribute("disabled"),
"Back button was not enabled after initial pushstate.");

popup.document.title = "title 1";
Expand Down
21 changes: 19 additions & 2 deletions editor/libeditor/text/tests/test_bug527935.html
Expand Up @@ -22,6 +22,22 @@
<pre id="test">
<script type="application/javascript">

function getAutocompletePopup() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var Ci = Components.interfaces;
chromeWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow);
autocompleteMenu = chromeWin.document.getElementById("PopupAutoComplete");
ok(autocompleteMenu, "Got autocomplete popup");

return autocompleteMenu;
}

/** Test for Bug 527935 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
Expand All @@ -35,10 +51,11 @@

setTimeout(function() {
var popupShown = false;
var popup = getAutocompletePopup();
function listener() {
popupShown = true;
}
SpecialPowers.addAutoCompletePopupEventListener(window, listener);
popup.addEventListener("popupshowing", listener, false);

var event = document.createEvent("KeyboardEvent");

Expand All @@ -50,7 +67,7 @@

setTimeout(function() {
ok(!popupShown, "Popup must not be opened");
SpecialPowers.removeAutoCompletePopupEventListener(window, listener);
popup.removeEventListener("popupshowing", listener, false);
SimpleTest.finish();
}, 1000);
}, 0);
Expand Down
58 changes: 9 additions & 49 deletions js/src/xpconnect/wrappers/AccessCheck.cpp
Expand Up @@ -423,65 +423,25 @@ AccessCheck::deny(JSContext *cx, jsid id)
}
}

enum Access { READ = (1<<0), WRITE = (1<<1), NO_ACCESS = 0 };

bool
PermitIfUniversalXPConnect(ExposedPropertiesOnly::Permission &perm)
{
// If UniversalXPConnect is enabled, allow access even if __exposedProps__ doesn't
// exists.
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
if (!ssm) {
return false;
}
PRBool privileged;
if (NS_SUCCEEDED(ssm->IsCapabilityEnabled("UniversalXPConnect", &privileged)) &&
privileged) {
perm = ExposedPropertiesOnly::PermitPropertyAccess;
return true; // Allow
}

// Use default
return true;
}
typedef enum { READ = (1<<0), WRITE = (1<<1), NO_ACCESS = 0 } Access;

bool
ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, JSWrapper::Action act,
Permission &perm)
{
JSObject *wrappedObject = JSWrapper::wrappedObject(wrapper);

if (act == JSWrapper::CALL) {
perm = PermitObjectAccess;
return true;
}
JSObject *holder = JSWrapper::wrappedObject(wrapper);

perm = DenyAccess;

jsid exposedPropsId = GetRTIdByIndex(cx, XPCJSRuntime::IDX_EXPOSEDPROPS);

JSBool found = JS_FALSE;
JSAutoEnterCompartment ac;
if (!ac.enter(cx, wrappedObject) ||
!JS_HasPropertyById(cx, wrappedObject, exposedPropsId, &found))
if (!ac.enter(cx, holder) || !JS_HasPropertyById(cx, holder, exposedPropsId, &found))
return false;

// Always permit access to "length" and indexed properties of arrays.
if (JS_IsArrayObject(cx, wrappedObject) &&
((JSID_IS_INT(id) && JSID_TO_INT(id) >= 0) ||
(JSID_IS_ATOM(id) && JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "length")))) {
perm = PermitPropertyAccess;
return true; // Allow
}

// If no __exposedProps__ existed, deny access.
if (!found) {
// For now, only do this on functions.
if (!JS_ObjectIsFunction(cx, wrappedObject)) {
perm = PermitPropertyAccess;
return true;
}
return PermitIfUniversalXPConnect(perm); // Deny
perm = PermitObjectAccess;
return true; // Allow
}

if (id == JSID_VOID) {
Expand All @@ -491,11 +451,11 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, JSWrappe
}

jsval exposedProps;
if (!JS_LookupPropertyById(cx, wrappedObject, exposedPropsId, &exposedProps))
if (!JS_LookupPropertyById(cx, holder, exposedPropsId, &exposedProps))
return false;

if (JSVAL_IS_VOID(exposedProps) || JSVAL_IS_NULL(exposedProps)) {
return PermitIfUniversalXPConnect(perm); // Deny
return true; // Deny
}

if (!JSVAL_IS_OBJECT(exposedProps)) {
Expand All @@ -512,7 +472,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, JSWrappe
return false; // Error
}
if (desc.obj == NULL || !(desc.attrs & JSPROP_ENUMERATE)) {
return PermitIfUniversalXPConnect(perm); // Deny
return true; // Deny
}

if (!JSVAL_IS_STRING(desc.value)) {
Expand Down Expand Up @@ -557,7 +517,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, JSWrappe

if ((act == JSWrapper::SET && !(access & WRITE)) ||
(act != JSWrapper::SET && !(access & READ))) {
return PermitIfUniversalXPConnect(perm); // Deny
return true; // Deny
}

perm = PermitPropertyAccess;
Expand Down
2 changes: 0 additions & 2 deletions layout/base/tests/test_bug458898.html
Expand Up @@ -19,7 +19,6 @@
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();
// This should be rewritten as a chrome test
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var win = window.openDialog("data:text/html,<div style='height:200px; width:100px;'>");

Expand All @@ -29,7 +28,6 @@
var testfunc_w = (navigator.userAgent.match(/Windows/)) ? ok : testfunc_h;

function loaded() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
win.sizeToContent();
testfunc_w(win.innerWidth >= 100, "innerWidth: " + win.innerWidth + " >= 100 ?");
testfunc_h(win.innerHeight >= 200, "innerHeight: " + win.innerHeight + " >= 200 ?");
Expand Down
8 changes: 3 additions & 5 deletions layout/tools/reftest/reftest.js
Expand Up @@ -385,7 +385,7 @@ function BuildConditionSandbox(aURL) {
var sandbox = new Components.utils.Sandbox(aURL.spec);
var xr = CC[NS_XREAPPINFO_CONTRACTID].getService(CI.nsIXULRuntime);
sandbox.isDebugBuild = gDebug.isDebugBuild;
sandbox.xulRuntime = {widgetToolkit: xr.widgetToolkit, OS: xr.OS, __exposedProps__: { widgetToolkit: "r", OS: "r", XPCOMABI: "r", shell: "r" } };
sandbox.xulRuntime = {widgetToolkit: xr.widgetToolkit, OS: xr.OS};

// xr.XPCOMABI throws exception for configurations without full ABI
// support (mobile builds on ARM)
Expand Down Expand Up @@ -415,14 +415,12 @@ function BuildConditionSandbox(aURL) {

var hh = CC[NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX + "http"].
getService(CI.nsIHttpProtocolHandler);
sandbox.http = { __exposedProps__: {} };
sandbox.http = {};
for each (var prop in [ "userAgent", "appName", "appVersion",
"vendor", "vendorSub",
"product", "productSub",
"platform", "oscpu", "language", "misc" ]) {
"platform", "oscpu", "language", "misc" ])
sandbox.http[prop] = hh[prop];
sandbox.http.__exposedProps__[prop] = "r";
}
// see if we have the test plugin available,
// and set a sandox prop accordingly
sandbox.haveTestPlugin = false;
Expand Down
38 changes: 1 addition & 37 deletions testing/mochitest/specialpowers/content/specialpowers.js
Expand Up @@ -89,45 +89,9 @@ var SpecialPowers = {
msg = {'op':'set', 'prefName': aPrefName, 'prefType': aPrefType, 'prefValue': aValue};
}
return(sendSyncMessage('SPPrefService', msg)[0]);
},

_getTopChromeWindow: function(window) {
var Ci = Components.interfaces;
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow);
},
_getAutoCompletePopup: function(window) {
return this._getTopChromeWindow(window).document
.getElementById("PopupAutoComplete");
},
addAutoCompletePopupEventListener: function(window, listener) {
this._getAutoCompletePopup(window).addEventListener("popupshowing",
listener,
false);
},
removeAutoCompletePopupEventListener: function(window, listener) {
this._getAutoCompletePopup(window).removeEventListener("popupshowing",
listener,
false);
},
isBackButtonEnabled: function(window) {
return !this._getTopChromeWindow(window).document
.getElementById("Browser:Back")
.hasAttribute("disabled")
},
}

SpecialPowers.__exposedProps__ = {};
for each (i in Object.keys(SpecialPowers).filter(function(v) {return v.charAt(0) != "_"})) {
SpecialPowers.__exposedProps__[i] = "r";
}
}


// Attach our API to the window
function attachSpecialPwrToWindow(aSubject) {
try {
Expand Down
Expand Up @@ -81,7 +81,6 @@
<script class="testbody" type="text/javascript">

function hTest(node, validate) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (node)
Microformats.parser.newMicroformat(this, node, "hTest", validate);
}
Expand Down
5 changes: 1 addition & 4 deletions toolkit/components/prompts/test/test_modal_prompts.html
Expand Up @@ -759,10 +759,7 @@
// Can't use setInterval here, because the window's in a modal state
// and thus DOM events are suppressed.
pollTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
pollTimer.initWithCallback(function() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
pollDialog(ui.button0);
},
pollTimer.initWithCallback(function() { pollDialog(ui.button0); },
100, Ci.nsITimer.TYPE_REPEATING_SLACK);
return;
} else {
Expand Down

0 comments on commit 45bbc3e

Please sign in to comment.