author | Gian-Carlo Pascutto <gpascutto@mozilla.com> |
Tue, 01 Nov 2011 21:02:24 +0100 | |
changeset 81709 | a0e94d288ba09c870e38ee9fb898a05bcfbfe6f5 |
parent 81708 | 473727215fbe9aef82de4cbacb5be7b7e28819d6 |
child 81710 | e532cb6dd56e459dcdc604c43e150a9c371b333f |
push id | 21573 |
push user | blassey@mozilla.com |
push date | Tue, 06 Dec 2011 18:57:07 +0000 |
treeherder | mozilla-central@0e397568c71e [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mfinkle |
bugs | 697549 |
milestone | 10.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/mobile/components/ContentPermissionPrompt.js +++ b/mobile/components/ContentPermissionPrompt.js @@ -79,20 +79,16 @@ const kEntities = { "geolocation": "geol function ContentPermissionPrompt() {} ContentPermissionPrompt.prototype = { classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"), QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]), - _promptId : 0, - _callbackId : 0, - _callbacks : [], - handleExistingPermission: function handleExistingPermission(request) { let result = Services.perms.testExactPermission(request.uri, request.type); if (result == Ci.nsIPermissionManager.ALLOW_ACTION) { request.allow(); return true; } if (result == Ci.nsIPermissionManager.DENY_ACTION) { request.cancel(); @@ -107,127 +103,67 @@ ContentPermissionPrompt.prototype = { .QueryInterface(Ci.nsIDocShellTreeItem) .rootTreeItem .QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIDOMWindow) .QueryInterface(Ci.nsIDOMChromeWindow); return chromeWin; }, - getTabForRequest: function getTabForRequest(request) { + getChromeForRequest: function getChromeForRequest(request) { if (request.window) { let requestingWindow = request.window.top; - let chromeWin = this.getChromeWindow(requestingWindow).wrappedJSObject; - let windowID = chromeWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID; + return this.getChromeWindow(requestingWindow).wrappedJSObject; + } + return request.element.ownerDocument.defaultView; + }, + + getTabForRequest: function getTabForRequest(request) { + let chromeWin = this.getChromeForRequest(request); + if (request.window) { let browser = chromeWin.BrowserApp.getBrowserForWindow(request.window); let tabID = chromeWin.BrowserApp.getTabForBrowser(browser).id; return tabID; } - let chromeWin = request.element.ownerDocument.defaultView; - let browser = chromeWin.Browser; - let tabID = chromeWin.BrowserApp.getTabForBrowser(browser).id; - return tabID; + // Fix this if e10s is needed again + return null; }, prompt: function(request) { // returns true if the request was handled if (this.handleExistingPermission(request)) return; let pm = Services.perms; let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); let entityName = kEntities[request.type]; let tabID = this.getTabForRequest(request); - - this._promptId++; - this._callbackId++; - let allowCallback = { - cb : function(notification) { - setPagePermission(request.type, request.uri, true); - request.allow(); - }, - callbackId : this._callbackId, - promptId : this._promptId - }; - this._callbackId++; - let denyCallback = { - cb : function(notification) { - setPagePermission(request.type, request.uri, false); - request.cancel(); - }, - callbackId : this._callbackId, - promptId : this._promptId - }; - this._callbacks.push(allowCallback); - this._callbacks.push(denyCallback); + let chromeWin = this.getChromeForRequest(request); let buttons = [{ label: browserBundle.GetStringFromName(entityName + ".allow"), accessKey: null, - callback: allowCallback.callbackId + callback: function(notification) { + setPagePermission(request.type, request.uri, true); + request.allow(); + } }, { label: browserBundle.GetStringFromName(entityName + ".dontAllow"), accessKey: null, - callback: denyCallback.callbackId + callback: function(notification) { + setPagePermission(request.type, request.uri, false); + request.cancel(); + } }]; let message = browserBundle.formatStringFromName(entityName + ".wantsTo", [request.uri.host], 1); - let DoorhangerEventListener = { - _contentPermission: this, - init: function(owner) { - Services.obs.addObserver(this, "Doorhanger:Reply", false); - }, - observe: function(aSubject, aTopic, aData) { - let cpo = this._contentPermission; - if (aTopic == "Doorhanger:Reply") { - let cbId = parseInt(aData); - let promptId = -1; - let keepStack = []; - // Find the callback to call for this id - for (i = 0; i < cpo._callbacks.length; i++) { - if (cpo._callbacks[i].callbackId == cbId) { - promptId = cpo._callbacks[i].promptId; - cpo._callbacks[i].cb(); - break; - } - } - // Now find all remaining callbacks that were not - // in the same notification (!same promptId) - for (i = 0; i < cpo._callbacks.length; i++) { - if (cpo._callbacks[i].promptId != promptId) { - keepStack.push(cpo._callbacks[i]); - } - } - // Keep those, throw away everything else - cpo._callbacks = keepStack; - if (cpo._callbacks.length == 0) { - // Remove if this was the last one outstanding - Services.obs.removeObserver(this, "Doorhanger:Reply"); - } - } - } - }; - DoorhangerEventListener.init(this); - - let json = { - gecko: { - type: "Doorhanger:Add", - message: message, - severity: "PRIORITY_WARNING_MEDIUM", - buttons: buttons, - tabID: tabID - } - }; - - Cc["@mozilla.org/android/bridge;1"] - .getService(Ci.nsIAndroidBridge) - .handleGeckoMessage(JSON.stringify(json)); + chromeWin.NativeWindow.doorhanger.show(message, buttons, tabID); } }; //module initialization const NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPermissionPrompt]);