blob: dd243b4e2326803141cfe2c4755c3a2222dfca19 [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
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
27import android.os.Bundle;
28import android.text.TextUtils;
29import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.view.Gravity;
31import android.view.LayoutInflater;
32import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080034import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080036import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080038import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.webkit.WebView;
41import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.widget.LinearLayout;
44import android.widget.Toast;
45
Michael Kolb1bf23132010-11-19 12:55:12 -080046import java.util.List;
47
Michael Kolb8233fac2010-10-26 16:08:53 -070048/**
49 * UI interface definitions
50 */
Michael Kolb66706532010-12-12 19:50:22 -080051public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070052
53 private static final String LOGTAG = "BaseUi";
54
Michael Kolb66706532010-12-12 19:50:22 -080055 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070056 new FrameLayout.LayoutParams(
57 ViewGroup.LayoutParams.MATCH_PARENT,
58 ViewGroup.LayoutParams.MATCH_PARENT);
59
Michael Kolb66706532010-12-12 19:50:22 -080060 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070061 new FrameLayout.LayoutParams(
62 ViewGroup.LayoutParams.MATCH_PARENT,
63 ViewGroup.LayoutParams.MATCH_PARENT,
64 Gravity.CENTER);
65
66 Activity mActivity;
67 UiController mUiController;
68 TabControl mTabControl;
Michael Kolb77df4562010-11-19 14:49:34 -080069 private Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080070 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070071
72 private Drawable mSecLockIcon;
73 private Drawable mMixLockIcon;
74
Michael Kolb8233fac2010-10-26 16:08:53 -070075 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080076 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070077 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070078
79 private View mCustomView;
80 private WebChromeClient.CustomViewCallback mCustomViewCallback;
81
82 private CombinedBookmarkHistoryView mComboView;
83
84 private LinearLayout mErrorConsoleContainer = null;
85
86 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070087
Michael Kolb7cdc4902011-02-03 17:54:40 -080088 private boolean mTitleShowing;
89
Michael Kolb8233fac2010-10-26 16:08:53 -070090 // the default <video> poster
91 private Bitmap mDefaultVideoPoster;
92 // the video progress view
93 private View mVideoProgressView;
94
Michael Kolb8233fac2010-10-26 16:08:53 -070095 private boolean mActivityPaused;
96
97 public BaseUi(Activity browser, UiController controller) {
98 mActivity = browser;
99 mUiController = controller;
100 mTabControl = controller.getTabControl();
101 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800102 mInputManager = (InputMethodManager)
103 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800104 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700105 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
108 .getDecorView().findViewById(android.R.id.content);
109 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
110 .inflate(R.layout.custom_screen, null);
111 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
112 R.id.main_content);
113 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
114 .findViewById(R.id.error_console);
115 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
116 .findViewById(R.id.fullscreen_custom_content);
117 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800118 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700119 }
120
Michael Kolb66706532010-12-12 19:50:22 -0800121 /**
122 * common webview initialization
123 * @param w the webview to initialize
124 */
125 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700126 w.setScrollbarFadingEnabled(true);
127 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
128 w.setMapTrackballToArrowKeys(false); // use trackball directly
129 // Enable the built-in zoom
130 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700131
132 // Add this WebView to the settings observer list and update the
133 // settings
134 final BrowserSettings s = BrowserSettings.getInstance();
135 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 }
137
138 private void cancelStopToast() {
139 if (mStopToast != null) {
140 mStopToast.cancel();
141 mStopToast = null;
142 }
143 }
144
145 // lifecycle
146
147 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800148 if (isCustomViewShowing()) {
149 onHideCustomView();
150 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700151 cancelStopToast();
152 mActivityPaused = true;
153 }
154
155 public void onResume() {
156 mActivityPaused = false;
157 }
158
Michael Kolb66706532010-12-12 19:50:22 -0800159 protected boolean isActivityPaused() {
160 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700161 }
162
163 public void onConfigurationChanged(Configuration config) {
164 }
165
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800166 public abstract void editUrl(boolean clearInput);
167
Michael Kolb8233fac2010-10-26 16:08:53 -0700168 // key handling
169
170 @Override
171 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700172 if (mComboView != null) {
173 if (!mComboView.onBackPressed()) {
174 mUiController.removeComboView();
175 }
176 return true;
177 }
178 if (mCustomView != null) {
179 mUiController.hideCustomView();
180 return true;
181 }
182 return false;
183 }
184
John Reck30c714c2010-12-16 17:30:34 -0800185 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700186 @Override
John Reck30c714c2010-12-16 17:30:34 -0800187 public void onTabDataChanged(Tab tab) {
188 setUrlTitle(tab);
189 setFavicon(tab);
190 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800191 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700192 }
193
194 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500195 public void bookmarkedStatusHasChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800196 // no op in base case
Leon Scroggins4cd97792010-12-03 15:31:56 -0500197 }
198
199 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700200 public void onPageStopped(Tab tab) {
201 cancelStopToast();
202 if (tab.inForeground()) {
203 mStopToast = Toast
204 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
205 mStopToast.show();
206 }
207 }
208
209 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800210 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800211 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800212 }
213
214 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700215 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 }
217
218 @Override
219 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800220 if ((tab != mActiveTab) && (mActiveTab != null)) {
221 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 }
Michael Kolb77df4562010-11-19 14:49:34 -0800223 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700224 attachTabToContentView(tab);
225 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800226 onTabDataChanged(tab);
227 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800228 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800229 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700230 }
231
Michael Kolbcfa3af52010-12-14 10:36:11 -0800232 Tab getActiveTab() {
233 return mActiveTab;
234 }
235
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800237 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800238 }
239
240 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800242 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800244 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700245 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700246 }
247
248 @Override
249 public void detachTab(Tab tab) {
250 removeTabFromContentView(tab);
251 }
252
253 @Override
254 public void attachTab(Tab tab) {
255 attachTabToContentView(tab);
256 }
257
258 private void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800259 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700260 return;
261 }
262 View container = tab.getViewContainer();
263 WebView mainView = tab.getWebView();
264 // Attach the WebView to the container and then attach the
265 // container to the content view.
266 FrameLayout wrapper =
267 (FrameLayout) container.findViewById(R.id.webview_wrapper);
268 ViewGroup parent = (ViewGroup) mainView.getParent();
269 if (parent != wrapper) {
270 if (parent != null) {
271 Log.w(LOGTAG, "mMainView already has a parent in"
272 + " attachTabToContentView!");
273 parent.removeView(mainView);
274 }
275 wrapper.addView(mainView);
276 } else {
277 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
278 + " attachTabToContentView!");
279 }
280 parent = (ViewGroup) container.getParent();
281 if (parent != mContentView) {
282 if (parent != null) {
283 Log.w(LOGTAG, "mContainer already has a parent in"
284 + " attachTabToContentView!");
285 parent.removeView(container);
286 }
287 mContentView.addView(container, COVER_SCREEN_PARAMS);
288 } else {
289 Log.w(LOGTAG, "mContainer is already attached to content in"
290 + " attachTabToContentView!");
291 }
Michael Kolba4183062011-01-16 10:43:21 -0800292 mainView.setNextFocusUpId(R.id.url_focused);
293 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700294 mUiController.attachSubWindow(tab);
295 }
296
297 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800298 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700299 // Remove the container that contains the main WebView.
300 WebView mainView = tab.getWebView();
301 View container = tab.getViewContainer();
302 if (mainView == null) {
303 return;
304 }
305 // Remove the container from the content and then remove the
306 // WebView from the container. This will trigger a focus change
307 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800308 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700309 FrameLayout wrapper =
310 (FrameLayout) container.findViewById(R.id.webview_wrapper);
311 wrapper.removeView(mainView);
312 mContentView.removeView(container);
313 mUiController.endActionMode();
314 mUiController.removeSubWindow(tab);
315 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
316 if (errorConsole != null) {
317 mErrorConsoleContainer.removeView(errorConsole);
318 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700319 }
320
Michael Kolba713ec82010-11-29 17:27:06 -0800321 @Override
322 public void onSetWebView(Tab tab, WebView webView) {
323 View container = tab.getViewContainer();
324 if (container == null) {
325 // The tab consists of a container view, which contains the main
326 // WebView, as well as any other UI elements associated with the tab.
327 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
328 null);
329 tab.setViewContainer(container);
330 }
331 if (tab.getWebView() != webView) {
332 // Just remove the old one.
333 FrameLayout wrapper =
334 (FrameLayout) container.findViewById(R.id.webview_wrapper);
335 wrapper.removeView(tab.getWebView());
336 }
337 }
338
Michael Kolb8233fac2010-10-26 16:08:53 -0700339 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800340 * create a sub window container and webview for the tab
341 * Note: this methods operates through side-effects for now
342 * it sets both the subView and subViewContainer for the given tab
343 * @param tab tab to create the sub window for
344 * @param subView webview to be set as a subwindow for the tab
345 */
346 @Override
347 public void createSubWindow(Tab tab, WebView subView) {
348 View subViewContainer = mActivity.getLayoutInflater().inflate(
349 R.layout.browser_subwindow, null);
350 ViewGroup inner = (ViewGroup) subViewContainer
351 .findViewById(R.id.inner_container);
352 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
353 LayoutParams.MATCH_PARENT));
354 final ImageButton cancel = (ImageButton) subViewContainer
355 .findViewById(R.id.subwindow_close);
356 final WebView cancelSubView = subView;
357 cancel.setOnClickListener(new OnClickListener() {
358 public void onClick(View v) {
359 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
360 }
361 });
362 tab.setSubWebView(subView);
363 tab.setSubViewContainer(subViewContainer);
364 }
365
366 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700367 * Remove the sub window from the content view.
368 */
369 @Override
370 public void removeSubWindow(View subviewContainer) {
371 mContentView.removeView(subviewContainer);
372 mUiController.endActionMode();
373 }
374
375 /**
376 * Attach the sub window to the content view.
377 */
378 @Override
379 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800380 if (container.getParent() != null) {
381 // already attached, remove first
382 ((ViewGroup) container.getParent()).removeView(container);
383 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700384 mContentView.addView(container, COVER_SCREEN_PARAMS);
385 }
386
Michael Kolb7cdc4902011-02-03 17:54:40 -0800387 boolean canShowTitleBar() {
388 return !isTitleBarShowing()
389 && !isActivityPaused()
390 && (getActiveTab() != null)
391 && (getActiveTab().getWebView() != null)
392 && !mUiController.isInCustomActionMode();
393 }
394
395 void showTitleBar() {
396 mTitleShowing = true;
397 }
398
399 protected void hideTitleBar() {
400 mTitleShowing = false;
401 }
402
403 protected boolean isTitleBarShowing() {
404 return mTitleShowing;
405 }
406
407 protected abstract TitleBarBase getTitleBar();
408
409 protected void setTitleGravity(int gravity) {
410 getTitleBar().setTitleGravity(gravity);
411 Tab tab = getActiveTab();
412 if ((tab != null) && (tab.getWebView() != null)) {
413 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700414 }
415 }
416
Michael Kolb66706532010-12-12 19:50:22 -0800417 @Override
418 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800419 getTitleBar().setInVoiceMode(true);
420 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700421 }
422
Michael Kolb66706532010-12-12 19:50:22 -0800423 @Override
424 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800425 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800426 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800427 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 }
429
430 @Override
431 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800432 if (mComboView != null) {
433 return;
434 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700435 mComboView = new CombinedBookmarkHistoryView(mActivity,
436 mUiController,
437 startWithHistory ?
438 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
439 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
440 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800441 FrameLayout wrapper =
442 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
443 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800444 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800445 dismissIME();
446 if (mActiveTab != null) {
447 WebView web = mActiveTab.getWebView();
448 mActiveTab.putInBackground();
449 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700450 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
451 }
452
453 /**
454 * dismiss the ComboPage
455 */
456 @Override
457 public void hideComboView() {
458 if (mComboView != null) {
459 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800460 FrameLayout wrapper =
461 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
462 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700463 mComboView = null;
464 }
Michael Kolb3a696282010-12-05 13:23:24 -0800465 if (mActiveTab != null) {
466 mActiveTab.putInForeground();
467 }
John Reckb3417f02011-01-14 11:01:05 -0800468 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700469 }
470
471 @Override
472 public void showCustomView(View view,
473 WebChromeClient.CustomViewCallback callback) {
474 // if a view already exists then immediately terminate the new one
475 if (mCustomView != null) {
476 callback.onCustomViewHidden();
477 return;
478 }
479
480 // Add the custom view to its container.
481 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
482 mCustomView = view;
483 mCustomViewCallback = callback;
484 // Hide the content view.
485 mContentView.setVisibility(View.GONE);
486 // Finally show the custom view container.
487 setStatusBarVisibility(false);
488 mCustomViewContainer.setVisibility(View.VISIBLE);
489 mCustomViewContainer.bringToFront();
490 }
491
492 @Override
493 public void onHideCustomView() {
494 if (mCustomView == null)
495 return;
496
497 // Hide the custom view.
498 mCustomView.setVisibility(View.GONE);
499 // Remove the custom view from its container.
500 mCustomViewContainer.removeView(mCustomView);
501 mCustomView = null;
502 mCustomViewContainer.setVisibility(View.GONE);
503 mCustomViewCallback.onCustomViewHidden();
504 // Show the content view.
505 setStatusBarVisibility(true);
506 mContentView.setVisibility(View.VISIBLE);
507 }
508
509 @Override
510 public boolean isCustomViewShowing() {
511 return mCustomView != null;
512 }
513
Michael Kolb66706532010-12-12 19:50:22 -0800514 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800515 if (mInputManager.isActive()) {
516 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
517 0);
518 }
519 }
520
Michael Kolb66706532010-12-12 19:50:22 -0800521 @Override
522 public boolean showsWeb() {
523 return mCustomView == null
524 && mComboView == null;
525 }
526
Michael Kolb8233fac2010-10-26 16:08:53 -0700527 // -------------------------------------------------------------------------
528
Michael Kolb5a72f182011-01-13 20:35:06 -0800529 protected void updateNavigationState(Tab tab) {
530 }
531
Michael Kolb8233fac2010-10-26 16:08:53 -0700532 /**
533 * Update the lock icon to correspond to our latest state.
534 */
Michael Kolb66706532010-12-12 19:50:22 -0800535 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800536 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700537 updateLockIconImage(t.getLockIconType());
538 }
539 }
540
541 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700542 * Updates the lock-icon image in the title-bar.
543 */
John Reck30c714c2010-12-16 17:30:34 -0800544 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800546 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700547 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800548 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700549 d = mMixLockIcon;
550 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800551 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700552 }
553
John Reck30c714c2010-12-16 17:30:34 -0800554 protected void setUrlTitle(Tab tab) {
555 String url = tab.getUrl();
556 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800557 if (TextUtils.isEmpty(title)) {
558 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800559 }
Michael Kolb66706532010-12-12 19:50:22 -0800560 if (tab.isInVoiceSearchMode()) return;
561 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800562 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800563 }
564 }
565
566 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800567 protected void setFavicon(Tab tab) {
568 if (tab.inForeground()) {
569 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800570 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800571 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700572 }
573
574 @Override
575 public void onActionModeFinished(boolean inLoad) {
576 if (inLoad) {
577 // the titlebar was removed when the CAB was shown
578 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800579 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 }
581 }
582
Michael Kolb66706532010-12-12 19:50:22 -0800583 // active tabs page
584
585 public void showActiveTabsPage() {
586 }
587
588 /**
589 * Remove the active tabs page.
590 */
591 public void removeActiveTabsPage() {
592 }
593
Michael Kolb8233fac2010-10-26 16:08:53 -0700594 // menu handling callbacks
595
596 @Override
597 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 }
599
600 @Override
601 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 }
603
604 @Override
605 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 }
607
608 @Override
609 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700610 }
611
612 @Override
613 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 }
615
616 @Override
617 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700618 }
619
620 // error console
621
622 @Override
623 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800624 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
626 if (flag) {
627 // Setting the show state of the console will cause it's the layout
628 // to be inflated.
629 if (errorConsole.numberOfErrors() > 0) {
630 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
631 } else {
632 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
633 }
634 if (errorConsole.getParent() != null) {
635 mErrorConsoleContainer.removeView(errorConsole);
636 }
637 // Now we can add it to the main view.
638 mErrorConsoleContainer.addView(errorConsole,
639 new LinearLayout.LayoutParams(
640 ViewGroup.LayoutParams.MATCH_PARENT,
641 ViewGroup.LayoutParams.WRAP_CONTENT));
642 } else {
643 mErrorConsoleContainer.removeView(errorConsole);
644 }
645 }
646
647 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800648 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
649 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
650 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 }
652
Michael Kolb8233fac2010-10-26 16:08:53 -0700653 // -------------------------------------------------------------------------
654 // Helper function for WebChromeClient
655 // -------------------------------------------------------------------------
656
657 @Override
658 public Bitmap getDefaultVideoPoster() {
659 if (mDefaultVideoPoster == null) {
660 mDefaultVideoPoster = BitmapFactory.decodeResource(
661 mActivity.getResources(), R.drawable.default_video_poster);
662 }
663 return mDefaultVideoPoster;
664 }
665
666 @Override
667 public View getVideoLoadingProgressView() {
668 if (mVideoProgressView == null) {
669 LayoutInflater inflater = LayoutInflater.from(mActivity);
670 mVideoProgressView = inflater.inflate(
671 R.layout.video_loading_progress, null);
672 }
673 return mVideoProgressView;
674 }
675
Michael Kolb843510f2010-12-09 10:51:49 -0800676 @Override
677 public void showMaxTabsWarning() {
678 Toast warning = Toast.makeText(mActivity,
679 mActivity.getString(R.string.max_tabs_warning),
680 Toast.LENGTH_SHORT);
681 warning.show();
682 }
683
Michael Kolb8233fac2010-10-26 16:08:53 -0700684}