Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 19 | import com.android.browser.Tab.LockIcon; |
| 20 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 22 | import android.content.res.Configuration; |
| 23 | import android.content.res.Resources; |
| 24 | import android.graphics.Bitmap; |
| 25 | import android.graphics.BitmapFactory; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 26 | import android.graphics.drawable.Drawable; |
| 27 | import android.os.Bundle; |
| 28 | import android.text.TextUtils; |
| 29 | import android.util.Log; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 30 | import android.view.Gravity; |
| 31 | import android.view.LayoutInflater; |
| 32 | import android.view.Menu; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 33 | import android.view.View; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 34 | import android.view.View.OnClickListener; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 35 | import android.view.View.OnKeyListener; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 36 | import android.view.ViewGroup; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 37 | import android.view.ViewGroup.LayoutParams; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 38 | import android.view.WindowManager; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 39 | import android.view.inputmethod.InputMethodManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 40 | import android.webkit.WebChromeClient; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 41 | import android.webkit.WebView; |
| 42 | import android.widget.FrameLayout; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 43 | import android.widget.ImageButton; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 44 | import android.widget.LinearLayout; |
| 45 | import android.widget.Toast; |
| 46 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 47 | import java.util.List; |
| 48 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 49 | /** |
| 50 | * UI interface definitions |
| 51 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 52 | public abstract class BaseUi implements UI, WebViewFactory { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 53 | |
| 54 | private static final String LOGTAG = "BaseUi"; |
| 55 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 56 | protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 57 | new FrameLayout.LayoutParams( |
| 58 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 59 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 60 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 61 | protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 62 | new FrameLayout.LayoutParams( |
| 63 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 64 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 65 | Gravity.CENTER); |
| 66 | |
| 67 | Activity mActivity; |
| 68 | UiController mUiController; |
| 69 | TabControl mTabControl; |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 70 | private Tab mActiveTab; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 71 | private InputMethodManager mInputManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 72 | |
| 73 | private Drawable mSecLockIcon; |
| 74 | private Drawable mMixLockIcon; |
| 75 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 76 | private FrameLayout mBrowserFrameLayout; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 77 | protected FrameLayout mContentView; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 78 | private FrameLayout mCustomViewContainer; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 79 | |
| 80 | private View mCustomView; |
| 81 | private WebChromeClient.CustomViewCallback mCustomViewCallback; |
| 82 | |
| 83 | private CombinedBookmarkHistoryView mComboView; |
| 84 | |
| 85 | private LinearLayout mErrorConsoleContainer = null; |
| 86 | |
| 87 | private Toast mStopToast; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 88 | |
| 89 | // the default <video> poster |
| 90 | private Bitmap mDefaultVideoPoster; |
| 91 | // the video progress view |
| 92 | private View mVideoProgressView; |
| 93 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 94 | private boolean mActivityPaused; |
| 95 | |
| 96 | public BaseUi(Activity browser, UiController controller) { |
| 97 | mActivity = browser; |
| 98 | mUiController = controller; |
| 99 | mTabControl = controller.getTabControl(); |
| 100 | Resources res = mActivity.getResources(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 101 | mInputManager = (InputMethodManager) |
| 102 | browser.getSystemService(Activity.INPUT_METHOD_SERVICE); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 103 | mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 104 | mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure); |
| 105 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 106 | FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() |
| 107 | .getDecorView().findViewById(android.R.id.content); |
| 108 | mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity) |
| 109 | .inflate(R.layout.custom_screen, null); |
| 110 | mContentView = (FrameLayout) mBrowserFrameLayout.findViewById( |
| 111 | R.id.main_content); |
| 112 | mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout |
| 113 | .findViewById(R.id.error_console); |
| 114 | mCustomViewContainer = (FrameLayout) mBrowserFrameLayout |
| 115 | .findViewById(R.id.fullscreen_custom_content); |
| 116 | frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 119 | /** |
| 120 | * common webview initialization |
| 121 | * @param w the webview to initialize |
| 122 | */ |
| 123 | protected void initWebViewSettings(WebView w) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 124 | w.setScrollbarFadingEnabled(true); |
| 125 | w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); |
| 126 | w.setMapTrackballToArrowKeys(false); // use trackball directly |
| 127 | // Enable the built-in zoom |
| 128 | w.getSettings().setBuiltInZoomControls(true); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 129 | |
| 130 | // Add this WebView to the settings observer list and update the |
| 131 | // settings |
| 132 | final BrowserSettings s = BrowserSettings.getInstance(); |
| 133 | s.addObserver(w.getSettings()).update(s, null); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | private void cancelStopToast() { |
| 137 | if (mStopToast != null) { |
| 138 | mStopToast.cancel(); |
| 139 | mStopToast = null; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // lifecycle |
| 144 | |
| 145 | public void onPause() { |
Michael Kolb | 7a5cf47 | 2010-11-30 13:23:53 -0800 | [diff] [blame] | 146 | if (isCustomViewShowing()) { |
| 147 | onHideCustomView(); |
| 148 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 149 | cancelStopToast(); |
| 150 | mActivityPaused = true; |
| 151 | } |
| 152 | |
| 153 | public void onResume() { |
| 154 | mActivityPaused = false; |
| 155 | } |
| 156 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 157 | protected boolean isActivityPaused() { |
| 158 | return mActivityPaused; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | public void onConfigurationChanged(Configuration config) { |
| 162 | } |
| 163 | |
| 164 | // key handling |
| 165 | |
| 166 | @Override |
| 167 | public boolean onBackKey() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 168 | if (mComboView != null) { |
| 169 | if (!mComboView.onBackPressed()) { |
| 170 | mUiController.removeComboView(); |
| 171 | } |
| 172 | return true; |
| 173 | } |
| 174 | if (mCustomView != null) { |
| 175 | mUiController.hideCustomView(); |
| 176 | return true; |
| 177 | } |
| 178 | return false; |
| 179 | } |
| 180 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 181 | // Tab callbacks |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 182 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 183 | public void onTabDataChanged(Tab tab) { |
| 184 | setUrlTitle(tab); |
| 185 | setFavicon(tab); |
| 186 | updateLockIconToLatest(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 187 | updateNavigationState(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 191 | public void bookmarkedStatusHasChanged(Tab tab) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 192 | // no op in base case |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 196 | public void onPageStopped(Tab tab) { |
| 197 | cancelStopToast(); |
| 198 | if (tab.inForeground()) { |
| 199 | mStopToast = Toast |
| 200 | .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); |
| 201 | mStopToast.show(); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 206 | public boolean needsRestoreAllTabs() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 207 | return false; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 211 | public void addTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public void setActiveTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 216 | if ((tab != mActiveTab) && (mActiveTab != null)) { |
| 217 | removeTabFromContentView(mActiveTab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 218 | } |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 219 | mActiveTab = tab; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 220 | attachTabToContentView(tab); |
| 221 | setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 222 | onTabDataChanged(tab); |
| 223 | onProgressChanged(tab); |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 224 | boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled(); |
| 225 | getEmbeddedTitleBar().setIncognitoMode(incognito); |
| 226 | getFakeTitleBar().setIncognitoMode(incognito); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 229 | Tab getActiveTab() { |
| 230 | return mActiveTab; |
| 231 | } |
| 232 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 233 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 234 | public void updateTabs(List<Tab> tabs) { |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 238 | public void removeTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 239 | if (mActiveTab == tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 240 | removeTabFromContentView(tab); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 241 | mActiveTab = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 242 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public void detachTab(Tab tab) { |
| 247 | removeTabFromContentView(tab); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void attachTab(Tab tab) { |
| 252 | attachTabToContentView(tab); |
| 253 | } |
| 254 | |
| 255 | private void attachTabToContentView(Tab tab) { |
Michael Kolb | d1e2ccc | 2011-01-24 11:38:31 -0800 | [diff] [blame] | 256 | if ((tab == null) || (tab.getWebView() == null)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | View container = tab.getViewContainer(); |
| 260 | WebView mainView = tab.getWebView(); |
| 261 | // Attach the WebView to the container and then attach the |
| 262 | // container to the content view. |
| 263 | FrameLayout wrapper = |
| 264 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 265 | ViewGroup parent = (ViewGroup) mainView.getParent(); |
| 266 | if (parent != wrapper) { |
| 267 | if (parent != null) { |
| 268 | Log.w(LOGTAG, "mMainView already has a parent in" |
| 269 | + " attachTabToContentView!"); |
| 270 | parent.removeView(mainView); |
| 271 | } |
| 272 | wrapper.addView(mainView); |
| 273 | } else { |
| 274 | Log.w(LOGTAG, "mMainView is already attached to wrapper in" |
| 275 | + " attachTabToContentView!"); |
| 276 | } |
| 277 | parent = (ViewGroup) container.getParent(); |
| 278 | if (parent != mContentView) { |
| 279 | if (parent != null) { |
| 280 | Log.w(LOGTAG, "mContainer already has a parent in" |
| 281 | + " attachTabToContentView!"); |
| 282 | parent.removeView(container); |
| 283 | } |
| 284 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 285 | } else { |
| 286 | Log.w(LOGTAG, "mContainer is already attached to content in" |
| 287 | + " attachTabToContentView!"); |
| 288 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 289 | mainView.setNextFocusUpId(R.id.url_focused); |
| 290 | mainView.setNextFocusDownId(R.id.url_focused); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 291 | mUiController.attachSubWindow(tab); |
| 292 | } |
| 293 | |
| 294 | private void removeTabFromContentView(Tab tab) { |
Michael Kolb | 20776cc | 2011-01-31 10:19:05 -0800 | [diff] [blame^] | 295 | hideFakeTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 296 | // Remove the container that contains the main WebView. |
| 297 | WebView mainView = tab.getWebView(); |
| 298 | View container = tab.getViewContainer(); |
| 299 | if (mainView == null) { |
| 300 | return; |
| 301 | } |
| 302 | // Remove the container from the content and then remove the |
| 303 | // WebView from the container. This will trigger a focus change |
| 304 | // needed by WebView. |
Michael Kolb | 20776cc | 2011-01-31 10:19:05 -0800 | [diff] [blame^] | 305 | mainView.setEmbeddedTitleBar(null); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 306 | FrameLayout wrapper = |
| 307 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 308 | wrapper.removeView(mainView); |
| 309 | mContentView.removeView(container); |
| 310 | mUiController.endActionMode(); |
| 311 | mUiController.removeSubWindow(tab); |
| 312 | ErrorConsoleView errorConsole = tab.getErrorConsole(false); |
| 313 | if (errorConsole != null) { |
| 314 | mErrorConsoleContainer.removeView(errorConsole); |
| 315 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 318 | @Override |
| 319 | public void onSetWebView(Tab tab, WebView webView) { |
| 320 | View container = tab.getViewContainer(); |
| 321 | if (container == null) { |
| 322 | // The tab consists of a container view, which contains the main |
| 323 | // WebView, as well as any other UI elements associated with the tab. |
| 324 | container = mActivity.getLayoutInflater().inflate(R.layout.tab, |
| 325 | null); |
| 326 | tab.setViewContainer(container); |
| 327 | } |
| 328 | if (tab.getWebView() != webView) { |
| 329 | // Just remove the old one. |
| 330 | FrameLayout wrapper = |
| 331 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 332 | wrapper.removeView(tab.getWebView()); |
| 333 | } |
| 334 | } |
| 335 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 336 | /** |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 337 | * create a sub window container and webview for the tab |
| 338 | * Note: this methods operates through side-effects for now |
| 339 | * it sets both the subView and subViewContainer for the given tab |
| 340 | * @param tab tab to create the sub window for |
| 341 | * @param subView webview to be set as a subwindow for the tab |
| 342 | */ |
| 343 | @Override |
| 344 | public void createSubWindow(Tab tab, WebView subView) { |
| 345 | View subViewContainer = mActivity.getLayoutInflater().inflate( |
| 346 | R.layout.browser_subwindow, null); |
| 347 | ViewGroup inner = (ViewGroup) subViewContainer |
| 348 | .findViewById(R.id.inner_container); |
| 349 | inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, |
| 350 | LayoutParams.MATCH_PARENT)); |
| 351 | final ImageButton cancel = (ImageButton) subViewContainer |
| 352 | .findViewById(R.id.subwindow_close); |
| 353 | final WebView cancelSubView = subView; |
| 354 | cancel.setOnClickListener(new OnClickListener() { |
| 355 | public void onClick(View v) { |
| 356 | cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView); |
| 357 | } |
| 358 | }); |
| 359 | tab.setSubWebView(subView); |
| 360 | tab.setSubViewContainer(subViewContainer); |
| 361 | } |
| 362 | |
| 363 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 364 | * Remove the sub window from the content view. |
| 365 | */ |
| 366 | @Override |
| 367 | public void removeSubWindow(View subviewContainer) { |
| 368 | mContentView.removeView(subviewContainer); |
| 369 | mUiController.endActionMode(); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Attach the sub window to the content view. |
| 374 | */ |
| 375 | @Override |
| 376 | public void attachSubWindow(View container) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 377 | if (container.getParent() != null) { |
| 378 | // already attached, remove first |
| 379 | ((ViewGroup) container.getParent()).removeView(container); |
| 380 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 381 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 382 | } |
| 383 | |
| 384 | void showFakeTitleBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 385 | if (!isFakeTitleBarShowing() && !isActivityPaused()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 386 | WebView mainView = mUiController.getCurrentWebView(); |
| 387 | // if there is no current WebView, don't show the faked title bar; |
| 388 | if (mainView == null) { |
| 389 | return; |
| 390 | } |
| 391 | // Do not need to check for null, since the current tab will have |
| 392 | // at least a main WebView, or we would have returned above. |
| 393 | if (mUiController.isInCustomActionMode()) { |
| 394 | // Do not show the fake title bar, while a custom ActionMode |
| 395 | // (i.e. find or select) is showing. |
| 396 | return; |
| 397 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 398 | attachFakeTitleBar(mainView); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 402 | protected abstract void attachFakeTitleBar(WebView mainView); |
| 403 | |
| 404 | protected abstract void hideFakeTitleBar(); |
| 405 | |
| 406 | protected abstract boolean isFakeTitleBarShowing(); |
| 407 | |
| 408 | protected abstract TitleBarBase getFakeTitleBar(); |
| 409 | |
| 410 | protected abstract TitleBarBase getEmbeddedTitleBar(); |
| 411 | |
| 412 | @Override |
| 413 | public void showVoiceTitleBar(String title) { |
| 414 | getEmbeddedTitleBar().setInVoiceMode(true); |
| 415 | getEmbeddedTitleBar().setDisplayTitle(title); |
| 416 | getFakeTitleBar().setInVoiceMode(true); |
| 417 | getFakeTitleBar().setDisplayTitle(title); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 420 | @Override |
| 421 | public void revertVoiceTitleBar(Tab tab) { |
| 422 | getEmbeddedTitleBar().setInVoiceMode(false); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 423 | String url = tab.getUrl(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 424 | getEmbeddedTitleBar().setDisplayTitle(url); |
| 425 | getFakeTitleBar().setInVoiceMode(false); |
| 426 | getFakeTitleBar().setDisplayTitle(url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public void showComboView(boolean startWithHistory, Bundle extras) { |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 431 | if (mComboView != null) { |
| 432 | return; |
| 433 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 434 | mComboView = new CombinedBookmarkHistoryView(mActivity, |
| 435 | mUiController, |
| 436 | startWithHistory ? |
| 437 | CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY |
| 438 | : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS, |
| 439 | extras); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 440 | FrameLayout wrapper = |
| 441 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 442 | wrapper.setVisibility(View.GONE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 443 | hideFakeTitleBar(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 444 | dismissIME(); |
| 445 | if (mActiveTab != null) { |
| 446 | WebView web = mActiveTab.getWebView(); |
| 447 | mActiveTab.putInBackground(); |
| 448 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 449 | mContentView.addView(mComboView, COVER_SCREEN_PARAMS); |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * dismiss the ComboPage |
| 454 | */ |
| 455 | @Override |
| 456 | public void hideComboView() { |
| 457 | if (mComboView != null) { |
| 458 | mContentView.removeView(mComboView); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 459 | FrameLayout wrapper = |
| 460 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 461 | wrapper.setVisibility(View.VISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 462 | mComboView = null; |
| 463 | } |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 464 | if (mActiveTab != null) { |
| 465 | mActiveTab.putInForeground(); |
| 466 | } |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 467 | mActivity.invalidateOptionsMenu(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | @Override |
| 471 | public void showCustomView(View view, |
| 472 | WebChromeClient.CustomViewCallback callback) { |
| 473 | // if a view already exists then immediately terminate the new one |
| 474 | if (mCustomView != null) { |
| 475 | callback.onCustomViewHidden(); |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | // Add the custom view to its container. |
| 480 | mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); |
| 481 | mCustomView = view; |
| 482 | mCustomViewCallback = callback; |
| 483 | // Hide the content view. |
| 484 | mContentView.setVisibility(View.GONE); |
| 485 | // Finally show the custom view container. |
| 486 | setStatusBarVisibility(false); |
| 487 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 488 | mCustomViewContainer.bringToFront(); |
| 489 | } |
| 490 | |
| 491 | @Override |
| 492 | public void onHideCustomView() { |
| 493 | if (mCustomView == null) |
| 494 | return; |
| 495 | |
| 496 | // Hide the custom view. |
| 497 | mCustomView.setVisibility(View.GONE); |
| 498 | // Remove the custom view from its container. |
| 499 | mCustomViewContainer.removeView(mCustomView); |
| 500 | mCustomView = null; |
| 501 | mCustomViewContainer.setVisibility(View.GONE); |
| 502 | mCustomViewCallback.onCustomViewHidden(); |
| 503 | // Show the content view. |
| 504 | setStatusBarVisibility(true); |
| 505 | mContentView.setVisibility(View.VISIBLE); |
| 506 | } |
| 507 | |
| 508 | @Override |
| 509 | public boolean isCustomViewShowing() { |
| 510 | return mCustomView != null; |
| 511 | } |
| 512 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 513 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 514 | if (mInputManager.isActive()) { |
| 515 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 516 | 0); |
| 517 | } |
| 518 | } |
| 519 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 520 | @Override |
| 521 | public boolean showsWeb() { |
| 522 | return mCustomView == null |
| 523 | && mComboView == null; |
| 524 | } |
| 525 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 526 | // ------------------------------------------------------------------------- |
| 527 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 528 | protected void updateNavigationState(Tab tab) { |
| 529 | } |
| 530 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 531 | /** |
| 532 | * Update the lock icon to correspond to our latest state. |
| 533 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 534 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 535 | if (t != null && t.inForeground()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 536 | updateLockIconImage(t.getLockIconType()); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 541 | * Updates the lock-icon image in the title-bar. |
| 542 | */ |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 543 | private void updateLockIconImage(LockIcon lockIconType) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 544 | Drawable d = null; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 545 | if (lockIconType == LockIcon.LOCK_ICON_SECURE) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 546 | d = mSecLockIcon; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 547 | } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 548 | d = mMixLockIcon; |
| 549 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 550 | getEmbeddedTitleBar().setLock(d); |
| 551 | getFakeTitleBar().setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 552 | } |
| 553 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 554 | protected void setUrlTitle(Tab tab) { |
| 555 | String url = tab.getUrl(); |
| 556 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 557 | if (TextUtils.isEmpty(title)) { |
| 558 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 559 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 560 | if (tab.isInVoiceSearchMode()) return; |
| 561 | if (tab.inForeground()) { |
| 562 | getEmbeddedTitleBar().setDisplayTitle(url); |
| 563 | getFakeTitleBar().setDisplayTitle(url); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 568 | protected void setFavicon(Tab tab) { |
| 569 | if (tab.inForeground()) { |
| 570 | Bitmap icon = tab.getFavicon(); |
| 571 | getEmbeddedTitleBar().setFavicon(icon); |
| 572 | getFakeTitleBar().setFavicon(icon); |
| 573 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | @Override |
| 577 | public void onActionModeFinished(boolean inLoad) { |
| 578 | if (inLoad) { |
| 579 | // the titlebar was removed when the CAB was shown |
| 580 | // if the page is loading, show it again |
| 581 | showFakeTitleBar(); |
| 582 | } |
| 583 | } |
| 584 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 585 | // active tabs page |
| 586 | |
| 587 | public void showActiveTabsPage() { |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Remove the active tabs page. |
| 592 | */ |
| 593 | public void removeActiveTabsPage() { |
| 594 | } |
| 595 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 596 | // menu handling callbacks |
| 597 | |
| 598 | @Override |
| 599 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | @Override |
| 603 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | @Override |
| 615 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | @Override |
| 619 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | // error console |
| 623 | |
| 624 | @Override |
| 625 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
| 626 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 627 | if (flag) { |
| 628 | // Setting the show state of the console will cause it's the layout |
| 629 | // to be inflated. |
| 630 | if (errorConsole.numberOfErrors() > 0) { |
| 631 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 632 | } else { |
| 633 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 634 | } |
| 635 | if (errorConsole.getParent() != null) { |
| 636 | mErrorConsoleContainer.removeView(errorConsole); |
| 637 | } |
| 638 | // Now we can add it to the main view. |
| 639 | mErrorConsoleContainer.addView(errorConsole, |
| 640 | new LinearLayout.LayoutParams( |
| 641 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 642 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 643 | } else { |
| 644 | mErrorConsoleContainer.removeView(errorConsole); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | private void setStatusBarVisibility(boolean visible) { |
Joe Onorato | d3bf86f | 2011-01-25 20:07:10 -0800 | [diff] [blame] | 649 | WindowManager.LayoutParams params = mActivity.getWindow().getAttributes(); |
| 650 | params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN; |
| 651 | mActivity.getWindow().setAttributes(params); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 654 | // ------------------------------------------------------------------------- |
| 655 | // Helper function for WebChromeClient |
| 656 | // ------------------------------------------------------------------------- |
| 657 | |
| 658 | @Override |
| 659 | public Bitmap getDefaultVideoPoster() { |
| 660 | if (mDefaultVideoPoster == null) { |
| 661 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 662 | mActivity.getResources(), R.drawable.default_video_poster); |
| 663 | } |
| 664 | return mDefaultVideoPoster; |
| 665 | } |
| 666 | |
| 667 | @Override |
| 668 | public View getVideoLoadingProgressView() { |
| 669 | if (mVideoProgressView == null) { |
| 670 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 671 | mVideoProgressView = inflater.inflate( |
| 672 | R.layout.video_loading_progress, null); |
| 673 | } |
| 674 | return mVideoProgressView; |
| 675 | } |
| 676 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 677 | @Override |
| 678 | public void showMaxTabsWarning() { |
| 679 | Toast warning = Toast.makeText(mActivity, |
| 680 | mActivity.getString(R.string.max_tabs_warning), |
| 681 | Toast.LENGTH_SHORT); |
| 682 | warning.show(); |
| 683 | } |
| 684 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 685 | } |