BaseUi.java revision 1acef69ffc079d1bc029ff7eb1f5043f7efd7f36
18233facddcc51865d612a919d450db6954aa48e3Michael Kolb/* 28233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Copyright (C) 2010 The Android Open Source Project 38233facddcc51865d612a919d450db6954aa48e3Michael Kolb * 48233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Licensed under the Apache License, Version 2.0 (the "License"); 58233facddcc51865d612a919d450db6954aa48e3Michael Kolb * you may not use this file except in compliance with the License. 68233facddcc51865d612a919d450db6954aa48e3Michael Kolb * You may obtain a copy of the License at 78233facddcc51865d612a919d450db6954aa48e3Michael Kolb * 88233facddcc51865d612a919d450db6954aa48e3Michael Kolb * http://www.apache.org/licenses/LICENSE-2.0 98233facddcc51865d612a919d450db6954aa48e3Michael Kolb * 108233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Unless required by applicable law or agreed to in writing, software 118233facddcc51865d612a919d450db6954aa48e3Michael Kolb * distributed under the License is distributed on an "AS IS" BASIS, 128233facddcc51865d612a919d450db6954aa48e3Michael Kolb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138233facddcc51865d612a919d450db6954aa48e3Michael Kolb * See the License for the specific language governing permissions and 148233facddcc51865d612a919d450db6954aa48e3Michael Kolb * limitations under the License. 158233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 168233facddcc51865d612a919d450db6954aa48e3Michael Kolb 178233facddcc51865d612a919d450db6954aa48e3Michael Kolbpackage com.android.browser; 188233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1930c714c853a4239e72ab1e238ce2a92472d06ab0John Reckimport com.android.browser.Tab.LockIcon; 205119edd5744cfc6d3a8ed480a8853586c737bed4Narayan Kamathimport com.android.browser.UI.DropdownChangeListener; 2130c714c853a4239e72ab1e238ce2a92472d06ab0John Reck 22377ea31324391e7878f6f5b7a991c74988c18403Michael Kolbimport android.animation.Animator; 23377ea31324391e7878f6f5b7a991c74988c18403Michael Kolbimport android.animation.Animator.AnimatorListener; 245289bc38ab5d94514a3297cebf1a29ed80de9f98John Reckimport android.animation.ObjectAnimator; 258233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.app.Activity; 268233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.content.res.Configuration; 278233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.content.res.Resources; 288233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.Bitmap; 298233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.BitmapFactory; 308233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.drawable.Drawable; 318233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.os.Bundle; 328233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.text.TextUtils; 338233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.util.Log; 348233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.Gravity; 358233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.LayoutInflater; 368233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.Menu; 378233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.View; 381514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.view.View.OnClickListener; 398233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.ViewGroup; 401514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.view.ViewGroup.LayoutParams; 418233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.WindowManager; 423a696280cba53eea153c9d5707b236997d193328Michael Kolbimport android.view.inputmethod.InputMethodManager; 438233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.webkit.WebChromeClient; 448233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.webkit.WebView; 458233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.FrameLayout; 461514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.widget.ImageButton; 478233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.LinearLayout; 488233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.Toast; 498233facddcc51865d612a919d450db6954aa48e3Michael Kolb 501bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolbimport java.util.List; 511bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb 528233facddcc51865d612a919d450db6954aa48e3Michael Kolb/** 538233facddcc51865d612a919d450db6954aa48e3Michael Kolb * UI interface definitions 548233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 556670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolbpublic abstract class BaseUi implements UI, WebViewFactory { 568233facddcc51865d612a919d450db6954aa48e3Michael Kolb 578233facddcc51865d612a919d450db6954aa48e3Michael Kolb private static final String LOGTAG = "BaseUi"; 588233facddcc51865d612a919d450db6954aa48e3Michael Kolb 596670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = 608233facddcc51865d612a919d450db6954aa48e3Michael Kolb new FrameLayout.LayoutParams( 618233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 628233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT); 638233facddcc51865d612a919d450db6954aa48e3Michael Kolb 646670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = 658233facddcc51865d612a919d450db6954aa48e3Michael Kolb new FrameLayout.LayoutParams( 668233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 678233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 688233facddcc51865d612a919d450db6954aa48e3Michael Kolb Gravity.CENTER); 698233facddcc51865d612a919d450db6954aa48e3Michael Kolb 708233facddcc51865d612a919d450db6954aa48e3Michael Kolb Activity mActivity; 718233facddcc51865d612a919d450db6954aa48e3Michael Kolb UiController mUiController; 728233facddcc51865d612a919d450db6954aa48e3Michael Kolb TabControl mTabControl; 73377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb protected Tab mActiveTab; 743a696280cba53eea153c9d5707b236997d193328Michael Kolb private InputMethodManager mInputManager; 758233facddcc51865d612a919d450db6954aa48e3Michael Kolb 768233facddcc51865d612a919d450db6954aa48e3Michael Kolb private Drawable mSecLockIcon; 778233facddcc51865d612a919d450db6954aa48e3Michael Kolb private Drawable mMixLockIcon; 788233facddcc51865d612a919d450db6954aa48e3Michael Kolb 798233facddcc51865d612a919d450db6954aa48e3Michael Kolb private FrameLayout mBrowserFrameLayout; 806670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected FrameLayout mContentView; 818233facddcc51865d612a919d450db6954aa48e3Michael Kolb private FrameLayout mCustomViewContainer; 828233facddcc51865d612a919d450db6954aa48e3Michael Kolb 838233facddcc51865d612a919d450db6954aa48e3Michael Kolb private View mCustomView; 848233facddcc51865d612a919d450db6954aa48e3Michael Kolb private WebChromeClient.CustomViewCallback mCustomViewCallback; 858233facddcc51865d612a919d450db6954aa48e3Michael Kolb 868233facddcc51865d612a919d450db6954aa48e3Michael Kolb private CombinedBookmarkHistoryView mComboView; 878233facddcc51865d612a919d450db6954aa48e3Michael Kolb 888233facddcc51865d612a919d450db6954aa48e3Michael Kolb private LinearLayout mErrorConsoleContainer = null; 898233facddcc51865d612a919d450db6954aa48e3Michael Kolb 908233facddcc51865d612a919d450db6954aa48e3Michael Kolb private Toast mStopToast; 918233facddcc51865d612a919d450db6954aa48e3Michael Kolb 927cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb private boolean mTitleShowing; 937cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb 948233facddcc51865d612a919d450db6954aa48e3Michael Kolb // the default <video> poster 958233facddcc51865d612a919d450db6954aa48e3Michael Kolb private Bitmap mDefaultVideoPoster; 968233facddcc51865d612a919d450db6954aa48e3Michael Kolb // the video progress view 978233facddcc51865d612a919d450db6954aa48e3Michael Kolb private View mVideoProgressView; 988233facddcc51865d612a919d450db6954aa48e3Michael Kolb 998233facddcc51865d612a919d450db6954aa48e3Michael Kolb private boolean mActivityPaused; 1008233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1018233facddcc51865d612a919d450db6954aa48e3Michael Kolb public BaseUi(Activity browser, UiController controller) { 1028233facddcc51865d612a919d450db6954aa48e3Michael Kolb mActivity = browser; 1038233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController = controller; 1048233facddcc51865d612a919d450db6954aa48e3Michael Kolb mTabControl = controller.getTabControl(); 1058233facddcc51865d612a919d450db6954aa48e3Michael Kolb Resources res = mActivity.getResources(); 1063a696280cba53eea153c9d5707b236997d193328Michael Kolb mInputManager = (InputMethodManager) 1073a696280cba53eea153c9d5707b236997d193328Michael Kolb browser.getSystemService(Activity.INPUT_METHOD_SERVICE); 1085a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark); 1098233facddcc51865d612a919d450db6954aa48e3Michael Kolb mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure); 1108233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1118233facddcc51865d612a919d450db6954aa48e3Michael Kolb FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() 1128233facddcc51865d612a919d450db6954aa48e3Michael Kolb .getDecorView().findViewById(android.R.id.content); 1138233facddcc51865d612a919d450db6954aa48e3Michael Kolb mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity) 1148233facddcc51865d612a919d450db6954aa48e3Michael Kolb .inflate(R.layout.custom_screen, null); 1158233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView = (FrameLayout) mBrowserFrameLayout.findViewById( 1168233facddcc51865d612a919d450db6954aa48e3Michael Kolb R.id.main_content); 1178233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout 1188233facddcc51865d612a919d450db6954aa48e3Michael Kolb .findViewById(R.id.error_console); 1198233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewContainer = (FrameLayout) mBrowserFrameLayout 1208233facddcc51865d612a919d450db6954aa48e3Michael Kolb .findViewById(R.id.fullscreen_custom_content); 1218233facddcc51865d612a919d450db6954aa48e3Michael Kolb frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS); 1227cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb mTitleShowing = false; 1238233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1248233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1256670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb /** 1266670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb * common webview initialization 1276670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb * @param w the webview to initialize 1286670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb */ 1296670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected void initWebViewSettings(WebView w) { 1308233facddcc51865d612a919d450db6954aa48e3Michael Kolb w.setScrollbarFadingEnabled(true); 1318233facddcc51865d612a919d450db6954aa48e3Michael Kolb w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); 1328233facddcc51865d612a919d450db6954aa48e3Michael Kolb w.setMapTrackballToArrowKeys(false); // use trackball directly 1338233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Enable the built-in zoom 1348233facddcc51865d612a919d450db6954aa48e3Michael Kolb w.getSettings().setBuiltInZoomControls(true); 1358233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1368233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Add this WebView to the settings observer list and update the 1378233facddcc51865d612a919d450db6954aa48e3Michael Kolb // settings 1388233facddcc51865d612a919d450db6954aa48e3Michael Kolb final BrowserSettings s = BrowserSettings.getInstance(); 1398233facddcc51865d612a919d450db6954aa48e3Michael Kolb s.addObserver(w.getSettings()).update(s, null); 1408233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1418233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1428233facddcc51865d612a919d450db6954aa48e3Michael Kolb private void cancelStopToast() { 1438233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mStopToast != null) { 1448233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast.cancel(); 1458233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast = null; 1468233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1478233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1488233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1498233facddcc51865d612a919d450db6954aa48e3Michael Kolb // lifecycle 1508233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1518233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onPause() { 1527a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb if (isCustomViewShowing()) { 1537a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb onHideCustomView(); 1547a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb } 1558233facddcc51865d612a919d450db6954aa48e3Michael Kolb cancelStopToast(); 1568233facddcc51865d612a919d450db6954aa48e3Michael Kolb mActivityPaused = true; 1578233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1588233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1598233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onResume() { 1608233facddcc51865d612a919d450db6954aa48e3Michael Kolb mActivityPaused = false; 1618233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1628233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1636670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected boolean isActivityPaused() { 1646670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb return mActivityPaused; 1658233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1668233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1678233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onConfigurationChanged(Configuration config) { 1688233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1698233facddcc51865d612a919d450db6954aa48e3Michael Kolb 170dc2ee1bfb50b7bec0cf3215e3d298b246dc71101Michael Kolb public abstract void editUrl(boolean clearInput); 171dc2ee1bfb50b7bec0cf3215e3d298b246dc71101Michael Kolb 1728233facddcc51865d612a919d450db6954aa48e3Michael Kolb // key handling 1738233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1748233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 1758233facddcc51865d612a919d450db6954aa48e3Michael Kolb public boolean onBackKey() { 1768233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mComboView != null) { 1778233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (!mComboView.onBackPressed()) { 1788233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.removeComboView(); 1798233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1808233facddcc51865d612a919d450db6954aa48e3Michael Kolb return true; 1818233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1828233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mCustomView != null) { 1838233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.hideCustomView(); 1848233facddcc51865d612a919d450db6954aa48e3Michael Kolb return true; 1858233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1868233facddcc51865d612a919d450db6954aa48e3Michael Kolb return false; 1878233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1888233facddcc51865d612a919d450db6954aa48e3Michael Kolb 18930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck // Tab callbacks 1908233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 19130c714c853a4239e72ab1e238ce2a92472d06ab0John Reck public void onTabDataChanged(Tab tab) { 19230c714c853a4239e72ab1e238ce2a92472d06ab0John Reck setUrlTitle(tab); 19330c714c853a4239e72ab1e238ce2a92472d06ab0John Reck setFavicon(tab); 19430c714c853a4239e72ab1e238ce2a92472d06ab0John Reck updateLockIconToLatest(tab); 1955a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb updateNavigationState(tab); 1968233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1978233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1988233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 1994cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins public void bookmarkedStatusHasChanged(Tab tab) { 20094b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck if (tab.inForeground()) { 20194b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck boolean isBookmark = tab.isBookmarkedSite(); 20294b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck getTitleBar().setCurrentUrlIsBookmark(isBookmark); 20394b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck } 2044cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins } 2054cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins 2064cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins @Override 2078233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onPageStopped(Tab tab) { 2088233facddcc51865d612a919d450db6954aa48e3Michael Kolb cancelStopToast(); 2098233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (tab.inForeground()) { 2108233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast = Toast 2118233facddcc51865d612a919d450db6954aa48e3Michael Kolb .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); 2128233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast.show(); 2138233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2148233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2158233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2168233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2171bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb public boolean needsRestoreAllTabs() { 2186670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb return false; 2191bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb } 2201bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb 2211bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb @Override 2228233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void addTab(Tab tab) { 2238233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2248233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2258233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 226377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb public void setActiveTab(final Tab tab) { 227377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb setActiveTab(tab, true); 228377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb } 229377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb 230377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb void setActiveTab(Tab tab, boolean needsAttaching) { 23177df4568331d527f993f4d69168218ddf5acdddaMichael Kolb if ((tab != mActiveTab) && (mActiveTab != null)) { 23277df4568331d527f993f4d69168218ddf5acdddaMichael Kolb removeTabFromContentView(mActiveTab); 2338233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 23477df4568331d527f993f4d69168218ddf5acdddaMichael Kolb mActiveTab = tab; 235377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb if (needsAttaching) { 236377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb attachTabToContentView(tab); 237377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb } 2388233facddcc51865d612a919d450db6954aa48e3Michael Kolb setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); 23930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck onTabDataChanged(tab); 24030c714c853a4239e72ab1e238ce2a92472d06ab0John Reck onProgressChanged(tab); 241117f07d08e3e25e3c920a1dabe31dcd7643bacb2John Reck boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled(); 2427cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setIncognitoMode(incognito); 2438233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2448233facddcc51865d612a919d450db6954aa48e3Michael Kolb 245cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb Tab getActiveTab() { 246cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb return mActiveTab; 247cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb } 248cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb 2498233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2501bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb public void updateTabs(List<Tab> tabs) { 2511bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb } 2521bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb 2531bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb @Override 2548233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void removeTab(Tab tab) { 25577df4568331d527f993f4d69168218ddf5acdddaMichael Kolb if (mActiveTab == tab) { 2568233facddcc51865d612a919d450db6954aa48e3Michael Kolb removeTabFromContentView(tab); 25777df4568331d527f993f4d69168218ddf5acdddaMichael Kolb mActiveTab = null; 2588233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2598233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2608233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2618233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2628233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void detachTab(Tab tab) { 2638233facddcc51865d612a919d450db6954aa48e3Michael Kolb removeTabFromContentView(tab); 2648233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2658233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2668233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2678233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void attachTab(Tab tab) { 2688233facddcc51865d612a919d450db6954aa48e3Michael Kolb attachTabToContentView(tab); 2698233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2708233facddcc51865d612a919d450db6954aa48e3Michael Kolb 271377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb protected void attachTabToContentView(Tab tab) { 272d1e2ccc38a2d5318a4ab06b2349cb43303fd6cebMichael Kolb if ((tab == null) || (tab.getWebView() == null)) { 2738233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 2748233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2758233facddcc51865d612a919d450db6954aa48e3Michael Kolb View container = tab.getViewContainer(); 2768233facddcc51865d612a919d450db6954aa48e3Michael Kolb WebView mainView = tab.getWebView(); 2778233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Attach the WebView to the container and then attach the 2788233facddcc51865d612a919d450db6954aa48e3Michael Kolb // container to the content view. 2798233facddcc51865d612a919d450db6954aa48e3Michael Kolb FrameLayout wrapper = 2808233facddcc51865d612a919d450db6954aa48e3Michael Kolb (FrameLayout) container.findViewById(R.id.webview_wrapper); 2818233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup parent = (ViewGroup) mainView.getParent(); 2828233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != wrapper) { 2838233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != null) { 2848233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mMainView already has a parent in" 2858233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 2868233facddcc51865d612a919d450db6954aa48e3Michael Kolb parent.removeView(mainView); 2878233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2888233facddcc51865d612a919d450db6954aa48e3Michael Kolb wrapper.addView(mainView); 2898233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 2908233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mMainView is already attached to wrapper in" 2918233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 2928233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2938233facddcc51865d612a919d450db6954aa48e3Michael Kolb parent = (ViewGroup) container.getParent(); 2948233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != mContentView) { 2958233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != null) { 2968233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mContainer already has a parent in" 2978233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 2988233facddcc51865d612a919d450db6954aa48e3Michael Kolb parent.removeView(container); 2998233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3008233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.addView(container, COVER_SCREEN_PARAMS); 3018233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 3028233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mContainer is already attached to content in" 3038233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 3048233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 305a418306e08e008da99cef929c48e05d2a101ceafMichael Kolb mainView.setNextFocusUpId(R.id.url_focused); 306a418306e08e008da99cef929c48e05d2a101ceafMichael Kolb mainView.setNextFocusDownId(R.id.url_focused); 3078233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.attachSubWindow(tab); 3088233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3098233facddcc51865d612a919d450db6954aa48e3Michael Kolb 3108233facddcc51865d612a919d450db6954aa48e3Michael Kolb private void removeTabFromContentView(Tab tab) { 3117cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb hideTitleBar(); 3128233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Remove the container that contains the main WebView. 3138233facddcc51865d612a919d450db6954aa48e3Michael Kolb WebView mainView = tab.getWebView(); 3148233facddcc51865d612a919d450db6954aa48e3Michael Kolb View container = tab.getViewContainer(); 3158233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mainView == null) { 3168233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 3178233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3188233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Remove the container from the content and then remove the 3198233facddcc51865d612a919d450db6954aa48e3Michael Kolb // WebView from the container. This will trigger a focus change 3208233facddcc51865d612a919d450db6954aa48e3Michael Kolb // needed by WebView. 32120776cc370cf1f092b73c356c02a0df966cfd185Michael Kolb mainView.setEmbeddedTitleBar(null); 3228233facddcc51865d612a919d450db6954aa48e3Michael Kolb FrameLayout wrapper = 3238233facddcc51865d612a919d450db6954aa48e3Michael Kolb (FrameLayout) container.findViewById(R.id.webview_wrapper); 3248233facddcc51865d612a919d450db6954aa48e3Michael Kolb wrapper.removeView(mainView); 3258233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.removeView(container); 3268233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.endActionMode(); 3278233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.removeSubWindow(tab); 3288233facddcc51865d612a919d450db6954aa48e3Michael Kolb ErrorConsoleView errorConsole = tab.getErrorConsole(false); 3298233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (errorConsole != null) { 3308233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.removeView(errorConsole); 3318233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3328233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3338233facddcc51865d612a919d450db6954aa48e3Michael Kolb 334a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb @Override 335a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb public void onSetWebView(Tab tab, WebView webView) { 336a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb View container = tab.getViewContainer(); 337a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb if (container == null) { 338a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb // The tab consists of a container view, which contains the main 339a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb // WebView, as well as any other UI elements associated with the tab. 340a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb container = mActivity.getLayoutInflater().inflate(R.layout.tab, 341a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb null); 342a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb tab.setViewContainer(container); 343a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb } 344a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb if (tab.getWebView() != webView) { 345a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb // Just remove the old one. 346a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb FrameLayout wrapper = 347a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb (FrameLayout) container.findViewById(R.id.webview_wrapper); 348a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb wrapper.removeView(tab.getWebView()); 349a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb } 350a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb } 351a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb 3528233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 3531514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * create a sub window container and webview for the tab 3541514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * Note: this methods operates through side-effects for now 3551514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * it sets both the subView and subViewContainer for the given tab 3561514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * @param tab tab to create the sub window for 3571514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * @param subView webview to be set as a subwindow for the tab 3581514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb */ 3591514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb @Override 3601514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb public void createSubWindow(Tab tab, WebView subView) { 3611514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb View subViewContainer = mActivity.getLayoutInflater().inflate( 3621514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb R.layout.browser_subwindow, null); 3631514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb ViewGroup inner = (ViewGroup) subViewContainer 3641514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb .findViewById(R.id.inner_container); 3651514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, 3661514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb LayoutParams.MATCH_PARENT)); 3671514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb final ImageButton cancel = (ImageButton) subViewContainer 3681514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb .findViewById(R.id.subwindow_close); 3691514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb final WebView cancelSubView = subView; 3701514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb cancel.setOnClickListener(new OnClickListener() { 3711514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb public void onClick(View v) { 3721514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView); 3731514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb } 3741514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb }); 3751514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb tab.setSubWebView(subView); 3761514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb tab.setSubViewContainer(subViewContainer); 3771514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb } 3781514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb 3791514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb /** 3808233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Remove the sub window from the content view. 3818233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 3828233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 3838233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void removeSubWindow(View subviewContainer) { 3848233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.removeView(subviewContainer); 3858233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.endActionMode(); 3868233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3878233facddcc51865d612a919d450db6954aa48e3Michael Kolb 3888233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 3898233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Attach the sub window to the content view. 3908233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 3918233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 3928233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void attachSubWindow(View container) { 3931514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb if (container.getParent() != null) { 3941514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb // already attached, remove first 3951514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb ((ViewGroup) container.getParent()).removeView(container); 3961514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb } 3978233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.addView(container, COVER_SCREEN_PARAMS); 3988233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3998233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4007cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb boolean canShowTitleBar() { 4017cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb return !isTitleBarShowing() 4027cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb && !isActivityPaused() 4037cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb && (getActiveTab() != null) 4047cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb && (getActiveTab().getWebView() != null) 4057cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb && !mUiController.isInCustomActionMode(); 4068233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4078233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4087cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb void showTitleBar() { 4097cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb mTitleShowing = true; 4107cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4116670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4127cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb protected void hideTitleBar() { 4137cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb mTitleShowing = false; 4147cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4156670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4167cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb protected boolean isTitleBarShowing() { 4177cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb return mTitleShowing; 4187cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4196670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4207cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb protected abstract TitleBarBase getTitleBar(); 4216670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4227cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb protected void setTitleGravity(int gravity) { 4237cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setTitleGravity(gravity); 4247cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb Tab tab = getActiveTab(); 4257cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb if ((tab != null) && (tab.getWebView() != null)) { 4267cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb tab.getWebView().setTitleBarGravity(gravity); 4277cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4287cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4296670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4306670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb @Override 4316670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public void showVoiceTitleBar(String title) { 4327cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setInVoiceMode(true); 4337cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setDisplayTitle(title); 4348233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4358233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4366670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb @Override 4376670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public void revertVoiceTitleBar(Tab tab) { 4387cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setInVoiceMode(false); 43930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck String url = tab.getUrl(); 4407cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setDisplayTitle(url); 4418233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4428233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4438233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 4448233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void showComboView(boolean startWithHistory, Bundle extras) { 445439c9a58765aa6aab95d55422ee61ea8360e912dJohn Reck if (mComboView != null) { 446439c9a58765aa6aab95d55422ee61ea8360e912dJohn Reck return; 447439c9a58765aa6aab95d55422ee61ea8360e912dJohn Reck } 4488233facddcc51865d612a919d450db6954aa48e3Michael Kolb mComboView = new CombinedBookmarkHistoryView(mActivity, 4498233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController, 4508233facddcc51865d612a919d450db6954aa48e3Michael Kolb startWithHistory ? 4518233facddcc51865d612a919d450db6954aa48e3Michael Kolb CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY 4528233facddcc51865d612a919d450db6954aa48e3Michael Kolb : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS, 4538233facddcc51865d612a919d450db6954aa48e3Michael Kolb extras); 45447d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb FrameLayout wrapper = 45547d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); 45647d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb wrapper.setVisibility(View.GONE); 4577cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb hideTitleBar(); 4583a696280cba53eea153c9d5707b236997d193328Michael Kolb dismissIME(); 4593a696280cba53eea153c9d5707b236997d193328Michael Kolb if (mActiveTab != null) { 4603a696280cba53eea153c9d5707b236997d193328Michael Kolb WebView web = mActiveTab.getWebView(); 4613a696280cba53eea153c9d5707b236997d193328Michael Kolb mActiveTab.putInBackground(); 4623a696280cba53eea153c9d5707b236997d193328Michael Kolb } 4635289bc38ab5d94514a3297cebf1a29ed80de9f98John Reck mComboView.setAlpha(0f); 4645289bc38ab5d94514a3297cebf1a29ed80de9f98John Reck ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f); 4655289bc38ab5d94514a3297cebf1a29ed80de9f98John Reck Resources res = mActivity.getResources(); 4665289bc38ab5d94514a3297cebf1a29ed80de9f98John Reck anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration)); 4675289bc38ab5d94514a3297cebf1a29ed80de9f98John Reck anim.start(); 4688233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.addView(mComboView, COVER_SCREEN_PARAMS); 4698233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4708233facddcc51865d612a919d450db6954aa48e3Michael Kolb 471ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb public boolean isComboViewShowing() { 472ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb return (mComboView != null); 473ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb } 474ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb 4758233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 4768233facddcc51865d612a919d450db6954aa48e3Michael Kolb * dismiss the ComboPage 4778233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 4788233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 4798233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void hideComboView() { 4808233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mComboView != null) { 4818233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.removeView(mComboView); 48247d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb FrameLayout wrapper = 48347d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); 48447d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb wrapper.setVisibility(View.VISIBLE); 4858233facddcc51865d612a919d450db6954aa48e3Michael Kolb mComboView = null; 4868233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4873a696280cba53eea153c9d5707b236997d193328Michael Kolb if (mActiveTab != null) { 4883a696280cba53eea153c9d5707b236997d193328Michael Kolb mActiveTab.putInForeground(); 4893a696280cba53eea153c9d5707b236997d193328Michael Kolb } 490b3417f0a68a1efc64604ea354ae7f856ce79cb16John Reck mActivity.invalidateOptionsMenu(); 4918233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4928233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4938233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 4948233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void showCustomView(View view, 4958233facddcc51865d612a919d450db6954aa48e3Michael Kolb WebChromeClient.CustomViewCallback callback) { 4968233facddcc51865d612a919d450db6954aa48e3Michael Kolb // if a view already exists then immediately terminate the new one 4978233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mCustomView != null) { 4988233facddcc51865d612a919d450db6954aa48e3Michael Kolb callback.onCustomViewHidden(); 4998233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 5008233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5018233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5028233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Add the custom view to its container. 5038233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); 5048233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomView = view; 5058233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewCallback = callback; 5068233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Hide the content view. 5078233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.setVisibility(View.GONE); 5088233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Finally show the custom view container. 5098233facddcc51865d612a919d450db6954aa48e3Michael Kolb setStatusBarVisibility(false); 5108233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewContainer.setVisibility(View.VISIBLE); 5118233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewContainer.bringToFront(); 5128233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5138233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5148233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 5158233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onHideCustomView() { 5168233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mCustomView == null) 5178233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 5188233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5198233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Hide the custom view. 5208233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomView.setVisibility(View.GONE); 5218233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Remove the custom view from its container. 5228233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewContainer.removeView(mCustomView); 5238233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomView = null; 5248233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewContainer.setVisibility(View.GONE); 5258233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewCallback.onCustomViewHidden(); 5268233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Show the content view. 5278233facddcc51865d612a919d450db6954aa48e3Michael Kolb setStatusBarVisibility(true); 5288233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.setVisibility(View.VISIBLE); 5298233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5308233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5318233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 5328233facddcc51865d612a919d450db6954aa48e3Michael Kolb public boolean isCustomViewShowing() { 5338233facddcc51865d612a919d450db6954aa48e3Michael Kolb return mCustomView != null; 5348233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5358233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5366670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected void dismissIME() { 5373a696280cba53eea153c9d5707b236997d193328Michael Kolb if (mInputManager.isActive()) { 5383a696280cba53eea153c9d5707b236997d193328Michael Kolb mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), 5393a696280cba53eea153c9d5707b236997d193328Michael Kolb 0); 5403a696280cba53eea153c9d5707b236997d193328Michael Kolb } 5413a696280cba53eea153c9d5707b236997d193328Michael Kolb } 5423a696280cba53eea153c9d5707b236997d193328Michael Kolb 5436670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb @Override 5446670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public boolean showsWeb() { 5456670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb return mCustomView == null 5466670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb && mComboView == null; 5476670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 5486670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 5498233facddcc51865d612a919d450db6954aa48e3Michael Kolb // ------------------------------------------------------------------------- 5508233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5515a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb protected void updateNavigationState(Tab tab) { 5525a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb } 5535a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb 5548233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 5558233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Update the lock icon to correspond to our latest state. 5568233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 5576670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected void updateLockIconToLatest(Tab t) { 55830c714c853a4239e72ab1e238ce2a92472d06ab0John Reck if (t != null && t.inForeground()) { 5598233facddcc51865d612a919d450db6954aa48e3Michael Kolb updateLockIconImage(t.getLockIconType()); 5608233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5618233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5628233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5638233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 5648233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Updates the lock-icon image in the title-bar. 5658233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 56630c714c853a4239e72ab1e238ce2a92472d06ab0John Reck private void updateLockIconImage(LockIcon lockIconType) { 5678233facddcc51865d612a919d450db6954aa48e3Michael Kolb Drawable d = null; 56830c714c853a4239e72ab1e238ce2a92472d06ab0John Reck if (lockIconType == LockIcon.LOCK_ICON_SECURE) { 5698233facddcc51865d612a919d450db6954aa48e3Michael Kolb d = mSecLockIcon; 57030c714c853a4239e72ab1e238ce2a92472d06ab0John Reck } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) { 5718233facddcc51865d612a919d450db6954aa48e3Michael Kolb d = mMixLockIcon; 5728233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5737cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setLock(d); 5748233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5758233facddcc51865d612a919d450db6954aa48e3Michael Kolb 57630c714c853a4239e72ab1e238ce2a92472d06ab0John Reck protected void setUrlTitle(Tab tab) { 57730c714c853a4239e72ab1e238ce2a92472d06ab0John Reck String url = tab.getUrl(); 57830c714c853a4239e72ab1e238ce2a92472d06ab0John Reck String title = tab.getTitle(); 5796670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb if (TextUtils.isEmpty(title)) { 5806670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb title = url; 5816670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 5826670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb if (tab.isInVoiceSearchMode()) return; 5836670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb if (tab.inForeground()) { 5847cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setDisplayTitle(url); 5856670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 5868233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5878233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5886670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb // Set the favicon in the title bar. 58930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck protected void setFavicon(Tab tab) { 59030c714c853a4239e72ab1e238ce2a92472d06ab0John Reck if (tab.inForeground()) { 59130c714c853a4239e72ab1e238ce2a92472d06ab0John Reck Bitmap icon = tab.getFavicon(); 5927cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb getTitleBar().setFavicon(icon); 59330c714c853a4239e72ab1e238ce2a92472d06ab0John Reck } 5948233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5958233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5968233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 5978233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onActionModeFinished(boolean inLoad) { 5988233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (inLoad) { 5998233facddcc51865d612a919d450db6954aa48e3Michael Kolb // the titlebar was removed when the CAB was shown 6008233facddcc51865d612a919d450db6954aa48e3Michael Kolb // if the page is loading, show it again 6017cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb showTitleBar(); 6028233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6038233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6048233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6056670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb // active tabs page 6066670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 6076670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public void showActiveTabsPage() { 6086670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 6096670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 6106670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb /** 6116670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb * Remove the active tabs page. 6126670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb */ 6136670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public void removeActiveTabsPage() { 6146670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 6156670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 6168233facddcc51865d612a919d450db6954aa48e3Michael Kolb // menu handling callbacks 6178233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6188233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6191acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb public boolean onPrepareOptionsMenu(Menu menu) { 6201acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb return true; 6211acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 6221acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 6231acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb @Override 6248233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onOptionsMenuOpened() { 6258233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6268233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6278233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6288233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onExtendedMenuOpened() { 6298233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6308233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6318233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6328233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onOptionsMenuClosed(boolean inLoad) { 6338233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6348233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6358233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6368233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onExtendedMenuClosed(boolean inLoad) { 6378233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6388233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6398233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6408233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onContextMenuCreated(Menu menu) { 6418233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6428233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6438233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6448233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onContextMenuClosed(Menu menu, boolean inLoad) { 6458233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6468233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6478233facddcc51865d612a919d450db6954aa48e3Michael Kolb // error console 6488233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6498233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6508233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void setShouldShowErrorConsole(Tab tab, boolean flag) { 6519fcefd19ee20ec9f792ddc84be9a871550e82997Michael Kolb if (tab == null) return; 6528233facddcc51865d612a919d450db6954aa48e3Michael Kolb ErrorConsoleView errorConsole = tab.getErrorConsole(true); 6538233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (flag) { 6548233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Setting the show state of the console will cause it's the layout 6558233facddcc51865d612a919d450db6954aa48e3Michael Kolb // to be inflated. 6568233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (errorConsole.numberOfErrors() > 0) { 6578233facddcc51865d612a919d450db6954aa48e3Michael Kolb errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); 6588233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 6598233facddcc51865d612a919d450db6954aa48e3Michael Kolb errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); 6608233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6618233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (errorConsole.getParent() != null) { 6628233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.removeView(errorConsole); 6638233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6648233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Now we can add it to the main view. 6658233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.addView(errorConsole, 6668233facddcc51865d612a919d450db6954aa48e3Michael Kolb new LinearLayout.LayoutParams( 6678233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 6688233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.WRAP_CONTENT)); 6698233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 6708233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.removeView(errorConsole); 6718233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6728233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6738233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6748233facddcc51865d612a919d450db6954aa48e3Michael Kolb private void setStatusBarVisibility(boolean visible) { 675d3bf86fd84f4f1a75cc9cd26f818ae157c806d9bJoe Onorato WindowManager.LayoutParams params = mActivity.getWindow().getAttributes(); 676d3bf86fd84f4f1a75cc9cd26f818ae157c806d9bJoe Onorato params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN; 677d3bf86fd84f4f1a75cc9cd26f818ae157c806d9bJoe Onorato mActivity.getWindow().setAttributes(params); 6788233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6798233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6808233facddcc51865d612a919d450db6954aa48e3Michael Kolb // ------------------------------------------------------------------------- 6818233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Helper function for WebChromeClient 6828233facddcc51865d612a919d450db6954aa48e3Michael Kolb // ------------------------------------------------------------------------- 6838233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6848233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6858233facddcc51865d612a919d450db6954aa48e3Michael Kolb public Bitmap getDefaultVideoPoster() { 6868233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mDefaultVideoPoster == null) { 6878233facddcc51865d612a919d450db6954aa48e3Michael Kolb mDefaultVideoPoster = BitmapFactory.decodeResource( 6888233facddcc51865d612a919d450db6954aa48e3Michael Kolb mActivity.getResources(), R.drawable.default_video_poster); 6898233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6908233facddcc51865d612a919d450db6954aa48e3Michael Kolb return mDefaultVideoPoster; 6918233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6928233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6938233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6948233facddcc51865d612a919d450db6954aa48e3Michael Kolb public View getVideoLoadingProgressView() { 6958233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mVideoProgressView == null) { 6968233facddcc51865d612a919d450db6954aa48e3Michael Kolb LayoutInflater inflater = LayoutInflater.from(mActivity); 6978233facddcc51865d612a919d450db6954aa48e3Michael Kolb mVideoProgressView = inflater.inflate( 6988233facddcc51865d612a919d450db6954aa48e3Michael Kolb R.layout.video_loading_progress, null); 6998233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7008233facddcc51865d612a919d450db6954aa48e3Michael Kolb return mVideoProgressView; 7018233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7028233facddcc51865d612a919d450db6954aa48e3Michael Kolb 703843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb @Override 704843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb public void showMaxTabsWarning() { 705843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb Toast warning = Toast.makeText(mActivity, 706843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb mActivity.getString(R.string.max_tabs_warning), 707843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb Toast.LENGTH_SHORT); 708843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb warning.show(); 709843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb } 710843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb 7115119edd5744cfc6d3a8ed480a8853586c737bed4Narayan Kamath @Override 7125119edd5744cfc6d3a8ed480a8853586c737bed4Narayan Kamath public void registerDropdownChangeListener(DropdownChangeListener d) { 7135119edd5744cfc6d3a8ed480a8853586c737bed4Narayan Kamath } 7148233facddcc51865d612a919d450db6954aa48e3Michael Kolb} 715