Bug 1169633 - [Browser API] getWebManifest(). r=kanru, r=bholley

This commit is contained in:
Marcos Caceres 2015-11-03 03:52:00 +01:00
parent 66acd27cd3
commit 9859867e5b
14 changed files with 181 additions and 5 deletions

View File

@ -19,6 +19,11 @@ Cu.import("resource://gre/modules/ExtensionContent.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "acs",
"@mozilla.org/audiochannel/service;1",
"nsIAudioChannelService");
XPCOMUtils.defineLazyModuleGetter(this, "ManifestFinder",
"resource://gre/modules/ManifestFinder.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ManifestObtainer",
"resource://gre/modules/ManifestObtainer.jsm");
var kLongestReturnedString = 128;
@ -289,7 +294,8 @@ BrowserElementChild.prototype = {
"get-audio-channel-muted": this._recvGetAudioChannelMuted,
"set-audio-channel-muted": this._recvSetAudioChannelMuted,
"get-is-audio-channel-active": this._recvIsAudioChannelActive,
"get-structured-data": this._recvGetStructuredData
"get-structured-data": this._recvGetStructuredData,
"get-web-manifest": this._recvGetWebManifest,
}
addMessageListener("browser-element-api:call", function(aMessage) {
@ -1527,7 +1533,26 @@ BrowserElementChild.prototype = {
id: data.json.id, successRv: active
});
},
_recvGetWebManifest: Task.async(function* (data) {
debug(`Received GetWebManifest message: (${data.json.id})`);
let manifest = null;
let hasManifest = ManifestFinder.contentHasManifestLink(content);
if (hasManifest) {
try {
manifest = yield ManifestObtainer.contentObtainManifest(content);
} catch (e) {
sendAsyncMsg('got-web-manifest', {
id: data.json.id,
errorMsg: `Error fetching web manifest: ${e}.`,
});
return;
}
}
sendAsyncMsg('got-web-manifest', {
id: data.json.id,
successRv: manifest
});
}),
_initFinder: function() {
if (!this._finder) {
try {

View File

@ -385,7 +385,8 @@ BrowserElementParent.prototype = {
"got-audio-channel-muted": this._gotDOMRequestResult,
"got-set-audio-channel-muted": this._gotDOMRequestResult,
"got-is-audio-channel-active": this._gotDOMRequestResult,
"got-structured-data": this._gotDOMRequestResult
"got-structured-data": this._gotDOMRequestResult,
"got-web-manifest": this._gotDOMRequestResult,
};
let mmSecuritySensitiveCalls = {
@ -1209,6 +1210,7 @@ BrowserElementParent.prototype = {
getStructuredData: defineDOMRequestMethod('get-structured-data'),
getWebManifest: defineDOMRequestMethod('get-web-manifest'),
/**
* Called when the visibility of the window which owns this iframe changes.
*/

View File

@ -0,0 +1,65 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/*globals async, ok, is, SimpleTest, browserElementTestHelpers*/
// Bug 1169633 - getWebManifest tests
'use strict';
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
// request to load a manifest from a page that doesn't have a manifest.
// The expected result to be null.
var test1 = async(function* () {
var manifest = yield requestManifest('file_empty.html');
is(manifest, null, 'it should be null.');
});
// request to load a manifest from a page that has a manifest.
// The expected manifest to have a property name whose value is 'pass'.
var test2 = async(function* () {
var manifest = yield requestManifest('file_web_manifest.html');
is(manifest && manifest.name, 'pass', 'it should return a manifest with name pass.');
});
// Cause an exception by attempting to fetch a file URL,
// expect onerror to be called.
var test3 = async(function* () {
var gotError = false;
try {
yield requestManifest('file_illegal_web_manifest.html');
} catch (err) {
gotError = true;
}
ok(gotError, 'onerror was called on the DOMRequest.');
});
// Run the tests
addEventListener('testready', () => {
Promise
.all([test1(), test2(), test3()])
.then(SimpleTest.finish);
});
function requestManifest(url) {
var iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
iframe.src = url;
document.body.appendChild(iframe);
return new Promise((resolve, reject) => {
iframe.addEventListener('mozbrowserloadend', function loadend() {
iframe.removeEventListener('mozbrowserloadend', loadend);
SimpleTest.executeSoon(() => {
var req = iframe.getWebManifest();
req.onsuccess = () => {
document.body.removeChild(iframe);
resolve(req.result);
};
req.onerror = () => {
document.body.removeChild(iframe);
reject(new Error(req.error));
};
});
});
});
}

View File

@ -0,0 +1,6 @@
<!doctype html>
<meta charset=utf-8>
<head>
<link rel="manifest" href="file://this_is_not_allowed!">
</head>
<h1>Support Page for Web Manifest Tests</h1>

View File

@ -0,0 +1,6 @@
<!doctype html>
<meta charset=utf-8>
<head>
<link rel="manifest" href="file_web_manifest.json">
</head>
<h1>Support Page for Web Manifest Tests</h1>

View File

@ -0,0 +1 @@
{"name": "pass"}

View File

@ -119,3 +119,4 @@ disabled = bug 924771
[test_browserElement_oop_GetContentDimensions.html]
[test_browserElement_oop_AudioChannel.html]
[test_browserElement_oop_SetNFCFocus.html]
[test_browserElement_oop_getWebManifest.html]

View File

@ -39,6 +39,7 @@ support-files =
browserElement_GetScreenshot.js
browserElement_GetScreenshotDppx.js
browserElement_getStructuredData.js
browserElement_getWebManifest.js
browserElement_Iconchange.js
browserElement_LoadEvents.js
browserElement_Manifestchange.js
@ -136,10 +137,14 @@ support-files =
file_wyciwyg.html
file_audio.html
iframe_file_audio.html
file_web_manifest.html
file_web_manifest.json
file_illegal_web_manifest.html
# Note: browserElementTestHelpers.js looks at the test's filename to determine
# whether the test should be OOP. "_oop_" signals OOP, "_inproc_" signals in
# process. Default is OOP.
[test_browserElement_inproc_getWebManifest.html]
[test_browserElement_NoAttr.html]
[test_browserElement_NoPref.html]
[test_browserElement_NoPermission.html]

View File

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 1169633</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/dom/browser-element/mochitest/browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.8"
src="async.js">
</script>
<script type="application/javascript;version=1.8"
src="browserElement_getWebManifest.js">
</script>
</body>
</html>

View File

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 1169633</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/dom/browser-element/mochitest/browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.8"
src="async.js"></script>
<script type="application/javascript;version=1.8"
src="browserElement_getWebManifest.js">
</script>
</body>
</html>

View File

@ -9,7 +9,7 @@
interface nsIDOMDOMRequest;
interface nsIFrameLoader;
[scriptable, function, uuid(c0c2dd9b-41ef-42dd-a4c1-e456619c1941)]
[scriptable, function, uuid(00d0e19d-bd67-491f-8e85-b9905224d3bb)]
interface nsIBrowserElementNextPaintListener : nsISupports
{
void recvNextPaint();
@ -26,7 +26,7 @@ interface nsIBrowserElementNextPaintListener : nsISupports
* Interface to the BrowserElementParent implementation. All methods
* but setFrameLoader throw when the remote process is dead.
*/
[scriptable, uuid(9946695c-1ed3-4abb-bc60-6f8947fd5641)]
[scriptable, uuid(1e098c3a-7d65-452d-a2b2-9ffd1b6e04bb)]
interface nsIBrowserElementAPI : nsISupports
{
const long FIND_CASE_SENSITIVE = 0;
@ -101,6 +101,12 @@ interface nsIBrowserElementAPI : nsISupports
nsIDOMDOMRequest executeScript(in DOMString script, in jsval options);
/**
* Returns an object that represents a Web Manifest:
* http://w3c.github.io/manifest/
*/
nsIDOMDOMRequest getWebManifest();
/**
* Returns a JSON string representing Microdata objects on the page.
* Format is described at:

View File

@ -778,4 +778,22 @@ nsBrowserElement::GetStructuredData(ErrorResult& aRv)
return req.forget().downcast<DOMRequest>();
}
already_AddRefed<DOMRequest>
nsBrowserElement::GetWebManifest(ErrorResult& aRv)
{
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = mBrowserElementAPI->GetWebManifest(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>();
}
} // namespace mozilla

View File

@ -114,6 +114,8 @@ public:
already_AddRefed<dom::DOMRequest> GetStructuredData(ErrorResult& aRv);
already_AddRefed<dom::DOMRequest> GetWebManifest(ErrorResult& aRv);
void SetNFCFocus(bool isFocus,
ErrorResult& aRv);

View File

@ -179,4 +179,10 @@ interface BrowserElementPrivileged {
Pref="dom.mozBrowserFramesEnabled",
CheckAllPermissions="browser"]
DOMRequest getStructuredData();
[Throws,
Pref="dom.mozBrowserFramesEnabled",
CheckAllPermissions="browser"]
DOMRequest getWebManifest();
};