Skip to content
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

(7_3_X) [TIMOB-26325] Android: Ti.UI.WebView not firing events in 7.x #10273

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public class TiUIWebView extends TiUIView
public static final int PLUGIN_STATE_ON = 1;
public static final int PLUGIN_STATE_ON_DEMAND = 2;

// TIMOB-25462: minor 'hack' to prevent 'beforeload' and 'load' being
// called when the user-agent has been changed, this is a chromium bug
// https://bugs.chromium.org/p/chromium/issues/detail?id=315891
public boolean hasSetUserAgent = false;

private static enum reloadTypes { DEFAULT, DATA, HTML, URL }

private reloadTypes reloadMethod = reloadTypes.DEFAULT;
Expand Down Expand Up @@ -443,6 +438,11 @@ public void processProperties(KrollDict d)
}
}

// set user-agent befoe loading url to avoid immediate reload
if (d.containsKey(TiC.PROPERTY_USER_AGENT)) {
((WebViewProxy) getProxy()).setUserAgent(d.getString(TiC.PROPERTY_USER_AGENT));
}

if (d.containsKey(TiC.PROPERTY_URL)
&& !TiC.URL_ANDROID_ASSET_RESOURCES.equals(TiConvert.toString(d, TiC.PROPERTY_URL))) {
setUrl(TiConvert.toString(d, TiC.PROPERTY_URL));
Expand Down Expand Up @@ -483,10 +483,6 @@ public void processProperties(KrollDict d)
disableContextMenu = TiConvert.toBoolean(d, TiC.PROPERTY_DISABLE_CONTEXT_MENU);
}

if (d.containsKey(TiC.PROPERTY_USER_AGENT)) {
((WebViewProxy) getProxy()).setUserAgent(d.getString(TiC.PROPERTY_USER_AGENT));
}

if (d.containsKey(TiC.PROPERTY_ZOOM_LEVEL)) {
zoomBy(getWebView(), TiConvert.toFloat(d, TiC.PROPERTY_ZOOM_LEVEL));
}
Expand Down Expand Up @@ -720,11 +716,11 @@ public void setHtml(String html, HashMap<String, Object> d)
}

/**
* Loads HTML content into the web view. Note that the "historyUrl" property
* must be set to non null in order for the web view history to work correctly
* when working with local files (IE: goBack() and goForward() will not work if
* Loads HTML content into the web view. Note that the "historyUrl" property
* must be set to non null in order for the web view history to work correctly
* when working with local files (IE: goBack() and goForward() will not work if
* null is used)
*
*
* @param html HTML data to load into the web view
* @param baseUrl url to associate with the data being loaded
* @param mimeType mime type of the data being loaded
Expand Down Expand Up @@ -897,7 +893,6 @@ public void setUserAgentString(String userAgentString)
{
WebView currWebView = getWebView();
if (currWebView != null) {
hasSetUserAgent = true;
currWebView.getSettings().setUserAgentString(userAgentString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
WebViewProxy proxy = (WebViewProxy) webView.getProxy();
if (proxy == null || webView.hasSetUserAgent) {
webView.hasSetUserAgent = false;
if (proxy == null) {
return;
}
webView.changeProxyUrl(url);
Expand Down Expand Up @@ -94,7 +93,7 @@ public void onPageStarted(WebView view, String url, Bitmap favicon)
{
super.onPageStarted(view, url, favicon);
WebViewProxy proxy = (WebViewProxy) webView.getProxy();
if (proxy == null || webView.hasSetUserAgent) {
if (proxy == null) {
return;
}
KrollDict data = new KrollDict();
Expand Down Expand Up @@ -312,8 +311,8 @@ public void onReceivedClientCertRequest(WebView view, ClientCertRequestHandler h
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
{
/*
* in theory this should be checked to make sure it's not null but if there is some failure
* in the association then usage of proxy should trigger a NPE to make sure the issue
* in theory this should be checked to make sure it's not null but if there is some failure
* in the association then usage of proxy should trigger a NPE to make sure the issue
* is not ignored
*/
WebViewProxy proxy = (WebViewProxy) webView.getProxy();
Expand Down
4 changes: 4 additions & 0 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ properties:
description: |
On the iOS platform, this is not per-webview. Once you have set this property for a webview
it will not change for same. But while creating new webview it can be changed to new user agent.

On Android, changing the user agent after the webview has begun loading content may cause
the webview to reload and fire multiple `load` or `beforeLoad` events. Developers should provide the
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is beforeload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch Hans!

user agent value in the creation properties to avoid the reload and multiple events firing.
type: String
default: System default user-agent value.
platforms: [android, iphone, ipad]
Expand Down