Bug 1412872 - 6. Remove default prompt delegate support; r=snorp

Remove support for a default prompt delegate in GeckoView. Instead, all
prompts without a known window will go to the active GeckoView if
available.

MozReview-Commit-ID: C62V6jtgDCl
This commit is contained in:
Jim Chen 2017-11-01 14:54:03 -04:00
Родитель e8b3470987
Коммит e6d6cbb51a
2 изменённых файлов: 31 добавлений и 72 удалений

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

@ -9,6 +9,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
EventDispatcher: "resource://gre/modules/Messaging.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm",
GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
});
@ -358,19 +359,12 @@ function PromptDelegate(aDomWin) {
return;
}
this._dispatcher = EventDispatcher.instance;
if (!aDomWin) {
return;
if (aDomWin) {
this._dispatcher = GeckoViewUtils.getDispatcherForWindow(aDomWin);
}
let gvWin = aDomWin.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell).QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
try {
this._dispatcher = gvWin.WindowEventDispatcher || EventDispatcher.for(gvWin);
} catch (e) {
// Use global dispatcher.
if (!this._dispatcher) {
this._dispatcher = GeckoViewUtils.getActiveDispatcher();
}
}
@ -457,24 +451,31 @@ PromptDelegate.prototype = {
}
let handled = false;
let onResponse = response => {
if (handled) {
return;
}
aCallback(response);
// This callback object is tied to the Java garbage collector because
// it is invoked from Java. Manually release the target callback
// here; otherwise we may hold onto resources for too long, because
// we would be relying on both the Java and the JS garbage collectors
// to run.
aMsg = undefined;
aCallback = undefined;
handled = true;
};
if (!this._dispatcher) {
onResponse(null);
return;
}
this._dispatcher.dispatch("GeckoView:Prompt", aMsg, {
onSuccess: response => {
if (handled) {
return;
}
aCallback(response);
// This callback object is tied to the Java garbage collector because
// it is invoked from Java. Manually release the target callback
// here; otherwise we may hold onto resources for too long, because
// we would be relying on both the Java and the JS garbage collectors
// to run.
aMsg = undefined;
aCallback = undefined;
handled = true;
},
onSuccess: onResponse,
onError: error => {
Cu.reportError("Prompt error: " + error);
this.onSuccess(null);
onResponse(null);
},
});
},

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

@ -75,20 +75,6 @@ public class GeckoView extends LayerView {
}
}
static {
EventDispatcher.getInstance().registerUiThreadListener(new BundleEventListener() {
@Override
public void handleMessage(final String event, final GeckoBundle message,
final EventCallback callback) {
if ("GeckoView:Prompt".equals(event)) {
handlePromptEvent(/* view */ null, message, callback);
}
}
}, "GeckoView:Prompt");
}
private static PromptDelegate sDefaultPromptDelegate;
private final NativeQueue mNativeQueue =
new NativeQueue(State.INITIAL, State.READY);
@ -860,17 +846,6 @@ public class GeckoView extends LayerView {
return mNavigationHandler.getListener();
}
/**
* Set the default prompt delegate for all GeckoView instances. The default prompt
* delegate is used for certain types of prompts and for GeckoViews that do not have
* custom prompt delegates.
* @param delegate PromptDelegate instance or null to use the built-in delegate.
* @see #setPromptDelegate(PromptDelegate)
*/
public static void setDefaultPromptDelegate(PromptDelegate delegate) {
sDefaultPromptDelegate = delegate;
}
/**
* Set the content scroll callback handler.
* This will replace the current handler.
@ -880,19 +855,9 @@ public class GeckoView extends LayerView {
mScrollHandler.setListener(listener, this);
}
/**
* Get the default prompt delegate for all GeckoView instances.
* @return PromptDelegate instance
* @see #getPromptDelegate()
*/
public static PromptDelegate getDefaultPromptDelegate() {
return sDefaultPromptDelegate;
}
/**
* Set the current prompt delegate for this GeckoView.
* @param delegate PromptDelegate instance or null to use the default delegate.
* @see #setDefaultPromptDelegate(PromptDelegate)
* @param delegate PromptDelegate instance or null to use the built-in delegate.
*/
public void setPromptDelegate(PromptDelegate delegate) {
mPromptDelegate = delegate;
@ -900,8 +865,7 @@ public class GeckoView extends LayerView {
/**
* Get the current prompt delegate for this GeckoView.
* @return PromptDelegate instance or null if using default delegate.
* @see #getDefaultPromptDelegate()
* @return PromptDelegate instance or null if using built-in delegate.
*/
public PromptDelegate getPromptDelegate() {
return mPromptDelegate;
@ -1132,13 +1096,7 @@ public class GeckoView extends LayerView {
/* package */ static void handlePromptEvent(final GeckoView view,
final GeckoBundle message,
final EventCallback callback) {
final PromptDelegate delegate;
if (view != null && view.mPromptDelegate != null) {
delegate = view.mPromptDelegate;
} else {
delegate = sDefaultPromptDelegate;
}
final PromptDelegate delegate = view.getPromptDelegate();
if (delegate == null) {
// Default behavior is same as calling dismiss() on callback.
callback.sendSuccess(null);