The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
Mike Reed | e5073c2 | 2010-01-29 11:31:39 -0500 | [diff] [blame] | 19 | import android.graphics.Bitmap; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 20 | import android.os.Bundle; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 21 | import android.util.Log; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 22 | import android.view.View; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 23 | import android.webkit.WebBackForwardList; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 24 | import android.webkit.WebView; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 25 | |
| 26 | import java.io.File; |
| 27 | import java.util.ArrayList; |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 28 | import java.util.HashMap; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 29 | import java.util.Vector; |
| 30 | |
| 31 | class TabControl { |
| 32 | // Log Tag |
| 33 | private static final String LOGTAG = "TabControl"; |
| 34 | // Maximum number of tabs. |
Michael Kolb | 6e4653e | 2010-09-27 16:22:38 -0700 | [diff] [blame] | 35 | private int mMaxTabs; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 36 | // Private array of WebViews that are used as tabs. |
Michael Kolb | 6e4653e | 2010-09-27 16:22:38 -0700 | [diff] [blame] | 37 | private ArrayList<Tab> mTabs; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 38 | // Queue of most recently viewed tabs. |
Michael Kolb | 6e4653e | 2010-09-27 16:22:38 -0700 | [diff] [blame] | 39 | private ArrayList<Tab> mTabQueue; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 40 | // Current position in mTabs. |
| 41 | private int mCurrentTab = -1; |
| 42 | // A private instance of BrowserActivity to interface with when adding and |
| 43 | // switching between tabs. |
| 44 | private final BrowserActivity mActivity; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 45 | // Directory to store thumbnails for each WebView. |
| 46 | private final File mThumbnailDir; |
Michael Kolb | 6877575 | 2010-08-19 12:42:01 -0700 | [diff] [blame] | 47 | // Use on screen zoom buttons |
| 48 | private boolean mDisplayZoomControls; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Construct a new TabControl object that interfaces with the given |
| 52 | * BrowserActivity instance. |
| 53 | * @param activity A BrowserActivity instance that TabControl will interface |
| 54 | * with. |
| 55 | */ |
| 56 | TabControl(BrowserActivity activity) { |
| 57 | mActivity = activity; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 58 | mThumbnailDir = activity.getDir("thumbnails", 0); |
Michael Kolb | 6877575 | 2010-08-19 12:42:01 -0700 | [diff] [blame] | 59 | mDisplayZoomControls = true; |
Michael Kolb | 6e4653e | 2010-09-27 16:22:38 -0700 | [diff] [blame] | 60 | mMaxTabs = activity.getResources().getInteger(R.integer.max_tabs); |
| 61 | mTabs = new ArrayList<Tab>(mMaxTabs); |
| 62 | mTabQueue = new ArrayList<Tab>(mMaxTabs); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | File getThumbnailDir() { |
| 66 | return mThumbnailDir; |
| 67 | } |
| 68 | |
| 69 | BrowserActivity getBrowserActivity() { |
| 70 | return mActivity; |
| 71 | } |
| 72 | |
| 73 | /** |
Michael Kolb | 6877575 | 2010-08-19 12:42:01 -0700 | [diff] [blame] | 74 | * Set if the webview should use the on screen zoom controls |
| 75 | * @param enabled |
| 76 | */ |
| 77 | void setDisplayZoomControls(boolean enabled) { |
| 78 | mDisplayZoomControls = enabled; |
| 79 | } |
| 80 | |
| 81 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 82 | * Return the current tab's main WebView. This will always return the main |
| 83 | * WebView for a given tab and not a subwindow. |
| 84 | * @return The current tab's WebView. |
| 85 | */ |
| 86 | WebView getCurrentWebView() { |
| 87 | Tab t = getTab(mCurrentTab); |
| 88 | if (t == null) { |
| 89 | return null; |
| 90 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 91 | return t.getWebView(); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 95 | * Return the current tab's top-level WebView. This can return a subwindow |
| 96 | * if one exists. |
| 97 | * @return The top-level WebView of the current tab. |
| 98 | */ |
| 99 | WebView getCurrentTopWebView() { |
| 100 | Tab t = getTab(mCurrentTab); |
| 101 | if (t == null) { |
| 102 | return null; |
| 103 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 104 | return t.getTopWindow(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Return the current tab's subwindow if it exists. |
| 109 | * @return The subwindow of the current tab or null if it doesn't exist. |
| 110 | */ |
| 111 | WebView getCurrentSubWindow() { |
| 112 | Tab t = getTab(mCurrentTab); |
| 113 | if (t == null) { |
| 114 | return null; |
| 115 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 116 | return t.getSubWebView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Return the tab at the specified index. |
| 121 | * @return The Tab for the specified index or null if the tab does not |
| 122 | * exist. |
| 123 | */ |
| 124 | Tab getTab(int index) { |
| 125 | if (index >= 0 && index < mTabs.size()) { |
| 126 | return mTabs.get(index); |
| 127 | } |
| 128 | return null; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Return the current tab. |
| 133 | * @return The current tab. |
| 134 | */ |
| 135 | Tab getCurrentTab() { |
| 136 | return getTab(mCurrentTab); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Return the current tab index. |
| 141 | * @return The current tab index |
| 142 | */ |
| 143 | int getCurrentIndex() { |
| 144 | return mCurrentTab; |
| 145 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 146 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 147 | /** |
| 148 | * Given a Tab, find it's index |
| 149 | * @param Tab to find |
| 150 | * @return index of Tab or -1 if not found |
| 151 | */ |
| 152 | int getTabIndex(Tab tab) { |
Patrick Scott | ae641ac | 2009-04-20 13:51:49 -0400 | [diff] [blame] | 153 | if (tab == null) { |
| 154 | return -1; |
| 155 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 156 | return mTabs.indexOf(tab); |
| 157 | } |
| 158 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 159 | boolean canCreateNewTab() { |
Michael Kolb | 6e4653e | 2010-09-27 16:22:38 -0700 | [diff] [blame] | 160 | return mMaxTabs != mTabs.size(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 161 | } |
| 162 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 163 | /** |
Elliott Slaughter | e440a88 | 2010-08-20 13:54:45 -0700 | [diff] [blame] | 164 | * Returns true if there are any incognito tabs open. |
| 165 | * @return True when any incognito tabs are open, false otherwise. |
| 166 | */ |
| 167 | boolean hasAnyOpenIncognitoTabs() { |
| 168 | for (Tab tab : mTabs) { |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 169 | if (tab.getWebView() != null && tab.getWebView().isPrivateBrowsingEnabled()) { |
Elliott Slaughter | e440a88 | 2010-08-20 13:54:45 -0700 | [diff] [blame] | 170 | return true; |
| 171 | } |
| 172 | } |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | /** |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 177 | * Create a new tab. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 178 | * @return The newly createTab or null if we have reached the maximum |
| 179 | * number of open tabs. |
| 180 | */ |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 181 | Tab createNewTab(boolean closeOnExit, String appId, String url, |
| 182 | boolean privateBrowsing) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 183 | int size = mTabs.size(); |
| 184 | // Return false if we have maxed out on tabs |
Michael Kolb | 6e4653e | 2010-09-27 16:22:38 -0700 | [diff] [blame] | 185 | if (mMaxTabs == size) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 186 | return null; |
| 187 | } |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 188 | final WebView w = createNewWebView(privateBrowsing); |
Steve Block | 2bc6991 | 2009-07-30 14:45:13 +0100 | [diff] [blame] | 189 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 190 | // Create a new tab and add it to the tab list |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 191 | Tab t = new Tab(mActivity, w, closeOnExit, appId, url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 192 | mTabs.add(t); |
The Android Open Source Project | 4e5f587 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 193 | // Initially put the tab in the background. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 194 | t.putInBackground(); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 195 | if (mTabChangeListener != null) { |
| 196 | mTabChangeListener.onNewTab(t); |
| 197 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 198 | return t; |
| 199 | } |
| 200 | |
| 201 | /** |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 202 | * Create a new tab with default values for closeOnExit(false), |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 203 | * appId(null), url(null), and privateBrowsing(false). |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 204 | */ |
| 205 | Tab createNewTab() { |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 206 | return createNewTab(false, null, null, false); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /** |
Leon Scroggins | fde9746 | 2010-01-11 13:06:21 -0500 | [diff] [blame] | 210 | * Remove the parent child relationships from all tabs. |
| 211 | */ |
| 212 | void removeParentChildRelationShips() { |
| 213 | for (Tab tab : mTabs) { |
| 214 | tab.removeFromTree(); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 219 | * Remove the tab from the list. If the tab is the current tab shown, the |
| 220 | * last created tab will be shown. |
| 221 | * @param t The tab to be removed. |
| 222 | */ |
| 223 | boolean removeTab(Tab t) { |
| 224 | if (t == null) { |
| 225 | return false; |
| 226 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 227 | |
Patrick Scott | d944d4d | 2010-01-27 16:39:11 -0500 | [diff] [blame] | 228 | // Grab the current tab before modifying the list. |
| 229 | Tab current = getCurrentTab(); |
| 230 | |
| 231 | // Remove t from our list of tabs. |
| 232 | mTabs.remove(t); |
| 233 | |
| 234 | // Put the tab in the background only if it is the current one. |
| 235 | if (current == t) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 236 | t.putInBackground(); |
| 237 | mCurrentTab = -1; |
Patrick Scott | d944d4d | 2010-01-27 16:39:11 -0500 | [diff] [blame] | 238 | } else { |
| 239 | // If a tab that is earlier in the list gets removed, the current |
| 240 | // index no longer points to the correct tab. |
| 241 | mCurrentTab = getTabIndex(current); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 244 | // destroy the tab |
| 245 | t.destroy(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 246 | // clear it's references to parent and children |
| 247 | t.removeFromTree(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 248 | |
| 249 | // The tab indices have shifted, update all the saved state so we point |
| 250 | // to the correct index. |
| 251 | for (Tab tab : mTabs) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 252 | Vector<Tab> children = tab.getChildTabs(); |
| 253 | if (children != null) { |
| 254 | for (Tab child : children) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 255 | child.setParentTab(tab); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 260 | // Remove it from the queue of viewed tabs. |
| 261 | mTabQueue.remove(t); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 262 | if (mTabChangeListener != null) { |
| 263 | mTabChangeListener.onRemoveTab(t); |
| 264 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 265 | return true; |
| 266 | } |
| 267 | |
| 268 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 269 | * Destroy all the tabs and subwindows |
| 270 | */ |
| 271 | void destroy() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 272 | for (Tab t : mTabs) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 273 | t.destroy(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 274 | } |
| 275 | mTabs.clear(); |
| 276 | mTabQueue.clear(); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Returns the number of tabs created. |
| 281 | * @return The number of tabs created. |
| 282 | */ |
| 283 | int getTabCount() { |
| 284 | return mTabs.size(); |
| 285 | } |
| 286 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 287 | |
| 288 | /** |
| 289 | * Save the state of all the Tabs. |
| 290 | * @param outState The Bundle to save the state to. |
| 291 | */ |
| 292 | void saveState(Bundle outState) { |
| 293 | final int numTabs = getTabCount(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 294 | outState.putInt(Tab.NUMTABS, numTabs); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 295 | final int index = getCurrentIndex(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 296 | outState.putInt(Tab.CURRTAB, (index >= 0 && index < numTabs) ? index : 0); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 297 | for (int i = 0; i < numTabs; i++) { |
| 298 | final Tab t = getTab(i); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 299 | if (t.saveState()) { |
| 300 | outState.putBundle(Tab.WEBVIEW + i, t.getSavedState()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Restore the state of all the tabs. |
| 307 | * @param inState The saved state of all the tabs. |
| 308 | * @return True if there were previous tabs that were restored. False if |
| 309 | * there was no saved state or restoring the state failed. |
| 310 | */ |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 311 | boolean restoreState(Bundle inState, boolean dontRestoreIncognitoTabs) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 312 | final int numTabs = (inState == null) |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 313 | ? -1 : inState.getInt(Tab.NUMTABS, -1); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 314 | if (numTabs == -1) { |
| 315 | return false; |
| 316 | } else { |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 317 | final int oldCurrentTab = inState.getInt(Tab.CURRTAB, -1); |
| 318 | |
| 319 | // Determine whether the saved current tab can be restored, and |
| 320 | // if not, which tab will take its place. |
| 321 | int currentTab = -1; |
| 322 | if (!dontRestoreIncognitoTabs |
| 323 | || !inState.getBundle(Tab.WEBVIEW + oldCurrentTab).getBoolean(Tab.INCOGNITO)) { |
| 324 | currentTab = oldCurrentTab; |
| 325 | } else { |
| 326 | for (int i = 0; i < numTabs; i++) { |
| 327 | if (!inState.getBundle(Tab.WEBVIEW + i).getBoolean(Tab.INCOGNITO)) { |
| 328 | currentTab = i; |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | if (currentTab < 0) { |
| 334 | return false; |
| 335 | } |
| 336 | |
| 337 | // Map saved tab indices to new indices, in case any incognito tabs |
| 338 | // need to not be restored. |
| 339 | HashMap<Integer, Integer> originalTabIndices = new HashMap<Integer, Integer>(); |
| 340 | originalTabIndices.put(-1, -1); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 341 | for (int i = 0; i < numTabs; i++) { |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 342 | Bundle state = inState.getBundle(Tab.WEBVIEW + i); |
| 343 | |
| 344 | if (dontRestoreIncognitoTabs && state != null && state.getBoolean(Tab.INCOGNITO)) { |
| 345 | originalTabIndices.put(i, -1); |
| 346 | } else if (i == currentTab) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 347 | Tab t = createNewTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 348 | // Me must set the current tab before restoring the state |
| 349 | // so that all the client classes are set. |
| 350 | setCurrentTab(t); |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 351 | if (!t.restoreState(state)) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 352 | Log.w(LOGTAG, "Fail in restoreState, load home page."); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 353 | t.getWebView().loadUrl(BrowserSettings.getInstance() |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 354 | .getHomePage()); |
| 355 | } |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 356 | originalTabIndices.put(i, getTabCount() - 1); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 357 | } else { |
| 358 | // Create a new tab and don't restore the state yet, add it |
| 359 | // to the tab list |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 360 | Tab t = new Tab(mActivity, null, false, null, null); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 361 | if (state != null) { |
| 362 | t.setSavedState(state); |
| 363 | t.populatePickerDataFromSavedState(); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 364 | // Need to maintain the app id and original url so we |
| 365 | // can possibly reuse this tab. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 366 | t.setAppId(state.getString(Tab.APPID)); |
| 367 | t.setOriginalUrl(state.getString(Tab.ORIGINALURL)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 368 | } |
| 369 | mTabs.add(t); |
Grace Kloba | f56f68d | 2010-04-11 22:53:42 -0700 | [diff] [blame] | 370 | // added the tab to the front as they are not current |
| 371 | mTabQueue.add(0, t); |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 372 | originalTabIndices.put(i, getTabCount() - 1); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 373 | } |
| 374 | } |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 375 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 376 | // Rebuild the tree of tabs. Do this after all tabs have been |
| 377 | // created/restored so that the parent tab exists. |
| 378 | for (int i = 0; i < numTabs; i++) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 379 | final Bundle b = inState.getBundle(Tab.WEBVIEW + i); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 380 | final Tab t = getTab(i); |
| 381 | if (b != null && t != null) { |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 382 | final Integer parentIndex = originalTabIndices.get(b.getInt(Tab.PARENTTAB, -1)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 383 | if (parentIndex != -1) { |
| 384 | final Tab parent = getTab(parentIndex); |
| 385 | if (parent != null) { |
| 386 | parent.addChildTab(t); |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | return true; |
| 393 | } |
| 394 | |
| 395 | /** |
Grace Kloba | f56f68d | 2010-04-11 22:53:42 -0700 | [diff] [blame] | 396 | * Free the memory in this order, 1) free the background tabs; 2) free the |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 397 | * WebView cache; |
| 398 | */ |
| 399 | void freeMemory() { |
Grace Kloba | 92c18a5 | 2009-07-31 23:48:32 -0700 | [diff] [blame] | 400 | if (getTabCount() == 0) return; |
| 401 | |
Grace Kloba | f56f68d | 2010-04-11 22:53:42 -0700 | [diff] [blame] | 402 | // free the least frequently used background tabs |
| 403 | Vector<Tab> tabs = getHalfLeastUsedTabs(getCurrentTab()); |
| 404 | if (tabs.size() > 0) { |
| 405 | Log.w(LOGTAG, "Free " + tabs.size() + " tabs in the browser"); |
| 406 | for (Tab t : tabs) { |
| 407 | // store the WebView's state. |
| 408 | t.saveState(); |
| 409 | // destroy the tab |
| 410 | t.destroy(); |
| 411 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
Derek Sollenberger | 4433d03 | 2009-06-10 15:37:21 -0400 | [diff] [blame] | 415 | // free the WebView's unused memory (this includes the cache) |
| 416 | Log.w(LOGTAG, "Free WebView's unused memory and cache"); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 417 | WebView view = getCurrentWebView(); |
| 418 | if (view != null) { |
Derek Sollenberger | 4433d03 | 2009-06-10 15:37:21 -0400 | [diff] [blame] | 419 | view.freeMemory(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 420 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Grace Kloba | f56f68d | 2010-04-11 22:53:42 -0700 | [diff] [blame] | 423 | private Vector<Tab> getHalfLeastUsedTabs(Tab current) { |
| 424 | Vector<Tab> tabsToGo = new Vector<Tab>(); |
| 425 | |
Patrick Scott | 2a67de4 | 2009-08-31 09:48:37 -0400 | [diff] [blame] | 426 | // Don't do anything if we only have 1 tab or if the current tab is |
| 427 | // null. |
| 428 | if (getTabCount() == 1 || current == null) { |
Grace Kloba | f56f68d | 2010-04-11 22:53:42 -0700 | [diff] [blame] | 429 | return tabsToGo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Grace Kloba | f56f68d | 2010-04-11 22:53:42 -0700 | [diff] [blame] | 432 | if (mTabQueue.size() == 0) { |
| 433 | return tabsToGo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Grace Kloba | f56f68d | 2010-04-11 22:53:42 -0700 | [diff] [blame] | 436 | // Rip through the queue starting at the beginning and tear down half of |
| 437 | // available tabs which are not the current tab or the parent of the |
| 438 | // current tab. |
| 439 | int openTabCount = 0; |
| 440 | for (Tab t : mTabQueue) { |
| 441 | if (t != null && t.getWebView() != null) { |
| 442 | openTabCount++; |
| 443 | if (t != current && t != current.getParentTab()) { |
| 444 | tabsToGo.add(t); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | openTabCount /= 2; |
| 450 | if (tabsToGo.size() > openTabCount) { |
| 451 | tabsToGo.setSize(openTabCount); |
| 452 | } |
| 453 | |
| 454 | return tabsToGo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 455 | } |
| 456 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 457 | /** |
| 458 | * Show the tab that contains the given WebView. |
| 459 | * @param view The WebView used to find the tab. |
| 460 | */ |
| 461 | Tab getTabFromView(WebView view) { |
| 462 | final int size = getTabCount(); |
| 463 | for (int i = 0; i < size; i++) { |
| 464 | final Tab t = getTab(i); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 465 | if (t.getSubWebView() == view || t.getWebView() == view) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 466 | return t; |
| 467 | } |
| 468 | } |
| 469 | return null; |
| 470 | } |
| 471 | |
| 472 | /** |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 473 | * Return the tab with the matching application id. |
| 474 | * @param id The application identifier. |
| 475 | */ |
| 476 | Tab getTabFromId(String id) { |
| 477 | if (id == null) { |
| 478 | return null; |
| 479 | } |
| 480 | final int size = getTabCount(); |
| 481 | for (int i = 0; i < size; i++) { |
| 482 | final Tab t = getTab(i); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 483 | if (id.equals(t.getAppId())) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 484 | return t; |
| 485 | } |
| 486 | } |
| 487 | return null; |
| 488 | } |
| 489 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 490 | /** |
| 491 | * Stop loading in all opened WebView including subWindows. |
| 492 | */ |
Grace Kloba | 5d0e02e | 2009-10-05 15:15:36 -0700 | [diff] [blame] | 493 | void stopAllLoading() { |
| 494 | final int size = getTabCount(); |
| 495 | for (int i = 0; i < size; i++) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 496 | final Tab t = getTab(i); |
| 497 | final WebView webview = t.getWebView(); |
Grace Kloba | 5d0e02e | 2009-10-05 15:15:36 -0700 | [diff] [blame] | 498 | if (webview != null) { |
| 499 | webview.stopLoading(); |
| 500 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 501 | final WebView subview = t.getSubWebView(); |
| 502 | if (subview != null) { |
| 503 | webview.stopLoading(); |
| 504 | } |
Grace Kloba | 5d0e02e | 2009-10-05 15:15:36 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 508 | // This method checks if a non-app tab (one created within the browser) |
| 509 | // matches the given url. |
| 510 | private boolean tabMatchesUrl(Tab t, String url) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 511 | if (t.getAppId() != null) { |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 512 | return false; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 513 | } |
| 514 | WebView webview = t.getWebView(); |
| 515 | if (webview == null) { |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 516 | return false; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 517 | } else if (url.equals(webview.getUrl()) |
| 518 | || url.equals(webview.getOriginalUrl())) { |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 519 | return true; |
| 520 | } |
| 521 | return false; |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Return the tab that has no app id associated with it and the url of the |
| 526 | * tab matches the given url. |
| 527 | * @param url The url to search for. |
| 528 | */ |
| 529 | Tab findUnusedTabWithUrl(String url) { |
| 530 | if (url == null) { |
| 531 | return null; |
| 532 | } |
| 533 | // Check the current tab first. |
| 534 | Tab t = getCurrentTab(); |
| 535 | if (t != null && tabMatchesUrl(t, url)) { |
| 536 | return t; |
| 537 | } |
| 538 | // Now check all the rest. |
| 539 | final int size = getTabCount(); |
| 540 | for (int i = 0; i < size; i++) { |
| 541 | t = getTab(i); |
| 542 | if (tabMatchesUrl(t, url)) { |
| 543 | return t; |
| 544 | } |
| 545 | } |
| 546 | return null; |
| 547 | } |
| 548 | |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 549 | /** |
| 550 | * Recreate the main WebView of the given tab. Returns true if the WebView |
Leon Scroggins | 6eac63e | 2010-03-15 18:19:14 -0400 | [diff] [blame] | 551 | * requires a load, whether it was due to the fact that it was deleted, or |
| 552 | * it is because it was a voice search. |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 553 | */ |
Leon Scroggins | 6eac63e | 2010-03-15 18:19:14 -0400 | [diff] [blame] | 554 | boolean recreateWebView(Tab t, BrowserActivity.UrlData urlData) { |
| 555 | final String url = urlData.mUrl; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 556 | final WebView w = t.getWebView(); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 557 | if (w != null) { |
Leon Scroggins | 4720868 | 2010-04-07 17:59:48 -0400 | [diff] [blame] | 558 | if (url != null && url.equals(t.getOriginalUrl()) |
| 559 | // Treat a voice intent as though it is a different URL, |
| 560 | // since it most likely is. |
| 561 | && urlData.mVoiceIntent == null) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 562 | // The original url matches the current url. Just go back to the |
| 563 | // first history item so we can load it faster than if we |
| 564 | // rebuilt the WebView. |
| 565 | final WebBackForwardList list = w.copyBackForwardList(); |
| 566 | if (list != null) { |
| 567 | w.goBackOrForward(-list.getCurrentIndex()); |
| 568 | w.clearHistory(); // maintains the current page. |
| 569 | return false; |
| 570 | } |
| 571 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 572 | t.destroy(); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 573 | } |
| 574 | // Create a new WebView. If this tab is the current tab, we need to put |
| 575 | // back all the clients so force it to be the current tab. |
Steve Block | 2bc6991 | 2009-07-30 14:45:13 +0100 | [diff] [blame] | 576 | t.setWebView(createNewWebView()); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 577 | if (getCurrentTab() == t) { |
| 578 | setCurrentTab(t, true); |
| 579 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 580 | // Clear the saved state and picker data |
| 581 | t.setSavedState(null); |
| 582 | t.clearPickerData(); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 583 | // Save the new url in order to avoid deleting the WebView. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 584 | t.setOriginalUrl(url); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 585 | return true; |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Creates a new WebView and registers it with the global settings. |
| 590 | */ |
| 591 | private WebView createNewWebView() { |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 592 | return createNewWebView(false); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Creates a new WebView and registers it with the global settings. |
| 597 | * @param privateBrowsing When true, enables private browsing in the new |
| 598 | * WebView. |
| 599 | */ |
| 600 | private WebView createNewWebView(boolean privateBrowsing) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 601 | // Create a new WebView |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 602 | ScrollWebView w = new ScrollWebView(mActivity, null, |
Bjorn Bringert | b1402a5 | 2010-10-12 10:53:12 +0100 | [diff] [blame] | 603 | android.R.attr.webViewStyle, privateBrowsing); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 604 | w.setScrollListener(mActivity.getScrollListener()); |
Grace Kloba | 67f0a56 | 2009-09-28 21:24:51 -0700 | [diff] [blame] | 605 | w.setScrollbarFadingEnabled(true); |
| 606 | w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 607 | w.setMapTrackballToArrowKeys(false); // use trackball directly |
The Android Open Source Project | a3c0aab | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 608 | // Enable the built-in zoom |
| 609 | w.getSettings().setBuiltInZoomControls(true); |
Michael Kolb | 6877575 | 2010-08-19 12:42:01 -0700 | [diff] [blame] | 610 | w.getSettings().setDisplayZoomControls(mDisplayZoomControls); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 611 | // Add this WebView to the settings observer list and update the |
| 612 | // settings |
| 613 | final BrowserSettings s = BrowserSettings.getInstance(); |
| 614 | s.addObserver(w.getSettings()).update(s, null); |
Mike Reed | d5a80a5 | 2009-11-12 12:49:34 -0500 | [diff] [blame] | 615 | |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 616 | return w; |
| 617 | } |
| 618 | |
| 619 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 620 | * Put the current tab in the background and set newTab as the current tab. |
| 621 | * @param newTab The new tab. If newTab is null, the current tab is not |
| 622 | * set. |
| 623 | */ |
| 624 | boolean setCurrentTab(Tab newTab) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 625 | return setCurrentTab(newTab, false); |
| 626 | } |
| 627 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 628 | void pauseCurrentTab() { |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 629 | Tab t = getCurrentTab(); |
| 630 | if (t != null) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 631 | t.pause(); |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 635 | void resumeCurrentTab() { |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 636 | Tab t = getCurrentTab(); |
| 637 | if (t != null) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 638 | t.resume(); |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 642 | /** |
| 643 | * If force is true, this method skips the check for newTab == current. |
| 644 | */ |
| 645 | private boolean setCurrentTab(Tab newTab, boolean force) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 646 | Tab current = getTab(mCurrentTab); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 647 | if (current == newTab && !force) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 648 | return true; |
| 649 | } |
| 650 | if (current != null) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 651 | current.putInBackground(); |
| 652 | mCurrentTab = -1; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 653 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 654 | if (newTab == null) { |
| 655 | return false; |
| 656 | } |
| 657 | |
| 658 | // Move the newTab to the end of the queue |
| 659 | int index = mTabQueue.indexOf(newTab); |
| 660 | if (index != -1) { |
| 661 | mTabQueue.remove(index); |
| 662 | } |
| 663 | mTabQueue.add(newTab); |
| 664 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 665 | // Display the new current tab |
| 666 | mCurrentTab = mTabs.indexOf(newTab); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 667 | WebView mainView = newTab.getWebView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 668 | boolean needRestore = (mainView == null); |
| 669 | if (needRestore) { |
| 670 | // Same work as in createNewTab() except don't do new Tab() |
Steve Block | 2bc6991 | 2009-07-30 14:45:13 +0100 | [diff] [blame] | 671 | mainView = createNewWebView(); |
| 672 | newTab.setWebView(mainView); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 673 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 674 | newTab.putInForeground(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 675 | if (needRestore) { |
| 676 | // Have to finish setCurrentTab work before calling restoreState |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 677 | if (!newTab.restoreState(newTab.getSavedState())) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 678 | mainView.loadUrl(BrowserSettings.getInstance().getHomePage()); |
| 679 | } |
| 680 | } |
| 681 | return true; |
| 682 | } |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 683 | |
| 684 | interface TabChangeListener { |
| 685 | |
| 686 | public void onNewTab(Tab tab); |
| 687 | |
| 688 | public void onRemoveTab(Tab tab); |
| 689 | |
| 690 | public void onCurrentTab(Tab tab); |
| 691 | |
| 692 | public void onProgress(Tab tab, int progress); |
| 693 | |
| 694 | public void onUrlAndTitle(Tab tab, String url, String title); |
| 695 | |
| 696 | public void onFavicon(Tab tab, Bitmap favicon); |
| 697 | |
John Reck | fb3017f | 2010-10-26 19:01:24 -0700 | [diff] [blame^] | 698 | public void onPageStarted(Tab tab, String url, Bitmap favicon); |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 699 | |
| 700 | public void onPageFinished(Tab tab); |
| 701 | |
| 702 | } |
| 703 | |
| 704 | private TabChangeListener mTabChangeListener; |
| 705 | |
| 706 | /** |
| 707 | * register the TabChangeListener with the tab control |
| 708 | * @param listener |
| 709 | */ |
| 710 | void setOnTabChangeListener(TabChangeListener listener) { |
| 711 | mTabChangeListener = listener; |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * get the current TabChangeListener (used by the tabs) |
| 716 | */ |
| 717 | TabChangeListener getTabChangeListener() { |
| 718 | return mTabChangeListener; |
| 719 | } |
| 720 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 721 | } |