Bug 1634504 - Remove deprecated registerWebExtension. r=snorp

Differential Revision: https://phabricator.services.mozilla.com/D87512
This commit is contained in:
Agi Sferro 2020-08-20 01:15:00 +00:00
Родитель a594ed407c
Коммит fcb9b12423
8 изменённых файлов: 60 добавлений и 388 удалений

Просмотреть файл

@ -531,13 +531,11 @@ package org.mozilla.geckoview {
method @UiThread public void orientationChanged();
method @UiThread public void orientationChanged(int);
method @AnyThread public void readFromParcel(@NonNull Parcel);
method @Deprecated @UiThread @NonNull public GeckoResult<Void> registerWebExtension(@NonNull WebExtension);
method @UiThread public void setDelegate(@Nullable GeckoRuntime.Delegate);
method @UiThread public void setLoginStorageDelegate(@Nullable Autocomplete.LoginStorageDelegate);
method @UiThread public void setServiceWorkerDelegate(@Nullable GeckoRuntime.ServiceWorkerDelegate);
method @UiThread public void setWebNotificationDelegate(@Nullable WebNotificationDelegate);
method @AnyThread public void shutdown();
method @Deprecated @UiThread @NonNull public GeckoResult<Void> unregisterWebExtension(@NonNull WebExtension);
field public static final String ACTION_CRASHED = "org.mozilla.gecko.ACTION_CRASHED";
field public static final Parcelable.Creator<GeckoRuntime> CREATOR;
field public static final String EXTRA_CRASH_FATAL = "fatal";
@ -1557,8 +1555,6 @@ package org.mozilla.geckoview {
}
public class WebExtension {
ctor @Deprecated public WebExtension(@NonNull String, @NonNull String, long, @NonNull WebExtensionController);
ctor @Deprecated public WebExtension(@NonNull String, @NonNull WebExtensionController);
method @UiThread @Nullable public WebExtension.TabDelegate getTabDelegate();
method @AnyThread public void setActionDelegate(@Nullable WebExtension.ActionDelegate);
method @UiThread public void setMessageDelegate(@Nullable WebExtension.MessageDelegate, @NonNull String);
@ -1567,7 +1563,7 @@ package org.mozilla.geckoview {
field @NonNull public final String id;
field public final boolean isBuiltIn;
field @NonNull public final String location;
field @Nullable public final WebExtension.MetaData metaData;
field @NonNull public final WebExtension.MetaData metaData;
}
@AnyThread public static class WebExtension.Action {
@ -1768,11 +1764,6 @@ package org.mozilla.geckoview {
method @Nullable default public GeckoResult<AllowOrDeny> onUpdatePrompt(@NonNull WebExtension, @NonNull WebExtension, @NonNull String[], @NonNull String[]);
}
@Deprecated public static interface WebExtensionController.TabDelegate {
method @UiThread @NonNull default public GeckoResult<AllowOrDeny> onCloseTab(@Nullable WebExtension, @NonNull GeckoSession);
method @UiThread @Nullable default public GeckoResult<GeckoSession> onNewTab(@Nullable WebExtension, @Nullable String);
}
@AnyThread public abstract class WebMessage {
ctor protected WebMessage(@NonNull WebMessage.Builder);
field @NonNull public final Map<String,String> headers;

Просмотреть файл

@ -1458,9 +1458,9 @@ class NavigationDelegateTest : BaseSessionTest() {
controller.install("https://example.org/tests/junit/page-history.xpi"))
assertThat("baseUrl should be a valid extension URL",
extension.metaData!!.baseUrl, startsWith("moz-extension://"))
extension.metaData.baseUrl, startsWith("moz-extension://"))
val url = extension.metaData!!.baseUrl + "page.html"
val url = extension.metaData.baseUrl + "page.html"
val isRemote = sessionRule.getPrefs("extensions.webextensions.remote")[0] as Boolean
processSwitchingTest(url, isRemote)

Просмотреть файл

@ -87,13 +87,13 @@ class WebExtensionTest : BaseSessionTest() {
// Check that the WebExtension was applied by checking the border color
assertBodyBorderEqualTo("red")
// Unregister WebExtension and check again
// Uninstall WebExtension and check again
sessionRule.waitForResult(controller.uninstall(borderify))
mainSession.reload()
sessionRule.waitForPageStop()
// Check that the WebExtension was not applied after being unregistered
// Check that the WebExtension was not applied after being uninstalled
assertBodyBorderEqualTo("")
}
@ -120,15 +120,15 @@ class WebExtensionTest : BaseSessionTest() {
}
assertThat("enabled should match",
extension.metaData!!.enabled, equalTo(enabled))
extension.metaData.enabled, equalTo(enabled))
assertThat("userDisabled should match",
extension.metaData!!.disabledFlags and DisabledFlags.USER > 0,
extension.metaData.disabledFlags and DisabledFlags.USER > 0,
equalTo(userDisabled))
assertThat("appDisabled should match",
extension.metaData!!.disabledFlags and DisabledFlags.APP > 0,
extension.metaData.disabledFlags and DisabledFlags.APP > 0,
equalTo(appDisabled))
assertThat("blocklistDisabled should match",
extension.metaData!!.disabledFlags and DisabledFlags.BLOCKLIST > 0,
extension.metaData.disabledFlags and DisabledFlags.BLOCKLIST > 0,
equalTo(blocklistDisabled))
}
@ -190,15 +190,15 @@ class WebExtensionTest : BaseSessionTest() {
sessionRule.delegateDuringNextWait(object : WebExtensionController.PromptDelegate {
@AssertCalled
override fun onInstallPrompt(extension: WebExtension): GeckoResult<AllowOrDeny> {
assertEquals(extension.metaData!!.description,
assertEquals(extension.metaData.description,
"Adds a red border to all webpages matching example.com.")
assertEquals(extension.metaData!!.name, "Borderify")
assertEquals(extension.metaData!!.version, "1.0")
assertEquals(extension.metaData.name, "Borderify")
assertEquals(extension.metaData.version, "1.0")
assertEquals(extension.isBuiltIn, false)
assertEquals(extension.metaData!!.enabled, false)
assertEquals(extension.metaData!!.signedState,
assertEquals(extension.metaData.enabled, false)
assertEquals(extension.metaData.signedState,
WebExtension.SignedStateFlags.SIGNED)
assertEquals(extension.metaData!!.blocklistState,
assertEquals(extension.metaData.blocklistState,
WebExtension.BlocklistStateFlags.NOT_BLOCKED)
return GeckoResult.fromValue(AllowOrDeny.ALLOW)
@ -219,7 +219,7 @@ class WebExtensionTest : BaseSessionTest() {
assertTrue(list.containsKey(borderify.id))
assertTrue(list.containsKey(RuntimeCreator.TEST_SUPPORT_EXTENSION_ID))
// Unregister WebExtension and check again
// Uninstall WebExtension and check again
sessionRule.waitForResult(controller.uninstall(borderify))
list = extensionsMap(sessionRule.waitForResult(controller.list()))
@ -229,7 +229,7 @@ class WebExtensionTest : BaseSessionTest() {
mainSession.reload()
sessionRule.waitForPageStop()
// Check that the WebExtension was not applied after being unregistered
// Check that the WebExtension was not applied after being uninstalled
assertBodyBorderEqualTo("")
}
@ -254,14 +254,14 @@ class WebExtensionTest : BaseSessionTest() {
// Make sure private mode is enabled
assertTrue(mainSession.settings.usePrivateMode)
assertFalse(borderify.metaData!!.allowedInPrivateBrowsing)
assertFalse(borderify.metaData.allowedInPrivateBrowsing)
// Check that the WebExtension was not applied to a private mode page
assertBodyBorderEqualTo("")
borderify = sessionRule.waitForResult(
controller.setAllowedInPrivateBrowsing(borderify, true))
assertTrue(borderify.metaData!!.allowedInPrivateBrowsing)
assertTrue(borderify.metaData.allowedInPrivateBrowsing)
// Check that the WebExtension was applied to a private mode page now that the extension
// is enabled in private mode
mainSession.reload();
@ -271,14 +271,14 @@ class WebExtensionTest : BaseSessionTest() {
borderify = sessionRule.waitForResult(
controller.setAllowedInPrivateBrowsing(borderify, false))
assertFalse(borderify.metaData!!.allowedInPrivateBrowsing)
assertFalse(borderify.metaData.allowedInPrivateBrowsing)
// Check that the WebExtension was not applied to a private mode page after being
// not allowed to run in private mode
mainSession.reload();
sessionRule.waitForPageStop()
assertBodyBorderEqualTo("")
// Unregister WebExtension and check again
// Uninstall WebExtension and check again
sessionRule.waitForResult(controller.uninstall(borderify))
mainSession.reload();
sessionRule.waitForPageStop()
@ -302,7 +302,7 @@ class WebExtensionTest : BaseSessionTest() {
val dummy = sessionRule.waitForResult(
controller.install("resource://android/assets/web_extensions/dummy.xpi"))
val metadata = dummy.metaData!!
val metadata = dummy.metaData
assertTrue((metadata.optionsPageUrl ?: "").matches("^moz-extension://[0-9a-f\\-]*/options.html$".toRegex()));
assertEquals(metadata.openOptionsPageInTab, true);
assertTrue(metadata.baseUrl.matches("^moz-extension://[0-9a-f\\-]*/$".toRegex()))
@ -404,11 +404,11 @@ class WebExtensionTest : BaseSessionTest() {
val borderify = sessionRule.waitForResult(controller.install(
"resource://android/assets/web_extensions/borderify-unsigned.xpi")
.then { extension ->
assertEquals(extension!!.metaData!!.signedState,
assertEquals(extension!!.metaData.signedState,
WebExtension.SignedStateFlags.MISSING)
assertEquals(extension.metaData!!.blocklistState,
assertEquals(extension.metaData.blocklistState,
WebExtension.BlocklistStateFlags.NOT_BLOCKED)
assertEquals(extension.metaData!!.name, "Borderify")
assertEquals(extension.metaData.name, "Borderify")
GeckoResult.fromValue(extension)
})
@ -806,7 +806,7 @@ class WebExtensionTest : BaseSessionTest() {
}
// This test
// - registers a web extension
// - installs a web extension
// - waits for the web extension to connect to the browser
// - on connect it will start listening on the port for a message
// - When the message is received it sends a message in response and waits for another message
@ -1202,7 +1202,7 @@ class WebExtensionTest : BaseSessionTest() {
"extension-page-update@tests.mozilla.org"))
assertThat("ID match", ensure.id, equalTo(extension.id))
assertThat("version match", ensure.metaData!!.version, equalTo(extension.metaData!!.version))
assertThat("version match", ensure.metaData.version, equalTo(extension.metaData.version))
// Make sure the page loaded successfully
sessionRule.waitForResult(pageStop)
@ -1212,14 +1212,14 @@ class WebExtensionTest : BaseSessionTest() {
assertThat("WebExtension page should have access to privileged APIs",
sessionRule.waitForResult(result), equalTo("HELLO_FROM_PAGE"))
// Test that after unregistering an extension, all its pages get closed
// Test that after uninstalling an extension, all its pages get closed
sessionRule.addExternalDelegateUntilTestEnd(
WebExtension.SessionTabDelegate::class,
{ delegate -> mainSession.webExtensionController.setTabDelegate(extension, delegate) },
{ mainSession.webExtensionController.setTabDelegate(extension, null) },
object : WebExtension.SessionTabDelegate {})
val unregister = controller.uninstall(extension)
val uninstall = controller.uninstall(extension)
sessionRule.waitUntilCalled(object : WebExtension.SessionTabDelegate {
@AssertCalled
@ -1231,7 +1231,7 @@ class WebExtensionTest : BaseSessionTest() {
}
})
sessionRule.waitForResult(unregister)
sessionRule.waitForResult(uninstall)
}
@Test
@ -1298,7 +1298,7 @@ class WebExtensionTest : BaseSessionTest() {
sessionRule.delegateDuringNextWait(object : WebExtensionController.PromptDelegate {
@AssertCalled
override fun onInstallPrompt(extension: WebExtension): GeckoResult<AllowOrDeny> {
assertEquals(extension.metaData!!.version, "1.0")
assertEquals(extension.metaData.version, "1.0")
return GeckoResult.fromValue(AllowOrDeny.ALLOW)
}
@ -1314,7 +1314,7 @@ class WebExtensionTest : BaseSessionTest() {
assertBodyBorderEqualTo("red")
val update2 = sessionRule.waitForResult(controller.update(update1));
assertEquals(update2.metaData!!.version, "2.0")
assertEquals(update2.metaData.version, "2.0")
mainSession.reload()
sessionRule.waitForPageStop()
@ -1322,13 +1322,13 @@ class WebExtensionTest : BaseSessionTest() {
// Check that updated extension changed the border color.
assertBodyBorderEqualTo("blue")
// Unregister WebExtension and check again
// Uninstall WebExtension and check again
sessionRule.waitForResult(controller.uninstall(update2))
mainSession.reload()
sessionRule.waitForPageStop()
// Check that the WebExtension was not applied after being unregistered
// Check that the WebExtension was not applied after being uninstalled
assertBodyBorderEqualTo("")
}
@ -1350,7 +1350,7 @@ class WebExtensionTest : BaseSessionTest() {
sessionRule.delegateDuringNextWait(object : WebExtensionController.PromptDelegate {
@AssertCalled
override fun onInstallPrompt(extension: WebExtension): GeckoResult<AllowOrDeny> {
assertEquals(extension.metaData!!.version, "1.0")
assertEquals(extension.metaData.version, "1.0")
return GeckoResult.fromValue(AllowOrDeny.ALLOW)
}
@ -1371,8 +1371,8 @@ class WebExtensionTest : BaseSessionTest() {
updatedExtension: WebExtension,
newPermissions: Array<String>,
newOrigins: Array<String>): GeckoResult<AllowOrDeny> {
assertEquals(currentlyInstalled.metaData!!.version, "1.0")
assertEquals(updatedExtension.metaData!!.version, "2.0")
assertEquals(currentlyInstalled.metaData.version, "1.0")
assertEquals(updatedExtension.metaData.version, "2.0")
assertEquals(newPermissions.size, 1)
assertEquals(newPermissions[0], "tabs")
return GeckoResult.fromValue(AllowOrDeny.ALLOW);
@ -1380,7 +1380,7 @@ class WebExtensionTest : BaseSessionTest() {
})
val update2 = sessionRule.waitForResult(controller.update(update1));
assertEquals(update2.metaData!!.version, "2.0")
assertEquals(update2.metaData.version, "2.0")
mainSession.reload()
sessionRule.waitForPageStop()
@ -1388,13 +1388,13 @@ class WebExtensionTest : BaseSessionTest() {
// Check that updated extension changed the border color.
assertBodyBorderEqualTo("blue")
// Unregister WebExtension and check again
// Uninstall WebExtension and check again
sessionRule.waitForResult(controller.uninstall(update2))
mainSession.reload()
sessionRule.waitForPageStop()
// Check that the WebExtension was not applied after being unregistered
// Check that the WebExtension was not applied after being uninstalled
assertBodyBorderEqualTo("")
}
@ -1416,7 +1416,7 @@ class WebExtensionTest : BaseSessionTest() {
sessionRule.delegateDuringNextWait(object : WebExtensionController.PromptDelegate {
@AssertCalled
override fun onInstallPrompt(extension: WebExtension): GeckoResult<AllowOrDeny> {
assertEquals(extension.metaData!!.version, "2.0")
assertEquals(extension.metaData.version, "2.0")
return GeckoResult.fromValue(AllowOrDeny.ALLOW)
}
@ -1434,13 +1434,13 @@ class WebExtensionTest : BaseSessionTest() {
val update2 = sessionRule.waitForResult(controller.update(update1))
assertNull(update2);
// Unregister WebExtension and check again
// Uninstall WebExtension and check again
sessionRule.waitForResult(controller.uninstall(update1))
mainSession.reload()
sessionRule.waitForPageStop()
// Check that the WebExtension was not applied after being unregistered
// Check that the WebExtension was not applied after being uninstalled
assertBodyBorderEqualTo("")
}
@ -1462,7 +1462,7 @@ class WebExtensionTest : BaseSessionTest() {
sessionRule.delegateDuringNextWait(object : WebExtensionController.PromptDelegate {
@AssertCalled
override fun onInstallPrompt(extension: WebExtension): GeckoResult<AllowOrDeny> {
assertEquals(extension.metaData!!.version, "1.0")
assertEquals(extension.metaData.version, "1.0")
return GeckoResult.fromValue(AllowOrDeny.ALLOW)
}
@ -1483,8 +1483,8 @@ class WebExtensionTest : BaseSessionTest() {
updatedExtension: WebExtension,
newPermissions: Array<String>,
newOrigins: Array<String>): GeckoResult<AllowOrDeny> {
assertEquals(currentlyInstalled.metaData!!.version, "1.0")
assertEquals(updatedExtension.metaData!!.version, "2.0")
assertEquals(currentlyInstalled.metaData.version, "1.0")
assertEquals(updatedExtension.metaData.version, "2.0")
return GeckoResult.fromValue(AllowOrDeny.DENY);
}
})
@ -1505,13 +1505,13 @@ class WebExtensionTest : BaseSessionTest() {
// Check that updated extension changed the border color.
assertBodyBorderEqualTo("red")
// Unregister WebExtension and check again
// Uninstall WebExtension and check again
sessionRule.waitForResult(controller.uninstall(update1))
mainSession.reload()
sessionRule.waitForPageStop()
// Check that the WebExtension was not applied after being unregistered
// Check that the WebExtension was not applied after being uninstalled
assertBodyBorderEqualTo("")
}
@ -1560,7 +1560,7 @@ class WebExtensionTest : BaseSessionTest() {
sessionRule.delegateDuringNextWait(object : WebExtensionController.PromptDelegate {
@AssertCalled
override fun onInstallPrompt(extension: WebExtension): GeckoResult<AllowOrDeny> {
assertEquals(extension.metaData!!.version, "1.0")
assertEquals(extension.metaData.version, "1.0")
return GeckoResult.fromValue(AllowOrDeny.ALLOW)
}
})
@ -1688,7 +1688,7 @@ class WebExtensionTest : BaseSessionTest() {
@AssertCalled(count = 1)
override fun onOpenOptionsPage(source: WebExtension) {
assertThat(
source.metaData!!.optionsPageUrl,
source.metaData.optionsPageUrl,
endsWith("options.html"))
assertEquals(optionsExtension!!.id, source.id)
openOptionsPageResult.complete(null)

Просмотреть файл

@ -463,99 +463,6 @@ public final class GeckoRuntime implements Parcelable {
return mProfilerController;
}
/**
* Register a {@link WebExtension} that will be run with this GeckoRuntime.
*
* <p>At this time, WebExtensions don't have access to any UI element and
* cannot communicate with the application. Any UI element will be
* ignored.</p>
*
* Example:
* <pre><code>
* runtime.registerWebExtension(new WebExtension(
* "resource://android/assets/web_extensions/my_webextension/"))
* .exceptionally(ex -&gt; {
* Log.e("MyActivity", "Could not register WebExtension", ex);
* return null;
* });
*
* runtime.registerWebExtension(new WebExtension(
* "file:///path/to/web_extension/my_webextension2.xpi",
* "mywebextension2@example.com"));
* </code></pre>
*
* To learn more about WebExtensions refer to
* <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions">
* Mozilla/Add-ons/WebExtensions
* </a>.
*
* @param webExtension {@link WebExtension} to register
*
* @return A {@link GeckoResult} that will complete when the WebExtension
* has been installed.
*
* @deprecated Use {@link WebExtensionController#installBuiltIn} instead. This method will
* be removed in GeckoView 81.
*/
@Deprecated // Bug 1634504
@UiThread
public @NonNull GeckoResult<Void> registerWebExtension(
final @NonNull WebExtension webExtension) {
final CallbackResult<Void> result = new CallbackResult<Void>() {
@Override
public void sendSuccess(final Object response) {
complete(null);
}
};
final GeckoBundle bundle = new GeckoBundle(3);
bundle.putString("locationUri", webExtension.location);
bundle.putString("id", webExtension.id);
bundle.putBoolean("allowContentMessaging",
(webExtension.flags & WebExtension.Flags.ALLOW_CONTENT_MESSAGING) > 0);
mWebExtensionController.registerWebExtension(webExtension);
EventDispatcher.getInstance().dispatch("GeckoView:RegisterWebExtension",
bundle, result);
return result;
}
/**
* Unregisters this WebExtension. After a WebExtension is unregistered all
* scripts associated with it stop running.
*
* @param webExtension {@link WebExtension} to unregister
*
* @return A {@link GeckoResult} that will complete when the WebExtension
* has been unregistered.
*
* @deprecated Use {@link WebExtensionController#uninstall} instead. This method will
* be removed in GeckoView 81.
*/
@Deprecated // Bug 1634504
@UiThread
public @NonNull GeckoResult<Void> unregisterWebExtension(
final @NonNull WebExtension webExtension) {
final CallbackResult<Void> result = new CallbackResult<Void>() {
@Override
public void sendSuccess(final Object response) {
complete(null);
}
};
final GeckoBundle bundle = new GeckoBundle(1);
bundle.putString("id", webExtension.id);
EventDispatcher.getInstance().dispatch("GeckoView:UnregisterWebExtension", bundle, result);
return result.then(success -> {
mWebExtensionController.unregisterWebExtension(webExtension);
return GeckoResult.fromValue(success);
});
}
/**
* Create a new runtime with the given settings and attach it to the given
* context.

Просмотреть файл

@ -25,7 +25,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* Represents a WebExtension that may be used by GeckoView.
@ -55,8 +54,7 @@ public class WebExtension {
public final @WebExtensionFlags long flags;
/** Provides information about this {@link WebExtension}. */
// TODO: move to @NonNull when we remove registerWebExtension
public final @Nullable MetaData metaData;
public final @NonNull MetaData metaData;
/**
* Whether this extension is built-in. Built-in extension can be installed
@ -123,70 +121,6 @@ public class WebExtension {
}
}
/**
* Builds a WebExtension instance that can be loaded in GeckoView using
* {@link GeckoRuntime#registerWebExtension}
*
* @param location The WebExtension install location. It must be either a
* <code>resource:</code> URI to a folder inside the APK or
* a <code>file:</code> URL to a <code>.xpi</code> file.
* @param id Unique identifier for this WebExtension. This identifier must
* either be a GUID or a string formatted like an email address.
* E.g. <pre><code>
* "extensionname@example.org"
* "{daf44bf7-a45e-4450-979c-91cf07434c3d}"
* </code></pre>
*
* See also: <ul>
* <li><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_specific_settings">
* WebExtensions/manifest.json/browser_specific_settings
* </a>
* <li><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/WebExtensions_and_the_Add-on_ID#When_do_you_need_an_add-on_ID">
* WebExtensions/WebExtensions_and_the_Add-on_ID
* </a>
* </ul>
* @param flags {@link Flags} for this WebExtension.
* @param controller the current {@link WebExtensionController} instance
*
* @deprecated Use the return value of {@link WebExtensionController#installBuiltIn} instead.
* This method will be removed in GeckoView 81.
*/
@Deprecated
public WebExtension(final @NonNull String location, final @NonNull String id,
final @WebExtensionFlags long flags,
final @NonNull WebExtensionController controller) {
setDelegateController(controller.delegateFor(this));
this.location = location;
this.id = id;
this.flags = flags;
// TODO:
this.isBuiltIn = false;
this.metaData = null;
}
/**
* Builds a WebExtension instance that can be loaded in GeckoView using
* {@link GeckoRuntime#registerWebExtension}
* The <code>id</code> for this web extension will be automatically
* generated.
*
* All messaging from the web extension will be ignored.
*
* @param location The WebExtension install location. It must be either a
* <code>resource:</code> URI to a folder inside the APK or
* a <code>file:</code> URL to a <code>.xpi</code> file.
* @param controller the current {@link WebExtensionController} instance
*
* @deprecated Use the return value of {@link WebExtensionController#installBuiltIn} instead.
* This method will be removed in GeckoView 81.
*/
@Deprecated
public WebExtension(final @NonNull String location,
final @NonNull WebExtensionController controller) {
this(location, "{" + UUID.randomUUID().toString() + "}", Flags.NONE, controller);
}
/**
* Defines the message delegate for a Native App.
*
@ -471,8 +405,7 @@ public class WebExtension {
* See also: <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/remove">
* WebExtensions/API/tabs/remove</a>
*
* @param source An instance of {@link WebExtension} or null if extension was not registered
* with GeckoRuntime.registerWebextension
* @param source An instance of {@link WebExtension}
* @param session An instance of {@link GeckoSession} to be closed.
* @return GeckoResult.ALLOW if the tab will be closed, GeckoResult.DENY otherwise
*/

Просмотреть файл

@ -176,52 +176,6 @@ public class WebExtensionController {
}
}
// TODO: remove once we remove GeckoRuntime#registerWebExtension
/* package */ DelegateController delegateFor(final WebExtension extension) {
return new DelegateController(extension);
}
/**
* @deprecated Use {@link WebExtension.TabDelegate} and {@link WebExtension.SessionTabDelegate}.
*/
@Deprecated
public interface TabDelegate {
/**
* Called when tabs.create is invoked, this method returns a *newly-created* session
* that GeckoView will use to load the requested page on. If the returned value
* is null the page will not be opened.
*
* @param source An instance of {@link WebExtension} or null if extension was not registered
* with GeckoRuntime.registerWebextension
* @param uri The URI to be loaded. This is provided for informational purposes only,
* do not call {@link GeckoSession#loadUri} on it.
* @return A {@link GeckoResult} which holds the returned GeckoSession. May be null, in
* which case the request for a new tab by the extension will fail.
* The implementation of onNewTab is responsible for maintaining a reference
* to the returned object, to prevent it from being garbage collected.
*/
@UiThread
@Nullable
default GeckoResult<GeckoSession> onNewTab(@Nullable WebExtension source, @Nullable String uri) {
return null;
}
/**
* Called when tabs.remove is invoked, this method decides if WebExtension can close the
* tab. In case WebExtension can close the tab, it should close passed GeckoSession and
* return GeckoResult.ALLOW or GeckoResult.DENY in case tab cannot be closed.
*
* @param source An instance of {@link WebExtension} or null if extension was not registered
* with GeckoRuntime.registerWebextension
* @param session An instance of {@link GeckoSession} to be closed.
* @return GeckoResult.ALLOW if the tab will be closed, GeckoResult.DENY otherwise
*/
@UiThread
@NonNull
default GeckoResult<AllowOrDeny> onCloseTab(@Nullable WebExtension source, @NonNull GeckoSession session) {
return GeckoResult.DENY;
}
}
/**
* This delegate will be called whenever an extension is about to be installed or it needs
* new permissions, e.g during an update or because it called <code>permissions.request</code>

Просмотреть файл

@ -18,6 +18,7 @@ exclude: true
to [`ContentBlocking.Settings`][81.2].
- Added [`GeckoSession.ContentDelegate.onPaintStatusReset()`][81.3] callback which notifies when valid content is no longer being rendered.
- Made [`GeckoSession.ContentDelegate.onFirstContentfulPaint()`][81.4] additionally be called for the first contentful paint following a `onPaintStatusReset()` event, rather than just the first contentful paint of the session.
- Removed deprecated `GeckoRuntime.registerWebExtension`. Use [`WebExtensionController.install`][73.1] instead.
[81.1]: {{javadoc_uri}}/ContentBlocking.Settings.Builder.html
[81.2]: {{javadoc_uri}}/ContentBlocking.Settings.html
@ -765,4 +766,4 @@ to allow adding gecko profiler markers.
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
[65.25]: {{javadoc_uri}}/GeckoResult.html
[api-version]: 9f4bf24e0795c8da7caf58487e659918ea1a56cc
[api-version]: d698a9e1bfdf7614a478c8fdc772967e945ced24

Просмотреть файл

@ -164,18 +164,7 @@ class GeckoViewConnection {
constructor(sender, nativeApp, allowContentMessaging) {
this.sender = sender;
this.nativeApp = nativeApp;
if (allowContentMessaging) {
this.allowContentMessaging = allowContentMessaging;
} else {
const scope = GeckoViewWebExtension.extensionScopes.get(
sender.extensionId
);
if (scope) {
this.allowContentMessaging = scope.allowContentMessaging;
} else {
this.allowContentMessaging = false;
}
}
this.allowContentMessaging = allowContentMessaging;
if (!this.allowContentMessaging && !sender.verified) {
throw new Error(`Unexpected messaging sender: ${JSON.stringify(sender)}`);
@ -595,56 +584,13 @@ var GeckoViewWebExtension = {
}
},
async registerWebExtension(aId, aUri, allowContentMessaging, aCallback) {
const params = {
id: aId,
resourceURI: aUri,
temporarilyInstalled: true,
builtIn: true,
};
let file;
if (aUri instanceof Ci.nsIFileURL) {
file = aUri.file;
}
const scope = Extension.getBootstrapScope(aId, file);
scope.allowContentMessaging = allowContentMessaging;
// Always allow built-in extensions to run in private browsing
ExtensionPermissions.add(aId, PRIVATE_BROWSING_PERMISSION);
this.extensionScopes.set(aId, scope);
await scope.startup(params, undefined);
scope.extension.callOnClose({
close: () => this.extensionScopes.delete(aId),
});
},
async unregisterWebExtension(aId, aCallback) {
try {
const scope = this.extensionScopes.get(aId);
await scope.shutdown();
this.extensionScopes.delete(aId);
aCallback.onSuccess();
} catch (ex) {
aCallback.onError(`Error unregistering WebExtension ${aId}. ${ex}`);
}
},
async extensionById(aId) {
const scope = this.extensionScopes.get(aId);
if (!scope) {
// Check if this is an installed extension
const addon = await AddonManager.getAddonByID(aId);
if (!addon) {
debug`Could not find extension with id=${aId}`;
return null;
}
return addon;
const addon = await AddonManager.getAddonByID(aId);
if (!addon) {
debug`Could not find extension with id=${aId}`;
return null;
}
return scope.extension;
return addon;
},
async ensureBuiltIn(aUri, aId) {
@ -882,69 +828,11 @@ var GeckoViewWebExtension = {
break;
}
// TODO: Remove deprecated Bug 1634504
case "GeckoView:RegisterWebExtension": {
let uri;
try {
uri = Services.io.newURI(aData.locationUri);
} catch (ex) {
aCallback.onError(`Could not parse URI: ${aData.locationUri}`);
return;
}
if (
!uri ||
(!(uri instanceof Ci.nsIFileURL) && !(uri instanceof Ci.nsIJARURI))
) {
aCallback.onError(
`Extension does not point to a resource URI or a file URL. extension=${aData.locationUri}`
);
return;
}
if (uri.fileName != "" && uri.fileExtension != "xpi") {
aCallback.onError(
`Extension does not point to a folder or an .xpi file. Hint: the path needs to end with a "/" to be considered a folder. extension=${aData.locationUri}`
);
return;
}
if (this.extensionScopes.has(aData.id)) {
aCallback.onError(
`An extension with id='${aData.id}' has already been registered.`
);
return;
}
this.registerWebExtension(
aData.id,
uri,
aData.allowContentMessaging
).then(aCallback.onSuccess, error =>
aCallback.onError(
`An error occurred while registering the WebExtension ${aData.locationUri}: ${error}.`
)
);
break;
}
case "GeckoView:ActionDelegate:Attached": {
this.actionDelegateAttached(aData.extensionId);
break;
}
// TODO: Remove deprecated Bug 1634504
case "GeckoView:UnregisterWebExtension": {
if (!this.extensionScopes.has(aData.id)) {
aCallback.onError(
`Could not find an extension with id='${aData.id}'.`
);
return;
}
this.unregisterWebExtension(aData.id, aCallback);
break;
}
case "GeckoView:WebExtension:Get": {
const extension = await this.extensionById(aData.extensionId);
if (!extension) {
@ -1131,8 +1019,6 @@ var GeckoViewWebExtension = {
},
};
// TODO: Remove deprecated Bug 1634504
GeckoViewWebExtension.extensionScopes = new Map();
// WeakMap[Extension -> BrowserAction]
GeckoViewWebExtension.browserActions = new WeakMap();
// WeakMap[Extension -> PageAction]