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 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 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; |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 35 | import android.view.ActionMode; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 36 | import android.view.Gravity; |
| 37 | import android.view.LayoutInflater; |
| 38 | import android.view.Menu; |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 39 | import android.view.MenuItem; |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 40 | import android.view.MotionEvent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 41 | import android.view.View; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 42 | import android.view.View.OnClickListener; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 43 | import android.view.ViewGroup; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 44 | import android.view.ViewGroup.LayoutParams; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 45 | import android.view.Window; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 46 | import android.view.WindowManager; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 47 | import android.view.inputmethod.InputMethodManager; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 48 | import android.webkit.WebChromeClient.CustomViewCallback; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 49 | import android.widget.FrameLayout; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 50 | import android.widget.ImageButton; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 51 | import android.widget.LinearLayout; |
| 52 | import android.widget.Toast; |
| 53 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 54 | import com.android.browser.R; |
| 55 | import com.android.browser.Tab.SecurityState; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 56 | |
| 57 | import org.codeaurora.swe.WebView; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 58 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 59 | import java.util.List; |
| 60 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 61 | /** |
| 62 | * UI interface definitions |
| 63 | */ |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 64 | public abstract class BaseUi implements UI { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 65 | |
| 66 | private static final String LOGTAG = "BaseUi"; |
| 67 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 68 | protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 69 | new FrameLayout.LayoutParams( |
| 70 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 71 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 72 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 73 | protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 74 | new FrameLayout.LayoutParams( |
| 75 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 76 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 77 | Gravity.CENTER); |
| 78 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 79 | private static final int MSG_HIDE_TITLEBAR = 1; |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 80 | public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 81 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 82 | Activity mActivity; |
| 83 | UiController mUiController; |
| 84 | TabControl mTabControl; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 85 | protected Tab mActiveTab; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 86 | private InputMethodManager mInputManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 87 | |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 88 | private Drawable mLockIconSecure; |
| 89 | private Drawable mLockIconMixed; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 90 | protected Drawable mGenericFavicon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 91 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 92 | protected FrameLayout mContentView; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 93 | protected FrameLayout mCustomViewContainer; |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 94 | protected FrameLayout mFullscreenContainer; |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 95 | private FrameLayout mFixedTitlebarContainer; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 96 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 97 | private View mCustomView; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 98 | private CustomViewCallback mCustomViewCallback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 99 | private int mOriginalOrientation; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 100 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 101 | private LinearLayout mErrorConsoleContainer = null; |
| 102 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 103 | private UrlBarAutoShowManager mUrlBarAutoShowManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 104 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 105 | private Toast mStopToast; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 106 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 107 | // the default <video> poster |
| 108 | private Bitmap mDefaultVideoPoster; |
| 109 | // the video progress view |
| 110 | private View mVideoProgressView; |
| 111 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 112 | private boolean mActivityPaused; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 113 | protected boolean mUseQuickControls; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 114 | protected TitleBar mTitleBar; |
| 115 | private NavigationBarBase mNavigationBar; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 116 | protected PieControl mPieControl; |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 117 | private boolean mBlockFocusAnimations; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 118 | |
| 119 | public BaseUi(Activity browser, UiController controller) { |
| 120 | mActivity = browser; |
| 121 | mUiController = controller; |
| 122 | mTabControl = controller.getTabControl(); |
| 123 | Resources res = mActivity.getResources(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 124 | mInputManager = (InputMethodManager) |
| 125 | browser.getSystemService(Activity.INPUT_METHOD_SERVICE); |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 126 | mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark); |
| 127 | mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 128 | FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() |
| 129 | .getDecorView().findViewById(android.R.id.content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 130 | LayoutInflater.from(mActivity) |
| 131 | .inflate(R.layout.custom_screen, frameLayout); |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 132 | mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById( |
| 133 | R.id.fixed_titlebar_container); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 134 | mContentView = (FrameLayout) frameLayout.findViewById( |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 135 | R.id.main_content); |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 136 | mCustomViewContainer = (FrameLayout) frameLayout.findViewById( |
| 137 | R.id.fullscreen_custom_content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 138 | mErrorConsoleContainer = (LinearLayout) frameLayout |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 139 | .findViewById(R.id.error_console); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 140 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 141 | mGenericFavicon = res.getDrawable( |
| 142 | R.drawable.app_web_browser_sm); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 143 | mTitleBar = new TitleBar(mActivity, mUiController, this, |
| 144 | mContentView); |
| 145 | mTitleBar.setProgress(100); |
| 146 | mNavigationBar = mTitleBar.getNavigationBar(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 147 | mUrlBarAutoShowManager = new UrlBarAutoShowManager(this); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 150 | private void cancelStopToast() { |
| 151 | if (mStopToast != null) { |
| 152 | mStopToast.cancel(); |
| 153 | mStopToast = null; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // lifecycle |
| 158 | |
| 159 | public void onPause() { |
Michael Kolb | 7a5cf47 | 2010-11-30 13:23:53 -0800 | [diff] [blame] | 160 | if (isCustomViewShowing()) { |
| 161 | onHideCustomView(); |
| 162 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 163 | cancelStopToast(); |
| 164 | mActivityPaused = true; |
| 165 | } |
| 166 | |
| 167 | public void onResume() { |
| 168 | mActivityPaused = false; |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 169 | // check if we exited without setting active tab |
| 170 | // b: 5188145 |
Michael Kolb | 1a4625a | 2011-08-24 13:40:44 -0700 | [diff] [blame] | 171 | final Tab ct = mTabControl.getCurrentTab(); |
| 172 | if (ct != null) { |
| 173 | setActiveTab(ct); |
| 174 | } |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 175 | mTitleBar.onResume(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 178 | protected boolean isActivityPaused() { |
| 179 | return mActivityPaused; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | public void onConfigurationChanged(Configuration config) { |
| 183 | } |
| 184 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 185 | public Activity getActivity() { |
| 186 | return mActivity; |
| 187 | } |
| 188 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 189 | // key handling |
| 190 | |
| 191 | @Override |
| 192 | public boolean onBackKey() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 193 | if (mCustomView != null) { |
| 194 | mUiController.hideCustomView(); |
| 195 | return true; |
| 196 | } |
| 197 | return false; |
| 198 | } |
| 199 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 200 | @Override |
| 201 | public boolean onMenuKey() { |
| 202 | return false; |
| 203 | } |
| 204 | |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 205 | @Override |
| 206 | public void setUseQuickControls(boolean useQuickControls) { |
| 207 | mUseQuickControls = useQuickControls; |
| 208 | mTitleBar.setUseQuickControls(mUseQuickControls); |
| 209 | if (useQuickControls) { |
| 210 | mPieControl = new PieControl(mActivity, mUiController, this); |
| 211 | mPieControl.attachToContainer(mContentView); |
| 212 | } else { |
| 213 | if (mPieControl != null) { |
| 214 | mPieControl.removeFromContainer(mContentView); |
| 215 | } |
| 216 | } |
| 217 | updateUrlBarAutoShowManagerTarget(); |
| 218 | } |
| 219 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 220 | // Tab callbacks |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 221 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 222 | public void onTabDataChanged(Tab tab) { |
| 223 | setUrlTitle(tab); |
| 224 | setFavicon(tab); |
| 225 | updateLockIconToLatest(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 226 | updateNavigationState(tab); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 227 | mTitleBar.onTabDataChanged(tab); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 228 | mNavigationBar.onTabDataChanged(tab); |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 229 | onProgressChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Override |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 233 | public void onProgressChanged(Tab tab) { |
| 234 | int progress = tab.getLoadProgress(); |
| 235 | if (tab.inForeground()) { |
| 236 | mTitleBar.setProgress(progress); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 241 | public void bookmarkedStatusHasChanged(Tab tab) { |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 242 | if (tab.inForeground()) { |
| 243 | boolean isBookmark = tab.isBookmarkedSite(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 244 | mNavigationBar.setCurrentUrlIsBookmark(isBookmark); |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 245 | } |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 249 | public void onPageStopped(Tab tab) { |
| 250 | cancelStopToast(); |
| 251 | if (tab.inForeground()) { |
| 252 | mStopToast = Toast |
| 253 | .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); |
| 254 | mStopToast.show(); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 259 | public boolean needsRestoreAllTabs() { |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 260 | return true; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 264 | public void addTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 268 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 7ac63b6 | 2011-12-16 09:52:29 -0800 | [diff] [blame] | 269 | if (tab == null) return; |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 270 | // block unnecessary focus change animations during tab switch |
| 271 | mBlockFocusAnimations = true; |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 272 | mHandler.removeMessages(MSG_HIDE_TITLEBAR); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 273 | if ((tab != mActiveTab) && (mActiveTab != null)) { |
| 274 | removeTabFromContentView(mActiveTab); |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 275 | WebView web = mActiveTab.getWebView(); |
| 276 | if (web != null) { |
| 277 | web.setOnTouchListener(null); |
| 278 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 279 | } |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 280 | mActiveTab = tab; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 281 | BrowserWebView web = (BrowserWebView) mActiveTab.getWebView(); |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 282 | updateUrlBarAutoShowManagerTarget(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 283 | attachTabToContentView(tab); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 284 | if (web != null) { |
| 285 | // Request focus on the top window. |
| 286 | if (mUseQuickControls) { |
| 287 | mPieControl.forceToTop(mContentView); |
| 288 | web.setTitleBar(null); |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 289 | mTitleBar.hide(); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 290 | } else { |
| 291 | web.setTitleBar(mTitleBar); |
| 292 | mTitleBar.onScrollChanged(); |
| 293 | } |
| 294 | } |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 295 | mTitleBar.bringToFront(); |
Michael Kolb | f896352 | 2012-04-10 10:52:34 -0700 | [diff] [blame] | 296 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 297 | setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 298 | onTabDataChanged(tab); |
| 299 | onProgressChanged(tab); |
Michael Kolb | 03b6bc6 | 2011-09-02 16:19:53 -0700 | [diff] [blame] | 300 | mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled()); |
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, |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 524 | CustomViewCallback callback) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 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 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 575 | // ------------------------------------------------------------------------- |
| 576 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 577 | protected void updateNavigationState(Tab tab) { |
| 578 | } |
| 579 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 580 | /** |
| 581 | * Update the lock icon to correspond to our latest state. |
| 582 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 583 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 584 | if (t != null && t.inForeground()) { |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 585 | updateLockIconImage(t.getSecurityState()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 590 | * Updates the lock-icon image in the title-bar. |
| 591 | */ |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 592 | private void updateLockIconImage(SecurityState securityState) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 593 | Drawable d = null; |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 594 | if (securityState == SecurityState.SECURITY_STATE_SECURE) { |
| 595 | d = mLockIconSecure; |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 596 | } else if (securityState == SecurityState.SECURITY_STATE_MIXED |
| 597 | || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) { |
| 598 | // TODO: It would be good to have different icons for insecure vs mixed content. |
| 599 | // See http://b/5403800 |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 600 | d = mLockIconMixed; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 601 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 602 | mNavigationBar.setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 603 | } |
| 604 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 605 | protected void setUrlTitle(Tab tab) { |
| 606 | String url = tab.getUrl(); |
| 607 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 608 | if (TextUtils.isEmpty(title)) { |
| 609 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 610 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 611 | if (tab.inForeground()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 612 | mNavigationBar.setDisplayTitle(url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
| 616 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 617 | protected void setFavicon(Tab tab) { |
| 618 | if (tab.inForeground()) { |
| 619 | Bitmap icon = tab.getFavicon(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 620 | mNavigationBar.setFavicon(icon); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 621 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 624 | // active tabs page |
| 625 | |
| 626 | public void showActiveTabsPage() { |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Remove the active tabs page. |
| 631 | */ |
| 632 | public void removeActiveTabsPage() { |
| 633 | } |
| 634 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 635 | // menu handling callbacks |
| 636 | |
| 637 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 638 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 639 | return true; |
| 640 | } |
| 641 | |
| 642 | @Override |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 643 | public void updateMenuState(Tab tab, Menu menu) { |
| 644 | } |
| 645 | |
| 646 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 647 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | @Override |
| 651 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 655 | public boolean onOptionsItemSelected(MenuItem item) { |
| 656 | return false; |
| 657 | } |
| 658 | |
| 659 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 660 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | @Override |
| 664 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | @Override |
| 668 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | @Override |
| 672 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | // error console |
| 676 | |
| 677 | @Override |
| 678 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
Michael Kolb | 9fcefd1 | 2011-02-17 10:55:59 -0800 | [diff] [blame] | 679 | if (tab == null) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 680 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 681 | if (flag) { |
| 682 | // Setting the show state of the console will cause it's the layout |
| 683 | // to be inflated. |
| 684 | if (errorConsole.numberOfErrors() > 0) { |
| 685 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 686 | } else { |
| 687 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 688 | } |
| 689 | if (errorConsole.getParent() != null) { |
| 690 | mErrorConsoleContainer.removeView(errorConsole); |
| 691 | } |
| 692 | // Now we can add it to the main view. |
| 693 | mErrorConsoleContainer.addView(errorConsole, |
| 694 | new LinearLayout.LayoutParams( |
| 695 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 696 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 697 | } else { |
| 698 | mErrorConsoleContainer.removeView(errorConsole); |
| 699 | } |
| 700 | } |
| 701 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 702 | // ------------------------------------------------------------------------- |
| 703 | // Helper function for WebChromeClient |
| 704 | // ------------------------------------------------------------------------- |
| 705 | |
| 706 | @Override |
| 707 | public Bitmap getDefaultVideoPoster() { |
| 708 | if (mDefaultVideoPoster == null) { |
| 709 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 710 | mActivity.getResources(), R.drawable.default_video_poster); |
| 711 | } |
| 712 | return mDefaultVideoPoster; |
| 713 | } |
| 714 | |
| 715 | @Override |
| 716 | public View getVideoLoadingProgressView() { |
| 717 | if (mVideoProgressView == null) { |
| 718 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 719 | mVideoProgressView = inflater.inflate( |
| 720 | R.layout.video_loading_progress, null); |
| 721 | } |
| 722 | return mVideoProgressView; |
| 723 | } |
| 724 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 725 | @Override |
| 726 | public void showMaxTabsWarning() { |
| 727 | Toast warning = Toast.makeText(mActivity, |
| 728 | mActivity.getString(R.string.max_tabs_warning), |
| 729 | Toast.LENGTH_SHORT); |
| 730 | warning.show(); |
| 731 | } |
| 732 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 733 | protected WebView getWebView() { |
| 734 | if (mActiveTab != null) { |
| 735 | return mActiveTab.getWebView(); |
| 736 | } else { |
| 737 | return null; |
| 738 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 741 | public void setFullscreen(boolean enabled) { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 742 | Window win = mActivity.getWindow(); |
| 743 | WindowManager.LayoutParams winParams = win.getAttributes(); |
Michael Kolb | 76dff39 | 2011-12-06 09:51:18 -0800 | [diff] [blame] | 744 | final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 745 | if (enabled) { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 746 | winParams.flags |= bits; |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 747 | } else { |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 748 | winParams.flags &= ~bits; |
| 749 | if (mCustomView != null) { |
| 750 | mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); |
| 751 | } else { |
| 752 | mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); |
| 753 | } |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 754 | } |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 755 | win.setAttributes(winParams); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 756 | } |
| 757 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 758 | public Drawable getFaviconDrawable(Bitmap icon) { |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 759 | Drawable[] array = new Drawable[3]; |
| 760 | array[0] = new PaintDrawable(Color.BLACK); |
| 761 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 762 | array[1] = p; |
| 763 | if (icon == null) { |
| 764 | array[2] = mGenericFavicon; |
| 765 | } else { |
| 766 | array[2] = new BitmapDrawable(icon); |
| 767 | } |
| 768 | LayerDrawable d = new LayerDrawable(array); |
| 769 | d.setLayerInset(1, 1, 1, 1, 1); |
| 770 | d.setLayerInset(2, 2, 2, 2, 2); |
| 771 | return d; |
| 772 | } |
| 773 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 774 | public boolean isLoading() { |
| 775 | return mActiveTab != null ? mActiveTab.inPageLoad() : false; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * Suggest to the UI that the title bar can be hidden. The UI will then |
| 780 | * decide whether or not to hide based off a number of factors, such |
| 781 | * as if the user is editing the URL bar or if the page is loading |
| 782 | */ |
| 783 | public void suggestHideTitleBar() { |
John Reck | 5889190 | 2011-08-11 17:48:53 -0700 | [diff] [blame] | 784 | if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible() |
| 785 | && !mNavigationBar.isMenuShowing()) { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 786 | hideTitleBar(); |
| 787 | } |
| 788 | } |
| 789 | |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame] | 790 | protected final void showTitleBarForDuration() { |
| 791 | showTitleBarForDuration(HIDE_TITLEBAR_DELAY); |
| 792 | } |
| 793 | |
| 794 | protected final void showTitleBarForDuration(long duration) { |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 795 | showTitleBar(); |
| 796 | Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR); |
John Reck | bc6adb4 | 2011-09-01 18:03:20 -0700 | [diff] [blame] | 797 | mHandler.sendMessageDelayed(msg, duration); |
John Reck | 6ac5bfd | 2011-07-01 17:02:55 -0700 | [diff] [blame] | 798 | } |
| 799 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 800 | protected Handler mHandler = new Handler() { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 801 | |
| 802 | @Override |
| 803 | public void handleMessage(Message msg) { |
| 804 | if (msg.what == MSG_HIDE_TITLEBAR) { |
| 805 | suggestHideTitleBar(); |
| 806 | } |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 807 | BaseUi.this.handleMessage(msg); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 808 | } |
| 809 | }; |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 810 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 811 | protected void handleMessage(Message msg) {} |
| 812 | |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 813 | @Override |
| 814 | public void showWeb(boolean animate) { |
| 815 | mUiController.hideCustomView(); |
| 816 | } |
| 817 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 818 | static class FullscreenHolder extends FrameLayout { |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 819 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 820 | public FullscreenHolder(Context ctx) { |
| 821 | super(ctx); |
| 822 | setBackgroundColor(ctx.getResources().getColor(R.color.black)); |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 825 | @Override |
| 826 | public boolean onTouchEvent(MotionEvent evt) { |
| 827 | return true; |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 828 | } |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 829 | |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 830 | } |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 831 | |
| 832 | public void addFixedTitleBar(View view) { |
| 833 | mFixedTitlebarContainer.addView(view); |
| 834 | } |
| 835 | |
| 836 | public void setContentViewMarginTop(int margin) { |
| 837 | LinearLayout.LayoutParams params = |
| 838 | (LinearLayout.LayoutParams) mContentView.getLayoutParams(); |
| 839 | if (params.topMargin != margin) { |
| 840 | params.topMargin = margin; |
| 841 | mContentView.setLayoutParams(params); |
| 842 | } |
| 843 | } |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 844 | |
| 845 | @Override |
| 846 | public boolean blockFocusAnimations() { |
| 847 | return mBlockFocusAnimations; |
| 848 | } |
| 849 | |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 850 | @Override |
| 851 | public void onVoiceResult(String result) { |
| 852 | mNavigationBar.onVoiceResult(result); |
| 853 | } |
| 854 | |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 855 | protected UiController getUiController() { |
| 856 | return mUiController; |
| 857 | } |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 858 | |
| 859 | @Override |
| 860 | public void onActionModeStarted(ActionMode mode) { |
| 861 | int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0; |
| 862 | mFixedTitlebarContainer.setY(fixedTbarHeight); |
| 863 | setContentViewMarginTop(fixedTbarHeight); |
| 864 | } |
| 865 | |
| 866 | @Override |
| 867 | public void onActionModeFinished(boolean inLoad) { |
| 868 | mFixedTitlebarContainer.setY(0); |
| 869 | setContentViewMarginTop(0); |
| 870 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 871 | } |