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