blob: 568a7e970aa25c2738446da6f5690bfda6365d78 [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 Kolb5a72f182011-01-13 20:35:06 -0800102 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700103 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 Kolb5a72f182011-01-13 20:35:06 -0800187 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 }
189
190 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500191 public void bookmarkedStatusHasChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800192 // no op in base case
Leon Scroggins4cd97792010-12-03 15:31:56 -0500193 }
194
195 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 public void onPageStopped(Tab tab) {
197 cancelStopToast();
198 if (tab.inForeground()) {
199 mStopToast = Toast
200 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
201 mStopToast.show();
202 }
203 }
204
205 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800206 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800207 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800208 }
209
210 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 }
213
214 @Override
215 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800216 if ((tab != mActiveTab) && (mActiveTab != null)) {
217 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 }
Michael Kolb77df4562010-11-19 14:49:34 -0800219 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 attachTabToContentView(tab);
221 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800222 onTabDataChanged(tab);
223 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800224 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
225 getEmbeddedTitleBar().setIncognitoMode(incognito);
226 getFakeTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 }
228
Michael Kolbcfa3af52010-12-14 10:36:11 -0800229 Tab getActiveTab() {
230 return mActiveTab;
231 }
232
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800234 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800235 }
236
237 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800239 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800241 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 }
244
245 @Override
246 public void detachTab(Tab tab) {
247 removeTabFromContentView(tab);
248 }
249
250 @Override
251 public void attachTab(Tab tab) {
252 attachTabToContentView(tab);
253 }
254
255 private void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800256 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 return;
258 }
259 View container = tab.getViewContainer();
260 WebView mainView = tab.getWebView();
261 // Attach the WebView to the container and then attach the
262 // container to the content view.
263 FrameLayout wrapper =
264 (FrameLayout) container.findViewById(R.id.webview_wrapper);
265 ViewGroup parent = (ViewGroup) mainView.getParent();
266 if (parent != wrapper) {
267 if (parent != null) {
268 Log.w(LOGTAG, "mMainView already has a parent in"
269 + " attachTabToContentView!");
270 parent.removeView(mainView);
271 }
272 wrapper.addView(mainView);
273 } else {
274 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
275 + " attachTabToContentView!");
276 }
277 parent = (ViewGroup) container.getParent();
278 if (parent != mContentView) {
279 if (parent != null) {
280 Log.w(LOGTAG, "mContainer already has a parent in"
281 + " attachTabToContentView!");
282 parent.removeView(container);
283 }
284 mContentView.addView(container, COVER_SCREEN_PARAMS);
285 } else {
286 Log.w(LOGTAG, "mContainer is already attached to content in"
287 + " attachTabToContentView!");
288 }
289 mUiController.attachSubWindow(tab);
290 }
291
292 private void removeTabFromContentView(Tab tab) {
293 // Remove the container that contains the main WebView.
294 WebView mainView = tab.getWebView();
295 View container = tab.getViewContainer();
296 if (mainView == null) {
297 return;
298 }
299 // Remove the container from the content and then remove the
300 // WebView from the container. This will trigger a focus change
301 // needed by WebView.
302 FrameLayout wrapper =
303 (FrameLayout) container.findViewById(R.id.webview_wrapper);
304 wrapper.removeView(mainView);
305 mContentView.removeView(container);
306 mUiController.endActionMode();
307 mUiController.removeSubWindow(tab);
308 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
309 if (errorConsole != null) {
310 mErrorConsoleContainer.removeView(errorConsole);
311 }
312 mainView.setEmbeddedTitleBar(null);
313 }
314
Michael Kolba713ec82010-11-29 17:27:06 -0800315 @Override
316 public void onSetWebView(Tab tab, WebView webView) {
317 View container = tab.getViewContainer();
318 if (container == null) {
319 // The tab consists of a container view, which contains the main
320 // WebView, as well as any other UI elements associated with the tab.
321 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
322 null);
323 tab.setViewContainer(container);
324 }
325 if (tab.getWebView() != webView) {
326 // Just remove the old one.
327 FrameLayout wrapper =
328 (FrameLayout) container.findViewById(R.id.webview_wrapper);
329 wrapper.removeView(tab.getWebView());
330 }
331 }
332
Michael Kolb8233fac2010-10-26 16:08:53 -0700333 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800334 * create a sub window container and webview for the tab
335 * Note: this methods operates through side-effects for now
336 * it sets both the subView and subViewContainer for the given tab
337 * @param tab tab to create the sub window for
338 * @param subView webview to be set as a subwindow for the tab
339 */
340 @Override
341 public void createSubWindow(Tab tab, WebView subView) {
342 View subViewContainer = mActivity.getLayoutInflater().inflate(
343 R.layout.browser_subwindow, null);
344 ViewGroup inner = (ViewGroup) subViewContainer
345 .findViewById(R.id.inner_container);
346 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
347 LayoutParams.MATCH_PARENT));
348 final ImageButton cancel = (ImageButton) subViewContainer
349 .findViewById(R.id.subwindow_close);
350 final WebView cancelSubView = subView;
351 cancel.setOnClickListener(new OnClickListener() {
352 public void onClick(View v) {
353 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
354 }
355 });
356 tab.setSubWebView(subView);
357 tab.setSubViewContainer(subViewContainer);
358 }
359
360 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700361 * Remove the sub window from the content view.
362 */
363 @Override
364 public void removeSubWindow(View subviewContainer) {
365 mContentView.removeView(subviewContainer);
366 mUiController.endActionMode();
367 }
368
369 /**
370 * Attach the sub window to the content view.
371 */
372 @Override
373 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800374 if (container.getParent() != null) {
375 // already attached, remove first
376 ((ViewGroup) container.getParent()).removeView(container);
377 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 mContentView.addView(container, COVER_SCREEN_PARAMS);
379 }
380
381 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800382 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700383 WebView mainView = mUiController.getCurrentWebView();
384 // if there is no current WebView, don't show the faked title bar;
385 if (mainView == null) {
386 return;
387 }
388 // Do not need to check for null, since the current tab will have
389 // at least a main WebView, or we would have returned above.
390 if (mUiController.isInCustomActionMode()) {
391 // Do not show the fake title bar, while a custom ActionMode
392 // (i.e. find or select) is showing.
393 return;
394 }
Michael Kolb66706532010-12-12 19:50:22 -0800395 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700396 }
397 }
398
Michael Kolb66706532010-12-12 19:50:22 -0800399 protected abstract void attachFakeTitleBar(WebView mainView);
400
401 protected abstract void hideFakeTitleBar();
402
403 protected abstract boolean isFakeTitleBarShowing();
404
405 protected abstract TitleBarBase getFakeTitleBar();
406
407 protected abstract TitleBarBase getEmbeddedTitleBar();
408
409 @Override
410 public void showVoiceTitleBar(String title) {
411 getEmbeddedTitleBar().setInVoiceMode(true);
412 getEmbeddedTitleBar().setDisplayTitle(title);
413 getFakeTitleBar().setInVoiceMode(true);
414 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700415 }
416
Michael Kolb66706532010-12-12 19:50:22 -0800417 @Override
418 public void revertVoiceTitleBar(Tab tab) {
419 getEmbeddedTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800420 String url = tab.getUrl();
Michael Kolb66706532010-12-12 19:50:22 -0800421 getEmbeddedTitleBar().setDisplayTitle(url);
422 getFakeTitleBar().setInVoiceMode(false);
423 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700424 }
425
426 @Override
427 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800428 if (mComboView != null) {
429 return;
430 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 mComboView = new CombinedBookmarkHistoryView(mActivity,
432 mUiController,
433 startWithHistory ?
434 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
435 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
436 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800437 FrameLayout wrapper =
438 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
439 wrapper.setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700440 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800441 dismissIME();
442 if (mActiveTab != null) {
443 WebView web = mActiveTab.getWebView();
444 mActiveTab.putInBackground();
445 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700446 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
447 }
448
449 /**
450 * dismiss the ComboPage
451 */
452 @Override
453 public void hideComboView() {
454 if (mComboView != null) {
455 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800456 FrameLayout wrapper =
457 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
458 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700459 mComboView = null;
460 }
Michael Kolb3a696282010-12-05 13:23:24 -0800461 if (mActiveTab != null) {
462 mActiveTab.putInForeground();
463 }
John Reckb3417f02011-01-14 11:01:05 -0800464 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700465 }
466
467 @Override
468 public void showCustomView(View view,
469 WebChromeClient.CustomViewCallback callback) {
470 // if a view already exists then immediately terminate the new one
471 if (mCustomView != null) {
472 callback.onCustomViewHidden();
473 return;
474 }
475
476 // Add the custom view to its container.
477 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
478 mCustomView = view;
479 mCustomViewCallback = callback;
480 // Hide the content view.
481 mContentView.setVisibility(View.GONE);
482 // Finally show the custom view container.
483 setStatusBarVisibility(false);
484 mCustomViewContainer.setVisibility(View.VISIBLE);
485 mCustomViewContainer.bringToFront();
486 }
487
488 @Override
489 public void onHideCustomView() {
490 if (mCustomView == null)
491 return;
492
493 // Hide the custom view.
494 mCustomView.setVisibility(View.GONE);
495 // Remove the custom view from its container.
496 mCustomViewContainer.removeView(mCustomView);
497 mCustomView = null;
498 mCustomViewContainer.setVisibility(View.GONE);
499 mCustomViewCallback.onCustomViewHidden();
500 // Show the content view.
501 setStatusBarVisibility(true);
502 mContentView.setVisibility(View.VISIBLE);
503 }
504
505 @Override
506 public boolean isCustomViewShowing() {
507 return mCustomView != null;
508 }
509
Michael Kolb66706532010-12-12 19:50:22 -0800510 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800511 if (mInputManager.isActive()) {
512 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
513 0);
514 }
515 }
516
Michael Kolb66706532010-12-12 19:50:22 -0800517 @Override
518 public boolean showsWeb() {
519 return mCustomView == null
520 && mComboView == null;
521 }
522
Michael Kolb8233fac2010-10-26 16:08:53 -0700523 // -------------------------------------------------------------------------
524
Michael Kolb5a72f182011-01-13 20:35:06 -0800525 protected void updateNavigationState(Tab tab) {
526 }
527
Michael Kolb8233fac2010-10-26 16:08:53 -0700528 /**
529 * Update the lock icon to correspond to our latest state.
530 */
Michael Kolb66706532010-12-12 19:50:22 -0800531 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800532 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700533 updateLockIconImage(t.getLockIconType());
534 }
535 }
536
537 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700538 * Updates the lock-icon image in the title-bar.
539 */
John Reck30c714c2010-12-16 17:30:34 -0800540 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700541 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800542 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700543 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800544 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 d = mMixLockIcon;
546 }
Michael Kolb66706532010-12-12 19:50:22 -0800547 getEmbeddedTitleBar().setLock(d);
548 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700549 }
550
John Reck30c714c2010-12-16 17:30:34 -0800551 protected void setUrlTitle(Tab tab) {
552 String url = tab.getUrl();
553 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800554 if (TextUtils.isEmpty(title)) {
555 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800556 }
Michael Kolb66706532010-12-12 19:50:22 -0800557 if (tab.isInVoiceSearchMode()) return;
558 if (tab.inForeground()) {
559 getEmbeddedTitleBar().setDisplayTitle(url);
560 getFakeTitleBar().setDisplayTitle(url);
561 }
562 }
563
564 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800565 protected void setFavicon(Tab tab) {
566 if (tab.inForeground()) {
567 Bitmap icon = tab.getFavicon();
568 getEmbeddedTitleBar().setFavicon(icon);
569 getFakeTitleBar().setFavicon(icon);
570 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700571 }
572
573 @Override
574 public void onActionModeFinished(boolean inLoad) {
575 if (inLoad) {
576 // the titlebar was removed when the CAB was shown
577 // if the page is loading, show it again
578 showFakeTitleBar();
579 }
580 }
581
Michael Kolb66706532010-12-12 19:50:22 -0800582 // active tabs page
583
584 public void showActiveTabsPage() {
585 }
586
587 /**
588 * Remove the active tabs page.
589 */
590 public void removeActiveTabsPage() {
591 }
592
Michael Kolb8233fac2010-10-26 16:08:53 -0700593 // menu handling callbacks
594
595 @Override
596 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700597 }
598
599 @Override
600 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 }
602
603 @Override
604 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700605 }
606
607 @Override
608 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 }
610
611 @Override
612 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700613 }
614
615 @Override
616 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 }
618
619 // error console
620
621 @Override
622 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
623 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
624 if (flag) {
625 // Setting the show state of the console will cause it's the layout
626 // to be inflated.
627 if (errorConsole.numberOfErrors() > 0) {
628 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
629 } else {
630 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
631 }
632 if (errorConsole.getParent() != null) {
633 mErrorConsoleContainer.removeView(errorConsole);
634 }
635 // Now we can add it to the main view.
636 mErrorConsoleContainer.addView(errorConsole,
637 new LinearLayout.LayoutParams(
638 ViewGroup.LayoutParams.MATCH_PARENT,
639 ViewGroup.LayoutParams.WRAP_CONTENT));
640 } else {
641 mErrorConsoleContainer.removeView(errorConsole);
642 }
643 }
644
645 private void setStatusBarVisibility(boolean visible) {
646 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
647 mActivity.getWindow().setFlags(flag,
648 WindowManager.LayoutParams.FLAG_FULLSCREEN);
649 }
650
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 // -------------------------------------------------------------------------
652 // Helper function for WebChromeClient
653 // -------------------------------------------------------------------------
654
655 @Override
656 public Bitmap getDefaultVideoPoster() {
657 if (mDefaultVideoPoster == null) {
658 mDefaultVideoPoster = BitmapFactory.decodeResource(
659 mActivity.getResources(), R.drawable.default_video_poster);
660 }
661 return mDefaultVideoPoster;
662 }
663
664 @Override
665 public View getVideoLoadingProgressView() {
666 if (mVideoProgressView == null) {
667 LayoutInflater inflater = LayoutInflater.from(mActivity);
668 mVideoProgressView = inflater.inflate(
669 R.layout.video_loading_progress, null);
670 }
671 return mVideoProgressView;
672 }
673
Michael Kolb843510f2010-12-09 10:51:49 -0800674 @Override
675 public void showMaxTabsWarning() {
676 Toast warning = Toast.makeText(mActivity,
677 mActivity.getString(R.string.max_tabs_warning),
678 Toast.LENGTH_SHORT);
679 warning.show();
680 }
681
Michael Kolb8233fac2010-10-26 16:08:53 -0700682}