| 1 | // Copyright (c) 2012 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. |
| 4 | |
| 5 | package org.chromium.content.browser; |
| 6 | |
| 7 | import org.chromium.base.CalledByNative; |
| 8 | import org.chromium.base.JNINamespace; |
| 9 | |
| 10 | /** |
| 11 | * This class receives callbacks that act as hooks for various a native web contents events related |
| 12 | * to loading a url. A single web contents can have multiple WebContentObserverAndroids. |
| 13 | */ |
| 14 | @JNINamespace("content") |
| 15 | public abstract class WebContentsObserverAndroid { |
| 16 | private int mNativeWebContentsObserverAndroid; |
| 17 | |
| 18 | public WebContentsObserverAndroid(ContentViewCore contentViewCore) { |
| 19 | mNativeWebContentsObserverAndroid = nativeInit(contentViewCore.getNativeContentViewCore()); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Called when the a page starts loading. |
| 24 | * @param url The validated url for the loading page. |
| 25 | */ |
| 26 | @CalledByNative |
| 27 | public void didStartLoading(String url) { |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Called when the a page finishes loading. |
| 32 | * @param url The validated url for the page. |
| 33 | */ |
| 34 | @CalledByNative |
| 35 | public void didStopLoading(String url) { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Called when an error occurs while loading a page and/or the page fails to load. |
| 40 | * @param errorCode Error code for the occurring error. |
| 41 | * @param description The description for the error. |
| 42 | * @param failingUrl The url that was loading when the error occurred. |
| 43 | */ |
| 44 | @CalledByNative |
| 45 | public void didFailLoad(boolean isProvisionalLoad, |
| 46 | boolean isMainFrame, int errorCode, String description, String failingUrl) { |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Called when the main frame of the page has committed. |
| 51 | * @param url The validated url for the page. |
| 52 | * @param baseUrl The validated base url for the page. |
| 53 | * @param isNavigationToDifferentPage Whether the main frame navigated to a different page. |
| 54 | */ |
| 55 | @CalledByNative |
| 56 | public void didNavigateMainFrame(String url, String baseUrl, |
| 57 | boolean isNavigationToDifferentPage) { |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Similar to didNavigateMainFrame but also called on subframe navigations. |
| 62 | * @param url The validated url for the page. |
| 63 | * @param baseUrl The validated base url for the page. |
| 64 | * @param isReload True if this navigation is a reload. |
| 65 | */ |
| 66 | @CalledByNative |
| 67 | public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) { |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Notifies that a load is started for a given frame. |
| 72 | * @param frameId A positive, non-zero integer identifying the navigating frame. |
| 73 | * @param parentFrameId The frame identifier of the frame containing the navigating frame, |
| 74 | * or -1 if the frame is not contained in another frame. |
| 75 | * @param isMainFrame Whether the load is happening for the main frame. |
| 76 | * @param validatedUrl The validated URL that is being navigated to. |
| 77 | * @param isErrorPage Whether this is navigating to an error page. |
| 78 | * @param isIframeSrcdoc Whether this is navigating to about:srcdoc. |
| 79 | */ |
| 80 | @CalledByNative |
| 81 | public void didStartProvisionalLoadForFrame( |
| 82 | long frameId, |
| 83 | long parentFrameId, |
| 84 | boolean isMainFrame, |
| 85 | String validatedUrl, |
| 86 | boolean isErrorPage, |
| 87 | boolean isIframeSrcdoc) { |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Notifies that the provisional load was successfully committed. The RenderViewHost is now |
| 92 | * the current RenderViewHost of the WebContents. |
| 93 | * @param frameId A positive, non-zero integer identifying the navigating frame. |
| 94 | * @param isMainFrame Whether the load is happening for the main frame. |
| 95 | * @param url The committed URL being navigated to. |
| 96 | * @param transitionType The transition type as defined in |
| 97 | * {@link org.chromium.content.browser.PageTransitionTypes} for the load. |
| 98 | */ |
| 99 | @CalledByNative |
| 100 | public void didCommitProvisionalLoadForFrame( |
| 101 | long frameId, boolean isMainFrame, String url, int transitionType) { |
| 102 | |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Notifies that a load has finished for a given frame. |
| 107 | * @param frameId A positive, non-zero integer identifying the navigating frame. |
| 108 | * @param validatedUrl The validated URL that is being navigated to. |
| 109 | * @param isMainFrame Whether the load is happening for the main frame. |
| 110 | */ |
| 111 | @CalledByNative |
| 112 | public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) { |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Invoked when visible SSL state changes. |
| 117 | */ |
| 118 | @CalledByNative |
| 119 | public void didChangeVisibleSSLState() { |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Destroy the corresponding native object. |
| 124 | */ |
| 125 | @CalledByNative |
| 126 | public void detachFromWebContents() { |
| 127 | if (mNativeWebContentsObserverAndroid != 0) { |
| 128 | nativeDestroy(mNativeWebContentsObserverAndroid); |
| 129 | mNativeWebContentsObserverAndroid = 0; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | private native int nativeInit(int contentViewCorePtr); |
| 134 | private native void nativeDestroy(int nativeWebContentsObserverAndroid); |
| 135 | } |