Backed out 8 changesets (bug 1044736) for breaking the statusbar on b2g a=backout

Backed out changeset b1a6ecfca674 (bug 1044736)
Backed out changeset 61fc517d0336 (bug 1044736)
Backed out changeset 59a47fafaccf (bug 1044736)
Backed out changeset b3ff4ce20e67 (bug 1044736)
Backed out changeset e4f1f09f150f (bug 1044736)
Backed out changeset 8ecfc1f41ddc (bug 1044736)
Backed out changeset c7c9170ab299 (bug 1044736)
Backed out changeset 78aacc35b4e7 (bug 1044736)

--HG--
rename : dom/browser-element/BrowserElementParent.js => dom/browser-element/BrowserElementParent.jsm
This commit is contained in:
Wes Kocher 2014-11-17 20:34:00 -08:00
parent 022cfb7eb1
commit 3696aa8ceb
19 changed files with 387 additions and 1287 deletions

View File

@ -132,7 +132,6 @@
@BINPATH@/components/autocomplete.xpt
@BINPATH@/components/autoconfig.xpt
@BINPATH@/components/browsercompsbase.xpt
@BINPATH@/components/browser-element.xpt
@BINPATH@/components/browser-feeds.xpt
@BINPATH@/components/caps.xpt
@BINPATH@/components/chardet.xpt

View File

@ -177,7 +177,6 @@
@BINPATH@/components/appstartup.xpt
@BINPATH@/components/autocomplete.xpt
@BINPATH@/components/autoconfig.xpt
@BINPATH@/components/browser-element.xpt
@BINPATH@/browser/components/browsercompsbase.xpt
@BINPATH@/browser/components/browser-feeds.xpt
@BINPATH@/components/caps.xpt

View File

@ -1,231 +0,0 @@
var gWidgetManifestURL = 'http://test/tests/dom/apps/tests/file_app.sjs?apptype=widget&getmanifest=true';
var gInvalidWidgetManifestURL = 'http://test/tests/dom/apps/tests/file_app.sjs?apptype=invalidWidget&getmanifest=true';
var gApp;
var gHasBrowserPermission;
function onError() {
ok(false, "Error callback invoked");
finish();
}
function installApp(path) {
var request = navigator.mozApps.install(path);
request.onerror = onError;
request.onsuccess = function() {
gApp = request.result;
runTest();
}
}
function uninstallApp() {
// Uninstall the app.
var request = navigator.mozApps.mgmt.uninstall(gApp);
request.onerror = onError;
request.onsuccess = function() {
// All done.
info("All done");
runTest();
}
}
function testApp(isValidWidget) {
info("Test widget feature. IsValidWidget: " + isValidWidget);
var ifr = document.createElement('iframe');
ifr.setAttribute('mozbrowser', 'true');
ifr.setAttribute('mozwidget', gApp.manifestURL);
ifr.setAttribute('src', gApp.origin+gApp.manifest.launch_path);
var domParent = document.getElementById('container');
domParent.appendChild(ifr);
var mm = SpecialPowers.getBrowserFrameMessageManager(ifr);
mm.addMessageListener('OK', function(msg) {
ok(isValidWidget, "Message from widget: " + SpecialPowers.wrap(msg).json);
});
mm.addMessageListener('KO', function(msg) {
ok(!isValidWidget, "Message from widget: " + SpecialPowers.wrap(msg).json);
});
mm.addMessageListener('DONE', function(msg) {
ok(true, "Message from widget complete: "+SpecialPowers.wrap(msg).json);
domParent.removeChild(ifr);
runTest();
});
ifr.addEventListener('mozbrowserloadend', function() {
ok(true, "receive mozbrowserloadend");
// Test limited browser API feature only for valid widget case
if (isValidWidget) {
testLimitedBrowserAPI(ifr);
}
SimpleTest.executeSoon(()=>loadFrameScript(mm));
}, false);
// Test limited browser API feature only for valid widget case
if (!isValidWidget) {
return;
}
[
'mozbrowsertitlechange',
'mozbrowseropenwindow',
'mozbrowserscroll',
'mozbrowserasyncscroll'
].forEach( function(topic) {
ifr.addEventListener(topic, function() {
ok(false, topic + " should be hidden");
}, false);
});
}
function testLimitedBrowserAPI(ifr) {
var securitySensitiveCalls = [
{ api: 'sendMouseEvent' , args: ['mousedown', 0, 0, 0, 0, 0] },
{ api: 'sendTouchEvent' , args: ['touchstart', [0], [0], [0], [1], [1], [0], [1], 1, 0] },
{ api: 'goBack' , args: [] },
{ api: 'goForward' , args: [] },
{ api: 'reload' , args: [] },
{ api: 'stop' , args: [] },
{ api: 'download' , args: ['http://example.org'] },
{ api: 'purgeHistory' , args: [] },
{ api: 'getScreenshot' , args: [0, 0] },
{ api: 'zoom' , args: [0.1] },
{ api: 'getCanGoBack' , args: [] },
{ api: 'getCanGoForward' , args: [] },
{ api: 'getContentDimensions', args: [] }
];
securitySensitiveCalls.forEach( function(call) {
if (gHasBrowserPermission) {
isnot(typeof ifr[call.api], "undefined", call.api + " should be defined");
var didThrow;
try {
ifr[call.api].apply(ifr, call.args);
} catch (e) {
ok(e instanceof DOMException, "throw right exception type");
didThrow = e.code;
}
is(didThrow, DOMException.INVALID_NODE_TYPE_ERR, "call " + call.api + " should throw exception");
} else {
is(typeof ifr[call.api], "undefined", call.api + " should be hidden for widget");
}
});
}
function loadFrameScript(mm) {
var script = 'data:,\
function ok(p, msg) { \
if (p) { \
sendAsyncMessage("OK", msg); \
} else { \
sendAsyncMessage("KO", msg); \
} \
} \
\
function is(a, b, msg) { \
if (a == b) { \
sendAsyncMessage("OK", a + " == " + b + " - " + msg); \
} else { \
sendAsyncMessage("KO", a + " != " + b + " - " + msg); \
} \
} \
\
function finish() { \
sendAsyncMessage("DONE",""); \
} \
\
function onError() { \
ok(false, "Error callback invoked"); \
finish(); \
} \
\
function checkWidget(widget) { \
/*For invalid widget case, ignore the following check*/\
if (widget) { \
var widgetName = "Really Rapid Release (APPTYPETOKEN)"; \
is(widget.origin, "http://test", "Widget origin should be correct"); \
is(widget.installOrigin, "http://mochi.test:8888", "Install origin should be correct"); \
} \
finish(); \
} \
\
var request = content.window.navigator.mozApps.getSelf(); \
request.onsuccess = function() { \
var widget = request.result; \
ok(widget,"Should be a widget"); \
checkWidget(widget); \
}; \
request.onerror = onError; \
content.window.open("about:blank"); /*test mozbrowseropenwindow*/ \
content.window.scrollTo(4000, 4000); /*test mozbrowser(async)scroll*/ \
';
mm.loadFrameScript(script, /* allowDelayedLoad = */ false);
}
var tests = [
// Permissions
function() {
SpecialPowers.pushPermissions(
[{ "type": "browser", "allow": gHasBrowserPermission ? 1 : 0, "context": document },
{ "type": "embed-widgets", "allow": 1, "context": document },
{ "type": "webapps-manage", "allow": 1, "context": document }], runTest);
},
// Preferences
function() {
SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true],
["dom.enable_widgets", true],
["dom.datastore.sysMsgOnChangeShortTimeoutSec", 1],
["dom.datastore.sysMsgOnChangeLongTimeoutSec", 3]]}, runTest);
},
function() {
if (SpecialPowers.isMainProcess()) {
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
}
SpecialPowers.setAllAppsLaunchable(true);
runTest();
},
// No confirmation needed when an app is installed
function() {
SpecialPowers.autoConfirmAppInstall(() => {
SpecialPowers.autoConfirmAppUninstall(runTest);
});
},
// Installing the app
()=>installApp(gWidgetManifestURL),
// Run tests in app
()=>testApp(true),
// Uninstall the app
uninstallApp,
// Installing the app for invalid widget case
()=>installApp(gInvalidWidgetManifestURL),
// Run tests in app for invalid widget case
()=>testApp(false),
// Uninstall the app
uninstallApp
];
function runTest() {
if (!tests.length) {
finish();
return;
}
var test = tests.shift();
test();
}
function finish() {
SimpleTest.finish();
}

View File

@ -17,7 +17,6 @@ support-files =
file_packaged_app.template.webapp
file_widget_app.template.webapp
file_widget_app.template.html
file_test_widget.js
signed_app.sjs
signed_app_template.webapp
signed/*
@ -45,5 +44,3 @@ skip-if = (toolkit == 'android' && processor == 'x86') #x86 only
[test_web_app_install.html]
[test_widget.html]
skip-if = os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app
[test_widget_browser.html]
skip-if = os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app

View File

@ -4,14 +4,231 @@
<meta charset="utf-8">
<title>Test for DataStore - basic operation on a readonly db</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="file_test_widget.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="container"></div>
<script type="application/javascript;version=1.7">
var gWidgetManifestURL = 'http://test/tests/dom/apps/tests/file_app.sjs?apptype=widget&getmanifest=true';
var gInvalidWidgetManifestURL = 'http://test/tests/dom/apps/tests/file_app.sjs?apptype=invalidWidget&getmanifest=true';
var gApp;
function onError() {
ok(false, "Error callback invoked");
finish();
}
function installApp(path) {
var request = navigator.mozApps.install(path);
request.onerror = onError;
request.onsuccess = function() {
gApp = request.result;
runTest();
}
}
function uninstallApp() {
// Uninstall the app.
var request = navigator.mozApps.mgmt.uninstall(gApp);
request.onerror = onError;
request.onsuccess = function() {
// All done.
info("All done");
runTest();
}
}
function testApp(isValidWidget) {
info("Test widget feature. IsValidWidget: " + isValidWidget);
var ifr = document.createElement('iframe');
ifr.setAttribute('mozbrowser', 'true');
ifr.setAttribute('mozwidget', gApp.manifestURL);
ifr.setAttribute('src', gApp.origin+gApp.manifest.launch_path);
var domParent = document.getElementById('container');
domParent.appendChild(ifr);
var mm = SpecialPowers.getBrowserFrameMessageManager(ifr);
mm.addMessageListener('OK', function(msg) {
ok(isValidWidget, "Message from widget: " + SpecialPowers.wrap(msg).json);
});
mm.addMessageListener('KO', function(msg) {
ok(!isValidWidget, "Message from widget: " + SpecialPowers.wrap(msg).json);
});
mm.addMessageListener('DONE', function(msg) {
ok(true, "Message from widget complete: "+SpecialPowers.wrap(msg).json);
domParent.removeChild(ifr);
runTest();
});
ifr.addEventListener('mozbrowserloadend', function() {
ok(true, "receive mozbrowserloadend");
// Test limited browser API feature only for valid widget case
if (isValidWidget) {
testLimitedBrowserAPI(ifr);
}
SimpleTest.executeSoon(()=>loadFrameScript(mm));
}, false);
// Test limited browser API feature only for valid widget case
if (!isValidWidget) {
return;
}
[
'mozbrowsertitlechange',
'mozbrowseropenwindow',
'mozbrowserscroll',
'mozbrowserasyncscroll'
].forEach( function(topic) {
ifr.addEventListener(topic, function() {
ok(false, topic + " should be hidden");
}, false);
});
}
function testLimitedBrowserAPI(ifr) {
var securitySensitiveCalls = [
'sendMouseEvent',
'sendTouchEvent',
'goBack',
'goForward',
'reload',
'stop',
'download',
'purgeHistory',
'getScreenshot',
'zoom',
'getCanGoBack',
'getCanGoForward'
];
securitySensitiveCalls.forEach( function(call) {
is(typeof ifr[call], "undefined", call + " should be hidden for widget");
});
}
function loadFrameScript(mm) {
var script = 'data:,\
function ok(p, msg) { \
if (p) { \
sendAsyncMessage("OK", msg); \
} else { \
sendAsyncMessage("KO", msg); \
} \
} \
\
function is(a, b, msg) { \
if (a == b) { \
sendAsyncMessage("OK", a + " == " + b + " - " + msg); \
} else { \
sendAsyncMessage("KO", a + " != " + b + " - " + msg); \
} \
} \
\
function finish() { \
sendAsyncMessage("DONE",""); \
} \
\
function onError() { \
ok(false, "Error callback invoked"); \
finish(); \
} \
\
function checkWidget(widget) { \
/*For invalid widget case, ignore the following check*/\
if (widget) { \
var widgetName = "Really Rapid Release (APPTYPETOKEN)"; \
is(widget.origin, "http://test", "Widget origin should be correct"); \
is(widget.installOrigin, "http://mochi.test:8888", "Install origin should be correct"); \
} \
finish(); \
} \
\
var request = content.window.navigator.mozApps.getSelf(); \
request.onsuccess = function() { \
var widget = request.result; \
ok(widget,"Should be a widget"); \
checkWidget(widget); \
}; \
request.onerror = onError; \
content.window.open("about:blank"); /*test mozbrowseropenwindow*/ \
content.window.scrollTo(4000, 4000); /*test mozbrowser(async)scroll*/ \
';
mm.loadFrameScript(script, /* allowDelayedLoad = */ false);
}
var tests = [
// Permissions
function() {
SpecialPowers.pushPermissions(
[{ "type": "browser", "allow": 1, "context": document },
{ "type": "embed-widgets", "allow": 1, "context": document },
{ "type": "webapps-manage", "allow": 1, "context": document }], runTest);
},
// Preferences
function() {
SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true],
["dom.enable_widgets", true],
["dom.datastore.sysMsgOnChangeShortTimeoutSec", 1],
["dom.datastore.sysMsgOnChangeLongTimeoutSec", 3]]}, runTest);
},
function() {
if (SpecialPowers.isMainProcess()) {
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
}
SpecialPowers.setAllAppsLaunchable(true);
runTest();
},
// No confirmation needed when an app is installed
function() {
SpecialPowers.autoConfirmAppInstall(() => {
SpecialPowers.autoConfirmAppUninstall(runTest);
});
},
// Installing the app
()=>installApp(gWidgetManifestURL),
// Run tests in app
()=>testApp(true),
// Uninstall the app
uninstallApp,
// Installing the app for invalid widget case
()=>installApp(gInvalidWidgetManifestURL),
// Run tests in app for invalid widget case
()=>testApp(false),
// Uninstall the app
uninstallApp
];
function runTest() {
if (!tests.length) {
finish();
return;
}
var test = tests.shift();
test();
}
function finish() {
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
gHasBrowserPermission = false;
runTest();
</script>
</body>

View File

@ -1,18 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for DataStore - basic operation on a readonly db</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="file_test_widget.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="container"></div>
<script type="application/javascript;version=1.7">
SimpleTest.waitForExplicitFinish();
gHasBrowserPermission = true;
runTest();
</script>
</body>
</html>

View File

@ -14,6 +14,8 @@ let Cr = Components.results;
* appropriate action here in the parent.
*/
this.EXPORTED_SYMBOLS = ["BrowserElementParentBuilder"];
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/BrowserElementPromptService.jsm");
@ -23,8 +25,10 @@ XPCOMUtils.defineLazyGetter(this, "DOMApplicationRegistry", function () {
return DOMApplicationRegistry;
});
const TOUCH_EVENTS_ENABLED_PREF = "dom.w3c_touch_events.enabled";
function debug(msg) {
//dump("BrowserElementParent - " + msg + "\n");
//dump("BrowserElementParent.jsm - " + msg + "\n");
}
function getIntPref(prefName, def) {
@ -55,83 +59,138 @@ function visibilityChangeHandler(e) {
}
}
function defineNoReturnMethod(fn) {
return function method() {
if (!this._domRequestReady) {
// Remote browser haven't been created, we just queue the API call.
let args = Array.slice(arguments);
args.unshift(this);
this._pendingAPICalls.push(method.bind.apply(fn, args));
return;
}
if (this._isAlive()) {
fn.apply(this, arguments);
}
};
this.BrowserElementParentBuilder = {
create: function create(frameLoader, hasRemoteFrame, isPendingFrame) {
return new BrowserElementParent(frameLoader, hasRemoteFrame);
}
}
function defineDOMRequestMethod(msgName) {
return function() {
return this._sendDOMRequest(msgName);
};
}
function BrowserElementParent() {
debug("Creating new BrowserElementParent object");
function BrowserElementParent(frameLoader, hasRemoteFrame, isPendingFrame) {
debug("Creating new BrowserElementParent object for " + frameLoader);
this._domRequestCounter = 0;
this._domRequestReady = false;
this._pendingAPICalls = [];
this._pendingDOMRequests = {};
this._pendingSetInputMethodActive = [];
this._hasRemoteFrame = hasRemoteFrame;
this._nextPaintListeners = [];
this._frameLoader = frameLoader;
this._frameElement = frameLoader.QueryInterface(Ci.nsIFrameLoader).ownerElement;
let self = this;
if (!this._frameElement) {
debug("No frame element?");
return;
}
Services.obs.addObserver(this, 'ask-children-to-exit-fullscreen', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'oop-frameloader-crashed', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'copypaste-docommand', /* ownsWeak = */ true);
let defineMethod = function(name, fn) {
XPCNativeWrapper.unwrap(self._frameElement)[name] = Cu.exportFunction(function() {
if (self._isAlive()) {
return fn.apply(self, arguments);
}
}, self._frameElement);
}
let defineNoReturnMethod = function(name, fn) {
XPCNativeWrapper.unwrap(self._frameElement)[name] = Cu.exportFunction(function method() {
if (!self._domRequestReady) {
// Remote browser haven't been created, we just queue the API call.
let args = Array.slice(arguments);
args.unshift(self);
self._pendingAPICalls.push(method.bind.apply(fn, args));
return;
}
if (self._isAlive()) {
fn.apply(self, arguments);
}
}, self._frameElement);
};
let defineDOMRequestMethod = function(domName, msgName) {
XPCNativeWrapper.unwrap(self._frameElement)[domName] = Cu.exportFunction(function() {
return self._sendDOMRequest(msgName);
}, self._frameElement);
}
// Define methods on the frame element.
defineNoReturnMethod('setVisible', this._setVisible);
defineDOMRequestMethod('getVisible', 'get-visible');
// Not expose security sensitive browser API for widgets
if (!this._frameLoader.QueryInterface(Ci.nsIFrameLoader).ownerIsWidget) {
defineNoReturnMethod('sendMouseEvent', this._sendMouseEvent);
// 0 = disabled, 1 = enabled, 2 - auto detect
if (getIntPref(TOUCH_EVENTS_ENABLED_PREF, 0) != 0) {
defineNoReturnMethod('sendTouchEvent', this._sendTouchEvent);
}
defineNoReturnMethod('goBack', this._goBack);
defineNoReturnMethod('goForward', this._goForward);
defineNoReturnMethod('reload', this._reload);
defineNoReturnMethod('stop', this._stop);
defineMethod('download', this._download);
defineDOMRequestMethod('purgeHistory', 'purge-history');
defineMethod('getScreenshot', this._getScreenshot);
defineNoReturnMethod('zoom', this._zoom);
defineDOMRequestMethod('getCanGoBack', 'get-can-go-back');
defineDOMRequestMethod('getCanGoForward', 'get-can-go-forward');
defineDOMRequestMethod('getContentDimensions', 'get-contentdimensions');
}
defineMethod('addNextPaintListener', this._addNextPaintListener);
defineMethod('removeNextPaintListener', this._removeNextPaintListener);
defineNoReturnMethod('setActive', this._setActive);
defineMethod('getActive', 'this._getActive');
let principal = this._frameElement.ownerDocument.nodePrincipal;
let perm = Services.perms
.testExactPermissionFromPrincipal(principal, "input-manage");
if (perm === Ci.nsIPermissionManager.ALLOW_ACTION) {
defineMethod('setInputMethodActive', this._setInputMethodActive);
}
// Listen to visibilitychange on the iframe's owner window, and forward
// changes down to the child. We want to do this while registering as few
// visibilitychange listeners on _window as possible, because such a listener
// may live longer than this BrowserElementParent object.
//
// To accomplish this, we register just one listener on the window, and have
// it reference a WeakMap whose keys are all the BrowserElementParent objects
// on the window. Then when the listener fires, we iterate over the
// WeakMap's keys (which we can do, because we're chrome) to notify the
// BrowserElementParents.
if (!this._window._browserElementParents) {
this._window._browserElementParents = new WeakMap();
this._window.addEventListener('visibilitychange',
visibilityChangeHandler,
/* useCapture = */ false,
/* wantsUntrusted = */ false);
}
this._window._browserElementParents.set(this, null);
// Insert ourself into the prompt service.
BrowserElementPromptService.mapFrameToBrowserElementParent(this._frameElement, this);
if (!isPendingFrame) {
this._setupMessageListener();
this._registerAppManifest();
} else {
// if we are a pending frame, we setup message manager after
// observing remote-browser-frame-shown
Services.obs.addObserver(this, 'remote-browser-frame-shown', /* ownsWeak = */ true);
}
}
BrowserElementParent.prototype = {
classDescription: "BrowserElementAPI implementation",
classID: Components.ID("{9f171ac4-0939-4ef8-b360-3408aedc3060}"),
contractID: "@mozilla.org/dom/browser-element-api;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserElementAPI,
Ci.nsIObserver,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
setFrameLoader: function(frameLoader) {
this._frameLoader = frameLoader;
this._frameElement = frameLoader.QueryInterface(Ci.nsIFrameLoader).ownerElement;
if (!this._frameElement) {
debug("No frame element?");
return;
}
// Listen to visibilitychange on the iframe's owner window, and forward
// changes down to the child. We want to do this while registering as few
// visibilitychange listeners on _window as possible, because such a listener
// may live longer than this BrowserElementParent object.
//
// To accomplish this, we register just one listener on the window, and have
// it reference a WeakMap whose keys are all the BrowserElementParent objects
// on the window. Then when the listener fires, we iterate over the
// WeakMap's keys (which we can do, because we're chrome) to notify the
// BrowserElementParents.
if (!this._window._browserElementParents) {
this._window._browserElementParents = new WeakMap();
this._window.addEventListener('visibilitychange',
visibilityChangeHandler,
/* useCapture = */ false,
/* wantsUntrusted = */ false);
}
this._window._browserElementParents.set(this, null);
// Insert ourself into the prompt service.
BrowserElementPromptService.mapFrameToBrowserElementParent(this._frameElement, this);
this._setupMessageListener();
this._registerAppManifest();
},
_runPendingAPICall: function() {
if (!this._pendingAPICalls) {
return;
@ -533,27 +592,20 @@ BrowserElementParent.prototype = {
}
},
setVisible: defineNoReturnMethod(function(visible) {
_setVisible: function(visible) {
this._sendAsyncMsg('set-visible', {visible: visible});
this._frameLoader.visible = visible;
}),
},
getVisible: defineDOMRequestMethod('get-visible'),
setActive: defineNoReturnMethod(function(active) {
_setActive: function(active) {
this._frameLoader.visible = active;
}),
getActive: function() {
if (!this._isAlive()) {
throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
},
_getActive: function() {
return this._frameLoader.visible;
},
sendMouseEvent: defineNoReturnMethod(function(type, x, y, button, clickCount, modifiers) {
_sendMouseEvent: function(type, x, y, button, clickCount, modifiers) {
this._sendAsyncMsg("send-mouse-event", {
"type": type,
"x": x,
@ -562,11 +614,11 @@ BrowserElementParent.prototype = {
"clickCount": clickCount,
"modifiers": modifiers
});
}),
},
sendTouchEvent: defineNoReturnMethod(function(type, identifiers, touchesX, touchesY,
radiisX, radiisY, rotationAngles, forces,
count, modifiers) {
_sendTouchEvent: function(type, identifiers, touchesX, touchesY,
radiisX, radiisY, rotationAngles, forces,
count, modifiers) {
let tabParent = this._frameLoader.tabParent;
if (tabParent && tabParent.useAsyncPanZoom) {
@ -594,45 +646,35 @@ BrowserElementParent.prototype = {
"modifiers": modifiers
});
}
}),
},
getCanGoBack: defineDOMRequestMethod('get-can-go-back'),
getCanGoForward: defineDOMRequestMethod('get-can-go-forward'),
getContentDimensions: defineDOMRequestMethod('get-contentdimensions'),
goBack: defineNoReturnMethod(function() {
_goBack: function() {
this._sendAsyncMsg('go-back');
}),
},
goForward: defineNoReturnMethod(function() {
_goForward: function() {
this._sendAsyncMsg('go-forward');
}),
},
reload: defineNoReturnMethod(function(hardReload) {
_reload: function(hardReload) {
this._sendAsyncMsg('reload', {hardReload: hardReload});
}),
},
stop: defineNoReturnMethod(function() {
_stop: function() {
this._sendAsyncMsg('stop');
}),
},
/*
* The valid range of zoom scale is defined in preference "zoom.maxPercent" and "zoom.minPercent".
*/
zoom: defineNoReturnMethod(function(zoom) {
_zoom: function(zoom) {
zoom *= 100;
zoom = Math.min(getIntPref("zoom.maxPercent", 300), zoom);
zoom = Math.max(getIntPref("zoom.minPercent", 50), zoom);
this._sendAsyncMsg('zoom', {zoom: zoom / 100.0});
}),
},
purgeHistory: defineDOMRequestMethod('purge-history'),
download: function(_url, _options) {
if (!this._isAlive()) {
return null;
}
_download: function(_url, _options) {
let ioService =
Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
let uri = ioService.newURI(_url, null, null);
@ -718,7 +760,7 @@ BrowserElementParent.prototype = {
this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
aOffset, aCount);
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamListener,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamListener,
Ci.nsIRequestObserver])
};
@ -752,12 +794,7 @@ BrowserElementParent.prototype = {
return req;
},
getScreenshot: function(_width, _height, _mimeType) {
if (!this._isAlive()) {
throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
_getScreenshot: function(_width, _height, _mimeType) {
let width = parseInt(_width);
let height = parseInt(_height);
let mimeType = (typeof _mimeType === 'string') ?
@ -777,18 +814,16 @@ BrowserElementParent.prototype = {
this._nextPaintListeners = [];
for (let listener of listeners) {
try {
listener.recvNextPaint();
listener();
} catch (e) {
// If a listener throws we'll continue.
}
}
},
addNextPaintListener: function(listener) {
if (!this._isAlive()) {
throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
_addNextPaintListener: function(listener) {
if (typeof listener != 'function')
throw Components.Exception("Invalid argument", Cr.NS_ERROR_INVALID_ARG);
let self = this;
let run = function() {
@ -802,11 +837,9 @@ BrowserElementParent.prototype = {
}
},
removeNextPaintListener: function(listener) {
if (!this._isAlive()) {
throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
_removeNextPaintListener: function(listener) {
if (typeof listener != 'function')
throw Components.Exception("Invalid argument", Cr.NS_ERROR_INVALID_ARG);
let self = this;
let run = function() {
@ -827,12 +860,7 @@ BrowserElementParent.prototype = {
}
},
setInputMethodActive: function(isActive) {
if (!this._isAlive()) {
throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
_setInputMethodActive: function(isActive) {
if (typeof isActive !== 'boolean') {
throw Components.Exception("Invalid argument",
Cr.NS_ERROR_INVALID_ARG);
@ -894,10 +922,18 @@ BrowserElementParent.prototype = {
case 'ask-children-to-exit-fullscreen':
if (this._isAlive() &&
this._frameElement.ownerDocument == subject &&
this._frameLoader.QueryInterface(Ci.nsIFrameLoader).tabParent) {
this._hasRemoteFrame) {
this._sendAsyncMsg('exit-fullscreen');
}
break;
case 'remote-browser-frame-shown':
if (this._frameLoader == subject) {
if (!this._mm) {
this._setupMessageListener();
this._registerAppManifest();
}
Services.obs.removeObserver(this, 'remote-browser-frame-shown');
}
case 'copypaste-docommand':
if (this._isAlive() && this._frameElement.isEqualNode(subject.wrappedJSObject)) {
this._sendAsyncMsg('do-command', { command: data });
@ -909,5 +945,3 @@ BrowserElementParent.prototype = {
};
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([BrowserElementParent]);

View File

@ -1,2 +1,3 @@
component {9f171ac4-0939-4ef8-b360-3408aedc3060} BrowserElementParent.js
contract @mozilla.org/dom/browser-element-api;1 {9f171ac4-0939-4ef8-b360-3408aedc3060}
component {ddeafdac-cb39-47c4-9cb8-c9027ee36d26} BrowserElementParent.js
contract @mozilla.org/browser-element-parent-factory;1 {ddeafdac-cb39-47c4-9cb8-c9027ee36d26}
category app-startup BrowserElementParentFactory service,@mozilla.org/browser-element-parent-factory;1

View File

@ -12,18 +12,13 @@ SOURCES += [
'BrowserElementParent.cpp',
]
XPIDL_SOURCES += [
'nsIBrowserElementAPI.idl',
]
XPIDL_MODULE = 'browser-element'
EXTRA_COMPONENTS += [
'BrowserElementParent.js',
'BrowserElementParent.manifest',
]
EXTRA_JS_MODULES += [
'BrowserElementParent.jsm',
'BrowserElementPromptService.jsm',
]

View File

@ -1,74 +0,0 @@
/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsIDOMDOMRequest;
interface nsIFrameLoader;
[scriptable, function, uuid(c0c2dd9b-41ef-42dd-a4c1-e456619c1941)]
interface nsIBrowserElementNextPaintListener : nsISupports
{
void recvNextPaint();
};
%{C++
#define BROWSER_ELEMENT_API_CONTRACTID "@mozilla.org/dom/browser-element-api;1"
#define BROWSER_ELEMENT_API_CID \
{ 0x651db7e3, 0x1734, 0x4536, \
{ 0xb1, 0x5a, 0x5b, 0x3a, 0xe6, 0x44, 0x13, 0x4c } }
%}
/**
* Interface to the BrowserElementParent implementation. All methods
* but setFrameLoader throw when the remote process is dead.
*/
[scriptable, uuid(abae4fb1-7d6f-4e3f-b435-6501f1d4c659)]
interface nsIBrowserElementAPI : nsISupports
{
void setFrameLoader(in nsIFrameLoader frameLoader);
void setVisible(in boolean visible);
nsIDOMDOMRequest getVisible();
void setActive(in boolean active);
boolean getActive();
void sendMouseEvent(in DOMString type,
in uint32_t x,
in uint32_t y,
in uint32_t button,
in uint32_t clickCount,
in uint32_t mifiers);
void sendTouchEvent(in DOMString aType,
[const, array, size_is(count)] in uint32_t aIdentifiers,
[const, array, size_is(count)] in int32_t aXs,
[const, array, size_is(count)] in int32_t aYs,
[const, array, size_is(count)] in uint32_t aRxs,
[const, array, size_is(count)] in uint32_t aRys,
[const, array, size_is(count)] in float aRotationAngles,
[const, array, size_is(count)] in float aForces,
in uint32_t count,
in long aModifiers);
void goBack();
void goForward();
void reload(in boolean hardReload);
void stop();
nsIDOMDOMRequest download(in DOMString url,
[optional] in jsval options);
nsIDOMDOMRequest purgeHistory();
nsIDOMDOMRequest getScreenshot(in uint32_t width,
in uint32_t height,
[optional] in DOMString mimeType);
void zoom(in float zoom);
nsIDOMDOMRequest getCanGoBack();
nsIDOMDOMRequest getCanGoForward();
nsIDOMDOMRequest getContentDimensions();
void addNextPaintListener(in nsIBrowserElementNextPaintListener listener);
void removeNextPaintListener(in nsIBrowserElementNextPaintListener listener);
nsIDOMDOMRequest setInputMethodActive(in boolean isActive);
};

View File

@ -112,7 +112,6 @@ EXPORTS.mozilla.dom += [
'HTMLVideoElement.h',
'ImageDocument.h',
'MediaError.h',
'nsBrowserElement.h',
'RadioNodeList.h',
'TextTrackManager.h',
'TimeRanges.h',
@ -191,7 +190,6 @@ UNIFIED_SOURCES += [
'ImageDocument.cpp',
'MediaDocument.cpp',
'MediaError.cpp',
'nsBrowserElement.cpp',
'nsDOMStringMap.cpp',
'nsFormSubmission.cpp',
'nsGenericHTMLElement.cpp',

View File

@ -1,542 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsBrowserElement.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/dom/BrowserElementBinding.h"
#include "mozilla/dom/DOMRequest.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsFrameLoader.h"
#include "nsIDOMDOMRequest.h"
#include "nsIDOMElement.h"
#include "nsINode.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIPrincipal.h"
#include "nsWeakReference.h"
using namespace mozilla::dom;
namespace mozilla {
static const char kRemoteBrowserPending[] = "remote-browser-pending";
static const char kInprocessBrowserShown[] = "inprocess-browser-shown";
class nsBrowserElement::BrowserShownObserver : public nsIObserver
, public nsSupportsWeakReference
{
public:
BrowserShownObserver(nsBrowserElement* aBrowserElement);
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
void AddObserver();
void RemoveObserver();
private:
virtual ~BrowserShownObserver();
// Weak reference to the browser element. nsBrowserElement has a
// reference to us. nsBrowserElement's destructor is responsible to
// null out this weak reference via RemoveObserver()
nsBrowserElement* mBrowserElement;
};
NS_IMPL_ISUPPORTS(nsBrowserElement::BrowserShownObserver, nsIObserver, nsISupportsWeakReference)
nsBrowserElement::BrowserShownObserver::BrowserShownObserver(nsBrowserElement* aBrowserElement)
: mBrowserElement(aBrowserElement)
{
}
nsBrowserElement::BrowserShownObserver::~BrowserShownObserver()
{
RemoveObserver();
}
NS_IMETHODIMP
nsBrowserElement::BrowserShownObserver::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData)
{
NS_ENSURE_TRUE(mBrowserElement, NS_OK);
if (!strcmp(aTopic, kRemoteBrowserPending) ||
!strcmp(aTopic, kInprocessBrowserShown)) {
nsCOMPtr<nsIFrameLoader> frameLoader = do_QueryInterface(aSubject);
nsCOMPtr<nsIFrameLoader> myFrameLoader = mBrowserElement->GetFrameLoader();
// The browser element API needs the frameloader to
// initialize. We still use the observer to get notified when the
// frameloader is created. So we check if the frameloader created
// is ours, then initialize the browser element API.
if (frameLoader && frameLoader == myFrameLoader) {
mBrowserElement->InitBrowserElementAPI();
}
}
return NS_OK;
}
void
nsBrowserElement::BrowserShownObserver::AddObserver()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
obs->AddObserver(this, kRemoteBrowserPending, true);
obs->AddObserver(this, kInprocessBrowserShown, true);
}
}
void
nsBrowserElement::BrowserShownObserver::RemoveObserver()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, kRemoteBrowserPending);
obs->RemoveObserver(this, kInprocessBrowserShown);
}
mBrowserElement = nullptr;
}
bool
nsBrowserElement::IsBrowserElementOrThrow(ErrorResult& aRv)
{
if (mBrowserElementAPI) {
return true;
}
aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
return false;
}
bool
nsBrowserElement::IsNotWidgetOrThrow(ErrorResult& aRv)
{
if (!mOwnerIsWidget) {
return true;
}
aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
return false;
}
void
nsBrowserElement::InitBrowserElementAPI()
{
bool isBrowserOrApp;
nsCOMPtr<nsIFrameLoader> frameLoader = GetFrameLoader();
NS_ENSURE_TRUE_VOID(frameLoader);
nsresult rv = frameLoader->GetOwnerIsBrowserOrAppFrame(&isBrowserOrApp);
NS_ENSURE_SUCCESS_VOID(rv);
rv = frameLoader->GetOwnerIsWidget(&mOwnerIsWidget);
NS_ENSURE_SUCCESS_VOID(rv);
if (!isBrowserOrApp) {
return;
}
mBrowserElementAPI = do_CreateInstance("@mozilla.org/dom/browser-element-api;1");
if (mBrowserElementAPI) {
mBrowserElementAPI->SetFrameLoader(frameLoader);
}
}
nsBrowserElement::nsBrowserElement()
: mOwnerIsWidget(false)
{
mObserver = new BrowserShownObserver(this);
mObserver->AddObserver();
}
nsBrowserElement::~nsBrowserElement()
{
mObserver->RemoveObserver();
}
void
nsBrowserElement::SetVisible(bool aVisible, ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
nsresult rv = mBrowserElementAPI->SetVisible(aVisible);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
already_AddRefed<DOMRequest>
nsBrowserElement::GetVisible(ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = mBrowserElementAPI->GetVisible(getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
void
nsBrowserElement::SetActive(bool aVisible, ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
nsresult rv = mBrowserElementAPI->SetActive(aVisible);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
bool
nsBrowserElement::GetActive(ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), false);
bool isActive;
nsresult rv = mBrowserElementAPI->GetActive(&isActive);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return false;
}
return isActive;
}
void
nsBrowserElement::SendMouseEvent(const nsAString& aType,
uint32_t aX,
uint32_t aY,
uint32_t aButton,
uint32_t aClickCount,
uint32_t aModifiers,
ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
nsresult rv = mBrowserElementAPI->SendMouseEvent(aType,
aX,
aY,
aButton,
aClickCount,
aModifiers);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
void
nsBrowserElement::SendTouchEvent(const nsAString& aType,
const Sequence<uint32_t>& aIdentifiers,
const Sequence<int32_t>& aXs,
const Sequence<int32_t>& aYs,
const Sequence<uint32_t>& aRxs,
const Sequence<uint32_t>& aRys,
const Sequence<float>& aRotationAngles,
const Sequence<float>& aForces,
uint32_t aCount,
uint32_t aModifiers,
ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
if (aIdentifiers.Length() != aCount ||
aXs.Length() != aCount ||
aYs.Length() != aCount ||
aRxs.Length() != aCount ||
aRys.Length() != aCount ||
aRotationAngles.Length() != aCount ||
aForces.Length() != aCount) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return;
}
nsresult rv = mBrowserElementAPI->SendTouchEvent(aType,
aIdentifiers.Elements(),
aXs.Elements(),
aYs.Elements(),
aRxs.Elements(),
aRys.Elements(),
aRotationAngles.Elements(),
aForces.Elements(),
aCount,
aModifiers);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
void
nsBrowserElement::GoBack(ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
nsresult rv = mBrowserElementAPI->GoBack();
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
void
nsBrowserElement::GoForward(ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
nsresult rv = mBrowserElementAPI->GoForward();
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
void
nsBrowserElement::Reload(bool aHardReload, ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
nsresult rv = mBrowserElementAPI->Reload(aHardReload);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
void
nsBrowserElement::Stop(ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
nsresult rv = mBrowserElementAPI->Stop();
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
already_AddRefed<DOMRequest>
nsBrowserElement::Download(const nsAString& aUrl,
const BrowserElementDownloadOptions& aOptions,
ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
AutoJSAPI jsapi;
jsapi.Init();
JS::Rooted<JS::Value> options(jsapi.cx());
if (!ToJSValue(jsapi.cx(), aOptions, &options)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsresult rv = mBrowserElementAPI->Download(aUrl, options, getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
already_AddRefed<DOMRequest>
nsBrowserElement::PurgeHistory(ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = mBrowserElementAPI->PurgeHistory(getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
already_AddRefed<DOMRequest>
nsBrowserElement::GetScreenshot(uint32_t aWidth,
uint32_t aHeight,
const nsAString& aMimeType,
ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = mBrowserElementAPI->GetScreenshot(aWidth, aHeight, aMimeType,
getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
if (rv == NS_ERROR_INVALID_ARG) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
} else {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
void
nsBrowserElement::Zoom(float aZoom, ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
NS_ENSURE_TRUE_VOID(IsNotWidgetOrThrow(aRv));
nsresult rv = mBrowserElementAPI->Zoom(aZoom);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
already_AddRefed<DOMRequest>
nsBrowserElement::GetCanGoBack(ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = mBrowserElementAPI->GetCanGoBack(getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
already_AddRefed<DOMRequest>
nsBrowserElement::GetCanGoForward(ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = mBrowserElementAPI->GetCanGoForward(getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
already_AddRefed<DOMRequest>
nsBrowserElement::GetContentDimensions(ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
NS_ENSURE_TRUE(IsNotWidgetOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = mBrowserElementAPI->GetContentDimensions(getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
void
nsBrowserElement::AddNextPaintListener(BrowserElementNextPaintEventCallback& aListener,
ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
CallbackObjectHolder<BrowserElementNextPaintEventCallback,
nsIBrowserElementNextPaintListener> holder(&aListener);
nsCOMPtr<nsIBrowserElementNextPaintListener> listener = holder.ToXPCOMCallback();
nsresult rv = mBrowserElementAPI->AddNextPaintListener(listener);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
void
nsBrowserElement::RemoveNextPaintListener(BrowserElementNextPaintEventCallback& aListener,
ErrorResult& aRv)
{
NS_ENSURE_TRUE_VOID(IsBrowserElementOrThrow(aRv));
CallbackObjectHolder<BrowserElementNextPaintEventCallback,
nsIBrowserElementNextPaintListener> holder(&aListener);
nsCOMPtr<nsIBrowserElementNextPaintListener> listener = holder.ToXPCOMCallback();
nsresult rv = mBrowserElementAPI->RemoveNextPaintListener(listener);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
}
already_AddRefed<DOMRequest>
nsBrowserElement::SetInputMethodActive(bool aIsActive,
ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
nsCOMPtr<nsIFrameLoader> frameLoader = GetFrameLoader();
if (!frameLoader) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIDOMElement> ownerElement;
nsresult rv = frameLoader->GetOwnerElement(getter_AddRefs(ownerElement));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
nsCOMPtr<nsINode> node = do_QueryInterface(ownerElement);
nsCOMPtr<nsIPrincipal> principal = node->NodePrincipal();
if (!nsContentUtils::IsExactSitePermAllow(principal, "input-manage")) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return nullptr;
}
nsCOMPtr<nsIDOMDOMRequest> req;
rv = mBrowserElementAPI->SetInputMethodActive(aIsActive,
getter_AddRefs(req));
if (NS_WARN_IF(NS_FAILED(rv))) {
if (rv == NS_ERROR_INVALID_ARG) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
} else {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
}
return nullptr;
}
return req.forget().downcast<DOMRequest>();
}
} // namespace mozilla

View File

@ -1,109 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsBrowserElement_h
#define nsBrowserElement_h
#include "mozilla/dom/BindingDeclarations.h"
#include "nsCOMPtr.h"
#include "nsIBrowserElementAPI.h"
class nsFrameLoader;
class nsIObserver;
namespace mozilla {
namespace dom {
struct BrowserElementDownloadOptions;
class BrowserElementNextPaintEventCallback;
class DOMRequest;
} // namespace dom
class ErrorResult;
/**
* A helper class for browser-element frames
*/
class nsBrowserElement
{
public:
nsBrowserElement();
virtual ~nsBrowserElement();
void SetVisible(bool aVisible, ErrorResult& aRv);
already_AddRefed<dom::DOMRequest> GetVisible(ErrorResult& aRv);
void SetActive(bool aActive, ErrorResult& aRv);
bool GetActive(ErrorResult& aRv);
void SendMouseEvent(const nsAString& aType,
uint32_t aX,
uint32_t aY,
uint32_t aButton,
uint32_t aClickCount,
uint32_t aModifiers,
ErrorResult& aRv);
void SendTouchEvent(const nsAString& aType,
const dom::Sequence<uint32_t>& aIdentifiers,
const dom::Sequence<int32_t>& aX,
const dom::Sequence<int32_t>& aY,
const dom::Sequence<uint32_t>& aRx,
const dom::Sequence<uint32_t>& aRy,
const dom::Sequence<float>& aRotationAngles,
const dom::Sequence<float>& aForces,
uint32_t aCount,
uint32_t aModifiers,
ErrorResult& aRv);
void GoBack(ErrorResult& aRv);
void GoForward(ErrorResult& aRv);
void Reload(bool aHardReload, ErrorResult& aRv);
void Stop(ErrorResult& aRv);
already_AddRefed<dom::DOMRequest>
Download(const nsAString& aUrl,
const dom::BrowserElementDownloadOptions& options,
ErrorResult& aRv);
already_AddRefed<dom::DOMRequest> PurgeHistory(ErrorResult& aRv);
already_AddRefed<dom::DOMRequest>
GetScreenshot(uint32_t aWidth,
uint32_t aHeight,
const nsAString& aMimeType,
ErrorResult& aRv);
void Zoom(float aZoom, ErrorResult& aRv);
already_AddRefed<dom::DOMRequest> GetCanGoBack(ErrorResult& aRv);
already_AddRefed<dom::DOMRequest> GetCanGoForward(ErrorResult& aRv);
already_AddRefed<dom::DOMRequest> GetContentDimensions(ErrorResult& aRv);
void AddNextPaintListener(dom::BrowserElementNextPaintEventCallback& listener,
ErrorResult& aRv);
void RemoveNextPaintListener(dom::BrowserElementNextPaintEventCallback& listener,
ErrorResult& aRv);
already_AddRefed<dom::DOMRequest> SetInputMethodActive(bool isActive,
ErrorResult& aRv);
protected:
NS_IMETHOD_(already_AddRefed<nsFrameLoader>) GetFrameLoader() = 0;
nsCOMPtr<nsIBrowserElementAPI> mBrowserElementAPI;
private:
void InitBrowserElementAPI();
bool IsBrowserElementOrThrow(ErrorResult& aRv);
bool IsNotWidgetOrThrow(ErrorResult& aRv);
bool mOwnerIsWidget;
class BrowserShownObserver;
friend class BrowserShownObserver;
nsRefPtr<BrowserShownObserver> mObserver;
};
} // namespace mozilla
#endif // nsBrowserElement_h

View File

@ -34,7 +34,6 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericHTMLFrameElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGenericHTMLFrameElement,
nsGenericHTMLElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameLoader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserElementAPI)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsGenericHTMLFrameElement, nsGenericHTMLElement)
@ -307,10 +306,6 @@ nsGenericHTMLFrameElement::GetReallyIsBrowserOrApp(bool *aOut)
uint32_t permission = nsIPermissionManager::DENY_ACTION;
nsresult rv = permMgr->TestPermissionFromPrincipal(principal, "browser", &permission);
NS_ENSURE_SUCCESS(rv, NS_OK);
if (permission != nsIPermissionManager::ALLOW_ACTION) {
rv = permMgr->TestPermissionFromPrincipal(principal, "embed-widgets", &permission);
NS_ENSURE_SUCCESS(rv, NS_OK);
}
*aOut = permission == nsIPermissionManager::ALLOW_ACTION;
return NS_OK;
}

View File

@ -9,15 +9,14 @@
#define nsGenericHTMLFrameElement_h
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/nsBrowserElement.h"
#include "nsElementFrameLoaderOwner.h"
#include "nsFrameLoader.h"
#include "nsGenericHTMLElement.h"
#include "nsIDOMEventListener.h"
#include "nsIFrameLoader.h"
#include "nsIMozBrowserFrame.h"
#include "nsIDOMEventListener.h"
#include "mozilla/ErrorResult.h"
#include "nsFrameLoader.h"
class nsXULElement;
@ -26,7 +25,6 @@ class nsXULElement;
*/
class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
public nsElementFrameLoaderOwner,
public mozilla::nsBrowserElement,
public nsIMozBrowserFrame
{
public:
@ -34,7 +32,6 @@ public:
mozilla::dom::FromParser aFromParser)
: nsGenericHTMLElement(aNodeInfo)
, nsElementFrameLoaderOwner(aFromParser)
, nsBrowserElement()
{
}
@ -74,19 +71,6 @@ public:
static bool BrowserFramesEnabled();
/**
* nsIFrameLoaderOwner defines two GetFrameLoader() overloads. One
* is XPCOM style interface, the other one is C++ only. "using" pulls
* them both in, now GetFrameLoader() is ambiguous because
* nsBrowserElement also has GetFrameLoader(). Explicit redefine
* GetFrameLoader() to choose nsElementFrameLoaderOwner::GetFrameLoader()
*/
using nsElementFrameLoaderOwner::GetFrameLoader;
NS_IMETHOD_(already_AddRefed<nsFrameLoader>) GetFrameLoader() MOZ_OVERRIDE
{
return nsElementFrameLoaderOwner::GetFrameLoader();
}
/**
* Helper method to map a HTML 'scrolling' attribute value to a nsIScrollable
* enum value. scrolling="no" (and its synonyms) maps to

View File

@ -1,142 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
callback BrowserElementNextPaintEventCallback = void ();
dictionary BrowserElementDownloadOptions {
DOMString? filename;
};
[NoInterfaceObject]
interface BrowserElement {
};
BrowserElement implements BrowserElementCommon;
BrowserElement implements BrowserElementPrivileged;
[NoInterfaceObject]
interface BrowserElementCommon {
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser embed-widgets"]
void setVisible(boolean visible);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser embed-widgets"]
DOMRequest getVisible();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser embed-widgets"]
void setActive(boolean active);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser embed-widgets"]
boolean getActive();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser embed-widgets"]
void addNextPaintListener(BrowserElementNextPaintEventCallback listener);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser embed-widgets"]
void removeNextPaintListener(BrowserElementNextPaintEventCallback listener);
};
[NoInterfaceObject]
interface BrowserElementPrivileged {
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
void sendMouseEvent(DOMString type,
unsigned long x,
unsigned long y,
unsigned long button,
unsigned long clickCount,
unsigned long modifiers);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
Func="TouchEvent::PrefEnabled",
CheckPermissions="browser"]
void sendTouchEvent(DOMString type,
sequence<unsigned long> identifiers,
sequence<long> x,
sequence<long> y,
sequence<unsigned long> rx,
sequence<unsigned long> ry,
sequence<float> rotationAngles,
sequence<float> forces,
unsigned long count,
unsigned long modifiers);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
void goBack();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
void goForward();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
void reload(optional boolean hardReload = false);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
void stop();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
DOMRequest download(DOMString url,
optional BrowserElementDownloadOptions options);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
DOMRequest purgeHistory();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
DOMRequest getScreenshot([EnforceRange] unsigned long width,
[EnforceRange] unsigned long height,
optional DOMString mimeType="");
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
void zoom(float zoom);
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
DOMRequest getCanGoBack();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
DOMRequest getCanGoForward();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
DOMRequest getContentDimensions();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckPermissions="browser"]
DOMRequest setInputMethodActive(boolean isActive);
};

View File

@ -63,4 +63,3 @@ partial interface HTMLIFrameElement {
};
HTMLIFrameElement implements MozFrameLoaderOwner;
HTMLIFrameElement implements BrowserElement;

View File

@ -55,7 +55,6 @@ WEBIDL_FILES = [
'BiquadFilterNode.webidl',
'Blob.webidl',
'BoxObject.webidl',
'BrowserElement.webidl',
'BrowserElementDictionaries.webidl',
'CallsList.webidl',
'CameraCapabilities.webidl',

View File

@ -117,7 +117,6 @@
@BINPATH@/components/autocomplete.xpt
@BINPATH@/components/autoconfig.xpt
@BINPATH@/components/browsercompsbase.xpt
@BINPATH@/components/browser-element.xpt
@BINPATH@/components/browser-feeds.xpt
@BINPATH@/components/caps.xpt
@BINPATH@/components/chardet.xpt