1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview;
7 import org.chromium.content.browser.WebContentsObserverAndroid;
8 import org.chromium.content_public.browser.WebContents;
9 import org.chromium.net.NetError;
12 * Routes notifications from WebContents to AwContentsClient and other listeners.
14 public class AwWebContentsObserver extends WebContentsObserverAndroid {
15 private final AwContentsClient mAwContentsClient;
17 public AwWebContentsObserver(WebContents webContents, AwContentsClient awContentsClient) {
19 mAwContentsClient = awContentsClient;
23 public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
24 String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl();
26 unreachableWebDataUrl != null && unreachableWebDataUrl.equals(validatedUrl);
27 if (isMainFrame && !isErrorUrl) {
28 mAwContentsClient.onPageFinished(validatedUrl);
33 public void didFailLoad(boolean isProvisionalLoad,
34 boolean isMainFrame, int errorCode, String description, String failingUrl) {
35 String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl();
37 unreachableWebDataUrl != null && unreachableWebDataUrl.equals(failingUrl);
38 if (isMainFrame && !isErrorUrl) {
39 if (errorCode != NetError.ERR_ABORTED) {
40 // This error code is generated for the following reasons:
41 // - WebView.stopLoading is called,
42 // - the navigation is intercepted by the embedder via shouldOverrideNavigation.
44 // The Android WebView does not notify the embedder of these situations using
45 // this error code with the WebViewClient.onReceivedError callback.
46 mAwContentsClient.onReceivedError(
47 ErrorCodeConversionHelper.convertErrorCode(errorCode), description,
50 // Need to call onPageFinished after onReceivedError (if there is an error) for
51 // backwards compatibility with the classic webview.
52 mAwContentsClient.onPageFinished(failingUrl);
57 public void didNavigateMainFrame(String url, String baseUrl,
58 boolean isNavigationToDifferentPage, boolean isFragmentNavigation) {
59 // This is here to emulate the Classic WebView firing onPageFinished for main frame
60 // navigations where only the hash fragment changes.
61 if (isFragmentNavigation) {
62 mAwContentsClient.onPageFinished(url);
67 public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) {
68 mAwContentsClient.doUpdateVisitedHistory(url, isReload);