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