Shingo Toda created CB-8317:
-------------------------------
Summary: exit message is not delivered even though about:blank is
loaded
Key: CB-8317
URL: https://issues.apache.org/jira/browse/CB-8317
Project: Apache Cordova
Issue Type: Bug
Components: Android
Affects Versions: 3.6.0
Environment: Android 4.0.4 (Samsung Galaxy S2), 4.4.3 (Nexus 7)
Reporter: Shingo Toda
Priority: Minor
I'm developing an application using Embeded WebView way and tweaked
{{onMessage}} method to do our things when "exit" is sent. This {{onMessage}}
expects to receive "exit" message which would be dispatched from
{{CordovaWebViewClient#onPageFinished}} if {{about:blank}} is loaded, which is
triggered by {{CordovaActivity#handleDestroy}}. But the implementation as of
Cordova Android 3.6.4 seems to block loading {{about:blank}} for some reasons.
h3. about:load cannot be loaded
Firstly I tried adding {{about:blank}} to whitelist like below, but it didn't
work.
{code:xml}
<access origin="about:blank" />
{code}
It seems that NullPointerException happens at {{URLPattern#matches}} when
about:blank is evaluated because {{uri.getHost()}} returns null.
{code:title=Whitelist.java}
public boolean matches(Uri uri) {
try {
return ((scheme == null ||
scheme.matcher(uri.getScheme()).matches()) &&
(host == null || host.matcher(uri.getHost()).matches())
&&
(port == null || port.equals(uri.getPort())) &&
(path == null ||
path.matcher(uri.getPath()).matches()));
} catch (Exception e) {
{code}
So I changed {{CordovaWebViewClient#loadUrlNow}} to let "about:blank" be loaded
by adding {{url.startsWith("about:")}} in if statement.
{code:title=CordovaWebViewClient#loadUrlNow|borderStyle=solid}
void loadUrlNow(String url) {
if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
LOG.d(TAG, ">>> loadUrlNow()");
}
boolean hoge = internalWhitelist.isUrlWhiteListed(url);
//if (url.startsWith("file://") || url.startsWith("javascript:") ||
internalWhitelist.isUrlWhiteListed(url)) {
if (url.startsWith("file://") || url.startsWith("javascript:") ||
url.startsWith("about:") || internalWhitelist.isUrlWhiteListed(url)) {
super.loadUrl(url);
}
}
{code}
This patch makes about:blank loaded and "exit" is successfully sent on device <
KitKat but still not on KitKat.
h3. exit is not sent on KitKat
On KitKat, exit is not sent even though {{loadUrlNow}} loads {{about:blank}}
because of two issues below.
* It seems that KitKat does not call {{CordovaWebViewClient#onPageStarted}}
when about:blank is loaded.
https://code.google.com/p/android/issues/detail?id=65701
* Crodova is implemented to expect both {{onPageStarted}} and
{{onPageFinished}} would be called due to this commit.
https://github.com/apache/cordova-android/commit/a5c8472a374c1c2b2026fa9dbb39235e198768ef
Now {{onPageStarted}} is supposed to set {{isCurrentlyLoading}} to {{true}} but
this method is not called on KitKat for {{about:blank}}. Then in
{{onPageFinished}}, {{isCurrentlyLoading}} is still {{false}} so it ended up
exiting without doing anything.
As workaround, I made tentative patch to ignore {{isCurrentlyLoading}} variable
if an app is running on on KitKat. This patch make "exit" message dispatched.
{code:title=CordovaWebView#onPageFinished}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// Ignore excessive calls.
if (android.os.Build.VERSION.SDK_INT !=
android.os.Build.VERSION_CODES.KITKAT){
if (!isCurrentlyLoading) {
return;
}
}
{code}
h3. Question
I want to change some source code to fix this issue but since a couple of
problems are involved in this issue and I'm not sure what was a purpose of
those lines, I would like to know some things.
h4. Q1
Andrew's commit says
bq. I believe this happens only when using custom schemes.
What is the case of this? Actually my patch ignores this possible multiple
{{onPageFinished}} call so it would cause some problem.
h4. Q2
Does whitelist not support {{about:blank}}? Also current implementation seems
to block any loading of {{about:blank}}. Do you really intend to do this?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]