blob: 1e9038d6f9a281b86aa7c6199e6605f7bcfb6bc5 [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 }
235
Michael Kolbcfa3af52010-12-14 10:36:11 -0800236 Tab getActiveTab() {
237 return mActiveTab;
238 }
239
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800241 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800242 }
243
244 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700245 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800246 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800248 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 }
251
252 @Override
253 public void detachTab(Tab tab) {
254 removeTabFromContentView(tab);
255 }
256
257 @Override
258 public void attachTab(Tab tab) {
259 attachTabToContentView(tab);
260 }
261
262 private void attachTabToContentView(Tab tab) {
263 if (tab.getWebView() == null) {
264 return;
265 }
266 View container = tab.getViewContainer();
267 WebView mainView = tab.getWebView();
268 // Attach the WebView to the container and then attach the
269 // container to the content view.
270 FrameLayout wrapper =
271 (FrameLayout) container.findViewById(R.id.webview_wrapper);
272 ViewGroup parent = (ViewGroup) mainView.getParent();
273 if (parent != wrapper) {
274 if (parent != null) {
275 Log.w(LOGTAG, "mMainView already has a parent in"
276 + " attachTabToContentView!");
277 parent.removeView(mainView);
278 }
279 wrapper.addView(mainView);
280 } else {
281 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
282 + " attachTabToContentView!");
283 }
284 parent = (ViewGroup) container.getParent();
285 if (parent != mContentView) {
286 if (parent != null) {
287 Log.w(LOGTAG, "mContainer already has a parent in"
288 + " attachTabToContentView!");
289 parent.removeView(container);
290 }
291 mContentView.addView(container, COVER_SCREEN_PARAMS);
292 } else {
293 Log.w(LOGTAG, "mContainer is already attached to content in"
294 + " attachTabToContentView!");
295 }
296 mUiController.attachSubWindow(tab);
297 }
298
299 private void removeTabFromContentView(Tab tab) {
300 // Remove the container that contains the main WebView.
301 WebView mainView = tab.getWebView();
302 View container = tab.getViewContainer();
303 if (mainView == null) {
304 return;
305 }
306 // Remove the container from the content and then remove the
307 // WebView from the container. This will trigger a focus change
308 // needed by WebView.
309 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 }
319 mainView.setEmbeddedTitleBar(null);
320 }
321
Michael Kolba713ec82010-11-29 17:27:06 -0800322 @Override
323 public void onSetWebView(Tab tab, WebView webView) {
324 View container = tab.getViewContainer();
325 if (container == null) {
326 // The tab consists of a container view, which contains the main
327 // WebView, as well as any other UI elements associated with the tab.
328 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
329 null);
330 tab.setViewContainer(container);
331 }
332 if (tab.getWebView() != webView) {
333 // Just remove the old one.
334 FrameLayout wrapper =
335 (FrameLayout) container.findViewById(R.id.webview_wrapper);
336 wrapper.removeView(tab.getWebView());
337 }
338 }
339
Michael Kolb8233fac2010-10-26 16:08:53 -0700340 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800341 * create a sub window container and webview for the tab
342 * Note: this methods operates through side-effects for now
343 * it sets both the subView and subViewContainer for the given tab
344 * @param tab tab to create the sub window for
345 * @param subView webview to be set as a subwindow for the tab
346 */
347 @Override
348 public void createSubWindow(Tab tab, WebView subView) {
349 View subViewContainer = mActivity.getLayoutInflater().inflate(
350 R.layout.browser_subwindow, null);
351 ViewGroup inner = (ViewGroup) subViewContainer
352 .findViewById(R.id.inner_container);
353 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
354 LayoutParams.MATCH_PARENT));
355 final ImageButton cancel = (ImageButton) subViewContainer
356 .findViewById(R.id.subwindow_close);
357 final WebView cancelSubView = subView;
358 cancel.setOnClickListener(new OnClickListener() {
359 public void onClick(View v) {
360 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
361 }
362 });
363 tab.setSubWebView(subView);
364 tab.setSubViewContainer(subViewContainer);
365 }
366
367 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700368 * Remove the sub window from the content view.
369 */
370 @Override
371 public void removeSubWindow(View subviewContainer) {
372 mContentView.removeView(subviewContainer);
373 mUiController.endActionMode();
374 }
375
376 /**
377 * Attach the sub window to the content view.
378 */
379 @Override
380 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800381 if (container.getParent() != null) {
382 // already attached, remove first
383 ((ViewGroup) container.getParent()).removeView(container);
384 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700385 mContentView.addView(container, COVER_SCREEN_PARAMS);
386 }
387
388 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800389 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700390 WebView mainView = mUiController.getCurrentWebView();
391 // if there is no current WebView, don't show the faked title bar;
392 if (mainView == null) {
393 return;
394 }
395 // Do not need to check for null, since the current tab will have
396 // at least a main WebView, or we would have returned above.
397 if (mUiController.isInCustomActionMode()) {
398 // Do not show the fake title bar, while a custom ActionMode
399 // (i.e. find or select) is showing.
400 return;
401 }
Michael Kolb66706532010-12-12 19:50:22 -0800402 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700403 }
404 }
405
Michael Kolb66706532010-12-12 19:50:22 -0800406 protected abstract void attachFakeTitleBar(WebView mainView);
407
408 protected abstract void hideFakeTitleBar();
409
410 protected abstract boolean isFakeTitleBarShowing();
411
412 protected abstract TitleBarBase getFakeTitleBar();
413
414 protected abstract TitleBarBase getEmbeddedTitleBar();
415
416 @Override
417 public void showVoiceTitleBar(String title) {
418 getEmbeddedTitleBar().setInVoiceMode(true);
419 getEmbeddedTitleBar().setDisplayTitle(title);
420 getFakeTitleBar().setInVoiceMode(true);
421 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700422 }
423
Michael Kolb66706532010-12-12 19:50:22 -0800424 @Override
425 public void revertVoiceTitleBar(Tab tab) {
426 getEmbeddedTitleBar().setInVoiceMode(false);
427 String url = tab.getCurrentUrl();
428 getEmbeddedTitleBar().setDisplayTitle(url);
429 getFakeTitleBar().setInVoiceMode(false);
430 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 }
432
433 @Override
434 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800435 if (mComboView != null) {
436 return;
437 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700438 mComboView = new CombinedBookmarkHistoryView(mActivity,
439 mUiController,
440 startWithHistory ?
441 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
442 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
443 extras);
Michael Kolb66706532010-12-12 19:50:22 -0800444 getEmbeddedTitleBar().setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700445 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800446 dismissIME();
447 if (mActiveTab != null) {
448 WebView web = mActiveTab.getWebView();
449 mActiveTab.putInBackground();
450 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700451 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
452 }
453
454 /**
455 * dismiss the ComboPage
456 */
457 @Override
458 public void hideComboView() {
459 if (mComboView != null) {
460 mContentView.removeView(mComboView);
Michael Kolb66706532010-12-12 19:50:22 -0800461 getEmbeddedTitleBar().setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700462 mComboView = null;
463 }
Michael Kolb3a696282010-12-05 13:23:24 -0800464 if (mActiveTab != null) {
465 mActiveTab.putInForeground();
466 }
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
527 @Override
528 public void resetTitleAndRevertLockIcon(Tab tab) {
529 tab.revertLockIcon();
530 updateLockIconToLatest(tab);
531 resetTitleIconAndProgress(tab);
532 }
533
534 /**
535 * Resets the lock icon. This method is called when we start a new load and
536 * know the url to be loaded.
537 */
538 private void resetLockIcon(Tab tab, String url) {
539 // Save the lock-icon state (we revert to it if the load gets cancelled)
540 tab.resetLockIcon(url);
541 updateLockIconImage(Tab.LOCK_ICON_UNSECURE);
542 }
543
544 /**
545 * Update the lock icon to correspond to our latest state.
546 */
Michael Kolb66706532010-12-12 19:50:22 -0800547 protected void updateLockIconToLatest(Tab t) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700548 if (t != null) {
549 updateLockIconImage(t.getLockIconType());
550 }
551 }
552
553 /**
554 * Reset the title, favicon, and progress.
555 */
Michael Kolb66706532010-12-12 19:50:22 -0800556 protected void resetTitleIconAndProgress(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700557 WebView current = tab.getWebView();
558 if (current == null) {
559 return;
560 }
Michael Kolb41d3b942010-12-05 11:35:20 -0800561 resetTitleAndIcon(tab, current);
Michael Kolb8233fac2010-10-26 16:08:53 -0700562 int progress = current.getProgress();
563 current.getWebChromeClient().onProgressChanged(current, progress);
564 }
565
566 @Override
567 public void resetTitleAndIcon(Tab tab) {
568 WebView current = tab.getWebView();
569 if (current != null) {
Michael Kolb41d3b942010-12-05 11:35:20 -0800570 resetTitleAndIcon(tab, current);
Michael Kolb8233fac2010-10-26 16:08:53 -0700571 }
572 }
573
574 // Reset the title and the icon based on the given item.
Michael Kolb41d3b942010-12-05 11:35:20 -0800575 private void resetTitleAndIcon(Tab tab, WebView view) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700576 WebHistoryItem item = view.copyBackForwardList().getCurrentItem();
Michael Kolb8233fac2010-10-26 16:08:53 -0700577 if (item != null) {
578 setUrlTitle(tab, item.getUrl(), item.getTitle());
579 setFavicon(tab, item.getFavicon());
580 } else {
John Reckef074262010-12-02 16:09:14 -0800581 setUrlTitle(tab, null, mActivity.getString(R.string.new_tab));
Michael Kolb8233fac2010-10-26 16:08:53 -0700582 setFavicon(tab, null);
583 }
584 }
585
586 /**
587 * Updates the lock-icon image in the title-bar.
588 */
589 private void updateLockIconImage(int lockIconType) {
590 Drawable d = null;
591 if (lockIconType == Tab.LOCK_ICON_SECURE) {
592 d = mSecLockIcon;
593 } else if (lockIconType == Tab.LOCK_ICON_MIXED) {
594 d = mMixLockIcon;
595 }
Michael Kolb66706532010-12-12 19:50:22 -0800596 getEmbeddedTitleBar().setLock(d);
597 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 }
599
Michael Kolb8233fac2010-10-26 16:08:53 -0700600 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800601 public void setUrlTitle(Tab tab, String url, String title) {
602 if (TextUtils.isEmpty(title)) {
603 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800604 }
Michael Kolb66706532010-12-12 19:50:22 -0800605 if (tab.isInVoiceSearchMode()) return;
606 if (tab.inForeground()) {
607 getEmbeddedTitleBar().setDisplayTitle(url);
608 getFakeTitleBar().setDisplayTitle(url);
609 }
610 }
611
612 // Set the favicon in the title bar.
613 @Override
614 public void setFavicon(Tab tab, Bitmap icon) {
615 getEmbeddedTitleBar().setFavicon(icon);
616 getFakeTitleBar().setFavicon(icon);
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 }
618
619 @Override
620 public void onActionModeFinished(boolean inLoad) {
621 if (inLoad) {
622 // the titlebar was removed when the CAB was shown
623 // if the page is loading, show it again
624 showFakeTitleBar();
625 }
626 }
627
Michael Kolb66706532010-12-12 19:50:22 -0800628 // active tabs page
629
630 public void showActiveTabsPage() {
631 }
632
633 /**
634 * Remove the active tabs page.
635 */
636 public void removeActiveTabsPage() {
637 }
638
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 // menu handling callbacks
640
641 @Override
642 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700643 }
644
645 @Override
646 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700647 }
648
649 @Override
650 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 }
652
653 @Override
654 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 }
656
657 @Override
658 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 }
660
661 @Override
662 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 }
664
665 // error console
666
667 @Override
668 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
669 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
670 if (flag) {
671 // Setting the show state of the console will cause it's the layout
672 // to be inflated.
673 if (errorConsole.numberOfErrors() > 0) {
674 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
675 } else {
676 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
677 }
678 if (errorConsole.getParent() != null) {
679 mErrorConsoleContainer.removeView(errorConsole);
680 }
681 // Now we can add it to the main view.
682 mErrorConsoleContainer.addView(errorConsole,
683 new LinearLayout.LayoutParams(
684 ViewGroup.LayoutParams.MATCH_PARENT,
685 ViewGroup.LayoutParams.WRAP_CONTENT));
686 } else {
687 mErrorConsoleContainer.removeView(errorConsole);
688 }
689 }
690
691 private void setStatusBarVisibility(boolean visible) {
692 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
693 mActivity.getWindow().setFlags(flag,
694 WindowManager.LayoutParams.FLAG_FULLSCREEN);
695 }
696
697 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700698 public void onPrepareOptionsMenu(Menu menu) {
Michael Kolb66706532010-12-12 19:50:22 -0800699 final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
700 newtab.setEnabled(mUiController.getTabControl().canCreateNewTab());
Michael Kolb8233fac2010-10-26 16:08:53 -0700701 }
702
703 // -------------------------------------------------------------------------
704 // Helper function for WebChromeClient
705 // -------------------------------------------------------------------------
706
707 @Override
708 public Bitmap getDefaultVideoPoster() {
709 if (mDefaultVideoPoster == null) {
710 mDefaultVideoPoster = BitmapFactory.decodeResource(
711 mActivity.getResources(), R.drawable.default_video_poster);
712 }
713 return mDefaultVideoPoster;
714 }
715
716 @Override
717 public View getVideoLoadingProgressView() {
718 if (mVideoProgressView == null) {
719 LayoutInflater inflater = LayoutInflater.from(mActivity);
720 mVideoProgressView = inflater.inflate(
721 R.layout.video_loading_progress, null);
722 }
723 return mVideoProgressView;
724 }
725
Michael Kolb843510f2010-12-09 10:51:49 -0800726 @Override
727 public void showMaxTabsWarning() {
728 Toast warning = Toast.makeText(mActivity,
729 mActivity.getString(R.string.max_tabs_warning),
730 Toast.LENGTH_SHORT);
731 warning.show();
732 }
733
Michael Kolb8233fac2010-10-26 16:08:53 -0700734}