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 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 20 | import android.content.Context; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 21 | import android.content.Intent; |
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 | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 26 | import android.graphics.Color; |
| 27 | import android.graphics.drawable.BitmapDrawable; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 29 | import android.graphics.drawable.LayerDrawable; |
| 30 | import android.graphics.drawable.PaintDrawable; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 32 | import android.os.Handler; |
| 33 | import android.os.Message; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 34 | import android.text.TextUtils; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 35 | import android.view.Gravity; |
| 36 | import android.view.LayoutInflater; |
| 37 | import android.view.Menu; |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 38 | import android.view.MenuItem; |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 39 | import android.view.MotionEvent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 40 | import android.view.View; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 41 | import android.view.View.OnClickListener; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 42 | import android.view.ViewGroup; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 43 | import android.view.ViewGroup.LayoutParams; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 44 | import android.view.Window; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 45 | import android.view.WindowManager; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 46 | import android.view.inputmethod.InputMethodManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 47 | import android.webkit.WebChromeClient; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 48 | import android.webkit.WebView; |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame] | 49 | import android.webkit.WebViewClassic; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 50 | import android.widget.FrameLayout; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 51 | import android.widget.ImageButton; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 52 | import android.widget.LinearLayout; |
| 53 | import android.widget.Toast; |
| 54 | |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 55 | import com.android.browser.Tab.SecurityState; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 56 | import com.android.internal.view.menu.MenuBuilder; |
| 57 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 58 | import java.util.List; |
| 59 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 60 | /** |
| 61 | * UI interface definitions |
| 62 | */ |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 63 | public abstract class BaseUi implements UI { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 64 | |
| 65 | private static final String LOGTAG = "BaseUi"; |
| 66 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 67 | protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 68 | new FrameLayout.LayoutParams( |
| 69 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 70 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 71 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 72 | protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 73 | new FrameLayout.LayoutParams( |
| 74 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 75 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 76 | Gravity.CENTER); |
| 77 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 78 | private static final int MSG_HIDE_TITLEBAR = 1; |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 79 | public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 80 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 81 | Activity mActivity; |
| 82 | UiController mUiController; |
| 83 | TabControl mTabControl; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 84 | protected Tab mActiveTab; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 85 | private InputMethodManager mInputManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 86 | |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 87 | private Drawable mLockIconSecure; |
| 88 | private Drawable mLockIconMixed; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 89 | protected Drawable mGenericFavicon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 90 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 91 | protected FrameLayout mContentView; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 92 | protected FrameLayout mCustomViewContainer; |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 93 | protected FrameLayout mFullscreenContainer; |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 94 | private FrameLayout mFixedTitlebarContainer; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 95 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 96 | private View mCustomView; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 97 | private WebChromeClient.CustomViewCallback mCustomViewCallback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 98 | private int mOriginalOrientation; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 99 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 100 | private LinearLayout mErrorConsoleContainer = null; |
| 101 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 102 | private UrlBarAutoShowManager mUrlBarAutoShowManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 103 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 104 | private Toast mStopToast; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 105 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 106 | // the default <video> poster |
| 107 | private Bitmap mDefaultVideoPoster; |
| 108 | // the video progress view |
| 109 | private View mVideoProgressView; |
| 110 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 111 | private boolean mActivityPaused; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 112 | protected boolean mUseQuickControls; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 113 | protected TitleBar mTitleBar; |
| 114 | private NavigationBarBase mNavigationBar; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 115 | protected PieControl mPieControl; |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 116 | private boolean mBlockFocusAnimations; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 117 | |
| 118 | public BaseUi(Activity browser, UiController controller) { |
| 119 | mActivity = browser; |
| 120 | mUiController = controller; |
| 121 | mTabControl = controller.getTabControl(); |
| 122 | Resources res = mActivity.getResources(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 123 | mInputManager = (InputMethodManager) |
| 124 | browser.getSystemService(Activity.INPUT_METHOD_SERVICE); |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 125 | mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark); |
| 126 | mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 127 | FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() |
| 128 | .getDecorView().findViewById(android.R.id.content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 129 | LayoutInflater.from(mActivity) |
| 130 | .inflate(R.layout.custom_screen, frameLayout); |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 131 | mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById( |
| 132 | R.id.fixed_titlebar_container); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 133 | mContentView = (FrameLayout) frameLayout.findViewById( |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 134 | R.id.main_content); |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 135 | mCustomViewContainer = (FrameLayout) frameLayout.findViewById( |
| 136 | R.id.fullscreen_custom_content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 137 | mErrorConsoleContainer = (LinearLayout) frameLayout |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 138 | .findViewById(R.id.error_console); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 139 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 140 | mGenericFavicon = res.getDrawable( |
| 141 | R.drawable.app_web_browser_sm); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 142 | mTitleBar = new TitleBar(mActivity, mUiController, this, |
| 143 | mContentView); |
| 144 | mTitleBar.setProgress(100); |
| 145 | mNavigationBar = mTitleBar.getNavigationBar(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 146 | mUrlBarAutoShowManager = new UrlBarAutoShowManager(this); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 149 | private void cancelStopToast() { |
| 150 | if (mStopToast != null) { |
| 151 | mStopToast.cancel(); |
| 152 | mStopToast = null; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // lifecycle |
| 157 | |
| 158 | public void onPause() { |
Michael Kolb | 7a5cf47 | 2010-11-30 13:23:53 -0800 | [diff] [blame] | 159 | if (isCustomViewShowing()) { |
| 160 | onHideCustomView(); |
| 161 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 162 | cancelStopToast(); |
| 163 | mActivityPaused = true; |
| 164 | } |
| 165 | |
| 166 | public void onResume() { |
| 167 | mActivityPaused = false; |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 168 | // check if we exited without setting active tab |
| 169 | // b: 5188145 |
Michael Kolb | 1a4625a | 2011-08-24 13:40:44 -0700 | [diff] [blame] | 170 | final Tab ct = mTabControl.getCurrentTab(); |
| 171 | if (ct != null) { |
| 172 | setActiveTab(ct); |
| 173 | } |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 174 | mTitleBar.onResume(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 177 | protected boolean isActivityPaused() { |
| 178 | return mActivityPaused; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | public void onConfigurationChanged(Configuration config) { |
| 182 | } |
| 183 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 184 | public Activity getActivity() { |
| 185 | return mActivity; |
| 186 | } |
| 187 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 188 | // key handling |
| 189 | |
| 190 | @Override |
| 191 | public boolean onBackKey() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 192 | if (mCustomView != null) { |
| 193 | mUiController.hideCustomView(); |
| 194 | return true; |
| 195 | } |
| 196 | return false; |
| 197 | } |
| 198 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 199 | @Override |
| 200 | public boolean onMenuKey() { |
| 201 | return false; |
| 202 | } |
| 203 | |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 204 | @Override |
| 205 | public void setUseQuickControls(boolean useQuickControls) { |
| 206 | mUseQuickControls = useQuickControls; |
| 207 | mTitleBar.setUseQuickControls(mUseQuickControls); |
| 208 | if (useQuickControls) { |
| 209 | mPieControl = new PieControl(mActivity, mUiController, this); |
| 210 | mPieControl.attachToContainer(mContentView); |
| 211 | } else { |
| 212 | if (mPieControl != null) { |
| 213 | mPieControl.removeFromContainer(mContentView); |
| 214 | } |
| 215 | } |
| 216 | updateUrlBarAutoShowManagerTarget(); |
| 217 | } |
| 218 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 219 | // Tab callbacks |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 220 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 221 | public void onTabDataChanged(Tab tab) { |
| 222 | setUrlTitle(tab); |
| 223 | setFavicon(tab); |
| 224 | updateLockIconToLatest(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 225 | updateNavigationState(tab); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 226 | mTitleBar.onTabDataChanged(tab); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 227 | mNavigationBar.onTabDataChanged(tab); |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 228 | onProgressChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Override |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 232 | public void onProgressChanged(Tab tab) { |
| 233 | int progress = tab.getLoadProgress(); |
| 234 | if (tab.inForeground()) { |
| 235 | mTitleBar.setProgress(progress); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 240 | public void bookmarkedStatusHasChanged(Tab tab) { |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 241 | if (tab.inForeground()) { |
| 242 | boolean isBookmark = tab.isBookmarkedSite(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 243 | mNavigationBar.setCurrentUrlIsBookmark(isBookmark); |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 244 | } |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 248 | public void onPageStopped(Tab tab) { |
| 249 | cancelStopToast(); |
| 250 | if (tab.inForeground()) { |
| 251 | mStopToast = Toast |
| 252 | .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); |
| 253 | mStopToast.show(); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 258 | public boolean needsRestoreAllTabs() { |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 259 | return true; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 263 | public void addTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 267 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 7ac63b6 | 2011-12-16 09:52:29 -0800 | [diff] [blame] | 268 | if (tab == null) return; |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 269 | // block unnecessary focus change animations during tab switch |
| 270 | mBlockFocusAnimations = true; |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 271 | mHandler.removeMessages(MSG_HIDE_TITLEBAR); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 272 | if ((tab != mActiveTab) && (mActiveTab != null)) { |
| 273 | removeTabFromContentView(mActiveTab); |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 274 | WebView web = mActiveTab.getWebView(); |
| 275 | if (web != null) { |
| 276 | web.setOnTouchListener(null); |
| 277 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 278 | } |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 279 | mActiveTab = tab; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 280 | BrowserWebView web = (BrowserWebView) mActiveTab.getWebView(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 281 | updateUrlBarAutoShowManagerTarget(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 282 | attachTabToContentView(tab); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 283 | if (web != null) { |
| 284 | // Request focus on the top window. |
| 285 | if (mUseQuickControls) { |
| 286 | mPieControl.forceToTop(mContentView); |
| 287 | web.setTitleBar(null); |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 288 | mTitleBar.hide(); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 289 | } else { |
| 290 | web.setTitleBar(mTitleBar); |
| 291 | mTitleBar.onScrollChanged(); |
| 292 | } |
| 293 | } |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 294 | mTitleBar.bringToFront(); |
Michael Kolb | f896352 | 2012-04-10 10:52:34 -0700 | [diff] [blame] | 295 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 296 | setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 297 | onTabDataChanged(tab); |
| 298 | onProgressChanged(tab); |
Michael Kolb | 03b6bc6 | 2011-09-02 16:19:53 -0700 | [diff] [blame] | 299 | mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled()); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 300 | updateAutoLogin(tab, false); |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 301 | mBlockFocusAnimations = false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 302 | } |
| 303 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 304 | protected void updateUrlBarAutoShowManagerTarget() { |
| 305 | WebView web = mActiveTab != null ? mActiveTab.getWebView() : null; |
| 306 | if (!mUseQuickControls && web instanceof BrowserWebView) { |
| 307 | mUrlBarAutoShowManager.setTarget((BrowserWebView) web); |
| 308 | } else { |
| 309 | mUrlBarAutoShowManager.setTarget(null); |
| 310 | } |
| 311 | } |
| 312 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 313 | Tab getActiveTab() { |
| 314 | return mActiveTab; |
| 315 | } |
| 316 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 317 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 318 | public void updateTabs(List<Tab> tabs) { |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 322 | public void removeTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 323 | if (mActiveTab == tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 324 | removeTabFromContentView(tab); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 325 | mActiveTab = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 326 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public void detachTab(Tab tab) { |
| 331 | removeTabFromContentView(tab); |
| 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public void attachTab(Tab tab) { |
| 336 | attachTabToContentView(tab); |
| 337 | } |
| 338 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 339 | protected void attachTabToContentView(Tab tab) { |
Michael Kolb | d1e2ccc | 2011-01-24 11:38:31 -0800 | [diff] [blame] | 340 | if ((tab == null) || (tab.getWebView() == null)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 341 | return; |
| 342 | } |
| 343 | View container = tab.getViewContainer(); |
| 344 | WebView mainView = tab.getWebView(); |
| 345 | // Attach the WebView to the container and then attach the |
| 346 | // container to the content view. |
| 347 | FrameLayout wrapper = |
| 348 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 349 | ViewGroup parent = (ViewGroup) mainView.getParent(); |
| 350 | if (parent != wrapper) { |
| 351 | if (parent != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 352 | parent.removeView(mainView); |
| 353 | } |
| 354 | wrapper.addView(mainView); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 355 | } |
| 356 | parent = (ViewGroup) container.getParent(); |
| 357 | if (parent != mContentView) { |
| 358 | if (parent != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 359 | parent.removeView(container); |
| 360 | } |
| 361 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 362 | } |
| 363 | mUiController.attachSubWindow(tab); |
| 364 | } |
| 365 | |
| 366 | private void removeTabFromContentView(Tab tab) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 367 | hideTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 368 | // Remove the container that contains the main WebView. |
| 369 | WebView mainView = tab.getWebView(); |
| 370 | View container = tab.getViewContainer(); |
| 371 | if (mainView == null) { |
| 372 | return; |
| 373 | } |
| 374 | // Remove the container from the content and then remove the |
| 375 | // WebView from the container. This will trigger a focus change |
| 376 | // needed by WebView. |
| 377 | FrameLayout wrapper = |
| 378 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 379 | wrapper.removeView(mainView); |
| 380 | mContentView.removeView(container); |
| 381 | mUiController.endActionMode(); |
| 382 | mUiController.removeSubWindow(tab); |
| 383 | ErrorConsoleView errorConsole = tab.getErrorConsole(false); |
| 384 | if (errorConsole != null) { |
| 385 | mErrorConsoleContainer.removeView(errorConsole); |
| 386 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 389 | @Override |
| 390 | public void onSetWebView(Tab tab, WebView webView) { |
| 391 | View container = tab.getViewContainer(); |
| 392 | if (container == null) { |
| 393 | // The tab consists of a container view, which contains the main |
| 394 | // WebView, as well as any other UI elements associated with the tab. |
| 395 | container = mActivity.getLayoutInflater().inflate(R.layout.tab, |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 396 | mContentView, false); |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 397 | tab.setViewContainer(container); |
| 398 | } |
| 399 | if (tab.getWebView() != webView) { |
| 400 | // Just remove the old one. |
| 401 | FrameLayout wrapper = |
| 402 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 403 | wrapper.removeView(tab.getWebView()); |
| 404 | } |
| 405 | } |
| 406 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 407 | /** |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 408 | * create a sub window container and webview for the tab |
| 409 | * Note: this methods operates through side-effects for now |
| 410 | * it sets both the subView and subViewContainer for the given tab |
| 411 | * @param tab tab to create the sub window for |
| 412 | * @param subView webview to be set as a subwindow for the tab |
| 413 | */ |
| 414 | @Override |
| 415 | public void createSubWindow(Tab tab, WebView subView) { |
| 416 | View subViewContainer = mActivity.getLayoutInflater().inflate( |
| 417 | R.layout.browser_subwindow, null); |
| 418 | ViewGroup inner = (ViewGroup) subViewContainer |
| 419 | .findViewById(R.id.inner_container); |
| 420 | inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, |
| 421 | LayoutParams.MATCH_PARENT)); |
| 422 | final ImageButton cancel = (ImageButton) subViewContainer |
| 423 | .findViewById(R.id.subwindow_close); |
| 424 | final WebView cancelSubView = subView; |
| 425 | cancel.setOnClickListener(new OnClickListener() { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 426 | @Override |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 427 | public void onClick(View v) { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 428 | ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView); |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 429 | } |
| 430 | }); |
| 431 | tab.setSubWebView(subView); |
| 432 | tab.setSubViewContainer(subViewContainer); |
| 433 | } |
| 434 | |
| 435 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 436 | * Remove the sub window from the content view. |
| 437 | */ |
| 438 | @Override |
| 439 | public void removeSubWindow(View subviewContainer) { |
| 440 | mContentView.removeView(subviewContainer); |
| 441 | mUiController.endActionMode(); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Attach the sub window to the content view. |
| 446 | */ |
| 447 | @Override |
| 448 | public void attachSubWindow(View container) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 449 | if (container.getParent() != null) { |
| 450 | // already attached, remove first |
| 451 | ((ViewGroup) container.getParent()).removeView(container); |
| 452 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 453 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 454 | } |
| 455 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 456 | protected void refreshWebView() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 457 | WebView web = getWebView(); |
| 458 | if (web != null) { |
| 459 | web.invalidate(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 463 | public void editUrl(boolean clearInput, boolean forceIME) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 464 | if (mUiController.isInCustomActionMode()) { |
| 465 | mUiController.endActionMode(); |
| 466 | } |
| 467 | showTitleBar(); |
Michael Kolb | ace2ff8 | 2011-08-12 13:36:07 -0700 | [diff] [blame] | 468 | if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 469 | mNavigationBar.startEditingUrl(clearInput, forceIME); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 470 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 473 | boolean canShowTitleBar() { |
| 474 | return !isTitleBarShowing() |
| 475 | && !isActivityPaused() |
| 476 | && (getActiveTab() != null) |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 477 | && (getWebView() != null) |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 478 | && !mUiController.isInCustomActionMode(); |
| 479 | } |
| 480 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 481 | protected void showTitleBar() { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 482 | mHandler.removeMessages(MSG_HIDE_TITLEBAR); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 483 | if (canShowTitleBar()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 484 | mTitleBar.show(); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 485 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | protected void hideTitleBar() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 489 | if (mTitleBar.isShowing()) { |
| 490 | mTitleBar.hide(); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 491 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | protected boolean isTitleBarShowing() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 495 | return mTitleBar.isShowing(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 496 | } |
| 497 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 498 | public boolean isEditingUrl() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 499 | return mTitleBar.isEditingUrl(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Michael Kolb | 80f7508 | 2012-04-10 10:50:06 -0700 | [diff] [blame] | 502 | public void stopEditingUrl() { |
| 503 | mTitleBar.getNavigationBar().stopEditingUrl(); |
| 504 | } |
| 505 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 506 | public TitleBar getTitleBar() { |
| 507 | return mTitleBar; |
| 508 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 509 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 510 | @Override |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 511 | public void showComboView(ComboViews startingView, Bundle extras) { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 512 | Intent intent = new Intent(mActivity, ComboViewActivity.class); |
| 513 | intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name()); |
| 514 | intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras); |
| 515 | Tab t = getActiveTab(); |
| 516 | if (t != null) { |
| 517 | intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl()); |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 518 | } |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 519 | mActivity.startActivityForResult(intent, Controller.COMBO_VIEW); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | @Override |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 523 | public void showCustomView(View view, int requestedOrientation, |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 524 | WebChromeClient.CustomViewCallback callback) { |
| 525 | // if a view already exists then immediately terminate the new one |
| 526 | if (mCustomView != null) { |
| 527 | callback.onCustomViewHidden(); |
| 528 | return; |
| 529 | } |
| 530 | |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 531 | mOriginalOrientation = mActivity.getRequestedOrientation(); |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 532 | FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); |
| 533 | mFullscreenContainer = new FullscreenHolder(mActivity); |
| 534 | mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS); |
| 535 | decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS); |
| 536 | mCustomView = view; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 537 | setFullscreen(true); |
Michael Kolb | 54217b3 | 2012-05-15 13:24:24 -0700 | [diff] [blame] | 538 | ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 539 | mCustomViewCallback = callback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 540 | mActivity.setRequestedOrientation(requestedOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | @Override |
| 544 | public void onHideCustomView() { |
Michael Kolb | 54217b3 | 2012-05-15 13:24:24 -0700 | [diff] [blame] | 545 | ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 546 | if (mCustomView == null) |
| 547 | return; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 548 | setFullscreen(false); |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 549 | FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); |
| 550 | decor.removeView(mFullscreenContainer); |
| 551 | mFullscreenContainer = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 552 | mCustomView = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 553 | mCustomViewCallback.onCustomViewHidden(); |
| 554 | // Show the content view. |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 555 | mActivity.setRequestedOrientation(mOriginalOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public boolean isCustomViewShowing() { |
| 560 | return mCustomView != null; |
| 561 | } |
| 562 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 563 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 564 | if (mInputManager.isActive()) { |
| 565 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 566 | 0); |
| 567 | } |
| 568 | } |
| 569 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 570 | @Override |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 571 | public boolean isWebShowing() { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 572 | return mCustomView == null; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 575 | @Override |
| 576 | public void showAutoLogin(Tab tab) { |
| 577 | updateAutoLogin(tab, true); |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public void hideAutoLogin(Tab tab) { |
| 582 | updateAutoLogin(tab, true); |
| 583 | } |
| 584 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 585 | // ------------------------------------------------------------------------- |
| 586 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 587 | protected void updateNavigationState(Tab tab) { |
| 588 | } |
| 589 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 590 | protected void updateAutoLogin(Tab tab, boolean animate) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 591 | mTitleBar.updateAutoLogin(tab, animate); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 592 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 593 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 594 | /** |
| 595 | * Update the lock icon to correspond to our latest state. |
| 596 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 597 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 598 | if (t != null && t.inForeground()) { |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 599 | updateLockIconImage(t.getSecurityState()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
| 603 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 604 | * Updates the lock-icon image in the title-bar. |
| 605 | */ |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 606 | private void updateLockIconImage(SecurityState securityState) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 607 | Drawable d = null; |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 608 | if (securityState == SecurityState.SECURITY_STATE_SECURE) { |
| 609 | d = mLockIconSecure; |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 610 | } else if (securityState == SecurityState.SECURITY_STATE_MIXED |
| 611 | || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) { |
| 612 | // TODO: It would be good to have different icons for insecure vs mixed content. |
| 613 | // See http://b/5403800 |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 614 | d = mLockIconMixed; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 615 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 616 | mNavigationBar.setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 617 | } |
| 618 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 619 | protected void setUrlTitle(Tab tab) { |
| 620 | String url = tab.getUrl(); |
| 621 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 622 | if (TextUtils.isEmpty(title)) { |
| 623 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 624 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 625 | if (tab.inForeground()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 626 | mNavigationBar.setDisplayTitle(url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
| 630 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 631 | protected void setFavicon(Tab tab) { |
| 632 | if (tab.inForeground()) { |
| 633 | Bitmap icon = tab.getFavicon(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 634 | mNavigationBar.setFavicon(icon); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 635 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | @Override |
| 639 | public void onActionModeFinished(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 642 | // active tabs page |
| 643 | |
| 644 | public void showActiveTabsPage() { |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Remove the active tabs page. |
| 649 | */ |
| 650 | public void removeActiveTabsPage() { |
| 651 | } |
| 652 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 653 | // menu handling callbacks |
| 654 | |
| 655 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 656 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 657 | return true; |
| 658 | } |
| 659 | |
| 660 | @Override |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 661 | public void updateMenuState(Tab tab, Menu menu) { |
| 662 | } |
| 663 | |
| 664 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 665 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | @Override |
| 669 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 673 | public boolean onOptionsItemSelected(MenuItem item) { |
| 674 | return false; |
| 675 | } |
| 676 | |
| 677 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 678 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | @Override |
| 682 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | @Override |
| 686 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | @Override |
| 690 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // error console |
| 694 | |
| 695 | @Override |
| 696 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
Michael Kolb | 9fcefd1 | 2011-02-17 10:55:59 -0800 | [diff] [blame] | 697 | if (tab == null) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 698 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 699 | if (flag) { |
| 700 | // Setting the show state of the console will cause it's the layout |
| 701 | // to be inflated. |
| 702 | if (errorConsole.numberOfErrors() > 0) { |
| 703 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 704 | } else { |
| 705 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 706 | } |
| 707 | if (errorConsole.getParent() != null) { |
| 708 | mErrorConsoleContainer.removeView(errorConsole); |
| 709 | } |
| 710 | // Now we can add it to the main view. |
| 711 | mErrorConsoleContainer.addView(errorConsole, |
| 712 | new LinearLayout.LayoutParams( |
| 713 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 714 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 715 | } else { |
| 716 | mErrorConsoleContainer.removeView(errorConsole); |
| 717 | } |
| 718 | } |
| 719 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 720 | // ------------------------------------------------------------------------- |
| 721 | // Helper function for WebChromeClient |
| 722 | // ------------------------------------------------------------------------- |
| 723 | |
| 724 | @Override |
| 725 | public Bitmap getDefaultVideoPoster() { |
| 726 | if (mDefaultVideoPoster == null) { |
| 727 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 728 | mActivity.getResources(), R.drawable.default_video_poster); |
| 729 | } |
| 730 | return mDefaultVideoPoster; |
| 731 | } |
| 732 | |
| 733 | @Override |
| 734 | public View getVideoLoadingProgressView() { |
| 735 | if (mVideoProgressView == null) { |
| 736 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 737 | mVideoProgressView = inflater.inflate( |
| 738 | R.layout.video_loading_progress, null); |
| 739 | } |
| 740 | return mVideoProgressView; |
| 741 | } |
| 742 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 743 | @Override |
| 744 | public void showMaxTabsWarning() { |
| 745 | Toast warning = Toast.makeText(mActivity, |
| 746 | mActivity.getString(R.string.max_tabs_warning), |
| 747 | Toast.LENGTH_SHORT); |
| 748 | warning.show(); |
| 749 | } |
| 750 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 751 | protected WebView getWebView() { |
| 752 | if (mActiveTab != null) { |
| 753 | return mActiveTab.getWebView(); |
| 754 | } else { |
| 755 | return null; |
| 756 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Michael Kolb | fedb492 | 2011-04-20 16:45:33 -0700 | [diff] [blame] | 759 | protected Menu getMenu() { |
| 760 | MenuBuilder menu = new MenuBuilder(mActivity); |
| 761 | mActivity.getMenuInflater().inflate(R.menu.browser, menu); |
| 762 | return menu; |
| 763 | } |
| 764 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 765 | public void setFullscreen(boolean enabled) { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 766 | Window win = mActivity.getWindow(); |
| 767 | WindowManager.LayoutParams winParams = win.getAttributes(); |
Michael Kolb | 76dff39 | 2011-12-06 09:51:18 -0800 | [diff] [blame] | 768 | final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 769 | if (enabled) { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 770 | winParams.flags |= bits; |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 771 | } else { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 772 | winParams.flags &= ~bits; |
| 773 | if (mCustomView != null) { |
| 774 | mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); |
| 775 | } else { |
| 776 | mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); |
| 777 | } |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 778 | } |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 779 | win.setAttributes(winParams); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 780 | } |
| 781 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 782 | public Drawable getFaviconDrawable(Bitmap icon) { |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 783 | Drawable[] array = new Drawable[3]; |
| 784 | array[0] = new PaintDrawable(Color.BLACK); |
| 785 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 786 | array[1] = p; |
| 787 | if (icon == null) { |
| 788 | array[2] = mGenericFavicon; |
| 789 | } else { |
| 790 | array[2] = new BitmapDrawable(icon); |
| 791 | } |
| 792 | LayerDrawable d = new LayerDrawable(array); |
| 793 | d.setLayerInset(1, 1, 1, 1, 1); |
| 794 | d.setLayerInset(2, 2, 2, 2, 2); |
| 795 | return d; |
| 796 | } |
| 797 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 798 | public boolean isLoading() { |
| 799 | return mActiveTab != null ? mActiveTab.inPageLoad() : false; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Suggest to the UI that the title bar can be hidden. The UI will then |
| 804 | * decide whether or not to hide based off a number of factors, such |
| 805 | * as if the user is editing the URL bar or if the page is loading |
| 806 | */ |
| 807 | public void suggestHideTitleBar() { |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 808 | if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible() |
| 809 | && !mNavigationBar.isMenuShowing()) { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 810 | hideTitleBar(); |
| 811 | } |
| 812 | } |
| 813 | |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame] | 814 | protected final void showTitleBarForDuration() { |
| 815 | showTitleBarForDuration(HIDE_TITLEBAR_DELAY); |
| 816 | } |
| 817 | |
| 818 | protected final void showTitleBarForDuration(long duration) { |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 819 | showTitleBar(); |
| 820 | Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR); |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame] | 821 | mHandler.sendMessageDelayed(msg, duration); |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 822 | } |
| 823 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 824 | protected Handler mHandler = new Handler() { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 825 | |
| 826 | @Override |
| 827 | public void handleMessage(Message msg) { |
| 828 | if (msg.what == MSG_HIDE_TITLEBAR) { |
| 829 | suggestHideTitleBar(); |
| 830 | } |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 831 | BaseUi.this.handleMessage(msg); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 832 | } |
| 833 | }; |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 834 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 835 | protected void handleMessage(Message msg) {} |
| 836 | |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 837 | @Override |
| 838 | public void showWeb(boolean animate) { |
| 839 | mUiController.hideCustomView(); |
| 840 | } |
| 841 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 842 | static class FullscreenHolder extends FrameLayout { |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 843 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 844 | public FullscreenHolder(Context ctx) { |
| 845 | super(ctx); |
| 846 | setBackgroundColor(ctx.getResources().getColor(R.color.black)); |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 849 | @Override |
| 850 | public boolean onTouchEvent(MotionEvent evt) { |
| 851 | return true; |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 852 | } |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 853 | |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 854 | } |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 855 | |
| 856 | public void addFixedTitleBar(View view) { |
| 857 | mFixedTitlebarContainer.addView(view); |
| 858 | } |
| 859 | |
| 860 | public void setContentViewMarginTop(int margin) { |
| 861 | LinearLayout.LayoutParams params = |
| 862 | (LinearLayout.LayoutParams) mContentView.getLayoutParams(); |
| 863 | if (params.topMargin != margin) { |
| 864 | params.topMargin = margin; |
| 865 | mContentView.setLayoutParams(params); |
| 866 | } |
| 867 | } |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 868 | |
| 869 | @Override |
| 870 | public boolean blockFocusAnimations() { |
| 871 | return mBlockFocusAnimations; |
| 872 | } |
| 873 | |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 874 | @Override |
| 875 | public void onVoiceResult(String result) { |
| 876 | mNavigationBar.onVoiceResult(result); |
| 877 | } |
| 878 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 879 | } |