1// Copyright 2013 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.chrome.browser; 6 7import android.view.ContextMenu; 8 9import org.chromium.content.browser.ContentViewCore; 10 11/** 12 * An observer that is notified of changes to a {@link Tab} object. 13 */ 14public interface TabObserver { 15 16 /** 17 * Called when a {@link Tab} is being destroyed. 18 * @param tab The notifying {@link Tab}. 19 */ 20 void onDestroyed(Tab tab); 21 22 /** 23 * Called when the tab content changes (to/from native pages or swapping native WebContents). 24 * @param tab The notifying {@link Tab}. 25 */ 26 void onContentChanged(Tab tab); 27 28 /** 29 * Called when loadUrl is triggered on a a {@link Tab}. 30 * @param tab The notifying {@link Tab}. 31 * @param url The url that is being loaded. 32 * @param loadType The type of load that was performed. 33 * 34 * @see TabLoadStatus#PAGE_LOAD_FAILED 35 * @see TabLoadStatus#DEFAULT_PAGE_LOAD 36 * @see TabLoadStatus#PARTIAL_PRERENDERED_PAGE_LOAD 37 * @see TabLoadStatus#FULL_PRERENDERED_PAGE_LOAD 38 */ 39 void onLoadUrl(Tab tab, String url, int loadType); 40 41 /** 42 * Called when the favicon of a {@link Tab} has been updated. 43 * @param tab The notifying {@link Tab}. 44 */ 45 void onFaviconUpdated(Tab tab); 46 47 /** 48 * Called when the title of a {@link Tab} changes. 49 * @param tab The notifying {@link Tab}. 50 */ 51 void onTitleUpdated(Tab tab); 52 53 /** 54 * Called when the URL of a {@link Tab} changes. 55 * @param tab The notifying {@link Tab}. 56 */ 57 void onUrlUpdated(Tab tab); 58 59 /** 60 * Called when the SSL state of a {@link Tab} changes. 61 * @param tab The notifying {@link Tab}. 62 */ 63 void onSSLStateUpdated(Tab tab); 64 65 /** 66 * Called when the WebContents of a {@link Tab} have been swapped. 67 * @param tab The notifying {@link Tab}. 68 * @param didStartLoad Whether WebContentsObserver::DidStartProvisionalLoadForFrame() has 69 * already been called. 70 * @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has already been called. 71 */ 72 void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad); 73 74 /** 75 * Called when a context menu is shown for a {@link ContentViewCore} owned by a {@link Tab}. 76 * @param tab The notifying {@link Tab}. 77 * @param menu The {@link ContextMenu} that is being shown. 78 */ 79 void onContextMenuShown(Tab tab, ContextMenu menu); 80 81 /** 82 * Called when the WebContents Instant support is disabled. 83 */ 84 void onWebContentsInstantSupportDisabled(); 85 86 // WebContentsDelegateAndroid methods --------------------------------------------------------- 87 88 /** 89 * Called when the contents loading starts. 90 * @param tab The notifying {@link Tab}. 91 */ 92 void onLoadStarted(Tab tab); 93 94 /** 95 * Called when the contents loading stops. 96 * @param tab The notifying {@link Tab}. 97 */ 98 void onLoadStopped(Tab tab); 99 100 /** 101 * Called when the load progress of a {@link Tab} changes. 102 * @param tab The notifying {@link Tab}. 103 * @param progress The new progress from [0,100]. 104 */ 105 void onLoadProgressChanged(Tab tab, int progress); 106 107 /** 108 * Called when the URL of a {@link Tab} changes. 109 * @param tab The notifying {@link Tab}. 110 * @param url The new URL. 111 */ 112 void onUpdateUrl(Tab tab, String url); 113 114 /** 115 * Called when the {@link Tab} should enter or leave fullscreen mode. 116 * @param tab The notifying {@link Tab}. 117 * @param enable Whether or not to enter fullscreen mode. 118 */ 119 void onToggleFullscreenMode(Tab tab, boolean enable); 120 121 // WebContentsObserverAndroid methods --------------------------------------------------------- 122 123 /** 124 * Called when an error occurs while loading a page and/or the page fails to load. 125 * @param tab The notifying {@link Tab}. 126 * @param isProvisionalLoad Whether the failed load occurred during the provisional load. 127 * @param isMainFrame Whether failed load happened for the main frame. 128 * @param errorCode Code for the occurring error. 129 * @param description The description for the error. 130 * @param failingUrl The url that was loading when the error occurred. 131 */ 132 void onDidFailLoad( 133 Tab tab, boolean isProvisionalLoad, boolean isMainFrame, int errorCode, 134 String description, String failingUrl); 135 136 /** 137 * Called when load is started for a given frame. 138 * @param tab The notifying {@link Tab}. 139 * @param frameId A positive, non-zero integer identifying the navigating frame. 140 * @param parentFrameId The frame identifier of the frame containing the navigating frame, 141 * or -1 if the frame is not contained in another frame. 142 * @param isMainFrame Whether the load is happening for the main frame. 143 * @param validatedUrl The validated URL that is being navigated to. 144 * @param isErrorPage Whether this is navigating to an error page. 145 * @param isIframeSrcdoc Whether this is navigating to about:srcdoc. 146 */ 147 public void onDidStartProvisionalLoadForFrame( 148 Tab tab, long frameId, long parentFrameId, boolean isMainFrame, String validatedUrl, 149 boolean isErrorPage, boolean isIframeSrcdoc); 150 151 /** 152 * Called when the main frame of the page has committed. 153 * 154 * @param tab The notifying {@link Tab}. 155 * @param url The validated url for the page. 156 * @param baseUrl The validated base url for the page. 157 * @param isNavigationToDifferentPage Whether the main frame navigated to a different page. 158 * @param isFragmentNavigation Whether the main frame navigation did not cause changes 159 * to the document (for example scrolling to a named anchor 160 * or PopState). 161 * @param statusCode The HTTP status code of the navigation. 162 */ 163 public void onDidNavigateMainFrame(Tab tab, String url, String baseUrl, 164 boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode); 165 166 /** 167 * Called when the theme color is changed 168 * @param color the new color in ARGB format. 169 */ 170 public void onDidChangeThemeColor(int color); 171} 172