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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java

Issue 2666833002: Create entry to PWSharing through ShareHelper (Closed)
Patch Set: Fixing nits Created 3 years, 10 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: chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java
new file mode 100644
index 0000000000000000000000000000000000000000..aabb6e6d465617a4f5c723dd595caf31a22a08d1
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.share;
+
+import android.app.Activity;
+import android.content.Intent;
+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.tab.Tab;
+import org.chromium.chrome.browser.util.IntentUtils;
+
+import java.lang.ref.WeakReference;
+import java.util.List;
+
+/**
+ * {@code ShareActivity} is the base class for share options, which
+ * are activities that are shown in the share chooser. Activities subclassing
+ * ShareActivity override featureIsEnabled, and handleShareAction.
+ */
+public abstract class ShareActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ try {
+ Intent intent = getIntent();
+ if (intent == null) return;
+ if (!Intent.ACTION_SEND.equals(intent.getAction())) return;
+ if (!IntentUtils.safeHasExtra(intent, ShareHelper.EXTRA_TASK_ID)) return;
+ handleShareAction();
+ } finally {
+ finish();
+ }
+ }
+
+ /**
+ * Returns the ChromeActivity that called the share intent picker.
+ */
+ protected ChromeActivity getTriggeringActivity() {
+ 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;
+ }
+
+ /**
+ * Override to handle the desired action of the activity.
+ */
+ protected abstract void handleShareAction();
+
+ /**
+ * Override this method to describe the conditions this share option should be present
+ * in the share chooser.
+ * @param currentTab The current Tab that chrome has open. This gives access to
+ * critical information such as MIME type or Nativity.
+ * @return {@code true} if feature should be enabled.
+ */
+ public abstract boolean featureIsEnabled(Tab currentTab);
+}

Powered by Google App Engine
This is Rietveld 408576698