blob: 6b8b4473fae7f1bb03dd579a9e5beffe60419b6c [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
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070020import android.content.res.Configuration;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070024import android.graphics.drawable.Drawable;
25import android.os.Bundle;
26import android.text.TextUtils;
27import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.view.Gravity;
29import android.view.LayoutInflater;
30import android.view.Menu;
31import android.view.MenuItem;
32import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080033import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080035import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080037import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.webkit.WebChromeClient;
39import android.webkit.WebHistoryItem;
40import 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
88 // the default <video> poster
89 private Bitmap mDefaultVideoPoster;
90 // the video progress view
91 private View mVideoProgressView;
92
Michael Kolb8233fac2010-10-26 16:08:53 -070093 private boolean mActivityPaused;
94
95 public BaseUi(Activity browser, UiController controller) {
96 mActivity = browser;
97 mUiController = controller;
98 mTabControl = controller.getTabControl();
99 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800100 mInputManager = (InputMethodManager)
101 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700102 mSecLockIcon = res.getDrawable(R.drawable.ic_secure);
103 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
104
Michael Kolb8233fac2010-10-26 16:08:53 -0700105 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
106 .getDecorView().findViewById(android.R.id.content);
107 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
108 .inflate(R.layout.custom_screen, null);
109 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
110 R.id.main_content);
111 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
112 .findViewById(R.id.error_console);
113 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
114 .findViewById(R.id.fullscreen_custom_content);
115 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
116
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
181 // WebView callbacks
182
183 @Override
184 public void onPageStarted(Tab tab, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700185 if (tab.inForeground()) {
186 resetLockIcon(tab, url);
187 setUrlTitle(tab, url, null);
188 setFavicon(tab, favicon);
189 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 }
191
192 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500193 public void bookmarkedStatusHasChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800194 // no op in base case
Leon Scroggins4cd97792010-12-03 15:31:56 -0500195 }
196
197 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 public void onPageFinished(Tab tab, String url) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700199 if (tab.inForeground()) {
200 // Reset the title and icon in case we stopped a provisional load.
201 resetTitleAndIcon(tab);
202 // Update the lock icon image only once we are done loading
203 updateLockIconToLatest(tab);
204 }
205 }
206
207 @Override
208 public void onPageStopped(Tab tab) {
209 cancelStopToast();
210 if (tab.inForeground()) {
211 mStopToast = Toast
212 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
213 mStopToast.show();
214 }
215 }
216
217 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800218 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800219 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800220 }
221
222 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700224 }
225
226 @Override
227 public void setActiveTab(Tab tab) {
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 Kolb8233fac2010-10-26 16:08:53 -0700232 attachTabToContentView(tab);
233 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 WebView view = tab.getWebView();
Michael Kolb77df4562010-11-19 14:49:34 -0800235 // TabControl.setCurrentTab has been called before this,
236 // so the tab is guaranteed to have a webview
237 if (view == null) {
238 Log.e(LOGTAG, "active tab with no webview detected");
239 return;
240 }
Michael Kolb66706532010-12-12 19:50:22 -0800241 view.setEmbeddedTitleBar(getEmbeddedTitleBar());
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 if (tab.isInVoiceSearchMode()) {
243 showVoiceTitleBar(tab.getVoiceDisplayTitle());
244 } else {
245 revertVoiceTitleBar(tab);
246 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 resetTitleIconAndProgress(tab);
248 updateLockIconToLatest(tab);
249 tab.getTopWindow().requestFocus();
250 }
251
252 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800253 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800254 }
255
256 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800258 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800260 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700261 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700262 }
263
264 @Override
265 public void detachTab(Tab tab) {
266 removeTabFromContentView(tab);
267 }
268
269 @Override
270 public void attachTab(Tab tab) {
271 attachTabToContentView(tab);
272 }
273
274 private void attachTabToContentView(Tab tab) {
275 if (tab.getWebView() == null) {
276 return;
277 }
278 View container = tab.getViewContainer();
279 WebView mainView = tab.getWebView();
280 // Attach the WebView to the container and then attach the
281 // container to the content view.
282 FrameLayout wrapper =
283 (FrameLayout) container.findViewById(R.id.webview_wrapper);
284 ViewGroup parent = (ViewGroup) mainView.getParent();
285 if (parent != wrapper) {
286 if (parent != null) {
287 Log.w(LOGTAG, "mMainView already has a parent in"
288 + " attachTabToContentView!");
289 parent.removeView(mainView);
290 }
291 wrapper.addView(mainView);
292 } else {
293 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
294 + " attachTabToContentView!");
295 }
296 parent = (ViewGroup) container.getParent();
297 if (parent != mContentView) {
298 if (parent != null) {
299 Log.w(LOGTAG, "mContainer already has a parent in"
300 + " attachTabToContentView!");
301 parent.removeView(container);
302 }
303 mContentView.addView(container, COVER_SCREEN_PARAMS);
304 } else {
305 Log.w(LOGTAG, "mContainer is already attached to content in"
306 + " attachTabToContentView!");
307 }
308 mUiController.attachSubWindow(tab);
309 }
310
311 private void removeTabFromContentView(Tab tab) {
312 // Remove the container that contains the main WebView.
313 WebView mainView = tab.getWebView();
314 View container = tab.getViewContainer();
315 if (mainView == null) {
316 return;
317 }
318 // Remove the container from the content and then remove the
319 // WebView from the container. This will trigger a focus change
320 // needed by WebView.
321 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 }
331 mainView.setEmbeddedTitleBar(null);
332 }
333
Michael Kolba713ec82010-11-29 17:27:06 -0800334 @Override
335 public void onSetWebView(Tab tab, WebView webView) {
336 View container = tab.getViewContainer();
337 if (container == null) {
338 // The tab consists of a container view, which contains the main
339 // WebView, as well as any other UI elements associated with the tab.
340 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
341 null);
342 tab.setViewContainer(container);
343 }
344 if (tab.getWebView() != webView) {
345 // Just remove the old one.
346 FrameLayout wrapper =
347 (FrameLayout) container.findViewById(R.id.webview_wrapper);
348 wrapper.removeView(tab.getWebView());
349 }
350 }
351
Michael Kolb8233fac2010-10-26 16:08:53 -0700352 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800353 * create a sub window container and webview for the tab
354 * Note: this methods operates through side-effects for now
355 * it sets both the subView and subViewContainer for the given tab
356 * @param tab tab to create the sub window for
357 * @param subView webview to be set as a subwindow for the tab
358 */
359 @Override
360 public void createSubWindow(Tab tab, WebView subView) {
361 View subViewContainer = mActivity.getLayoutInflater().inflate(
362 R.layout.browser_subwindow, null);
363 ViewGroup inner = (ViewGroup) subViewContainer
364 .findViewById(R.id.inner_container);
365 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
366 LayoutParams.MATCH_PARENT));
367 final ImageButton cancel = (ImageButton) subViewContainer
368 .findViewById(R.id.subwindow_close);
369 final WebView cancelSubView = subView;
370 cancel.setOnClickListener(new OnClickListener() {
371 public void onClick(View v) {
372 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
373 }
374 });
375 tab.setSubWebView(subView);
376 tab.setSubViewContainer(subViewContainer);
377 }
378
379 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 * Remove the sub window from the content view.
381 */
382 @Override
383 public void removeSubWindow(View subviewContainer) {
384 mContentView.removeView(subviewContainer);
385 mUiController.endActionMode();
386 }
387
388 /**
389 * Attach the sub window to the content view.
390 */
391 @Override
392 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800393 if (container.getParent() != null) {
394 // already attached, remove first
395 ((ViewGroup) container.getParent()).removeView(container);
396 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700397 mContentView.addView(container, COVER_SCREEN_PARAMS);
398 }
399
400 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800401 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 WebView mainView = mUiController.getCurrentWebView();
403 // if there is no current WebView, don't show the faked title bar;
404 if (mainView == null) {
405 return;
406 }
407 // Do not need to check for null, since the current tab will have
408 // at least a main WebView, or we would have returned above.
409 if (mUiController.isInCustomActionMode()) {
410 // Do not show the fake title bar, while a custom ActionMode
411 // (i.e. find or select) is showing.
412 return;
413 }
Michael Kolb66706532010-12-12 19:50:22 -0800414 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700415 }
416 }
417
Michael Kolb66706532010-12-12 19:50:22 -0800418 protected abstract void attachFakeTitleBar(WebView mainView);
419
420 protected abstract void hideFakeTitleBar();
421
422 protected abstract boolean isFakeTitleBarShowing();
423
424 protected abstract TitleBarBase getFakeTitleBar();
425
426 protected abstract TitleBarBase getEmbeddedTitleBar();
427
428 @Override
429 public void showVoiceTitleBar(String title) {
430 getEmbeddedTitleBar().setInVoiceMode(true);
431 getEmbeddedTitleBar().setDisplayTitle(title);
432 getFakeTitleBar().setInVoiceMode(true);
433 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700434 }
435
Michael Kolb66706532010-12-12 19:50:22 -0800436 @Override
437 public void revertVoiceTitleBar(Tab tab) {
438 getEmbeddedTitleBar().setInVoiceMode(false);
439 String url = tab.getCurrentUrl();
440 getEmbeddedTitleBar().setDisplayTitle(url);
441 getFakeTitleBar().setInVoiceMode(false);
442 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700443 }
444
445 @Override
446 public void showComboView(boolean startWithHistory, Bundle extras) {
447 mComboView = new CombinedBookmarkHistoryView(mActivity,
448 mUiController,
449 startWithHistory ?
450 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
451 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
452 extras);
Michael Kolb66706532010-12-12 19:50:22 -0800453 getEmbeddedTitleBar().setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700454 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800455 dismissIME();
456 if (mActiveTab != null) {
457 WebView web = mActiveTab.getWebView();
458 mActiveTab.putInBackground();
459 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
461 }
462
463 /**
464 * dismiss the ComboPage
465 */
466 @Override
467 public void hideComboView() {
468 if (mComboView != null) {
469 mContentView.removeView(mComboView);
Michael Kolb66706532010-12-12 19:50:22 -0800470 getEmbeddedTitleBar().setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700471 mComboView = null;
472 }
Michael Kolb3a696282010-12-05 13:23:24 -0800473 if (mActiveTab != null) {
474 mActiveTab.putInForeground();
475 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700476 }
477
478 @Override
479 public void showCustomView(View view,
480 WebChromeClient.CustomViewCallback callback) {
481 // if a view already exists then immediately terminate the new one
482 if (mCustomView != null) {
483 callback.onCustomViewHidden();
484 return;
485 }
486
487 // Add the custom view to its container.
488 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
489 mCustomView = view;
490 mCustomViewCallback = callback;
491 // Hide the content view.
492 mContentView.setVisibility(View.GONE);
493 // Finally show the custom view container.
494 setStatusBarVisibility(false);
495 mCustomViewContainer.setVisibility(View.VISIBLE);
496 mCustomViewContainer.bringToFront();
497 }
498
499 @Override
500 public void onHideCustomView() {
501 if (mCustomView == null)
502 return;
503
504 // Hide the custom view.
505 mCustomView.setVisibility(View.GONE);
506 // Remove the custom view from its container.
507 mCustomViewContainer.removeView(mCustomView);
508 mCustomView = null;
509 mCustomViewContainer.setVisibility(View.GONE);
510 mCustomViewCallback.onCustomViewHidden();
511 // Show the content view.
512 setStatusBarVisibility(true);
513 mContentView.setVisibility(View.VISIBLE);
514 }
515
516 @Override
517 public boolean isCustomViewShowing() {
518 return mCustomView != null;
519 }
520
Michael Kolb66706532010-12-12 19:50:22 -0800521 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800522 if (mInputManager.isActive()) {
523 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
524 0);
525 }
526 }
527
Michael Kolb66706532010-12-12 19:50:22 -0800528 @Override
529 public boolean showsWeb() {
530 return mCustomView == null
531 && mComboView == null;
532 }
533
Michael Kolb8233fac2010-10-26 16:08:53 -0700534 // -------------------------------------------------------------------------
535
536 @Override
537 public void resetTitleAndRevertLockIcon(Tab tab) {
538 tab.revertLockIcon();
539 updateLockIconToLatest(tab);
540 resetTitleIconAndProgress(tab);
541 }
542
543 /**
544 * Resets the lock icon. This method is called when we start a new load and
545 * know the url to be loaded.
546 */
547 private void resetLockIcon(Tab tab, String url) {
548 // Save the lock-icon state (we revert to it if the load gets cancelled)
549 tab.resetLockIcon(url);
550 updateLockIconImage(Tab.LOCK_ICON_UNSECURE);
551 }
552
553 /**
554 * Update the lock icon to correspond to our latest state.
555 */
Michael Kolb66706532010-12-12 19:50:22 -0800556 protected void updateLockIconToLatest(Tab t) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700557 if (t != null) {
558 updateLockIconImage(t.getLockIconType());
559 }
560 }
561
562 /**
563 * Reset the title, favicon, and progress.
564 */
Michael Kolb66706532010-12-12 19:50:22 -0800565 protected void resetTitleIconAndProgress(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700566 WebView current = tab.getWebView();
567 if (current == null) {
568 return;
569 }
Michael Kolb41d3b942010-12-05 11:35:20 -0800570 resetTitleAndIcon(tab, current);
Michael Kolb8233fac2010-10-26 16:08:53 -0700571 int progress = current.getProgress();
572 current.getWebChromeClient().onProgressChanged(current, progress);
573 }
574
575 @Override
576 public void resetTitleAndIcon(Tab tab) {
577 WebView current = tab.getWebView();
578 if (current != null) {
Michael Kolb41d3b942010-12-05 11:35:20 -0800579 resetTitleAndIcon(tab, current);
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 }
581 }
582
583 // Reset the title and the icon based on the given item.
Michael Kolb41d3b942010-12-05 11:35:20 -0800584 private void resetTitleAndIcon(Tab tab, WebView view) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700585 WebHistoryItem item = view.copyBackForwardList().getCurrentItem();
Michael Kolb8233fac2010-10-26 16:08:53 -0700586 if (item != null) {
587 setUrlTitle(tab, item.getUrl(), item.getTitle());
588 setFavicon(tab, item.getFavicon());
589 } else {
John Reckef074262010-12-02 16:09:14 -0800590 setUrlTitle(tab, null, mActivity.getString(R.string.new_tab));
Michael Kolb8233fac2010-10-26 16:08:53 -0700591 setFavicon(tab, null);
592 }
593 }
594
595 /**
596 * Updates the lock-icon image in the title-bar.
597 */
598 private void updateLockIconImage(int lockIconType) {
599 Drawable d = null;
600 if (lockIconType == Tab.LOCK_ICON_SECURE) {
601 d = mSecLockIcon;
602 } else if (lockIconType == Tab.LOCK_ICON_MIXED) {
603 d = mMixLockIcon;
604 }
Michael Kolb66706532010-12-12 19:50:22 -0800605 getEmbeddedTitleBar().setLock(d);
606 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 }
608
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800610 public void setUrlTitle(Tab tab, String url, String title) {
611 if (TextUtils.isEmpty(title)) {
612 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800613 }
Michael Kolb66706532010-12-12 19:50:22 -0800614 if (tab.isInVoiceSearchMode()) return;
615 if (tab.inForeground()) {
616 getEmbeddedTitleBar().setDisplayTitle(url);
617 getFakeTitleBar().setDisplayTitle(url);
618 }
619 }
620
621 // Set the favicon in the title bar.
622 @Override
623 public void setFavicon(Tab tab, Bitmap icon) {
624 getEmbeddedTitleBar().setFavicon(icon);
625 getFakeTitleBar().setFavicon(icon);
Michael Kolb8233fac2010-10-26 16:08:53 -0700626 }
627
628 @Override
629 public void onActionModeFinished(boolean inLoad) {
630 if (inLoad) {
631 // the titlebar was removed when the CAB was shown
632 // if the page is loading, show it again
633 showFakeTitleBar();
634 }
635 }
636
Michael Kolb66706532010-12-12 19:50:22 -0800637 // active tabs page
638
639 public void showActiveTabsPage() {
640 }
641
642 /**
643 * Remove the active tabs page.
644 */
645 public void removeActiveTabsPage() {
646 }
647
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 // menu handling callbacks
649
650 @Override
651 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700652 }
653
654 @Override
655 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 }
657
658 @Override
659 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700660 }
661
662 @Override
663 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700664 }
665
666 @Override
667 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 }
669
670 @Override
671 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 }
673
674 // error console
675
676 @Override
677 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
678 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
679 if (flag) {
680 // Setting the show state of the console will cause it's the layout
681 // to be inflated.
682 if (errorConsole.numberOfErrors() > 0) {
683 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
684 } else {
685 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
686 }
687 if (errorConsole.getParent() != null) {
688 mErrorConsoleContainer.removeView(errorConsole);
689 }
690 // Now we can add it to the main view.
691 mErrorConsoleContainer.addView(errorConsole,
692 new LinearLayout.LayoutParams(
693 ViewGroup.LayoutParams.MATCH_PARENT,
694 ViewGroup.LayoutParams.WRAP_CONTENT));
695 } else {
696 mErrorConsoleContainer.removeView(errorConsole);
697 }
698 }
699
700 private void setStatusBarVisibility(boolean visible) {
701 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
702 mActivity.getWindow().setFlags(flag,
703 WindowManager.LayoutParams.FLAG_FULLSCREEN);
704 }
705
706 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700707 public void onPrepareOptionsMenu(Menu menu) {
Michael Kolb66706532010-12-12 19:50:22 -0800708 final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
709 newtab.setEnabled(mUiController.getTabControl().canCreateNewTab());
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 }
711
712 // -------------------------------------------------------------------------
713 // Helper function for WebChromeClient
714 // -------------------------------------------------------------------------
715
716 @Override
717 public Bitmap getDefaultVideoPoster() {
718 if (mDefaultVideoPoster == null) {
719 mDefaultVideoPoster = BitmapFactory.decodeResource(
720 mActivity.getResources(), R.drawable.default_video_poster);
721 }
722 return mDefaultVideoPoster;
723 }
724
725 @Override
726 public View getVideoLoadingProgressView() {
727 if (mVideoProgressView == null) {
728 LayoutInflater inflater = LayoutInflater.from(mActivity);
729 mVideoProgressView = inflater.inflate(
730 R.layout.video_loading_progress, null);
731 }
732 return mVideoProgressView;
733 }
734
Michael Kolb843510f2010-12-09 10:51:49 -0800735 @Override
736 public void showMaxTabsWarning() {
737 Toast warning = Toast.makeText(mActivity,
738 mActivity.getString(R.string.max_tabs_warning),
739 Toast.LENGTH_SHORT);
740 warning.show();
741 }
742
Michael Kolb8233fac2010-10-26 16:08:53 -0700743}