blob: 4f80e9d100a03ef8fba31bff5ba5ee53879056b1 [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 Reck74830e12011-03-14 11:43:05 -070021import 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 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);
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
Michael Kolb377ea312011-02-17 14:36:56 -0800223 public void setActiveTab(final Tab tab) {
224 setActiveTab(tab, true);
225 }
226
227 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800228 if ((tab != mActiveTab) && (mActiveTab != null)) {
229 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700230 }
Michael Kolb77df4562010-11-19 14:49:34 -0800231 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800232 if (needsAttaching) {
233 attachTabToContentView(tab);
234 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800236 onTabDataChanged(tab);
237 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800238 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800239 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500240 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 }
242
Michael Kolbcfa3af52010-12-14 10:36:11 -0800243 Tab getActiveTab() {
244 return mActiveTab;
245 }
246
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800248 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800249 }
250
251 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800253 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800255 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 }
258
259 @Override
260 public void detachTab(Tab tab) {
261 removeTabFromContentView(tab);
262 }
263
264 @Override
265 public void attachTab(Tab tab) {
266 attachTabToContentView(tab);
267 }
268
Michael Kolb377ea312011-02-17 14:36:56 -0800269 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800270 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 return;
272 }
273 View container = tab.getViewContainer();
274 WebView mainView = tab.getWebView();
275 // Attach the WebView to the container and then attach the
276 // container to the content view.
277 FrameLayout wrapper =
278 (FrameLayout) container.findViewById(R.id.webview_wrapper);
279 ViewGroup parent = (ViewGroup) mainView.getParent();
280 if (parent != wrapper) {
281 if (parent != null) {
282 Log.w(LOGTAG, "mMainView already has a parent in"
283 + " attachTabToContentView!");
284 parent.removeView(mainView);
285 }
286 wrapper.addView(mainView);
287 } else {
288 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
289 + " attachTabToContentView!");
290 }
291 parent = (ViewGroup) container.getParent();
292 if (parent != mContentView) {
293 if (parent != null) {
294 Log.w(LOGTAG, "mContainer already has a parent in"
295 + " attachTabToContentView!");
296 parent.removeView(container);
297 }
298 mContentView.addView(container, COVER_SCREEN_PARAMS);
299 } else {
300 Log.w(LOGTAG, "mContainer is already attached to content in"
301 + " attachTabToContentView!");
302 }
Michael Kolba4183062011-01-16 10:43:21 -0800303 mainView.setNextFocusUpId(R.id.url_focused);
304 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700305 mUiController.attachSubWindow(tab);
306 }
307
308 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800309 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700310 // Remove the container that contains the main WebView.
311 WebView mainView = tab.getWebView();
312 View container = tab.getViewContainer();
313 if (mainView == null) {
314 return;
315 }
316 // Remove the container from the content and then remove the
317 // WebView from the container. This will trigger a focus change
318 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800319 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700320 FrameLayout wrapper =
321 (FrameLayout) container.findViewById(R.id.webview_wrapper);
322 wrapper.removeView(mainView);
323 mContentView.removeView(container);
324 mUiController.endActionMode();
325 mUiController.removeSubWindow(tab);
326 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
327 if (errorConsole != null) {
328 mErrorConsoleContainer.removeView(errorConsole);
329 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700330 }
331
Michael Kolba713ec82010-11-29 17:27:06 -0800332 @Override
333 public void onSetWebView(Tab tab, WebView webView) {
334 View container = tab.getViewContainer();
335 if (container == null) {
336 // The tab consists of a container view, which contains the main
337 // WebView, as well as any other UI elements associated with the tab.
338 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
339 null);
340 tab.setViewContainer(container);
341 }
342 if (tab.getWebView() != webView) {
343 // Just remove the old one.
344 FrameLayout wrapper =
345 (FrameLayout) container.findViewById(R.id.webview_wrapper);
346 wrapper.removeView(tab.getWebView());
347 }
348 }
349
Michael Kolb8233fac2010-10-26 16:08:53 -0700350 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800351 * create a sub window container and webview for the tab
352 * Note: this methods operates through side-effects for now
353 * it sets both the subView and subViewContainer for the given tab
354 * @param tab tab to create the sub window for
355 * @param subView webview to be set as a subwindow for the tab
356 */
357 @Override
358 public void createSubWindow(Tab tab, WebView subView) {
359 View subViewContainer = mActivity.getLayoutInflater().inflate(
360 R.layout.browser_subwindow, null);
361 ViewGroup inner = (ViewGroup) subViewContainer
362 .findViewById(R.id.inner_container);
363 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
364 LayoutParams.MATCH_PARENT));
365 final ImageButton cancel = (ImageButton) subViewContainer
366 .findViewById(R.id.subwindow_close);
367 final WebView cancelSubView = subView;
368 cancel.setOnClickListener(new OnClickListener() {
369 public void onClick(View v) {
370 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
371 }
372 });
373 tab.setSubWebView(subView);
374 tab.setSubViewContainer(subViewContainer);
375 }
376
377 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 * Remove the sub window from the content view.
379 */
380 @Override
381 public void removeSubWindow(View subviewContainer) {
382 mContentView.removeView(subviewContainer);
383 mUiController.endActionMode();
384 }
385
386 /**
387 * Attach the sub window to the content view.
388 */
389 @Override
390 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800391 if (container.getParent() != null) {
392 // already attached, remove first
393 ((ViewGroup) container.getParent()).removeView(container);
394 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700395 mContentView.addView(container, COVER_SCREEN_PARAMS);
396 }
397
Michael Kolb7cdc4902011-02-03 17:54:40 -0800398 boolean canShowTitleBar() {
399 return !isTitleBarShowing()
400 && !isActivityPaused()
401 && (getActiveTab() != null)
402 && (getActiveTab().getWebView() != null)
403 && !mUiController.isInCustomActionMode();
404 }
405
406 void showTitleBar() {
407 mTitleShowing = true;
408 }
409
410 protected void hideTitleBar() {
411 mTitleShowing = false;
412 }
413
414 protected boolean isTitleBarShowing() {
415 return mTitleShowing;
416 }
417
418 protected abstract TitleBarBase getTitleBar();
419
420 protected void setTitleGravity(int gravity) {
Michael Kolb1214af32011-05-05 15:26:37 -0700421 WebView web = getWebView();
422 if (web != null) {
423 web.setTitleBarGravity(gravity);
424 web.invalidate();
Michael Kolb8233fac2010-10-26 16:08:53 -0700425 }
426 }
427
Michael Kolb66706532010-12-12 19:50:22 -0800428 @Override
429 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800430 getTitleBar().setInVoiceMode(true);
431 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700432 }
433
Michael Kolb66706532010-12-12 19:50:22 -0800434 @Override
435 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800436 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800437 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800438 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700439 }
440
441 @Override
442 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800443 if (mComboView != null) {
444 return;
445 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700446 mComboView = new CombinedBookmarkHistoryView(mActivity,
447 mUiController,
448 startWithHistory ?
449 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
450 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
451 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800452 FrameLayout wrapper =
453 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
454 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800455 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800456 dismissIME();
457 if (mActiveTab != null) {
458 WebView web = mActiveTab.getWebView();
459 mActiveTab.putInBackground();
460 }
John Reck74830e12011-03-14 11:43:05 -0700461 mComboView.setAlpha(0f);
462 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
463 Resources res = mActivity.getResources();
464 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
465 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700466 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
467 }
468
Michael Kolbba238702011-03-08 10:40:50 -0800469 public boolean isComboViewShowing() {
470 return (mComboView != null);
471 }
472
Michael Kolb8233fac2010-10-26 16:08:53 -0700473 /**
474 * dismiss the ComboPage
475 */
476 @Override
477 public void hideComboView() {
478 if (mComboView != null) {
479 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800480 FrameLayout wrapper =
481 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
482 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700483 mComboView = null;
484 }
Michael Kolb3a696282010-12-05 13:23:24 -0800485 if (mActiveTab != null) {
486 mActiveTab.putInForeground();
487 }
John Reckb3417f02011-01-14 11:01:05 -0800488 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700489 }
490
491 @Override
492 public void showCustomView(View view,
493 WebChromeClient.CustomViewCallback callback) {
494 // if a view already exists then immediately terminate the new one
495 if (mCustomView != null) {
496 callback.onCustomViewHidden();
497 return;
498 }
499
500 // Add the custom view to its container.
501 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
502 mCustomView = view;
503 mCustomViewCallback = callback;
504 // Hide the content view.
505 mContentView.setVisibility(View.GONE);
506 // Finally show the custom view container.
507 setStatusBarVisibility(false);
508 mCustomViewContainer.setVisibility(View.VISIBLE);
509 mCustomViewContainer.bringToFront();
510 }
511
512 @Override
513 public void onHideCustomView() {
514 if (mCustomView == null)
515 return;
516
517 // Hide the custom view.
518 mCustomView.setVisibility(View.GONE);
519 // Remove the custom view from its container.
520 mCustomViewContainer.removeView(mCustomView);
521 mCustomView = null;
522 mCustomViewContainer.setVisibility(View.GONE);
523 mCustomViewCallback.onCustomViewHidden();
524 // Show the content view.
525 setStatusBarVisibility(true);
526 mContentView.setVisibility(View.VISIBLE);
527 }
528
529 @Override
530 public boolean isCustomViewShowing() {
531 return mCustomView != null;
532 }
533
Michael Kolb66706532010-12-12 19:50:22 -0800534 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800535 if (mInputManager.isActive()) {
536 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
537 0);
538 }
539 }
540
Michael Kolb66706532010-12-12 19:50:22 -0800541 @Override
542 public boolean showsWeb() {
543 return mCustomView == null
544 && mComboView == null;
545 }
546
Patrick Scott92066772011-03-10 08:46:27 -0500547 @Override
548 public void showAutoLogin(Tab tab) {
549 updateAutoLogin(tab, true);
550 }
551
552 @Override
553 public void hideAutoLogin(Tab tab) {
554 updateAutoLogin(tab, true);
555 }
556
Michael Kolb8233fac2010-10-26 16:08:53 -0700557 // -------------------------------------------------------------------------
558
Michael Kolb5a72f182011-01-13 20:35:06 -0800559 protected void updateNavigationState(Tab tab) {
560 }
561
Patrick Scott92066772011-03-10 08:46:27 -0500562 protected void updateAutoLogin(Tab tab, boolean animate) {}
563
Michael Kolb8233fac2010-10-26 16:08:53 -0700564 /**
565 * Update the lock icon to correspond to our latest state.
566 */
Michael Kolb66706532010-12-12 19:50:22 -0800567 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800568 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700569 updateLockIconImage(t.getLockIconType());
570 }
571 }
572
573 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700574 * Updates the lock-icon image in the title-bar.
575 */
John Reck30c714c2010-12-16 17:30:34 -0800576 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700577 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800578 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700579 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800580 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700581 d = mMixLockIcon;
582 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800583 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700584 }
585
John Reck30c714c2010-12-16 17:30:34 -0800586 protected void setUrlTitle(Tab tab) {
587 String url = tab.getUrl();
588 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800589 if (TextUtils.isEmpty(title)) {
590 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800591 }
Michael Kolb66706532010-12-12 19:50:22 -0800592 if (tab.isInVoiceSearchMode()) return;
593 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800594 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800595 }
596 }
597
598 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800599 protected void setFavicon(Tab tab) {
600 if (tab.inForeground()) {
601 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800602 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800603 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700604 }
605
606 @Override
607 public void onActionModeFinished(boolean inLoad) {
608 if (inLoad) {
609 // the titlebar was removed when the CAB was shown
610 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800611 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 }
613 }
614
Michael Kolb66706532010-12-12 19:50:22 -0800615 // active tabs page
616
617 public void showActiveTabsPage() {
618 }
619
620 /**
621 * Remove the active tabs page.
622 */
623 public void removeActiveTabsPage() {
624 }
625
Michael Kolb8233fac2010-10-26 16:08:53 -0700626 // menu handling callbacks
627
628 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800629 public boolean onPrepareOptionsMenu(Menu menu) {
630 return true;
631 }
632
633 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700634 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 }
636
637 @Override
638 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 }
640
641 @Override
642 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700643 }
644
645 @Override
646 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700647 }
648
649 @Override
650 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 }
652
653 @Override
654 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 }
656
657 // error console
658
659 @Override
660 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800661 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
663 if (flag) {
664 // Setting the show state of the console will cause it's the layout
665 // to be inflated.
666 if (errorConsole.numberOfErrors() > 0) {
667 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
668 } else {
669 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
670 }
671 if (errorConsole.getParent() != null) {
672 mErrorConsoleContainer.removeView(errorConsole);
673 }
674 // Now we can add it to the main view.
675 mErrorConsoleContainer.addView(errorConsole,
676 new LinearLayout.LayoutParams(
677 ViewGroup.LayoutParams.MATCH_PARENT,
678 ViewGroup.LayoutParams.WRAP_CONTENT));
679 } else {
680 mErrorConsoleContainer.removeView(errorConsole);
681 }
682 }
683
684 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800685 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
686 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
687 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700688 }
689
Michael Kolb8233fac2010-10-26 16:08:53 -0700690 // -------------------------------------------------------------------------
691 // Helper function for WebChromeClient
692 // -------------------------------------------------------------------------
693
694 @Override
695 public Bitmap getDefaultVideoPoster() {
696 if (mDefaultVideoPoster == null) {
697 mDefaultVideoPoster = BitmapFactory.decodeResource(
698 mActivity.getResources(), R.drawable.default_video_poster);
699 }
700 return mDefaultVideoPoster;
701 }
702
703 @Override
704 public View getVideoLoadingProgressView() {
705 if (mVideoProgressView == null) {
706 LayoutInflater inflater = LayoutInflater.from(mActivity);
707 mVideoProgressView = inflater.inflate(
708 R.layout.video_loading_progress, null);
709 }
710 return mVideoProgressView;
711 }
712
Michael Kolb843510f2010-12-09 10:51:49 -0800713 @Override
714 public void showMaxTabsWarning() {
715 Toast warning = Toast.makeText(mActivity,
716 mActivity.getString(R.string.max_tabs_warning),
717 Toast.LENGTH_SHORT);
718 warning.show();
719 }
720
Narayan Kamath5119edd2011-02-23 15:49:17 +0000721 @Override
722 public void registerDropdownChangeListener(DropdownChangeListener d) {
723 }
Michael Kolb1214af32011-05-05 15:26:37 -0700724
725 protected WebView getWebView() {
726 Tab tab = getActiveTab();
727 if (tab != null) {
728 return tab.getWebView();
729 }
730 return null;
731 }
732
Michael Kolb8233fac2010-10-26 16:08:53 -0700733}