Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 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
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
298a705
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Feb 12, 2024
70f5eb0
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Mar 31, 2024
8f67ab9
Remove dependency overrides
Alex-Usmanov Mar 31, 2024
c203ae0
Revert changelog
Alex-Usmanov Apr 1, 2024
5ae7bc9
Merge branch 'main' into show-title
Alex-Usmanov Apr 7, 2024
e646958
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 10, 2024
7d92695
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 21, 2024
90360b0
Fix missing classname in type_conversion.dart
Alex-Usmanov Jun 3, 2024
647a8ce
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Jun 3, 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
Prev Previous commit
Next Next commit
Wrap browser customization values in another configuration object
  • Loading branch information
Alex-Usmanov committed Oct 20, 2023
commit f59475bd58fce64086d3d5b631dc318d5e9e1db6
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class _MyHomePageState extends State<MyHomePage> {
if (!await launchUrl(
url,
mode: LaunchMode.inAppWebView,
webViewConfiguration: const WebViewConfiguration(showTitle: true),
browserConfiguration: const BrowserConfiguration(showTitle: true),
)) {
throw Exception('Could not launch $url');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ import 'types.dart';

/// Converts an (app-facing) [WebViewConfiguration] to a (platform interface)
/// [InAppWebViewConfiguration].
InAppWebViewConfiguration convertConfiguration(WebViewConfiguration config) {
InAppWebViewConfiguration convertWebViewConfiguration(
WebViewConfiguration config) {
return InAppWebViewConfiguration(
enableJavaScript: config.enableJavaScript,
enableDomStorage: config.enableDomStorage,
headers: config.headers,
);
}

/// Converts an (app-facing) [BrowserConfiguration] to a (platform interface)
/// [InApp].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[InAppBrowserConfiguration]

InAppBrowserConfiguration convertBrowserConfiguration(
BrowserConfiguration config) {
return InAppBrowserConfiguration(
showTitle: config.showTitle,
);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/url_launcher/url_launcher/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class WebViewConfiguration {
this.enableJavaScript = true,
this.enableDomStorage = true,
this.headers = const <String, String>{},
this.showTitle = false,
});

/// Whether or not JavaScript is enabled for the web content.
Expand All @@ -52,6 +51,14 @@ class WebViewConfiguration {
/// [Browser.EXTRA_HEADERS](https://developer.android.com/reference/android/provider/Browser#EXTRA_HEADERS)
/// Not all browsers support this, so it is not guaranteed to be honored.
final Map<String, String> headers;
}

/// Additional configuration options for [LaunchMode.inAppWebView]
// TODO(alex): replace this when the pr lands
@immutable
class BrowserConfiguration {
/// Creates a new InAppBrowserConfiguration with given settings.
const BrowserConfiguration({this.showTitle = false});

/// Whether or not to show the webpage title when using Chrome Custom Tabs.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Future<bool> launchUrlString(
urlString,
LaunchOptions(
mode: convertLaunchMode(mode),
webViewConfiguration: convertConfiguration(webViewConfiguration),
webViewConfiguration: convertWebViewConfiguration(webViewConfiguration),
webOnlyWindowName: webOnlyWindowName,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Future<bool> launchUrl(
Uri url, {
LaunchMode mode = LaunchMode.platformDefault,
WebViewConfiguration webViewConfiguration = const WebViewConfiguration(),
BrowserConfiguration browserConfiguration = const BrowserConfiguration(),
String? webOnlyWindowName,
}) async {
if (mode == LaunchMode.inAppWebView &&
Expand All @@ -54,7 +55,8 @@ Future<bool> launchUrl(
url.toString(),
LaunchOptions(
mode: convertLaunchMode(mode),
webViewConfiguration: convertConfiguration(webViewConfiguration),
webViewConfiguration: convertWebViewConfiguration(webViewConfiguration),
browserConfiguration: convertBrowserConfiguration(browserConfiguration),
webOnlyWindowName: webOnlyWindowName,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MockUrlLauncher extends Fake
expect(options.webViewConfiguration.enableJavaScript, enableJavaScript);
expect(options.webViewConfiguration.enableDomStorage, enableDomStorage);
expect(options.webViewConfiguration.headers, headers);
expect(options.webViewConfiguration.showTitle, showTitle);
expect(options.browserConfiguration.showTitle, showTitle);
expect(options.webOnlyWindowName, webOnlyWindowName);
launchCalled = true;
return response!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ void main() {
)
..setResponse(true);
expect(
await launchUrl(url,
mode: LaunchMode.inAppWebView,
webViewConfiguration:
const WebViewConfiguration(showTitle: true)),
await launchUrl(
url,
mode: LaunchMode.inAppWebView,
browserConfiguration: const BrowserConfiguration(showTitle: true),
),
isTrue);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,6 @@ public void setHeaders(@NonNull Map<String, String> setterArg) {
this.headers = setterArg;
}

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. */
WebViewOptions() {}

Expand All @@ -139,30 +126,21 @@ public static final class Builder {
return this;
}

private @Nullable Boolean showTitle;

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

public @NonNull WebViewOptions build() {
WebViewOptions pigeonReturn = new WebViewOptions();
pigeonReturn.setEnableJavaScript(enableJavaScript);
pigeonReturn.setEnableDomStorage(enableDomStorage);
pigeonReturn.setHeaders(headers);
pigeonReturn.setShowTitle(showTitle);
return pigeonReturn;
}
}

@NonNull
ArrayList<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<Object>(4);
ArrayList<Object> toListResult = new ArrayList<Object>(3);
toListResult.add(enableJavaScript);
toListResult.add(enableDomStorage);
toListResult.add(headers);
toListResult.add(showTitle);
return toListResult;
}

Expand All @@ -174,7 +152,54 @@ ArrayList<Object> toList() {
pigeonResult.setEnableDomStorage((Boolean) enableDomStorage);
Object headers = list.get(2);
pigeonResult.setHeaders((Map<String, String>) headers);
Object showTitle = list.get(3);
return pigeonResult;
}
}

/** 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;
}
Expand All @@ -189,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 @@ -197,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 @@ -216,7 +246,10 @@ public interface UrlLauncherApi {
Boolean launchUrl(@NonNull String url, @NonNull Map<String, String> headers);
/** Opens the URL in an in-app WebView, returning true if it opens successfully. */
@NonNull
Boolean openUrlInWebView(@NonNull String url, @NonNull WebViewOptions options);
Boolean openUrlInWebView(
@NonNull String url,
@NonNull WebViewOptions webViewOptions,
@NonNull BrowserOptions browserOptions);
/** Closes the view opened by [openUrlInSafariViewController]. */
void closeWebView();

Expand Down Expand Up @@ -289,9 +322,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String urlArg = (String) args.get(0);
WebViewOptions optionsArg = (WebViewOptions) args.get(1);
WebViewOptions webViewOptionsArg = (WebViewOptions) args.get(1);
BrowserOptions browserOptionsArg = (BrowserOptions) args.get(2);
try {
Boolean output = api.openUrlInWebView(urlArg, optionsArg);
Boolean output =
api.openUrlInWebView(urlArg, 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 @@ -19,6 +19,7 @@
import androidx.browser.customtabs.CustomTabsIntent;
import io.flutter.plugins.urllauncher.Messages.UrlLauncherApi;
import io.flutter.plugins.urllauncher.Messages.WebViewOptions;
import io.flutter.plugins.urllauncher.Messages.BrowserOptions;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -95,16 +96,19 @@ void setActivity(@Nullable Activity activity) {
}

@Override
public @NonNull Boolean openUrlInWebView(@NonNull String url, @NonNull WebViewOptions options) {
public @NonNull Boolean openUrlInWebView(
@NonNull String url,
@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.
if (!containsRestrictedHeader(options.getHeaders())) {
if (!containsRestrictedHeader(webViewOptions.getHeaders())) {
Uri uri = Uri.parse(url);
if (openCustomTab(activity, uri, headersBundle, options)) {
if (openCustomTab(activity, uri, headersBundle, browserOptions)) {
return true;
}
}
Expand All @@ -114,8 +118,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 @@ -136,7 +140,7 @@ public static boolean openCustomTab(
@NonNull Context context,
@NonNull Uri uri,
@NonNull Bundle headersBundle,
@NonNull WebViewOptions options) {
@NonNull BrowserOptions options) {
CustomTabsIntent customTabsIntent =
new CustomTabsIntent.Builder().setShowTitle(options.getShowTitle()).build();

Expand Down
Loading