blob: 15f07c6370f563aa70173d4f44d59a1f931a154d [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;
Narayan Kamath5119edd2011-02-23 15:49:17 +000020import com.android.browser.UI.DropdownChangeListener;
John Reck30c714c2010-12-16 17:30:34 -080021
John Reck5289bc32011-02-18 14:38:08 -080022import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070024import android.content.res.Configuration;
25import android.content.res.Resources;
26import android.graphics.Bitmap;
27import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
29import android.os.Bundle;
30import android.text.TextUtils;
31import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070032import android.view.Gravity;
33import android.view.LayoutInflater;
34import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080036import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080038import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080040import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.webkit.WebView;
43import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080044import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070045import android.widget.LinearLayout;
46import android.widget.Toast;
47
Michael Kolb1bf23132010-11-19 12:55:12 -080048import java.util.List;
49
Michael Kolb8233fac2010-10-26 16:08:53 -070050/**
51 * UI interface definitions
52 */
Michael Kolb66706532010-12-12 19:50:22 -080053public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070054
55 private static final String LOGTAG = "BaseUi";
56
Michael Kolb66706532010-12-12 19:50:22 -080057 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070058 new FrameLayout.LayoutParams(
59 ViewGroup.LayoutParams.MATCH_PARENT,
60 ViewGroup.LayoutParams.MATCH_PARENT);
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT,
66 Gravity.CENTER);
67
68 Activity mActivity;
69 UiController mUiController;
70 TabControl mTabControl;
Michael Kolb77df4562010-11-19 14:49:34 -080071 private Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080072 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070073
74 private Drawable mSecLockIcon;
75 private Drawable mMixLockIcon;
76
Michael Kolb8233fac2010-10-26 16:08:53 -070077 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080078 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070079 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070080
81 private View mCustomView;
82 private WebChromeClient.CustomViewCallback mCustomViewCallback;
83
84 private CombinedBookmarkHistoryView mComboView;
85
86 private LinearLayout mErrorConsoleContainer = null;
87
88 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070089
Michael Kolb7cdc4902011-02-03 17:54:40 -080090 private boolean mTitleShowing;
91
Michael Kolb8233fac2010-10-26 16:08:53 -070092 // the default <video> poster
93 private Bitmap mDefaultVideoPoster;
94 // the video progress view
95 private View mVideoProgressView;
96
Michael Kolb8233fac2010-10-26 16:08:53 -070097 private boolean mActivityPaused;
98
99 public BaseUi(Activity browser, UiController controller) {
100 mActivity = browser;
101 mUiController = controller;
102 mTabControl = controller.getTabControl();
103 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800104 mInputManager = (InputMethodManager)
105 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800106 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
108
Michael Kolb8233fac2010-10-26 16:08:53 -0700109 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
110 .getDecorView().findViewById(android.R.id.content);
111 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
112 .inflate(R.layout.custom_screen, null);
113 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
114 R.id.main_content);
115 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
116 .findViewById(R.id.error_console);
117 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
118 .findViewById(R.id.fullscreen_custom_content);
119 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800120 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700121 }
122
Michael Kolb66706532010-12-12 19:50:22 -0800123 /**
124 * common webview initialization
125 * @param w the webview to initialize
126 */
127 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 w.setScrollbarFadingEnabled(true);
129 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
130 w.setMapTrackballToArrowKeys(false); // use trackball directly
131 // Enable the built-in zoom
132 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700133
134 // Add this WebView to the settings observer list and update the
135 // settings
136 final BrowserSettings s = BrowserSettings.getInstance();
137 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700138 }
139
140 private void cancelStopToast() {
141 if (mStopToast != null) {
142 mStopToast.cancel();
143 mStopToast = null;
144 }
145 }
146
147 // lifecycle
148
149 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800150 if (isCustomViewShowing()) {
151 onHideCustomView();
152 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700153 cancelStopToast();
154 mActivityPaused = true;
155 }
156
157 public void onResume() {
158 mActivityPaused = false;
159 }
160
Michael Kolb66706532010-12-12 19:50:22 -0800161 protected boolean isActivityPaused() {
162 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 }
164
165 public void onConfigurationChanged(Configuration config) {
166 }
167
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800168 public abstract void editUrl(boolean clearInput);
169
Michael Kolb8233fac2010-10-26 16:08:53 -0700170 // key handling
171
172 @Override
173 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700174 if (mComboView != null) {
175 if (!mComboView.onBackPressed()) {
176 mUiController.removeComboView();
177 }
178 return true;
179 }
180 if (mCustomView != null) {
181 mUiController.hideCustomView();
182 return true;
183 }
184 return false;
185 }
186
John Reck30c714c2010-12-16 17:30:34 -0800187 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 @Override
John Reck30c714c2010-12-16 17:30:34 -0800189 public void onTabDataChanged(Tab tab) {
190 setUrlTitle(tab);
191 setFavicon(tab);
192 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800193 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700194 }
195
196 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500197 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800198 if (tab.inForeground()) {
199 boolean isBookmark = tab.isBookmarkedSite();
200 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
201 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500202 }
203
204 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700205 public void onPageStopped(Tab tab) {
206 cancelStopToast();
207 if (tab.inForeground()) {
208 mStopToast = Toast
209 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
210 mStopToast.show();
211 }
212 }
213
214 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800215 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800216 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800217 }
218
219 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 }
222
223 @Override
224 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800225 if ((tab != mActiveTab) && (mActiveTab != null)) {
226 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 }
Michael Kolb77df4562010-11-19 14:49:34 -0800228 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700229 attachTabToContentView(tab);
230 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800231 onTabDataChanged(tab);
232 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800233 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800234 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 }
236
Michael Kolbcfa3af52010-12-14 10:36:11 -0800237 Tab getActiveTab() {
238 return mActiveTab;
239 }
240
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800242 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800243 }
244
245 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700246 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800247 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800249 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700251 }
252
253 @Override
254 public void detachTab(Tab tab) {
255 removeTabFromContentView(tab);
256 }
257
258 @Override
259 public void attachTab(Tab tab) {
260 attachTabToContentView(tab);
261 }
262
263 private void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800264 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 return;
266 }
267 View container = tab.getViewContainer();
268 WebView mainView = tab.getWebView();
269 // Attach the WebView to the container and then attach the
270 // container to the content view.
271 FrameLayout wrapper =
272 (FrameLayout) container.findViewById(R.id.webview_wrapper);
273 ViewGroup parent = (ViewGroup) mainView.getParent();
274 if (parent != wrapper) {
275 if (parent != null) {
276 Log.w(LOGTAG, "mMainView already has a parent in"
277 + " attachTabToContentView!");
278 parent.removeView(mainView);
279 }
280 wrapper.addView(mainView);
281 } else {
282 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
283 + " attachTabToContentView!");
284 }
285 parent = (ViewGroup) container.getParent();
286 if (parent != mContentView) {
287 if (parent != null) {
288 Log.w(LOGTAG, "mContainer already has a parent in"
289 + " attachTabToContentView!");
290 parent.removeView(container);
291 }
292 mContentView.addView(container, COVER_SCREEN_PARAMS);
293 } else {
294 Log.w(LOGTAG, "mContainer is already attached to content in"
295 + " attachTabToContentView!");
296 }
Michael Kolba4183062011-01-16 10:43:21 -0800297 mainView.setNextFocusUpId(R.id.url_focused);
298 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700299 mUiController.attachSubWindow(tab);
300 }
301
302 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800303 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700304 // Remove the container that contains the main WebView.
305 WebView mainView = tab.getWebView();
306 View container = tab.getViewContainer();
307 if (mainView == null) {
308 return;
309 }
310 // Remove the container from the content and then remove the
311 // WebView from the container. This will trigger a focus change
312 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800313 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700314 FrameLayout wrapper =
315 (FrameLayout) container.findViewById(R.id.webview_wrapper);
316 wrapper.removeView(mainView);
317 mContentView.removeView(container);
318 mUiController.endActionMode();
319 mUiController.removeSubWindow(tab);
320 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
321 if (errorConsole != null) {
322 mErrorConsoleContainer.removeView(errorConsole);
323 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700324 }
325
Michael Kolba713ec82010-11-29 17:27:06 -0800326 @Override
327 public void onSetWebView(Tab tab, WebView webView) {
328 View container = tab.getViewContainer();
329 if (container == null) {
330 // The tab consists of a container view, which contains the main
331 // WebView, as well as any other UI elements associated with the tab.
332 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
333 null);
334 tab.setViewContainer(container);
335 }
336 if (tab.getWebView() != webView) {
337 // Just remove the old one.
338 FrameLayout wrapper =
339 (FrameLayout) container.findViewById(R.id.webview_wrapper);
340 wrapper.removeView(tab.getWebView());
341 }
342 }
343
Michael Kolb8233fac2010-10-26 16:08:53 -0700344 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800345 * create a sub window container and webview for the tab
346 * Note: this methods operates through side-effects for now
347 * it sets both the subView and subViewContainer for the given tab
348 * @param tab tab to create the sub window for
349 * @param subView webview to be set as a subwindow for the tab
350 */
351 @Override
352 public void createSubWindow(Tab tab, WebView subView) {
353 View subViewContainer = mActivity.getLayoutInflater().inflate(
354 R.layout.browser_subwindow, null);
355 ViewGroup inner = (ViewGroup) subViewContainer
356 .findViewById(R.id.inner_container);
357 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
358 LayoutParams.MATCH_PARENT));
359 final ImageButton cancel = (ImageButton) subViewContainer
360 .findViewById(R.id.subwindow_close);
361 final WebView cancelSubView = subView;
362 cancel.setOnClickListener(new OnClickListener() {
363 public void onClick(View v) {
364 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
365 }
366 });
367 tab.setSubWebView(subView);
368 tab.setSubViewContainer(subViewContainer);
369 }
370
371 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700372 * Remove the sub window from the content view.
373 */
374 @Override
375 public void removeSubWindow(View subviewContainer) {
376 mContentView.removeView(subviewContainer);
377 mUiController.endActionMode();
378 }
379
380 /**
381 * Attach the sub window to the content view.
382 */
383 @Override
384 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800385 if (container.getParent() != null) {
386 // already attached, remove first
387 ((ViewGroup) container.getParent()).removeView(container);
388 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700389 mContentView.addView(container, COVER_SCREEN_PARAMS);
390 }
391
Michael Kolb7cdc4902011-02-03 17:54:40 -0800392 boolean canShowTitleBar() {
393 return !isTitleBarShowing()
394 && !isActivityPaused()
395 && (getActiveTab() != null)
396 && (getActiveTab().getWebView() != null)
397 && !mUiController.isInCustomActionMode();
398 }
399
400 void showTitleBar() {
401 mTitleShowing = true;
402 }
403
404 protected void hideTitleBar() {
405 mTitleShowing = false;
406 }
407
408 protected boolean isTitleBarShowing() {
409 return mTitleShowing;
410 }
411
412 protected abstract TitleBarBase getTitleBar();
413
414 protected void setTitleGravity(int gravity) {
415 getTitleBar().setTitleGravity(gravity);
416 Tab tab = getActiveTab();
417 if ((tab != null) && (tab.getWebView() != null)) {
418 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700419 }
420 }
421
Michael Kolb66706532010-12-12 19:50:22 -0800422 @Override
423 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800424 getTitleBar().setInVoiceMode(true);
425 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427
Michael Kolb66706532010-12-12 19:50:22 -0800428 @Override
429 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800430 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800431 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800432 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700433 }
434
435 @Override
436 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800437 if (mComboView != null) {
438 return;
439 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700440 mComboView = new CombinedBookmarkHistoryView(mActivity,
441 mUiController,
442 startWithHistory ?
443 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
444 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
445 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800446 FrameLayout wrapper =
447 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
448 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800449 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800450 dismissIME();
451 if (mActiveTab != null) {
452 WebView web = mActiveTab.getWebView();
453 mActiveTab.putInBackground();
454 }
John Reck5289bc32011-02-18 14:38:08 -0800455 mComboView.setAlpha(0f);
456 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
457 Resources res = mActivity.getResources();
458 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
459 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
461 }
462
463 /**
464 * dismiss the ComboPage
465 */
466 @Override
467 public void hideComboView() {
468 if (mComboView != null) {
469 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800470 FrameLayout wrapper =
471 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
472 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700473 mComboView = null;
474 }
Michael Kolb3a696282010-12-05 13:23:24 -0800475 if (mActiveTab != null) {
476 mActiveTab.putInForeground();
477 }
John Reckb3417f02011-01-14 11:01:05 -0800478 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700479 }
480
481 @Override
482 public void showCustomView(View view,
483 WebChromeClient.CustomViewCallback callback) {
484 // if a view already exists then immediately terminate the new one
485 if (mCustomView != null) {
486 callback.onCustomViewHidden();
487 return;
488 }
489
490 // Add the custom view to its container.
491 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
492 mCustomView = view;
493 mCustomViewCallback = callback;
494 // Hide the content view.
495 mContentView.setVisibility(View.GONE);
496 // Finally show the custom view container.
497 setStatusBarVisibility(false);
498 mCustomViewContainer.setVisibility(View.VISIBLE);
499 mCustomViewContainer.bringToFront();
500 }
501
502 @Override
503 public void onHideCustomView() {
504 if (mCustomView == null)
505 return;
506
507 // Hide the custom view.
508 mCustomView.setVisibility(View.GONE);
509 // Remove the custom view from its container.
510 mCustomViewContainer.removeView(mCustomView);
511 mCustomView = null;
512 mCustomViewContainer.setVisibility(View.GONE);
513 mCustomViewCallback.onCustomViewHidden();
514 // Show the content view.
515 setStatusBarVisibility(true);
516 mContentView.setVisibility(View.VISIBLE);
517 }
518
519 @Override
520 public boolean isCustomViewShowing() {
521 return mCustomView != null;
522 }
523
Michael Kolb66706532010-12-12 19:50:22 -0800524 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800525 if (mInputManager.isActive()) {
526 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
527 0);
528 }
529 }
530
Michael Kolb66706532010-12-12 19:50:22 -0800531 @Override
532 public boolean showsWeb() {
533 return mCustomView == null
534 && mComboView == null;
535 }
536
Michael Kolb8233fac2010-10-26 16:08:53 -0700537 // -------------------------------------------------------------------------
538
Michael Kolb5a72f182011-01-13 20:35:06 -0800539 protected void updateNavigationState(Tab tab) {
540 }
541
Michael Kolb8233fac2010-10-26 16:08:53 -0700542 /**
543 * Update the lock icon to correspond to our latest state.
544 */
Michael Kolb66706532010-12-12 19:50:22 -0800545 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800546 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700547 updateLockIconImage(t.getLockIconType());
548 }
549 }
550
551 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700552 * Updates the lock-icon image in the title-bar.
553 */
John Reck30c714c2010-12-16 17:30:34 -0800554 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700555 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800556 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700557 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800558 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700559 d = mMixLockIcon;
560 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800561 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700562 }
563
John Reck30c714c2010-12-16 17:30:34 -0800564 protected void setUrlTitle(Tab tab) {
565 String url = tab.getUrl();
566 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800567 if (TextUtils.isEmpty(title)) {
568 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800569 }
Michael Kolb66706532010-12-12 19:50:22 -0800570 if (tab.isInVoiceSearchMode()) return;
571 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800572 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800573 }
574 }
575
576 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800577 protected void setFavicon(Tab tab) {
578 if (tab.inForeground()) {
579 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800580 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800581 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700582 }
583
584 @Override
585 public void onActionModeFinished(boolean inLoad) {
586 if (inLoad) {
587 // the titlebar was removed when the CAB was shown
588 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800589 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700590 }
591 }
592
Michael Kolb66706532010-12-12 19:50:22 -0800593 // active tabs page
594
595 public void showActiveTabsPage() {
596 }
597
598 /**
599 * Remove the active tabs page.
600 */
601 public void removeActiveTabsPage() {
602 }
603
Michael Kolb8233fac2010-10-26 16:08:53 -0700604 // menu handling callbacks
605
606 @Override
607 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 }
609
610 @Override
611 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 }
613
614 @Override
615 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 }
617
618 @Override
619 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 }
621
622 @Override
623 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700624 }
625
626 @Override
627 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700628 }
629
630 // error console
631
632 @Override
633 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800634 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
636 if (flag) {
637 // Setting the show state of the console will cause it's the layout
638 // to be inflated.
639 if (errorConsole.numberOfErrors() > 0) {
640 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
641 } else {
642 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
643 }
644 if (errorConsole.getParent() != null) {
645 mErrorConsoleContainer.removeView(errorConsole);
646 }
647 // Now we can add it to the main view.
648 mErrorConsoleContainer.addView(errorConsole,
649 new LinearLayout.LayoutParams(
650 ViewGroup.LayoutParams.MATCH_PARENT,
651 ViewGroup.LayoutParams.WRAP_CONTENT));
652 } else {
653 mErrorConsoleContainer.removeView(errorConsole);
654 }
655 }
656
657 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800658 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
659 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
660 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 }
662
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 // -------------------------------------------------------------------------
664 // Helper function for WebChromeClient
665 // -------------------------------------------------------------------------
666
667 @Override
668 public Bitmap getDefaultVideoPoster() {
669 if (mDefaultVideoPoster == null) {
670 mDefaultVideoPoster = BitmapFactory.decodeResource(
671 mActivity.getResources(), R.drawable.default_video_poster);
672 }
673 return mDefaultVideoPoster;
674 }
675
676 @Override
677 public View getVideoLoadingProgressView() {
678 if (mVideoProgressView == null) {
679 LayoutInflater inflater = LayoutInflater.from(mActivity);
680 mVideoProgressView = inflater.inflate(
681 R.layout.video_loading_progress, null);
682 }
683 return mVideoProgressView;
684 }
685
Michael Kolb843510f2010-12-09 10:51:49 -0800686 @Override
687 public void showMaxTabsWarning() {
688 Toast warning = Toast.makeText(mActivity,
689 mActivity.getString(R.string.max_tabs_warning),
690 Toast.LENGTH_SHORT);
691 warning.show();
692 }
693
Narayan Kamath5119edd2011-02-23 15:49:17 +0000694 @Override
695 public void registerDropdownChangeListener(DropdownChangeListener d) {
696 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700697}