blob: 756f8b894ef8563d9aa731f3f282afdc1bb757a2 [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 Kolba4183062011-01-16 10:43:21 -080035import android.view.View.OnKeyListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080037import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080039import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.webkit.WebView;
42import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.widget.LinearLayout;
45import android.widget.Toast;
46
Michael Kolb1bf23132010-11-19 12:55:12 -080047import java.util.List;
48
Michael Kolb8233fac2010-10-26 16:08:53 -070049/**
50 * UI interface definitions
51 */
Michael Kolb66706532010-12-12 19:50:22 -080052public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070053
54 private static final String LOGTAG = "BaseUi";
55
Michael Kolb66706532010-12-12 19:50:22 -080056 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070057 new FrameLayout.LayoutParams(
58 ViewGroup.LayoutParams.MATCH_PARENT,
59 ViewGroup.LayoutParams.MATCH_PARENT);
60
Michael Kolb66706532010-12-12 19:50:22 -080061 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070062 new FrameLayout.LayoutParams(
63 ViewGroup.LayoutParams.MATCH_PARENT,
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 Gravity.CENTER);
66
67 Activity mActivity;
68 UiController mUiController;
69 TabControl mTabControl;
Michael Kolb77df4562010-11-19 14:49:34 -080070 private Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080071 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070072
73 private Drawable mSecLockIcon;
74 private Drawable mMixLockIcon;
75
Michael Kolb8233fac2010-10-26 16:08:53 -070076 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080077 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070078 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070079
80 private View mCustomView;
81 private WebChromeClient.CustomViewCallback mCustomViewCallback;
82
83 private CombinedBookmarkHistoryView mComboView;
84
85 private LinearLayout mErrorConsoleContainer = null;
86
87 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
89 // the default <video> poster
90 private Bitmap mDefaultVideoPoster;
91 // the video progress view
92 private View mVideoProgressView;
93
Michael Kolb8233fac2010-10-26 16:08:53 -070094 private boolean mActivityPaused;
95
96 public BaseUi(Activity browser, UiController controller) {
97 mActivity = browser;
98 mUiController = controller;
99 mTabControl = controller.getTabControl();
100 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800101 mInputManager = (InputMethodManager)
102 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800103 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700104 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
105
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
107 .getDecorView().findViewById(android.R.id.content);
108 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
109 .inflate(R.layout.custom_screen, null);
110 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
111 R.id.main_content);
112 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
113 .findViewById(R.id.error_console);
114 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
115 .findViewById(R.id.fullscreen_custom_content);
116 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
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 }
Michael Kolba4183062011-01-16 10:43:21 -0800289 mainView.setNextFocusUpId(R.id.url_focused);
290 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700291 mUiController.attachSubWindow(tab);
292 }
293
294 private void removeTabFromContentView(Tab tab) {
Michael Kolb20776cc2011-01-31 10:19:05 -0800295 hideFakeTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700296 // Remove the container that contains the main WebView.
297 WebView mainView = tab.getWebView();
298 View container = tab.getViewContainer();
299 if (mainView == null) {
300 return;
301 }
302 // Remove the container from the content and then remove the
303 // WebView from the container. This will trigger a focus change
304 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800305 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700306 FrameLayout wrapper =
307 (FrameLayout) container.findViewById(R.id.webview_wrapper);
308 wrapper.removeView(mainView);
309 mContentView.removeView(container);
310 mUiController.endActionMode();
311 mUiController.removeSubWindow(tab);
312 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
313 if (errorConsole != null) {
314 mErrorConsoleContainer.removeView(errorConsole);
315 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700316 }
317
Michael Kolba713ec82010-11-29 17:27:06 -0800318 @Override
319 public void onSetWebView(Tab tab, WebView webView) {
320 View container = tab.getViewContainer();
321 if (container == null) {
322 // The tab consists of a container view, which contains the main
323 // WebView, as well as any other UI elements associated with the tab.
324 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
325 null);
326 tab.setViewContainer(container);
327 }
328 if (tab.getWebView() != webView) {
329 // Just remove the old one.
330 FrameLayout wrapper =
331 (FrameLayout) container.findViewById(R.id.webview_wrapper);
332 wrapper.removeView(tab.getWebView());
333 }
334 }
335
Michael Kolb8233fac2010-10-26 16:08:53 -0700336 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800337 * create a sub window container and webview for the tab
338 * Note: this methods operates through side-effects for now
339 * it sets both the subView and subViewContainer for the given tab
340 * @param tab tab to create the sub window for
341 * @param subView webview to be set as a subwindow for the tab
342 */
343 @Override
344 public void createSubWindow(Tab tab, WebView subView) {
345 View subViewContainer = mActivity.getLayoutInflater().inflate(
346 R.layout.browser_subwindow, null);
347 ViewGroup inner = (ViewGroup) subViewContainer
348 .findViewById(R.id.inner_container);
349 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
350 LayoutParams.MATCH_PARENT));
351 final ImageButton cancel = (ImageButton) subViewContainer
352 .findViewById(R.id.subwindow_close);
353 final WebView cancelSubView = subView;
354 cancel.setOnClickListener(new OnClickListener() {
355 public void onClick(View v) {
356 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
357 }
358 });
359 tab.setSubWebView(subView);
360 tab.setSubViewContainer(subViewContainer);
361 }
362
363 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700364 * Remove the sub window from the content view.
365 */
366 @Override
367 public void removeSubWindow(View subviewContainer) {
368 mContentView.removeView(subviewContainer);
369 mUiController.endActionMode();
370 }
371
372 /**
373 * Attach the sub window to the content view.
374 */
375 @Override
376 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800377 if (container.getParent() != null) {
378 // already attached, remove first
379 ((ViewGroup) container.getParent()).removeView(container);
380 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 mContentView.addView(container, COVER_SCREEN_PARAMS);
382 }
383
384 void showFakeTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800385 if (!isFakeTitleBarShowing() && !isActivityPaused()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700386 WebView mainView = mUiController.getCurrentWebView();
387 // if there is no current WebView, don't show the faked title bar;
388 if (mainView == null) {
389 return;
390 }
391 // Do not need to check for null, since the current tab will have
392 // at least a main WebView, or we would have returned above.
393 if (mUiController.isInCustomActionMode()) {
394 // Do not show the fake title bar, while a custom ActionMode
395 // (i.e. find or select) is showing.
396 return;
397 }
Michael Kolb66706532010-12-12 19:50:22 -0800398 attachFakeTitleBar(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700399 }
400 }
401
Michael Kolb66706532010-12-12 19:50:22 -0800402 protected abstract void attachFakeTitleBar(WebView mainView);
403
404 protected abstract void hideFakeTitleBar();
405
406 protected abstract boolean isFakeTitleBarShowing();
407
408 protected abstract TitleBarBase getFakeTitleBar();
409
410 protected abstract TitleBarBase getEmbeddedTitleBar();
411
412 @Override
413 public void showVoiceTitleBar(String title) {
414 getEmbeddedTitleBar().setInVoiceMode(true);
415 getEmbeddedTitleBar().setDisplayTitle(title);
416 getFakeTitleBar().setInVoiceMode(true);
417 getFakeTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700418 }
419
Michael Kolb66706532010-12-12 19:50:22 -0800420 @Override
421 public void revertVoiceTitleBar(Tab tab) {
422 getEmbeddedTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800423 String url = tab.getUrl();
Michael Kolb66706532010-12-12 19:50:22 -0800424 getEmbeddedTitleBar().setDisplayTitle(url);
425 getFakeTitleBar().setInVoiceMode(false);
426 getFakeTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700427 }
428
429 @Override
430 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800431 if (mComboView != null) {
432 return;
433 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700434 mComboView = new CombinedBookmarkHistoryView(mActivity,
435 mUiController,
436 startWithHistory ?
437 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
438 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
439 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800440 FrameLayout wrapper =
441 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
442 wrapper.setVisibility(View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700443 hideFakeTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800444 dismissIME();
445 if (mActiveTab != null) {
446 WebView web = mActiveTab.getWebView();
447 mActiveTab.putInBackground();
448 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700449 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
450 }
451
452 /**
453 * dismiss the ComboPage
454 */
455 @Override
456 public void hideComboView() {
457 if (mComboView != null) {
458 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800459 FrameLayout wrapper =
460 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
461 wrapper.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 }
John Reckb3417f02011-01-14 11:01:05 -0800467 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700468 }
469
470 @Override
471 public void showCustomView(View view,
472 WebChromeClient.CustomViewCallback callback) {
473 // if a view already exists then immediately terminate the new one
474 if (mCustomView != null) {
475 callback.onCustomViewHidden();
476 return;
477 }
478
479 // Add the custom view to its container.
480 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
481 mCustomView = view;
482 mCustomViewCallback = callback;
483 // Hide the content view.
484 mContentView.setVisibility(View.GONE);
485 // Finally show the custom view container.
486 setStatusBarVisibility(false);
487 mCustomViewContainer.setVisibility(View.VISIBLE);
488 mCustomViewContainer.bringToFront();
489 }
490
491 @Override
492 public void onHideCustomView() {
493 if (mCustomView == null)
494 return;
495
496 // Hide the custom view.
497 mCustomView.setVisibility(View.GONE);
498 // Remove the custom view from its container.
499 mCustomViewContainer.removeView(mCustomView);
500 mCustomView = null;
501 mCustomViewContainer.setVisibility(View.GONE);
502 mCustomViewCallback.onCustomViewHidden();
503 // Show the content view.
504 setStatusBarVisibility(true);
505 mContentView.setVisibility(View.VISIBLE);
506 }
507
508 @Override
509 public boolean isCustomViewShowing() {
510 return mCustomView != null;
511 }
512
Michael Kolb66706532010-12-12 19:50:22 -0800513 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800514 if (mInputManager.isActive()) {
515 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
516 0);
517 }
518 }
519
Michael Kolb66706532010-12-12 19:50:22 -0800520 @Override
521 public boolean showsWeb() {
522 return mCustomView == null
523 && mComboView == null;
524 }
525
Michael Kolb8233fac2010-10-26 16:08:53 -0700526 // -------------------------------------------------------------------------
527
Michael Kolb5a72f182011-01-13 20:35:06 -0800528 protected void updateNavigationState(Tab tab) {
529 }
530
Michael Kolb8233fac2010-10-26 16:08:53 -0700531 /**
532 * Update the lock icon to correspond to our latest state.
533 */
Michael Kolb66706532010-12-12 19:50:22 -0800534 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800535 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700536 updateLockIconImage(t.getLockIconType());
537 }
538 }
539
540 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700541 * Updates the lock-icon image in the title-bar.
542 */
John Reck30c714c2010-12-16 17:30:34 -0800543 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700544 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800545 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700546 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800547 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700548 d = mMixLockIcon;
549 }
Michael Kolb66706532010-12-12 19:50:22 -0800550 getEmbeddedTitleBar().setLock(d);
551 getFakeTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700552 }
553
John Reck30c714c2010-12-16 17:30:34 -0800554 protected void setUrlTitle(Tab tab) {
555 String url = tab.getUrl();
556 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800557 if (TextUtils.isEmpty(title)) {
558 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800559 }
Michael Kolb66706532010-12-12 19:50:22 -0800560 if (tab.isInVoiceSearchMode()) return;
561 if (tab.inForeground()) {
562 getEmbeddedTitleBar().setDisplayTitle(url);
563 getFakeTitleBar().setDisplayTitle(url);
564 }
565 }
566
567 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800568 protected void setFavicon(Tab tab) {
569 if (tab.inForeground()) {
570 Bitmap icon = tab.getFavicon();
571 getEmbeddedTitleBar().setFavicon(icon);
572 getFakeTitleBar().setFavicon(icon);
573 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700574 }
575
576 @Override
577 public void onActionModeFinished(boolean inLoad) {
578 if (inLoad) {
579 // the titlebar was removed when the CAB was shown
580 // if the page is loading, show it again
581 showFakeTitleBar();
582 }
583 }
584
Michael Kolb66706532010-12-12 19:50:22 -0800585 // active tabs page
586
587 public void showActiveTabsPage() {
588 }
589
590 /**
591 * Remove the active tabs page.
592 */
593 public void removeActiveTabsPage() {
594 }
595
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 // menu handling callbacks
597
598 @Override
599 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700600 }
601
602 @Override
603 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700604 }
605
606 @Override
607 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 }
609
610 @Override
611 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 }
613
614 @Override
615 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 }
617
618 @Override
619 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 }
621
622 // error console
623
624 @Override
625 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
626 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
627 if (flag) {
628 // Setting the show state of the console will cause it's the layout
629 // to be inflated.
630 if (errorConsole.numberOfErrors() > 0) {
631 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
632 } else {
633 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
634 }
635 if (errorConsole.getParent() != null) {
636 mErrorConsoleContainer.removeView(errorConsole);
637 }
638 // Now we can add it to the main view.
639 mErrorConsoleContainer.addView(errorConsole,
640 new LinearLayout.LayoutParams(
641 ViewGroup.LayoutParams.MATCH_PARENT,
642 ViewGroup.LayoutParams.WRAP_CONTENT));
643 } else {
644 mErrorConsoleContainer.removeView(errorConsole);
645 }
646 }
647
648 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800649 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
650 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
651 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700652 }
653
Michael Kolb8233fac2010-10-26 16:08:53 -0700654 // -------------------------------------------------------------------------
655 // Helper function for WebChromeClient
656 // -------------------------------------------------------------------------
657
658 @Override
659 public Bitmap getDefaultVideoPoster() {
660 if (mDefaultVideoPoster == null) {
661 mDefaultVideoPoster = BitmapFactory.decodeResource(
662 mActivity.getResources(), R.drawable.default_video_poster);
663 }
664 return mDefaultVideoPoster;
665 }
666
667 @Override
668 public View getVideoLoadingProgressView() {
669 if (mVideoProgressView == null) {
670 LayoutInflater inflater = LayoutInflater.from(mActivity);
671 mVideoProgressView = inflater.inflate(
672 R.layout.video_loading_progress, null);
673 }
674 return mVideoProgressView;
675 }
676
Michael Kolb843510f2010-12-09 10:51:49 -0800677 @Override
678 public void showMaxTabsWarning() {
679 Toast warning = Toast.makeText(mActivity,
680 mActivity.getString(R.string.max_tabs_warning),
681 Toast.LENGTH_SHORT);
682 warning.show();
683 }
684
Michael Kolb8233fac2010-10-26 16:08:53 -0700685}