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