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