Backed out changeset d045286cff6e (original backout of 8 changesets) for not working right a=backout

This commit is contained in:
Wes Kocher
2014-11-17 22:19:49 -08:00
parent df63c516ef
commit 18435c6ea3
19 changed files with 1287 additions and 387 deletions

View File

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

View File

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

View File

@@ -0,0 +1,231 @@
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,6 +17,7 @@ support-files =
file_packaged_app.template.webapp file_packaged_app.template.webapp
file_widget_app.template.webapp file_widget_app.template.webapp
file_widget_app.template.html file_widget_app.template.html
file_test_widget.js
signed_app.sjs signed_app.sjs
signed_app_template.webapp signed_app_template.webapp
signed/* signed/*
@@ -44,3 +45,5 @@ skip-if = (toolkit == 'android' && processor == 'x86') #x86 only
[test_web_app_install.html] [test_web_app_install.html]
[test_widget.html] [test_widget.html]
skip-if = os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app 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,231 +4,14 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Test for DataStore - basic operation on a readonly db</title> <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="/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"/> <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head> </head>
<body> <body>
<div id="container"></div> <div id="container"></div>
<script type="application/javascript;version=1.7"> <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(); SimpleTest.waitForExplicitFinish();
gHasBrowserPermission = false;
runTest(); runTest();
</script> </script>
</body> </body>

View File

@@ -0,0 +1,18 @@
<!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,8 +14,6 @@ let Cr = Components.results;
* appropriate action here in the parent. * appropriate action here in the parent.
*/ */
this.EXPORTED_SYMBOLS = ["BrowserElementParentBuilder"];
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/BrowserElementPromptService.jsm"); Cu.import("resource://gre/modules/BrowserElementPromptService.jsm");
@@ -25,10 +23,8 @@ XPCOMUtils.defineLazyGetter(this, "DOMApplicationRegistry", function () {
return DOMApplicationRegistry; return DOMApplicationRegistry;
}); });
const TOUCH_EVENTS_ENABLED_PREF = "dom.w3c_touch_events.enabled";
function debug(msg) { function debug(msg) {
//dump("BrowserElementParent.jsm - " + msg + "\n"); //dump("BrowserElementParent - " + msg + "\n");
} }
function getIntPref(prefName, def) { function getIntPref(prefName, def) {
@@ -59,101 +55,57 @@ function visibilityChangeHandler(e) {
} }
} }
this.BrowserElementParentBuilder = { function defineNoReturnMethod(fn) {
create: function create(frameLoader, hasRemoteFrame, isPendingFrame) { return function method() {
return new BrowserElementParent(frameLoader, hasRemoteFrame); 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);
}
};
} }
function BrowserElementParent(frameLoader, hasRemoteFrame, isPendingFrame) { function defineDOMRequestMethod(msgName) {
debug("Creating new BrowserElementParent object for " + frameLoader); return function() {
return this._sendDOMRequest(msgName);
};
}
function BrowserElementParent() {
debug("Creating new BrowserElementParent object");
this._domRequestCounter = 0; this._domRequestCounter = 0;
this._domRequestReady = false; this._domRequestReady = false;
this._pendingAPICalls = []; this._pendingAPICalls = [];
this._pendingDOMRequests = {}; this._pendingDOMRequests = {};
this._pendingSetInputMethodActive = []; this._pendingSetInputMethodActive = [];
this._hasRemoteFrame = hasRemoteFrame;
this._nextPaintListeners = []; 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, 'ask-children-to-exit-fullscreen', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'oop-frameloader-crashed', /* ownsWeak = */ true); Services.obs.addObserver(this, 'oop-frameloader-crashed', /* ownsWeak = */ true);
Services.obs.addObserver(this, 'copypaste-docommand', /* 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) { BrowserElementParent.prototype = {
XPCNativeWrapper.unwrap(self._frameElement)[name] = Cu.exportFunction(function method() {
if (!self._domRequestReady) { classDescription: "BrowserElementAPI implementation",
// Remote browser haven't been created, we just queue the API call. classID: Components.ID("{9f171ac4-0939-4ef8-b360-3408aedc3060}"),
let args = Array.slice(arguments); contractID: "@mozilla.org/dom/browser-element-api;1",
args.unshift(self); QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserElementAPI,
self._pendingAPICalls.push(method.bind.apply(fn, args)); 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; 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 // 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 // changes down to the child. We want to do this while registering as few
// visibilitychange listeners on _window as possible, because such a listener // visibilitychange listeners on _window as possible, because such a listener
@@ -176,20 +128,9 @@ function BrowserElementParent(frameLoader, hasRemoteFrame, isPendingFrame) {
// Insert ourself into the prompt service. // Insert ourself into the prompt service.
BrowserElementPromptService.mapFrameToBrowserElementParent(this._frameElement, this); BrowserElementPromptService.mapFrameToBrowserElementParent(this._frameElement, this);
if (!isPendingFrame) {
this._setupMessageListener(); this._setupMessageListener();
this._registerAppManifest(); 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 = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
_runPendingAPICall: function() { _runPendingAPICall: function() {
if (!this._pendingAPICalls) { if (!this._pendingAPICalls) {
@@ -592,20 +533,27 @@ BrowserElementParent.prototype = {
} }
}, },
_setVisible: function(visible) { setVisible: defineNoReturnMethod(function(visible) {
this._sendAsyncMsg('set-visible', {visible: visible}); this._sendAsyncMsg('set-visible', {visible: visible});
this._frameLoader.visible = visible; this._frameLoader.visible = visible;
}, }),
_setActive: function(active) { getVisible: defineDOMRequestMethod('get-visible'),
setActive: defineNoReturnMethod(function(active) {
this._frameLoader.visible = 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; return this._frameLoader.visible;
}, },
_sendMouseEvent: function(type, x, y, button, clickCount, modifiers) { sendMouseEvent: defineNoReturnMethod(function(type, x, y, button, clickCount, modifiers) {
this._sendAsyncMsg("send-mouse-event", { this._sendAsyncMsg("send-mouse-event", {
"type": type, "type": type,
"x": x, "x": x,
@@ -614,9 +562,9 @@ BrowserElementParent.prototype = {
"clickCount": clickCount, "clickCount": clickCount,
"modifiers": modifiers "modifiers": modifiers
}); });
}, }),
_sendTouchEvent: function(type, identifiers, touchesX, touchesY, sendTouchEvent: defineNoReturnMethod(function(type, identifiers, touchesX, touchesY,
radiisX, radiisY, rotationAngles, forces, radiisX, radiisY, rotationAngles, forces,
count, modifiers) { count, modifiers) {
@@ -646,35 +594,45 @@ BrowserElementParent.prototype = {
"modifiers": modifiers "modifiers": modifiers
}); });
} }
}, }),
_goBack: function() { getCanGoBack: defineDOMRequestMethod('get-can-go-back'),
getCanGoForward: defineDOMRequestMethod('get-can-go-forward'),
getContentDimensions: defineDOMRequestMethod('get-contentdimensions'),
goBack: defineNoReturnMethod(function() {
this._sendAsyncMsg('go-back'); this._sendAsyncMsg('go-back');
}, }),
_goForward: function() { goForward: defineNoReturnMethod(function() {
this._sendAsyncMsg('go-forward'); this._sendAsyncMsg('go-forward');
}, }),
_reload: function(hardReload) { reload: defineNoReturnMethod(function(hardReload) {
this._sendAsyncMsg('reload', {hardReload: hardReload}); this._sendAsyncMsg('reload', {hardReload: hardReload});
}, }),
_stop: function() { stop: defineNoReturnMethod(function() {
this._sendAsyncMsg('stop'); this._sendAsyncMsg('stop');
}, }),
/* /*
* The valid range of zoom scale is defined in preference "zoom.maxPercent" and "zoom.minPercent". * The valid range of zoom scale is defined in preference "zoom.maxPercent" and "zoom.minPercent".
*/ */
_zoom: function(zoom) { zoom: defineNoReturnMethod(function(zoom) {
zoom *= 100; zoom *= 100;
zoom = Math.min(getIntPref("zoom.maxPercent", 300), zoom); zoom = Math.min(getIntPref("zoom.maxPercent", 300), zoom);
zoom = Math.max(getIntPref("zoom.minPercent", 50), zoom); zoom = Math.max(getIntPref("zoom.minPercent", 50), zoom);
this._sendAsyncMsg('zoom', {zoom: zoom / 100.0}); this._sendAsyncMsg('zoom', {zoom: zoom / 100.0});
}, }),
_download: function(_url, _options) { purgeHistory: defineDOMRequestMethod('purge-history'),
download: function(_url, _options) {
if (!this._isAlive()) {
return null;
}
let ioService = let ioService =
Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService); Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
let uri = ioService.newURI(_url, null, null); let uri = ioService.newURI(_url, null, null);
@@ -794,7 +752,12 @@ BrowserElementParent.prototype = {
return req; return req;
}, },
_getScreenshot: function(_width, _height, _mimeType) { getScreenshot: function(_width, _height, _mimeType) {
if (!this._isAlive()) {
throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
let width = parseInt(_width); let width = parseInt(_width);
let height = parseInt(_height); let height = parseInt(_height);
let mimeType = (typeof _mimeType === 'string') ? let mimeType = (typeof _mimeType === 'string') ?
@@ -814,16 +777,18 @@ BrowserElementParent.prototype = {
this._nextPaintListeners = []; this._nextPaintListeners = [];
for (let listener of listeners) { for (let listener of listeners) {
try { try {
listener(); listener.recvNextPaint();
} catch (e) { } catch (e) {
// If a listener throws we'll continue. // If a listener throws we'll continue.
} }
} }
}, },
_addNextPaintListener: function(listener) { addNextPaintListener: function(listener) {
if (typeof listener != 'function') if (!this._isAlive()) {
throw Components.Exception("Invalid argument", Cr.NS_ERROR_INVALID_ARG); throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
let self = this; let self = this;
let run = function() { let run = function() {
@@ -837,9 +802,11 @@ BrowserElementParent.prototype = {
} }
}, },
_removeNextPaintListener: function(listener) { removeNextPaintListener: function(listener) {
if (typeof listener != 'function') if (!this._isAlive()) {
throw Components.Exception("Invalid argument", Cr.NS_ERROR_INVALID_ARG); throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
let self = this; let self = this;
let run = function() { let run = function() {
@@ -860,7 +827,12 @@ BrowserElementParent.prototype = {
} }
}, },
_setInputMethodActive: function(isActive) { setInputMethodActive: function(isActive) {
if (!this._isAlive()) {
throw Components.Exception("Dead content process",
Cr.NS_ERROR_DOM_INVALID_STATE_ERR);
}
if (typeof isActive !== 'boolean') { if (typeof isActive !== 'boolean') {
throw Components.Exception("Invalid argument", throw Components.Exception("Invalid argument",
Cr.NS_ERROR_INVALID_ARG); Cr.NS_ERROR_INVALID_ARG);
@@ -922,18 +894,10 @@ BrowserElementParent.prototype = {
case 'ask-children-to-exit-fullscreen': case 'ask-children-to-exit-fullscreen':
if (this._isAlive() && if (this._isAlive() &&
this._frameElement.ownerDocument == subject && this._frameElement.ownerDocument == subject &&
this._hasRemoteFrame) { this._frameLoader.QueryInterface(Ci.nsIFrameLoader).tabParent) {
this._sendAsyncMsg('exit-fullscreen'); this._sendAsyncMsg('exit-fullscreen');
} }
break; 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': case 'copypaste-docommand':
if (this._isAlive() && this._frameElement.isEqualNode(subject.wrappedJSObject)) { if (this._isAlive() && this._frameElement.isEqualNode(subject.wrappedJSObject)) {
this._sendAsyncMsg('do-command', { command: data }); this._sendAsyncMsg('do-command', { command: data });
@@ -945,3 +909,5 @@ BrowserElementParent.prototype = {
}; };
}, },
}; };
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([BrowserElementParent]);

View File

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

View File

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

View File

@@ -0,0 +1,74 @@
/* -*- 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,6 +112,7 @@ EXPORTS.mozilla.dom += [
'HTMLVideoElement.h', 'HTMLVideoElement.h',
'ImageDocument.h', 'ImageDocument.h',
'MediaError.h', 'MediaError.h',
'nsBrowserElement.h',
'RadioNodeList.h', 'RadioNodeList.h',
'TextTrackManager.h', 'TextTrackManager.h',
'TimeRanges.h', 'TimeRanges.h',
@@ -190,6 +191,7 @@ UNIFIED_SOURCES += [
'ImageDocument.cpp', 'ImageDocument.cpp',
'MediaDocument.cpp', 'MediaDocument.cpp',
'MediaError.cpp', 'MediaError.cpp',
'nsBrowserElement.cpp',
'nsDOMStringMap.cpp', 'nsDOMStringMap.cpp',
'nsFormSubmission.cpp', 'nsFormSubmission.cpp',
'nsGenericHTMLElement.cpp', 'nsGenericHTMLElement.cpp',

View File

@@ -0,0 +1,542 @@
/* -*- 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

109
dom/html/nsBrowserElement.h Normal file
View File

@@ -0,0 +1,109 @@
/* -*- 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,6 +34,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericHTMLFrameElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGenericHTMLFrameElement, NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGenericHTMLFrameElement,
nsGenericHTMLElement) nsGenericHTMLElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameLoader) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameLoader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserElementAPI)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsGenericHTMLFrameElement, nsGenericHTMLElement) NS_IMPL_ADDREF_INHERITED(nsGenericHTMLFrameElement, nsGenericHTMLElement)
@@ -306,6 +307,10 @@ nsGenericHTMLFrameElement::GetReallyIsBrowserOrApp(bool *aOut)
uint32_t permission = nsIPermissionManager::DENY_ACTION; uint32_t permission = nsIPermissionManager::DENY_ACTION;
nsresult rv = permMgr->TestPermissionFromPrincipal(principal, "browser", &permission); nsresult rv = permMgr->TestPermissionFromPrincipal(principal, "browser", &permission);
NS_ENSURE_SUCCESS(rv, NS_OK); 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; *aOut = permission == nsIPermissionManager::ALLOW_ACTION;
return NS_OK; return NS_OK;
} }

View File

@@ -9,14 +9,15 @@
#define nsGenericHTMLFrameElement_h #define nsGenericHTMLFrameElement_h
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/nsBrowserElement.h"
#include "nsElementFrameLoaderOwner.h" #include "nsElementFrameLoaderOwner.h"
#include "nsFrameLoader.h"
#include "nsGenericHTMLElement.h" #include "nsGenericHTMLElement.h"
#include "nsIDOMEventListener.h"
#include "nsIFrameLoader.h" #include "nsIFrameLoader.h"
#include "nsIMozBrowserFrame.h" #include "nsIMozBrowserFrame.h"
#include "nsIDOMEventListener.h"
#include "mozilla/ErrorResult.h"
#include "nsFrameLoader.h"
class nsXULElement; class nsXULElement;
@@ -25,6 +26,7 @@ class nsXULElement;
*/ */
class nsGenericHTMLFrameElement : public nsGenericHTMLElement, class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
public nsElementFrameLoaderOwner, public nsElementFrameLoaderOwner,
public mozilla::nsBrowserElement,
public nsIMozBrowserFrame public nsIMozBrowserFrame
{ {
public: public:
@@ -32,6 +34,7 @@ public:
mozilla::dom::FromParser aFromParser) mozilla::dom::FromParser aFromParser)
: nsGenericHTMLElement(aNodeInfo) : nsGenericHTMLElement(aNodeInfo)
, nsElementFrameLoaderOwner(aFromParser) , nsElementFrameLoaderOwner(aFromParser)
, nsBrowserElement()
{ {
} }
@@ -71,6 +74,19 @@ public:
static bool BrowserFramesEnabled(); 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 * Helper method to map a HTML 'scrolling' attribute value to a nsIScrollable
* enum value. scrolling="no" (and its synonyms) maps to * enum value. scrolling="no" (and its synonyms) maps to

View File

@@ -0,0 +1,142 @@
/* -*- 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,3 +63,4 @@ partial interface HTMLIFrameElement {
}; };
HTMLIFrameElement implements MozFrameLoaderOwner; HTMLIFrameElement implements MozFrameLoaderOwner;
HTMLIFrameElement implements BrowserElement;

View File

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

View File

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