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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java

Issue 2719493003: Add PhysicalWebBroadcastService (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.physicalweb; 5 package org.chromium.chrome.browser.physicalweb;
6 6
7 import android.app.Activity;
7 import android.content.Intent; 8 import android.content.Intent;
8 import android.os.Build; 9 import android.os.Build;
9 import android.os.Bundle; 10 import android.os.Bundle;
10 import android.support.v7.app.AppCompatActivity; 11 import android.support.v7.app.AppCompatActivity;
11 12
13 import org.chromium.base.ApplicationStatus;
14 import org.chromium.chrome.browser.ChromeActivity;
12 import org.chromium.chrome.browser.share.ShareHelper; 15 import org.chromium.chrome.browser.share.ShareHelper;
13 import org.chromium.chrome.browser.tab.Tab; 16 import org.chromium.chrome.browser.tab.Tab;
14 import org.chromium.chrome.browser.util.IntentUtils; 17 import org.chromium.chrome.browser.util.IntentUtils;
15 18
19 import java.lang.ref.WeakReference;
20 import java.util.List;
16 /** 21 /**
17 * A simple activity that allows Chrome to start the physical web sharing servic e. 22 * A simple activity that allows Chrome to start the physical web sharing servic e.
18 */ 23 */
19 public class PhysicalWebShareActivity extends AppCompatActivity { 24 public class PhysicalWebShareActivity extends AppCompatActivity {
20 private static final String TAG = "PhysicalWebShareActivity"; 25 private static final String TAG = "PhysicalWebShareActivity";
21 26
22 @Override 27 @Override
23 protected void onCreate(Bundle savedInstanceState) { 28 protected void onCreate(Bundle savedInstanceState) {
24 super.onCreate(savedInstanceState); 29 super.onCreate(savedInstanceState);
25 30
26 try { 31 try {
27 Intent intent = getIntent(); 32 Intent intent = getIntent();
28 if (intent == null) return; 33 if (intent == null) return;
29 if (!Intent.ACTION_SEND.equals(intent.getAction())) return; 34 if (!Intent.ACTION_SEND.equals(intent.getAction())) return;
30 if (!IntentUtils.safeHasExtra(getIntent(), ShareHelper.EXTRA_TASK_ID )) return; 35 if (!IntentUtils.safeHasExtra(getIntent(), ShareHelper.EXTRA_TASK_ID )) return;
31 handleShareAction(); 36 handleShareAction();
32 } finally { 37 } finally {
33 finish(); 38 finish();
34 } 39 }
35 } 40 }
36 41
37 private void handleShareAction() { 42 private void handleShareAction() {
38 // TODO(iankc): implement sharing 43 ChromeActivity openPage = getTriggeringActivity();
44 if (openPage == null) return;
45
46 Intent intent = new Intent(this, PhysicalWebBroadcastService.class);
47 intent.putExtra(
48 PhysicalWebBroadcastService.DISPLAY_URL_KEY, openPage.getActivit yTab().getUrl());
49 startService(intent);
39 } 50 }
40 51
41 public static boolean sharingIsEnabled(Tab currentTab) { 52 public static boolean sharingIsEnabled(Tab currentTab) {
42 return PhysicalWeb.sharingIsEnabled() && Build.VERSION.SDK_INT >= Build. VERSION_CODES.M; 53 return PhysicalWeb.sharingIsEnabled() && Build.VERSION.SDK_INT >= Build. VERSION_CODES.M;
43 } 54 }
55
56 /**
57 * Returns the ChromeActivity that called the share intent picker.
58 */
59 protected ChromeActivity getTriggeringActivity() {
cco3 2017/02/25 00:09:26 If we have to add code like this, I'd prefer you m
60 int triggeringTaskId =
61 IntentUtils.safeGetIntExtra(getIntent(), ShareHelper.EXTRA_TASK_ ID, 0);
62 List<WeakReference<Activity>> activities = ApplicationStatus.getRunningA ctivities();
63 ChromeActivity triggeringActivity = null;
64 for (int i = 0; i < activities.size(); i++) {
65 Activity activity = activities.get(i).get();
66 if (activity == null) continue;
67
68 // Since the share intent is triggered without NEW_TASK or NEW_DOCUM ENT, the task ID
69 // of this activity will match that of the triggering activity.
70 if (activity.getTaskId() == triggeringTaskId && activity instanceof ChromeActivity) {
71 return (ChromeActivity) activity;
72 }
73 }
74 return null;
75 }
44 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698