Skip to content

Commit

Permalink
Ignore multiple onPageFinished() callbacks & onReceivedError due to s…
Browse files Browse the repository at this point in the history
…topLoading()

I believe this happens only when using custom schemes.
  • Loading branch information
agrieve committed Feb 4, 2014
1 parent dfae374 commit a5c8472
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions framework/src/org/apache/cordova/CordovaWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ public void loadUrlIntoView(final String url, final int time) {
this.loadUrlIntoView(url);
}

@Override
public void stopLoading() {
viewClient.isCurrentlyLoading = false;
super.stopLoading();
}

public void onScrollChanged(int l, int t, int oldl, int oldt)
{
Expand Down
14 changes: 13 additions & 1 deletion framework/src/org/apache/cordova/CordovaWebViewClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class CordovaWebViewClient extends WebViewClient {
CordovaInterface cordova;
CordovaWebView appView;
private boolean doClearHistory = false;
private boolean isCurrentlyLoading;

/** The authorization tokens. */
private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
Expand Down Expand Up @@ -266,7 +267,9 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {

super.onPageStarted(view, url, favicon);
isCurrentlyLoading = true;
LOG.d(TAG, "onPageStarted(" + url + ")");
// Flush stale messages.
this.appView.jsMessageQueue.reset();

Expand All @@ -290,6 +293,11 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// Ignore excessive calls.
if (!isCurrentlyLoading) {
return;
}
isCurrentlyLoading = false;
LOG.d(TAG, "onPageFinished(" + url + ")");

/**
Expand Down Expand Up @@ -344,6 +352,10 @@ public void run() {
*/
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// Ignore error due to stopLoading().
if (!isCurrentlyLoading) {
return;
}
LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

// Clear timeout flag
Expand Down

0 comments on commit a5c8472

Please sign in to comment.