blob: 20652cfa54ee8ff379f86f53e45782726ba862df [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);
Michael Kolb8233fac2010-10-26 16:08:53 -0700224 }
225
Michael Kolbcfa3af52010-12-14 10:36:11 -0800226 Tab getActiveTab() {
227 return mActiveTab;
228 }
229
Michael Kolb8233fac2010-10-26 16:08:53 -0700230 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800231 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800232 }
233
234 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800236 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700237 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800238 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700239 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 }
241
242 @Override
243 public void detachTab(Tab tab) {
244 removeTabFromContentView(tab);
245 }
246
247 @Override
248 public void attachTab(Tab tab) {
249 attachTabToContentView(tab);
250 }
251
252 private void attachTabToContentView(Tab tab) {
253 if (tab.getWebView() == null) {
254 return;
255 }
256 View container = tab.getViewContainer();
257 WebView mainView = tab.getWebView();
258 // Attach the WebView to the container and then attach the
259 // container to the content view.
260 FrameLayout wrapper =
261 (FrameLayout) container.findViewById(R.id.webview_wrapper);
262 ViewGroup parent = (ViewGroup) mainView.getParent();
263 if (parent != wrapper) {
264 if (parent != null) {
265 Log.w(LOGTAG, "mMainView already has a parent in"
266 + " attachTabToContentView!");
267 parent.removeView(mainView);
268 }
269 wrapper.addView(mainView);
270 } else {
271 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
272 + " attachTabToContentView!");
273 }
274 parent = (ViewGroup) container.getParent();
275 if (parent != mContentView) {
276 if (parent != null) {
277 Log.w(LOGTAG, "mContainer already has a parent in"
278 + " attachTabToContentView!");
279 parent.removeView(container);
280 }
281 mContentView.addView(container, COVER_SCREEN_PARAMS);
282 } else {
283 Log.w(LOGTAG, "mContainer is already attached to content in"
284 + " attachTabToContentView!");
285 }
286 mUiController.attachSubWindow(tab);
287 }
288
289 private void removeTabFromContentView(Tab tab) {
290 // Remove the container that contains the main WebView.
291 WebView mainView = tab.getWebView();
292 View container = tab.getViewContainer();
293 if (mainView == null) {
294 return;
295 }
296 // Remove the container from the content and then remove the
297 // WebView from the container. This will trigger a focus change
298 // needed by WebView.
299 FrameLayout wrapper =
300 (FrameLayout) container.findViewById(R.id.webview_wrapper);
301 wrapper.removeView(mainView);
302 mContentView.removeView(container);
303 mUiController.endActionMode();
304 mUiController.removeSubWindow(tab);
305 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
306 if (errorConsole != null) {
307 mErrorConsoleContainer.removeView(errorConsole);
308 }
309 mainView.setEmbeddedTitleBar(null);
310 }
311
Michael Kolba713ec82010-11-29 17:27:06 -0800312 @Override
313 public void onSetWebView(Tab tab, WebView webView) {
314 View container = tab.getViewContainer();
315 if (container == null) {
316 // The tab consists of a container view, which contains the main
317 // WebView, as well as any other UI elements associated with the tab.
318 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
319 null);
320 tab.setViewContainer(container);
321 }
322 if (tab.getWebView() != webView) {
323 // Just remove the old one.
324 FrameLayout wrapper =
325 (FrameLayout) container.findViewById(R.id.webview_wrapper);
326 wrapper.removeView(tab.getWebView());
327 }
328 }
329
Michael Kolb8233fac2010-10-26 16:08:53 -0700330 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800331 * create a sub window container and webview for the tab
332 * Note: this methods operates through side-effects for now
333 * it sets both the subView and subViewContainer for the given tab
334 * @param tab tab to create the sub window for
335 * @param subView webview to be set as a subwindow for the tab
336 */
337 @Override
338 public void createSubWindow(Tab tab, WebView subView) {
339 View subViewContainer = mActivity.getLayoutInflater().inflate(
340 R.layout.browser_subwindow, null);
341 ViewGroup inner = (ViewGroup) subViewContainer
342 .findViewById(R.id.inner_container);
343 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
344 LayoutParams.MATCH_PARENT));
345 final ImageButton cancel = (ImageButton) subViewContainer
346 .findViewById(R.id.subwindow_close);
347 final WebView cancelSubView = subView;
348 cancel.setOnClickListener(new OnClickListener() {
349 public void onClick(View v) {
350 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
351 }
352 });
353 tab.setSubWebView(subView);
354 tab.setSubViewContainer(subViewContainer);
355 }
356
357 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700358 * Remove the sub window from the content view.
359 */
360 @Override
361 public void removeSubWindow(View subviewContainer) {
362 mContentView.removeView(subviewContainer);
363 mUiController.endActionMode();
364 }
365
366 /**
367 * Attach the sub window to the content view.
368 */
369 @Override
370 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800371 if (container.getParent() != null) {
372 // already attached, remove first
373 ((ViewGroup) container.getParent()).removeView(container);
374 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700375 mContentView.addView(container, COVER_SCREEN_PARAMS);
376 }
377
378 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800379 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 WebView mainView = mUiController.getCurrentWebView();
381 // if there is no current WebView, don't show the faked title bar;
382 if (mainView == null) {
383 return;
384 }
385 // Do not need to check for null, since the current tab will have
386 // at least a main WebView, or we would have returned above.
387 if (mUiController.isInCustomActionMode()) {
388 // Do not show the fake title bar, while a custom ActionMode
389 // (i.e. find or select) is showing.
390 return;
391 }
Michael Kolb66706532010-12-12 19:50:22 -0800392 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700393 }
394 }
395
Michael Kolb66706532010-12-12 19:50:22 -0800396 protected abstract void attachFakeTitleBar(WebView mainView);
397
398 protected abstract void hideFakeTitleBar();
399
400 protected abstract boolean isFakeTitleBarShowing();
401
402 protected abstract TitleBarBase getFakeTitleBar();
403
404 protected abstract TitleBarBase getEmbeddedTitleBar();
405
406 @Override
407 public void showVoiceTitleBar(String title) {
408 getEmbeddedTitleBar().setInVoiceMode(true);
409 getEmbeddedTitleBar().setDisplayTitle(title);
410 getFakeTitleBar().setInVoiceMode(true);
411 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700412 }
413
Michael Kolb66706532010-12-12 19:50:22 -0800414 @Override
415 public void revertVoiceTitleBar(Tab tab) {
416 getEmbeddedTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800417 String url = tab.getUrl();
Michael Kolb66706532010-12-12 19:50:22 -0800418 getEmbeddedTitleBar().setDisplayTitle(url);
419 getFakeTitleBar().setInVoiceMode(false);
420 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700421 }
422
423 @Override
424 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800425 if (mComboView != null) {
426 return;
427 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 mComboView = new CombinedBookmarkHistoryView(mActivity,
429 mUiController,
430 startWithHistory ?
431 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
432 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
433 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800434 FrameLayout wrapper =
435 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
436 wrapper.setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700437 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800438 dismissIME();
439 if (mActiveTab != null) {
440 WebView web = mActiveTab.getWebView();
441 mActiveTab.putInBackground();
442 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700443 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
444 }
445
446 /**
447 * dismiss the ComboPage
448 */
449 @Override
450 public void hideComboView() {
451 if (mComboView != null) {
452 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800453 FrameLayout wrapper =
454 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
455 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700456 mComboView = null;
457 }
Michael Kolb3a696282010-12-05 13:23:24 -0800458 if (mActiveTab != null) {
459 mActiveTab.putInForeground();
460 }
John Reckb3417f02011-01-14 11:01:05 -0800461 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700462 }
463
464 @Override
465 public void showCustomView(View view,
466 WebChromeClient.CustomViewCallback callback) {
467 // if a view already exists then immediately terminate the new one
468 if (mCustomView != null) {
469 callback.onCustomViewHidden();
470 return;
471 }
472
473 // Add the custom view to its container.
474 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
475 mCustomView = view;
476 mCustomViewCallback = callback;
477 // Hide the content view.
478 mContentView.setVisibility(View.GONE);
479 // Finally show the custom view container.
480 setStatusBarVisibility(false);
481 mCustomViewContainer.setVisibility(View.VISIBLE);
482 mCustomViewContainer.bringToFront();
483 }
484
485 @Override
486 public void onHideCustomView() {
487 if (mCustomView == null)
488 return;
489
490 // Hide the custom view.
491 mCustomView.setVisibility(View.GONE);
492 // Remove the custom view from its container.
493 mCustomViewContainer.removeView(mCustomView);
494 mCustomView = null;
495 mCustomViewContainer.setVisibility(View.GONE);
496 mCustomViewCallback.onCustomViewHidden();
497 // Show the content view.
498 setStatusBarVisibility(true);
499 mContentView.setVisibility(View.VISIBLE);
500 }
501
502 @Override
503 public boolean isCustomViewShowing() {
504 return mCustomView != null;
505 }
506
Michael Kolb66706532010-12-12 19:50:22 -0800507 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800508 if (mInputManager.isActive()) {
509 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
510 0);
511 }
512 }
513
Michael Kolb66706532010-12-12 19:50:22 -0800514 @Override
515 public boolean showsWeb() {
516 return mCustomView == null
517 && mComboView == null;
518 }
519
Michael Kolb8233fac2010-10-26 16:08:53 -0700520 // -------------------------------------------------------------------------
521
Michael Kolb5a72f182011-01-13 20:35:06 -0800522 protected void updateNavigationState(Tab tab) {
523 }
524
Michael Kolb8233fac2010-10-26 16:08:53 -0700525 /**
526 * Update the lock icon to correspond to our latest state.
527 */
Michael Kolb66706532010-12-12 19:50:22 -0800528 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800529 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700530 updateLockIconImage(t.getLockIconType());
531 }
532 }
533
534 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700535 * Updates the lock-icon image in the title-bar.
536 */
John Reck30c714c2010-12-16 17:30:34 -0800537 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700538 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800539 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700540 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800541 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700542 d = mMixLockIcon;
543 }
Michael Kolb66706532010-12-12 19:50:22 -0800544 getEmbeddedTitleBar().setLock(d);
545 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700546 }
547
John Reck30c714c2010-12-16 17:30:34 -0800548 protected void setUrlTitle(Tab tab) {
549 String url = tab.getUrl();
550 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800551 if (TextUtils.isEmpty(title)) {
552 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800553 }
Michael Kolb66706532010-12-12 19:50:22 -0800554 if (tab.isInVoiceSearchMode()) return;
555 if (tab.inForeground()) {
556 getEmbeddedTitleBar().setDisplayTitle(url);
557 getFakeTitleBar().setDisplayTitle(url);
558 }
559 }
560
561 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800562 protected void setFavicon(Tab tab) {
563 if (tab.inForeground()) {
564 Bitmap icon = tab.getFavicon();
565 getEmbeddedTitleBar().setFavicon(icon);
566 getFakeTitleBar().setFavicon(icon);
567 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700568 }
569
570 @Override
571 public void onActionModeFinished(boolean inLoad) {
572 if (inLoad) {
573 // the titlebar was removed when the CAB was shown
574 // if the page is loading, show it again
575 showFakeTitleBar();
576 }
577 }
578
Michael Kolb66706532010-12-12 19:50:22 -0800579 // active tabs page
580
581 public void showActiveTabsPage() {
582 }
583
584 /**
585 * Remove the active tabs page.
586 */
587 public void removeActiveTabsPage() {
588 }
589
Michael Kolb8233fac2010-10-26 16:08:53 -0700590 // menu handling callbacks
591
592 @Override
593 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700594 }
595
596 @Override
597 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 }
599
600 @Override
601 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 }
603
604 @Override
605 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 }
607
608 @Override
609 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700610 }
611
612 @Override
613 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 }
615
616 // error console
617
618 @Override
619 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
620 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
621 if (flag) {
622 // Setting the show state of the console will cause it's the layout
623 // to be inflated.
624 if (errorConsole.numberOfErrors() > 0) {
625 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
626 } else {
627 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
628 }
629 if (errorConsole.getParent() != null) {
630 mErrorConsoleContainer.removeView(errorConsole);
631 }
632 // Now we can add it to the main view.
633 mErrorConsoleContainer.addView(errorConsole,
634 new LinearLayout.LayoutParams(
635 ViewGroup.LayoutParams.MATCH_PARENT,
636 ViewGroup.LayoutParams.WRAP_CONTENT));
637 } else {
638 mErrorConsoleContainer.removeView(errorConsole);
639 }
640 }
641
642 private void setStatusBarVisibility(boolean visible) {
643 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
644 mActivity.getWindow().setFlags(flag,
645 WindowManager.LayoutParams.FLAG_FULLSCREEN);
646 }
647
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 // -------------------------------------------------------------------------
649 // Helper function for WebChromeClient
650 // -------------------------------------------------------------------------
651
652 @Override
653 public Bitmap getDefaultVideoPoster() {
654 if (mDefaultVideoPoster == null) {
655 mDefaultVideoPoster = BitmapFactory.decodeResource(
656 mActivity.getResources(), R.drawable.default_video_poster);
657 }
658 return mDefaultVideoPoster;
659 }
660
661 @Override
662 public View getVideoLoadingProgressView() {
663 if (mVideoProgressView == null) {
664 LayoutInflater inflater = LayoutInflater.from(mActivity);
665 mVideoProgressView = inflater.inflate(
666 R.layout.video_loading_progress, null);
667 }
668 return mVideoProgressView;
669 }
670
Michael Kolb843510f2010-12-09 10:51:49 -0800671 @Override
672 public void showMaxTabsWarning() {
673 Toast warning = Toast.makeText(mActivity,
674 mActivity.getString(R.string.max_tabs_warning),
675 Toast.LENGTH_SHORT);
676 warning.show();
677 }
678
Michael Kolb8233fac2010-10-26 16:08:53 -0700679}