OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.webshare; | 5 package org.chromium.chrome.browser.webshare; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
9 import android.support.annotation.Nullable; | 9 import android.support.annotation.Nullable; |
10 | 10 |
11 import org.chromium.chrome.browser.share.ShareHelper; | 11 import org.chromium.chrome.browser.share.ShareHelper; |
12 import org.chromium.content.browser.ContentViewCore; | 12 import org.chromium.content.browser.ContentViewCore; |
13 import org.chromium.content_public.browser.WebContents; | 13 import org.chromium.content_public.browser.WebContents; |
14 import org.chromium.mojo.system.MojoException; | 14 import org.chromium.mojo.system.MojoException; |
15 import org.chromium.mojom.url.mojom.Url; | |
16 import org.chromium.mojom.webshare.ShareService; | 15 import org.chromium.mojom.webshare.ShareService; |
17 import org.chromium.ui.base.WindowAndroid; | 16 import org.chromium.ui.base.WindowAndroid; |
18 | 17 |
19 /** | 18 /** |
20 * Android implementation of the ShareService service defined in | 19 * Android implementation of the ShareService service defined in |
21 * third_party/WebKit/public/platform/modules/webshare/webshare.mojom. | 20 * third_party/WebKit/public/platform/modules/webshare/webshare.mojom. |
22 */ | 21 */ |
23 public class ShareServiceImpl implements ShareService { | 22 public class ShareServiceImpl implements ShareService { |
24 private final Activity mActivity; | 23 private final Activity mActivity; |
25 | 24 |
26 public ShareServiceImpl(@Nullable WebContents webContents) { | 25 public ShareServiceImpl(@Nullable WebContents webContents) { |
27 mActivity = activityFromWebContents(webContents); | 26 mActivity = activityFromWebContents(webContents); |
28 } | 27 } |
29 | 28 |
30 @Override | 29 @Override |
31 public void close() {} | 30 public void close() {} |
32 | 31 |
33 @Override | 32 @Override |
34 public void onConnectionError(MojoException e) {} | 33 public void onConnectionError(MojoException e) {} |
35 | 34 |
36 @Override | 35 @Override |
37 public void share(String title, String text, Url url, final ShareResponse ca
llback) { | 36 public void share(String title, String text, final ShareResponse callback) { |
38 if (mActivity == null) { | 37 if (mActivity == null) { |
39 callback.call("Share failed"); | 38 callback.call("Share failed"); |
40 return; | 39 return; |
41 } | 40 } |
42 | 41 |
43 ShareHelper.TargetChosenCallback innerCallback = new ShareHelper.TargetC
hosenCallback() { | 42 ShareHelper.TargetChosenCallback innerCallback = new ShareHelper.TargetC
hosenCallback() { |
44 public void onTargetChosen(ComponentName chosenComponent) { | 43 public void onTargetChosen(ComponentName chosenComponent) { |
45 callback.call(null); | 44 callback.call(null); |
46 } | 45 } |
47 }; | 46 }; |
48 | 47 |
49 ShareHelper.share(false, false, mActivity, title, text, url.url, null, n
ull, innerCallback); | 48 ShareHelper.share(false, false, mActivity, title, text, null, null, null
, innerCallback); |
50 } | 49 } |
51 | 50 |
52 @Nullable | 51 @Nullable |
53 private static Activity activityFromWebContents(@Nullable WebContents webCon
tents) { | 52 private static Activity activityFromWebContents(@Nullable WebContents webCon
tents) { |
54 if (webContents == null) return null; | 53 if (webContents == null) return null; |
55 | 54 |
56 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webCon
tents); | 55 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(webCon
tents); |
57 if (contentViewCore == null) return null; | 56 if (contentViewCore == null) return null; |
58 | 57 |
59 WindowAndroid window = contentViewCore.getWindowAndroid(); | 58 WindowAndroid window = contentViewCore.getWindowAndroid(); |
60 if (window == null) return null; | 59 if (window == null) return null; |
61 | 60 |
62 return window.getActivity().get(); | 61 return window.getActivity().get(); |
63 } | 62 } |
64 } | 63 } |
OLD | NEW |