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