blob: 95e795cc4bab58887d3e9f0ae38f3936b44ef313 [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
Michael Kolbcfa3af52010-12-14 10:36:11 -0800252 Tab getActiveTab() {
253 return mActiveTab;
254 }
255
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800257 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800258 }
259
260 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700261 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800262 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700263 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800264 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700266 }
267
268 @Override
269 public void detachTab(Tab tab) {
270 removeTabFromContentView(tab);
271 }
272
273 @Override
274 public void attachTab(Tab tab) {
275 attachTabToContentView(tab);
276 }
277
278 private void attachTabToContentView(Tab tab) {
279 if (tab.getWebView() == null) {
280 return;
281 }
282 View container = tab.getViewContainer();
283 WebView mainView = tab.getWebView();
284 // Attach the WebView to the container and then attach the
285 // container to the content view.
286 FrameLayout wrapper =
287 (FrameLayout) container.findViewById(R.id.webview_wrapper);
288 ViewGroup parent = (ViewGroup) mainView.getParent();
289 if (parent != wrapper) {
290 if (parent != null) {
291 Log.w(LOGTAG, "mMainView already has a parent in"
292 + " attachTabToContentView!");
293 parent.removeView(mainView);
294 }
295 wrapper.addView(mainView);
296 } else {
297 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
298 + " attachTabToContentView!");
299 }
300 parent = (ViewGroup) container.getParent();
301 if (parent != mContentView) {
302 if (parent != null) {
303 Log.w(LOGTAG, "mContainer already has a parent in"
304 + " attachTabToContentView!");
305 parent.removeView(container);
306 }
307 mContentView.addView(container, COVER_SCREEN_PARAMS);
308 } else {
309 Log.w(LOGTAG, "mContainer is already attached to content in"
310 + " attachTabToContentView!");
311 }
312 mUiController.attachSubWindow(tab);
313 }
314
315 private void removeTabFromContentView(Tab tab) {
316 // Remove the container that contains the main WebView.
317 WebView mainView = tab.getWebView();
318 View container = tab.getViewContainer();
319 if (mainView == null) {
320 return;
321 }
322 // Remove the container from the content and then remove the
323 // WebView from the container. This will trigger a focus change
324 // needed by WebView.
325 FrameLayout wrapper =
326 (FrameLayout) container.findViewById(R.id.webview_wrapper);
327 wrapper.removeView(mainView);
328 mContentView.removeView(container);
329 mUiController.endActionMode();
330 mUiController.removeSubWindow(tab);
331 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
332 if (errorConsole != null) {
333 mErrorConsoleContainer.removeView(errorConsole);
334 }
335 mainView.setEmbeddedTitleBar(null);
336 }
337
Michael Kolba713ec82010-11-29 17:27:06 -0800338 @Override
339 public void onSetWebView(Tab tab, WebView webView) {
340 View container = tab.getViewContainer();
341 if (container == null) {
342 // The tab consists of a container view, which contains the main
343 // WebView, as well as any other UI elements associated with the tab.
344 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
345 null);
346 tab.setViewContainer(container);
347 }
348 if (tab.getWebView() != webView) {
349 // Just remove the old one.
350 FrameLayout wrapper =
351 (FrameLayout) container.findViewById(R.id.webview_wrapper);
352 wrapper.removeView(tab.getWebView());
353 }
354 }
355
Michael Kolb8233fac2010-10-26 16:08:53 -0700356 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800357 * create a sub window container and webview for the tab
358 * Note: this methods operates through side-effects for now
359 * it sets both the subView and subViewContainer for the given tab
360 * @param tab tab to create the sub window for
361 * @param subView webview to be set as a subwindow for the tab
362 */
363 @Override
364 public void createSubWindow(Tab tab, WebView subView) {
365 View subViewContainer = mActivity.getLayoutInflater().inflate(
366 R.layout.browser_subwindow, null);
367 ViewGroup inner = (ViewGroup) subViewContainer
368 .findViewById(R.id.inner_container);
369 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
370 LayoutParams.MATCH_PARENT));
371 final ImageButton cancel = (ImageButton) subViewContainer
372 .findViewById(R.id.subwindow_close);
373 final WebView cancelSubView = subView;
374 cancel.setOnClickListener(new OnClickListener() {
375 public void onClick(View v) {
376 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
377 }
378 });
379 tab.setSubWebView(subView);
380 tab.setSubViewContainer(subViewContainer);
381 }
382
383 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700384 * Remove the sub window from the content view.
385 */
386 @Override
387 public void removeSubWindow(View subviewContainer) {
388 mContentView.removeView(subviewContainer);
389 mUiController.endActionMode();
390 }
391
392 /**
393 * Attach the sub window to the content view.
394 */
395 @Override
396 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800397 if (container.getParent() != null) {
398 // already attached, remove first
399 ((ViewGroup) container.getParent()).removeView(container);
400 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700401 mContentView.addView(container, COVER_SCREEN_PARAMS);
402 }
403
404 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800405 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700406 WebView mainView = mUiController.getCurrentWebView();
407 // if there is no current WebView, don't show the faked title bar;
408 if (mainView == null) {
409 return;
410 }
411 // Do not need to check for null, since the current tab will have
412 // at least a main WebView, or we would have returned above.
413 if (mUiController.isInCustomActionMode()) {
414 // Do not show the fake title bar, while a custom ActionMode
415 // (i.e. find or select) is showing.
416 return;
417 }
Michael Kolb66706532010-12-12 19:50:22 -0800418 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700419 }
420 }
421
Michael Kolb66706532010-12-12 19:50:22 -0800422 protected abstract void attachFakeTitleBar(WebView mainView);
423
424 protected abstract void hideFakeTitleBar();
425
426 protected abstract boolean isFakeTitleBarShowing();
427
428 protected abstract TitleBarBase getFakeTitleBar();
429
430 protected abstract TitleBarBase getEmbeddedTitleBar();
431
432 @Override
433 public void showVoiceTitleBar(String title) {
434 getEmbeddedTitleBar().setInVoiceMode(true);
435 getEmbeddedTitleBar().setDisplayTitle(title);
436 getFakeTitleBar().setInVoiceMode(true);
437 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700438 }
439
Michael Kolb66706532010-12-12 19:50:22 -0800440 @Override
441 public void revertVoiceTitleBar(Tab tab) {
442 getEmbeddedTitleBar().setInVoiceMode(false);
443 String url = tab.getCurrentUrl();
444 getEmbeddedTitleBar().setDisplayTitle(url);
445 getFakeTitleBar().setInVoiceMode(false);
446 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700447 }
448
449 @Override
450 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800451 if (mComboView != null) {
452 return;
453 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700454 mComboView = new CombinedBookmarkHistoryView(mActivity,
455 mUiController,
456 startWithHistory ?
457 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
458 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
459 extras);
Michael Kolb66706532010-12-12 19:50:22 -0800460 getEmbeddedTitleBar().setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700461 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800462 dismissIME();
463 if (mActiveTab != null) {
464 WebView web = mActiveTab.getWebView();
465 mActiveTab.putInBackground();
466 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
468 }
469
470 /**
471 * dismiss the ComboPage
472 */
473 @Override
474 public void hideComboView() {
475 if (mComboView != null) {
476 mContentView.removeView(mComboView);
Michael Kolb66706532010-12-12 19:50:22 -0800477 getEmbeddedTitleBar().setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700478 mComboView = null;
479 }
Michael Kolb3a696282010-12-05 13:23:24 -0800480 if (mActiveTab != null) {
481 mActiveTab.putInForeground();
482 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700483 }
484
485 @Override
486 public void showCustomView(View view,
487 WebChromeClient.CustomViewCallback callback) {
488 // if a view already exists then immediately terminate the new one
489 if (mCustomView != null) {
490 callback.onCustomViewHidden();
491 return;
492 }
493
494 // Add the custom view to its container.
495 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
496 mCustomView = view;
497 mCustomViewCallback = callback;
498 // Hide the content view.
499 mContentView.setVisibility(View.GONE);
500 // Finally show the custom view container.
501 setStatusBarVisibility(false);
502 mCustomViewContainer.setVisibility(View.VISIBLE);
503 mCustomViewContainer.bringToFront();
504 }
505
506 @Override
507 public void onHideCustomView() {
508 if (mCustomView == null)
509 return;
510
511 // Hide the custom view.
512 mCustomView.setVisibility(View.GONE);
513 // Remove the custom view from its container.
514 mCustomViewContainer.removeView(mCustomView);
515 mCustomView = null;
516 mCustomViewContainer.setVisibility(View.GONE);
517 mCustomViewCallback.onCustomViewHidden();
518 // Show the content view.
519 setStatusBarVisibility(true);
520 mContentView.setVisibility(View.VISIBLE);
521 }
522
523 @Override
524 public boolean isCustomViewShowing() {
525 return mCustomView != null;
526 }
527
Michael Kolb66706532010-12-12 19:50:22 -0800528 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800529 if (mInputManager.isActive()) {
530 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
531 0);
532 }
533 }
534
Michael Kolb66706532010-12-12 19:50:22 -0800535 @Override
536 public boolean showsWeb() {
537 return mCustomView == null
538 && mComboView == null;
539 }
540
Michael Kolb8233fac2010-10-26 16:08:53 -0700541 // -------------------------------------------------------------------------
542
543 @Override
544 public void resetTitleAndRevertLockIcon(Tab tab) {
545 tab.revertLockIcon();
546 updateLockIconToLatest(tab);
547 resetTitleIconAndProgress(tab);
548 }
549
550 /**
551 * Resets the lock icon. This method is called when we start a new load and
552 * know the url to be loaded.
553 */
554 private void resetLockIcon(Tab tab, String url) {
555 // Save the lock-icon state (we revert to it if the load gets cancelled)
556 tab.resetLockIcon(url);
557 updateLockIconImage(Tab.LOCK_ICON_UNSECURE);
558 }
559
560 /**
561 * Update the lock icon to correspond to our latest state.
562 */
Michael Kolb66706532010-12-12 19:50:22 -0800563 protected void updateLockIconToLatest(Tab t) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700564 if (t != null) {
565 updateLockIconImage(t.getLockIconType());
566 }
567 }
568
569 /**
570 * Reset the title, favicon, and progress.
571 */
Michael Kolb66706532010-12-12 19:50:22 -0800572 protected void resetTitleIconAndProgress(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700573 WebView current = tab.getWebView();
574 if (current == null) {
575 return;
576 }
Michael Kolb41d3b942010-12-05 11:35:20 -0800577 resetTitleAndIcon(tab, current);
Michael Kolb8233fac2010-10-26 16:08:53 -0700578 int progress = current.getProgress();
579 current.getWebChromeClient().onProgressChanged(current, progress);
580 }
581
582 @Override
583 public void resetTitleAndIcon(Tab tab) {
584 WebView current = tab.getWebView();
585 if (current != null) {
Michael Kolb41d3b942010-12-05 11:35:20 -0800586 resetTitleAndIcon(tab, current);
Michael Kolb8233fac2010-10-26 16:08:53 -0700587 }
588 }
589
590 // Reset the title and the icon based on the given item.
Michael Kolb41d3b942010-12-05 11:35:20 -0800591 private void resetTitleAndIcon(Tab tab, WebView view) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700592 WebHistoryItem item = view.copyBackForwardList().getCurrentItem();
Michael Kolb8233fac2010-10-26 16:08:53 -0700593 if (item != null) {
594 setUrlTitle(tab, item.getUrl(), item.getTitle());
595 setFavicon(tab, item.getFavicon());
596 } else {
John Reckef074262010-12-02 16:09:14 -0800597 setUrlTitle(tab, null, mActivity.getString(R.string.new_tab));
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 setFavicon(tab, null);
599 }
600 }
601
602 /**
603 * Updates the lock-icon image in the title-bar.
604 */
605 private void updateLockIconImage(int lockIconType) {
606 Drawable d = null;
607 if (lockIconType == Tab.LOCK_ICON_SECURE) {
608 d = mSecLockIcon;
609 } else if (lockIconType == Tab.LOCK_ICON_MIXED) {
610 d = mMixLockIcon;
611 }
Michael Kolb66706532010-12-12 19:50:22 -0800612 getEmbeddedTitleBar().setLock(d);
613 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 }
615
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800617 public void setUrlTitle(Tab tab, String url, String title) {
618 if (TextUtils.isEmpty(title)) {
619 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800620 }
Michael Kolb66706532010-12-12 19:50:22 -0800621 if (tab.isInVoiceSearchMode()) return;
622 if (tab.inForeground()) {
623 getEmbeddedTitleBar().setDisplayTitle(url);
624 getFakeTitleBar().setDisplayTitle(url);
625 }
626 }
627
628 // Set the favicon in the title bar.
629 @Override
630 public void setFavicon(Tab tab, Bitmap icon) {
631 getEmbeddedTitleBar().setFavicon(icon);
632 getFakeTitleBar().setFavicon(icon);
Michael Kolb8233fac2010-10-26 16:08:53 -0700633 }
634
635 @Override
636 public void onActionModeFinished(boolean inLoad) {
637 if (inLoad) {
638 // the titlebar was removed when the CAB was shown
639 // if the page is loading, show it again
640 showFakeTitleBar();
641 }
642 }
643
Michael Kolb66706532010-12-12 19:50:22 -0800644 // active tabs page
645
646 public void showActiveTabsPage() {
647 }
648
649 /**
650 * Remove the active tabs page.
651 */
652 public void removeActiveTabsPage() {
653 }
654
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 // menu handling callbacks
656
657 @Override
658 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 }
660
661 @Override
662 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 }
664
665 @Override
666 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700667 }
668
669 @Override
670 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 }
672
673 @Override
674 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700675 }
676
677 @Override
678 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700679 }
680
681 // error console
682
683 @Override
684 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
685 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
686 if (flag) {
687 // Setting the show state of the console will cause it's the layout
688 // to be inflated.
689 if (errorConsole.numberOfErrors() > 0) {
690 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
691 } else {
692 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
693 }
694 if (errorConsole.getParent() != null) {
695 mErrorConsoleContainer.removeView(errorConsole);
696 }
697 // Now we can add it to the main view.
698 mErrorConsoleContainer.addView(errorConsole,
699 new LinearLayout.LayoutParams(
700 ViewGroup.LayoutParams.MATCH_PARENT,
701 ViewGroup.LayoutParams.WRAP_CONTENT));
702 } else {
703 mErrorConsoleContainer.removeView(errorConsole);
704 }
705 }
706
707 private void setStatusBarVisibility(boolean visible) {
708 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
709 mActivity.getWindow().setFlags(flag,
710 WindowManager.LayoutParams.FLAG_FULLSCREEN);
711 }
712
713 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700714 public void onPrepareOptionsMenu(Menu menu) {
Michael Kolb66706532010-12-12 19:50:22 -0800715 final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
716 newtab.setEnabled(mUiController.getTabControl().canCreateNewTab());
Michael Kolb8233fac2010-10-26 16:08:53 -0700717 }
718
719 // -------------------------------------------------------------------------
720 // Helper function for WebChromeClient
721 // -------------------------------------------------------------------------
722
723 @Override
724 public Bitmap getDefaultVideoPoster() {
725 if (mDefaultVideoPoster == null) {
726 mDefaultVideoPoster = BitmapFactory.decodeResource(
727 mActivity.getResources(), R.drawable.default_video_poster);
728 }
729 return mDefaultVideoPoster;
730 }
731
732 @Override
733 public View getVideoLoadingProgressView() {
734 if (mVideoProgressView == null) {
735 LayoutInflater inflater = LayoutInflater.from(mActivity);
736 mVideoProgressView = inflater.inflate(
737 R.layout.video_loading_progress, null);
738 }
739 return mVideoProgressView;
740 }
741
Michael Kolb843510f2010-12-09 10:51:49 -0800742 @Override
743 public void showMaxTabsWarning() {
744 Toast warning = Toast.makeText(mActivity,
745 mActivity.getString(R.string.max_tabs_warning),
746 Toast.LENGTH_SHORT);
747 warning.show();
748 }
749
Michael Kolb8233fac2010-10-26 16:08:53 -0700750}