blob: 508d2c9ad5cc28bf5c995041fbbb0dfd20b3fefa [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;
Sagar Dhawan2abecc62015-09-14 18:53:04 -070049import android.widget.ImageView;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070051import android.content.res.TypedArray;
jrizzoli7924a0c2016-02-05 14:30:14 +010052import android.util.Log;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070053
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
77 Activity mActivity;
78 UiController mUiController;
79 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080080 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080081 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070083 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070084
Michael Kolb66706532010-12-12 19:50:22 -080085 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070086 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070087
Michael Kolb31065b12011-10-06 13:51:32 -070088 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080089 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040090 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
John Reck718a24d2011-08-12 11:08:30 -070092 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070093
Michael Kolb8233fac2010-10-26 16:08:53 -070094 // the default <video> poster
95 private Bitmap mDefaultVideoPoster;
96 // the video progress view
97 private View mVideoProgressView;
98
Sagar Dhawan1e040c72014-12-11 20:24:12 -080099 private final View mDecorView;
100
Michael Kolb8233fac2010-10-26 16:08:53 -0700101 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700102 protected TitleBar mTitleBar;
103 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700104 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700105 private boolean mFullscreenModeLocked;
Sagar Dhawan55165b82015-09-03 15:33:02 -0700106 private final static int mFullScreenImmersiveSetting =
107 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
108 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
109 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
110 View.SYSTEM_UI_FLAG_FULLSCREEN |
111 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Michael Kolb8233fac2010-10-26 16:08:53 -0700112
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700113 private EdgeSwipeController mEdgeSwipeController;
114 private EdgeSwipeSettings mEdgeSwipeSettings;
115
Sagar Dhawan55165b82015-09-03 15:33:02 -0700116 // This Runnable is used to re-set fullscreen mode after resume.
117 // The immersive mode API on android <6.0 is buggy and will more
118 // often then not glitch out. Using a runnable really helps reduce
119 // the repeatability of this framework bug, however some corner cases
120 // remain. Specifically when interacting with pop-up windows(menu).
121 private Runnable mFullScreenModeRunnable = new Runnable() {
122 @Override
123 public void run() {
124 if (BrowserSettings.getInstance() != null)
125 setFullscreen(BrowserSettings.getInstance().useFullscreen());
126 }
127 };
128
Michael Kolb8233fac2010-10-26 16:08:53 -0700129 public BaseUi(Activity browser, UiController controller) {
130 mActivity = browser;
131 mUiController = controller;
132 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800133 mInputManager = (InputMethodManager)
134 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800135 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
136 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700137 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
138 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700139 LayoutInflater.from(mActivity)
140 .inflate(R.layout.custom_screen, frameLayout);
jrizzoli7924a0c2016-02-05 14:30:14 +0100141
142 // If looklock is enabled, set FLAG_SECURE
143 if (BrowserSettings.getInstance().isLookLockEnabled()) {
144 mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
145 WindowManager.LayoutParams.FLAG_SECURE);
146 } else {
147 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
148 }
149
John Reck7c6e1c92011-06-30 11:55:55 -0700150 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700151 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700152 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
153 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700154 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700155 mTitleBar = new TitleBar(mActivity, mUiController, this,
156 mContentView);
157 mTitleBar.setProgress(100);
158 mNavigationBar = mTitleBar.getNavigationBar();
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800159
160 // install system ui visibility listeners
161 mDecorView = mActivity.getWindow().getDecorView();
162 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700163 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700164 }
165
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800166 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
167 new View.OnSystemUiVisibilityChangeListener() {
168 @Override
169 public void onSystemUiVisibilityChange(int visFlags) {
Sagar Dhawan55165b82015-09-03 15:33:02 -0700170 final boolean lostFullscreen = (visFlags & mFullScreenImmersiveSetting) == 0;
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800171 if (lostFullscreen)
172 setFullscreen(BrowserSettings.getInstance().useFullscreen());
173 }
174 };
175
Michael Kolb8233fac2010-10-26 16:08:53 -0700176 private void cancelStopToast() {
177 if (mStopToast != null) {
178 mStopToast.cancel();
179 mStopToast = null;
180 }
181 }
182
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700183 protected Drawable getGenericFavicon() {
184 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800185 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700186 }
187 return mGenericFavicon;
188 }
189
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 // lifecycle
191
192 public void onPause() {
jrizzoli7924a0c2016-02-05 14:30:14 +0100193 if (BrowserSettings.getInstance().isLookLockEnabled()) {
194 mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
195 WindowManager.LayoutParams.FLAG_SECURE);
196 } else {
197 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
198 }
Michael Kolb7a5cf472010-11-30 13:23:53 -0800199 if (isCustomViewShowing()) {
200 onHideCustomView();
201 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500202 if (mTabControl.getCurrentTab() != null) {
203 mTabControl.getCurrentTab().exitFullscreen();
204 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700205 cancelStopToast();
206 mActivityPaused = true;
207 }
208
209 public void onResume() {
210 mActivityPaused = false;
jrizzoli7924a0c2016-02-05 14:30:14 +0100211 if (BrowserSettings.getInstance().isLookLockEnabled()) {
212 mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
213 WindowManager.LayoutParams.FLAG_SECURE);
214 } else {
215 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
216 }
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700217 // check if we exited without setting active tab
218 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800219 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Sagar Dhawan55165b82015-09-03 15:33:02 -0700220 //Work around for < Android M
221 if (Build.VERSION.SDK_INT <= 22 && BrowserSettings.getInstance().useFullscreen())
222 mHandler.postDelayed(mFullScreenModeRunnable, 500);
223
Michael Kolb1a4625a2011-08-24 13:40:44 -0700224 final Tab ct = mTabControl.getCurrentTab();
225 if (ct != null) {
226 setActiveTab(ct);
227 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700228 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700229 }
230
Michael Kolb66706532010-12-12 19:50:22 -0800231 protected boolean isActivityPaused() {
232 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 }
234
235 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700236 if (mEdgeSwipeController != null) {
237 mEdgeSwipeController.onConfigurationChanged();
238 }
239 if (mEdgeSwipeSettings != null) {
240 mEdgeSwipeSettings.onConfigurationChanged();
241 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 }
243
John Reck0f602f32011-07-07 15:38:43 -0700244 public Activity getActivity() {
245 return mActivity;
246 }
247
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 // key handling
249
250 @Override
251 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 if (mCustomView != null) {
253 mUiController.hideCustomView();
254 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700255 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700256 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700257 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700258 }
259 return false;
260 }
261
Vivek Sekhard4de6162015-07-21 15:01:45 -0700262 public boolean isFullScreen() {
263 if (mTabControl.getCurrentTab() != null)
264 return mTabControl.getCurrentTab().isTabFullScreen();
265 return false;
266 }
267
Michael Kolb2814a362011-05-19 15:49:41 -0700268 @Override
269 public boolean onMenuKey() {
270 return false;
271 }
272
John Reck30c714c2010-12-16 17:30:34 -0800273 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700274 @Override
John Reck30c714c2010-12-16 17:30:34 -0800275 public void onTabDataChanged(Tab tab) {
276 setUrlTitle(tab);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700277 updateTabSecurityState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800278 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700279 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700280 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700281 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700282 }
283
284 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700285 public void onProgressChanged(Tab tab) {
286 int progress = tab.getLoadProgress();
287 if (tab.inForeground()) {
Pankaj Gargf9040c82015-08-14 10:19:31 -0700288 if (tab.inPageLoad()) {
289 mTitleBar.setProgress(progress);
290 } else {
291 mTitleBar.setProgress(100);
292 }
Michael Kolbe8a82332012-04-25 14:14:26 -0700293 }
294 }
295
296 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500297 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800298 if (tab.inForeground()) {
299 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700300 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800301 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500302 }
303
304 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700305 public void onPageStopped(Tab tab) {
306 cancelStopToast();
307 if (tab.inForeground()) {
308 mStopToast = Toast
309 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
310 mStopToast.show();
311 }
312 }
313
314 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800315 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700316 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800317 }
318
319 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700320 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700321 }
322
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800323 public void cancelNavScreenRequest(){
324 }
325
Michael Kolb377ea312011-02-17 14:36:56 -0800326 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800327 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400328 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700329 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400330
Michael Kolbbae0cb22012-05-29 11:15:27 -0700331 // block unnecessary focus change animations during tab switch
332 mBlockFocusAnimations = true;
Michael Kolb77df4562010-11-19 14:49:34 -0800333 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400334 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700335 WebView web = mActiveTab.getWebView();
336 if (web != null) {
337 web.setOnTouchListener(null);
338 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700339 }
Michael Kolb77df4562010-11-19 14:49:34 -0800340 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800341
Michael Kolbda580632012-04-16 13:30:28 -0700342 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck5d43ce82011-06-21 17:16:51 -0700343 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700344 if (web != null) {
345 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700346 web.setTitleBar(mTitleBar);
347 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700348 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700349 }
Michael Kolb4923c222012-04-02 16:18:36 -0700350 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700351 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800352 onTabDataChanged(tab);
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700353 setFavicon(tab);
John Reck30c714c2010-12-16 17:30:34 -0800354 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700355 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700356 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400357
Vivek Sekhar943f0672014-05-01 18:35:22 -0700358 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700359
360 updateTabSecurityState(tab);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400361 }
362
363 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700364 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400365 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700366 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400367
Vivek Sekhar943f0672014-05-01 18:35:22 -0700368 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800369
370 if(tabToWaitFor == mTabToRemove) {
371 if (mRunnable != null) {
372 mTitleBar.removeCallbacks(mRunnable);
373 }
374 mTabToRemove = null;
375 mTabToWaitFor = null;
376 mRunnable = null;
377 return;
378 }
379
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400380 //remove previously scehduled tab
381 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700382 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700383 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400384 removeTabFromContentView(mTabToRemove);
385 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700386 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400387 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700388 mTabToRemove = tabToRemove;
389 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400390 mNumRemoveTries = 0;
391
392 if (mTabToRemove != null) {
393 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700394 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400395 }
396 }
397
398 protected void tryRemoveTab() {
399 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700400 // Ensure the webview is still valid
401 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
402 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700403 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700404 mRunnable = new Runnable() {
405 public void run() {
406 tryRemoveTab();
407 }
408 };
409 }
410 /*if the new tab is still not ready, wait another 2 frames
411 before trying again. 1 frame for the tab to render the first
412 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700413 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400414 return;
415 }
416 }
417 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700418 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700419 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400420 removeTabFromContentView(mTabToRemove);
421 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700422 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400423 }
424 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700425 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427
Michael Kolbcfa3af52010-12-14 10:36:11 -0800428 Tab getActiveTab() {
429 return mActiveTab;
430 }
431
Michael Kolb8233fac2010-10-26 16:08:53 -0700432 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800433 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800434 }
435
436 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700437 public void removeTab(Tab tab) {
Sagar Dhawan20b1deb2015-10-12 11:13:18 -0700438 removeTabFromContentView(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700439 }
440
441 @Override
442 public void detachTab(Tab tab) {
443 removeTabFromContentView(tab);
444 }
445
446 @Override
447 public void attachTab(Tab tab) {
448 attachTabToContentView(tab);
449 }
450
Michael Kolb377ea312011-02-17 14:36:56 -0800451 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800452 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700453 return;
454 }
455 View container = tab.getViewContainer();
456 WebView mainView = tab.getWebView();
457 // Attach the WebView to the container and then attach the
458 // container to the content view.
459 FrameLayout wrapper =
460 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700461 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
462
463 if (wrapper != parentView) {
464 // clean up old view before attaching new view
465 // this helping in fixing issues such touch event
466 // getting triggered on old view instead of new one
467 if (parentView != null) {
468 parentView.removeView(mainView.getView());
469 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800470 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700471 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800472 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700473 if (parent != mContentView) {
474 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700475 parent.removeView(container);
476 }
477 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700478 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700479
480 refreshEdgeSwipeController(container);
481
Michael Kolb8233fac2010-10-26 16:08:53 -0700482 mUiController.attachSubWindow(tab);
483 }
484
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700485 public void refreshEdgeSwipeController(View container) {
Site Mao61b68212015-07-16 10:56:31 -0700486 if (isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700487 return;
488 }
489
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700490 if (mEdgeSwipeController != null) {
491 mEdgeSwipeController.cleanup();
492 }
493
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700494 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
495
Sagar Dhawan05e3c352015-09-07 15:24:33 +0200496 if (mEdgeSwipeSettings != null) {
497 mEdgeSwipeSettings.cleanup();
498 }
499 mEdgeSwipeSettings = null;
500
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700501 if (action.equalsIgnoreCase(
502 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
503 mEdgeSwipeController = new EdgeSwipeController(
504 container,
505 R.id.stationary_navview,
506 R.id.sliding_navview,
507 R.id.sliding_navview_shadow,
508 R.id.navview_opacity,
509 R.id.webview_wrapper,
510 R.id.draggable_mainframe,
511 this);
512 } else if (action.equalsIgnoreCase(
513 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
514 mEdgeSwipeSettings = new EdgeSwipeSettings(
515 container,
516 R.id.stationary_navview,
517 R.id.edge_sliding_settings,
518 R.id.sliding_navview_shadow,
519 R.id.webview_wrapper,
520 R.id.draggable_mainframe,
521 this);
522 } else {
523 DraggableFrameLayout draggableView = (DraggableFrameLayout)
524 container.findViewById(R.id.draggable_mainframe);
525 draggableView.setDragHelper(null);
526 }
527 }
528
Michael Kolb8233fac2010-10-26 16:08:53 -0700529 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800530 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700531 // Remove the container that contains the main WebView.
532 WebView mainView = tab.getWebView();
533 View container = tab.getViewContainer();
534 if (mainView == null) {
535 return;
536 }
537 // Remove the container from the content and then remove the
538 // WebView from the container. This will trigger a focus change
539 // needed by WebView.
540 FrameLayout wrapper =
541 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800542 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700543 mContentView.removeView(container);
544 mUiController.endActionMode();
545 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700546 }
547
Michael Kolba713ec82010-11-29 17:27:06 -0800548 @Override
549 public void onSetWebView(Tab tab, WebView webView) {
550 View container = tab.getViewContainer();
551 if (container == null) {
552 // The tab consists of a container view, which contains the main
553 // WebView, as well as any other UI elements associated with the tab.
554 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700555 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800556 tab.setViewContainer(container);
557 }
558 if (tab.getWebView() != webView) {
559 // Just remove the old one.
560 FrameLayout wrapper =
561 (FrameLayout) container.findViewById(R.id.webview_wrapper);
562 wrapper.removeView(tab.getWebView());
563 }
564 }
565
Michael Kolb8233fac2010-10-26 16:08:53 -0700566 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800567 * create a sub window container and webview for the tab
568 * Note: this methods operates through side-effects for now
569 * it sets both the subView and subViewContainer for the given tab
570 * @param tab tab to create the sub window for
571 * @param subView webview to be set as a subwindow for the tab
572 */
573 @Override
574 public void createSubWindow(Tab tab, WebView subView) {
575 View subViewContainer = mActivity.getLayoutInflater().inflate(
576 R.layout.browser_subwindow, null);
577 ViewGroup inner = (ViewGroup) subViewContainer
578 .findViewById(R.id.inner_container);
579 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
580 LayoutParams.MATCH_PARENT));
581 final ImageButton cancel = (ImageButton) subViewContainer
582 .findViewById(R.id.subwindow_close);
583 final WebView cancelSubView = subView;
584 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800585 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800586 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800587 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800588 }
589 });
590 tab.setSubWebView(subView);
591 tab.setSubViewContainer(subViewContainer);
592 }
593
594 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700595 * Remove the sub window from the content view.
596 */
597 @Override
598 public void removeSubWindow(View subviewContainer) {
599 mContentView.removeView(subviewContainer);
600 mUiController.endActionMode();
601 }
602
603 /**
604 * Attach the sub window to the content view.
605 */
606 @Override
607 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800608 if (container.getParent() != null) {
609 // already attached, remove first
610 ((ViewGroup) container.getParent()).removeView(container);
611 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 mContentView.addView(container, COVER_SCREEN_PARAMS);
613 }
614
Michael Kolb11d19782011-03-20 10:17:40 -0700615 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700616 WebView web = getWebView();
617 if (web != null) {
618 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700619 }
620 }
621
Michael Kolb1f9b3562012-04-24 14:38:34 -0700622 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700623 if (mUiController.isInCustomActionMode()) {
624 mUiController.endActionMode();
625 }
626 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700627 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700628 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700629 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700630 }
631
Michael Kolb7cdc4902011-02-03 17:54:40 -0800632 boolean canShowTitleBar() {
633 return !isTitleBarShowing()
634 && !isActivityPaused()
635 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700636 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800637 && !mUiController.isInCustomActionMode();
638 }
639
John Reck0f602f32011-07-07 15:38:43 -0700640 protected void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700641 if (canShowTitleBar()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700642 mTitleBar.showTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700643 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800644 }
645
646 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700647 if (mTitleBar.isShowing()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700648 mTitleBar.enableTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700649 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800650 }
651
652 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700653 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800654 }
655
John Reck5d43ce82011-06-21 17:16:51 -0700656 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700657 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700658 }
659
Michael Kolb80f75082012-04-10 10:50:06 -0700660 public void stopEditingUrl() {
661 mTitleBar.getNavigationBar().stopEditingUrl();
662 }
663
John Reck0f602f32011-07-07 15:38:43 -0700664 public TitleBar getTitleBar() {
665 return mTitleBar;
666 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800667
Michael Kolb66706532010-12-12 19:50:22 -0800668 @Override
John Reck2bc80422011-06-30 15:11:49 -0700669 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700670 Intent intent = new Intent(mActivity, ComboViewActivity.class);
671 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
672 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
673 Tab t = getActiveTab();
674 if (t != null) {
675 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800676 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700677 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700678 }
679
680 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800681 public void hideComboView() {
682 }
683
684 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400685 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800686 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700687 // if a view already exists then immediately terminate the new one
688 if (mCustomView != null) {
689 callback.onCustomViewHidden();
690 return;
691 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400692 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700693 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400694 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700695 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400696 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700697 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700698 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400699 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 }
701
702 @Override
703 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700704 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700705 if (mCustomView == null)
706 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400707 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700708 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400709 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700711 mCustomViewCallback.onCustomViewHidden();
712 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400713 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700714 }
715
716 @Override
717 public boolean isCustomViewShowing() {
718 return mCustomView != null;
719 }
720
Michael Kolb66706532010-12-12 19:50:22 -0800721 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800722 if (mInputManager.isActive()) {
723 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
724 0);
725 }
726 }
727
Michael Kolb66706532010-12-12 19:50:22 -0800728 @Override
John Reck3ba45532011-08-11 16:26:53 -0700729 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700730 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800731 }
732
Tarun Nainani87a86682015-02-05 11:47:35 -0800733 @Override
734 public boolean isComboViewShowing() {
735 return false;
736 }
737
Site Mao61b68212015-07-16 10:56:31 -0700738 public static boolean isUiLowPowerMode() {
Site Mao7521b092015-07-20 18:27:20 -0700739 return BrowserCommandLine.hasSwitch("ui-low-power-mode")
740 || BrowserSettings.getInstance().isPowerSaveModeEnabled()
741 || BrowserSettings.getInstance().isDisablePerfFeatures();
Site Mao61b68212015-07-16 10:56:31 -0700742 }
743
Michael Kolb8233fac2010-10-26 16:08:53 -0700744 // -------------------------------------------------------------------------
745
Michael Kolb5a72f182011-01-13 20:35:06 -0800746 protected void updateNavigationState(Tab tab) {
747 }
748
Michael Kolb8233fac2010-10-26 16:08:53 -0700749 /**
750 * Update the lock icon to correspond to our latest state.
751 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700752 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800753 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700754 mNavigationBar.setSecurityState(t.getSecurityState());
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700755 setUrlTitle(t);
Michael Kolb8233fac2010-10-26 16:08:53 -0700756 }
757 }
758
John Reck30c714c2010-12-16 17:30:34 -0800759 protected void setUrlTitle(Tab tab) {
760 String url = tab.getUrl();
761 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800762 if (TextUtils.isEmpty(title)) {
763 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800764 }
Michael Kolb66706532010-12-12 19:50:22 -0800765 if (tab.inForeground()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700766 mNavigationBar.setDisplayTitle(title, url);
Michael Kolb66706532010-12-12 19:50:22 -0800767 }
768 }
769
770 // Set the favicon in the title bar.
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700771 public void setFavicon(Tab tab) {
772 mNavigationBar.showCurrentFavicon(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700773 }
774
Michael Kolb66706532010-12-12 19:50:22 -0800775 // active tabs page
776
777 public void showActiveTabsPage() {
778 }
779
780 /**
781 * Remove the active tabs page.
782 */
783 public void removeActiveTabsPage() {
784 }
785
Michael Kolb8233fac2010-10-26 16:08:53 -0700786 // menu handling callbacks
787
788 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800789 public boolean onPrepareOptionsMenu(Menu menu) {
790 return true;
791 }
792
793 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700794 public void updateMenuState(Tab tab, Menu menu) {
795 }
796
797 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700798 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700799 }
800
801 @Override
802 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700803 }
804
805 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700806 public boolean onOptionsItemSelected(MenuItem item) {
807 return false;
808 }
809
810 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700811 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700812 }
813
814 @Override
815 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700816 }
817
818 @Override
819 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700820 }
821
822 @Override
823 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700824 }
825
Michael Kolb8233fac2010-10-26 16:08:53 -0700826 // -------------------------------------------------------------------------
827 // Helper function for WebChromeClient
828 // -------------------------------------------------------------------------
829
830 @Override
831 public Bitmap getDefaultVideoPoster() {
832 if (mDefaultVideoPoster == null) {
833 mDefaultVideoPoster = BitmapFactory.decodeResource(
834 mActivity.getResources(), R.drawable.default_video_poster);
835 }
836 return mDefaultVideoPoster;
837 }
838
839 @Override
840 public View getVideoLoadingProgressView() {
841 if (mVideoProgressView == null) {
842 LayoutInflater inflater = LayoutInflater.from(mActivity);
843 mVideoProgressView = inflater.inflate(
844 R.layout.video_loading_progress, null);
845 }
846 return mVideoProgressView;
847 }
848
Michael Kolb843510f2010-12-09 10:51:49 -0800849 @Override
850 public void showMaxTabsWarning() {
851 Toast warning = Toast.makeText(mActivity,
852 mActivity.getString(R.string.max_tabs_warning),
853 Toast.LENGTH_SHORT);
854 warning.show();
855 }
856
Michael Kolb46f987e2011-04-05 10:39:10 -0700857 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800858
Michael Kolb46f987e2011-04-05 10:39:10 -0700859 if (mActiveTab != null) {
860 return mActiveTab.getWebView();
861 } else {
862 return null;
863 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700864 }
865
Pankaj Garg62bc7912015-04-14 16:08:59 -0700866 public void forceDisableFullscreenMode(boolean disabled) {
867 mFullscreenModeLocked = false;
868 setFullscreen(!disabled);
869 mFullscreenModeLocked = disabled;
870 }
871
Michael Kolbc38c6042011-04-27 10:46:06 -0700872 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700873 if (mFullscreenModeLocked)
874 return;
875
Michael Kolbc5675ad2011-10-21 13:34:28 -0700876 Window win = mActivity.getWindow();
877 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800878 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500879
880 if (mCustomView != null) {
881 mCustomView.setSystemUiVisibility(enabled ?
Sagar Dhawan55165b82015-09-03 15:33:02 -0700882 mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800883 } else if (Build.VERSION.SDK_INT >= 19) {
884 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan55165b82015-09-03 15:33:02 -0700885 mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700886 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500887 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800888 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700889 }
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700890 if (enabled) {
891 winParams.flags |= bits;
892 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500893 winParams.flags &= ~bits;
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700894 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500895
Michael Kolbc5675ad2011-10-21 13:34:28 -0700896 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700897 }
898
Denise LaFayetteda31d742014-10-10 18:03:13 -0400899 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700900 public void showFullscreen(boolean fullScreen) {
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700901
Sudheer Koganti24766882014-10-02 10:58:09 -0700902 //Hide/show system ui bar as needed
903 if (!BrowserSettings.getInstance().useFullscreen())
904 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700905 //Hide/show topbar as needed
906 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700907 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700908 if (fullScreen) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700909 // hide titlebar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700910 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700911 } else {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700912 // show titlebar
913 mTitleBar.showTopControls(false);
914 // enable auto hide titlebar
Sudheer Koganti24766882014-10-02 10:58:09 -0700915 if (!mTitleBar.isFixed())
Vivek Sekhard4de6162015-07-21 15:01:45 -0700916 mTitleBar.enableTopControls(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700917 }
918 }
919 }
920
Tarun Nainani8eb00912014-07-17 12:28:32 -0700921 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700922 if (mTitleBar == null || mTitleBar.isFixed())
923 return;
924 if (!mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700925 if (topControlsOffsetYPix != 0.0) {
926 mTitleBar.setEnabled(false);
927 } else {
928 mTitleBar.setEnabled(true);
929 }
Vivek Sekhard4de6162015-07-21 15:01:45 -0700930 float currentY = mTitleBar.getTranslationY();
Sagar Dhawan7fa89622016-01-04 17:58:02 -0800931 float height = mTitleBar.getHeight();
932 float shadowHeight = mActivity.getResources().getDimension(R.dimen.dropshadow_height);
933 height -= shadowHeight; //this is the height of the titlebar without the shadow
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700934
Vivek Sekhard4de6162015-07-21 15:01:45 -0700935 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
936 mTitleBar.requestLayout();
937 } else if ((height + topControlsOffsetYPix) <= 0) {
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700938 // Need to add the progress bar's margin to the offest since it's height is not
939 // accounted for and the dropshadow draws inside it.
Sagar Dhawan7fa89622016-01-04 17:58:02 -0800940 topControlsOffsetYPix -= shadowHeight;
Vivek Sekhard4de6162015-07-21 15:01:45 -0700941 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800942 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800943 // This was done to get HTML5 fullscreen API to work with fixed mode since
944 // topcontrols are used to implement HTML5 fullscreen
945 mTitleBar.setTranslationY(topControlsOffsetYPix);
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700946
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700947 }
948 }
949
John Reck0f602f32011-07-07 15:38:43 -0700950 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800951 if (ENABLE_BORDER_AROUND_FAVICON) {
952 Drawable[] array = new Drawable[3];
953 array[0] = new PaintDrawable(Color.BLACK);
954 PaintDrawable p = new PaintDrawable(Color.WHITE);
955 array[1] = p;
956 if (icon == null) {
957 array[2] = getGenericFavicon();
958 } else {
959 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
960 }
961 LayerDrawable d = new LayerDrawable(array);
962 d.setLayerInset(1, 1, 1, 1, 1);
963 d.setLayerInset(2, 2, 2, 2, 2);
964 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700965 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800966 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700967 }
968
John Reck5d43ce82011-06-21 17:16:51 -0700969 public boolean isLoading() {
970 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
971 }
972
Enrico Ros1f5a0952014-11-18 20:15:48 -0800973 protected void setMenuItemVisibility(Menu menu, int id,
974 boolean visibility) {
975 MenuItem item = menu.findItem(id);
976 if (item != null) {
977 item.setVisible(visibility);
978 }
979 }
980
John Reck9c5004e2011-10-07 16:00:12 -0700981 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700982
983 @Override
984 public void handleMessage(Message msg) {
John Reck9c5004e2011-10-07 16:00:12 -0700985 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700986 }
987 };
John Reck3ba45532011-08-11 16:26:53 -0700988
John Reck9c5004e2011-10-07 16:00:12 -0700989 protected void handleMessage(Message msg) {}
990
John Reck3ba45532011-08-11 16:26:53 -0700991 @Override
992 public void showWeb(boolean animate) {
993 mUiController.hideCustomView();
994 }
995
John Reck2711fab2012-05-18 21:38:59 -0700996 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800997 FrameLayout.LayoutParams params =
998 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700999 if (params.topMargin != margin) {
1000 params.topMargin = margin;
1001 mContentView.setLayoutParams(params);
1002 }
1003 }
Michael Kolbbae0cb22012-05-29 11:15:27 -07001004
1005 @Override
1006 public boolean blockFocusAnimations() {
1007 return mBlockFocusAnimations;
1008 }
1009
Michael Kolb0b129122012-06-04 16:31:58 -07001010 @Override
1011 public void onVoiceResult(String result) {
1012 mNavigationBar.onVoiceResult(result);
1013 }
1014
kaiyizbb2db872013-08-01 22:24:07 -04001015 protected UiController getUiController() {
1016 return mUiController;
1017 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001018
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001019 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001020 private float getActionModeHeight() {
1021 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1022 new int[] { android.R.attr.actionBarSize });
1023 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1024 actionBarSizeTypedArray.recycle();
1025 return size;
1026 }
1027
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001028
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001029 @Override
1030 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001031 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001032
1033 if (mTitleBar.isFixed()) {
1034 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001035 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001036 } else {
1037 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001038 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001039 }
1040
1041 @Override
1042 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001043 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001044 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001045 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001046 } else {
1047 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001048 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001049 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001050
1051 @Override
1052 public boolean shouldCaptureThumbnails() {
1053 return true;
1054 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001055}