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