Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java |
| index 5fe13a3583fad9cb49531491e2635c90823778b5..105d061b62564a8956e3db789182b7219b33bf4f 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java |
| @@ -4,15 +4,20 @@ |
| package org.chromium.chrome.browser.physicalweb; |
| +import android.app.Activity; |
| import android.content.Intent; |
| import android.os.Build; |
| import android.os.Bundle; |
| import android.support.v7.app.AppCompatActivity; |
| +import org.chromium.base.ApplicationStatus; |
| +import org.chromium.chrome.browser.ChromeActivity; |
| import org.chromium.chrome.browser.share.ShareHelper; |
| import org.chromium.chrome.browser.tab.Tab; |
| import org.chromium.chrome.browser.util.IntentUtils; |
| +import java.lang.ref.WeakReference; |
| +import java.util.List; |
| /** |
| * A simple activity that allows Chrome to start the physical web sharing service. |
| */ |
| @@ -35,10 +40,37 @@ public class PhysicalWebShareActivity extends AppCompatActivity { |
| } |
| private void handleShareAction() { |
| - // TODO(iankc): implement sharing |
| + ChromeActivity openPage = getTriggeringActivity(); |
| + if (openPage == null) return; |
| + |
| + Intent intent = new Intent(this, PhysicalWebBroadcastService.class); |
| + intent.putExtra( |
| + PhysicalWebBroadcastService.DISPLAY_URL_KEY, openPage.getActivityTab().getUrl()); |
| + startService(intent); |
| } |
| public static boolean sharingIsEnabled(Tab currentTab) { |
| return PhysicalWeb.sharingIsEnabled() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; |
| } |
| + |
| + /** |
| + * Returns the ChromeActivity that called the share intent picker. |
| + */ |
| + protected ChromeActivity getTriggeringActivity() { |
|
cco3
2017/02/25 00:09:26
If we have to add code like this, I'd prefer you m
|
| + int triggeringTaskId = |
| + IntentUtils.safeGetIntExtra(getIntent(), ShareHelper.EXTRA_TASK_ID, 0); |
| + List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); |
| + ChromeActivity triggeringActivity = null; |
| + for (int i = 0; i < activities.size(); i++) { |
| + Activity activity = activities.get(i).get(); |
| + if (activity == null) continue; |
| + |
| + // Since the share intent is triggered without NEW_TASK or NEW_DOCUMENT, the task ID |
| + // of this activity will match that of the triggering activity. |
| + if (activity.getTaskId() == triggeringTaskId && activity instanceof ChromeActivity) { |
| + return (ChromeActivity) activity; |
| + } |
| + } |
| + return null; |
| + } |
| } |