blob: cd1388f65308e912a1c0b3617712e068add013a5 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb8233fac2010-10-26 16:08:53 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
John Reckd3e4d5b2011-07-13 15:48:43 -070020import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.content.res.Configuration;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.graphics.Bitmap;
23import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070024import android.graphics.Color;
25import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070027import android.graphics.drawable.LayerDrawable;
28import android.graphics.drawable.PaintDrawable;
Sagar Dhawan1e040c72014-12-11 20:24:12 -080029import android.os.Build;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070031import android.os.Handler;
32import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070034import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.Gravity;
36import android.view.LayoutInflater;
37import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070038import android.view.MenuItem;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080040import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070043import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080046import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080048import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070050import android.content.res.TypedArray;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070051
Bijan Amirzada41242f22014-03-21 12:12:18 -070052import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080053
Pankaj Garg18aa0a12015-06-22 11:06:12 -070054import org.codeaurora.swe.BrowserCommandLine;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080055import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070056
Michael Kolb1bf23132010-11-19 12:55:12 -080057import java.util.List;
58
Michael Kolb8233fac2010-10-26 16:08:53 -070059/**
60 * UI interface definitions
61 */
John Reck718a24d2011-08-12 11:08:30 -070062public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070063
Enrico Ros1f5a0952014-11-18 20:15:48 -080064 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070065
Michael Kolb66706532010-12-12 19:50:22 -080066 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070067 new FrameLayout.LayoutParams(
68 ViewGroup.LayoutParams.MATCH_PARENT,
69 ViewGroup.LayoutParams.MATCH_PARENT);
70
Michael Kolb66706532010-12-12 19:50:22 -080071 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070072 new FrameLayout.LayoutParams(
73 ViewGroup.LayoutParams.MATCH_PARENT,
74 ViewGroup.LayoutParams.MATCH_PARENT,
75 Gravity.CENTER);
76
John Reck5d43ce82011-06-21 17:16:51 -070077 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070078 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070079
Michael Kolb8233fac2010-10-26 16:08:53 -070080 Activity mActivity;
81 UiController mUiController;
82 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080083 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080084 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070085
Steve Block2466eff2011-10-03 15:33:09 +010086 private Drawable mLockIconSecure;
87 private Drawable mLockIconMixed;
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070088 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070089
Michael Kolb66706532010-12-12 19:50:22 -080090 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070091 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070092
Michael Kolb31065b12011-10-06 13:51:32 -070093 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080094 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040095 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070096
John Reck718a24d2011-08-12 11:08:30 -070097 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070098
John Reck718a24d2011-08-12 11:08:30 -070099 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700100
Michael Kolb8233fac2010-10-26 16:08:53 -0700101 // the default <video> poster
102 private Bitmap mDefaultVideoPoster;
103 // the video progress view
104 private View mVideoProgressView;
105
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800106 private final View mDecorView;
107
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700109 protected TitleBar mTitleBar;
110 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700111 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700112 private boolean mFullscreenModeLocked;
Michael Kolb8233fac2010-10-26 16:08:53 -0700113
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700114 private EdgeSwipeController mEdgeSwipeController;
115 private EdgeSwipeSettings mEdgeSwipeSettings;
116
Michael Kolb8233fac2010-10-26 16:08:53 -0700117 public BaseUi(Activity browser, UiController controller) {
118 mActivity = browser;
119 mUiController = controller;
120 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800121 mInputManager = (InputMethodManager)
122 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800123 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
124 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700125 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
126 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700127 LayoutInflater.from(mActivity)
128 .inflate(R.layout.custom_screen, frameLayout);
129 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700130 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700131 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
132 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700133 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700134 mTitleBar = new TitleBar(mActivity, mUiController, this,
135 mContentView);
136 mTitleBar.setProgress(100);
137 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700138 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800139
140 // install system ui visibility listeners
141 mDecorView = mActivity.getWindow().getDecorView();
142 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700143 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700144 }
145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800146 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
147 new View.OnSystemUiVisibilityChangeListener() {
148 @Override
149 public void onSystemUiVisibilityChange(int visFlags) {
150 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
151 if (lostFullscreen)
152 setFullscreen(BrowserSettings.getInstance().useFullscreen());
153 }
154 };
155
Michael Kolb8233fac2010-10-26 16:08:53 -0700156 private void cancelStopToast() {
157 if (mStopToast != null) {
158 mStopToast.cancel();
159 mStopToast = null;
160 }
161 }
162
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700163 private Drawable getLockIconSecure() {
164 if (mLockIconSecure == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700165 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700166 }
167 return mLockIconSecure;
168 }
169
170 private Drawable getLockIconMixed() {
171 if (mLockIconMixed == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700172 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure_partial);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700173 }
174 return mLockIconMixed;
175 }
176
177 protected Drawable getGenericFavicon() {
178 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800179 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700180 }
181 return mGenericFavicon;
182 }
183
Michael Kolb8233fac2010-10-26 16:08:53 -0700184 // lifecycle
185
186 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800187 if (isCustomViewShowing()) {
188 onHideCustomView();
189 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500190 if (mTabControl.getCurrentTab() != null) {
191 mTabControl.getCurrentTab().exitFullscreen();
192 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 cancelStopToast();
194 mActivityPaused = true;
195 }
196
197 public void onResume() {
198 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700199 // check if we exited without setting active tab
200 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800201 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700202 final Tab ct = mTabControl.getCurrentTab();
203 if (ct != null) {
204 setActiveTab(ct);
205 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700206 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 }
208
Michael Kolb66706532010-12-12 19:50:22 -0800209 protected boolean isActivityPaused() {
210 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 }
212
213 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700214 if (mEdgeSwipeController != null) {
215 mEdgeSwipeController.onConfigurationChanged();
216 }
217 if (mEdgeSwipeSettings != null) {
218 mEdgeSwipeSettings.onConfigurationChanged();
219 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 }
221
John Reck0f602f32011-07-07 15:38:43 -0700222 public Activity getActivity() {
223 return mActivity;
224 }
225
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 // key handling
227
228 @Override
229 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700230 if (mCustomView != null) {
231 mUiController.hideCustomView();
232 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700233 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700234 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700235 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 }
237 return false;
238 }
239
Michael Kolb2814a362011-05-19 15:49:41 -0700240 @Override
241 public boolean onMenuKey() {
242 return false;
243 }
244
John Reck30c714c2010-12-16 17:30:34 -0800245 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700246 @Override
John Reck30c714c2010-12-16 17:30:34 -0800247 public void onTabDataChanged(Tab tab) {
248 setUrlTitle(tab);
249 setFavicon(tab);
250 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800251 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700252 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700253 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700254 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 }
256
257 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700258 public void onProgressChanged(Tab tab) {
259 int progress = tab.getLoadProgress();
260 if (tab.inForeground()) {
261 mTitleBar.setProgress(progress);
262 }
263 }
264
265 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500266 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800267 if (tab.inForeground()) {
268 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700269 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800270 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500271 }
272
273 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700274 public void onPageStopped(Tab tab) {
275 cancelStopToast();
276 if (tab.inForeground()) {
277 mStopToast = Toast
278 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
279 mStopToast.show();
280 }
281 }
282
283 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800284 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700285 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800286 }
287
288 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700289 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700290 }
291
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800292 public void cancelNavScreenRequest(){
293 }
294
Michael Kolb377ea312011-02-17 14:36:56 -0800295 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800296 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400297 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700298 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400299
Michael Kolbbae0cb22012-05-29 11:15:27 -0700300 // block unnecessary focus change animations during tab switch
301 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700302 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800303 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400304 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700305 WebView web = mActiveTab.getWebView();
306 if (web != null) {
307 web.setOnTouchListener(null);
308 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700309 }
Michael Kolb77df4562010-11-19 14:49:34 -0800310 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800311
Michael Kolbda580632012-04-16 13:30:28 -0700312 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700313 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700314 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700315 if (web != null) {
316 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700317 web.setTitleBar(mTitleBar);
318 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700319 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700320 }
Michael Kolb4923c222012-04-02 16:18:36 -0700321 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700322 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800323 onTabDataChanged(tab);
324 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700325 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700326 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400327
Vivek Sekhar943f0672014-05-01 18:35:22 -0700328 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400329 }
330
331 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700332 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400333 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700334 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400335
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800337
338 if(tabToWaitFor == mTabToRemove) {
339 if (mRunnable != null) {
340 mTitleBar.removeCallbacks(mRunnable);
341 }
342 mTabToRemove = null;
343 mTabToWaitFor = null;
344 mRunnable = null;
345 return;
346 }
347
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400348 //remove previously scehduled tab
349 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700350 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700351 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400352 removeTabFromContentView(mTabToRemove);
353 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400355 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700356 mTabToRemove = tabToRemove;
357 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400358 mNumRemoveTries = 0;
359
360 if (mTabToRemove != null) {
361 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700362 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400363 }
364 }
365
366 protected void tryRemoveTab() {
367 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700368 // Ensure the webview is still valid
369 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
370 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700371 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700372 mRunnable = new Runnable() {
373 public void run() {
374 tryRemoveTab();
375 }
376 };
377 }
378 /*if the new tab is still not ready, wait another 2 frames
379 before trying again. 1 frame for the tab to render the first
380 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700381 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400382 return;
383 }
384 }
385 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700386 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700387 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400388 removeTabFromContentView(mTabToRemove);
389 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700390 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400391 }
392 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700393 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700394 }
395
John Reck718a24d2011-08-12 11:08:30 -0700396 protected void updateUrlBarAutoShowManagerTarget() {
397 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700398 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700399 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700400 }
401 }
402
Michael Kolbcfa3af52010-12-14 10:36:11 -0800403 Tab getActiveTab() {
404 return mActiveTab;
405 }
406
Michael Kolb8233fac2010-10-26 16:08:53 -0700407 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800408 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800409 }
410
411 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700412 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800413 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700414 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800415 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 }
418
419 @Override
420 public void detachTab(Tab tab) {
421 removeTabFromContentView(tab);
422 }
423
424 @Override
425 public void attachTab(Tab tab) {
426 attachTabToContentView(tab);
427 }
428
Michael Kolb377ea312011-02-17 14:36:56 -0800429 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800430 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 return;
432 }
433 View container = tab.getViewContainer();
434 WebView mainView = tab.getWebView();
435 // Attach the WebView to the container and then attach the
436 // container to the content view.
437 FrameLayout wrapper =
438 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700439 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
440
441 if (wrapper != parentView) {
442 // clean up old view before attaching new view
443 // this helping in fixing issues such touch event
444 // getting triggered on old view instead of new one
445 if (parentView != null) {
446 parentView.removeView(mainView.getView());
447 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800448 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700449 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800450 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700451 if (parent != mContentView) {
452 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700453 parent.removeView(container);
454 }
455 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700456 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700457
458 refreshEdgeSwipeController(container);
459
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 mUiController.attachSubWindow(tab);
461 }
462
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700463 public void refreshEdgeSwipeController(View container) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700464 if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
465 return;
466 }
467
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700468 if (mEdgeSwipeController != null) {
469 mEdgeSwipeController.cleanup();
470 }
471
472 mEdgeSwipeSettings = null;
473
474 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
475
476 if (action.equalsIgnoreCase(
477 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
478 mEdgeSwipeController = new EdgeSwipeController(
479 container,
480 R.id.stationary_navview,
481 R.id.sliding_navview,
482 R.id.sliding_navview_shadow,
483 R.id.navview_opacity,
484 R.id.webview_wrapper,
485 R.id.draggable_mainframe,
486 this);
487 } else if (action.equalsIgnoreCase(
488 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
489 mEdgeSwipeSettings = new EdgeSwipeSettings(
490 container,
491 R.id.stationary_navview,
492 R.id.edge_sliding_settings,
493 R.id.sliding_navview_shadow,
494 R.id.webview_wrapper,
495 R.id.draggable_mainframe,
496 this);
497 } else {
498 DraggableFrameLayout draggableView = (DraggableFrameLayout)
499 container.findViewById(R.id.draggable_mainframe);
500 draggableView.setDragHelper(null);
501 }
502 }
503
Michael Kolb8233fac2010-10-26 16:08:53 -0700504 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800505 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700506 // Remove the container that contains the main WebView.
507 WebView mainView = tab.getWebView();
508 View container = tab.getViewContainer();
509 if (mainView == null) {
510 return;
511 }
512 // Remove the container from the content and then remove the
513 // WebView from the container. This will trigger a focus change
514 // needed by WebView.
515 FrameLayout wrapper =
516 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800517 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700518 mContentView.removeView(container);
519 mUiController.endActionMode();
520 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700521 }
522
Michael Kolba713ec82010-11-29 17:27:06 -0800523 @Override
524 public void onSetWebView(Tab tab, WebView webView) {
525 View container = tab.getViewContainer();
526 if (container == null) {
527 // The tab consists of a container view, which contains the main
528 // WebView, as well as any other UI elements associated with the tab.
529 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700530 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800531 tab.setViewContainer(container);
532 }
533 if (tab.getWebView() != webView) {
534 // Just remove the old one.
535 FrameLayout wrapper =
536 (FrameLayout) container.findViewById(R.id.webview_wrapper);
537 wrapper.removeView(tab.getWebView());
538 }
539 }
540
Michael Kolb8233fac2010-10-26 16:08:53 -0700541 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800542 * create a sub window container and webview for the tab
543 * Note: this methods operates through side-effects for now
544 * it sets both the subView and subViewContainer for the given tab
545 * @param tab tab to create the sub window for
546 * @param subView webview to be set as a subwindow for the tab
547 */
548 @Override
549 public void createSubWindow(Tab tab, WebView subView) {
550 View subViewContainer = mActivity.getLayoutInflater().inflate(
551 R.layout.browser_subwindow, null);
552 ViewGroup inner = (ViewGroup) subViewContainer
553 .findViewById(R.id.inner_container);
554 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
555 LayoutParams.MATCH_PARENT));
556 final ImageButton cancel = (ImageButton) subViewContainer
557 .findViewById(R.id.subwindow_close);
558 final WebView cancelSubView = subView;
559 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800560 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800561 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800562 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800563 }
564 });
565 tab.setSubWebView(subView);
566 tab.setSubViewContainer(subViewContainer);
567 }
568
569 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700570 * Remove the sub window from the content view.
571 */
572 @Override
573 public void removeSubWindow(View subviewContainer) {
574 mContentView.removeView(subviewContainer);
575 mUiController.endActionMode();
576 }
577
578 /**
579 * Attach the sub window to the content view.
580 */
581 @Override
582 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800583 if (container.getParent() != null) {
584 // already attached, remove first
585 ((ViewGroup) container.getParent()).removeView(container);
586 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700587 mContentView.addView(container, COVER_SCREEN_PARAMS);
588 }
589
Michael Kolb11d19782011-03-20 10:17:40 -0700590 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700591 WebView web = getWebView();
592 if (web != null) {
593 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700594 }
595 }
596
Michael Kolb1f9b3562012-04-24 14:38:34 -0700597 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700598 if (mUiController.isInCustomActionMode()) {
599 mUiController.endActionMode();
600 }
601 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700602 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700603 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700604 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700605 }
606
Michael Kolb7cdc4902011-02-03 17:54:40 -0800607 boolean canShowTitleBar() {
608 return !isTitleBarShowing()
609 && !isActivityPaused()
610 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700611 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800612 && !mUiController.isInCustomActionMode();
613 }
614
John Reck0f602f32011-07-07 15:38:43 -0700615 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700616 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700617 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700618 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700619 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800620 }
621
622 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700623 if (mTitleBar.isShowing()) {
624 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700625 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800626 }
627
628 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700629 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800630 }
631
John Reck5d43ce82011-06-21 17:16:51 -0700632 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700633 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700634 }
635
Michael Kolb80f75082012-04-10 10:50:06 -0700636 public void stopEditingUrl() {
637 mTitleBar.getNavigationBar().stopEditingUrl();
638 }
639
John Reck0f602f32011-07-07 15:38:43 -0700640 public TitleBar getTitleBar() {
641 return mTitleBar;
642 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800643
Michael Kolb66706532010-12-12 19:50:22 -0800644 @Override
John Reck2bc80422011-06-30 15:11:49 -0700645 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700646 Intent intent = new Intent(mActivity, ComboViewActivity.class);
647 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
648 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
649 Tab t = getActiveTab();
650 if (t != null) {
651 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800652 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700653 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700654 }
655
656 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800657 public void hideComboView() {
658 }
659
660 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400661 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800662 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 // if a view already exists then immediately terminate the new one
664 if (mCustomView != null) {
665 callback.onCustomViewHidden();
666 return;
667 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400668 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700669 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400670 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700671 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400672 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700673 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700674 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400675 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 }
677
678 @Override
679 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700680 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700681 if (mCustomView == null)
682 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400683 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700684 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400685 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700687 mCustomViewCallback.onCustomViewHidden();
688 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400689 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700690 }
691
692 @Override
693 public boolean isCustomViewShowing() {
694 return mCustomView != null;
695 }
696
Michael Kolb66706532010-12-12 19:50:22 -0800697 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800698 if (mInputManager.isActive()) {
699 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
700 0);
701 }
702 }
703
Michael Kolb66706532010-12-12 19:50:22 -0800704 @Override
John Reck3ba45532011-08-11 16:26:53 -0700705 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700706 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800707 }
708
Tarun Nainani87a86682015-02-05 11:47:35 -0800709 @Override
710 public boolean isComboViewShowing() {
711 return false;
712 }
713
Michael Kolb8233fac2010-10-26 16:08:53 -0700714 // -------------------------------------------------------------------------
715
Michael Kolb5a72f182011-01-13 20:35:06 -0800716 protected void updateNavigationState(Tab tab) {
717 }
718
Michael Kolb8233fac2010-10-26 16:08:53 -0700719 /**
720 * Update the lock icon to correspond to our latest state.
721 */
Michael Kolb66706532010-12-12 19:50:22 -0800722 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800723 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100724 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 }
726 }
727
728 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700729 * Updates the lock-icon image in the title-bar.
730 */
Steve Block2466eff2011-10-03 15:33:09 +0100731 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700732 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100733 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700734 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100735 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
736 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
737 // TODO: It would be good to have different icons for insecure vs mixed content.
738 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700739 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700740 }
Pankaj Garg32e1b942015-06-03 18:13:24 -0700741 mNavigationBar.setLock(d, securityState);
Michael Kolb8233fac2010-10-26 16:08:53 -0700742 }
743
John Reck30c714c2010-12-16 17:30:34 -0800744 protected void setUrlTitle(Tab tab) {
745 String url = tab.getUrl();
746 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800747 if (TextUtils.isEmpty(title)) {
748 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800749 }
Michael Kolb66706532010-12-12 19:50:22 -0800750 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700751 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800752 }
753 }
754
755 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800756 protected void setFavicon(Tab tab) {
757 if (tab.inForeground()) {
758 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700759 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800760 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700761 }
762
Michael Kolb66706532010-12-12 19:50:22 -0800763 // active tabs page
764
765 public void showActiveTabsPage() {
766 }
767
768 /**
769 * Remove the active tabs page.
770 */
771 public void removeActiveTabsPage() {
772 }
773
Michael Kolb8233fac2010-10-26 16:08:53 -0700774 // menu handling callbacks
775
776 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800777 public boolean onPrepareOptionsMenu(Menu menu) {
778 return true;
779 }
780
781 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700782 public void updateMenuState(Tab tab, Menu menu) {
783 }
784
785 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700786 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700787 }
788
789 @Override
790 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700791 }
792
793 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700794 public boolean onOptionsItemSelected(MenuItem item) {
795 return false;
796 }
797
798 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700799 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700800 }
801
802 @Override
803 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700804 }
805
806 @Override
807 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700808 }
809
810 @Override
811 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700812 }
813
Michael Kolb8233fac2010-10-26 16:08:53 -0700814 // -------------------------------------------------------------------------
815 // Helper function for WebChromeClient
816 // -------------------------------------------------------------------------
817
818 @Override
819 public Bitmap getDefaultVideoPoster() {
820 if (mDefaultVideoPoster == null) {
821 mDefaultVideoPoster = BitmapFactory.decodeResource(
822 mActivity.getResources(), R.drawable.default_video_poster);
823 }
824 return mDefaultVideoPoster;
825 }
826
827 @Override
828 public View getVideoLoadingProgressView() {
829 if (mVideoProgressView == null) {
830 LayoutInflater inflater = LayoutInflater.from(mActivity);
831 mVideoProgressView = inflater.inflate(
832 R.layout.video_loading_progress, null);
833 }
834 return mVideoProgressView;
835 }
836
Michael Kolb843510f2010-12-09 10:51:49 -0800837 @Override
838 public void showMaxTabsWarning() {
839 Toast warning = Toast.makeText(mActivity,
840 mActivity.getString(R.string.max_tabs_warning),
841 Toast.LENGTH_SHORT);
842 warning.show();
843 }
844
Michael Kolb46f987e2011-04-05 10:39:10 -0700845 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800846
Michael Kolb46f987e2011-04-05 10:39:10 -0700847 if (mActiveTab != null) {
848 return mActiveTab.getWebView();
849 } else {
850 return null;
851 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700852 }
853
Pankaj Garg62bc7912015-04-14 16:08:59 -0700854 public void forceDisableFullscreenMode(boolean disabled) {
855 mFullscreenModeLocked = false;
856 setFullscreen(!disabled);
857 mFullscreenModeLocked = disabled;
858 }
859
Michael Kolbc38c6042011-04-27 10:46:06 -0700860 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700861 if (mFullscreenModeLocked)
862 return;
863
Michael Kolbc5675ad2011-10-21 13:34:28 -0700864 Window win = mActivity.getWindow();
865 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800866 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500867 final int fullscreenImmersiveSetting =
868 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
869 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
870 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
871 View.SYSTEM_UI_FLAG_FULLSCREEN |
872 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
873
874 if (mCustomView != null) {
875 mCustomView.setSystemUiVisibility(enabled ?
876 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800877 } else if (Build.VERSION.SDK_INT >= 19) {
878 mContentView.setSystemUiVisibility(enabled ?
879 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700880 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500881 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800882 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700883 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500884 if (enabled)
885 winParams.flags |= bits;
886 else
887 winParams.flags &= ~bits;
888
Michael Kolbc5675ad2011-10-21 13:34:28 -0700889 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700890 }
891
Denise LaFayetteda31d742014-10-10 18:03:13 -0400892 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700893 public void showFullscreen(boolean fullScreen) {
894 //Hide/show system ui bar as needed
895 if (!BrowserSettings.getInstance().useFullscreen())
896 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700897 //Hide/show topbar as needed
898 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700899 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700900 if (fullScreen) {
901 //hide topbar
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700902 bwv.enableTopControls(false);
Vivek Sekhare337acf2015-04-02 21:00:48 -0700903 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700904 } else {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700905 bwv.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700906 //show the topbar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700907 mTitleBar.showTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700908 //enable for auto-hide
909 if (!mTitleBar.isFixed())
Vivek Sekhare337acf2015-04-02 21:00:48 -0700910 mTitleBar.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700911 }
912 }
913 }
914
Tarun Nainani8eb00912014-07-17 12:28:32 -0700915 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700916 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700917 if (topControlsOffsetYPix != 0.0) {
918 mTitleBar.setEnabled(false);
919 } else {
920 mTitleBar.setEnabled(true);
921 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800922 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800923 float currentY = mTitleBar.getTranslationY();
Devdeep Choudhury904c7062015-03-17 19:47:29 -0700924 float height = mNavigationBar.getHeight();
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800925 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
926 mTitleBar.requestLayout();
927 } else if ((height + topControlsOffsetYPix) <= 0) {
928 topControlsOffsetYPix -= 1;
929 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
930 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800931 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800932 // This was done to get HTML5 fullscreen API to work with fixed mode since
933 // topcontrols are used to implement HTML5 fullscreen
934 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700935 }
936 }
937
John Reck0f602f32011-07-07 15:38:43 -0700938 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800939 if (ENABLE_BORDER_AROUND_FAVICON) {
940 Drawable[] array = new Drawable[3];
941 array[0] = new PaintDrawable(Color.BLACK);
942 PaintDrawable p = new PaintDrawable(Color.WHITE);
943 array[1] = p;
944 if (icon == null) {
945 array[2] = getGenericFavicon();
946 } else {
947 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
948 }
949 LayerDrawable d = new LayerDrawable(array);
950 d.setLayerInset(1, 1, 1, 1, 1);
951 d.setLayerInset(2, 2, 2, 2, 2);
952 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700953 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800954 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700955 }
956
John Reck5d43ce82011-06-21 17:16:51 -0700957 public boolean isLoading() {
958 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
959 }
960
961 /**
962 * Suggest to the UI that the title bar can be hidden. The UI will then
963 * decide whether or not to hide based off a number of factors, such
964 * as if the user is editing the URL bar or if the page is loading
965 */
966 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700967 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
968 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700969 hideTitleBar();
970 }
971 }
972
John Reckbc6adb42011-09-01 18:03:20 -0700973 protected final void showTitleBarForDuration() {
974 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
975 }
976
977 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700978 showTitleBar();
979 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700980 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700981 }
982
Enrico Ros1f5a0952014-11-18 20:15:48 -0800983 protected void setMenuItemVisibility(Menu menu, int id,
984 boolean visibility) {
985 MenuItem item = menu.findItem(id);
986 if (item != null) {
987 item.setVisible(visibility);
988 }
989 }
990
John Reck9c5004e2011-10-07 16:00:12 -0700991 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700992
993 @Override
994 public void handleMessage(Message msg) {
995 if (msg.what == MSG_HIDE_TITLEBAR) {
996 suggestHideTitleBar();
997 }
John Reck9c5004e2011-10-07 16:00:12 -0700998 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700999 }
1000 };
John Reck3ba45532011-08-11 16:26:53 -07001001
John Reck9c5004e2011-10-07 16:00:12 -07001002 protected void handleMessage(Message msg) {}
1003
John Reck3ba45532011-08-11 16:26:53 -07001004 @Override
1005 public void showWeb(boolean animate) {
1006 mUiController.hideCustomView();
1007 }
1008
John Reck2711fab2012-05-18 21:38:59 -07001009 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -08001010 FrameLayout.LayoutParams params =
1011 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -07001012 if (params.topMargin != margin) {
1013 params.topMargin = margin;
1014 mContentView.setLayoutParams(params);
1015 }
1016 }
Michael Kolbbae0cb22012-05-29 11:15:27 -07001017
1018 @Override
1019 public boolean blockFocusAnimations() {
1020 return mBlockFocusAnimations;
1021 }
1022
Michael Kolb0b129122012-06-04 16:31:58 -07001023 @Override
1024 public void onVoiceResult(String result) {
1025 mNavigationBar.onVoiceResult(result);
1026 }
1027
kaiyizbb2db872013-08-01 22:24:07 -04001028 protected UiController getUiController() {
1029 return mUiController;
1030 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001031
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001032 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001033 private float getActionModeHeight() {
1034 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1035 new int[] { android.R.attr.actionBarSize });
1036 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1037 actionBarSizeTypedArray.recycle();
1038 return size;
1039 }
1040
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001041
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001042 @Override
1043 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001044 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001045
1046 if (mTitleBar.isFixed()) {
1047 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001048 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001049 } else {
1050 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001051 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001052 }
1053
1054 @Override
1055 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001056 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001057 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001058 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001059 } else {
1060 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001061 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001062 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001063}