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