blob: c24cc48098df4b44608629867fa883e047aba13c [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;
Michael Kolb8233fac2010-10-26 16:08:53 -0700111
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700112 private EdgeSwipeController mEdgeSwipeController;
113 private EdgeSwipeSettings mEdgeSwipeSettings;
114
Michael Kolb8233fac2010-10-26 16:08:53 -0700115 public BaseUi(Activity browser, UiController controller) {
116 mActivity = browser;
117 mUiController = controller;
118 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800119 mInputManager = (InputMethodManager)
120 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800121 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
122 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700123 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
124 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700125 LayoutInflater.from(mActivity)
126 .inflate(R.layout.custom_screen, frameLayout);
127 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700129 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
130 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700131 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700132 mTitleBar = new TitleBar(mActivity, mUiController, this,
133 mContentView);
134 mTitleBar.setProgress(100);
135 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700136 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800137
138 // install system ui visibility listeners
139 mDecorView = mActivity.getWindow().getDecorView();
140 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Michael Kolb8233fac2010-10-26 16:08:53 -0700141 }
142
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800143 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
144 new View.OnSystemUiVisibilityChangeListener() {
145 @Override
146 public void onSystemUiVisibilityChange(int visFlags) {
147 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
148 if (lostFullscreen)
149 setFullscreen(BrowserSettings.getInstance().useFullscreen());
150 }
151 };
152
Michael Kolb8233fac2010-10-26 16:08:53 -0700153 private void cancelStopToast() {
154 if (mStopToast != null) {
155 mStopToast.cancel();
156 mStopToast = null;
157 }
158 }
159
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700160 private Drawable getLockIconSecure() {
161 if (mLockIconSecure == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700162 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700163 }
164 return mLockIconSecure;
165 }
166
167 private Drawable getLockIconMixed() {
168 if (mLockIconMixed == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700169 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure_partial);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700170 }
171 return mLockIconMixed;
172 }
173
174 protected Drawable getGenericFavicon() {
175 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800176 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700177 }
178 return mGenericFavicon;
179 }
180
Michael Kolb8233fac2010-10-26 16:08:53 -0700181 // lifecycle
182
183 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800184 if (isCustomViewShowing()) {
185 onHideCustomView();
186 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500187 if (mTabControl.getCurrentTab() != null) {
188 mTabControl.getCurrentTab().exitFullscreen();
189 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 cancelStopToast();
191 mActivityPaused = true;
192 }
193
194 public void onResume() {
195 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700196 // check if we exited without setting active tab
197 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800198 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700199 final Tab ct = mTabControl.getCurrentTab();
200 if (ct != null) {
201 setActiveTab(ct);
202 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700203 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700204 }
205
Michael Kolb66706532010-12-12 19:50:22 -0800206 protected boolean isActivityPaused() {
207 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700208 }
209
210 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700211 if (mEdgeSwipeController != null) {
212 mEdgeSwipeController.onConfigurationChanged();
213 }
214 if (mEdgeSwipeSettings != null) {
215 mEdgeSwipeSettings.onConfigurationChanged();
216 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 }
218
John Reck0f602f32011-07-07 15:38:43 -0700219 public Activity getActivity() {
220 return mActivity;
221 }
222
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 // key handling
224
225 @Override
226 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 if (mCustomView != null) {
228 mUiController.hideCustomView();
229 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700230 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700231 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700232 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 }
234 return false;
235 }
236
Michael Kolb2814a362011-05-19 15:49:41 -0700237 @Override
238 public boolean onMenuKey() {
239 return false;
240 }
241
John Reck30c714c2010-12-16 17:30:34 -0800242 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 @Override
John Reck30c714c2010-12-16 17:30:34 -0800244 public void onTabDataChanged(Tab tab) {
245 setUrlTitle(tab);
246 setFavicon(tab);
247 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800248 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700249 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700250 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700251 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 }
253
254 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700255 public void onProgressChanged(Tab tab) {
256 int progress = tab.getLoadProgress();
257 if (tab.inForeground()) {
258 mTitleBar.setProgress(progress);
259 }
260 }
261
262 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500263 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800264 if (tab.inForeground()) {
265 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700266 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800267 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500268 }
269
270 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 public void onPageStopped(Tab tab) {
272 cancelStopToast();
273 if (tab.inForeground()) {
274 mStopToast = Toast
275 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
276 mStopToast.show();
277 }
278 }
279
280 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800281 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700282 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800283 }
284
285 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700286 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700287 }
288
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800289 public void cancelNavScreenRequest(){
290 }
291
Michael Kolb377ea312011-02-17 14:36:56 -0800292 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800293 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400294 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700295 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400296
Michael Kolbbae0cb22012-05-29 11:15:27 -0700297 // block unnecessary focus change animations during tab switch
298 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700299 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800300 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400301 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700302 WebView web = mActiveTab.getWebView();
303 if (web != null) {
304 web.setOnTouchListener(null);
305 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700306 }
Michael Kolb77df4562010-11-19 14:49:34 -0800307 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800308
Michael Kolbda580632012-04-16 13:30:28 -0700309 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700310 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700311 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700312 if (web != null) {
313 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700314 web.setTitleBar(mTitleBar);
315 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700316 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700317 }
Michael Kolb4923c222012-04-02 16:18:36 -0700318 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700319 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800320 onTabDataChanged(tab);
321 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700322 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700323 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400324
Vivek Sekhar943f0672014-05-01 18:35:22 -0700325 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400326 }
327
328 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700329 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400330 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700331 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400332
Vivek Sekhar943f0672014-05-01 18:35:22 -0700333 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800334
335 if(tabToWaitFor == mTabToRemove) {
336 if (mRunnable != null) {
337 mTitleBar.removeCallbacks(mRunnable);
338 }
339 mTabToRemove = null;
340 mTabToWaitFor = null;
341 mRunnable = null;
342 return;
343 }
344
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400345 //remove previously scehduled tab
346 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700347 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700348 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400349 removeTabFromContentView(mTabToRemove);
350 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700351 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400352 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700353 mTabToRemove = tabToRemove;
354 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400355 mNumRemoveTries = 0;
356
357 if (mTabToRemove != null) {
358 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700359 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400360 }
361 }
362
363 protected void tryRemoveTab() {
364 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700365 // Ensure the webview is still valid
366 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
367 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700368 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700369 mRunnable = new Runnable() {
370 public void run() {
371 tryRemoveTab();
372 }
373 };
374 }
375 /*if the new tab is still not ready, wait another 2 frames
376 before trying again. 1 frame for the tab to render the first
377 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700378 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400379 return;
380 }
381 }
382 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700383 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700384 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400385 removeTabFromContentView(mTabToRemove);
386 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700387 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400388 }
389 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700390 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700391 }
392
John Reck718a24d2011-08-12 11:08:30 -0700393 protected void updateUrlBarAutoShowManagerTarget() {
394 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700395 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700396 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700397 }
398 }
399
Michael Kolbcfa3af52010-12-14 10:36:11 -0800400 Tab getActiveTab() {
401 return mActiveTab;
402 }
403
Michael Kolb8233fac2010-10-26 16:08:53 -0700404 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800405 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800406 }
407
408 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700409 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800410 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700411 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800412 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700413 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700414 }
415
416 @Override
417 public void detachTab(Tab tab) {
418 removeTabFromContentView(tab);
419 }
420
421 @Override
422 public void attachTab(Tab tab) {
423 attachTabToContentView(tab);
424 }
425
Michael Kolb377ea312011-02-17 14:36:56 -0800426 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800427 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 return;
429 }
430 View container = tab.getViewContainer();
431 WebView mainView = tab.getWebView();
432 // Attach the WebView to the container and then attach the
433 // container to the content view.
434 FrameLayout wrapper =
435 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700436 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
437
438 if (wrapper != parentView) {
439 // clean up old view before attaching new view
440 // this helping in fixing issues such touch event
441 // getting triggered on old view instead of new one
442 if (parentView != null) {
443 parentView.removeView(mainView.getView());
444 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800445 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700446 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800447 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700448 if (parent != mContentView) {
449 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700450 parent.removeView(container);
451 }
452 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700453 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700454
455 refreshEdgeSwipeController(container);
456
Michael Kolb8233fac2010-10-26 16:08:53 -0700457 mUiController.attachSubWindow(tab);
458 }
459
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700460 public void refreshEdgeSwipeController(View container) {
461 if (mEdgeSwipeController != null) {
462 mEdgeSwipeController.cleanup();
463 }
464
465 mEdgeSwipeSettings = null;
466
467 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
468
469 if (action.equalsIgnoreCase(
470 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
471 mEdgeSwipeController = new EdgeSwipeController(
472 container,
473 R.id.stationary_navview,
474 R.id.sliding_navview,
475 R.id.sliding_navview_shadow,
476 R.id.navview_opacity,
477 R.id.webview_wrapper,
478 R.id.draggable_mainframe,
479 this);
480 } else if (action.equalsIgnoreCase(
481 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
482 mEdgeSwipeSettings = new EdgeSwipeSettings(
483 container,
484 R.id.stationary_navview,
485 R.id.edge_sliding_settings,
486 R.id.sliding_navview_shadow,
487 R.id.webview_wrapper,
488 R.id.draggable_mainframe,
489 this);
490 } else {
491 DraggableFrameLayout draggableView = (DraggableFrameLayout)
492 container.findViewById(R.id.draggable_mainframe);
493 draggableView.setDragHelper(null);
494 }
495 }
496
Michael Kolb8233fac2010-10-26 16:08:53 -0700497 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800498 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700499 // Remove the container that contains the main WebView.
500 WebView mainView = tab.getWebView();
501 View container = tab.getViewContainer();
502 if (mainView == null) {
503 return;
504 }
505 // Remove the container from the content and then remove the
506 // WebView from the container. This will trigger a focus change
507 // needed by WebView.
508 FrameLayout wrapper =
509 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800510 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700511 mContentView.removeView(container);
512 mUiController.endActionMode();
513 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700514 }
515
Michael Kolba713ec82010-11-29 17:27:06 -0800516 @Override
517 public void onSetWebView(Tab tab, WebView webView) {
518 View container = tab.getViewContainer();
519 if (container == null) {
520 // The tab consists of a container view, which contains the main
521 // WebView, as well as any other UI elements associated with the tab.
522 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700523 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800524 tab.setViewContainer(container);
525 }
526 if (tab.getWebView() != webView) {
527 // Just remove the old one.
528 FrameLayout wrapper =
529 (FrameLayout) container.findViewById(R.id.webview_wrapper);
530 wrapper.removeView(tab.getWebView());
531 }
532 }
533
Michael Kolb8233fac2010-10-26 16:08:53 -0700534 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800535 * create a sub window container and webview for the tab
536 * Note: this methods operates through side-effects for now
537 * it sets both the subView and subViewContainer for the given tab
538 * @param tab tab to create the sub window for
539 * @param subView webview to be set as a subwindow for the tab
540 */
541 @Override
542 public void createSubWindow(Tab tab, WebView subView) {
543 View subViewContainer = mActivity.getLayoutInflater().inflate(
544 R.layout.browser_subwindow, null);
545 ViewGroup inner = (ViewGroup) subViewContainer
546 .findViewById(R.id.inner_container);
547 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
548 LayoutParams.MATCH_PARENT));
549 final ImageButton cancel = (ImageButton) subViewContainer
550 .findViewById(R.id.subwindow_close);
551 final WebView cancelSubView = subView;
552 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800553 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800554 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800555 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800556 }
557 });
558 tab.setSubWebView(subView);
559 tab.setSubViewContainer(subViewContainer);
560 }
561
562 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700563 * Remove the sub window from the content view.
564 */
565 @Override
566 public void removeSubWindow(View subviewContainer) {
567 mContentView.removeView(subviewContainer);
568 mUiController.endActionMode();
569 }
570
571 /**
572 * Attach the sub window to the content view.
573 */
574 @Override
575 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800576 if (container.getParent() != null) {
577 // already attached, remove first
578 ((ViewGroup) container.getParent()).removeView(container);
579 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 mContentView.addView(container, COVER_SCREEN_PARAMS);
581 }
582
Michael Kolb11d19782011-03-20 10:17:40 -0700583 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700584 WebView web = getWebView();
585 if (web != null) {
586 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700587 }
588 }
589
Michael Kolb1f9b3562012-04-24 14:38:34 -0700590 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700591 if (mUiController.isInCustomActionMode()) {
592 mUiController.endActionMode();
593 }
594 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700595 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700596 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700597 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700598 }
599
Michael Kolb7cdc4902011-02-03 17:54:40 -0800600 boolean canShowTitleBar() {
601 return !isTitleBarShowing()
602 && !isActivityPaused()
603 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700604 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800605 && !mUiController.isInCustomActionMode();
606 }
607
John Reck0f602f32011-07-07 15:38:43 -0700608 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700609 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700610 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700611 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700612 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800613 }
614
615 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700616 if (mTitleBar.isShowing()) {
617 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700618 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800619 }
620
621 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700622 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800623 }
624
John Reck5d43ce82011-06-21 17:16:51 -0700625 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700626 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700627 }
628
Michael Kolb80f75082012-04-10 10:50:06 -0700629 public void stopEditingUrl() {
630 mTitleBar.getNavigationBar().stopEditingUrl();
631 }
632
John Reck0f602f32011-07-07 15:38:43 -0700633 public TitleBar getTitleBar() {
634 return mTitleBar;
635 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800636
Michael Kolb66706532010-12-12 19:50:22 -0800637 @Override
John Reck2bc80422011-06-30 15:11:49 -0700638 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700639 Intent intent = new Intent(mActivity, ComboViewActivity.class);
640 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
641 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
642 Tab t = getActiveTab();
643 if (t != null) {
644 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800645 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700646 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700647 }
648
649 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800650 public void hideComboView() {
651 }
652
653 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400654 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800655 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 // if a view already exists then immediately terminate the new one
657 if (mCustomView != null) {
658 callback.onCustomViewHidden();
659 return;
660 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400661 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700662 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400663 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700664 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400665 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700666 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700667 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400668 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 }
670
671 @Override
672 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700673 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700674 if (mCustomView == null)
675 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400676 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700677 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400678 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700679 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700680 mCustomViewCallback.onCustomViewHidden();
681 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400682 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700683 }
684
685 @Override
686 public boolean isCustomViewShowing() {
687 return mCustomView != null;
688 }
689
Michael Kolb66706532010-12-12 19:50:22 -0800690 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800691 if (mInputManager.isActive()) {
692 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
693 0);
694 }
695 }
696
Michael Kolb66706532010-12-12 19:50:22 -0800697 @Override
John Reck3ba45532011-08-11 16:26:53 -0700698 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700699 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800700 }
701
Tarun Nainani87a86682015-02-05 11:47:35 -0800702 @Override
703 public boolean isComboViewShowing() {
704 return false;
705 }
706
Michael Kolb8233fac2010-10-26 16:08:53 -0700707 // -------------------------------------------------------------------------
708
Michael Kolb5a72f182011-01-13 20:35:06 -0800709 protected void updateNavigationState(Tab tab) {
710 }
711
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 /**
713 * Update the lock icon to correspond to our latest state.
714 */
Michael Kolb66706532010-12-12 19:50:22 -0800715 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800716 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100717 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700718 }
719 }
720
721 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700722 * Updates the lock-icon image in the title-bar.
723 */
Steve Block2466eff2011-10-03 15:33:09 +0100724 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100726 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700727 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100728 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
729 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
730 // TODO: It would be good to have different icons for insecure vs mixed content.
731 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700732 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700733 }
John Reck0f602f32011-07-07 15:38:43 -0700734 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700735 }
736
John Reck30c714c2010-12-16 17:30:34 -0800737 protected void setUrlTitle(Tab tab) {
738 String url = tab.getUrl();
739 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800740 if (TextUtils.isEmpty(title)) {
741 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800742 }
Michael Kolb66706532010-12-12 19:50:22 -0800743 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700744 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800745 }
746 }
747
748 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800749 protected void setFavicon(Tab tab) {
750 if (tab.inForeground()) {
751 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700752 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800753 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700754 }
755
Michael Kolb66706532010-12-12 19:50:22 -0800756 // active tabs page
757
758 public void showActiveTabsPage() {
759 }
760
761 /**
762 * Remove the active tabs page.
763 */
764 public void removeActiveTabsPage() {
765 }
766
Michael Kolb8233fac2010-10-26 16:08:53 -0700767 // menu handling callbacks
768
769 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800770 public boolean onPrepareOptionsMenu(Menu menu) {
771 return true;
772 }
773
774 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700775 public void updateMenuState(Tab tab, Menu menu) {
776 }
777
778 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700779 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700780 }
781
782 @Override
783 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700784 }
785
786 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700787 public boolean onOptionsItemSelected(MenuItem item) {
788 return false;
789 }
790
791 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700792 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700793 }
794
795 @Override
796 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700797 }
798
799 @Override
800 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700801 }
802
803 @Override
804 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700805 }
806
Michael Kolb8233fac2010-10-26 16:08:53 -0700807 // -------------------------------------------------------------------------
808 // Helper function for WebChromeClient
809 // -------------------------------------------------------------------------
810
811 @Override
812 public Bitmap getDefaultVideoPoster() {
813 if (mDefaultVideoPoster == null) {
814 mDefaultVideoPoster = BitmapFactory.decodeResource(
815 mActivity.getResources(), R.drawable.default_video_poster);
816 }
817 return mDefaultVideoPoster;
818 }
819
820 @Override
821 public View getVideoLoadingProgressView() {
822 if (mVideoProgressView == null) {
823 LayoutInflater inflater = LayoutInflater.from(mActivity);
824 mVideoProgressView = inflater.inflate(
825 R.layout.video_loading_progress, null);
826 }
827 return mVideoProgressView;
828 }
829
Michael Kolb843510f2010-12-09 10:51:49 -0800830 @Override
831 public void showMaxTabsWarning() {
832 Toast warning = Toast.makeText(mActivity,
833 mActivity.getString(R.string.max_tabs_warning),
834 Toast.LENGTH_SHORT);
835 warning.show();
836 }
837
Michael Kolb46f987e2011-04-05 10:39:10 -0700838 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800839
Michael Kolb46f987e2011-04-05 10:39:10 -0700840 if (mActiveTab != null) {
841 return mActiveTab.getWebView();
842 } else {
843 return null;
844 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700845 }
846
Michael Kolbc38c6042011-04-27 10:46:06 -0700847 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700848 Window win = mActivity.getWindow();
849 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800850 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500851 final int fullscreenImmersiveSetting =
852 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
853 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
854 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
855 View.SYSTEM_UI_FLAG_FULLSCREEN |
856 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
857
858 if (mCustomView != null) {
859 mCustomView.setSystemUiVisibility(enabled ?
860 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800861 } else if (Build.VERSION.SDK_INT >= 19) {
862 mContentView.setSystemUiVisibility(enabled ?
863 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700864 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500865 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800866 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700867 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500868 if (enabled)
869 winParams.flags |= bits;
870 else
871 winParams.flags &= ~bits;
872
Michael Kolbc5675ad2011-10-21 13:34:28 -0700873 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700874 }
875
Denise LaFayetteda31d742014-10-10 18:03:13 -0400876 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700877 public void showFullscreen(boolean fullScreen) {
878 //Hide/show system ui bar as needed
879 if (!BrowserSettings.getInstance().useFullscreen())
880 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700881 //Hide/show topbar as needed
882 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700883 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700884 if (fullScreen) {
885 //hide topbar
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700886 bwv.enableTopControls(false);
Vivek Sekhare337acf2015-04-02 21:00:48 -0700887 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700888 } else {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700889 bwv.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700890 //show the topbar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700891 mTitleBar.showTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700892 //enable for auto-hide
893 if (!mTitleBar.isFixed())
Vivek Sekhare337acf2015-04-02 21:00:48 -0700894 mTitleBar.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700895 }
896 }
897 }
898
Tarun Nainani8eb00912014-07-17 12:28:32 -0700899 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700900 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700901 if (topControlsOffsetYPix != 0.0) {
902 mTitleBar.setEnabled(false);
903 } else {
904 mTitleBar.setEnabled(true);
905 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800906 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800907 float currentY = mTitleBar.getTranslationY();
Devdeep Choudhury904c7062015-03-17 19:47:29 -0700908 float height = mNavigationBar.getHeight();
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800909 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
910 mTitleBar.requestLayout();
911 } else if ((height + topControlsOffsetYPix) <= 0) {
912 topControlsOffsetYPix -= 1;
913 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
914 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800915 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800916 // This was done to get HTML5 fullscreen API to work with fixed mode since
917 // topcontrols are used to implement HTML5 fullscreen
918 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700919 }
920 }
921
John Reck0f602f32011-07-07 15:38:43 -0700922 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800923 if (ENABLE_BORDER_AROUND_FAVICON) {
924 Drawable[] array = new Drawable[3];
925 array[0] = new PaintDrawable(Color.BLACK);
926 PaintDrawable p = new PaintDrawable(Color.WHITE);
927 array[1] = p;
928 if (icon == null) {
929 array[2] = getGenericFavicon();
930 } else {
931 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
932 }
933 LayerDrawable d = new LayerDrawable(array);
934 d.setLayerInset(1, 1, 1, 1, 1);
935 d.setLayerInset(2, 2, 2, 2, 2);
936 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700937 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800938 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700939 }
940
John Reck5d43ce82011-06-21 17:16:51 -0700941 public boolean isLoading() {
942 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
943 }
944
945 /**
946 * Suggest to the UI that the title bar can be hidden. The UI will then
947 * decide whether or not to hide based off a number of factors, such
948 * as if the user is editing the URL bar or if the page is loading
949 */
950 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700951 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
952 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700953 hideTitleBar();
954 }
955 }
956
John Reckbc6adb42011-09-01 18:03:20 -0700957 protected final void showTitleBarForDuration() {
958 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
959 }
960
961 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700962 showTitleBar();
963 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700964 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700965 }
966
Enrico Ros1f5a0952014-11-18 20:15:48 -0800967 protected void setMenuItemVisibility(Menu menu, int id,
968 boolean visibility) {
969 MenuItem item = menu.findItem(id);
970 if (item != null) {
971 item.setVisible(visibility);
972 }
973 }
974
John Reck9c5004e2011-10-07 16:00:12 -0700975 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700976
977 @Override
978 public void handleMessage(Message msg) {
979 if (msg.what == MSG_HIDE_TITLEBAR) {
980 suggestHideTitleBar();
981 }
John Reck9c5004e2011-10-07 16:00:12 -0700982 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700983 }
984 };
John Reck3ba45532011-08-11 16:26:53 -0700985
John Reck9c5004e2011-10-07 16:00:12 -0700986 protected void handleMessage(Message msg) {}
987
John Reck3ba45532011-08-11 16:26:53 -0700988 @Override
989 public void showWeb(boolean animate) {
990 mUiController.hideCustomView();
991 }
992
John Reck2711fab2012-05-18 21:38:59 -0700993 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800994 FrameLayout.LayoutParams params =
995 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700996 if (params.topMargin != margin) {
997 params.topMargin = margin;
998 mContentView.setLayoutParams(params);
999 }
1000 }
Michael Kolbbae0cb22012-05-29 11:15:27 -07001001
1002 @Override
1003 public boolean blockFocusAnimations() {
1004 return mBlockFocusAnimations;
1005 }
1006
Michael Kolb0b129122012-06-04 16:31:58 -07001007 @Override
1008 public void onVoiceResult(String result) {
1009 mNavigationBar.onVoiceResult(result);
1010 }
1011
kaiyizbb2db872013-08-01 22:24:07 -04001012 protected UiController getUiController() {
1013 return mUiController;
1014 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001015
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001016 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001017 private float getActionModeHeight() {
1018 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1019 new int[] { android.R.attr.actionBarSize });
1020 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1021 actionBarSizeTypedArray.recycle();
1022 return size;
1023 }
1024
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001025
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001026 @Override
1027 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001028 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001029
1030 if (mTitleBar.isFixed()) {
1031 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001032 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001033 } else {
1034 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001035 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001036 }
1037
1038 @Override
1039 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001040 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001041 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001042 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001043 } else {
1044 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001045 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001046 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001047}