blob: 2d7c0b38960ae1de9b49a091810e8184769da15c [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb8233fac2010-10-26 16:08:53 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
John Reckd3e4d5b2011-07-13 15:48:43 -070020import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.content.res.Configuration;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.graphics.Bitmap;
23import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070024import android.graphics.Color;
25import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070027import android.graphics.drawable.LayerDrawable;
28import android.graphics.drawable.PaintDrawable;
Sagar Dhawan1e040c72014-12-11 20:24:12 -080029import android.os.Build;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070031import android.os.Handler;
32import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070034import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.Gravity;
36import android.view.LayoutInflater;
37import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070038import android.view.MenuItem;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080040import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070043import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080046import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080048import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070050import android.content.res.TypedArray;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070051
Bijan Amirzada41242f22014-03-21 12:12:18 -070052import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080053
54import 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
John Reck5d43ce82011-06-21 17:16:51 -070076 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070077 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070078
Michael Kolb8233fac2010-10-26 16:08:53 -070079 Activity mActivity;
80 UiController mUiController;
81 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080082 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080083 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070084
Steve Block2466eff2011-10-03 15:33:09 +010085 private Drawable mLockIconSecure;
86 private Drawable mLockIconMixed;
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070087 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Michael Kolb66706532010-12-12 19:50:22 -080089 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070090 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb31065b12011-10-06 13:51:32 -070092 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080093 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040094 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
John Reck718a24d2011-08-12 11:08:30 -070096 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070097
John Reck718a24d2011-08-12 11:08:30 -070098 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070099
Michael Kolb8233fac2010-10-26 16:08:53 -0700100 // the default <video> poster
101 private Bitmap mDefaultVideoPoster;
102 // the video progress view
103 private View mVideoProgressView;
104
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800105 private final View mDecorView;
106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700108 protected TitleBar mTitleBar;
109 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700110 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700111 private boolean mFullscreenModeLocked;
Michael Kolb8233fac2010-10-26 16:08:53 -0700112
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700113 private EdgeSwipeController mEdgeSwipeController;
114 private EdgeSwipeSettings mEdgeSwipeSettings;
115
Michael Kolb8233fac2010-10-26 16:08:53 -0700116 public BaseUi(Activity browser, UiController controller) {
117 mActivity = browser;
118 mUiController = controller;
119 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800120 mInputManager = (InputMethodManager)
121 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800122 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
123 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700124 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
125 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700126 LayoutInflater.from(mActivity)
127 .inflate(R.layout.custom_screen, frameLayout);
128 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700129 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700130 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
131 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700132 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700133 mTitleBar = new TitleBar(mActivity, mUiController, this,
134 mContentView);
135 mTitleBar.setProgress(100);
136 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700137 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800138
139 // install system ui visibility listeners
140 mDecorView = mActivity.getWindow().getDecorView();
141 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700142 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700143 }
144
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800145 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
146 new View.OnSystemUiVisibilityChangeListener() {
147 @Override
148 public void onSystemUiVisibilityChange(int visFlags) {
149 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
150 if (lostFullscreen)
151 setFullscreen(BrowserSettings.getInstance().useFullscreen());
152 }
153 };
154
Michael Kolb8233fac2010-10-26 16:08:53 -0700155 private void cancelStopToast() {
156 if (mStopToast != null) {
157 mStopToast.cancel();
158 mStopToast = null;
159 }
160 }
161
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700162 private Drawable getLockIconSecure() {
163 if (mLockIconSecure == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700164 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700165 }
166 return mLockIconSecure;
167 }
168
169 private Drawable getLockIconMixed() {
170 if (mLockIconMixed == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700171 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure_partial);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700172 }
173 return mLockIconMixed;
174 }
175
176 protected Drawable getGenericFavicon() {
177 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800178 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700179 }
180 return mGenericFavicon;
181 }
182
Michael Kolb8233fac2010-10-26 16:08:53 -0700183 // lifecycle
184
185 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800186 if (isCustomViewShowing()) {
187 onHideCustomView();
188 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500189 if (mTabControl.getCurrentTab() != null) {
190 mTabControl.getCurrentTab().exitFullscreen();
191 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700192 cancelStopToast();
193 mActivityPaused = true;
194 }
195
196 public void onResume() {
197 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700198 // check if we exited without setting active tab
199 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800200 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700201 final Tab ct = mTabControl.getCurrentTab();
202 if (ct != null) {
203 setActiveTab(ct);
204 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700205 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700206 }
207
Michael Kolb66706532010-12-12 19:50:22 -0800208 protected boolean isActivityPaused() {
209 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700210 }
211
212 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700213 if (mEdgeSwipeController != null) {
214 mEdgeSwipeController.onConfigurationChanged();
215 }
216 if (mEdgeSwipeSettings != null) {
217 mEdgeSwipeSettings.onConfigurationChanged();
218 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 }
220
John Reck0f602f32011-07-07 15:38:43 -0700221 public Activity getActivity() {
222 return mActivity;
223 }
224
Michael Kolb8233fac2010-10-26 16:08:53 -0700225 // key handling
226
227 @Override
228 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700229 if (mCustomView != null) {
230 mUiController.hideCustomView();
231 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700232 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700233 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700234 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 }
236 return false;
237 }
238
Michael Kolb2814a362011-05-19 15:49:41 -0700239 @Override
240 public boolean onMenuKey() {
241 return false;
242 }
243
John Reck30c714c2010-12-16 17:30:34 -0800244 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700245 @Override
John Reck30c714c2010-12-16 17:30:34 -0800246 public void onTabDataChanged(Tab tab) {
247 setUrlTitle(tab);
248 setFavicon(tab);
249 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800250 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700251 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700252 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700253 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 }
255
256 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700257 public void onProgressChanged(Tab tab) {
258 int progress = tab.getLoadProgress();
259 if (tab.inForeground()) {
260 mTitleBar.setProgress(progress);
261 }
262 }
263
264 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500265 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800266 if (tab.inForeground()) {
267 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700268 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800269 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500270 }
271
272 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700273 public void onPageStopped(Tab tab) {
274 cancelStopToast();
275 if (tab.inForeground()) {
276 mStopToast = Toast
277 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
278 mStopToast.show();
279 }
280 }
281
282 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800283 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700284 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800285 }
286
287 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700288 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700289 }
290
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800291 public void cancelNavScreenRequest(){
292 }
293
Michael Kolb377ea312011-02-17 14:36:56 -0800294 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800295 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400296 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700297 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400298
Michael Kolbbae0cb22012-05-29 11:15:27 -0700299 // block unnecessary focus change animations during tab switch
300 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700301 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800302 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400303 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700304 WebView web = mActiveTab.getWebView();
305 if (web != null) {
306 web.setOnTouchListener(null);
307 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700308 }
Michael Kolb77df4562010-11-19 14:49:34 -0800309 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800310
Michael Kolbda580632012-04-16 13:30:28 -0700311 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700312 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700313 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700314 if (web != null) {
315 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700316 web.setTitleBar(mTitleBar);
317 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700318 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700319 }
Michael Kolb4923c222012-04-02 16:18:36 -0700320 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700321 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800322 onTabDataChanged(tab);
323 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700324 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700325 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400326
Vivek Sekhar943f0672014-05-01 18:35:22 -0700327 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400328 }
329
330 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700331 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400332 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700333 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400334
Vivek Sekhar943f0672014-05-01 18:35:22 -0700335 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800336
337 if(tabToWaitFor == mTabToRemove) {
338 if (mRunnable != null) {
339 mTitleBar.removeCallbacks(mRunnable);
340 }
341 mTabToRemove = null;
342 mTabToWaitFor = null;
343 mRunnable = null;
344 return;
345 }
346
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400347 //remove previously scehduled tab
348 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700349 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700350 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400351 removeTabFromContentView(mTabToRemove);
352 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700353 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400354 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700355 mTabToRemove = tabToRemove;
356 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400357 mNumRemoveTries = 0;
358
359 if (mTabToRemove != null) {
360 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700361 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400362 }
363 }
364
365 protected void tryRemoveTab() {
366 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700367 // Ensure the webview is still valid
368 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
369 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700370 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700371 mRunnable = new Runnable() {
372 public void run() {
373 tryRemoveTab();
374 }
375 };
376 }
377 /*if the new tab is still not ready, wait another 2 frames
378 before trying again. 1 frame for the tab to render the first
379 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700380 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400381 return;
382 }
383 }
384 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700385 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700386 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400387 removeTabFromContentView(mTabToRemove);
388 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700389 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400390 }
391 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700392 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700393 }
394
John Reck718a24d2011-08-12 11:08:30 -0700395 protected void updateUrlBarAutoShowManagerTarget() {
396 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700397 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700398 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700399 }
400 }
401
Michael Kolbcfa3af52010-12-14 10:36:11 -0800402 Tab getActiveTab() {
403 return mActiveTab;
404 }
405
Michael Kolb8233fac2010-10-26 16:08:53 -0700406 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800407 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800408 }
409
410 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700411 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800412 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700413 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800414 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700415 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 }
417
418 @Override
419 public void detachTab(Tab tab) {
420 removeTabFromContentView(tab);
421 }
422
423 @Override
424 public void attachTab(Tab tab) {
425 attachTabToContentView(tab);
426 }
427
Michael Kolb377ea312011-02-17 14:36:56 -0800428 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800429 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700430 return;
431 }
432 View container = tab.getViewContainer();
433 WebView mainView = tab.getWebView();
434 // Attach the WebView to the container and then attach the
435 // container to the content view.
436 FrameLayout wrapper =
437 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700438 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
439
440 if (wrapper != parentView) {
441 // clean up old view before attaching new view
442 // this helping in fixing issues such touch event
443 // getting triggered on old view instead of new one
444 if (parentView != null) {
445 parentView.removeView(mainView.getView());
446 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800447 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700448 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800449 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700450 if (parent != mContentView) {
451 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700452 parent.removeView(container);
453 }
454 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700455 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700456
457 refreshEdgeSwipeController(container);
458
Michael Kolb8233fac2010-10-26 16:08:53 -0700459 mUiController.attachSubWindow(tab);
460 }
461
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700462 public void refreshEdgeSwipeController(View container) {
463 if (mEdgeSwipeController != null) {
464 mEdgeSwipeController.cleanup();
465 }
466
467 mEdgeSwipeSettings = null;
468
469 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
470
471 if (action.equalsIgnoreCase(
472 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
473 mEdgeSwipeController = new EdgeSwipeController(
474 container,
475 R.id.stationary_navview,
476 R.id.sliding_navview,
477 R.id.sliding_navview_shadow,
478 R.id.navview_opacity,
479 R.id.webview_wrapper,
480 R.id.draggable_mainframe,
481 this);
482 } else if (action.equalsIgnoreCase(
483 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
484 mEdgeSwipeSettings = new EdgeSwipeSettings(
485 container,
486 R.id.stationary_navview,
487 R.id.edge_sliding_settings,
488 R.id.sliding_navview_shadow,
489 R.id.webview_wrapper,
490 R.id.draggable_mainframe,
491 this);
492 } else {
493 DraggableFrameLayout draggableView = (DraggableFrameLayout)
494 container.findViewById(R.id.draggable_mainframe);
495 draggableView.setDragHelper(null);
496 }
497 }
498
Michael Kolb8233fac2010-10-26 16:08:53 -0700499 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800500 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700501 // Remove the container that contains the main WebView.
502 WebView mainView = tab.getWebView();
503 View container = tab.getViewContainer();
504 if (mainView == null) {
505 return;
506 }
507 // Remove the container from the content and then remove the
508 // WebView from the container. This will trigger a focus change
509 // needed by WebView.
510 FrameLayout wrapper =
511 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800512 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700513 mContentView.removeView(container);
514 mUiController.endActionMode();
515 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700516 }
517
Michael Kolba713ec82010-11-29 17:27:06 -0800518 @Override
519 public void onSetWebView(Tab tab, WebView webView) {
520 View container = tab.getViewContainer();
521 if (container == null) {
522 // The tab consists of a container view, which contains the main
523 // WebView, as well as any other UI elements associated with the tab.
524 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700525 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800526 tab.setViewContainer(container);
527 }
528 if (tab.getWebView() != webView) {
529 // Just remove the old one.
530 FrameLayout wrapper =
531 (FrameLayout) container.findViewById(R.id.webview_wrapper);
532 wrapper.removeView(tab.getWebView());
533 }
534 }
535
Michael Kolb8233fac2010-10-26 16:08:53 -0700536 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800537 * create a sub window container and webview for the tab
538 * Note: this methods operates through side-effects for now
539 * it sets both the subView and subViewContainer for the given tab
540 * @param tab tab to create the sub window for
541 * @param subView webview to be set as a subwindow for the tab
542 */
543 @Override
544 public void createSubWindow(Tab tab, WebView subView) {
545 View subViewContainer = mActivity.getLayoutInflater().inflate(
546 R.layout.browser_subwindow, null);
547 ViewGroup inner = (ViewGroup) subViewContainer
548 .findViewById(R.id.inner_container);
549 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
550 LayoutParams.MATCH_PARENT));
551 final ImageButton cancel = (ImageButton) subViewContainer
552 .findViewById(R.id.subwindow_close);
553 final WebView cancelSubView = subView;
554 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800555 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800556 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800557 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800558 }
559 });
560 tab.setSubWebView(subView);
561 tab.setSubViewContainer(subViewContainer);
562 }
563
564 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700565 * Remove the sub window from the content view.
566 */
567 @Override
568 public void removeSubWindow(View subviewContainer) {
569 mContentView.removeView(subviewContainer);
570 mUiController.endActionMode();
571 }
572
573 /**
574 * Attach the sub window to the content view.
575 */
576 @Override
577 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800578 if (container.getParent() != null) {
579 // already attached, remove first
580 ((ViewGroup) container.getParent()).removeView(container);
581 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700582 mContentView.addView(container, COVER_SCREEN_PARAMS);
583 }
584
Michael Kolb11d19782011-03-20 10:17:40 -0700585 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700586 WebView web = getWebView();
587 if (web != null) {
588 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700589 }
590 }
591
Michael Kolb1f9b3562012-04-24 14:38:34 -0700592 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700593 if (mUiController.isInCustomActionMode()) {
594 mUiController.endActionMode();
595 }
596 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700597 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700598 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700599 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700600 }
601
Michael Kolb7cdc4902011-02-03 17:54:40 -0800602 boolean canShowTitleBar() {
603 return !isTitleBarShowing()
604 && !isActivityPaused()
605 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700606 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800607 && !mUiController.isInCustomActionMode();
608 }
609
John Reck0f602f32011-07-07 15:38:43 -0700610 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700611 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700612 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700613 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700614 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800615 }
616
617 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700618 if (mTitleBar.isShowing()) {
619 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700620 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800621 }
622
623 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700624 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800625 }
626
John Reck5d43ce82011-06-21 17:16:51 -0700627 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700628 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700629 }
630
Michael Kolb80f75082012-04-10 10:50:06 -0700631 public void stopEditingUrl() {
632 mTitleBar.getNavigationBar().stopEditingUrl();
633 }
634
John Reck0f602f32011-07-07 15:38:43 -0700635 public TitleBar getTitleBar() {
636 return mTitleBar;
637 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800638
Michael Kolb66706532010-12-12 19:50:22 -0800639 @Override
John Reck2bc80422011-06-30 15:11:49 -0700640 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700641 Intent intent = new Intent(mActivity, ComboViewActivity.class);
642 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
643 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
644 Tab t = getActiveTab();
645 if (t != null) {
646 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800647 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700648 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700649 }
650
651 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800652 public void hideComboView() {
653 }
654
655 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400656 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800657 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 // if a view already exists then immediately terminate the new one
659 if (mCustomView != null) {
660 callback.onCustomViewHidden();
661 return;
662 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400663 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700664 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400665 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700666 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400667 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700668 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400670 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 }
672
673 @Override
674 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700675 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 if (mCustomView == null)
677 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400678 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700679 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400680 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700681 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700682 mCustomViewCallback.onCustomViewHidden();
683 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400684 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700685 }
686
687 @Override
688 public boolean isCustomViewShowing() {
689 return mCustomView != null;
690 }
691
Michael Kolb66706532010-12-12 19:50:22 -0800692 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800693 if (mInputManager.isActive()) {
694 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
695 0);
696 }
697 }
698
Michael Kolb66706532010-12-12 19:50:22 -0800699 @Override
John Reck3ba45532011-08-11 16:26:53 -0700700 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700701 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800702 }
703
Tarun Nainani87a86682015-02-05 11:47:35 -0800704 @Override
705 public boolean isComboViewShowing() {
706 return false;
707 }
708
Michael Kolb8233fac2010-10-26 16:08:53 -0700709 // -------------------------------------------------------------------------
710
Michael Kolb5a72f182011-01-13 20:35:06 -0800711 protected void updateNavigationState(Tab tab) {
712 }
713
Michael Kolb8233fac2010-10-26 16:08:53 -0700714 /**
715 * Update the lock icon to correspond to our latest state.
716 */
Michael Kolb66706532010-12-12 19:50:22 -0800717 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800718 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100719 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700720 }
721 }
722
723 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700724 * Updates the lock-icon image in the title-bar.
725 */
Steve Block2466eff2011-10-03 15:33:09 +0100726 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700727 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100728 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700729 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100730 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
731 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
732 // TODO: It would be good to have different icons for insecure vs mixed content.
733 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700734 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700735 }
John Reck0f602f32011-07-07 15:38:43 -0700736 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700737 }
738
John Reck30c714c2010-12-16 17:30:34 -0800739 protected void setUrlTitle(Tab tab) {
740 String url = tab.getUrl();
741 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800742 if (TextUtils.isEmpty(title)) {
743 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800744 }
Michael Kolb66706532010-12-12 19:50:22 -0800745 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700746 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800747 }
748 }
749
750 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800751 protected void setFavicon(Tab tab) {
752 if (tab.inForeground()) {
753 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700754 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800755 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700756 }
757
Michael Kolb66706532010-12-12 19:50:22 -0800758 // active tabs page
759
760 public void showActiveTabsPage() {
761 }
762
763 /**
764 * Remove the active tabs page.
765 */
766 public void removeActiveTabsPage() {
767 }
768
Michael Kolb8233fac2010-10-26 16:08:53 -0700769 // menu handling callbacks
770
771 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800772 public boolean onPrepareOptionsMenu(Menu menu) {
773 return true;
774 }
775
776 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700777 public void updateMenuState(Tab tab, Menu menu) {
778 }
779
780 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700781 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700782 }
783
784 @Override
785 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700786 }
787
788 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700789 public boolean onOptionsItemSelected(MenuItem item) {
790 return false;
791 }
792
793 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700794 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700795 }
796
797 @Override
798 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700799 }
800
801 @Override
802 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700803 }
804
805 @Override
806 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700807 }
808
Michael Kolb8233fac2010-10-26 16:08:53 -0700809 // -------------------------------------------------------------------------
810 // Helper function for WebChromeClient
811 // -------------------------------------------------------------------------
812
813 @Override
814 public Bitmap getDefaultVideoPoster() {
815 if (mDefaultVideoPoster == null) {
816 mDefaultVideoPoster = BitmapFactory.decodeResource(
817 mActivity.getResources(), R.drawable.default_video_poster);
818 }
819 return mDefaultVideoPoster;
820 }
821
822 @Override
823 public View getVideoLoadingProgressView() {
824 if (mVideoProgressView == null) {
825 LayoutInflater inflater = LayoutInflater.from(mActivity);
826 mVideoProgressView = inflater.inflate(
827 R.layout.video_loading_progress, null);
828 }
829 return mVideoProgressView;
830 }
831
Michael Kolb843510f2010-12-09 10:51:49 -0800832 @Override
833 public void showMaxTabsWarning() {
834 Toast warning = Toast.makeText(mActivity,
835 mActivity.getString(R.string.max_tabs_warning),
836 Toast.LENGTH_SHORT);
837 warning.show();
838 }
839
Michael Kolb46f987e2011-04-05 10:39:10 -0700840 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800841
Michael Kolb46f987e2011-04-05 10:39:10 -0700842 if (mActiveTab != null) {
843 return mActiveTab.getWebView();
844 } else {
845 return null;
846 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700847 }
848
Pankaj Garg62bc7912015-04-14 16:08:59 -0700849 public void forceDisableFullscreenMode(boolean disabled) {
850 mFullscreenModeLocked = false;
851 setFullscreen(!disabled);
852 mFullscreenModeLocked = disabled;
853 }
854
Michael Kolbc38c6042011-04-27 10:46:06 -0700855 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700856 if (mFullscreenModeLocked)
857 return;
858
Michael Kolbc5675ad2011-10-21 13:34:28 -0700859 Window win = mActivity.getWindow();
860 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800861 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500862 final int fullscreenImmersiveSetting =
863 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
864 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
865 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
866 View.SYSTEM_UI_FLAG_FULLSCREEN |
867 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
868
869 if (mCustomView != null) {
870 mCustomView.setSystemUiVisibility(enabled ?
871 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800872 } else if (Build.VERSION.SDK_INT >= 19) {
873 mContentView.setSystemUiVisibility(enabled ?
874 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700875 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500876 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800877 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700878 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500879 if (enabled)
880 winParams.flags |= bits;
881 else
882 winParams.flags &= ~bits;
883
Michael Kolbc5675ad2011-10-21 13:34:28 -0700884 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700885 }
886
Denise LaFayetteda31d742014-10-10 18:03:13 -0400887 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700888 public void showFullscreen(boolean fullScreen) {
889 //Hide/show system ui bar as needed
890 if (!BrowserSettings.getInstance().useFullscreen())
891 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700892 //Hide/show topbar as needed
893 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700894 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700895 if (fullScreen) {
896 //hide topbar
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700897 bwv.enableTopControls(false);
Vivek Sekhare337acf2015-04-02 21:00:48 -0700898 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700899 } else {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700900 bwv.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700901 //show the topbar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700902 mTitleBar.showTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700903 //enable for auto-hide
904 if (!mTitleBar.isFixed())
Vivek Sekhare337acf2015-04-02 21:00:48 -0700905 mTitleBar.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700906 }
907 }
908 }
909
Tarun Nainani8eb00912014-07-17 12:28:32 -0700910 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700911 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700912 if (topControlsOffsetYPix != 0.0) {
913 mTitleBar.setEnabled(false);
914 } else {
915 mTitleBar.setEnabled(true);
916 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800917 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800918 float currentY = mTitleBar.getTranslationY();
Devdeep Choudhury904c7062015-03-17 19:47:29 -0700919 float height = mNavigationBar.getHeight();
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800920 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
921 mTitleBar.requestLayout();
922 } else if ((height + topControlsOffsetYPix) <= 0) {
923 topControlsOffsetYPix -= 1;
924 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
925 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800926 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800927 // This was done to get HTML5 fullscreen API to work with fixed mode since
928 // topcontrols are used to implement HTML5 fullscreen
929 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700930 }
931 }
932
John Reck0f602f32011-07-07 15:38:43 -0700933 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800934 if (ENABLE_BORDER_AROUND_FAVICON) {
935 Drawable[] array = new Drawable[3];
936 array[0] = new PaintDrawable(Color.BLACK);
937 PaintDrawable p = new PaintDrawable(Color.WHITE);
938 array[1] = p;
939 if (icon == null) {
940 array[2] = getGenericFavicon();
941 } else {
942 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
943 }
944 LayerDrawable d = new LayerDrawable(array);
945 d.setLayerInset(1, 1, 1, 1, 1);
946 d.setLayerInset(2, 2, 2, 2, 2);
947 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700948 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800949 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700950 }
951
John Reck5d43ce82011-06-21 17:16:51 -0700952 public boolean isLoading() {
953 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
954 }
955
956 /**
957 * Suggest to the UI that the title bar can be hidden. The UI will then
958 * decide whether or not to hide based off a number of factors, such
959 * as if the user is editing the URL bar or if the page is loading
960 */
961 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700962 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
963 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700964 hideTitleBar();
965 }
966 }
967
John Reckbc6adb42011-09-01 18:03:20 -0700968 protected final void showTitleBarForDuration() {
969 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
970 }
971
972 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700973 showTitleBar();
974 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700975 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700976 }
977
Enrico Ros1f5a0952014-11-18 20:15:48 -0800978 protected void setMenuItemVisibility(Menu menu, int id,
979 boolean visibility) {
980 MenuItem item = menu.findItem(id);
981 if (item != null) {
982 item.setVisible(visibility);
983 }
984 }
985
John Reck9c5004e2011-10-07 16:00:12 -0700986 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700987
988 @Override
989 public void handleMessage(Message msg) {
990 if (msg.what == MSG_HIDE_TITLEBAR) {
991 suggestHideTitleBar();
992 }
John Reck9c5004e2011-10-07 16:00:12 -0700993 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700994 }
995 };
John Reck3ba45532011-08-11 16:26:53 -0700996
John Reck9c5004e2011-10-07 16:00:12 -0700997 protected void handleMessage(Message msg) {}
998
John Reck3ba45532011-08-11 16:26:53 -0700999 @Override
1000 public void showWeb(boolean animate) {
1001 mUiController.hideCustomView();
1002 }
1003
John Reck2711fab2012-05-18 21:38:59 -07001004 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -08001005 FrameLayout.LayoutParams params =
1006 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -07001007 if (params.topMargin != margin) {
1008 params.topMargin = margin;
1009 mContentView.setLayoutParams(params);
1010 }
1011 }
Michael Kolbbae0cb22012-05-29 11:15:27 -07001012
1013 @Override
1014 public boolean blockFocusAnimations() {
1015 return mBlockFocusAnimations;
1016 }
1017
Michael Kolb0b129122012-06-04 16:31:58 -07001018 @Override
1019 public void onVoiceResult(String result) {
1020 mNavigationBar.onVoiceResult(result);
1021 }
1022
kaiyizbb2db872013-08-01 22:24:07 -04001023 protected UiController getUiController() {
1024 return mUiController;
1025 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001026
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001027 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001028 private float getActionModeHeight() {
1029 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1030 new int[] { android.R.attr.actionBarSize });
1031 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1032 actionBarSizeTypedArray.recycle();
1033 return size;
1034 }
1035
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001036
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001037 @Override
1038 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001039 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001040
1041 if (mTitleBar.isFixed()) {
1042 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001043 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001044 } else {
1045 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001046 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001047 }
1048
1049 @Override
1050 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001051 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001052 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001053 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001054 } else {
1055 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001056 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001057 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001058}