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