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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java

Issue 1814133002: Added experimental Share API on Android behind flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ballista-share-requester-mojo-blink
Patch Set: Fix comment format. Created 4 years, 5 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.webshare;
6
7 import android.content.Context;
8 import android.content.Intent;
9
10 import org.chromium.chrome.R;
11 import org.chromium.content.browser.ContentViewCore;
12 import org.chromium.content_public.browser.WebContents;
13 import org.chromium.mojo.system.MojoException;
14 import org.chromium.mojom.webshare.ShareService;
15 import org.chromium.ui.base.WindowAndroid;
16
17 /**
18 * Android implementation of the ShareService service defined in
19 * third_party/WebKit/public/platform/modules/webshare/webshare.mojom.
20 */
21 public class ShareServiceImpl implements ShareService {
22 private static final String TAG = "ShareServiceImpl";
23
24 private final WindowAndroid mWindow;
25 private final Context mContext;
26
27 public ShareServiceImpl(WebContents webContents) {
28 // 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.
29 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.
30 mWindow = null;
31 mContext = null;
32 return;
33 }
34
35 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webCon tents);
36 if (contentViewCore == null) {
37 mWindow = null;
38 mContext = null;
39 return;
40 }
41
42 mWindow = contentViewCore.getWindowAndroid();
43 if (mWindow == null) {
44 mContext = null;
45 return;
46 }
47
48 mContext = mWindow.getActivity().get();
49 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.
50 }
51
52 @Override
53 public void close() {}
54
55 @Override
56 public void onConnectionError(MojoException e) {}
57
58 @Override
59 public void share(String title, String text, ShareResponse callback) {
60 String chooserTitle = mContext.getString(R.string.share_link_chooser_tit le);
61 Intent send = new Intent(Intent.ACTION_SEND);
62 send.setType("text/plain");
63 send.putExtra(Intent.EXTRA_SUBJECT, text);
64 send.putExtra(Intent.EXTRA_TEXT, text);
65
66 Intent chooser = Intent.createChooser(send, chooserTitle);
67 if (!mWindow.showIntent(chooser, null, null)) {
68 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
69 return;
70 }
71
72 // Success.
73 // TODO(mgiuca): Wait until the user has made a choice, and report failu re if they cancel
74 // the picker or something else goes wrong.
75 callback.call(null);
76 }
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698