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