blob: 5ccfdda8d89c5910403a4eaada246ed01741e7d2 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
20
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
27import android.os.Bundle;
28import android.text.TextUtils;
29import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.view.Gravity;
31import android.view.LayoutInflater;
32import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080034import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080036import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080038import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.webkit.WebView;
41import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.widget.LinearLayout;
44import android.widget.Toast;
45
Michael Kolb1bf23132010-11-19 12:55:12 -080046import java.util.List;
47
Michael Kolb8233fac2010-10-26 16:08:53 -070048/**
49 * UI interface definitions
50 */
Michael Kolb66706532010-12-12 19:50:22 -080051public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070052
53 private static final String LOGTAG = "BaseUi";
54
Michael Kolb66706532010-12-12 19:50:22 -080055 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070056 new FrameLayout.LayoutParams(
57 ViewGroup.LayoutParams.MATCH_PARENT,
58 ViewGroup.LayoutParams.MATCH_PARENT);
59
Michael Kolb66706532010-12-12 19:50:22 -080060 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070061 new FrameLayout.LayoutParams(
62 ViewGroup.LayoutParams.MATCH_PARENT,
63 ViewGroup.LayoutParams.MATCH_PARENT,
64 Gravity.CENTER);
65
66 Activity mActivity;
67 UiController mUiController;
68 TabControl mTabControl;
Michael Kolb77df4562010-11-19 14:49:34 -080069 private Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080070 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070071
72 private Drawable mSecLockIcon;
73 private Drawable mMixLockIcon;
74
Michael Kolb8233fac2010-10-26 16:08:53 -070075 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080076 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070077 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070078
79 private View mCustomView;
80 private WebChromeClient.CustomViewCallback mCustomViewCallback;
81
82 private CombinedBookmarkHistoryView mComboView;
83
84 private LinearLayout mErrorConsoleContainer = null;
85
86 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070087
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
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 Kolb8233fac2010-10-26 16:08:53 -0700187 }
188
189 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500190 public void bookmarkedStatusHasChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800191 // no op in base case
Leon Scroggins4cd97792010-12-03 15:31:56 -0500192 }
193
194 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700195 public void onPageStopped(Tab tab) {
196 cancelStopToast();
197 if (tab.inForeground()) {
198 mStopToast = Toast
199 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
200 mStopToast.show();
201 }
202 }
203
204 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800205 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800206 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800207 }
208
209 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700210 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 }
212
213 @Override
214 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800215 if ((tab != mActiveTab) && (mActiveTab != null)) {
216 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 }
Michael Kolb77df4562010-11-19 14:49:34 -0800218 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 attachTabToContentView(tab);
220 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800221 onTabDataChanged(tab);
222 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 }
224
Michael Kolbcfa3af52010-12-14 10:36:11 -0800225 Tab getActiveTab() {
226 return mActiveTab;
227 }
228
Michael Kolb8233fac2010-10-26 16:08:53 -0700229 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800230 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800231 }
232
233 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800235 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800237 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700239 }
240
241 @Override
242 public void detachTab(Tab tab) {
243 removeTabFromContentView(tab);
244 }
245
246 @Override
247 public void attachTab(Tab tab) {
248 attachTabToContentView(tab);
249 }
250
251 private void attachTabToContentView(Tab tab) {
252 if (tab.getWebView() == null) {
253 return;
254 }
255 View container = tab.getViewContainer();
256 WebView mainView = tab.getWebView();
257 // Attach the WebView to the container and then attach the
258 // container to the content view.
259 FrameLayout wrapper =
260 (FrameLayout) container.findViewById(R.id.webview_wrapper);
261 ViewGroup parent = (ViewGroup) mainView.getParent();
262 if (parent != wrapper) {
263 if (parent != null) {
264 Log.w(LOGTAG, "mMainView already has a parent in"
265 + " attachTabToContentView!");
266 parent.removeView(mainView);
267 }
268 wrapper.addView(mainView);
269 } else {
270 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
271 + " attachTabToContentView!");
272 }
273 parent = (ViewGroup) container.getParent();
274 if (parent != mContentView) {
275 if (parent != null) {
276 Log.w(LOGTAG, "mContainer already has a parent in"
277 + " attachTabToContentView!");
278 parent.removeView(container);
279 }
280 mContentView.addView(container, COVER_SCREEN_PARAMS);
281 } else {
282 Log.w(LOGTAG, "mContainer is already attached to content in"
283 + " attachTabToContentView!");
284 }
285 mUiController.attachSubWindow(tab);
286 }
287
288 private void removeTabFromContentView(Tab tab) {
289 // Remove the container that contains the main WebView.
290 WebView mainView = tab.getWebView();
291 View container = tab.getViewContainer();
292 if (mainView == null) {
293 return;
294 }
295 // Remove the container from the content and then remove the
296 // WebView from the container. This will trigger a focus change
297 // needed by WebView.
298 FrameLayout wrapper =
299 (FrameLayout) container.findViewById(R.id.webview_wrapper);
300 wrapper.removeView(mainView);
301 mContentView.removeView(container);
302 mUiController.endActionMode();
303 mUiController.removeSubWindow(tab);
304 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
305 if (errorConsole != null) {
306 mErrorConsoleContainer.removeView(errorConsole);
307 }
308 mainView.setEmbeddedTitleBar(null);
309 }
310
Michael Kolba713ec82010-11-29 17:27:06 -0800311 @Override
312 public void onSetWebView(Tab tab, WebView webView) {
313 View container = tab.getViewContainer();
314 if (container == null) {
315 // The tab consists of a container view, which contains the main
316 // WebView, as well as any other UI elements associated with the tab.
317 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
318 null);
319 tab.setViewContainer(container);
320 }
321 if (tab.getWebView() != webView) {
322 // Just remove the old one.
323 FrameLayout wrapper =
324 (FrameLayout) container.findViewById(R.id.webview_wrapper);
325 wrapper.removeView(tab.getWebView());
326 }
327 }
328
Michael Kolb8233fac2010-10-26 16:08:53 -0700329 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800330 * create a sub window container and webview for the tab
331 * Note: this methods operates through side-effects for now
332 * it sets both the subView and subViewContainer for the given tab
333 * @param tab tab to create the sub window for
334 * @param subView webview to be set as a subwindow for the tab
335 */
336 @Override
337 public void createSubWindow(Tab tab, WebView subView) {
338 View subViewContainer = mActivity.getLayoutInflater().inflate(
339 R.layout.browser_subwindow, null);
340 ViewGroup inner = (ViewGroup) subViewContainer
341 .findViewById(R.id.inner_container);
342 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
343 LayoutParams.MATCH_PARENT));
344 final ImageButton cancel = (ImageButton) subViewContainer
345 .findViewById(R.id.subwindow_close);
346 final WebView cancelSubView = subView;
347 cancel.setOnClickListener(new OnClickListener() {
348 public void onClick(View v) {
349 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
350 }
351 });
352 tab.setSubWebView(subView);
353 tab.setSubViewContainer(subViewContainer);
354 }
355
356 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700357 * Remove the sub window from the content view.
358 */
359 @Override
360 public void removeSubWindow(View subviewContainer) {
361 mContentView.removeView(subviewContainer);
362 mUiController.endActionMode();
363 }
364
365 /**
366 * Attach the sub window to the content view.
367 */
368 @Override
369 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800370 if (container.getParent() != null) {
371 // already attached, remove first
372 ((ViewGroup) container.getParent()).removeView(container);
373 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700374 mContentView.addView(container, COVER_SCREEN_PARAMS);
375 }
376
377 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800378 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 WebView mainView = mUiController.getCurrentWebView();
380 // if there is no current WebView, don't show the faked title bar;
381 if (mainView == null) {
382 return;
383 }
384 // Do not need to check for null, since the current tab will have
385 // at least a main WebView, or we would have returned above.
386 if (mUiController.isInCustomActionMode()) {
387 // Do not show the fake title bar, while a custom ActionMode
388 // (i.e. find or select) is showing.
389 return;
390 }
Michael Kolb66706532010-12-12 19:50:22 -0800391 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700392 }
393 }
394
Michael Kolb66706532010-12-12 19:50:22 -0800395 protected abstract void attachFakeTitleBar(WebView mainView);
396
397 protected abstract void hideFakeTitleBar();
398
399 protected abstract boolean isFakeTitleBarShowing();
400
401 protected abstract TitleBarBase getFakeTitleBar();
402
403 protected abstract TitleBarBase getEmbeddedTitleBar();
404
405 @Override
406 public void showVoiceTitleBar(String title) {
407 getEmbeddedTitleBar().setInVoiceMode(true);
408 getEmbeddedTitleBar().setDisplayTitle(title);
409 getFakeTitleBar().setInVoiceMode(true);
410 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700411 }
412
Michael Kolb66706532010-12-12 19:50:22 -0800413 @Override
414 public void revertVoiceTitleBar(Tab tab) {
415 getEmbeddedTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800416 String url = tab.getUrl();
Michael Kolb66706532010-12-12 19:50:22 -0800417 getEmbeddedTitleBar().setDisplayTitle(url);
418 getFakeTitleBar().setInVoiceMode(false);
419 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700420 }
421
422 @Override
423 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800424 if (mComboView != null) {
425 return;
426 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700427 mComboView = new CombinedBookmarkHistoryView(mActivity,
428 mUiController,
429 startWithHistory ?
430 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
431 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
432 extras);
Michael Kolb66706532010-12-12 19:50:22 -0800433 getEmbeddedTitleBar().setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700434 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800435 dismissIME();
436 if (mActiveTab != null) {
437 WebView web = mActiveTab.getWebView();
438 mActiveTab.putInBackground();
439 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700440 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
441 }
442
443 /**
444 * dismiss the ComboPage
445 */
446 @Override
447 public void hideComboView() {
448 if (mComboView != null) {
449 mContentView.removeView(mComboView);
Michael Kolb66706532010-12-12 19:50:22 -0800450 getEmbeddedTitleBar().setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700451 mComboView = null;
452 }
Michael Kolb3a696282010-12-05 13:23:24 -0800453 if (mActiveTab != null) {
454 mActiveTab.putInForeground();
455 }
John Reckb3417f02011-01-14 11:01:05 -0800456 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700457 }
458
459 @Override
460 public void showCustomView(View view,
461 WebChromeClient.CustomViewCallback callback) {
462 // if a view already exists then immediately terminate the new one
463 if (mCustomView != null) {
464 callback.onCustomViewHidden();
465 return;
466 }
467
468 // Add the custom view to its container.
469 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
470 mCustomView = view;
471 mCustomViewCallback = callback;
472 // Hide the content view.
473 mContentView.setVisibility(View.GONE);
474 // Finally show the custom view container.
475 setStatusBarVisibility(false);
476 mCustomViewContainer.setVisibility(View.VISIBLE);
477 mCustomViewContainer.bringToFront();
478 }
479
480 @Override
481 public void onHideCustomView() {
482 if (mCustomView == null)
483 return;
484
485 // Hide the custom view.
486 mCustomView.setVisibility(View.GONE);
487 // Remove the custom view from its container.
488 mCustomViewContainer.removeView(mCustomView);
489 mCustomView = null;
490 mCustomViewContainer.setVisibility(View.GONE);
491 mCustomViewCallback.onCustomViewHidden();
492 // Show the content view.
493 setStatusBarVisibility(true);
494 mContentView.setVisibility(View.VISIBLE);
495 }
496
497 @Override
498 public boolean isCustomViewShowing() {
499 return mCustomView != null;
500 }
501
Michael Kolb66706532010-12-12 19:50:22 -0800502 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800503 if (mInputManager.isActive()) {
504 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
505 0);
506 }
507 }
508
Michael Kolb66706532010-12-12 19:50:22 -0800509 @Override
510 public boolean showsWeb() {
511 return mCustomView == null
512 && mComboView == null;
513 }
514
Michael Kolb8233fac2010-10-26 16:08:53 -0700515 // -------------------------------------------------------------------------
516
Michael Kolb8233fac2010-10-26 16:08:53 -0700517 /**
518 * Update the lock icon to correspond to our latest state.
519 */
Michael Kolb66706532010-12-12 19:50:22 -0800520 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800521 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700522 updateLockIconImage(t.getLockIconType());
523 }
524 }
525
526 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700527 * Updates the lock-icon image in the title-bar.
528 */
John Reck30c714c2010-12-16 17:30:34 -0800529 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700530 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800531 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700532 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800533 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700534 d = mMixLockIcon;
535 }
Michael Kolb66706532010-12-12 19:50:22 -0800536 getEmbeddedTitleBar().setLock(d);
537 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700538 }
539
John Reck30c714c2010-12-16 17:30:34 -0800540 protected void setUrlTitle(Tab tab) {
541 String url = tab.getUrl();
542 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800543 if (TextUtils.isEmpty(title)) {
544 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800545 }
Michael Kolb66706532010-12-12 19:50:22 -0800546 if (tab.isInVoiceSearchMode()) return;
547 if (tab.inForeground()) {
548 getEmbeddedTitleBar().setDisplayTitle(url);
549 getFakeTitleBar().setDisplayTitle(url);
550 }
551 }
552
553 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800554 protected void setFavicon(Tab tab) {
555 if (tab.inForeground()) {
556 Bitmap icon = tab.getFavicon();
557 getEmbeddedTitleBar().setFavicon(icon);
558 getFakeTitleBar().setFavicon(icon);
559 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700560 }
561
562 @Override
563 public void onActionModeFinished(boolean inLoad) {
564 if (inLoad) {
565 // the titlebar was removed when the CAB was shown
566 // if the page is loading, show it again
567 showFakeTitleBar();
568 }
569 }
570
Michael Kolb66706532010-12-12 19:50:22 -0800571 // active tabs page
572
573 public void showActiveTabsPage() {
574 }
575
576 /**
577 * Remove the active tabs page.
578 */
579 public void removeActiveTabsPage() {
580 }
581
Michael Kolb8233fac2010-10-26 16:08:53 -0700582 // menu handling callbacks
583
584 @Override
585 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700586 }
587
588 @Override
589 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700590 }
591
592 @Override
593 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700594 }
595
596 @Override
597 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 }
599
600 @Override
601 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 }
603
604 @Override
605 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 }
607
608 // error console
609
610 @Override
611 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
612 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
613 if (flag) {
614 // Setting the show state of the console will cause it's the layout
615 // to be inflated.
616 if (errorConsole.numberOfErrors() > 0) {
617 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
618 } else {
619 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
620 }
621 if (errorConsole.getParent() != null) {
622 mErrorConsoleContainer.removeView(errorConsole);
623 }
624 // Now we can add it to the main view.
625 mErrorConsoleContainer.addView(errorConsole,
626 new LinearLayout.LayoutParams(
627 ViewGroup.LayoutParams.MATCH_PARENT,
628 ViewGroup.LayoutParams.WRAP_CONTENT));
629 } else {
630 mErrorConsoleContainer.removeView(errorConsole);
631 }
632 }
633
634 private void setStatusBarVisibility(boolean visible) {
635 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
636 mActivity.getWindow().setFlags(flag,
637 WindowManager.LayoutParams.FLAG_FULLSCREEN);
638 }
639
Michael Kolb8233fac2010-10-26 16:08:53 -0700640 // -------------------------------------------------------------------------
641 // Helper function for WebChromeClient
642 // -------------------------------------------------------------------------
643
644 @Override
645 public Bitmap getDefaultVideoPoster() {
646 if (mDefaultVideoPoster == null) {
647 mDefaultVideoPoster = BitmapFactory.decodeResource(
648 mActivity.getResources(), R.drawable.default_video_poster);
649 }
650 return mDefaultVideoPoster;
651 }
652
653 @Override
654 public View getVideoLoadingProgressView() {
655 if (mVideoProgressView == null) {
656 LayoutInflater inflater = LayoutInflater.from(mActivity);
657 mVideoProgressView = inflater.inflate(
658 R.layout.video_loading_progress, null);
659 }
660 return mVideoProgressView;
661 }
662
Michael Kolb843510f2010-12-09 10:51:49 -0800663 @Override
664 public void showMaxTabsWarning() {
665 Toast warning = Toast.makeText(mActivity,
666 mActivity.getString(R.string.max_tabs_warning),
667 Toast.LENGTH_SHORT);
668 warning.show();
669 }
670
Michael Kolb8233fac2010-10-26 16:08:53 -0700671}