WebContentsObserverAndroid.java revision 0529e5d033099cbfc42635f6f6183833b09dff6e
1// Copyright 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 5package org.chromium.content.browser; 6 7import org.chromium.base.CalledByNative; 8import 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") 15public abstract class WebContentsObserverAndroid { 16 private long mNativeWebContentsObserverAndroid; 17 18 public WebContentsObserverAndroid(ContentViewCore contentViewCore) { 19 mNativeWebContentsObserverAndroid = nativeInit(contentViewCore.getNativeContentViewCore()); 20 } 21 22 @CalledByNative 23 public void renderProcessGone(boolean wasOomProtected) { 24 } 25 26 /** 27 * Called when the a page starts loading. 28 * @param url The validated url for the loading page. 29 */ 30 @CalledByNative 31 public void didStartLoading(String url) { 32 } 33 34 /** 35 * Called when the a page finishes loading. 36 * @param url The validated url for the page. 37 */ 38 @CalledByNative 39 public void didStopLoading(String url) { 40 } 41 42 /** 43 * Called when an error occurs while loading a page and/or the page fails to load. 44 * @param errorCode Error code for the occurring error. 45 * @param description The description for the error. 46 * @param failingUrl The url that was loading when the error occurred. 47 */ 48 @CalledByNative 49 public void didFailLoad(boolean isProvisionalLoad, 50 boolean isMainFrame, int errorCode, String description, String failingUrl) { 51 } 52 53 /** 54 * Called when the main frame of the page has committed. 55 * @param url The validated url for the page. 56 * @param baseUrl The validated base url for the page. 57 * @param isNavigationToDifferentPage Whether the main frame navigated to a different page. 58 * @param isNavigationInPage Whether the main frame navigation did not cause changes to the 59 * document (for example scrolling to a named anchor or PopState). 60 */ 61 @CalledByNative 62 public void didNavigateMainFrame(String url, String baseUrl, 63 boolean isNavigationToDifferentPage, boolean isNavigationInPage) { 64 } 65 66 /** 67 * Called when the page had painted something non-empty. 68 * @param pageId unique ID of the page in history entries. 69 */ 70 @CalledByNative 71 public void didFirstVisuallyNonEmptyPaint(int pageId) { 72 } 73 74 /** 75 * Similar to didNavigateMainFrame but also called on subframe navigations. 76 * @param url The validated url for the page. 77 * @param baseUrl The validated base url for the page. 78 * @param isReload True if this navigation is a reload. 79 */ 80 @CalledByNative 81 public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) { 82 } 83 84 /** 85 * Notifies that a load is started for a given frame. 86 * @param frameId A positive, non-zero integer identifying the navigating frame. 87 * @param parentFrameId The frame identifier of the frame containing the navigating frame, 88 * or -1 if the frame is not contained in another frame. 89 * @param isMainFrame Whether the load is happening for the main frame. 90 * @param validatedUrl The validated URL that is being navigated to. 91 * @param isErrorPage Whether this is navigating to an error page. 92 * @param isIframeSrcdoc Whether this is navigating to about:srcdoc. 93 */ 94 @CalledByNative 95 public void didStartProvisionalLoadForFrame( 96 long frameId, 97 long parentFrameId, 98 boolean isMainFrame, 99 String validatedUrl, 100 boolean isErrorPage, 101 boolean isIframeSrcdoc) { 102 } 103 104 /** 105 * Notifies that the provisional load was successfully committed. The RenderViewHost is now 106 * the current RenderViewHost of the WebContents. 107 * @param frameId A positive, non-zero integer identifying the navigating frame. 108 * @param isMainFrame Whether the load is happening for the main frame. 109 * @param url The committed URL being navigated to. 110 * @param transitionType The transition type as defined in 111 * {@link org.chromium.content.browser.PageTransitionTypes} for the load. 112 */ 113 @CalledByNative 114 public void didCommitProvisionalLoadForFrame( 115 long frameId, boolean isMainFrame, String url, int transitionType) { 116 117 } 118 119 /** 120 * Notifies that a load has finished for a given frame. 121 * @param frameId A positive, non-zero integer identifying the navigating frame. 122 * @param validatedUrl The validated URL that is being navigated to. 123 * @param isMainFrame Whether the load is happening for the main frame. 124 */ 125 @CalledByNative 126 public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) { 127 } 128 129 /** 130 * Notifies that a navigation entry has been committed. 131 */ 132 @CalledByNative 133 public void navigationEntryCommitted() { 134 } 135 136 /** 137 * Invoked when visible SSL state changes. 138 */ 139 @CalledByNative 140 public void didChangeVisibleSSLState() { 141 } 142 143 /** 144 * Called when an interstitial page gets attached to the tab content. 145 */ 146 @CalledByNative 147 public void didAttachInterstitialPage() { 148 } 149 150 /** 151 * Called when an interstitial page gets detached from the tab content. 152 */ 153 @CalledByNative 154 public void didDetachInterstitialPage() { 155 } 156 157 /** 158 * Destroy the corresponding native object. 159 */ 160 @CalledByNative 161 public void detachFromWebContents() { 162 if (mNativeWebContentsObserverAndroid != 0) { 163 nativeDestroy(mNativeWebContentsObserverAndroid); 164 mNativeWebContentsObserverAndroid = 0; 165 } 166 } 167 168 private native long nativeInit(long contentViewCorePtr); 169 private native void nativeDestroy(long nativeWebContentsObserverAndroid); 170} 171