зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1698823 - Don't allow null delegateController. r=aklotz,droeh
We used to support having a null delegateController because WebExtension could be constructed from the app. Now that we can only go through the Controller we don't need to do that anymore. Differential Revision: https://phabricator.services.mozilla.com/D108695
This commit is contained in:
Родитель
da4c6fbb94
Коммит
f6eb2f79b8
|
@ -72,12 +72,12 @@ public class WebExtension {
|
|||
DownloadDelegate getDownloadDelegate();
|
||||
}
|
||||
|
||||
private DelegateController mDelegateController = null;
|
||||
|
||||
/* package */ void setDelegateController(final DelegateController delegate) {
|
||||
mDelegateController = delegate;
|
||||
/* package */ interface DelegateControllerProvider {
|
||||
@NonNull DelegateController controllerFor(final WebExtension extension);
|
||||
}
|
||||
|
||||
private final DelegateController mDelegateController;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WebExtension {" +
|
||||
|
@ -110,7 +110,8 @@ public class WebExtension {
|
|||
value = { Flags.NONE, Flags.ALLOW_CONTENT_MESSAGING })
|
||||
/* package */ @interface WebExtensionFlags {}
|
||||
|
||||
/* package */ WebExtension(final GeckoBundle bundle) {
|
||||
/* package */ WebExtension(final DelegateControllerProvider provider,
|
||||
final GeckoBundle bundle) {
|
||||
location = bundle.getString("locationURI");
|
||||
id = bundle.getString("webExtensionId");
|
||||
flags = bundle.getInt("webExtensionFlags", 0);
|
||||
|
@ -120,6 +121,7 @@ public class WebExtension {
|
|||
} else {
|
||||
metaData = null;
|
||||
}
|
||||
mDelegateController = provider.controllerFor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,9 +175,7 @@ public class WebExtension {
|
|||
@UiThread
|
||||
public void setMessageDelegate(final @Nullable MessageDelegate messageDelegate,
|
||||
final @NonNull String nativeApp) {
|
||||
if (mDelegateController != null) {
|
||||
mDelegateController.onMessageDelegate(nativeApp, messageDelegate);
|
||||
}
|
||||
mDelegateController.onMessageDelegate(nativeApp, messageDelegate);
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
|
@ -817,9 +817,7 @@ public class WebExtension {
|
|||
*/
|
||||
@UiThread
|
||||
public void setTabDelegate(final @Nullable TabDelegate delegate) {
|
||||
if (mDelegateController != null) {
|
||||
mDelegateController.onTabDelegate(delegate);
|
||||
}
|
||||
mDelegateController.onTabDelegate(delegate);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
@ -830,9 +828,7 @@ public class WebExtension {
|
|||
|
||||
@UiThread
|
||||
public void setBrowsingDataDelegate(final @Nullable BrowsingDataDelegate delegate) {
|
||||
if (mDelegateController != null) {
|
||||
mDelegateController.onBrowsingDataDelegate(delegate);
|
||||
}
|
||||
mDelegateController.onBrowsingDataDelegate(delegate);
|
||||
}
|
||||
|
||||
private static class Sender {
|
||||
|
@ -1216,11 +1212,12 @@ public class WebExtension {
|
|||
}
|
||||
}
|
||||
|
||||
/* package */ static WebExtension fromBundle(final GeckoBundle bundle) {
|
||||
/* package */ static WebExtension fromBundle(final DelegateControllerProvider provider,
|
||||
final GeckoBundle bundle) {
|
||||
if (bundle == null) {
|
||||
return null;
|
||||
}
|
||||
return new WebExtension(bundle.getBundle("extension"));
|
||||
return new WebExtension(provider, bundle.getBundle("extension"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1673,9 +1670,7 @@ public class WebExtension {
|
|||
*/
|
||||
@AnyThread
|
||||
public void setActionDelegate(final @Nullable ActionDelegate delegate) {
|
||||
if (mDelegateController != null) {
|
||||
mDelegateController.onActionDelegate(delegate);
|
||||
}
|
||||
mDelegateController.onActionDelegate(delegate);
|
||||
|
||||
final GeckoBundle bundle = new GeckoBundle(1);
|
||||
bundle.putString("extensionId", id);
|
||||
|
@ -2260,9 +2255,7 @@ public class WebExtension {
|
|||
*/
|
||||
@UiThread
|
||||
public void setDownloadDelegate(final @Nullable DownloadDelegate delegate) {
|
||||
if (mDelegateController != null) {
|
||||
mDelegateController.onDownloadDelegate(delegate);
|
||||
}
|
||||
mDelegateController.onDownloadDelegate(delegate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,7 +66,7 @@ public class WebExtensionController {
|
|||
*
|
||||
* @param extension the newly-created extension object
|
||||
*/
|
||||
void onNewExtension(final WebExtension extension);
|
||||
WebExtension onNewExtension(final GeckoBundle extension);
|
||||
}
|
||||
|
||||
public GeckoResult<WebExtension> get(final String id) {
|
||||
|
@ -80,10 +80,9 @@ public class WebExtensionController {
|
|||
|
||||
final GeckoResult<WebExtension> pending = EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:Get", bundle)
|
||||
.map(WebExtension::fromBundle)
|
||||
.map(ext -> {
|
||||
.map(extensionBundle -> {
|
||||
final WebExtension ext = mObserver.onNewExtension(extensionBundle);
|
||||
mData.put(ext.id, ext);
|
||||
mObserver.onNewExtension(ext);
|
||||
return ext;
|
||||
});
|
||||
|
||||
|
@ -124,8 +123,8 @@ public class WebExtensionController {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onNewExtension(final WebExtension extension) {
|
||||
extension.setDelegateController(new DelegateController(extension));
|
||||
public WebExtension onNewExtension(final GeckoBundle bundle) {
|
||||
return WebExtension.fromBundle(mDelegateControllerProvider, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,6 +221,14 @@ public class WebExtensionController {
|
|||
}
|
||||
}
|
||||
|
||||
final WebExtension.DelegateControllerProvider mDelegateControllerProvider =
|
||||
new WebExtension.DelegateControllerProvider() {
|
||||
@Override
|
||||
public WebExtension.DelegateController controllerFor(final WebExtension extension) {
|
||||
return new DelegateController(extension);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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>
|
||||
|
@ -419,7 +426,7 @@ public class WebExtensionController {
|
|||
|
||||
final GeckoResult<WebExtension> result = EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:Install", bundle)
|
||||
.map(WebExtension::fromBundle,
|
||||
.map(ext -> WebExtension.fromBundle(mDelegateControllerProvider, ext),
|
||||
WebExtension.InstallException::fromQueryException)
|
||||
.map(this::registerWebExtension);
|
||||
result.setCancellationDelegate(canceller);
|
||||
|
@ -445,7 +452,7 @@ public class WebExtensionController {
|
|||
|
||||
return EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:SetPBAllowed", bundle)
|
||||
.map(WebExtension::fromBundle)
|
||||
.map(ext -> WebExtension.fromBundle(mDelegateControllerProvider, ext))
|
||||
.map(this::registerWebExtension);
|
||||
}
|
||||
|
||||
|
@ -479,7 +486,7 @@ public class WebExtensionController {
|
|||
|
||||
return EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:InstallBuiltIn", bundle)
|
||||
.map(WebExtension::fromBundle,
|
||||
.map(ext -> WebExtension.fromBundle(mDelegateControllerProvider, ext),
|
||||
WebExtension.InstallException::fromQueryException)
|
||||
.map(this::registerWebExtension);
|
||||
}
|
||||
|
@ -516,7 +523,7 @@ public class WebExtensionController {
|
|||
|
||||
return EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:EnsureBuiltIn", bundle)
|
||||
.map(WebExtension::fromBundle,
|
||||
.map(ext -> WebExtension.fromBundle(mDelegateControllerProvider, ext),
|
||||
WebExtension.InstallException::fromQueryException)
|
||||
.map(this::registerWebExtension);
|
||||
}
|
||||
|
@ -586,7 +593,7 @@ public class WebExtensionController {
|
|||
|
||||
return EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:Enable", bundle)
|
||||
.map(WebExtension::fromBundle)
|
||||
.map(ext -> WebExtension.fromBundle(mDelegateControllerProvider, ext))
|
||||
.map(this::registerWebExtension);
|
||||
}
|
||||
|
||||
|
@ -609,7 +616,7 @@ public class WebExtensionController {
|
|||
|
||||
return EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:Disable", bundle)
|
||||
.map(WebExtension::fromBundle)
|
||||
.map(ext -> WebExtension.fromBundle(mDelegateControllerProvider, ext))
|
||||
.map(this::registerWebExtension);
|
||||
}
|
||||
|
||||
|
@ -618,7 +625,7 @@ public class WebExtensionController {
|
|||
final List<WebExtension> list = new ArrayList<>(bundles.length);
|
||||
|
||||
for (GeckoBundle bundle : bundles) {
|
||||
final WebExtension extension = new WebExtension(bundle);
|
||||
final WebExtension extension = new WebExtension(mDelegateControllerProvider, bundle);
|
||||
list.add(registerWebExtension(extension));
|
||||
}
|
||||
|
||||
|
@ -671,7 +678,7 @@ public class WebExtensionController {
|
|||
|
||||
return EventDispatcher.getInstance()
|
||||
.queryBundle("GeckoView:WebExtension:Update", bundle)
|
||||
.map(WebExtension::fromBundle,
|
||||
.map(ext -> WebExtension.fromBundle(mDelegateControllerProvider, ext),
|
||||
WebExtension.InstallException::fromQueryException)
|
||||
.map(this::registerWebExtension);
|
||||
}
|
||||
|
@ -688,7 +695,6 @@ public class WebExtensionController {
|
|||
|
||||
/* package */ WebExtension registerWebExtension(final WebExtension webExtension) {
|
||||
if (webExtension != null) {
|
||||
webExtension.setDelegateController(new DelegateController(webExtension));
|
||||
mExtensions.update(webExtension.id, webExtension);
|
||||
}
|
||||
return webExtension;
|
||||
|
@ -799,8 +805,8 @@ public class WebExtensionController {
|
|||
return;
|
||||
}
|
||||
|
||||
final WebExtension extension = new WebExtension(extensionBundle);
|
||||
extension.setDelegateController(new DelegateController(extension));
|
||||
final WebExtension extension =
|
||||
new WebExtension(mDelegateControllerProvider, extensionBundle);
|
||||
|
||||
if (mPromptDelegate == null) {
|
||||
Log.e(LOGTAG, "Tried to install extension " + extension.id +
|
||||
|
@ -834,11 +840,11 @@ public class WebExtensionController {
|
|||
return;
|
||||
}
|
||||
|
||||
final WebExtension currentExtension = new WebExtension(currentBundle);
|
||||
currentExtension.setDelegateController(new DelegateController(currentExtension));
|
||||
final WebExtension currentExtension =
|
||||
new WebExtension(mDelegateControllerProvider, currentBundle);
|
||||
|
||||
final WebExtension updatedExtension = new WebExtension(updatedBundle);
|
||||
updatedExtension.setDelegateController(new DelegateController(updatedExtension));
|
||||
final WebExtension updatedExtension =
|
||||
new WebExtension(mDelegateControllerProvider, updatedBundle);
|
||||
|
||||
if (mPromptDelegate == null) {
|
||||
Log.e(LOGTAG, "Tried to update extension " + currentExtension.id +
|
||||
|
@ -1048,7 +1054,6 @@ public class WebExtensionController {
|
|||
|
||||
/* package */ void unregisterWebExtension(final WebExtension webExtension) {
|
||||
mExtensions.remove(webExtension.id);
|
||||
webExtension.setDelegateController(null);
|
||||
mListener.unregisterWebExtension(webExtension);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче