blob: e6e933777ba2782279a710b8d2dca5605c7130a6 [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;
Michael Kolb53ed62c2011-10-04 16:18:44 -070020import android.content.Context;
John Reckd3e4d5b2011-07-13 15:48:43 -070021import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070026import android.graphics.Color;
27import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.drawable.LayerDrawable;
30import android.graphics.drawable.PaintDrawable;
Sagar Dhawan1e040c72014-12-11 20:24:12 -080031import android.os.Build;
Michael Kolb8233fac2010-10-26 16:08:53 -070032import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070033import android.os.Handler;
34import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070036import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.Gravity;
38import android.view.LayoutInflater;
39import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070040import android.view.MenuItem;
Michael Kolb31065b12011-10-06 13:51:32 -070041import android.view.MotionEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080045import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070046import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080048import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080049import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080051import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070052import android.widget.LinearLayout;
53import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070054import android.content.res.TypedArray;
Bijan Amirzada41242f22014-03-21 12:12:18 -070055import com.android.browser.R;
56import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080057
58import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070059
Michael Kolb1bf23132010-11-19 12:55:12 -080060import java.util.List;
61
Michael Kolb8233fac2010-10-26 16:08:53 -070062/**
63 * UI interface definitions
64 */
John Reck718a24d2011-08-12 11:08:30 -070065public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070066
Enrico Ros1f5a0952014-11-18 20:15:48 -080067 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070068
Michael Kolb66706532010-12-12 19:50:22 -080069 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070070 new FrameLayout.LayoutParams(
71 ViewGroup.LayoutParams.MATCH_PARENT,
72 ViewGroup.LayoutParams.MATCH_PARENT);
73
Michael Kolb66706532010-12-12 19:50:22 -080074 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070075 new FrameLayout.LayoutParams(
76 ViewGroup.LayoutParams.MATCH_PARENT,
77 ViewGroup.LayoutParams.MATCH_PARENT,
78 Gravity.CENTER);
79
John Reck5d43ce82011-06-21 17:16:51 -070080 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070081 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070082
Michael Kolb8233fac2010-10-26 16:08:53 -070083 Activity mActivity;
84 UiController mUiController;
85 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080086 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080087 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Steve Block2466eff2011-10-03 15:33:09 +010089 private Drawable mLockIconSecure;
90 private Drawable mLockIconMixed;
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070091 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070092
Michael Kolb66706532010-12-12 19:50:22 -080093 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070094 protected FrameLayout mCustomViewContainer;
John Reck2711fab2012-05-18 21:38:59 -070095 private FrameLayout mFixedTitlebarContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070096
Michael Kolb31065b12011-10-06 13:51:32 -070097 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080098 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040099 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -0700100
Michael Kolb8233fac2010-10-26 16:08:53 -0700101 private LinearLayout mErrorConsoleContainer = null;
102
John Reck718a24d2011-08-12 11:08:30 -0700103 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -0700104
John Reck718a24d2011-08-12 11:08:30 -0700105 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 // the default <video> poster
108 private Bitmap mDefaultVideoPoster;
109 // the video progress view
110 private View mVideoProgressView;
111
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800112 private final View mDecorView;
113
Michael Kolb8233fac2010-10-26 16:08:53 -0700114 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700115 protected TitleBar mTitleBar;
116 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700117 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700118
119 public BaseUi(Activity browser, UiController controller) {
120 mActivity = browser;
121 mUiController = controller;
122 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800123 mInputManager = (InputMethodManager)
124 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800125 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
126 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700127 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
128 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700129 LayoutInflater.from(mActivity)
130 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700131 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
132 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700133 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700134 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700135 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
136 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700137 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700138 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700139 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700140 mTitleBar = new TitleBar(mActivity, mUiController, this,
141 mContentView);
142 mTitleBar.setProgress(100);
143 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700144 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800145
146 // install system ui visibility listeners
147 mDecorView = mActivity.getWindow().getDecorView();
148 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Michael Kolb8233fac2010-10-26 16:08:53 -0700149 }
150
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800151 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
152 new View.OnSystemUiVisibilityChangeListener() {
153 @Override
154 public void onSystemUiVisibilityChange(int visFlags) {
155 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
156 if (lostFullscreen)
157 setFullscreen(BrowserSettings.getInstance().useFullscreen());
158 }
159 };
160
Michael Kolb8233fac2010-10-26 16:08:53 -0700161 private void cancelStopToast() {
162 if (mStopToast != null) {
163 mStopToast.cancel();
164 mStopToast = null;
165 }
166 }
167
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700168 private Drawable getLockIconSecure() {
169 if (mLockIconSecure == null) {
170 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_secure_holo_dark);
171 }
172 return mLockIconSecure;
173 }
174
175 private Drawable getLockIconMixed() {
176 if (mLockIconMixed == null) {
177 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_secure_partial_holo_dark);
178 }
179 return mLockIconMixed;
180 }
181
182 protected Drawable getGenericFavicon() {
183 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800184 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700185 }
186 return mGenericFavicon;
187 }
188
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 // lifecycle
190
191 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800192 if (isCustomViewShowing()) {
193 onHideCustomView();
194 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500195 if (mTabControl.getCurrentTab() != null) {
196 mTabControl.getCurrentTab().exitFullscreen();
197 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 cancelStopToast();
199 mActivityPaused = true;
200 }
201
202 public void onResume() {
203 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700204 // check if we exited without setting active tab
205 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800206 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700207 final Tab ct = mTabControl.getCurrentTab();
208 if (ct != null) {
209 setActiveTab(ct);
210 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700211 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 }
213
Michael Kolb66706532010-12-12 19:50:22 -0800214 protected boolean isActivityPaused() {
215 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 }
217
218 public void onConfigurationChanged(Configuration config) {
219 }
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
291 @Override
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;
Michael Kolbda580632012-04-16 13:30:28 -0700308 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700309 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700310 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700311 if (web != null) {
312 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700313 web.setTitleBar(mTitleBar);
314 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700315 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700316 }
Michael Kolb4923c222012-04-02 16:18:36 -0700317 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700318 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700319 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
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) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400334 //remove previously scehduled tab
335 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700337 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400338 removeTabFromContentView(mTabToRemove);
339 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700340 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400341 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700342 mTabToRemove = tabToRemove;
343 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400344 mNumRemoveTries = 0;
345
346 if (mTabToRemove != null) {
347 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700348 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400349 }
350 }
351
352 protected void tryRemoveTab() {
353 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 // Ensure the webview is still valid
355 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
356 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700357 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700358 mRunnable = new Runnable() {
359 public void run() {
360 tryRemoveTab();
361 }
362 };
363 }
364 /*if the new tab is still not ready, wait another 2 frames
365 before trying again. 1 frame for the tab to render the first
366 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700367 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400368 return;
369 }
370 }
371 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700372 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700373 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400374 removeTabFromContentView(mTabToRemove);
375 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700376 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400377 }
378 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700379 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 }
381
John Reck718a24d2011-08-12 11:08:30 -0700382 protected void updateUrlBarAutoShowManagerTarget() {
383 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700384 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700385 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700386 }
387 }
388
Michael Kolbcfa3af52010-12-14 10:36:11 -0800389 Tab getActiveTab() {
390 return mActiveTab;
391 }
392
Michael Kolb8233fac2010-10-26 16:08:53 -0700393 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800394 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800395 }
396
397 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700398 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800399 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700400 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800401 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700403 }
404
405 @Override
406 public void detachTab(Tab tab) {
407 removeTabFromContentView(tab);
408 }
409
410 @Override
411 public void attachTab(Tab tab) {
412 attachTabToContentView(tab);
413 }
414
Michael Kolb377ea312011-02-17 14:36:56 -0800415 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800416 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 return;
418 }
419 View container = tab.getViewContainer();
420 WebView mainView = tab.getWebView();
421 // Attach the WebView to the container and then attach the
422 // container to the content view.
423 FrameLayout wrapper =
424 (FrameLayout) container.findViewById(R.id.webview_wrapper);
425 ViewGroup parent = (ViewGroup) mainView.getParent();
426 if (parent != wrapper) {
427 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 parent.removeView(mainView);
429 }
430 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 }
432 parent = (ViewGroup) container.getParent();
433 if (parent != mContentView) {
434 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700435 parent.removeView(container);
436 }
437 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700438 }
439 mUiController.attachSubWindow(tab);
440 }
441
442 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800443 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700444 // Remove the container that contains the main WebView.
445 WebView mainView = tab.getWebView();
446 View container = tab.getViewContainer();
447 if (mainView == null) {
448 return;
449 }
450 // Remove the container from the content and then remove the
451 // WebView from the container. This will trigger a focus change
452 // needed by WebView.
453 FrameLayout wrapper =
454 (FrameLayout) container.findViewById(R.id.webview_wrapper);
455 wrapper.removeView(mainView);
456 mContentView.removeView(container);
457 mUiController.endActionMode();
458 mUiController.removeSubWindow(tab);
459 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
460 if (errorConsole != null) {
461 mErrorConsoleContainer.removeView(errorConsole);
462 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700463 }
464
Michael Kolba713ec82010-11-29 17:27:06 -0800465 @Override
466 public void onSetWebView(Tab tab, WebView webView) {
467 View container = tab.getViewContainer();
468 if (container == null) {
469 // The tab consists of a container view, which contains the main
470 // WebView, as well as any other UI elements associated with the tab.
471 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700472 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800473 tab.setViewContainer(container);
474 }
475 if (tab.getWebView() != webView) {
476 // Just remove the old one.
477 FrameLayout wrapper =
478 (FrameLayout) container.findViewById(R.id.webview_wrapper);
479 wrapper.removeView(tab.getWebView());
480 }
481 }
482
Michael Kolb8233fac2010-10-26 16:08:53 -0700483 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800484 * create a sub window container and webview for the tab
485 * Note: this methods operates through side-effects for now
486 * it sets both the subView and subViewContainer for the given tab
487 * @param tab tab to create the sub window for
488 * @param subView webview to be set as a subwindow for the tab
489 */
490 @Override
491 public void createSubWindow(Tab tab, WebView subView) {
492 View subViewContainer = mActivity.getLayoutInflater().inflate(
493 R.layout.browser_subwindow, null);
494 ViewGroup inner = (ViewGroup) subViewContainer
495 .findViewById(R.id.inner_container);
496 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
497 LayoutParams.MATCH_PARENT));
498 final ImageButton cancel = (ImageButton) subViewContainer
499 .findViewById(R.id.subwindow_close);
500 final WebView cancelSubView = subView;
501 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800502 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800503 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800504 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800505 }
506 });
507 tab.setSubWebView(subView);
508 tab.setSubViewContainer(subViewContainer);
509 }
510
511 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700512 * Remove the sub window from the content view.
513 */
514 @Override
515 public void removeSubWindow(View subviewContainer) {
516 mContentView.removeView(subviewContainer);
517 mUiController.endActionMode();
518 }
519
520 /**
521 * Attach the sub window to the content view.
522 */
523 @Override
524 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800525 if (container.getParent() != null) {
526 // already attached, remove first
527 ((ViewGroup) container.getParent()).removeView(container);
528 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700529 mContentView.addView(container, COVER_SCREEN_PARAMS);
530 }
531
Michael Kolb11d19782011-03-20 10:17:40 -0700532 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700533 WebView web = getWebView();
534 if (web != null) {
535 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700536 }
537 }
538
Michael Kolb1f9b3562012-04-24 14:38:34 -0700539 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700540 if (mUiController.isInCustomActionMode()) {
541 mUiController.endActionMode();
542 }
543 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700544 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700545 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700546 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700547 }
548
Michael Kolb7cdc4902011-02-03 17:54:40 -0800549 boolean canShowTitleBar() {
550 return !isTitleBarShowing()
551 && !isActivityPaused()
552 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700553 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800554 && !mUiController.isInCustomActionMode();
555 }
556
John Reck0f602f32011-07-07 15:38:43 -0700557 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700558 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700559 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700560 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700561 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800562 }
563
564 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700565 if (mTitleBar.isShowing()) {
566 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700567 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800568 }
569
570 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700571 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800572 }
573
John Reck5d43ce82011-06-21 17:16:51 -0700574 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700575 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700576 }
577
Michael Kolb80f75082012-04-10 10:50:06 -0700578 public void stopEditingUrl() {
579 mTitleBar.getNavigationBar().stopEditingUrl();
580 }
581
John Reck0f602f32011-07-07 15:38:43 -0700582 public TitleBar getTitleBar() {
583 return mTitleBar;
584 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800585
Michael Kolb66706532010-12-12 19:50:22 -0800586 @Override
John Reck2bc80422011-06-30 15:11:49 -0700587 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700588 Intent intent = new Intent(mActivity, ComboViewActivity.class);
589 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
590 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
591 Tab t = getActiveTab();
592 if (t != null) {
593 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800594 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700595 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 }
597
598 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400599 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800600 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 // if a view already exists then immediately terminate the new one
602 if (mCustomView != null) {
603 callback.onCustomViewHidden();
604 return;
605 }
606
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400607 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700608 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400609 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700610 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400611 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700612 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700613 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400614 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 }
616
617 @Override
618 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700619 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 if (mCustomView == null)
621 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400622 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700623 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400624 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700626 mCustomViewCallback.onCustomViewHidden();
627 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400628 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700629 }
630
631 @Override
632 public boolean isCustomViewShowing() {
633 return mCustomView != null;
634 }
635
Michael Kolb66706532010-12-12 19:50:22 -0800636 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800637 if (mInputManager.isActive()) {
638 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
639 0);
640 }
641 }
642
Michael Kolb66706532010-12-12 19:50:22 -0800643 @Override
John Reck3ba45532011-08-11 16:26:53 -0700644 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700645 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800646 }
647
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 // -------------------------------------------------------------------------
649
Michael Kolb5a72f182011-01-13 20:35:06 -0800650 protected void updateNavigationState(Tab tab) {
651 }
652
Michael Kolb8233fac2010-10-26 16:08:53 -0700653 /**
654 * Update the lock icon to correspond to our latest state.
655 */
Michael Kolb66706532010-12-12 19:50:22 -0800656 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800657 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100658 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 }
660 }
661
662 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 * Updates the lock-icon image in the title-bar.
664 */
Steve Block2466eff2011-10-03 15:33:09 +0100665 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700666 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100667 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700668 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100669 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
670 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
671 // TODO: It would be good to have different icons for insecure vs mixed content.
672 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700673 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700674 }
John Reck0f602f32011-07-07 15:38:43 -0700675 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 }
677
John Reck30c714c2010-12-16 17:30:34 -0800678 protected void setUrlTitle(Tab tab) {
679 String url = tab.getUrl();
680 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800681 if (TextUtils.isEmpty(title)) {
682 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800683 }
Michael Kolb66706532010-12-12 19:50:22 -0800684 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700685 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800686 }
687 }
688
689 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800690 protected void setFavicon(Tab tab) {
691 if (tab.inForeground()) {
692 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700693 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800694 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700695 }
696
Michael Kolb66706532010-12-12 19:50:22 -0800697 // active tabs page
698
699 public void showActiveTabsPage() {
700 }
701
702 /**
703 * Remove the active tabs page.
704 */
705 public void removeActiveTabsPage() {
706 }
707
Michael Kolb8233fac2010-10-26 16:08:53 -0700708 // menu handling callbacks
709
710 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800711 public boolean onPrepareOptionsMenu(Menu menu) {
712 return true;
713 }
714
715 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700716 public void updateMenuState(Tab tab, Menu menu) {
717 }
718
719 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700720 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700721 }
722
723 @Override
724 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 }
726
727 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700728 public boolean onOptionsItemSelected(MenuItem item) {
729 return false;
730 }
731
732 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700733 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 }
735
736 @Override
737 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700738 }
739
740 @Override
741 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700742 }
743
744 @Override
745 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700746 }
747
748 // error console
749
750 @Override
751 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800752 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700753 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
754 if (flag) {
755 // Setting the show state of the console will cause it's the layout
756 // to be inflated.
757 if (errorConsole.numberOfErrors() > 0) {
758 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
759 } else {
760 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
761 }
762 if (errorConsole.getParent() != null) {
763 mErrorConsoleContainer.removeView(errorConsole);
764 }
765 // Now we can add it to the main view.
766 mErrorConsoleContainer.addView(errorConsole,
767 new LinearLayout.LayoutParams(
768 ViewGroup.LayoutParams.MATCH_PARENT,
769 ViewGroup.LayoutParams.WRAP_CONTENT));
770 } else {
771 mErrorConsoleContainer.removeView(errorConsole);
772 }
773 }
774
Michael Kolb8233fac2010-10-26 16:08:53 -0700775 // -------------------------------------------------------------------------
776 // Helper function for WebChromeClient
777 // -------------------------------------------------------------------------
778
779 @Override
780 public Bitmap getDefaultVideoPoster() {
781 if (mDefaultVideoPoster == null) {
782 mDefaultVideoPoster = BitmapFactory.decodeResource(
783 mActivity.getResources(), R.drawable.default_video_poster);
784 }
785 return mDefaultVideoPoster;
786 }
787
788 @Override
789 public View getVideoLoadingProgressView() {
790 if (mVideoProgressView == null) {
791 LayoutInflater inflater = LayoutInflater.from(mActivity);
792 mVideoProgressView = inflater.inflate(
793 R.layout.video_loading_progress, null);
794 }
795 return mVideoProgressView;
796 }
797
Michael Kolb843510f2010-12-09 10:51:49 -0800798 @Override
799 public void showMaxTabsWarning() {
800 Toast warning = Toast.makeText(mActivity,
801 mActivity.getString(R.string.max_tabs_warning),
802 Toast.LENGTH_SHORT);
803 warning.show();
804 }
805
Michael Kolb46f987e2011-04-05 10:39:10 -0700806 protected WebView getWebView() {
807 if (mActiveTab != null) {
808 return mActiveTab.getWebView();
809 } else {
810 return null;
811 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700812 }
813
Michael Kolbc38c6042011-04-27 10:46:06 -0700814 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700815 Window win = mActivity.getWindow();
816 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800817 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500818 final int fullscreenImmersiveSetting =
819 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
820 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
821 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
822 View.SYSTEM_UI_FLAG_FULLSCREEN |
823 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
824
825 if (mCustomView != null) {
826 mCustomView.setSystemUiVisibility(enabled ?
827 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800828 } else if (Build.VERSION.SDK_INT >= 19) {
829 mContentView.setSystemUiVisibility(enabled ?
830 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700831 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500832 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800833 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700834 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500835 if (enabled)
836 winParams.flags |= bits;
837 else
838 winParams.flags &= ~bits;
839
Michael Kolbc5675ad2011-10-21 13:34:28 -0700840 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700841 }
842
Denise LaFayetteda31d742014-10-10 18:03:13 -0400843 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700844 public void showFullscreen(boolean fullScreen) {
845 //Hide/show system ui bar as needed
846 if (!BrowserSettings.getInstance().useFullscreen())
847 setFullscreen(fullScreen);
848
849 //Hide/show topbar as needed
850 if (getWebView() != null) {
851 if (fullScreen) {
852 //hide topbar
853 getWebView().updateTopControls(true, false, false);
854 } else {
855 //show the topbar
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800856 getWebView().updateTopControls(false, true, false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700857 //enable for auto-hide
858 if (!mTitleBar.isFixed())
859 getWebView().updateTopControls(true, true, false);
860 }
861 }
862 }
863
864
865
Tarun Nainani8eb00912014-07-17 12:28:32 -0700866 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700867 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700868 if (topControlsOffsetYPix != 0.0) {
869 mTitleBar.setEnabled(false);
870 } else {
871 mTitleBar.setEnabled(true);
872 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800873 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800874 float currentY = mTitleBar.getTranslationY();
875 float height = mTitleBar.getHeight();
876 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
877 mTitleBar.requestLayout();
878 } else if ((height + topControlsOffsetYPix) <= 0) {
879 topControlsOffsetYPix -= 1;
880 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
881 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800882 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800883 // This was done to get HTML5 fullscreen API to work with fixed mode since
884 // topcontrols are used to implement HTML5 fullscreen
885 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700886 }
887 }
888
John Reck0f602f32011-07-07 15:38:43 -0700889 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800890 if (ENABLE_BORDER_AROUND_FAVICON) {
891 Drawable[] array = new Drawable[3];
892 array[0] = new PaintDrawable(Color.BLACK);
893 PaintDrawable p = new PaintDrawable(Color.WHITE);
894 array[1] = p;
895 if (icon == null) {
896 array[2] = getGenericFavicon();
897 } else {
898 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
899 }
900 LayerDrawable d = new LayerDrawable(array);
901 d.setLayerInset(1, 1, 1, 1, 1);
902 d.setLayerInset(2, 2, 2, 2, 2);
903 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700904 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800905 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700906 }
907
John Reck5d43ce82011-06-21 17:16:51 -0700908 public boolean isLoading() {
909 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
910 }
911
912 /**
913 * Suggest to the UI that the title bar can be hidden. The UI will then
914 * decide whether or not to hide based off a number of factors, such
915 * as if the user is editing the URL bar or if the page is loading
916 */
917 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700918 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
919 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700920 hideTitleBar();
921 }
922 }
923
John Reckbc6adb42011-09-01 18:03:20 -0700924 protected final void showTitleBarForDuration() {
925 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
926 }
927
928 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700929 showTitleBar();
930 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700931 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700932 }
933
Enrico Ros1f5a0952014-11-18 20:15:48 -0800934 protected void setMenuItemVisibility(Menu menu, int id,
935 boolean visibility) {
936 MenuItem item = menu.findItem(id);
937 if (item != null) {
938 item.setVisible(visibility);
939 }
940 }
941
John Reck9c5004e2011-10-07 16:00:12 -0700942 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700943
944 @Override
945 public void handleMessage(Message msg) {
946 if (msg.what == MSG_HIDE_TITLEBAR) {
947 suggestHideTitleBar();
948 }
John Reck9c5004e2011-10-07 16:00:12 -0700949 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700950 }
951 };
John Reck3ba45532011-08-11 16:26:53 -0700952
John Reck9c5004e2011-10-07 16:00:12 -0700953 protected void handleMessage(Message msg) {}
954
John Reck3ba45532011-08-11 16:26:53 -0700955 @Override
956 public void showWeb(boolean animate) {
957 mUiController.hideCustomView();
958 }
959
John Reck2711fab2012-05-18 21:38:59 -0700960 public void setContentViewMarginTop(int margin) {
961 LinearLayout.LayoutParams params =
962 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
963 if (params.topMargin != margin) {
964 params.topMargin = margin;
965 mContentView.setLayoutParams(params);
966 }
967 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700968
969 @Override
970 public boolean blockFocusAnimations() {
971 return mBlockFocusAnimations;
972 }
973
Michael Kolb0b129122012-06-04 16:31:58 -0700974 @Override
975 public void onVoiceResult(String result) {
976 mNavigationBar.onVoiceResult(result);
977 }
978
kaiyizbb2db872013-08-01 22:24:07 -0400979 protected UiController getUiController() {
980 return mUiController;
981 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700982
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700983 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700984 private float getActionModeHeight() {
985 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
986 new int[] { android.R.attr.actionBarSize });
987 float size = actionBarSizeTypedArray.getDimension(0, 0f);
988 actionBarSizeTypedArray.recycle();
989 return size;
990 }
991
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700992
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700993 @Override
994 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700995 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700996
997 if (mTitleBar.isFixed()) {
998 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700999 mFixedTitlebarContainer.setY(fixedTbarHeight);
1000 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001001 } else {
1002 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001003 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001004 }
1005
1006 @Override
1007 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001008 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001009 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001010 mFixedTitlebarContainer.setY(0);
1011 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001012 } else {
1013 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001014 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001015 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001016}