Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider that browsers might not be supported by devices #2070

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions flutter_inappwebview/example/integration_test/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class MyChromeSafariBrowser extends ChromeSafariBrowser {
relationshipValidationResult.complete(result);
}

@override
void onBrowserNotSupported() {}

@override
void onClosed() {
closed.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class MyChromeSafariBrowser extends ChromeSafariBrowser {
void onClosed() {
print("ChromeSafari browser closed");
}

@override
void onBrowserNotSupported() {
print("ChromeSafari is not supported");
}
}

class ChromeSafariBrowserExampleScreen extends StatefulWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,7 @@ class ChromeSafariBrowser implements PlatformChromeSafariBrowserEvents {

@override
void onWillOpenInBrowser() {}

@override
void onBrowserNotSupported() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@ protected void onCreate(Bundle savedInstanceState) {
customTabActivityHelper.setConnectionCallback(new CustomTabActivityHelper.ConnectionCallback() {
@Override
public void onCustomTabsConnected() {
customTabsConnected();
if (channelDelegate != null) {
channelDelegate.onServiceConnected();
try {
customTabsConnected();
if (channelDelegate != null) {
channelDelegate.onServiceConnected();
}
} catch (java.lang.Exception e) {
if (channelDelegate != null) {
channelDelegate.onBrowserNotSupported();
}
Log.d(LOG_TAG, "Custom Tabs not supported", e);
}
}

Expand Down Expand Up @@ -181,15 +188,15 @@ public void onRelationshipValidationResult(@CustomTabsService.Relation int relat
public void launchUrl(@NonNull String url,
@Nullable Map<String, String> headers,
@Nullable String referrer,
@Nullable List<String> otherLikelyURLs) {
@Nullable List<String> otherLikelyURLs) throws ClassNotFoundException {
launchUrlWithSession(customTabsSession, url, headers, referrer, otherLikelyURLs);
}

public void launchUrlWithSession(@Nullable CustomTabsSession session,
@NonNull String url,
@Nullable Map<String, String> headers,
@Nullable String referrer,
@Nullable List<String> otherLikelyURLs) {
@Nullable List<String> otherLikelyURLs) throws ClassNotFoundException {
mayLaunchUrl(url, otherLikelyURLs);
builder = new CustomTabsIntent.Builder(session);
prepareCustomTabs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ public void onSessionEnded(boolean didUserInteract) {
channel.invokeMethod("onSessionEnded", obj);
}

public void onBrowserNotSupported() {
MethodChannel channel = getChannel();
if (channel == null) return;
Map<String, Object> obj = new HashMap<>();
channel.invokeMethod("onBrowserNotSupported", obj);
}

@Override
public void dispose() {
super.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public void onMethodCall(final MethodCall call, final MethodChannel.Result resul
HashMap<String, Object> actionButton = (HashMap<String, Object>) call.argument("actionButton");
HashMap<String, Object> secondaryToolbar = (HashMap<String, Object>) call.argument("secondaryToolbar");
List<HashMap<String, Object>> menuItemList = (List<HashMap<String, Object>>) call.argument("menuItemList");
open(plugin.activity, viewId, url, headers, referrer, otherLikelyURLs, settings, actionButton, secondaryToolbar, menuItemList, result);
try {
open(plugin.activity, viewId, url, headers, referrer, otherLikelyURLs, settings, actionButton, secondaryToolbar, menuItemList, result);
} catch (ClassNotFoundException e) {
result.error(LOG_TAG, e.getMessage(), null);
}
} else {
result.success(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void openCustomTab(Activity activity,
Uri uri,
@Nullable Map<String, String> headers,
@Nullable Uri referrer,
int requestCode) {
int requestCode) throws ClassNotFoundException {
intent.setData(uri);
if (headers != null) {
Bundle bundleHeaders = new Bundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import io.flutter.plugin.common.MethodChannel;

Expand Down Expand Up @@ -145,7 +146,11 @@ protected void onCreate(Bundle savedInstanceState) {

actionBar = getSupportActionBar();

prepareView();
try {
prepareView();
} catch (ClassNotFoundException e) {
Log.d(LOG_TAG, Objects.requireNonNull(e.getMessage()));
}

if (windowId != -1) {
if (webView.plugin != null && webView.plugin.inAppWebViewManager != null) {
Expand Down Expand Up @@ -187,7 +192,7 @@ else if (initialUrlRequest != null) {
}
}

private void prepareView() {
private void prepareView() throws ClassNotFoundException {

if (webView != null) {
webView.prepare();
Expand Down Expand Up @@ -421,7 +426,7 @@ public void hide() {
}
}

public void show() {
public void show() throws ClassNotFoundException {
isHidden = false;
Intent openActivity = new Intent(this, InAppBrowserActivity.class);
openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Expand Down Expand Up @@ -451,7 +456,7 @@ public void closeButtonClicked(MenuItem item) {
close(null);
}

public void setSettings(InAppBrowserSettings newSettings, HashMap<String, Object> newSettingsMap) {
public void setSettings(InAppBrowserSettings newSettings, HashMap<String, Object> newSettingsMap) throws ClassNotFoundException {

InAppWebViewSettings newInAppWebViewSettings = new InAppWebViewSettings();
newInAppWebViewSettings.parse(newSettingsMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ public void onReceiveValue(String value) {
InAppBrowserSettings inAppBrowserSettings = new InAppBrowserSettings();
HashMap<String, Object> inAppBrowserSettingsMap = (HashMap<String, Object>) call.argument("settings");
inAppBrowserSettings.parse(inAppBrowserSettingsMap);
inAppBrowserActivity.setSettings(inAppBrowserSettings, inAppBrowserSettingsMap);
try {
inAppBrowserActivity.setSettings(inAppBrowserSettings, inAppBrowserSettingsMap);
} catch (ClassNotFoundException e) {
result.error(LOG_TAG, e.getMessage(), null);
}
} else if (webView != null) {
InAppWebViewSettings inAppWebViewSettings = new InAppWebViewSettings();
HashMap<String, Object> inAppWebViewSettingsMap = (HashMap<String, Object>) call.argument("settings");
Expand Down Expand Up @@ -247,7 +251,11 @@ public void onReceiveValue(String value) {
case show:
if (webView != null && webView.getInAppBrowserDelegate() instanceof InAppBrowserActivity) {
InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.getInAppBrowserDelegate();
inAppBrowserActivity.show();
try {
inAppBrowserActivity.show();
} catch (ClassNotFoundException e) {
result.error(LOG_TAG, e.getMessage(), null);
}
result.success(true);
} else {
result.notImplemented();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class AndroidChromeSafariBrowser extends PlatformChromeSafariBrowser
final bool didUserInteract = call.arguments["didUserInteract"];
eventHandler?.onSessionEnded(didUserInteract);
break;
case "onBrowserNotSupported":
eventHandler?.onBrowserNotSupported();
break;
default:
throw UnimplementedError("Unimplemented ${call.method} method");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ abstract class PlatformChromeSafariBrowserEvents {
///{@endtemplate}
void onGreatestScrollPercentageIncreased(int scrollPercentage) {}

///{@template flutter_inappwebview_platform_interface.PlatformChromeSafariBrowser.onBrowserNotSupported}
/// Called when the browser is not supported.
/// This can happen if a user forces a certain browser package to be used but the browser is not installed on the user's system.
void onBrowserNotSupported() {
throw UnimplementedError(
'onBrowserNotSupported is not implemented on the current platform');
}

///{@template flutter_inappwebview_platform_interface.PlatformChromeSafariBrowser.onSessionEnded}
///Called when a `CustomTabsSession` is ending or when no further Engagement Signals
///callbacks are expected to report whether any user action has occurred during the session.
Expand Down