expo-web-browser 10.2.1 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/android/build.gradle +3 -2
- package/android/src/main/java/expo/modules/webbrowser/CustomTabsActivitiesHelper.kt +123 -0
- package/android/src/main/java/expo/modules/webbrowser/CustomTabsConnectionHelper.kt +97 -0
- package/android/src/main/java/expo/modules/webbrowser/DeferredClientActionsQueue.kt +45 -0
- package/android/src/main/java/expo/modules/webbrowser/WebBrowserExceptions.kt +13 -0
- package/android/src/main/java/expo/modules/webbrowser/WebBrowserModule.kt +164 -0
- package/android/src/main/java/expo/modules/webbrowser/WebBrowserOptions.kt +15 -0
- package/build/ExpoWebBrowser.web.js +5 -5
- package/build/ExpoWebBrowser.web.js.map +1 -1
- package/build/WebBrowser.d.ts +6 -6
- package/build/WebBrowser.d.ts.map +1 -1
- package/build/WebBrowser.js +25 -16
- package/build/WebBrowser.js.map +1 -1
- package/build/WebBrowser.types.d.ts +3 -3
- package/build/WebBrowser.types.js.map +1 -1
- package/expo-module.config.json +3 -0
- package/ios/ExpoWebBrowser.podspec +1 -1
- package/ios/WebAuthSession.swift +2 -2
- package/ios/WebBrowserModule.swift +9 -9
- package/package.json +3 -3
- package/src/ExpoWebBrowser.web.ts +6 -6
- package/src/WebBrowser.ts +38 -19
- package/src/WebBrowser.types.ts +3 -3
- package/tsconfig.json +1 -1
- package/android/src/main/java/expo/modules/webbrowser/CustomTabsActivitiesHelper.java +0 -33
- package/android/src/main/java/expo/modules/webbrowser/CustomTabsConnectionHelper.java +0 -13
- package/android/src/main/java/expo/modules/webbrowser/DeferredClientActionsQueue.java +0 -50
- package/android/src/main/java/expo/modules/webbrowser/InternalCustomTabsActivitiesHelper.java +0 -127
- package/android/src/main/java/expo/modules/webbrowser/InternalCustomTabsConnectionHelper.java +0 -126
- package/android/src/main/java/expo/modules/webbrowser/WebBrowserModule.java +0 -218
- package/android/src/main/java/expo/modules/webbrowser/WebBrowserPackage.java +0 -27
- package/android/src/main/java/expo/modules/webbrowser/error/NoPreferredPackageFound.java +0 -15
- package/android/src/main/java/expo/modules/webbrowser/error/PackageManagerNotFoundException.java +0 -10
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
package expo.modules.webbrowser;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.content.Intent;
|
|
5
|
-
import android.graphics.Color;
|
|
6
|
-
import android.net.Uri;
|
|
7
|
-
import android.os.Bundle;
|
|
8
|
-
import android.text.TextUtils;
|
|
9
|
-
|
|
10
|
-
import expo.modules.core.ExportedModule;
|
|
11
|
-
import expo.modules.core.ModuleRegistry;
|
|
12
|
-
import expo.modules.core.Promise;
|
|
13
|
-
import expo.modules.core.arguments.ReadableArguments;
|
|
14
|
-
import expo.modules.core.errors.CurrentActivityNotFoundException;
|
|
15
|
-
import expo.modules.core.interfaces.ExpoMethod;
|
|
16
|
-
|
|
17
|
-
import java.util.ArrayList;
|
|
18
|
-
|
|
19
|
-
import androidx.annotation.Nullable;
|
|
20
|
-
import androidx.browser.customtabs.CustomTabsIntent;
|
|
21
|
-
import expo.modules.webbrowser.error.NoPreferredPackageFound;
|
|
22
|
-
import expo.modules.webbrowser.error.PackageManagerNotFoundException;
|
|
23
|
-
|
|
24
|
-
public class WebBrowserModule extends ExportedModule {
|
|
25
|
-
|
|
26
|
-
private final static String BROWSER_PACKAGE_KEY = "browserPackage";
|
|
27
|
-
private final static String SERVICE_PACKAGE_KEY = "servicePackage";
|
|
28
|
-
private final static String BROWSER_PACKAGES_KEY = "browserPackages";
|
|
29
|
-
private final static String SERVICE_PACKAGES_KEY = "servicePackages";
|
|
30
|
-
private final static String PREFERRED_BROWSER_PACKAGE = "preferredBrowserPackage";
|
|
31
|
-
private final static String DEFAULT_BROWSER_PACKAGE = "defaultBrowserPackage";
|
|
32
|
-
private final static String SHOW_IN_RECENTS = "showInRecents";
|
|
33
|
-
private final static String CREATE_TASK = "createTask";
|
|
34
|
-
private final static String DEFAULT_SHARE_MENU_ITEM = "enableDefaultShareMenuItem";
|
|
35
|
-
private final static String TOOLBAR_COLOR_KEY = "toolbarColor";
|
|
36
|
-
private final static String SECONDARY_TOOLBAR_COLOR_KEY = "secondaryToolbarColor";
|
|
37
|
-
|
|
38
|
-
private final static String ERROR_CODE = "EXWebBrowser";
|
|
39
|
-
private static final String TAG = "ExpoWebBrowser";
|
|
40
|
-
private static final String SHOW_TITLE_KEY = "showTitle";
|
|
41
|
-
private static final String ENABLE_BAR_COLLAPSING_KEY = "enableBarCollapsing";
|
|
42
|
-
|
|
43
|
-
private final static String NO_PREFERRED_PACKAGE_MSG = "Cannot determine preferred package without satisfying it.";
|
|
44
|
-
|
|
45
|
-
private CustomTabsActivitiesHelper mCustomTabsResolver;
|
|
46
|
-
private CustomTabsConnectionHelper mConnectionHelper;
|
|
47
|
-
|
|
48
|
-
public WebBrowserModule(Context context) {
|
|
49
|
-
super(context);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Override
|
|
53
|
-
public String getName() {
|
|
54
|
-
return TAG;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@Override
|
|
58
|
-
public void onCreate(ModuleRegistry moduleRegistry) {
|
|
59
|
-
mCustomTabsResolver = moduleRegistry.getModule(CustomTabsActivitiesHelper.class);
|
|
60
|
-
mConnectionHelper = moduleRegistry.getModule(CustomTabsConnectionHelper.class);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@ExpoMethod
|
|
64
|
-
public void warmUpAsync(@Nullable String packageName, final Promise promise) {
|
|
65
|
-
try {
|
|
66
|
-
packageName = givenOrPreferredPackageName(packageName);
|
|
67
|
-
mConnectionHelper.warmUp(packageName);
|
|
68
|
-
Bundle result = new Bundle();
|
|
69
|
-
result.putString(SERVICE_PACKAGE_KEY, packageName);
|
|
70
|
-
promise.resolve(result);
|
|
71
|
-
} catch (NoPreferredPackageFound ex) {
|
|
72
|
-
promise.reject(ex);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@ExpoMethod
|
|
77
|
-
public void coolDownAsync(@Nullable String packageName, final Promise promise) {
|
|
78
|
-
try {
|
|
79
|
-
packageName = givenOrPreferredPackageName(packageName);
|
|
80
|
-
if (mConnectionHelper.coolDown(packageName)) {
|
|
81
|
-
Bundle result = new Bundle();
|
|
82
|
-
result.putString(SERVICE_PACKAGE_KEY, packageName);
|
|
83
|
-
promise.resolve(result);
|
|
84
|
-
} else {
|
|
85
|
-
promise.resolve(new Bundle());
|
|
86
|
-
}
|
|
87
|
-
} catch (NoPreferredPackageFound ex) {
|
|
88
|
-
promise.reject(ex);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@ExpoMethod
|
|
93
|
-
public void mayInitWithUrlAsync(@Nullable final String url, String packageName, final Promise promise) {
|
|
94
|
-
try {
|
|
95
|
-
packageName = givenOrPreferredPackageName(packageName);
|
|
96
|
-
mConnectionHelper.mayInitWithUrl(packageName, Uri.parse(url));
|
|
97
|
-
Bundle result = new Bundle();
|
|
98
|
-
result.putString(SERVICE_PACKAGE_KEY, packageName);
|
|
99
|
-
promise.resolve(result);
|
|
100
|
-
} catch (NoPreferredPackageFound ex) {
|
|
101
|
-
promise.reject(ex);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
@ExpoMethod
|
|
106
|
-
public void getCustomTabsSupportingBrowsersAsync(final Promise promise) {
|
|
107
|
-
try {
|
|
108
|
-
ArrayList<String> activities = mCustomTabsResolver.getCustomTabsResolvingActivities();
|
|
109
|
-
ArrayList<String> services = mCustomTabsResolver.getCustomTabsResolvingServices();
|
|
110
|
-
String preferredPackage = mCustomTabsResolver.getPreferredCustomTabsResolvingActivity(activities);
|
|
111
|
-
String defaultPackage = mCustomTabsResolver.getDefaultCustomTabsResolvingActivity();
|
|
112
|
-
|
|
113
|
-
String defaultCustomTabsPackage = null;
|
|
114
|
-
if (activities.contains(defaultPackage)) { // It might happen, that default activity does not support Chrome Tabs. Then it will be ResolvingActivity and we don't want to return it as a result.
|
|
115
|
-
defaultCustomTabsPackage = defaultPackage;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
Bundle result = new Bundle();
|
|
119
|
-
result.putStringArrayList(BROWSER_PACKAGES_KEY, activities);
|
|
120
|
-
result.putStringArrayList(SERVICE_PACKAGES_KEY, services);
|
|
121
|
-
result.putString(PREFERRED_BROWSER_PACKAGE, preferredPackage);
|
|
122
|
-
result.putString(DEFAULT_BROWSER_PACKAGE, defaultCustomTabsPackage);
|
|
123
|
-
|
|
124
|
-
promise.resolve(result);
|
|
125
|
-
} catch (CurrentActivityNotFoundException | PackageManagerNotFoundException ex) {
|
|
126
|
-
promise.reject(ex);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @param url Url to be opened by WebBrowser
|
|
132
|
-
* @param arguments Required arguments are:
|
|
133
|
-
* toolbarColor: String;
|
|
134
|
-
* browserPackage: String;
|
|
135
|
-
* enableBarCollapsing: Boolean;
|
|
136
|
-
* showTitle: Boolean;
|
|
137
|
-
* enableDefaultShareMenuItem: Boolean;
|
|
138
|
-
* showInRecents: Boolean;
|
|
139
|
-
* @param promise
|
|
140
|
-
*/
|
|
141
|
-
@ExpoMethod
|
|
142
|
-
public void openBrowserAsync(final String url, ReadableArguments arguments, final Promise promise) {
|
|
143
|
-
|
|
144
|
-
Intent intent = createCustomTabsIntent(arguments);
|
|
145
|
-
intent.setData(Uri.parse(url));
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
if (mCustomTabsResolver.canResolveIntent(intent)) {
|
|
149
|
-
mCustomTabsResolver.startCustomTabs(intent);
|
|
150
|
-
Bundle result = new Bundle();
|
|
151
|
-
result.putString("type", "opened");
|
|
152
|
-
promise.resolve(result);
|
|
153
|
-
} else {
|
|
154
|
-
promise.reject(ERROR_CODE, "No matching activity!");
|
|
155
|
-
}
|
|
156
|
-
} catch (CurrentActivityNotFoundException | PackageManagerNotFoundException ex) {
|
|
157
|
-
promise.reject(ex);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private Intent createCustomTabsIntent(ReadableArguments arguments) {
|
|
163
|
-
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
|
164
|
-
String color = arguments.getString(TOOLBAR_COLOR_KEY);
|
|
165
|
-
String secondaryColor = arguments.getString(SECONDARY_TOOLBAR_COLOR_KEY);
|
|
166
|
-
String packageName = arguments.getString(BROWSER_PACKAGE_KEY);
|
|
167
|
-
try {
|
|
168
|
-
if (!TextUtils.isEmpty(color)) {
|
|
169
|
-
int intColor = Color.parseColor(color);
|
|
170
|
-
builder.setToolbarColor(intColor);
|
|
171
|
-
}
|
|
172
|
-
if (!TextUtils.isEmpty(secondaryColor)) {
|
|
173
|
-
int intSecondaryColor = Color.parseColor(secondaryColor);
|
|
174
|
-
builder.setSecondaryToolbarColor(intSecondaryColor);
|
|
175
|
-
}
|
|
176
|
-
} catch (IllegalArgumentException ignored) {
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
builder.setShowTitle(arguments.getBoolean(SHOW_TITLE_KEY, false));
|
|
180
|
-
|
|
181
|
-
if (arguments.containsKey(DEFAULT_SHARE_MENU_ITEM) && arguments.getBoolean(DEFAULT_SHARE_MENU_ITEM)) {
|
|
182
|
-
builder.addDefaultShareMenuItem();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
Intent intent = builder.build().intent;
|
|
186
|
-
|
|
187
|
-
// We cannot use builder's method enableUrlBarHiding, because there is no corresponding disable method and some browsers enables it by default.
|
|
188
|
-
intent.putExtra(CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, arguments.getBoolean(ENABLE_BAR_COLLAPSING_KEY, false));
|
|
189
|
-
if (!TextUtils.isEmpty(packageName)) {
|
|
190
|
-
intent.setPackage(packageName);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (arguments.getBoolean(CREATE_TASK, true)) {
|
|
194
|
-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
195
|
-
if (!arguments.getBoolean(SHOW_IN_RECENTS, false)) {
|
|
196
|
-
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
|
197
|
-
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return intent;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
private String givenOrPreferredPackageName(@Nullable String packageName) throws NoPreferredPackageFound {
|
|
205
|
-
try {
|
|
206
|
-
if (TextUtils.isEmpty(packageName)) {
|
|
207
|
-
packageName = mCustomTabsResolver.getPreferredCustomTabsResolvingActivity(null);
|
|
208
|
-
}
|
|
209
|
-
} catch (CurrentActivityNotFoundException | PackageManagerNotFoundException ex) {
|
|
210
|
-
throw new NoPreferredPackageFound(NO_PREFERRED_PACKAGE_MSG);
|
|
211
|
-
}
|
|
212
|
-
if (TextUtils.isEmpty(packageName)) {
|
|
213
|
-
throw new NoPreferredPackageFound(NO_PREFERRED_PACKAGE_MSG);
|
|
214
|
-
}
|
|
215
|
-
return packageName;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
package expo.modules.webbrowser;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
|
|
5
|
-
import expo.modules.core.BasePackage;
|
|
6
|
-
import expo.modules.core.ExportedModule;
|
|
7
|
-
import expo.modules.core.interfaces.InternalModule;
|
|
8
|
-
|
|
9
|
-
import java.util.ArrayList;
|
|
10
|
-
import java.util.Collections;
|
|
11
|
-
import java.util.List;
|
|
12
|
-
|
|
13
|
-
public class WebBrowserPackage extends BasePackage {
|
|
14
|
-
|
|
15
|
-
@Override
|
|
16
|
-
public List<InternalModule> createInternalModules(Context context) {
|
|
17
|
-
List<InternalModule> list = new ArrayList<>();
|
|
18
|
-
list.add(new InternalCustomTabsActivitiesHelper());
|
|
19
|
-
list.add(new InternalCustomTabsConnectionHelper(context));
|
|
20
|
-
return list;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Override
|
|
24
|
-
public List<ExportedModule> createExportedModules(Context context) {
|
|
25
|
-
return Collections.singletonList(new WebBrowserModule(context));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
package expo.modules.webbrowser.error;
|
|
2
|
-
|
|
3
|
-
import expo.modules.core.errors.CodedException;
|
|
4
|
-
|
|
5
|
-
public class NoPreferredPackageFound extends CodedException {
|
|
6
|
-
|
|
7
|
-
public NoPreferredPackageFound(String message) {
|
|
8
|
-
super(message);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@Override
|
|
12
|
-
public String getCode() {
|
|
13
|
-
return "PREFERRED_PACKAGE_NOT_FOUND";
|
|
14
|
-
}
|
|
15
|
-
}
|