blob: 589868008182409e75ef2b06e87707e808fec89e [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 Recke5c21d92011-03-11 15:09:46 -080021import android.animation.LayoutTransition;
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 Kolb377ea312011-02-17 14:36:56 -080070 protected 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);
John Recke5c21d92011-03-11 15:09:46 -0800114 mContentView.setLayoutTransition(new LayoutTransition());
Michael Kolb8233fac2010-10-26 16:08:53 -0700115 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
Michael Kolb377ea312011-02-17 14:36:56 -0800224 public void setActiveTab(final Tab tab) {
225 setActiveTab(tab, true);
226 }
227
228 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800229 if ((tab != mActiveTab) && (mActiveTab != null)) {
230 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700231 }
Michael Kolb77df4562010-11-19 14:49:34 -0800232 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800233 if (needsAttaching) {
234 attachTabToContentView(tab);
235 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800237 onTabDataChanged(tab);
238 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800239 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800240 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500241 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 }
243
Michael Kolbcfa3af52010-12-14 10:36:11 -0800244 Tab getActiveTab() {
245 return mActiveTab;
246 }
247
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800249 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800250 }
251
252 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700253 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800254 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800256 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700258 }
259
260 @Override
261 public void detachTab(Tab tab) {
262 removeTabFromContentView(tab);
263 }
264
265 @Override
266 public void attachTab(Tab tab) {
267 attachTabToContentView(tab);
268 }
269
Michael Kolb377ea312011-02-17 14:36:56 -0800270 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800271 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 return;
273 }
274 View container = tab.getViewContainer();
275 WebView mainView = tab.getWebView();
276 // Attach the WebView to the container and then attach the
277 // container to the content view.
278 FrameLayout wrapper =
279 (FrameLayout) container.findViewById(R.id.webview_wrapper);
280 ViewGroup parent = (ViewGroup) mainView.getParent();
281 if (parent != wrapper) {
282 if (parent != null) {
283 Log.w(LOGTAG, "mMainView already has a parent in"
284 + " attachTabToContentView!");
285 parent.removeView(mainView);
286 }
287 wrapper.addView(mainView);
288 } else {
289 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
290 + " attachTabToContentView!");
291 }
292 parent = (ViewGroup) container.getParent();
293 if (parent != mContentView) {
294 if (parent != null) {
295 Log.w(LOGTAG, "mContainer already has a parent in"
296 + " attachTabToContentView!");
297 parent.removeView(container);
298 }
299 mContentView.addView(container, COVER_SCREEN_PARAMS);
300 } else {
301 Log.w(LOGTAG, "mContainer is already attached to content in"
302 + " attachTabToContentView!");
303 }
Michael Kolba4183062011-01-16 10:43:21 -0800304 mainView.setNextFocusUpId(R.id.url_focused);
305 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700306 mUiController.attachSubWindow(tab);
307 }
308
309 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800310 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700311 // Remove the container that contains the main WebView.
312 WebView mainView = tab.getWebView();
313 View container = tab.getViewContainer();
314 if (mainView == null) {
315 return;
316 }
317 // Remove the container from the content and then remove the
318 // WebView from the container. This will trigger a focus change
319 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800320 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700321 FrameLayout wrapper =
322 (FrameLayout) container.findViewById(R.id.webview_wrapper);
323 wrapper.removeView(mainView);
324 mContentView.removeView(container);
325 mUiController.endActionMode();
326 mUiController.removeSubWindow(tab);
327 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
328 if (errorConsole != null) {
329 mErrorConsoleContainer.removeView(errorConsole);
330 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700331 }
332
Michael Kolba713ec82010-11-29 17:27:06 -0800333 @Override
334 public void onSetWebView(Tab tab, WebView webView) {
335 View container = tab.getViewContainer();
336 if (container == null) {
337 // The tab consists of a container view, which contains the main
338 // WebView, as well as any other UI elements associated with the tab.
339 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
340 null);
341 tab.setViewContainer(container);
342 }
343 if (tab.getWebView() != webView) {
344 // Just remove the old one.
345 FrameLayout wrapper =
346 (FrameLayout) container.findViewById(R.id.webview_wrapper);
347 wrapper.removeView(tab.getWebView());
348 }
349 }
350
Michael Kolb8233fac2010-10-26 16:08:53 -0700351 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800352 * create a sub window container and webview for the tab
353 * Note: this methods operates through side-effects for now
354 * it sets both the subView and subViewContainer for the given tab
355 * @param tab tab to create the sub window for
356 * @param subView webview to be set as a subwindow for the tab
357 */
358 @Override
359 public void createSubWindow(Tab tab, WebView subView) {
360 View subViewContainer = mActivity.getLayoutInflater().inflate(
361 R.layout.browser_subwindow, null);
362 ViewGroup inner = (ViewGroup) subViewContainer
363 .findViewById(R.id.inner_container);
364 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
365 LayoutParams.MATCH_PARENT));
366 final ImageButton cancel = (ImageButton) subViewContainer
367 .findViewById(R.id.subwindow_close);
368 final WebView cancelSubView = subView;
369 cancel.setOnClickListener(new OnClickListener() {
370 public void onClick(View v) {
371 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
372 }
373 });
374 tab.setSubWebView(subView);
375 tab.setSubViewContainer(subViewContainer);
376 }
377
378 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 * Remove the sub window from the content view.
380 */
381 @Override
382 public void removeSubWindow(View subviewContainer) {
383 mContentView.removeView(subviewContainer);
384 mUiController.endActionMode();
385 }
386
387 /**
388 * Attach the sub window to the content view.
389 */
390 @Override
391 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800392 if (container.getParent() != null) {
393 // already attached, remove first
394 ((ViewGroup) container.getParent()).removeView(container);
395 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700396 mContentView.addView(container, COVER_SCREEN_PARAMS);
397 }
398
Michael Kolb7cdc4902011-02-03 17:54:40 -0800399 boolean canShowTitleBar() {
400 return !isTitleBarShowing()
401 && !isActivityPaused()
402 && (getActiveTab() != null)
403 && (getActiveTab().getWebView() != null)
404 && !mUiController.isInCustomActionMode();
405 }
406
407 void showTitleBar() {
408 mTitleShowing = true;
409 }
410
411 protected void hideTitleBar() {
412 mTitleShowing = false;
413 }
414
415 protected boolean isTitleBarShowing() {
416 return mTitleShowing;
417 }
418
419 protected abstract TitleBarBase getTitleBar();
420
421 protected void setTitleGravity(int gravity) {
422 getTitleBar().setTitleGravity(gravity);
423 Tab tab = getActiveTab();
424 if ((tab != null) && (tab.getWebView() != null)) {
425 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427 }
428
Michael Kolb66706532010-12-12 19:50:22 -0800429 @Override
430 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800431 getTitleBar().setInVoiceMode(true);
432 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700433 }
434
Michael Kolb66706532010-12-12 19:50:22 -0800435 @Override
436 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800437 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800438 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800439 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700440 }
441
442 @Override
443 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800444 if (mComboView != null) {
445 return;
446 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700447 mComboView = new CombinedBookmarkHistoryView(mActivity,
448 mUiController,
449 startWithHistory ?
450 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
451 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
452 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800453 FrameLayout wrapper =
454 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
455 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800456 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800457 dismissIME();
458 if (mActiveTab != null) {
459 WebView web = mActiveTab.getWebView();
460 mActiveTab.putInBackground();
461 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700462 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
463 }
464
Michael Kolbba238702011-03-08 10:40:50 -0800465 public boolean isComboViewShowing() {
466 return (mComboView != null);
467 }
468
Michael Kolb8233fac2010-10-26 16:08:53 -0700469 /**
470 * dismiss the ComboPage
471 */
472 @Override
473 public void hideComboView() {
474 if (mComboView != null) {
475 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800476 FrameLayout wrapper =
477 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
478 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700479 mComboView = null;
480 }
Michael Kolb3a696282010-12-05 13:23:24 -0800481 if (mActiveTab != null) {
482 mActiveTab.putInForeground();
483 }
John Reckb3417f02011-01-14 11:01:05 -0800484 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700485 }
486
487 @Override
488 public void showCustomView(View view,
489 WebChromeClient.CustomViewCallback callback) {
490 // if a view already exists then immediately terminate the new one
491 if (mCustomView != null) {
492 callback.onCustomViewHidden();
493 return;
494 }
495
496 // Add the custom view to its container.
497 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
498 mCustomView = view;
499 mCustomViewCallback = callback;
500 // Hide the content view.
501 mContentView.setVisibility(View.GONE);
502 // Finally show the custom view container.
503 setStatusBarVisibility(false);
504 mCustomViewContainer.setVisibility(View.VISIBLE);
505 mCustomViewContainer.bringToFront();
506 }
507
508 @Override
509 public void onHideCustomView() {
510 if (mCustomView == null)
511 return;
512
513 // Hide the custom view.
514 mCustomView.setVisibility(View.GONE);
515 // Remove the custom view from its container.
516 mCustomViewContainer.removeView(mCustomView);
517 mCustomView = null;
518 mCustomViewContainer.setVisibility(View.GONE);
519 mCustomViewCallback.onCustomViewHidden();
520 // Show the content view.
521 setStatusBarVisibility(true);
522 mContentView.setVisibility(View.VISIBLE);
523 }
524
525 @Override
526 public boolean isCustomViewShowing() {
527 return mCustomView != null;
528 }
529
Michael Kolb66706532010-12-12 19:50:22 -0800530 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800531 if (mInputManager.isActive()) {
532 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
533 0);
534 }
535 }
536
Michael Kolb66706532010-12-12 19:50:22 -0800537 @Override
538 public boolean showsWeb() {
539 return mCustomView == null
540 && mComboView == null;
541 }
542
Patrick Scott92066772011-03-10 08:46:27 -0500543 @Override
544 public void showAutoLogin(Tab tab) {
545 updateAutoLogin(tab, true);
546 }
547
548 @Override
549 public void hideAutoLogin(Tab tab) {
550 updateAutoLogin(tab, true);
551 }
552
Michael Kolb8233fac2010-10-26 16:08:53 -0700553 // -------------------------------------------------------------------------
554
Michael Kolb5a72f182011-01-13 20:35:06 -0800555 protected void updateNavigationState(Tab tab) {
556 }
557
Patrick Scott92066772011-03-10 08:46:27 -0500558 protected void updateAutoLogin(Tab tab, boolean animate) {}
559
Michael Kolb8233fac2010-10-26 16:08:53 -0700560 /**
561 * Update the lock icon to correspond to our latest state.
562 */
Michael Kolb66706532010-12-12 19:50:22 -0800563 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800564 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700565 updateLockIconImage(t.getLockIconType());
566 }
567 }
568
569 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700570 * Updates the lock-icon image in the title-bar.
571 */
John Reck30c714c2010-12-16 17:30:34 -0800572 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700573 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800574 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700575 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800576 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700577 d = mMixLockIcon;
578 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800579 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 }
581
John Reck30c714c2010-12-16 17:30:34 -0800582 protected void setUrlTitle(Tab tab) {
583 String url = tab.getUrl();
584 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800585 if (TextUtils.isEmpty(title)) {
586 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800587 }
Michael Kolb66706532010-12-12 19:50:22 -0800588 if (tab.isInVoiceSearchMode()) return;
589 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800590 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800591 }
592 }
593
594 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800595 protected void setFavicon(Tab tab) {
596 if (tab.inForeground()) {
597 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800598 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800599 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700600 }
601
602 @Override
603 public void onActionModeFinished(boolean inLoad) {
604 if (inLoad) {
605 // the titlebar was removed when the CAB was shown
606 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800607 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 }
609 }
610
Michael Kolb66706532010-12-12 19:50:22 -0800611 // active tabs page
612
613 public void showActiveTabsPage() {
614 }
615
616 /**
617 * Remove the active tabs page.
618 */
619 public void removeActiveTabsPage() {
620 }
621
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 // menu handling callbacks
623
624 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800625 public boolean onPrepareOptionsMenu(Menu menu) {
626 return true;
627 }
628
629 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700630 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700631 }
632
633 @Override
634 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 }
636
637 @Override
638 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 }
640
641 @Override
642 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700643 }
644
645 @Override
646 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700647 }
648
649 @Override
650 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 }
652
653 // error console
654
655 @Override
656 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800657 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
659 if (flag) {
660 // Setting the show state of the console will cause it's the layout
661 // to be inflated.
662 if (errorConsole.numberOfErrors() > 0) {
663 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
664 } else {
665 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
666 }
667 if (errorConsole.getParent() != null) {
668 mErrorConsoleContainer.removeView(errorConsole);
669 }
670 // Now we can add it to the main view.
671 mErrorConsoleContainer.addView(errorConsole,
672 new LinearLayout.LayoutParams(
673 ViewGroup.LayoutParams.MATCH_PARENT,
674 ViewGroup.LayoutParams.WRAP_CONTENT));
675 } else {
676 mErrorConsoleContainer.removeView(errorConsole);
677 }
678 }
679
680 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800681 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
682 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
683 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700684 }
685
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 // -------------------------------------------------------------------------
687 // Helper function for WebChromeClient
688 // -------------------------------------------------------------------------
689
690 @Override
691 public Bitmap getDefaultVideoPoster() {
692 if (mDefaultVideoPoster == null) {
693 mDefaultVideoPoster = BitmapFactory.decodeResource(
694 mActivity.getResources(), R.drawable.default_video_poster);
695 }
696 return mDefaultVideoPoster;
697 }
698
699 @Override
700 public View getVideoLoadingProgressView() {
701 if (mVideoProgressView == null) {
702 LayoutInflater inflater = LayoutInflater.from(mActivity);
703 mVideoProgressView = inflater.inflate(
704 R.layout.video_loading_progress, null);
705 }
706 return mVideoProgressView;
707 }
708
Michael Kolb843510f2010-12-09 10:51:49 -0800709 @Override
710 public void showMaxTabsWarning() {
711 Toast warning = Toast.makeText(mActivity,
712 mActivity.getString(R.string.max_tabs_warning),
713 Toast.LENGTH_SHORT);
714 warning.show();
715 }
716
Narayan Kamath5119edd2011-02-23 15:49:17 +0000717 @Override
718 public void registerDropdownChangeListener(DropdownChangeListener d) {
719 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700720}