Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: shell/android/apk/src/org/chromium/mojo/shell/IntentReceiverRegistry.java

Issue 1116653002: Introduce authentication service. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: shell/android/apk/src/org/chromium/mojo/shell/IntentReceiverRegistry.java
diff --git a/shell/android/apk/src/org/chromium/mojo/shell/IntentReceiverRegistry.java b/shell/android/apk/src/org/chromium/mojo/shell/IntentReceiverRegistry.java
index 3b52f954cb37bf1d3bc078838e5c868455811962..e6f39ff97ce3391dd6224419be4bcc348ebfa7a6 100644
--- a/shell/android/apk/src/org/chromium/mojo/shell/IntentReceiverRegistry.java
+++ b/shell/android/apk/src/org/chromium/mojo/shell/IntentReceiverRegistry.java
@@ -4,6 +4,7 @@
package org.chromium.mojo.shell;
+import android.app.Activity;
import android.content.Intent;
import android.os.Parcel;
@@ -37,6 +38,7 @@ public class IntentReceiverRegistry {
private final Map<String, Long> mReceiversByUuid = new HashMap<>();
private final Map<Long, String> mUuidsByReceiver = new HashMap<>();
+ private int mLastRequestCode = 0;
private IntentReceiverRegistry() {}
@@ -45,7 +47,19 @@ public class IntentReceiverRegistry {
if (uuid == null) return;
Long ptr = mReceiversByUuid.get(uuid);
if (ptr == null) return;
- nativeOnIntentReceived(ptr, intentToBuffer(intent));
+ nativeOnIntentReceived(ptr, true, intentToBuffer(intent));
+ }
+
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ String uuid = Integer.toString(requestCode);
+ if (uuid == null) return;
+ Long ptr = mReceiversByUuid.get(uuid);
+ if (ptr == null) return;
+ if (resultCode == Activity.RESULT_OK) {
+ nativeOnIntentReceived(ptr, true, intentToBuffer(data));
+ } else {
+ nativeOnIntentReceived(ptr, false, null);
+ }
}
private static ByteBuffer intentToBuffer(Intent intent) {
@@ -59,8 +73,24 @@ public class IntentReceiverRegistry {
return result;
}
+ private static Intent bufferToIntent(ByteBuffer buffer) {
+ Parcel p = Parcel.obtain();
+ byte[] bytes;
+ if (buffer.hasArray()) {
+ bytes = buffer.array();
+ } else {
+ bytes = new byte[buffer.limit()];
+ buffer.get(bytes, 0, buffer.limit());
+ }
+ p.unmarshall(bytes, 0, bytes.length);
+ p.setDataPosition(0);
+ Intent result = Intent.CREATOR.createFromParcel(p);
+ p.recycle();
+ return result;
+ }
+
@CalledByNative
- private static ByteBuffer registerReceiver(long intentDispatcher) {
+ private static ByteBuffer registerIntentReceiver(long intentDispatcher) {
IntentReceiverRegistry registry = getInstance();
String uuid = UUID.randomUUID().toString();
Intent intent = new Intent(
@@ -71,6 +101,26 @@ public class IntentReceiverRegistry {
}
@CalledByNative
+ private static ByteBuffer registerActivityResultReceiver(long intentDispatcher) {
+ IntentReceiverRegistry registry = getInstance();
+ String uuid;
+ // Handle unlikely overflows.
+ do {
+ ++registry.mLastRequestCode;
+ if (registry.mLastRequestCode < 1) {
+ registry.mLastRequestCode = 1;
+ }
+ uuid = Integer.toString(registry.mLastRequestCode);
+ } while (registry.mReceiversByUuid.keySet().contains(uuid));
+ registry.mReceiversByUuid.put(uuid, intentDispatcher);
+ registry.mUuidsByReceiver.put(intentDispatcher, uuid);
+ Intent intent = new Intent(
+ uuid, null, ApplicationStatus.getApplicationContext(), IntentReceiverService.class);
+ intent.addCategory(IntentReceiverService.CATEGORY_START_ACTIVITY_FOR_RESULT);
+ return intentToBuffer(intent);
+ }
+
+ @CalledByNative
private static void unregisterReceiver(long intentDispatcher) {
IntentReceiverRegistry registry = getInstance();
String uuid = registry.mUuidsByReceiver.get(intentDispatcher);
@@ -80,5 +130,6 @@ public class IntentReceiverRegistry {
}
}
- private static native void nativeOnIntentReceived(long intentDispatcher, ByteBuffer intent);
+ private static native void nativeOnIntentReceived(
+ long intentDispatcher, boolean accepted, ByteBuffer intent);
}

Powered by Google App Engine
This is Rietveld 408576698