blob: 02d91991fba400aa4e9c7f0e89d3bbc7a7bdc29b [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 Kolba4183062011-01-16 10:43:21 -080035import android.view.View.OnKeyListener;
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 Kolb77df4562010-11-19 14:49:34 -080070 private 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
89 // the default <video> poster
90 private Bitmap mDefaultVideoPoster;
91 // the video progress view
92 private View mVideoProgressView;
93
Michael Kolb8233fac2010-10-26 16:08:53 -070094 private boolean mActivityPaused;
95
96 public BaseUi(Activity browser, UiController controller) {
97 mActivity = browser;
98 mUiController = controller;
99 mTabControl = controller.getTabControl();
100 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800101 mInputManager = (InputMethodManager)
102 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800103 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700104 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
105
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
107 .getDecorView().findViewById(android.R.id.content);
108 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
109 .inflate(R.layout.custom_screen, null);
110 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
111 R.id.main_content);
112 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
113 .findViewById(R.id.error_console);
114 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
115 .findViewById(R.id.fullscreen_custom_content);
116 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700117 }
118
Michael Kolb66706532010-12-12 19:50:22 -0800119 /**
120 * common webview initialization
121 * @param w the webview to initialize
122 */
123 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700124 w.setScrollbarFadingEnabled(true);
125 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
126 w.setMapTrackballToArrowKeys(false); // use trackball directly
127 // Enable the built-in zoom
128 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700129
130 // Add this WebView to the settings observer list and update the
131 // settings
132 final BrowserSettings s = BrowserSettings.getInstance();
133 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700134 }
135
136 private void cancelStopToast() {
137 if (mStopToast != null) {
138 mStopToast.cancel();
139 mStopToast = null;
140 }
141 }
142
143 // lifecycle
144
145 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800146 if (isCustomViewShowing()) {
147 onHideCustomView();
148 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700149 cancelStopToast();
150 mActivityPaused = true;
151 }
152
153 public void onResume() {
154 mActivityPaused = false;
155 }
156
Michael Kolb66706532010-12-12 19:50:22 -0800157 protected boolean isActivityPaused() {
158 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700159 }
160
161 public void onConfigurationChanged(Configuration config) {
162 }
163
164 // key handling
165
166 @Override
167 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700168 if (mComboView != null) {
169 if (!mComboView.onBackPressed()) {
170 mUiController.removeComboView();
171 }
172 return true;
173 }
174 if (mCustomView != null) {
175 mUiController.hideCustomView();
176 return true;
177 }
178 return false;
179 }
180
John Reck30c714c2010-12-16 17:30:34 -0800181 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700182 @Override
John Reck30c714c2010-12-16 17:30:34 -0800183 public void onTabDataChanged(Tab tab) {
184 setUrlTitle(tab);
185 setFavicon(tab);
186 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800187 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 }
189
190 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500191 public void bookmarkedStatusHasChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800192 // no op in base case
Leon Scroggins4cd97792010-12-03 15:31:56 -0500193 }
194
195 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 public void onPageStopped(Tab tab) {
197 cancelStopToast();
198 if (tab.inForeground()) {
199 mStopToast = Toast
200 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
201 mStopToast.show();
202 }
203 }
204
205 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800206 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800207 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800208 }
209
210 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 }
213
214 @Override
215 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800216 if ((tab != mActiveTab) && (mActiveTab != null)) {
217 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 }
Michael Kolb77df4562010-11-19 14:49:34 -0800219 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 attachTabToContentView(tab);
221 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800222 onTabDataChanged(tab);
223 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800224 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
225 getEmbeddedTitleBar().setIncognitoMode(incognito);
226 getFakeTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 }
228
Michael Kolbcfa3af52010-12-14 10:36:11 -0800229 Tab getActiveTab() {
230 return mActiveTab;
231 }
232
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800234 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800235 }
236
237 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800239 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800241 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 }
244
245 @Override
246 public void detachTab(Tab tab) {
247 removeTabFromContentView(tab);
248 }
249
250 @Override
251 public void attachTab(Tab tab) {
252 attachTabToContentView(tab);
253 }
254
255 private void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800256 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 return;
258 }
259 View container = tab.getViewContainer();
260 WebView mainView = tab.getWebView();
261 // Attach the WebView to the container and then attach the
262 // container to the content view.
263 FrameLayout wrapper =
264 (FrameLayout) container.findViewById(R.id.webview_wrapper);
265 ViewGroup parent = (ViewGroup) mainView.getParent();
266 if (parent != wrapper) {
267 if (parent != null) {
268 Log.w(LOGTAG, "mMainView already has a parent in"
269 + " attachTabToContentView!");
270 parent.removeView(mainView);
271 }
272 wrapper.addView(mainView);
273 } else {
274 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
275 + " attachTabToContentView!");
276 }
277 parent = (ViewGroup) container.getParent();
278 if (parent != mContentView) {
279 if (parent != null) {
280 Log.w(LOGTAG, "mContainer already has a parent in"
281 + " attachTabToContentView!");
282 parent.removeView(container);
283 }
284 mContentView.addView(container, COVER_SCREEN_PARAMS);
285 } else {
286 Log.w(LOGTAG, "mContainer is already attached to content in"
287 + " attachTabToContentView!");
288 }
Michael Kolba4183062011-01-16 10:43:21 -0800289 mainView.setNextFocusUpId(R.id.url_focused);
290 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700291 mUiController.attachSubWindow(tab);
292 }
293
294 private void removeTabFromContentView(Tab tab) {
295 // Remove the container that contains the main WebView.
296 WebView mainView = tab.getWebView();
297 View container = tab.getViewContainer();
298 if (mainView == null) {
299 return;
300 }
301 // Remove the container from the content and then remove the
302 // WebView from the container. This will trigger a focus change
303 // needed by WebView.
304 FrameLayout wrapper =
305 (FrameLayout) container.findViewById(R.id.webview_wrapper);
306 wrapper.removeView(mainView);
307 mContentView.removeView(container);
308 mUiController.endActionMode();
309 mUiController.removeSubWindow(tab);
310 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
311 if (errorConsole != null) {
312 mErrorConsoleContainer.removeView(errorConsole);
313 }
314 mainView.setEmbeddedTitleBar(null);
315 }
316
Michael Kolba713ec82010-11-29 17:27:06 -0800317 @Override
318 public void onSetWebView(Tab tab, WebView webView) {
319 View container = tab.getViewContainer();
320 if (container == null) {
321 // The tab consists of a container view, which contains the main
322 // WebView, as well as any other UI elements associated with the tab.
323 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
324 null);
325 tab.setViewContainer(container);
326 }
327 if (tab.getWebView() != webView) {
328 // Just remove the old one.
329 FrameLayout wrapper =
330 (FrameLayout) container.findViewById(R.id.webview_wrapper);
331 wrapper.removeView(tab.getWebView());
332 }
333 }
334
Michael Kolb8233fac2010-10-26 16:08:53 -0700335 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800336 * create a sub window container and webview for the tab
337 * Note: this methods operates through side-effects for now
338 * it sets both the subView and subViewContainer for the given tab
339 * @param tab tab to create the sub window for
340 * @param subView webview to be set as a subwindow for the tab
341 */
342 @Override
343 public void createSubWindow(Tab tab, WebView subView) {
344 View subViewContainer = mActivity.getLayoutInflater().inflate(
345 R.layout.browser_subwindow, null);
346 ViewGroup inner = (ViewGroup) subViewContainer
347 .findViewById(R.id.inner_container);
348 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
349 LayoutParams.MATCH_PARENT));
350 final ImageButton cancel = (ImageButton) subViewContainer
351 .findViewById(R.id.subwindow_close);
352 final WebView cancelSubView = subView;
353 cancel.setOnClickListener(new OnClickListener() {
354 public void onClick(View v) {
355 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
356 }
357 });
358 tab.setSubWebView(subView);
359 tab.setSubViewContainer(subViewContainer);
360 }
361
362 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700363 * Remove the sub window from the content view.
364 */
365 @Override
366 public void removeSubWindow(View subviewContainer) {
367 mContentView.removeView(subviewContainer);
368 mUiController.endActionMode();
369 }
370
371 /**
372 * Attach the sub window to the content view.
373 */
374 @Override
375 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800376 if (container.getParent() != null) {
377 // already attached, remove first
378 ((ViewGroup) container.getParent()).removeView(container);
379 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 mContentView.addView(container, COVER_SCREEN_PARAMS);
381 }
382
383 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800384 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700385 WebView mainView = mUiController.getCurrentWebView();
386 // if there is no current WebView, don't show the faked title bar;
387 if (mainView == null) {
388 return;
389 }
390 // Do not need to check for null, since the current tab will have
391 // at least a main WebView, or we would have returned above.
392 if (mUiController.isInCustomActionMode()) {
393 // Do not show the fake title bar, while a custom ActionMode
394 // (i.e. find or select) is showing.
395 return;
396 }
Michael Kolb66706532010-12-12 19:50:22 -0800397 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700398 }
399 }
400
Michael Kolb66706532010-12-12 19:50:22 -0800401 protected abstract void attachFakeTitleBar(WebView mainView);
402
403 protected abstract void hideFakeTitleBar();
404
405 protected abstract boolean isFakeTitleBarShowing();
406
407 protected abstract TitleBarBase getFakeTitleBar();
408
409 protected abstract TitleBarBase getEmbeddedTitleBar();
410
411 @Override
412 public void showVoiceTitleBar(String title) {
413 getEmbeddedTitleBar().setInVoiceMode(true);
414 getEmbeddedTitleBar().setDisplayTitle(title);
415 getFakeTitleBar().setInVoiceMode(true);
416 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 }
418
Michael Kolb66706532010-12-12 19:50:22 -0800419 @Override
420 public void revertVoiceTitleBar(Tab tab) {
421 getEmbeddedTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800422 String url = tab.getUrl();
Michael Kolb66706532010-12-12 19:50:22 -0800423 getEmbeddedTitleBar().setDisplayTitle(url);
424 getFakeTitleBar().setInVoiceMode(false);
425 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427
428 @Override
429 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800430 if (mComboView != null) {
431 return;
432 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700433 mComboView = new CombinedBookmarkHistoryView(mActivity,
434 mUiController,
435 startWithHistory ?
436 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
437 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
438 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800439 FrameLayout wrapper =
440 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
441 wrapper.setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700442 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800443 dismissIME();
444 if (mActiveTab != null) {
445 WebView web = mActiveTab.getWebView();
446 mActiveTab.putInBackground();
447 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700448 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
449 }
450
451 /**
452 * dismiss the ComboPage
453 */
454 @Override
455 public void hideComboView() {
456 if (mComboView != null) {
457 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800458 FrameLayout wrapper =
459 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
460 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700461 mComboView = null;
462 }
Michael Kolb3a696282010-12-05 13:23:24 -0800463 if (mActiveTab != null) {
464 mActiveTab.putInForeground();
465 }
John Reckb3417f02011-01-14 11:01:05 -0800466 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 }
468
469 @Override
470 public void showCustomView(View view,
471 WebChromeClient.CustomViewCallback callback) {
472 // if a view already exists then immediately terminate the new one
473 if (mCustomView != null) {
474 callback.onCustomViewHidden();
475 return;
476 }
477
478 // Add the custom view to its container.
479 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
480 mCustomView = view;
481 mCustomViewCallback = callback;
482 // Hide the content view.
483 mContentView.setVisibility(View.GONE);
484 // Finally show the custom view container.
485 setStatusBarVisibility(false);
486 mCustomViewContainer.setVisibility(View.VISIBLE);
487 mCustomViewContainer.bringToFront();
488 }
489
490 @Override
491 public void onHideCustomView() {
492 if (mCustomView == null)
493 return;
494
495 // Hide the custom view.
496 mCustomView.setVisibility(View.GONE);
497 // Remove the custom view from its container.
498 mCustomViewContainer.removeView(mCustomView);
499 mCustomView = null;
500 mCustomViewContainer.setVisibility(View.GONE);
501 mCustomViewCallback.onCustomViewHidden();
502 // Show the content view.
503 setStatusBarVisibility(true);
504 mContentView.setVisibility(View.VISIBLE);
505 }
506
507 @Override
508 public boolean isCustomViewShowing() {
509 return mCustomView != null;
510 }
511
Michael Kolb66706532010-12-12 19:50:22 -0800512 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800513 if (mInputManager.isActive()) {
514 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
515 0);
516 }
517 }
518
Michael Kolb66706532010-12-12 19:50:22 -0800519 @Override
520 public boolean showsWeb() {
521 return mCustomView == null
522 && mComboView == null;
523 }
524
Michael Kolb8233fac2010-10-26 16:08:53 -0700525 // -------------------------------------------------------------------------
526
Michael Kolb5a72f182011-01-13 20:35:06 -0800527 protected void updateNavigationState(Tab tab) {
528 }
529
Michael Kolb8233fac2010-10-26 16:08:53 -0700530 /**
531 * Update the lock icon to correspond to our latest state.
532 */
Michael Kolb66706532010-12-12 19:50:22 -0800533 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800534 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700535 updateLockIconImage(t.getLockIconType());
536 }
537 }
538
539 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700540 * Updates the lock-icon image in the title-bar.
541 */
John Reck30c714c2010-12-16 17:30:34 -0800542 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700543 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800544 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800546 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700547 d = mMixLockIcon;
548 }
Michael Kolb66706532010-12-12 19:50:22 -0800549 getEmbeddedTitleBar().setLock(d);
550 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700551 }
552
John Reck30c714c2010-12-16 17:30:34 -0800553 protected void setUrlTitle(Tab tab) {
554 String url = tab.getUrl();
555 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800556 if (TextUtils.isEmpty(title)) {
557 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800558 }
Michael Kolb66706532010-12-12 19:50:22 -0800559 if (tab.isInVoiceSearchMode()) return;
560 if (tab.inForeground()) {
561 getEmbeddedTitleBar().setDisplayTitle(url);
562 getFakeTitleBar().setDisplayTitle(url);
563 }
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();
570 getEmbeddedTitleBar().setFavicon(icon);
571 getFakeTitleBar().setFavicon(icon);
572 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700573 }
574
575 @Override
576 public void onActionModeFinished(boolean inLoad) {
577 if (inLoad) {
578 // the titlebar was removed when the CAB was shown
579 // if the page is loading, show it again
580 showFakeTitleBar();
581 }
582 }
583
Michael Kolb66706532010-12-12 19:50:22 -0800584 // active tabs page
585
586 public void showActiveTabsPage() {
587 }
588
589 /**
590 * Remove the active tabs page.
591 */
592 public void removeActiveTabsPage() {
593 }
594
Michael Kolb8233fac2010-10-26 16:08:53 -0700595 // menu handling callbacks
596
597 @Override
598 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700599 }
600
601 @Override
602 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 }
604
605 @Override
606 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 }
608
609 @Override
610 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 }
612
613 @Override
614 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 }
616
617 @Override
618 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700619 }
620
621 // error console
622
623 @Override
624 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
625 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) {
648 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
649 mActivity.getWindow().setFlags(flag,
650 WindowManager.LayoutParams.FLAG_FULLSCREEN);
651 }
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}