This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter_android] Fixes bug where a AndroidNavigationDelegate
was required to load a request
#6872
Merged
Merged
[webview_flutter_android] Fixes bug where a AndroidNavigationDelegate
was required to load a request
#6872
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/webview_flutter/webview_flutter_android/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugin.platform.PlatformView; | ||
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewHostApi; | ||
import io.flutter.plugins.webviewflutter.WebChromeClientHostApiImpl.WebChromeClientImpl; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
|
@@ -80,7 +79,7 @@ public void setWebContentsDebuggingEnabled(boolean enabled) { | |
/** Implementation of {@link WebView} that can be used as a Flutter {@link PlatformView}s. */ | ||
public static class WebViewPlatformView extends WebView implements PlatformView { | ||
private WebViewClient currentWebViewClient; | ||
private WebChromeClientImpl currentWebChromeClient; | ||
private WebChromeClientHostApiImpl.SecureWebChromeClient currentWebChromeClient; | ||
|
||
/** | ||
* Creates a {@link WebViewPlatformView}. | ||
|
@@ -91,9 +90,7 @@ public WebViewPlatformView( | |
Context context, BinaryMessenger binaryMessenger, InstanceManager instanceManager) { | ||
super(context); | ||
currentWebViewClient = new WebViewClient(); | ||
currentWebChromeClient = | ||
new WebChromeClientImpl( | ||
new WebChromeClientFlutterApiImpl(binaryMessenger, instanceManager)); | ||
currentWebChromeClient = new WebChromeClientHostApiImpl.SecureWebChromeClient(); | ||
|
||
setWebViewClient(currentWebViewClient); | ||
setWebChromeClient(currentWebChromeClient); | ||
|
@@ -119,12 +116,21 @@ public void setWebViewClient(WebViewClient webViewClient) { | |
@Override | ||
public void setWebChromeClient(WebChromeClient client) { | ||
super.setWebChromeClient(client); | ||
if (!(client instanceof WebChromeClientImpl)) { | ||
throw new AssertionError("Client must be a WebChromeClientImpl."); | ||
if (!(client instanceof WebChromeClientHostApiImpl.SecureWebChromeClient)) { | ||
throw new AssertionError("Client must be a SecureWebChromeClient."); | ||
} | ||
currentWebChromeClient = (WebChromeClientImpl) client; | ||
currentWebChromeClient = (WebChromeClientHostApiImpl.SecureWebChromeClient) client; | ||
currentWebChromeClient.setWebViewClient(currentWebViewClient); | ||
} | ||
|
||
// When running unit tests, the parent `WebView` class is replaced by a stub that returns null | ||
// for every method. This is overridden so that this returns the current WebChromeClient during | ||
// unit tests. This should only remain overridden as long as `setWebChromeClient` is overridden. | ||
@Nullable | ||
@Override | ||
public WebChromeClient getWebChromeClient() { | ||
return currentWebChromeClient; | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -135,7 +141,7 @@ public void setWebChromeClient(WebChromeClient client) { | |
public static class InputAwareWebViewPlatformView extends InputAwareWebView | ||
implements PlatformView { | ||
private WebViewClient currentWebViewClient; | ||
private WebChromeClientImpl currentWebChromeClient; | ||
private WebChromeClientHostApiImpl.SecureWebChromeClient currentWebChromeClient; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
|
||
/** | ||
* Creates a {@link InputAwareWebViewPlatformView}. | ||
|
@@ -149,9 +155,7 @@ public InputAwareWebViewPlatformView( | |
View containerView) { | ||
super(context, containerView); | ||
currentWebViewClient = new WebViewClient(); | ||
currentWebChromeClient = | ||
new WebChromeClientImpl( | ||
new WebChromeClientFlutterApiImpl(binaryMessenger, instanceManager)); | ||
currentWebChromeClient = new WebChromeClientHostApiImpl.SecureWebChromeClient(); | ||
|
||
setWebViewClient(currentWebViewClient); | ||
setWebChromeClient(currentWebChromeClient); | ||
|
@@ -198,10 +202,10 @@ public void setWebViewClient(WebViewClient webViewClient) { | |
@Override | ||
public void setWebChromeClient(WebChromeClient client) { | ||
super.setWebChromeClient(client); | ||
if (!(client instanceof WebChromeClientImpl)) { | ||
throw new AssertionError("Client must be a WebChromeClientImpl."); | ||
if (!(client instanceof WebChromeClientHostApiImpl.SecureWebChromeClient)) { | ||
throw new AssertionError("Client must be a SecureWebChromeClient."); | ||
} | ||
currentWebChromeClient = (WebChromeClientImpl) client; | ||
currentWebChromeClient = (WebChromeClientHostApiImpl.SecureWebChromeClient) client; | ||
currentWebChromeClient.setWebViewClient(currentWebViewClient); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't the type here just be
WebChromeClient
since it's only being accessed via overridden methods?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be set to
WebChromeClient
, but then the overridden methods would have to cast this value.