f48abad853074f705509752c74343619ccac2a58
[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     // WebContentsDelegateAndroid methods ---------------------------------------------------------
82
83     /**
84      * Called when the contents loading starts.
85      * @param tab The notifying {@link Tab}.
86      */
87     void onLoadStarted(Tab tab);
88
89     /**
90      * Called when the contents loading stops.
91      * @param tab The notifying {@link Tab}.
92      */
93     void onLoadStopped(Tab tab);
94
95     /**
96      * Called when the load progress of a {@link Tab} changes.
97      * @param tab      The notifying {@link Tab}.
98      * @param progress The new progress from [0,100].
99      */
100     void onLoadProgressChanged(Tab tab, int progress);
101
102     /**
103      * Called when the URL of a {@link Tab} changes.
104      * @param tab The notifying {@link Tab}.
105      * @param url The new URL.
106      */
107     void onUpdateUrl(Tab tab, String url);
108
109     /**
110      * Called when the {@link Tab} should enter or leave fullscreen mode.
111      * @param tab    The notifying {@link Tab}.
112      * @param enable Whether or not to enter fullscreen mode.
113      */
114     void onToggleFullscreenMode(Tab tab, boolean enable);
115
116     // WebContentsObserverAndroid methods ---------------------------------------------------------
117
118     /**
119      * Called when an error occurs while loading a page and/or the page fails to load.
120      * @param tab               The notifying {@link Tab}.
121      * @param isProvisionalLoad Whether the failed load occurred during the provisional load.
122      * @param isMainFrame       Whether failed load happened for the main frame.
123      * @param errorCode         Code for the occurring error.
124      * @param description       The description for the error.
125      * @param failingUrl        The url that was loading when the error occurred.
126      */
127     void onDidFailLoad(
128             Tab tab, boolean isProvisionalLoad, boolean isMainFrame, int errorCode,
129             String description, String failingUrl);
130
131     /**
132      * Called when load is started for a given frame.
133      * @param tab            The notifying {@link Tab}.
134      * @param frameId        A positive, non-zero integer identifying the navigating frame.
135      * @param parentFrameId  The frame identifier of the frame containing the navigating frame,
136      *                       or -1 if the frame is not contained in another frame.
137      * @param isMainFrame    Whether the load is happening for the main frame.
138      * @param validatedUrl   The validated URL that is being navigated to.
139      * @param isErrorPage    Whether this is navigating to an error page.
140      * @param isIframeSrcdoc Whether this is navigating to about:srcdoc.
141      */
142     public void onDidStartProvisionalLoadForFrame(
143             Tab tab, long frameId, long parentFrameId, boolean isMainFrame, String validatedUrl,
144             boolean isErrorPage, boolean isIframeSrcdoc);
145
146     /**
147      * Called when the brand color is changed
148      * @param color the new color in ARGB format.
149      */
150     public void onDidChangeBrandColor(int color);
151 }