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