| Index: chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java
|
| index 73fc0a48de73ae4153e8c20d997528f35c8c4807..f4dc23871fad8b038d4cdc37cc29e72d024a0c7d 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java
|
| @@ -4,11 +4,11 @@
|
|
|
| package org.chromium.chrome.browser.webshare;
|
|
|
| -import android.content.Context;
|
| -import android.content.Intent;
|
| +import android.app.Activity;
|
| +import android.content.ComponentName;
|
| import android.support.annotation.Nullable;
|
|
|
| -import org.chromium.chrome.R;
|
| +import org.chromium.chrome.browser.share.ShareHelper;
|
| import org.chromium.content.browser.ContentViewCore;
|
| import org.chromium.content_public.browser.WebContents;
|
| import org.chromium.mojo.system.MojoException;
|
| @@ -20,12 +20,10 @@ import org.chromium.ui.base.WindowAndroid;
|
| * third_party/WebKit/public/platform/modules/webshare/webshare.mojom.
|
| */
|
| public class ShareServiceImpl implements ShareService {
|
| - private final WindowAndroid mWindow;
|
| - private final Context mContext;
|
| + private final Activity mActivity;
|
|
|
| public ShareServiceImpl(@Nullable WebContents webContents) {
|
| - mWindow = windowFromWebContents(webContents);
|
| - mContext = contextFromWindow(mWindow);
|
| + mActivity = activityFromWebContents(webContents);
|
| }
|
|
|
| @Override
|
| @@ -35,42 +33,29 @@ public class ShareServiceImpl implements ShareService {
|
| public void onConnectionError(MojoException e) {}
|
|
|
| @Override
|
| - public void share(String title, String text, ShareResponse callback) {
|
| - if (mContext == null) {
|
| + public void share(String title, String text, final ShareResponse callback) {
|
| + if (mActivity == null) {
|
| callback.call("Share failed");
|
| return;
|
| }
|
|
|
| - String chooserTitle = mContext.getString(R.string.share_link_chooser_title);
|
| - Intent send = new Intent(Intent.ACTION_SEND);
|
| - send.setType("text/plain");
|
| - send.putExtra(Intent.EXTRA_SUBJECT, title);
|
| - send.putExtra(Intent.EXTRA_TEXT, text);
|
| + ShareHelper.TargetChosenCallback innerCallback = new ShareHelper.TargetChosenCallback() {
|
| + public void onTargetChosen(ComponentName chosenComponent) {
|
| + callback.call(null);
|
| + }
|
| + };
|
|
|
| - Intent chooser = Intent.createChooser(send, chooserTitle);
|
| - if (!mWindow.showIntent(chooser, null, null)) {
|
| - callback.call("Share failed");
|
| - return;
|
| - }
|
| -
|
| - // Success.
|
| - // TODO(mgiuca): Wait until the user has made a choice, and report failure if they cancel
|
| - // the picker or something else goes wrong.
|
| - callback.call(null);
|
| + ShareHelper.share(false, false, mActivity, title, text, null, null, innerCallback);
|
| }
|
|
|
| @Nullable
|
| - private static WindowAndroid windowFromWebContents(@Nullable WebContents webContents) {
|
| + private static Activity activityFromWebContents(@Nullable WebContents webContents) {
|
| if (webContents == null) return null;
|
|
|
| ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents);
|
| if (contentViewCore == null) return null;
|
|
|
| - return contentViewCore.getWindowAndroid();
|
| - }
|
| -
|
| - @Nullable
|
| - private static Context contextFromWindow(@Nullable WindowAndroid window) {
|
| + WindowAndroid window = contentViewCore.getWindowAndroid();
|
| if (window == null) return null;
|
|
|
| return window.getActivity().get();
|
|
|