Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / TabObserver.java
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
5 package org.chromium.chrome.browser;
6
7 import android.view.ContextMenu;
8
9 import org.chromium.content.browser.ContentViewCore;
10
11 /**
12  * An observer that is notified of changes to a {@link Tab} object.
13  */
14 public 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     // WebContentsObserver 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      * Notifies that the provisional load was successfully committed. The RenderViewHost is now
153      * the current RenderViewHost of the WebContents.
154      *
155      * @param tab            The notifying {@link Tab}.
156      * @param frameId        A positive, non-zero integer identifying the navigating frame.
157      * @param isMainFrame    Whether the load is happening for the main frame.
158      * @param url            The committed URL being navigated to.
159      * @param transitionType The transition type as defined in
160      *                       {@link org.chromium.ui.base.PageTransitionTypes} for the load.
161      */
162     public void onDidCommitProvisionalLoadForFrame(
163             Tab tab, long frameId, boolean isMainFrame, String url, int transitionType);
164
165     /**
166      * Called when the main frame of the page has committed.
167      *
168      * @param tab                         The notifying {@link Tab}.
169      * @param url                         The validated url for the page.
170      * @param baseUrl                     The validated base url for the page.
171      * @param isNavigationToDifferentPage Whether the main frame navigated to a different page.
172      * @param isFragmentNavigation        Whether the main frame navigation did not cause changes
173      *                                    to the document (for example scrolling to a named anchor
174      *                                    or PopState).
175      * @param statusCode                  The HTTP status code of the navigation.
176      */
177     public void onDidNavigateMainFrame(Tab tab, String url, String baseUrl,
178             boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode);
179
180     /**
181      * Called when the theme color is changed
182      * @param color the new color in ARGB format.
183      */
184     public void onDidChangeThemeColor(int color);
185 }