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

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: Respond to review. Created 4 years, 4 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";
Sam McNally 2016/07/28 07:16:04 Remove.
Matt Giuca 2016/07/28 07:40:42 Done.
23
24 private final WindowAndroid mWindow;
25 private final Context mContext;
26
27 public ShareServiceImpl(WebContents webContents) {
28 mWindow = windowFromWebContents(webContents);
29 mContext = contextFromWindow(mWindow);
30 }
31
32 // |webContents| can be null. Can return null.
33 static WindowAndroid windowFromWebContents(WebContents webContents) {
Sam McNally 2016/07/28 07:16:04 private
Matt Giuca 2016/07/28 07:40:42 Done.
34 if (webContents == null) return null;
35
36 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webCon tents);
37 if (contentViewCore == null) return null;
38
39 return contentViewCore.getWindowAndroid();
40 }
41
42 // |window| can be null. Can return null.
43 static Context contextFromWindow(WindowAndroid window) {
Sam McNally 2016/07/28 07:16:04 private
Matt Giuca 2016/07/28 07:40:42 Done.
44 if (window == null) return null;
45
46 return window.getActivity().get();
47 }
48
49 @Override
50 public void close() {}
51
52 @Override
53 public void onConnectionError(MojoException e) {}
54
55 @Override
56 public void share(String title, String text, ShareResponse callback) {
57 String chooserTitle = mContext.getString(R.string.share_link_chooser_tit le);
58 Intent send = new Intent(Intent.ACTION_SEND);
59 send.setType("text/plain");
60 send.putExtra(Intent.EXTRA_SUBJECT, text);
61 send.putExtra(Intent.EXTRA_TEXT, text);
62
63 Intent chooser = Intent.createChooser(send, chooserTitle);
64 if (!mWindow.showIntent(chooser, null, null)) {
65 callback.call("Share failed");
66 return;
67 }
68
69 // Success.
70 // TODO(mgiuca): Wait until the user has made a choice, and report failu re if they cancel
71 // the picker or something else goes wrong.
72 callback.call(null);
73 }
74 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/mojo/ChromeServiceRegistrar.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698