Skip to content

Commit

Permalink
Bug 1603673 - Signal that we support web manifest processing in Fenix…
Browse files Browse the repository at this point in the history
… r=snorp,agi,ladybenko

When enabled, `link.relList.supports("manifest")` will return `true`.

Differential Revision: https://phabricator.services.mozilla.com/D58181

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Marcos Cáceres committed Feb 26, 2020
1 parent 00dd87f commit 2cc840a
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions browser/components/ssb/tests/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ support-files =
test_page.html
empty_page.html
prefs =
dom.manfiest.enabled=true
browser.ssb.enabled=true
browser.ssb.osintegration=false

Expand Down
3 changes: 3 additions & 0 deletions devtools/client/application/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ async function enableApplicationPanel() {
// Enable all preferences related to service worker debugging.
await enableServiceWorkerDebugging();

// Enable web manifest processing.
Services.prefs.setBoolPref("dom.manifest.enabled", true);

// Enable application panel in DevTools.
await pushPref("devtools.application.enabled", true);
}
Expand Down
3 changes: 3 additions & 0 deletions devtools/server/tests/browser/browser_application_manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

"use strict";

// Enable web manifest processing.
Services.prefs.setBoolPref("dom.manifest.enabled", true);

add_task(async function() {
info("Testing fetching a valid manifest");
const response = await fetchManifest("application-manifest-basic.html");
Expand Down
7 changes: 7 additions & 0 deletions dom/manifest/ManifestObtainer.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/
"use strict";

const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

const { PromiseMessage } = ChromeUtils.import(
"resource://gre/modules/PromiseMessage.jsm"
);
Expand Down Expand Up @@ -72,6 +74,11 @@ var ManifestObtainer = {
aContent,
aOptions = { checkConformance: false }
) {
if (!Services.prefs.getBoolPref("dom.manifest.enabled")) {
throw new Error(
"Obtaining manifest is disabled by pref: dom.manifest.enabled"
);
}
if (!aContent || isXULBrowser(aContent)) {
const err = new TypeError("Invalid input. Expected a DOM Window.");
return Promise.reject(err);
Expand Down
3 changes: 3 additions & 0 deletions dom/manifest/test/browser_ManifestIcons_browserFetchIcon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Used by JSHint:
/* global Cu, BrowserTestUtils, ok, add_task, gBrowser */
"use strict";

Services.prefs.setBoolPref("dom.manifest.enabled", true);

const { ManifestIcons } = ChromeUtils.import(
"resource://gre/modules/ManifestIcons.jsm"
);
Expand Down
3 changes: 3 additions & 0 deletions dom/manifest/test/browser_ManifestObtainer_credentials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Used by JSHint:
/* global ok, is, Cu, BrowserTestUtils, add_task, gBrowser, makeTestURL, requestLongerTimeout*/
"use strict";

Services.prefs.setBoolPref("dom.manifest.enabled", true);

const { ManifestObtainer } = ChromeUtils.import(
"resource://gre/modules/ManifestObtainer.jsm"
);
Expand Down
2 changes: 2 additions & 0 deletions dom/manifest/test/browser_ManifestObtainer_obtain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* global ok, is, Cu, BrowserTestUtils, add_task, gBrowser, requestLongerTimeout*/
"use strict";

Services.prefs.setBoolPref("dom.manifest.enabled", true);

const { ManifestObtainer } = ChromeUtils.import(
"resource://gre/modules/ManifestObtainer.jsm"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const mixedContentFile = `${path}file_web_manifest_mixed_content.html`;
const server = `${path}file_testserver.sjs`;
const defaultURL = new URL(`http://example.org${server}`);
const mixedURL = new URL(`http://mochi.test:8888${server}`);

// Enable web manifest processing.
Services.prefs.setBoolPref("dom.manifest.enabled", true);

const tests = [
// Check interaction with default-src and another origin,
// CSP allows fetching from example.org, so manifest should load.
Expand Down
4 changes: 4 additions & 0 deletions dom/security/test/csp/browser_test_web_manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const httpsManifest = `${path}file_web_manifest_https.html`;
const server = `${path}file_testserver.sjs`;
const defaultURL = new URL(`http://example.org${server}`);
const secureURL = new URL(`https://example.com:443${server}`);

// Enable web manifest processing.
Services.prefs.setBoolPref("dom.manifest.enabled", true);

const tests = [
// CSP block everything, so trying to load a manifest
// will result in a policy violation.
Expand Down
3 changes: 3 additions & 0 deletions mobile/android/geckoview/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ package org.mozilla.geckoview {
method public boolean getUseMaxScreenDepth();
method public boolean getUseMultiprocess();
method public boolean getWebFontsEnabled();
method public boolean getWebManifestEnabled();
method @NonNull public GeckoRuntimeSettings setAboutConfigEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setAutomaticFontSizeAdjustment(boolean);
method @NonNull public GeckoRuntimeSettings setConsoleOutputEnabled(boolean);
Expand All @@ -535,6 +536,7 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings setPreferredColorScheme(int);
method @NonNull public GeckoRuntimeSettings setRemoteDebuggingEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setWebFontsEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setWebManifestEnabled(boolean);
field public static final int COLOR_SCHEME_DARK = 1;
field public static final int COLOR_SCHEME_LIGHT = 0;
field public static final int COLOR_SCHEME_SYSTEM = -1;
Expand Down Expand Up @@ -570,6 +572,7 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings.Builder useMaxScreenDepth(boolean);
method @NonNull public GeckoRuntimeSettings.Builder useMultiprocess(boolean);
method @NonNull public GeckoRuntimeSettings.Builder webFontsEnabled(boolean);
method @NonNull public GeckoRuntimeSettings.Builder webManifest(boolean);
method @NonNull protected GeckoRuntimeSettings newSettings(@Nullable GeckoRuntimeSettings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ class ContentDelegateTest : BaseSessionTest() {
})
}

@Test fun webAppManifestPref() {
val initialState = sessionRule.runtime.settings.getWebManifestEnabled()
val jsToRun = "document.querySelector('link[rel=manifest]').relList.supports('manifest');"

// Check pref'ed off
sessionRule.runtime.settings.setWebManifestEnabled(false)
mainSession.loadTestPath(HELLO_HTML_PATH)
var result = equalTo(mainSession.evaluateJS(jsToRun) as Boolean)

assertThat("Disabling pref makes relList.supports('manifest') return false", false, result)

// Check pref'ed on
sessionRule.runtime.settings.setWebManifestEnabled(true)
mainSession.loadTestPath(HELLO_HTML_PATH)
result = equalTo(mainSession.evaluateJS(jsToRun) as Boolean)
assertThat("Enabling pref makes relList.supports('manifest') return true", true, result)

sessionRule.runtime.settings.setWebManifestEnabled(initialState)
}

@Test fun webAppManifest() {
mainSession.loadTestPath(HELLO_HTML_PATH)
mainSession.waitUntilCalled(object : Callbacks.All {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ public static final class Builder
return this;
}

/**
* Set whether web manifest support is enabled.
*
* This controls if Gecko actually downloads, or "obtains", web
* manifests and processes them. Without setting this pref, trying
* to obtain a manifest throws.
*
* @param enabled A flag determining whether Web Manifest processing support is
* enabled.
* @return The builder instance.
*/
public @NonNull Builder webManifest(final boolean enabled) {
getSettings().mWebManifest.set(enabled);
return this;
}

/**
* Set whether or not web console messages should go to logcat.
*
Expand Down Expand Up @@ -431,6 +447,8 @@ public static final class Builder
return mContentBlocking;
}

/* package */ final Pref<Boolean> mWebManifest = new Pref<Boolean>(
"dom.manifest.enabled", true);
/* package */ final Pref<Boolean> mJavaScript = new Pref<Boolean>(
"javascript.enabled", true);
/* package */ final Pref<Boolean> mRemoteDebugging = new Pref<Boolean>(
Expand Down Expand Up @@ -772,6 +790,28 @@ private static String getLanguageTag(final Locale locale) {
return out.toString();
}

/**
* Sets whether Web Manifest processing support is enabled.
*
* @param enabled A flag determining whether Web Manifest processing support is
* enabled.
*
* @return This GeckoRuntimeSettings instance.
*/
public @NonNull GeckoRuntimeSettings setWebManifestEnabled(final boolean enabled) {
mWebManifest.commit(enabled);
return this;
}

/**
* Get whether or not Web Manifest processing support is enabled.
*
* @return True if web manifest processing support is enabled.
*/
public boolean getWebManifestEnabled() {
return mWebManifest.get();
}

/**
* Set whether or not web console messages should go to logcat.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ exclude: true
[`GeckoSession.PermissionDelegate#PERMISSION_AUTOPLAY_INAUDIBLE`][73.13] to
control autoplay.
([bug 1614894]({{bugzilla}}1614894))
- Added [`GeckoRuntimeSettings.setWebManifestEnabled`][75.4],
[`GeckoRuntimeSettings.webManifest`][75.5], and
[`GeckoRuntimeSettings.getWebManifestEnabled`][75.6]
([bug 1614894]({{bugzilla}}1603673)), to enable or check Web Manifest support.

[75.1]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#useMultiprocess-boolean-
[75.2]: {{javadoc_uri}}/WebExtensionController.DebuggerDelegate.html#onExtensionListUpdated--
[75.3]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#autoplayDefault-boolean-
[75.4]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#setWebManifestEnabled-boolean-
[75.5]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#webManifest-boolean-
[75.6]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#getWebManifestEnabled--

## v74
- Added [`WebExtensionController.enable`][74.1] and [`disable`][74.2] to
Expand Down Expand Up @@ -595,4 +602,4 @@ exclude: true
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
[65.25]: {{javadoc_uri}}/GeckoResult.html

[api-version]: 898e8783e858824b7af7e4e9763bf5aaa54c0b0c
[api-version]: 82255b8fdbc57e73920690426bdb4dd261cfe4ff

0 comments on commit 2cc840a

Please sign in to comment.