mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 974001 - Allow HelperApps to return results if requested. r=wesj
This commit is contained in:
parent
14f1d00d07
commit
12ba802815
@ -686,6 +686,36 @@ public abstract class GeckoApp
|
||||
GeckoAppShell.openUriExternal(message.optString("url"),
|
||||
message.optString("mime"), message.optString("packageName"),
|
||||
message.optString("className"), message.optString("action"), message.optString("title"));
|
||||
} else if (event.equals("Intent:OpenForResult")) {
|
||||
Intent intent = GeckoAppShell.getOpenURIIntent(this,
|
||||
message.optString("url"),
|
||||
message.optString("mime"),
|
||||
message.optString("action"),
|
||||
message.optString("title"));
|
||||
intent.setClassName(message.optString("packageName"), message.optString("className"));
|
||||
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
|
||||
final JSONObject originalMessage = message;
|
||||
ActivityHandlerHelper.startIntentForActivity(this,
|
||||
intent,
|
||||
new ActivityResultHandler() {
|
||||
@Override
|
||||
public void onActivityResult (int resultCode, Intent data) {
|
||||
JSONObject response = new JSONObject();
|
||||
|
||||
try {
|
||||
if (data != null) {
|
||||
response.put("extras", bundleToJSON(data.getExtras()));
|
||||
}
|
||||
response.put("resultCode", resultCode);
|
||||
} catch (JSONException e) {
|
||||
Log.w(LOGTAG, "Error building JSON response.", e);
|
||||
}
|
||||
|
||||
EventDispatcher.sendResponse(originalMessage, response);
|
||||
}
|
||||
});
|
||||
} else if (event.equals("Locale:Set")) {
|
||||
setLocale(message.getString("locale"));
|
||||
} else if (event.equals("NativeApp:IsDebuggable")) {
|
||||
@ -846,6 +876,23 @@ public abstract class GeckoApp
|
||||
});
|
||||
}
|
||||
|
||||
private JSONObject bundleToJSON(Bundle bundle) {
|
||||
JSONObject json = new JSONObject();
|
||||
if (bundle == null) {
|
||||
return json;
|
||||
}
|
||||
|
||||
for (String key : bundle.keySet()) {
|
||||
try {
|
||||
json.put(key, bundle.get(key));
|
||||
} catch (JSONException e) {
|
||||
Log.w(LOGTAG, "Error building JSON response.", e);
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
private void addFullScreenPluginView(View view) {
|
||||
if (mFullScreenPluginView != null) {
|
||||
Log.w(LOGTAG, "Already have a fullscreen plugin view");
|
||||
@ -1537,6 +1584,7 @@ public abstract class GeckoApp
|
||||
registerEventListener("PrivateBrowsing:Data");
|
||||
registerEventListener("Contact:Add");
|
||||
registerEventListener("Intent:Open");
|
||||
registerEventListener("Intent:OpenForResult");
|
||||
registerEventListener("Intent:GetHandlers");
|
||||
registerEventListener("Locale:Set");
|
||||
registerEventListener("NativeApp:IsDebuggable");
|
||||
|
@ -27,8 +27,9 @@ function App(data) {
|
||||
}
|
||||
|
||||
App.prototype = {
|
||||
launch: function(uri) {
|
||||
HelperApps._launchApp(this, uri);
|
||||
// callback will be null if a result is not requested
|
||||
launch: function(uri, callback) {
|
||||
HelperApps._launchApp(this, uri, callback);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -166,13 +167,24 @@ var HelperApps = {
|
||||
};
|
||||
},
|
||||
|
||||
_launchApp: function launchApp(app, uri) {
|
||||
_launchApp: function launchApp(app, uri, callback) {
|
||||
if (callback) {
|
||||
let msg = this._getMessage("Intent:OpenForResult", uri, {
|
||||
packageName: app.packageName,
|
||||
className: app.activityName
|
||||
});
|
||||
|
||||
sendMessageToJava(msg, function(data) {
|
||||
callback(JSON.parse(data));
|
||||
});
|
||||
} else {
|
||||
let msg = this._getMessage("Intent:Open", uri, {
|
||||
packageName: app.packageName,
|
||||
className: app.activityName
|
||||
});
|
||||
|
||||
sendMessageToJava(msg);
|
||||
}
|
||||
},
|
||||
|
||||
_sendMessageSync: function(msg) {
|
||||
|
Loading…
Reference in New Issue
Block a user