Skip to content

[url_launcher] Add InAppBrowserConfiguration parameter in implementations #5759

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

Merged
merged 37 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e41ea0e
add android show title customization functionality
Alex-Usmanov Oct 17, 2023
fb67692
Pass the parameter
Alex-Usmanov Oct 17, 2023
21cd06f
Dependency overrides
Alex-Usmanov Oct 17, 2023
276c08b
Add tests for native side
Alex-Usmanov Oct 17, 2023
1897451
Cover dart side with tests
Alex-Usmanov Oct 17, 2023
5cd1709
Format
Alex-Usmanov Oct 17, 2023
bc943c5
Reduce code repetition
Alex-Usmanov Oct 17, 2023
d6306ba
Revert todo change
Alex-Usmanov Oct 18, 2023
f59475b
Wrap browser customization values in another configuration object
Alex-Usmanov Oct 20, 2023
157343b
Remove deps overrides
Alex-Usmanov Oct 20, 2023
ae20b08
Revert more deps overrides
Alex-Usmanov Oct 20, 2023
214b0a9
Revert web as well
Alex-Usmanov Oct 20, 2023
cd7dfc9
Revert go_router
Alex-Usmanov Oct 20, 2023
d205c7c
Merge branch 'main' into main
Alex-Usmanov Oct 20, 2023
5eef662
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Oct 27, 2023
c86ff6e
Format files
Alex-Usmanov Oct 27, 2023
92b2197
Fix tests
Alex-Usmanov Oct 27, 2023
425617e
Add browseroptions to launchUrlString & add more tests
Alex-Usmanov Oct 30, 2023
ece2b78
Fix docstrings
Alex-Usmanov Dec 7, 2023
3ddd644
Revert test format change
Alex-Usmanov Dec 7, 2023
cd361d0
Fix tests
Alex-Usmanov Dec 8, 2023
f0017b7
Version bumps and changelogs
Alex-Usmanov Dec 8, 2023
6105671
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 8, 2023
a50be0f
Return path-based dependencies
Alex-Usmanov Dec 8, 2023
ef9c154
Add licences
Alex-Usmanov Dec 11, 2023
f4b08cb
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 11, 2023
80d439b
Fix documentation & changelog
Alex-Usmanov Dec 26, 2023
992d38e
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 26, 2023
fd6f0f2
Revert everything except for android implementation
Alex-Usmanov Dec 26, 2023
193c076
Add backticks to SFSafariViewController in platform interface changelog
Alex-Usmanov Jan 4, 2024
b399c9b
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Jan 4, 2024
1ad83a2
More merging
Alex-Usmanov Jan 4, 2024
9737ff0
Merge branch 'main' into show-title-implementations
Alex-Usmanov Jan 4, 2024
adf977f
Merge remote-tracking branch 'upstream/main' into show-title-implemen…
Alex-Usmanov Jan 25, 2024
fa2e62e
Reset platform interface changes
Alex-Usmanov Jan 25, 2024
caac897
Fix
Alex-Usmanov Feb 2, 2024
e89b7c2
Merge remote-tracking branch 'upstream/main' into show-title-implemen…
Alex-Usmanov Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/url_launcher/url_launcher_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 6.3.0

* Adds support for `BrowserConfiguration`.
* Implements `showTitle` functionality for Android Custom Tabs.
* Updates compileSdk version to 34.

## 6.2.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.4), do not edit directly.
// Autogenerated from Pigeon (v10.1.6), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.urllauncher;
Expand Down Expand Up @@ -156,6 +156,55 @@ ArrayList<Object> toList() {
}
}

/** Generated class from Pigeon that represents data sent in messages. */
public static final class BrowserOptions {
private @NonNull Boolean showTitle;

public @NonNull Boolean getShowTitle() {
return showTitle;
}

public void setShowTitle(@NonNull Boolean setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"showTitle\" is null.");
}
this.showTitle = setterArg;
}

/** Constructor is non-public to enforce null safety; use Builder. */
BrowserOptions() {}

public static final class Builder {

private @Nullable Boolean showTitle;

public @NonNull Builder setShowTitle(@NonNull Boolean setterArg) {
this.showTitle = setterArg;
return this;
}

public @NonNull BrowserOptions build() {
BrowserOptions pigeonReturn = new BrowserOptions();
pigeonReturn.setShowTitle(showTitle);
return pigeonReturn;
}
}

@NonNull
ArrayList<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<Object>(1);
toListResult.add(showTitle);
return toListResult;
}

static @NonNull BrowserOptions fromList(@NonNull ArrayList<Object> list) {
BrowserOptions pigeonResult = new BrowserOptions();
Object showTitle = list.get(0);
pigeonResult.setShowTitle((Boolean) showTitle);
return pigeonResult;
}
}

private static class UrlLauncherApiCodec extends StandardMessageCodec {
public static final UrlLauncherApiCodec INSTANCE = new UrlLauncherApiCodec();

Expand All @@ -165,6 +214,8 @@ private UrlLauncherApiCodec() {}
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 128:
return BrowserOptions.fromList((ArrayList<Object>) readValue(buffer));
case (byte) 129:
return WebViewOptions.fromList((ArrayList<Object>) readValue(buffer));
default:
return super.readValueOfType(type, buffer);
Expand All @@ -173,8 +224,11 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {

@Override
protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
if (value instanceof WebViewOptions) {
if (value instanceof BrowserOptions) {
stream.write(128);
writeValue(stream, ((BrowserOptions) value).toList());
} else if (value instanceof WebViewOptions) {
stream.write(129);
writeValue(stream, ((WebViewOptions) value).toList());
} else {
super.writeValue(stream, value);
Expand All @@ -190,12 +244,13 @@ public interface UrlLauncherApi {
/** Opens the URL externally, returning true if successful. */
@NonNull
Boolean launchUrl(@NonNull String url, @NonNull Map<String, String> headers);
/**
* Opens the URL in an in-app Custom Tab or WebView, returning true if it opens successfully.
*/
/** Opens the URL in an in-app WebView, returning true if it opens successfully. */
@NonNull
Boolean openUrlInApp(
@NonNull String url, @NonNull Boolean allowCustomTab, @NonNull WebViewOptions options);
@NonNull String url,
@NonNull Boolean allowCustomTab,
@NonNull WebViewOptions webViewOptions,
@NonNull BrowserOptions browserOptions);

@NonNull
Boolean supportsCustomTabs();
Expand Down Expand Up @@ -272,9 +327,12 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
ArrayList<Object> args = (ArrayList<Object>) message;
String urlArg = (String) args.get(0);
Boolean allowCustomTabArg = (Boolean) args.get(1);
WebViewOptions optionsArg = (WebViewOptions) args.get(2);
WebViewOptions webViewOptionsArg = (WebViewOptions) args.get(2);
BrowserOptions browserOptionsArg = (BrowserOptions) args.get(3);
try {
Boolean output = api.openUrlInApp(urlArg, allowCustomTabArg, optionsArg);
Boolean output =
api.openUrlInApp(
urlArg, allowCustomTabArg, webViewOptionsArg, browserOptionsArg);
wrapped.add(0, output);
} catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.browser.customtabs.CustomTabsClient;
import androidx.browser.customtabs.CustomTabsIntent;
import io.flutter.plugins.urllauncher.Messages.BrowserOptions;
import io.flutter.plugins.urllauncher.Messages.UrlLauncherApi;
import io.flutter.plugins.urllauncher.Messages.WebViewOptions;
import java.util.Collections;
Expand Down Expand Up @@ -98,17 +99,20 @@ void setActivity(@Nullable Activity activity) {

@Override
public @NonNull Boolean openUrlInApp(
@NonNull String url, @NonNull Boolean allowCustomTab, @NonNull WebViewOptions options) {
@NonNull String url,
@NonNull Boolean allowCustomTab,
@NonNull WebViewOptions webViewOptions,
@NonNull BrowserOptions browserOptions) {
ensureActivity();
assert activity != null;

Bundle headersBundle = extractBundle(options.getHeaders());
Bundle headersBundle = extractBundle(webViewOptions.getHeaders());

// Try to launch using Custom Tabs if they have the necessary functionality, unless the caller
// specifically requested a web view.
if (allowCustomTab && !containsRestrictedHeader(options.getHeaders())) {
if (allowCustomTab && !containsRestrictedHeader(webViewOptions.getHeaders())) {
Uri uri = Uri.parse(url);
if (openCustomTab(activity, uri, headersBundle)) {
if (openCustomTab(activity, uri, headersBundle, browserOptions)) {
return true;
}
}
Expand All @@ -118,8 +122,8 @@ void setActivity(@Nullable Activity activity) {
WebViewActivity.createIntent(
activity,
url,
options.getEnableJavaScript(),
options.getEnableDomStorage(),
webViewOptions.getEnableJavaScript(),
webViewOptions.getEnableDomStorage(),
headersBundle);
try {
activity.startActivity(launchIntent);
Expand All @@ -141,9 +145,14 @@ public void closeWebView() {
}

private static boolean openCustomTab(
@NonNull Context context, @NonNull Uri uri, @NonNull Bundle headersBundle) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
@NonNull Context context,
@NonNull Uri uri,
@NonNull Bundle headersBundle,
@NonNull BrowserOptions options) {
CustomTabsIntent customTabsIntent =
new CustomTabsIntent.Builder().setShowTitle(options.getShowTitle()).build();
customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headersBundle);

try {
customTabsIntent.launchUrl(context, uri);
} catch (ActivityNotFoundException ex) {
Expand Down
Loading