зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1600742 - Require WebExtensionController in the WebExtension constructor. r=esawin,snorp
The controller will be used in a later patch to listen to delegates updates. Differential Revision: https://phabricator.services.mozilla.com/D57366 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8fb7253c6a
Коммит
6c81d2a85b
|
@ -53,7 +53,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
WebExtension extension = new WebExtension(
|
||||
"resource://android/assets/messaging/",
|
||||
"myextension",
|
||||
WebExtension.Flags.ALLOW_CONTENT_MESSAGING);
|
||||
WebExtension.Flags.ALLOW_CONTENT_MESSAGING,
|
||||
sRuntime.getWebExtensionController());
|
||||
|
||||
sRuntime.registerWebExtension(extension).exceptionally(e -> {
|
||||
Log.e("MessageDelegate", "Error registering WebExtension", e);
|
||||
|
|
|
@ -59,7 +59,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
};
|
||||
|
||||
WebExtension extension = new WebExtension(
|
||||
"resource://android/assets/messaging/");
|
||||
"resource://android/assets/messaging/",
|
||||
sRuntime.getWebExtensionController());
|
||||
|
||||
extension.setMessageDelegate(messageDelegate, "browser");
|
||||
|
||||
|
|
|
@ -1421,8 +1421,8 @@ package org.mozilla.geckoview {
|
|||
}
|
||||
|
||||
public class WebExtension {
|
||||
ctor public WebExtension(@NonNull String, @NonNull String, long);
|
||||
ctor public WebExtension(@NonNull String);
|
||||
ctor public WebExtension(@NonNull String, @NonNull String, long, @NonNull WebExtensionController);
|
||||
ctor public WebExtension(@NonNull String, @NonNull WebExtensionController);
|
||||
method @AnyThread public void setActionDelegate(@Nullable WebExtension.ActionDelegate);
|
||||
method @UiThread public void setMessageDelegate(@Nullable WebExtension.MessageDelegate, @NonNull String);
|
||||
field public final long flags;
|
||||
|
|
|
@ -49,7 +49,8 @@ class ExtensionActionTest : BaseSessionTest() {
|
|||
val backgroundPortResult = GeckoResult<WebExtension.Port>()
|
||||
|
||||
extension = WebExtension("resource://android/assets/web_extensions/actions/",
|
||||
"actions", WebExtension.Flags.ALLOW_CONTENT_MESSAGING)
|
||||
"actions", WebExtension.Flags.ALLOW_CONTENT_MESSAGING,
|
||||
sessionRule.runtime.webExtensionController)
|
||||
|
||||
sessionRule.session.setMessageDelegate(
|
||||
extension!!,
|
||||
|
|
|
@ -69,7 +69,8 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
assertThat("The border color should be empty when loading without extensions.",
|
||||
colorBefore as String, equalTo(""))
|
||||
|
||||
val borderify = WebExtension("resource://android/assets/web_extensions/borderify/")
|
||||
val borderify = WebExtension("resource://android/assets/web_extensions/borderify/",
|
||||
controller)
|
||||
|
||||
// Load the WebExtension that will add a border to the body
|
||||
sessionRule.waitForResult(sessionRule.runtime.registerWebExtension(borderify))
|
||||
|
@ -280,7 +281,7 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
}
|
||||
}
|
||||
controller.tabDelegate = tabDelegate
|
||||
tabsExtension = WebExtension(TABS_CREATE_BACKGROUND)
|
||||
tabsExtension = WebExtension(TABS_CREATE_BACKGROUND, controller)
|
||||
|
||||
sessionRule.waitForResult(sessionRule.runtime.registerWebExtension(tabsExtension))
|
||||
sessionRule.waitForResult(tabsCreateResult)
|
||||
|
@ -321,7 +322,7 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
}
|
||||
})
|
||||
|
||||
tabsExtension = WebExtension(TABS_CREATE_REMOVE_BACKGROUND)
|
||||
tabsExtension = WebExtension(TABS_CREATE_REMOVE_BACKGROUND, controller)
|
||||
|
||||
sessionRule.waitForResult(sessionRule.runtime.registerWebExtension(tabsExtension))
|
||||
sessionRule.waitForResult(onCloseRequestResult)
|
||||
|
@ -357,7 +358,7 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
}
|
||||
})
|
||||
|
||||
val tabsExtension = WebExtension(TABS_REMOVE_BACKGROUND)
|
||||
val tabsExtension = WebExtension(TABS_REMOVE_BACKGROUND, controller)
|
||||
|
||||
sessionRule.waitForResult(sessionRule.runtime.registerWebExtension(tabsExtension))
|
||||
sessionRule.waitForResult(onCloseRequestResult)
|
||||
|
@ -371,11 +372,12 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
val uuid = "{${UUID.randomUUID()}}"
|
||||
|
||||
if (background) {
|
||||
webExtension = WebExtension(MESSAGING_BACKGROUND, uuid, WebExtension.Flags.NONE)
|
||||
webExtension = WebExtension(MESSAGING_BACKGROUND, uuid, WebExtension.Flags.NONE,
|
||||
controller)
|
||||
webExtension.setMessageDelegate(messageDelegate, "browser")
|
||||
} else {
|
||||
webExtension = WebExtension(MESSAGING_CONTENT, uuid,
|
||||
WebExtension.Flags.ALLOW_CONTENT_MESSAGING)
|
||||
WebExtension.Flags.ALLOW_CONTENT_MESSAGING, controller)
|
||||
sessionRule.session.setMessageDelegate(webExtension, messageDelegate, "browser")
|
||||
}
|
||||
|
||||
|
@ -680,7 +682,7 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
}
|
||||
|
||||
messaging = WebExtension("resource://android/assets/web_extensions/messaging-iframe/",
|
||||
"{${UUID.randomUUID()}}", WebExtension.Flags.ALLOW_CONTENT_MESSAGING)
|
||||
"{${UUID.randomUUID()}}", WebExtension.Flags.ALLOW_CONTENT_MESSAGING, controller)
|
||||
sessionRule.session.setMessageDelegate(messaging, messageDelegate, "browser")
|
||||
|
||||
sessionRule.waitForResult(sessionRule.runtime.registerWebExtension(messaging))
|
||||
|
@ -723,7 +725,8 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
}
|
||||
}
|
||||
|
||||
extension = WebExtension("resource://android/assets/web_extensions/extension-page-update/")
|
||||
extension = WebExtension("resource://android/assets/web_extensions/extension-page-update/",
|
||||
controller)
|
||||
|
||||
sessionRule.waitForResult(sessionRule.runtime.registerWebExtension(extension))
|
||||
mainSession.setMessageDelegate(extension, messageDelegate, "browser")
|
||||
|
@ -811,7 +814,7 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
private fun testRegisterError(location: String, expectedError: String) {
|
||||
try {
|
||||
sessionRule.waitForResult(sessionRule.runtime.registerWebExtension(
|
||||
WebExtension(location)
|
||||
WebExtension(location, controller)
|
||||
))
|
||||
} catch (ex: Exception) {
|
||||
// Let's make sure the error message contains the WebExtension URL
|
||||
|
|
|
@ -1093,7 +1093,7 @@ public class GeckoSessionTestRule implements TestRule {
|
|||
}
|
||||
|
||||
protected void prepareSession(final GeckoSession session) {
|
||||
session.setMessageDelegate(RuntimeCreator.TEST_SUPPORT_WEB_EXTENSION, mMessageDelegate,
|
||||
session.setMessageDelegate(RuntimeCreator.sTestSupportExtension, mMessageDelegate,
|
||||
"browser");
|
||||
for (final Class<?> cls : DEFAULT_DELEGATES) {
|
||||
try {
|
||||
|
|
|
@ -23,10 +23,7 @@ public class RuntimeCreator {
|
|||
|
||||
private static GeckoRuntime sRuntime;
|
||||
public static AtomicInteger sTestSupport = new AtomicInteger(0);
|
||||
public static final WebExtension TEST_SUPPORT_WEB_EXTENSION =
|
||||
new WebExtension("resource://android/assets/web_extensions/test-support/",
|
||||
"test-support@mozilla.com",
|
||||
WebExtension.Flags.ALLOW_CONTENT_MESSAGING);
|
||||
public static WebExtension sTestSupportExtension;
|
||||
|
||||
// The RuntimeTelemetry.Delegate can only be set when creating the RuntimeCreator, to
|
||||
// let tests set their own Delegate we need to create a proxy here.
|
||||
|
@ -94,7 +91,15 @@ public class RuntimeCreator {
|
|||
|
||||
public static void registerTestSupport() {
|
||||
sTestSupport.set(0);
|
||||
sRuntime.registerWebExtension(TEST_SUPPORT_WEB_EXTENSION)
|
||||
sTestSupportExtension =
|
||||
new WebExtension("resource://android/assets/web_extensions/test-support/",
|
||||
"test-support@mozilla.com",
|
||||
WebExtension.Flags.ALLOW_CONTENT_MESSAGING,
|
||||
sRuntime.getWebExtensionController());
|
||||
|
||||
sTestSupportExtension.setMessageDelegate(sMessageDelegate, "browser");
|
||||
|
||||
sRuntime.registerWebExtension(sTestSupportExtension)
|
||||
.accept(value -> {
|
||||
sTestSupport.set(TEST_SUPPORT_OK);
|
||||
}, exception -> {
|
||||
|
@ -124,8 +129,6 @@ public class RuntimeCreator {
|
|||
return sRuntime;
|
||||
}
|
||||
|
||||
TEST_SUPPORT_WEB_EXTENSION.setMessageDelegate(sMessageDelegate, "browser");
|
||||
|
||||
final GeckoRuntimeSettings runtimeSettings = new GeckoRuntimeSettings.Builder()
|
||||
.arguments(new String[]{"-purgecaches"})
|
||||
.extras(InstrumentationRegistry.getArguments())
|
||||
|
|
|
@ -159,9 +159,11 @@ public class WebExtension {
|
|||
* </a>
|
||||
* </ul>
|
||||
* @param flags {@link Flags} for this WebExtension.
|
||||
* @param controller the current {@link WebExtensionController} instance
|
||||
*/
|
||||
public WebExtension(final @NonNull String location, final @NonNull String id,
|
||||
final @WebExtensionFlags long flags) {
|
||||
final @WebExtensionFlags long flags,
|
||||
final @NonNull WebExtensionController controller) {
|
||||
this.location = location;
|
||||
this.id = id;
|
||||
this.flags = flags;
|
||||
|
@ -184,9 +186,11 @@ public class WebExtension {
|
|||
* @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
|
||||
*/
|
||||
public WebExtension(final @NonNull String location) {
|
||||
this(location, "{" + UUID.randomUUID().toString() + "}", Flags.NONE);
|
||||
public WebExtension(final @NonNull String location,
|
||||
final @NonNull WebExtensionController controller) {
|
||||
this(location, "{" + UUID.randomUUID().toString() + "}", Flags.NONE, controller);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,8 @@ exclude: true
|
|||
attaching a [`LoginStorage.Delegate`][73.8] via
|
||||
[`GeckoRuntime#setLoginStorageDelegate`][73.9]
|
||||
([bug 1602881]({{bugzilla}}1602881))
|
||||
- ⚠️ [`WebExtension`][69.5]'s constructor now requires a `WebExtensionController`
|
||||
instance.
|
||||
|
||||
|
||||
[73.1]: {{javadoc_uri}}/WebExtensionController.html#install-java.lang.String-
|
||||
|
@ -504,4 +506,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]: 07ee732ba2eaafada09739c61c0196e427a2f0ed
|
||||
[api-version]: b0fb9d3cfdb5503a94f1c17c64a801970d36a69d
|
||||
|
|
Загрузка…
Ссылка в новой задаче