blob: bca999d4105e8be01213ab4744f32936ccaa065b [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
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
20
John Reck5289bc32011-02-18 14:38:08 -080021import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.graphics.Bitmap;
26import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070027import android.graphics.drawable.Drawable;
28import android.os.Bundle;
29import android.text.TextUtils;
30import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.view.Gravity;
32import android.view.LayoutInflater;
33import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080035import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080037import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080039import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.webkit.WebView;
42import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.widget.LinearLayout;
45import android.widget.Toast;
46
Michael Kolb1bf23132010-11-19 12:55:12 -080047import java.util.List;
48
Michael Kolb8233fac2010-10-26 16:08:53 -070049/**
50 * UI interface definitions
51 */
Michael Kolb66706532010-12-12 19:50:22 -080052public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070053
54 private static final String LOGTAG = "BaseUi";
55
Michael Kolb66706532010-12-12 19:50:22 -080056 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070057 new FrameLayout.LayoutParams(
58 ViewGroup.LayoutParams.MATCH_PARENT,
59 ViewGroup.LayoutParams.MATCH_PARENT);
60
Michael Kolb66706532010-12-12 19:50:22 -080061 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070062 new FrameLayout.LayoutParams(
63 ViewGroup.LayoutParams.MATCH_PARENT,
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 Gravity.CENTER);
66
67 Activity mActivity;
68 UiController mUiController;
69 TabControl mTabControl;
Michael Kolb77df4562010-11-19 14:49:34 -080070 private Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080071 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070072
73 private Drawable mSecLockIcon;
74 private Drawable mMixLockIcon;
75
Michael Kolb8233fac2010-10-26 16:08:53 -070076 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080077 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070078 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070079
80 private View mCustomView;
81 private WebChromeClient.CustomViewCallback mCustomViewCallback;
82
83 private CombinedBookmarkHistoryView mComboView;
84
85 private LinearLayout mErrorConsoleContainer = null;
86
87 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Michael Kolb7cdc4902011-02-03 17:54:40 -080089 private boolean mTitleShowing;
90
Michael Kolb8233fac2010-10-26 16:08:53 -070091 // the default <video> poster
92 private Bitmap mDefaultVideoPoster;
93 // the video progress view
94 private View mVideoProgressView;
95
Michael Kolb8233fac2010-10-26 16:08:53 -070096 private boolean mActivityPaused;
97
98 public BaseUi(Activity browser, UiController controller) {
99 mActivity = browser;
100 mUiController = controller;
101 mTabControl = controller.getTabControl();
102 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800103 mInputManager = (InputMethodManager)
104 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800105 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
107
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
109 .getDecorView().findViewById(android.R.id.content);
110 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
111 .inflate(R.layout.custom_screen, null);
112 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
113 R.id.main_content);
114 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
115 .findViewById(R.id.error_console);
116 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
117 .findViewById(R.id.fullscreen_custom_content);
118 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800119 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700120 }
121
Michael Kolb66706532010-12-12 19:50:22 -0800122 /**
123 * common webview initialization
124 * @param w the webview to initialize
125 */
126 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700127 w.setScrollbarFadingEnabled(true);
128 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
129 w.setMapTrackballToArrowKeys(false); // use trackball directly
130 // Enable the built-in zoom
131 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700132
133 // Add this WebView to the settings observer list and update the
134 // settings
135 final BrowserSettings s = BrowserSettings.getInstance();
136 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700137 }
138
139 private void cancelStopToast() {
140 if (mStopToast != null) {
141 mStopToast.cancel();
142 mStopToast = null;
143 }
144 }
145
146 // lifecycle
147
148 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800149 if (isCustomViewShowing()) {
150 onHideCustomView();
151 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700152 cancelStopToast();
153 mActivityPaused = true;
154 }
155
156 public void onResume() {
157 mActivityPaused = false;
158 }
159
Michael Kolb66706532010-12-12 19:50:22 -0800160 protected boolean isActivityPaused() {
161 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700162 }
163
164 public void onConfigurationChanged(Configuration config) {
165 }
166
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800167 public abstract void editUrl(boolean clearInput);
168
Michael Kolb8233fac2010-10-26 16:08:53 -0700169 // key handling
170
171 @Override
172 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700173 if (mComboView != null) {
174 if (!mComboView.onBackPressed()) {
175 mUiController.removeComboView();
176 }
177 return true;
178 }
179 if (mCustomView != null) {
180 mUiController.hideCustomView();
181 return true;
182 }
183 return false;
184 }
185
John Reck30c714c2010-12-16 17:30:34 -0800186 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 @Override
John Reck30c714c2010-12-16 17:30:34 -0800188 public void onTabDataChanged(Tab tab) {
189 setUrlTitle(tab);
190 setFavicon(tab);
191 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800192 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 }
194
195 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500196 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800197 if (tab.inForeground()) {
198 boolean isBookmark = tab.isBookmarkedSite();
199 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
200 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500201 }
202
203 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700204 public void onPageStopped(Tab tab) {
205 cancelStopToast();
206 if (tab.inForeground()) {
207 mStopToast = Toast
208 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
209 mStopToast.show();
210 }
211 }
212
213 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800214 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800215 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800216 }
217
218 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 }
221
222 @Override
223 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800224 if ((tab != mActiveTab) && (mActiveTab != null)) {
225 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 }
Michael Kolb77df4562010-11-19 14:49:34 -0800227 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 attachTabToContentView(tab);
229 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800230 onTabDataChanged(tab);
231 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800232 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800233 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 }
235
Michael Kolbcfa3af52010-12-14 10:36:11 -0800236 Tab getActiveTab() {
237 return mActiveTab;
238 }
239
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800241 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800242 }
243
244 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700245 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800246 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800248 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 }
251
252 @Override
253 public void detachTab(Tab tab) {
254 removeTabFromContentView(tab);
255 }
256
257 @Override
258 public void attachTab(Tab tab) {
259 attachTabToContentView(tab);
260 }
261
262 private void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800263 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700264 return;
265 }
266 View container = tab.getViewContainer();
267 WebView mainView = tab.getWebView();
268 // Attach the WebView to the container and then attach the
269 // container to the content view.
270 FrameLayout wrapper =
271 (FrameLayout) container.findViewById(R.id.webview_wrapper);
272 ViewGroup parent = (ViewGroup) mainView.getParent();
273 if (parent != wrapper) {
274 if (parent != null) {
275 Log.w(LOGTAG, "mMainView already has a parent in"
276 + " attachTabToContentView!");
277 parent.removeView(mainView);
278 }
279 wrapper.addView(mainView);
280 } else {
281 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
282 + " attachTabToContentView!");
283 }
284 parent = (ViewGroup) container.getParent();
285 if (parent != mContentView) {
286 if (parent != null) {
287 Log.w(LOGTAG, "mContainer already has a parent in"
288 + " attachTabToContentView!");
289 parent.removeView(container);
290 }
291 mContentView.addView(container, COVER_SCREEN_PARAMS);
292 } else {
293 Log.w(LOGTAG, "mContainer is already attached to content in"
294 + " attachTabToContentView!");
295 }
Michael Kolba4183062011-01-16 10:43:21 -0800296 mainView.setNextFocusUpId(R.id.url_focused);
297 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700298 mUiController.attachSubWindow(tab);
299 }
300
301 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800302 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700303 // Remove the container that contains the main WebView.
304 WebView mainView = tab.getWebView();
305 View container = tab.getViewContainer();
306 if (mainView == null) {
307 return;
308 }
309 // Remove the container from the content and then remove the
310 // WebView from the container. This will trigger a focus change
311 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800312 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700313 FrameLayout wrapper =
314 (FrameLayout) container.findViewById(R.id.webview_wrapper);
315 wrapper.removeView(mainView);
316 mContentView.removeView(container);
317 mUiController.endActionMode();
318 mUiController.removeSubWindow(tab);
319 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
320 if (errorConsole != null) {
321 mErrorConsoleContainer.removeView(errorConsole);
322 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700323 }
324
Michael Kolba713ec82010-11-29 17:27:06 -0800325 @Override
326 public void onSetWebView(Tab tab, WebView webView) {
327 View container = tab.getViewContainer();
328 if (container == null) {
329 // The tab consists of a container view, which contains the main
330 // WebView, as well as any other UI elements associated with the tab.
331 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
332 null);
333 tab.setViewContainer(container);
334 }
335 if (tab.getWebView() != webView) {
336 // Just remove the old one.
337 FrameLayout wrapper =
338 (FrameLayout) container.findViewById(R.id.webview_wrapper);
339 wrapper.removeView(tab.getWebView());
340 }
341 }
342
Michael Kolb8233fac2010-10-26 16:08:53 -0700343 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800344 * create a sub window container and webview for the tab
345 * Note: this methods operates through side-effects for now
346 * it sets both the subView and subViewContainer for the given tab
347 * @param tab tab to create the sub window for
348 * @param subView webview to be set as a subwindow for the tab
349 */
350 @Override
351 public void createSubWindow(Tab tab, WebView subView) {
352 View subViewContainer = mActivity.getLayoutInflater().inflate(
353 R.layout.browser_subwindow, null);
354 ViewGroup inner = (ViewGroup) subViewContainer
355 .findViewById(R.id.inner_container);
356 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
357 LayoutParams.MATCH_PARENT));
358 final ImageButton cancel = (ImageButton) subViewContainer
359 .findViewById(R.id.subwindow_close);
360 final WebView cancelSubView = subView;
361 cancel.setOnClickListener(new OnClickListener() {
362 public void onClick(View v) {
363 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
364 }
365 });
366 tab.setSubWebView(subView);
367 tab.setSubViewContainer(subViewContainer);
368 }
369
370 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700371 * Remove the sub window from the content view.
372 */
373 @Override
374 public void removeSubWindow(View subviewContainer) {
375 mContentView.removeView(subviewContainer);
376 mUiController.endActionMode();
377 }
378
379 /**
380 * Attach the sub window to the content view.
381 */
382 @Override
383 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800384 if (container.getParent() != null) {
385 // already attached, remove first
386 ((ViewGroup) container.getParent()).removeView(container);
387 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700388 mContentView.addView(container, COVER_SCREEN_PARAMS);
389 }
390
Michael Kolb7cdc4902011-02-03 17:54:40 -0800391 boolean canShowTitleBar() {
392 return !isTitleBarShowing()
393 && !isActivityPaused()
394 && (getActiveTab() != null)
395 && (getActiveTab().getWebView() != null)
396 && !mUiController.isInCustomActionMode();
397 }
398
399 void showTitleBar() {
400 mTitleShowing = true;
401 }
402
403 protected void hideTitleBar() {
404 mTitleShowing = false;
405 }
406
407 protected boolean isTitleBarShowing() {
408 return mTitleShowing;
409 }
410
411 protected abstract TitleBarBase getTitleBar();
412
413 protected void setTitleGravity(int gravity) {
414 getTitleBar().setTitleGravity(gravity);
415 Tab tab = getActiveTab();
416 if ((tab != null) && (tab.getWebView() != null)) {
417 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700418 }
419 }
420
Michael Kolb66706532010-12-12 19:50:22 -0800421 @Override
422 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800423 getTitleBar().setInVoiceMode(true);
424 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700425 }
426
Michael Kolb66706532010-12-12 19:50:22 -0800427 @Override
428 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800429 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800430 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800431 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700432 }
433
434 @Override
435 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800436 if (mComboView != null) {
437 return;
438 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700439 mComboView = new CombinedBookmarkHistoryView(mActivity,
440 mUiController,
441 startWithHistory ?
442 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
443 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
444 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800445 FrameLayout wrapper =
446 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
447 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800448 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800449 dismissIME();
450 if (mActiveTab != null) {
451 WebView web = mActiveTab.getWebView();
452 mActiveTab.putInBackground();
453 }
John Reck5289bc32011-02-18 14:38:08 -0800454 mComboView.setAlpha(0f);
455 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
456 Resources res = mActivity.getResources();
457 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
458 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700459 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
460 }
461
462 /**
463 * dismiss the ComboPage
464 */
465 @Override
466 public void hideComboView() {
467 if (mComboView != null) {
468 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800469 FrameLayout wrapper =
470 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
471 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 mComboView = null;
473 }
Michael Kolb3a696282010-12-05 13:23:24 -0800474 if (mActiveTab != null) {
475 mActiveTab.putInForeground();
476 }
John Reckb3417f02011-01-14 11:01:05 -0800477 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700478 }
479
480 @Override
481 public void showCustomView(View view,
482 WebChromeClient.CustomViewCallback callback) {
483 // if a view already exists then immediately terminate the new one
484 if (mCustomView != null) {
485 callback.onCustomViewHidden();
486 return;
487 }
488
489 // Add the custom view to its container.
490 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
491 mCustomView = view;
492 mCustomViewCallback = callback;
493 // Hide the content view.
494 mContentView.setVisibility(View.GONE);
495 // Finally show the custom view container.
496 setStatusBarVisibility(false);
497 mCustomViewContainer.setVisibility(View.VISIBLE);
498 mCustomViewContainer.bringToFront();
499 }
500
501 @Override
502 public void onHideCustomView() {
503 if (mCustomView == null)
504 return;
505
506 // Hide the custom view.
507 mCustomView.setVisibility(View.GONE);
508 // Remove the custom view from its container.
509 mCustomViewContainer.removeView(mCustomView);
510 mCustomView = null;
511 mCustomViewContainer.setVisibility(View.GONE);
512 mCustomViewCallback.onCustomViewHidden();
513 // Show the content view.
514 setStatusBarVisibility(true);
515 mContentView.setVisibility(View.VISIBLE);
516 }
517
518 @Override
519 public boolean isCustomViewShowing() {
520 return mCustomView != null;
521 }
522
Michael Kolb66706532010-12-12 19:50:22 -0800523 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800524 if (mInputManager.isActive()) {
525 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
526 0);
527 }
528 }
529
Michael Kolb66706532010-12-12 19:50:22 -0800530 @Override
531 public boolean showsWeb() {
532 return mCustomView == null
533 && mComboView == null;
534 }
535
Michael Kolb8233fac2010-10-26 16:08:53 -0700536 // -------------------------------------------------------------------------
537
Michael Kolb5a72f182011-01-13 20:35:06 -0800538 protected void updateNavigationState(Tab tab) {
539 }
540
Michael Kolb8233fac2010-10-26 16:08:53 -0700541 /**
542 * Update the lock icon to correspond to our latest state.
543 */
Michael Kolb66706532010-12-12 19:50:22 -0800544 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800545 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700546 updateLockIconImage(t.getLockIconType());
547 }
548 }
549
550 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700551 * Updates the lock-icon image in the title-bar.
552 */
John Reck30c714c2010-12-16 17:30:34 -0800553 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700554 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800555 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700556 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800557 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700558 d = mMixLockIcon;
559 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800560 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700561 }
562
John Reck30c714c2010-12-16 17:30:34 -0800563 protected void setUrlTitle(Tab tab) {
564 String url = tab.getUrl();
565 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800566 if (TextUtils.isEmpty(title)) {
567 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800568 }
Michael Kolb66706532010-12-12 19:50:22 -0800569 if (tab.isInVoiceSearchMode()) return;
570 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800571 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800572 }
573 }
574
575 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800576 protected void setFavicon(Tab tab) {
577 if (tab.inForeground()) {
578 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800579 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800580 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700581 }
582
583 @Override
584 public void onActionModeFinished(boolean inLoad) {
585 if (inLoad) {
586 // the titlebar was removed when the CAB was shown
587 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800588 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700589 }
590 }
591
Michael Kolb66706532010-12-12 19:50:22 -0800592 // active tabs page
593
594 public void showActiveTabsPage() {
595 }
596
597 /**
598 * Remove the active tabs page.
599 */
600 public void removeActiveTabsPage() {
601 }
602
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 // menu handling callbacks
604
605 @Override
606 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 }
608
609 @Override
610 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 }
612
613 @Override
614 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 }
616
617 @Override
618 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700619 }
620
621 @Override
622 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700623 }
624
625 @Override
626 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700627 }
628
629 // error console
630
631 @Override
632 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800633 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700634 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
635 if (flag) {
636 // Setting the show state of the console will cause it's the layout
637 // to be inflated.
638 if (errorConsole.numberOfErrors() > 0) {
639 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
640 } else {
641 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
642 }
643 if (errorConsole.getParent() != null) {
644 mErrorConsoleContainer.removeView(errorConsole);
645 }
646 // Now we can add it to the main view.
647 mErrorConsoleContainer.addView(errorConsole,
648 new LinearLayout.LayoutParams(
649 ViewGroup.LayoutParams.MATCH_PARENT,
650 ViewGroup.LayoutParams.WRAP_CONTENT));
651 } else {
652 mErrorConsoleContainer.removeView(errorConsole);
653 }
654 }
655
656 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800657 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
658 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
659 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700660 }
661
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 // -------------------------------------------------------------------------
663 // Helper function for WebChromeClient
664 // -------------------------------------------------------------------------
665
666 @Override
667 public Bitmap getDefaultVideoPoster() {
668 if (mDefaultVideoPoster == null) {
669 mDefaultVideoPoster = BitmapFactory.decodeResource(
670 mActivity.getResources(), R.drawable.default_video_poster);
671 }
672 return mDefaultVideoPoster;
673 }
674
675 @Override
676 public View getVideoLoadingProgressView() {
677 if (mVideoProgressView == null) {
678 LayoutInflater inflater = LayoutInflater.from(mActivity);
679 mVideoProgressView = inflater.inflate(
680 R.layout.video_loading_progress, null);
681 }
682 return mVideoProgressView;
683 }
684
Michael Kolb843510f2010-12-09 10:51:49 -0800685 @Override
686 public void showMaxTabsWarning() {
687 Toast warning = Toast.makeText(mActivity,
688 mActivity.getString(R.string.max_tabs_warning),
689 Toast.LENGTH_SHORT);
690 warning.show();
691 }
692
Michael Kolb8233fac2010-10-26 16:08:53 -0700693}