Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Process feedback on PR
  • Loading branch information
mvanbeusekom committed Nov 29, 2021
commit c55603ee19e9e4625ab93c8243f3f3d4b2c5ce8b
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public void setWebChromeClient(Long instanceId, Long clientInstanceId) {
webView.setWebChromeClient((WebChromeClient) instanceManager.getInstance(clientInstanceId));
}

@Nullable
private static String parseNullStringIdentifier(String value) {
if (value.equals(nullStringIdentifier)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ class WebView {
/// The [mimeType] parameter specifies the format of the data. If WebView
/// can't handle the specified MIME type, it will download the data. If
/// `null`, defaults to 'text/html'.
Future<void> loadData(String data, String? mimeType, String? encoding) {
Future<void> loadData({
required String data,
String? mimeType,
String? encoding,
}) {
return api.loadDataFromInstance(
this,
data,
Expand All @@ -99,12 +103,12 @@ class WebView {
);
}

/// Loads the given data into this WebView, using baseUrl as the base URL for
/// the content.
/// Loads the given data into this WebView.
///
/// The [baseUrl] is used as base URL for the content. It is used both to
/// resolve relative URLs and when applying JavaScript's same origin policy.
///
/// The base URL is used both to resolve relative URLs and when applying
/// JavaScript's same origin policy. The [historyUrl] is used for the history
/// entry.
/// The [historyUrl] is used for the history entry.
///
/// The [mimeType] parameter specifies the format of the data. If WebView
/// can't handle the specified MIME type, it will download the data. If
Expand Down Expand Up @@ -134,13 +138,13 @@ class WebView {
/// malicious content can also create frames with a null origin. If you need
/// to identify the main frame's origin in a trustworthy way, you should use a
/// valid HTTP or HTTPS base URL to set the origin.
Future<void> loadDataWithBaseUrl(
Future<void> loadDataWithBaseUrl({
String? baseUrl,
String data,
required String data,
String? mimeType,
String? encoding,
String? historyUrl,
) {
}) {
return api.loadDataWithBaseUrlFromInstance(
this,
baseUrl ?? _nullStringIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ class WebViewAndroidPlatformController extends WebViewPlatformController {
@override
Future<void> loadHtmlString(String html, {String? baseUrl}) {
return webView.loadDataWithBaseUrl(
baseUrl,
html,
'text/html',
null,
null,
baseUrl: baseUrl,
data: html,
mimeType: 'text/html',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ void main() {
});

test('loadData', () {
webView.loadData('hello', 'text/plain', 'base64');
webView.loadData(
data: 'hello',
mimeType: 'text/plain',
encoding: 'base64',
);
verify(mockPlatformHostApi.loadData(
webViewInstanceId,
'hello',
Expand All @@ -69,7 +73,7 @@ void main() {
});

test('loadData with null values', () {
webView.loadData('hello', null, null);
webView.loadData(data: 'hello', mimeType: null, encoding: null);
verify(mockPlatformHostApi.loadData(
webViewInstanceId,
'hello',
Expand All @@ -80,11 +84,11 @@ void main() {

test('loadDataWithBaseUrl', () {
webView.loadDataWithBaseUrl(
'https://base.url',
'hello',
'text/plain',
'base64',
'https://history.url',
baseUrl: 'https://base.url',
data: 'hello',
mimeType: 'text/plain',
encoding: 'base64',
historyUrl: 'https://history.url',
);

verify(mockPlatformHostApi.loadDataWithBaseUrl(
Expand All @@ -98,7 +102,7 @@ void main() {
});

test('loadDataWithBaseUrl with null values', () {
webView.loadDataWithBaseUrl(null, 'hello', null, null, null);
webView.loadDataWithBaseUrl(data: 'hello');
verify(mockPlatformHostApi.loadDataWithBaseUrl(
webViewInstanceId,
'<null-value>',
Expand Down