blob: fd4f29408547c67ebd564de095430460b1c0f403 [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;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070052
Pankaj Garg18aa0a12015-06-22 11:06:12 -070053import org.codeaurora.swe.BrowserCommandLine;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080054import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070055
Michael Kolb1bf23132010-11-19 12:55:12 -080056import java.util.List;
57
Michael Kolb8233fac2010-10-26 16:08:53 -070058/**
59 * UI interface definitions
60 */
John Reck718a24d2011-08-12 11:08:30 -070061public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070062
Enrico Ros1f5a0952014-11-18 20:15:48 -080063 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070064
Michael Kolb66706532010-12-12 19:50:22 -080065 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070066 new FrameLayout.LayoutParams(
67 ViewGroup.LayoutParams.MATCH_PARENT,
68 ViewGroup.LayoutParams.MATCH_PARENT);
69
Michael Kolb66706532010-12-12 19:50:22 -080070 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070071 new FrameLayout.LayoutParams(
72 ViewGroup.LayoutParams.MATCH_PARENT,
73 ViewGroup.LayoutParams.MATCH_PARENT,
74 Gravity.CENTER);
75
76 Activity mActivity;
77 UiController mUiController;
78 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080079 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080080 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070081
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070082 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070083
Michael Kolb66706532010-12-12 19:50:22 -080084 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070085 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070086
Michael Kolb31065b12011-10-06 13:51:32 -070087 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080088 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040089 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070090
John Reck718a24d2011-08-12 11:08:30 -070091 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070092
Michael Kolb8233fac2010-10-26 16:08:53 -070093 // the default <video> poster
94 private Bitmap mDefaultVideoPoster;
95 // the video progress view
96 private View mVideoProgressView;
97
Sagar Dhawan1e040c72014-12-11 20:24:12 -080098 private final View mDecorView;
99
Michael Kolb8233fac2010-10-26 16:08:53 -0700100 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700101 protected TitleBar mTitleBar;
102 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700103 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700104 private boolean mFullscreenModeLocked;
Sagar Dhawan55165b82015-09-03 15:33:02 -0700105 private final static int mFullScreenImmersiveSetting =
106 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
107 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
108 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
109 View.SYSTEM_UI_FLAG_FULLSCREEN |
110 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Michael Kolb8233fac2010-10-26 16:08:53 -0700111
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700112 private EdgeSwipeController mEdgeSwipeController;
113 private EdgeSwipeSettings mEdgeSwipeSettings;
114
Sagar Dhawan55165b82015-09-03 15:33:02 -0700115 // This Runnable is used to re-set fullscreen mode after resume.
116 // The immersive mode API on android <6.0 is buggy and will more
117 // often then not glitch out. Using a runnable really helps reduce
118 // the repeatability of this framework bug, however some corner cases
119 // remain. Specifically when interacting with pop-up windows(menu).
120 private Runnable mFullScreenModeRunnable = new Runnable() {
121 @Override
122 public void run() {
123 if (BrowserSettings.getInstance() != null)
124 setFullscreen(BrowserSettings.getInstance().useFullscreen());
125 }
126 };
127
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 public BaseUi(Activity browser, UiController controller) {
129 mActivity = browser;
130 mUiController = controller;
131 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800132 mInputManager = (InputMethodManager)
133 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800134 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
135 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
137 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700138 LayoutInflater.from(mActivity)
139 .inflate(R.layout.custom_screen, frameLayout);
jrizzoli7924a0c2016-02-05 14:30:14 +0100140
141 // If looklock is enabled, set FLAG_SECURE
142 if (BrowserSettings.getInstance().isLookLockEnabled()) {
143 mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
144 WindowManager.LayoutParams.FLAG_SECURE);
145 } else {
146 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
147 }
148
John Reck7c6e1c92011-06-30 11:55:55 -0700149 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700150 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700151 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
152 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700153 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700154 mTitleBar = new TitleBar(mActivity, mUiController, this,
155 mContentView);
156 mTitleBar.setProgress(100);
157 mNavigationBar = mTitleBar.getNavigationBar();
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800158
159 // install system ui visibility listeners
160 mDecorView = mActivity.getWindow().getDecorView();
161 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700162 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 }
164
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800165 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
166 new View.OnSystemUiVisibilityChangeListener() {
167 @Override
168 public void onSystemUiVisibilityChange(int visFlags) {
Sagar Dhawan55165b82015-09-03 15:33:02 -0700169 final boolean lostFullscreen = (visFlags & mFullScreenImmersiveSetting) == 0;
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800170 if (lostFullscreen)
171 setFullscreen(BrowserSettings.getInstance().useFullscreen());
172 }
173 };
174
Michael Kolb8233fac2010-10-26 16:08:53 -0700175 private void cancelStopToast() {
176 if (mStopToast != null) {
177 mStopToast.cancel();
178 mStopToast = null;
179 }
180 }
181
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700182 protected Drawable getGenericFavicon() {
183 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800184 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700185 }
186 return mGenericFavicon;
187 }
188
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 // lifecycle
190
191 public void onPause() {
jrizzoli7924a0c2016-02-05 14:30:14 +0100192 if (BrowserSettings.getInstance().isLookLockEnabled()) {
193 mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
194 WindowManager.LayoutParams.FLAG_SECURE);
195 } else {
196 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
197 }
Michael Kolb7a5cf472010-11-30 13:23:53 -0800198 if (isCustomViewShowing()) {
199 onHideCustomView();
200 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500201 if (mTabControl.getCurrentTab() != null) {
202 mTabControl.getCurrentTab().exitFullscreen();
203 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700204 cancelStopToast();
205 mActivityPaused = true;
206 }
207
208 public void onResume() {
209 mActivityPaused = false;
jrizzoli7924a0c2016-02-05 14:30:14 +0100210 if (BrowserSettings.getInstance().isLookLockEnabled()) {
211 mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
212 WindowManager.LayoutParams.FLAG_SECURE);
213 } else {
214 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
215 }
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700216 // check if we exited without setting active tab
217 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800218 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Sagar Dhawan55165b82015-09-03 15:33:02 -0700219 //Work around for < Android M
220 if (Build.VERSION.SDK_INT <= 22 && BrowserSettings.getInstance().useFullscreen())
221 mHandler.postDelayed(mFullScreenModeRunnable, 500);
222
Michael Kolb1a4625a2011-08-24 13:40:44 -0700223 final Tab ct = mTabControl.getCurrentTab();
224 if (ct != null) {
225 setActiveTab(ct);
226 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700227 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 }
229
Michael Kolb66706532010-12-12 19:50:22 -0800230 protected boolean isActivityPaused() {
231 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700232 }
233
234 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700235 if (mEdgeSwipeController != null) {
236 mEdgeSwipeController.onConfigurationChanged();
237 }
238 if (mEdgeSwipeSettings != null) {
239 mEdgeSwipeSettings.onConfigurationChanged();
240 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 }
242
John Reck0f602f32011-07-07 15:38:43 -0700243 public Activity getActivity() {
244 return mActivity;
245 }
246
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 // key handling
248
249 @Override
250 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700251 if (mCustomView != null) {
252 mUiController.hideCustomView();
253 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700254 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700255 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700256 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 }
258 return false;
259 }
260
Vivek Sekhard4de6162015-07-21 15:01:45 -0700261 public boolean isFullScreen() {
262 if (mTabControl.getCurrentTab() != null)
263 return mTabControl.getCurrentTab().isTabFullScreen();
264 return false;
265 }
266
Michael Kolb2814a362011-05-19 15:49:41 -0700267 @Override
268 public boolean onMenuKey() {
269 return false;
270 }
271
John Reck30c714c2010-12-16 17:30:34 -0800272 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700273 @Override
John Reck30c714c2010-12-16 17:30:34 -0800274 public void onTabDataChanged(Tab tab) {
275 setUrlTitle(tab);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700276 updateTabSecurityState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800277 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700278 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700279 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700280 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700281 }
282
283 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700284 public void onProgressChanged(Tab tab) {
285 int progress = tab.getLoadProgress();
286 if (tab.inForeground()) {
Pankaj Gargf9040c82015-08-14 10:19:31 -0700287 if (tab.inPageLoad()) {
288 mTitleBar.setProgress(progress);
289 } else {
290 mTitleBar.setProgress(100);
291 }
Michael Kolbe8a82332012-04-25 14:14:26 -0700292 }
293 }
294
295 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500296 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800297 if (tab.inForeground()) {
298 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700299 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800300 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500301 }
302
303 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700304 public void onPageStopped(Tab tab) {
305 cancelStopToast();
306 if (tab.inForeground()) {
307 mStopToast = Toast
308 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
309 mStopToast.show();
310 }
311 }
312
313 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800314 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700315 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800316 }
317
318 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700319 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700320 }
321
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800322 public void cancelNavScreenRequest(){
323 }
324
Michael Kolb377ea312011-02-17 14:36:56 -0800325 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800326 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400327 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700328 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400329
Michael Kolbbae0cb22012-05-29 11:15:27 -0700330 // block unnecessary focus change animations during tab switch
331 mBlockFocusAnimations = true;
Michael Kolb77df4562010-11-19 14:49:34 -0800332 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400333 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700334 WebView web = mActiveTab.getWebView();
335 if (web != null) {
336 web.setOnTouchListener(null);
337 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700338 }
Michael Kolb77df4562010-11-19 14:49:34 -0800339 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800340
Michael Kolbda580632012-04-16 13:30:28 -0700341 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck5d43ce82011-06-21 17:16:51 -0700342 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700343 if (web != null) {
344 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700345 web.setTitleBar(mTitleBar);
346 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700347 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700348 }
Michael Kolb4923c222012-04-02 16:18:36 -0700349 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700350 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800351 onTabDataChanged(tab);
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700352 setFavicon(tab);
John Reck30c714c2010-12-16 17:30:34 -0800353 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700354 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700355 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400356
Vivek Sekhar943f0672014-05-01 18:35:22 -0700357 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700358
359 updateTabSecurityState(tab);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400360 }
361
362 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700363 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400364 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700365 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400366
Vivek Sekhar943f0672014-05-01 18:35:22 -0700367 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800368
369 if(tabToWaitFor == mTabToRemove) {
370 if (mRunnable != null) {
371 mTitleBar.removeCallbacks(mRunnable);
372 }
373 mTabToRemove = null;
374 mTabToWaitFor = null;
375 mRunnable = null;
376 return;
377 }
378
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400379 //remove previously scehduled tab
380 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700381 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700382 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400383 removeTabFromContentView(mTabToRemove);
384 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700385 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400386 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700387 mTabToRemove = tabToRemove;
388 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400389 mNumRemoveTries = 0;
390
391 if (mTabToRemove != null) {
392 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700393 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400394 }
395 }
396
397 protected void tryRemoveTab() {
398 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700399 // Ensure the webview is still valid
400 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
401 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700402 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700403 mRunnable = new Runnable() {
404 public void run() {
405 tryRemoveTab();
406 }
407 };
408 }
409 /*if the new tab is still not ready, wait another 2 frames
410 before trying again. 1 frame for the tab to render the first
411 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700412 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400413 return;
414 }
415 }
416 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700417 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700418 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400419 removeTabFromContentView(mTabToRemove);
420 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700421 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400422 }
423 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700424 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700425 }
426
Michael Kolbcfa3af52010-12-14 10:36:11 -0800427 Tab getActiveTab() {
428 return mActiveTab;
429 }
430
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800432 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800433 }
434
435 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700436 public void removeTab(Tab tab) {
Sagar Dhawan20b1deb2015-10-12 11:13:18 -0700437 removeTabFromContentView(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700438 }
439
440 @Override
441 public void detachTab(Tab tab) {
442 removeTabFromContentView(tab);
443 }
444
445 @Override
446 public void attachTab(Tab tab) {
447 attachTabToContentView(tab);
448 }
449
Michael Kolb377ea312011-02-17 14:36:56 -0800450 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800451 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700452 return;
453 }
454 View container = tab.getViewContainer();
455 WebView mainView = tab.getWebView();
456 // Attach the WebView to the container and then attach the
457 // container to the content view.
458 FrameLayout wrapper =
459 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700460 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
461
462 if (wrapper != parentView) {
463 // clean up old view before attaching new view
464 // this helping in fixing issues such touch event
465 // getting triggered on old view instead of new one
466 if (parentView != null) {
467 parentView.removeView(mainView.getView());
468 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800469 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700470 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800471 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 if (parent != mContentView) {
473 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700474 parent.removeView(container);
475 }
476 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700477 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700478
479 refreshEdgeSwipeController(container);
480
Michael Kolb8233fac2010-10-26 16:08:53 -0700481 mUiController.attachSubWindow(tab);
482 }
483
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700484 public void refreshEdgeSwipeController(View container) {
Site Mao61b68212015-07-16 10:56:31 -0700485 if (isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700486 return;
487 }
488
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700489 if (mEdgeSwipeController != null) {
490 mEdgeSwipeController.cleanup();
491 }
492
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700493 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
494
Sagar Dhawan05e3c352015-09-07 15:24:33 +0200495 if (mEdgeSwipeSettings != null) {
496 mEdgeSwipeSettings.cleanup();
497 }
498 mEdgeSwipeSettings = null;
499
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700500 if (action.equalsIgnoreCase(
501 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
502 mEdgeSwipeController = new EdgeSwipeController(
503 container,
504 R.id.stationary_navview,
505 R.id.sliding_navview,
506 R.id.sliding_navview_shadow,
507 R.id.navview_opacity,
508 R.id.webview_wrapper,
509 R.id.draggable_mainframe,
510 this);
511 } else if (action.equalsIgnoreCase(
512 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
513 mEdgeSwipeSettings = new EdgeSwipeSettings(
514 container,
515 R.id.stationary_navview,
516 R.id.edge_sliding_settings,
517 R.id.sliding_navview_shadow,
518 R.id.webview_wrapper,
519 R.id.draggable_mainframe,
520 this);
521 } else {
522 DraggableFrameLayout draggableView = (DraggableFrameLayout)
523 container.findViewById(R.id.draggable_mainframe);
524 draggableView.setDragHelper(null);
525 }
526 }
527
Michael Kolb8233fac2010-10-26 16:08:53 -0700528 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800529 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700530 // Remove the container that contains the main WebView.
531 WebView mainView = tab.getWebView();
532 View container = tab.getViewContainer();
533 if (mainView == null) {
534 return;
535 }
536 // Remove the container from the content and then remove the
537 // WebView from the container. This will trigger a focus change
538 // needed by WebView.
539 FrameLayout wrapper =
540 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800541 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700542 mContentView.removeView(container);
543 mUiController.endActionMode();
544 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 }
546
Michael Kolba713ec82010-11-29 17:27:06 -0800547 @Override
548 public void onSetWebView(Tab tab, WebView webView) {
549 View container = tab.getViewContainer();
550 if (container == null) {
551 // The tab consists of a container view, which contains the main
552 // WebView, as well as any other UI elements associated with the tab.
553 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700554 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800555 tab.setViewContainer(container);
556 }
557 if (tab.getWebView() != webView) {
558 // Just remove the old one.
559 FrameLayout wrapper =
560 (FrameLayout) container.findViewById(R.id.webview_wrapper);
561 wrapper.removeView(tab.getWebView());
562 }
563 }
564
Michael Kolb8233fac2010-10-26 16:08:53 -0700565 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800566 * create a sub window container and webview for the tab
567 * Note: this methods operates through side-effects for now
568 * it sets both the subView and subViewContainer for the given tab
569 * @param tab tab to create the sub window for
570 * @param subView webview to be set as a subwindow for the tab
571 */
572 @Override
573 public void createSubWindow(Tab tab, WebView subView) {
574 View subViewContainer = mActivity.getLayoutInflater().inflate(
575 R.layout.browser_subwindow, null);
576 ViewGroup inner = (ViewGroup) subViewContainer
577 .findViewById(R.id.inner_container);
578 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
579 LayoutParams.MATCH_PARENT));
580 final ImageButton cancel = (ImageButton) subViewContainer
581 .findViewById(R.id.subwindow_close);
582 final WebView cancelSubView = subView;
583 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800584 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800585 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800586 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800587 }
588 });
589 tab.setSubWebView(subView);
590 tab.setSubViewContainer(subViewContainer);
591 }
592
593 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700594 * Remove the sub window from the content view.
595 */
596 @Override
597 public void removeSubWindow(View subviewContainer) {
598 mContentView.removeView(subviewContainer);
599 mUiController.endActionMode();
600 }
601
602 /**
603 * Attach the sub window to the content view.
604 */
605 @Override
606 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800607 if (container.getParent() != null) {
608 // already attached, remove first
609 ((ViewGroup) container.getParent()).removeView(container);
610 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 mContentView.addView(container, COVER_SCREEN_PARAMS);
612 }
613
Michael Kolb11d19782011-03-20 10:17:40 -0700614 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700615 WebView web = getWebView();
616 if (web != null) {
617 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700618 }
619 }
620
Michael Kolb1f9b3562012-04-24 14:38:34 -0700621 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700622 if (mUiController.isInCustomActionMode()) {
623 mUiController.endActionMode();
624 }
625 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700626 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700627 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700628 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700629 }
630
Michael Kolb7cdc4902011-02-03 17:54:40 -0800631 boolean canShowTitleBar() {
632 return !isTitleBarShowing()
633 && !isActivityPaused()
634 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700635 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800636 && !mUiController.isInCustomActionMode();
637 }
638
John Reck0f602f32011-07-07 15:38:43 -0700639 protected void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700640 if (canShowTitleBar()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700641 mTitleBar.showTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700642 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800643 }
644
645 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700646 if (mTitleBar.isShowing()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700647 mTitleBar.enableTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700648 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800649 }
650
651 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700652 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800653 }
654
John Reck5d43ce82011-06-21 17:16:51 -0700655 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700656 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700657 }
658
Michael Kolb80f75082012-04-10 10:50:06 -0700659 public void stopEditingUrl() {
660 mTitleBar.getNavigationBar().stopEditingUrl();
661 }
662
John Reck0f602f32011-07-07 15:38:43 -0700663 public TitleBar getTitleBar() {
664 return mTitleBar;
665 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800666
Michael Kolb66706532010-12-12 19:50:22 -0800667 @Override
John Reck2bc80422011-06-30 15:11:49 -0700668 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700669 Intent intent = new Intent(mActivity, ComboViewActivity.class);
670 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
671 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
672 Tab t = getActiveTab();
673 if (t != null) {
674 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800675 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700676 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 }
678
679 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800680 public void hideComboView() {
681 }
682
683 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400684 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800685 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 // if a view already exists then immediately terminate the new one
687 if (mCustomView != null) {
688 callback.onCustomViewHidden();
689 return;
690 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400691 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700692 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400693 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700694 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400695 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700696 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700697 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400698 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 }
700
701 @Override
702 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700703 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 if (mCustomView == null)
705 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400706 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700707 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400708 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700709 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 mCustomViewCallback.onCustomViewHidden();
711 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400712 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700713 }
714
715 @Override
716 public boolean isCustomViewShowing() {
717 return mCustomView != null;
718 }
719
Michael Kolb66706532010-12-12 19:50:22 -0800720 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800721 if (mInputManager.isActive()) {
722 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
723 0);
724 }
725 }
726
Michael Kolb66706532010-12-12 19:50:22 -0800727 @Override
John Reck3ba45532011-08-11 16:26:53 -0700728 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700729 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800730 }
731
Tarun Nainani87a86682015-02-05 11:47:35 -0800732 @Override
733 public boolean isComboViewShowing() {
734 return false;
735 }
736
Site Mao61b68212015-07-16 10:56:31 -0700737 public static boolean isUiLowPowerMode() {
Site Mao7521b092015-07-20 18:27:20 -0700738 return BrowserCommandLine.hasSwitch("ui-low-power-mode")
739 || BrowserSettings.getInstance().isPowerSaveModeEnabled()
740 || BrowserSettings.getInstance().isDisablePerfFeatures();
Site Mao61b68212015-07-16 10:56:31 -0700741 }
742
Michael Kolb8233fac2010-10-26 16:08:53 -0700743 // -------------------------------------------------------------------------
744
Michael Kolb5a72f182011-01-13 20:35:06 -0800745 protected void updateNavigationState(Tab tab) {
746 }
747
Michael Kolb8233fac2010-10-26 16:08:53 -0700748 /**
749 * Update the lock icon to correspond to our latest state.
750 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700751 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800752 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700753 mNavigationBar.setSecurityState(t.getSecurityState());
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700754 setUrlTitle(t);
Michael Kolb8233fac2010-10-26 16:08:53 -0700755 }
756 }
757
John Reck30c714c2010-12-16 17:30:34 -0800758 protected void setUrlTitle(Tab tab) {
759 String url = tab.getUrl();
760 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800761 if (TextUtils.isEmpty(title)) {
762 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800763 }
Michael Kolb66706532010-12-12 19:50:22 -0800764 if (tab.inForeground()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700765 mNavigationBar.setDisplayTitle(title, url);
Michael Kolb66706532010-12-12 19:50:22 -0800766 }
767 }
768
769 // Set the favicon in the title bar.
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700770 public void setFavicon(Tab tab) {
771 mNavigationBar.showCurrentFavicon(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700772 }
773
Michael Kolb66706532010-12-12 19:50:22 -0800774 // active tabs page
775
776 public void showActiveTabsPage() {
777 }
778
779 /**
780 * Remove the active tabs page.
781 */
782 public void removeActiveTabsPage() {
783 }
784
Michael Kolb8233fac2010-10-26 16:08:53 -0700785 // menu handling callbacks
786
787 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800788 public boolean onPrepareOptionsMenu(Menu menu) {
789 return true;
790 }
791
792 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700793 public void updateMenuState(Tab tab, Menu menu) {
794 }
795
796 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700797 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700798 }
799
800 @Override
801 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700802 }
803
804 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700805 public boolean onOptionsItemSelected(MenuItem item) {
806 return false;
807 }
808
809 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700810 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700811 }
812
813 @Override
814 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700815 }
816
817 @Override
818 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700819 }
820
821 @Override
822 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700823 }
824
Michael Kolb8233fac2010-10-26 16:08:53 -0700825 // -------------------------------------------------------------------------
826 // Helper function for WebChromeClient
827 // -------------------------------------------------------------------------
828
829 @Override
830 public Bitmap getDefaultVideoPoster() {
831 if (mDefaultVideoPoster == null) {
832 mDefaultVideoPoster = BitmapFactory.decodeResource(
833 mActivity.getResources(), R.drawable.default_video_poster);
834 }
835 return mDefaultVideoPoster;
836 }
837
838 @Override
839 public View getVideoLoadingProgressView() {
840 if (mVideoProgressView == null) {
841 LayoutInflater inflater = LayoutInflater.from(mActivity);
842 mVideoProgressView = inflater.inflate(
843 R.layout.video_loading_progress, null);
844 }
845 return mVideoProgressView;
846 }
847
Michael Kolb843510f2010-12-09 10:51:49 -0800848 @Override
849 public void showMaxTabsWarning() {
850 Toast warning = Toast.makeText(mActivity,
851 mActivity.getString(R.string.max_tabs_warning),
852 Toast.LENGTH_SHORT);
853 warning.show();
854 }
855
Michael Kolb46f987e2011-04-05 10:39:10 -0700856 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800857
Michael Kolb46f987e2011-04-05 10:39:10 -0700858 if (mActiveTab != null) {
859 return mActiveTab.getWebView();
860 } else {
861 return null;
862 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700863 }
864
Pankaj Garg62bc7912015-04-14 16:08:59 -0700865 public void forceDisableFullscreenMode(boolean disabled) {
866 mFullscreenModeLocked = false;
867 setFullscreen(!disabled);
868 mFullscreenModeLocked = disabled;
869 }
870
Michael Kolbc38c6042011-04-27 10:46:06 -0700871 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700872 if (mFullscreenModeLocked)
873 return;
874
Michael Kolbc5675ad2011-10-21 13:34:28 -0700875 Window win = mActivity.getWindow();
876 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800877 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500878
879 if (mCustomView != null) {
880 mCustomView.setSystemUiVisibility(enabled ?
Sagar Dhawan55165b82015-09-03 15:33:02 -0700881 mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800882 } else if (Build.VERSION.SDK_INT >= 19) {
883 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan55165b82015-09-03 15:33:02 -0700884 mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700885 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500886 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800887 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700888 }
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700889 if (enabled) {
890 winParams.flags |= bits;
891 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500892 winParams.flags &= ~bits;
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700893 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500894
Michael Kolbc5675ad2011-10-21 13:34:28 -0700895 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700896 }
897
Denise LaFayetteda31d742014-10-10 18:03:13 -0400898 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700899 public void showFullscreen(boolean fullScreen) {
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700900
Sudheer Koganti24766882014-10-02 10:58:09 -0700901 //Hide/show system ui bar as needed
902 if (!BrowserSettings.getInstance().useFullscreen())
903 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700904 //Hide/show topbar as needed
905 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700906 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700907 if (fullScreen) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700908 // hide titlebar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700909 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700910 } else {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700911 // show titlebar
912 mTitleBar.showTopControls(false);
913 // enable auto hide titlebar
Sudheer Koganti24766882014-10-02 10:58:09 -0700914 if (!mTitleBar.isFixed())
Vivek Sekhard4de6162015-07-21 15:01:45 -0700915 mTitleBar.enableTopControls(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700916 }
917 }
918 }
919
Tarun Nainani8eb00912014-07-17 12:28:32 -0700920 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700921 if (mTitleBar == null || mTitleBar.isFixed())
922 return;
923 if (!mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700924 if (topControlsOffsetYPix != 0.0) {
925 mTitleBar.setEnabled(false);
926 } else {
927 mTitleBar.setEnabled(true);
928 }
Vivek Sekhard4de6162015-07-21 15:01:45 -0700929 float currentY = mTitleBar.getTranslationY();
Sagar Dhawan7fa89622016-01-04 17:58:02 -0800930 float height = mTitleBar.getHeight();
931 float shadowHeight = mActivity.getResources().getDimension(R.dimen.dropshadow_height);
932 height -= shadowHeight; //this is the height of the titlebar without the shadow
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700933
Vivek Sekhard4de6162015-07-21 15:01:45 -0700934 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
935 mTitleBar.requestLayout();
936 } else if ((height + topControlsOffsetYPix) <= 0) {
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700937 // Need to add the progress bar's margin to the offest since it's height is not
938 // accounted for and the dropshadow draws inside it.
Sagar Dhawan7fa89622016-01-04 17:58:02 -0800939 topControlsOffsetYPix -= shadowHeight;
Vivek Sekhard4de6162015-07-21 15:01:45 -0700940 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800941 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800942 // This was done to get HTML5 fullscreen API to work with fixed mode since
943 // topcontrols are used to implement HTML5 fullscreen
944 mTitleBar.setTranslationY(topControlsOffsetYPix);
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700945
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700946 }
947 }
948
John Reck0f602f32011-07-07 15:38:43 -0700949 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800950 if (ENABLE_BORDER_AROUND_FAVICON) {
951 Drawable[] array = new Drawable[3];
952 array[0] = new PaintDrawable(Color.BLACK);
953 PaintDrawable p = new PaintDrawable(Color.WHITE);
954 array[1] = p;
955 if (icon == null) {
956 array[2] = getGenericFavicon();
957 } else {
958 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
959 }
960 LayerDrawable d = new LayerDrawable(array);
961 d.setLayerInset(1, 1, 1, 1, 1);
962 d.setLayerInset(2, 2, 2, 2, 2);
963 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700964 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800965 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700966 }
967
John Reck5d43ce82011-06-21 17:16:51 -0700968 public boolean isLoading() {
969 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
970 }
971
Enrico Ros1f5a0952014-11-18 20:15:48 -0800972 protected void setMenuItemVisibility(Menu menu, int id,
973 boolean visibility) {
974 MenuItem item = menu.findItem(id);
975 if (item != null) {
976 item.setVisible(visibility);
977 }
978 }
979
John Reck9c5004e2011-10-07 16:00:12 -0700980 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700981
982 @Override
983 public void handleMessage(Message msg) {
John Reck9c5004e2011-10-07 16:00:12 -0700984 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700985 }
986 };
John Reck3ba45532011-08-11 16:26:53 -0700987
John Reck9c5004e2011-10-07 16:00:12 -0700988 protected void handleMessage(Message msg) {}
989
John Reck3ba45532011-08-11 16:26:53 -0700990 @Override
991 public void showWeb(boolean animate) {
992 mUiController.hideCustomView();
993 }
994
John Reck2711fab2012-05-18 21:38:59 -0700995 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800996 FrameLayout.LayoutParams params =
997 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700998 if (params.topMargin != margin) {
999 params.topMargin = margin;
1000 mContentView.setLayoutParams(params);
1001 }
1002 }
Michael Kolbbae0cb22012-05-29 11:15:27 -07001003
1004 @Override
1005 public boolean blockFocusAnimations() {
1006 return mBlockFocusAnimations;
1007 }
1008
Michael Kolb0b129122012-06-04 16:31:58 -07001009 @Override
1010 public void onVoiceResult(String result) {
1011 mNavigationBar.onVoiceResult(result);
1012 }
1013
kaiyizbb2db872013-08-01 22:24:07 -04001014 protected UiController getUiController() {
1015 return mUiController;
1016 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001017
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001018 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001019 private float getActionModeHeight() {
1020 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1021 new int[] { android.R.attr.actionBarSize });
1022 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1023 actionBarSizeTypedArray.recycle();
1024 return size;
1025 }
1026
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001027
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001028 @Override
1029 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001030 mInActionMode = true;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001031 }
1032
1033 @Override
1034 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001035 mInActionMode = false;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001036 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001037
1038 @Override
1039 public boolean shouldCaptureThumbnails() {
1040 return true;
1041 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001042}