blob: 71346ae35b61c74e315811c3520ff97d1ac07cae [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
Michael Kolb377ea312011-02-17 14:36:56 -080022import android.animation.Animator;
23import android.animation.Animator.AnimatorListener;
John Reck5289bc32011-02-18 14:38:08 -080024import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.content.res.Configuration;
27import android.content.res.Resources;
28import android.graphics.Bitmap;
29import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.graphics.drawable.Drawable;
31import android.os.Bundle;
32import android.text.TextUtils;
33import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.view.Gravity;
35import android.view.LayoutInflater;
36import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080038import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080040import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080042import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.webkit.WebView;
45import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080046import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.widget.LinearLayout;
48import android.widget.Toast;
49
Michael Kolb1bf23132010-11-19 12:55:12 -080050import java.util.List;
51
Michael Kolb8233fac2010-10-26 16:08:53 -070052/**
53 * UI interface definitions
54 */
Michael Kolb66706532010-12-12 19:50:22 -080055public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070056
57 private static final String LOGTAG = "BaseUi";
58
Michael Kolb66706532010-12-12 19:50:22 -080059 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070060 new FrameLayout.LayoutParams(
61 ViewGroup.LayoutParams.MATCH_PARENT,
62 ViewGroup.LayoutParams.MATCH_PARENT);
63
Michael Kolb66706532010-12-12 19:50:22 -080064 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070065 new FrameLayout.LayoutParams(
66 ViewGroup.LayoutParams.MATCH_PARENT,
67 ViewGroup.LayoutParams.MATCH_PARENT,
68 Gravity.CENTER);
69
70 Activity mActivity;
71 UiController mUiController;
72 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080073 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080074 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070075
76 private Drawable mSecLockIcon;
77 private Drawable mMixLockIcon;
78
Michael Kolb8233fac2010-10-26 16:08:53 -070079 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080080 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070081 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
83 private View mCustomView;
84 private WebChromeClient.CustomViewCallback mCustomViewCallback;
85
86 private CombinedBookmarkHistoryView mComboView;
87
88 private LinearLayout mErrorConsoleContainer = null;
89
90 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb7cdc4902011-02-03 17:54:40 -080092 private boolean mTitleShowing;
93
Michael Kolb8233fac2010-10-26 16:08:53 -070094 // the default <video> poster
95 private Bitmap mDefaultVideoPoster;
96 // the video progress view
97 private View mVideoProgressView;
98
Michael Kolb8233fac2010-10-26 16:08:53 -070099 private boolean mActivityPaused;
100
101 public BaseUi(Activity browser, UiController controller) {
102 mActivity = browser;
103 mUiController = controller;
104 mTabControl = controller.getTabControl();
105 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800106 mInputManager = (InputMethodManager)
107 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800108 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700109 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
110
Michael Kolb8233fac2010-10-26 16:08:53 -0700111 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
112 .getDecorView().findViewById(android.R.id.content);
113 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
114 .inflate(R.layout.custom_screen, null);
115 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
116 R.id.main_content);
117 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
118 .findViewById(R.id.error_console);
119 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
120 .findViewById(R.id.fullscreen_custom_content);
121 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800122 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700123 }
124
Michael Kolb66706532010-12-12 19:50:22 -0800125 /**
126 * common webview initialization
127 * @param w the webview to initialize
128 */
129 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700130 w.setScrollbarFadingEnabled(true);
131 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
132 w.setMapTrackballToArrowKeys(false); // use trackball directly
133 // Enable the built-in zoom
134 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700135
136 // Add this WebView to the settings observer list and update the
137 // settings
138 final BrowserSettings s = BrowserSettings.getInstance();
139 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700140 }
141
142 private void cancelStopToast() {
143 if (mStopToast != null) {
144 mStopToast.cancel();
145 mStopToast = null;
146 }
147 }
148
149 // lifecycle
150
151 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800152 if (isCustomViewShowing()) {
153 onHideCustomView();
154 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700155 cancelStopToast();
156 mActivityPaused = true;
157 }
158
159 public void onResume() {
160 mActivityPaused = false;
161 }
162
Michael Kolb66706532010-12-12 19:50:22 -0800163 protected boolean isActivityPaused() {
164 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700165 }
166
167 public void onConfigurationChanged(Configuration config) {
168 }
169
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800170 public abstract void editUrl(boolean clearInput);
171
Michael Kolb8233fac2010-10-26 16:08:53 -0700172 // key handling
173
174 @Override
175 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700176 if (mComboView != null) {
177 if (!mComboView.onBackPressed()) {
178 mUiController.removeComboView();
179 }
180 return true;
181 }
182 if (mCustomView != null) {
183 mUiController.hideCustomView();
184 return true;
185 }
186 return false;
187 }
188
John Reck30c714c2010-12-16 17:30:34 -0800189 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 @Override
John Reck30c714c2010-12-16 17:30:34 -0800191 public void onTabDataChanged(Tab tab) {
192 setUrlTitle(tab);
193 setFavicon(tab);
194 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800195 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 }
197
198 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500199 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800200 if (tab.inForeground()) {
201 boolean isBookmark = tab.isBookmarkedSite();
202 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
203 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500204 }
205
206 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 public void onPageStopped(Tab tab) {
208 cancelStopToast();
209 if (tab.inForeground()) {
210 mStopToast = Toast
211 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
212 mStopToast.show();
213 }
214 }
215
216 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800217 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800218 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800219 }
220
221 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 }
224
225 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800226 public void setActiveTab(final Tab tab) {
227 setActiveTab(tab, true);
228 }
229
230 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800231 if ((tab != mActiveTab) && (mActiveTab != null)) {
232 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 }
Michael Kolb77df4562010-11-19 14:49:34 -0800234 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800235 if (needsAttaching) {
236 attachTabToContentView(tab);
237 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800239 onTabDataChanged(tab);
240 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800241 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800242 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500243 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 }
245
Michael Kolbcfa3af52010-12-14 10:36:11 -0800246 Tab getActiveTab() {
247 return mActiveTab;
248 }
249
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800251 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800252 }
253
254 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800256 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800258 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700260 }
261
262 @Override
263 public void detachTab(Tab tab) {
264 removeTabFromContentView(tab);
265 }
266
267 @Override
268 public void attachTab(Tab tab) {
269 attachTabToContentView(tab);
270 }
271
Michael Kolb377ea312011-02-17 14:36:56 -0800272 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800273 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700274 return;
275 }
276 View container = tab.getViewContainer();
277 WebView mainView = tab.getWebView();
278 // Attach the WebView to the container and then attach the
279 // container to the content view.
280 FrameLayout wrapper =
281 (FrameLayout) container.findViewById(R.id.webview_wrapper);
282 ViewGroup parent = (ViewGroup) mainView.getParent();
283 if (parent != wrapper) {
284 if (parent != null) {
285 Log.w(LOGTAG, "mMainView already has a parent in"
286 + " attachTabToContentView!");
287 parent.removeView(mainView);
288 }
289 wrapper.addView(mainView);
290 } else {
291 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
292 + " attachTabToContentView!");
293 }
294 parent = (ViewGroup) container.getParent();
295 if (parent != mContentView) {
296 if (parent != null) {
297 Log.w(LOGTAG, "mContainer already has a parent in"
298 + " attachTabToContentView!");
299 parent.removeView(container);
300 }
301 mContentView.addView(container, COVER_SCREEN_PARAMS);
302 } else {
303 Log.w(LOGTAG, "mContainer is already attached to content in"
304 + " attachTabToContentView!");
305 }
Michael Kolba4183062011-01-16 10:43:21 -0800306 mainView.setNextFocusUpId(R.id.url_focused);
307 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700308 mUiController.attachSubWindow(tab);
309 }
310
311 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800312 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700313 // Remove the container that contains the main WebView.
314 WebView mainView = tab.getWebView();
315 View container = tab.getViewContainer();
316 if (mainView == null) {
317 return;
318 }
319 // Remove the container from the content and then remove the
320 // WebView from the container. This will trigger a focus change
321 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800322 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700323 FrameLayout wrapper =
324 (FrameLayout) container.findViewById(R.id.webview_wrapper);
325 wrapper.removeView(mainView);
326 mContentView.removeView(container);
327 mUiController.endActionMode();
328 mUiController.removeSubWindow(tab);
329 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
330 if (errorConsole != null) {
331 mErrorConsoleContainer.removeView(errorConsole);
332 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700333 }
334
Michael Kolba713ec82010-11-29 17:27:06 -0800335 @Override
336 public void onSetWebView(Tab tab, WebView webView) {
337 View container = tab.getViewContainer();
338 if (container == null) {
339 // The tab consists of a container view, which contains the main
340 // WebView, as well as any other UI elements associated with the tab.
341 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
342 null);
343 tab.setViewContainer(container);
344 }
345 if (tab.getWebView() != webView) {
346 // Just remove the old one.
347 FrameLayout wrapper =
348 (FrameLayout) container.findViewById(R.id.webview_wrapper);
349 wrapper.removeView(tab.getWebView());
350 }
351 }
352
Michael Kolb8233fac2010-10-26 16:08:53 -0700353 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800354 * create a sub window container and webview for the tab
355 * Note: this methods operates through side-effects for now
356 * it sets both the subView and subViewContainer for the given tab
357 * @param tab tab to create the sub window for
358 * @param subView webview to be set as a subwindow for the tab
359 */
360 @Override
361 public void createSubWindow(Tab tab, WebView subView) {
362 View subViewContainer = mActivity.getLayoutInflater().inflate(
363 R.layout.browser_subwindow, null);
364 ViewGroup inner = (ViewGroup) subViewContainer
365 .findViewById(R.id.inner_container);
366 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
367 LayoutParams.MATCH_PARENT));
368 final ImageButton cancel = (ImageButton) subViewContainer
369 .findViewById(R.id.subwindow_close);
370 final WebView cancelSubView = subView;
371 cancel.setOnClickListener(new OnClickListener() {
372 public void onClick(View v) {
373 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
374 }
375 });
376 tab.setSubWebView(subView);
377 tab.setSubViewContainer(subViewContainer);
378 }
379
380 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 * Remove the sub window from the content view.
382 */
383 @Override
384 public void removeSubWindow(View subviewContainer) {
385 mContentView.removeView(subviewContainer);
386 mUiController.endActionMode();
387 }
388
389 /**
390 * Attach the sub window to the content view.
391 */
392 @Override
393 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800394 if (container.getParent() != null) {
395 // already attached, remove first
396 ((ViewGroup) container.getParent()).removeView(container);
397 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700398 mContentView.addView(container, COVER_SCREEN_PARAMS);
399 }
400
Michael Kolb7cdc4902011-02-03 17:54:40 -0800401 boolean canShowTitleBar() {
402 return !isTitleBarShowing()
403 && !isActivityPaused()
404 && (getActiveTab() != null)
405 && (getActiveTab().getWebView() != null)
406 && !mUiController.isInCustomActionMode();
407 }
408
409 void showTitleBar() {
410 mTitleShowing = true;
411 }
412
413 protected void hideTitleBar() {
414 mTitleShowing = false;
415 }
416
417 protected boolean isTitleBarShowing() {
418 return mTitleShowing;
419 }
420
421 protected abstract TitleBarBase getTitleBar();
422
423 protected void setTitleGravity(int gravity) {
424 getTitleBar().setTitleGravity(gravity);
425 Tab tab = getActiveTab();
426 if ((tab != null) && (tab.getWebView() != null)) {
427 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 }
429 }
430
Michael Kolb66706532010-12-12 19:50:22 -0800431 @Override
432 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800433 getTitleBar().setInVoiceMode(true);
434 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700435 }
436
Michael Kolb66706532010-12-12 19:50:22 -0800437 @Override
438 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800439 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800440 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800441 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700442 }
443
444 @Override
445 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800446 if (mComboView != null) {
447 return;
448 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700449 mComboView = new CombinedBookmarkHistoryView(mActivity,
450 mUiController,
451 startWithHistory ?
452 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
453 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
454 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800455 FrameLayout wrapper =
456 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
457 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800458 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800459 dismissIME();
460 if (mActiveTab != null) {
461 WebView web = mActiveTab.getWebView();
462 mActiveTab.putInBackground();
463 }
John Reck5289bc32011-02-18 14:38:08 -0800464 mComboView.setAlpha(0f);
465 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
466 Resources res = mActivity.getResources();
467 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
468 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700469 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
470 }
471
Michael Kolbba238702011-03-08 10:40:50 -0800472 public boolean isComboViewShowing() {
473 return (mComboView != null);
474 }
475
Michael Kolb8233fac2010-10-26 16:08:53 -0700476 /**
477 * dismiss the ComboPage
478 */
479 @Override
480 public void hideComboView() {
481 if (mComboView != null) {
482 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800483 FrameLayout wrapper =
484 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
485 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700486 mComboView = null;
487 }
Michael Kolb3a696282010-12-05 13:23:24 -0800488 if (mActiveTab != null) {
489 mActiveTab.putInForeground();
490 }
John Reckb3417f02011-01-14 11:01:05 -0800491 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700492 }
493
494 @Override
495 public void showCustomView(View view,
496 WebChromeClient.CustomViewCallback callback) {
497 // if a view already exists then immediately terminate the new one
498 if (mCustomView != null) {
499 callback.onCustomViewHidden();
500 return;
501 }
502
503 // Add the custom view to its container.
504 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
505 mCustomView = view;
506 mCustomViewCallback = callback;
507 // Hide the content view.
508 mContentView.setVisibility(View.GONE);
509 // Finally show the custom view container.
510 setStatusBarVisibility(false);
511 mCustomViewContainer.setVisibility(View.VISIBLE);
512 mCustomViewContainer.bringToFront();
513 }
514
515 @Override
516 public void onHideCustomView() {
517 if (mCustomView == null)
518 return;
519
520 // Hide the custom view.
521 mCustomView.setVisibility(View.GONE);
522 // Remove the custom view from its container.
523 mCustomViewContainer.removeView(mCustomView);
524 mCustomView = null;
525 mCustomViewContainer.setVisibility(View.GONE);
526 mCustomViewCallback.onCustomViewHidden();
527 // Show the content view.
528 setStatusBarVisibility(true);
529 mContentView.setVisibility(View.VISIBLE);
530 }
531
532 @Override
533 public boolean isCustomViewShowing() {
534 return mCustomView != null;
535 }
536
Michael Kolb66706532010-12-12 19:50:22 -0800537 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800538 if (mInputManager.isActive()) {
539 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
540 0);
541 }
542 }
543
Michael Kolb66706532010-12-12 19:50:22 -0800544 @Override
545 public boolean showsWeb() {
546 return mCustomView == null
547 && mComboView == null;
548 }
549
Patrick Scott92066772011-03-10 08:46:27 -0500550 @Override
551 public void showAutoLogin(Tab tab) {
552 updateAutoLogin(tab, true);
553 }
554
555 @Override
556 public void hideAutoLogin(Tab tab) {
557 updateAutoLogin(tab, true);
558 }
559
Michael Kolb8233fac2010-10-26 16:08:53 -0700560 // -------------------------------------------------------------------------
561
Michael Kolb5a72f182011-01-13 20:35:06 -0800562 protected void updateNavigationState(Tab tab) {
563 }
564
Patrick Scott92066772011-03-10 08:46:27 -0500565 protected void updateAutoLogin(Tab tab, boolean animate) {}
566
Michael Kolb8233fac2010-10-26 16:08:53 -0700567 /**
568 * Update the lock icon to correspond to our latest state.
569 */
Michael Kolb66706532010-12-12 19:50:22 -0800570 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800571 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700572 updateLockIconImage(t.getLockIconType());
573 }
574 }
575
576 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700577 * Updates the lock-icon image in the title-bar.
578 */
John Reck30c714c2010-12-16 17:30:34 -0800579 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800581 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700582 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800583 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700584 d = mMixLockIcon;
585 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800586 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700587 }
588
John Reck30c714c2010-12-16 17:30:34 -0800589 protected void setUrlTitle(Tab tab) {
590 String url = tab.getUrl();
591 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800592 if (TextUtils.isEmpty(title)) {
593 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800594 }
Michael Kolb66706532010-12-12 19:50:22 -0800595 if (tab.isInVoiceSearchMode()) return;
596 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800597 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800598 }
599 }
600
601 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800602 protected void setFavicon(Tab tab) {
603 if (tab.inForeground()) {
604 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800605 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800606 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 }
608
609 @Override
610 public void onActionModeFinished(boolean inLoad) {
611 if (inLoad) {
612 // the titlebar was removed when the CAB was shown
613 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800614 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 }
616 }
617
Michael Kolb66706532010-12-12 19:50:22 -0800618 // active tabs page
619
620 public void showActiveTabsPage() {
621 }
622
623 /**
624 * Remove the active tabs page.
625 */
626 public void removeActiveTabsPage() {
627 }
628
Michael Kolb8233fac2010-10-26 16:08:53 -0700629 // menu handling callbacks
630
631 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800632 public boolean onPrepareOptionsMenu(Menu menu) {
633 return true;
634 }
635
636 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700637 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700638 }
639
640 @Override
641 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 }
643
644 @Override
645 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700646 }
647
648 @Override
649 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700650 }
651
652 @Override
653 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700654 }
655
656 @Override
657 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 }
659
660 // error console
661
662 @Override
663 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800664 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700665 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
666 if (flag) {
667 // Setting the show state of the console will cause it's the layout
668 // to be inflated.
669 if (errorConsole.numberOfErrors() > 0) {
670 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
671 } else {
672 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
673 }
674 if (errorConsole.getParent() != null) {
675 mErrorConsoleContainer.removeView(errorConsole);
676 }
677 // Now we can add it to the main view.
678 mErrorConsoleContainer.addView(errorConsole,
679 new LinearLayout.LayoutParams(
680 ViewGroup.LayoutParams.MATCH_PARENT,
681 ViewGroup.LayoutParams.WRAP_CONTENT));
682 } else {
683 mErrorConsoleContainer.removeView(errorConsole);
684 }
685 }
686
687 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800688 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
689 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
690 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700691 }
692
Michael Kolb8233fac2010-10-26 16:08:53 -0700693 // -------------------------------------------------------------------------
694 // Helper function for WebChromeClient
695 // -------------------------------------------------------------------------
696
697 @Override
698 public Bitmap getDefaultVideoPoster() {
699 if (mDefaultVideoPoster == null) {
700 mDefaultVideoPoster = BitmapFactory.decodeResource(
701 mActivity.getResources(), R.drawable.default_video_poster);
702 }
703 return mDefaultVideoPoster;
704 }
705
706 @Override
707 public View getVideoLoadingProgressView() {
708 if (mVideoProgressView == null) {
709 LayoutInflater inflater = LayoutInflater.from(mActivity);
710 mVideoProgressView = inflater.inflate(
711 R.layout.video_loading_progress, null);
712 }
713 return mVideoProgressView;
714 }
715
Michael Kolb843510f2010-12-09 10:51:49 -0800716 @Override
717 public void showMaxTabsWarning() {
718 Toast warning = Toast.makeText(mActivity,
719 mActivity.getString(R.string.max_tabs_warning),
720 Toast.LENGTH_SHORT);
721 warning.show();
722 }
723
Narayan Kamath5119edd2011-02-23 15:49:17 +0000724 @Override
725 public void registerDropdownChangeListener(DropdownChangeListener d) {
726 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700727}