Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..20af1ef7b77dfbc5a1044bdd7e123e875348b1b3 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.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.webshare; |
| + |
| +import android.content.Context; |
| +import android.content.Intent; |
| + |
| +import org.chromium.chrome.R; |
| +import org.chromium.content.browser.ContentViewCore; |
| +import org.chromium.content_public.browser.WebContents; |
| +import org.chromium.mojo.system.MojoException; |
| +import org.chromium.mojom.webshare.ShareService; |
| +import org.chromium.ui.base.WindowAndroid; |
| + |
| +/** |
| + * Android implementation of the ShareService service defined in |
| + * third_party/WebKit/public/platform/modules/webshare/webshare.mojom. |
| + */ |
| +public class ShareServiceImpl implements ShareService { |
| + private static final String TAG = "ShareServiceImpl"; |
| + |
| + private final WindowAndroid mWindow; |
| + private final Context mContext; |
| + |
| + public ShareServiceImpl(WebContents webContents) { |
| + // Get the Activity for the web contents, which will be used to send the intent. |
|
Sam McNally
2016/07/26 08:21:51
Is this still accurate?
Matt Giuca
2016/07/28 05:58:32
Done.
|
| + if (webContents == null) { |
|
Sam McNally
2016/07/26 08:21:51
Please add helper functions to map from WebContent
Matt Giuca
2016/07/28 05:58:32
Done.
|
| + mWindow = null; |
| + mContext = null; |
| + return; |
| + } |
| + |
| + ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webContents); |
| + if (contentViewCore == null) { |
| + mWindow = null; |
| + mContext = null; |
| + return; |
| + } |
| + |
| + mWindow = contentViewCore.getWindowAndroid(); |
| + if (mWindow == null) { |
| + mContext = null; |
| + return; |
| + } |
| + |
| + mContext = mWindow.getActivity().get(); |
| + if (mContext == null) return; |
|
Sam McNally
2016/07/26 08:21:51
Is this really necessary?
Matt Giuca
2016/07/28 05:58:32
No, it was a joke lol.
|
| + } |
| + |
| + @Override |
| + public void close() {} |
| + |
| + @Override |
| + public void onConnectionError(MojoException e) {} |
| + |
| + @Override |
| + public void share(String title, String text, ShareResponse callback) { |
| + 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, text); |
| + send.putExtra(Intent.EXTRA_TEXT, text); |
| + |
| + Intent chooser = Intent.createChooser(send, chooserTitle); |
| + if (!mWindow.showIntent(chooser, null, null)) { |
| + callback.call("Could not start intent"); |
|
Sam McNally
2016/07/26 08:21:52
I don't think we should expose platform-specific e
Matt Giuca
2016/07/28 05:58:32
I think we should just return an enum of errors if
|
| + 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); |
| + } |
| +} |