blob: 025482b4c880130a602a67ef2244fd67c39e5ac0 [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
Michael Kolb7cdc4902011-02-03 17:54:40 -080088 private boolean mTitleShowing;
89
Michael Kolb8233fac2010-10-26 16:08:53 -070090 // the default <video> poster
91 private Bitmap mDefaultVideoPoster;
92 // the video progress view
93 private View mVideoProgressView;
94
Michael Kolb8233fac2010-10-26 16:08:53 -070095 private boolean mActivityPaused;
96
97 public BaseUi(Activity browser, UiController controller) {
98 mActivity = browser;
99 mUiController = controller;
100 mTabControl = controller.getTabControl();
101 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800102 mInputManager = (InputMethodManager)
103 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800104 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700105 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
108 .getDecorView().findViewById(android.R.id.content);
109 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
110 .inflate(R.layout.custom_screen, null);
111 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
112 R.id.main_content);
113 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
114 .findViewById(R.id.error_console);
115 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
116 .findViewById(R.id.fullscreen_custom_content);
117 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800118 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700119 }
120
Michael Kolb66706532010-12-12 19:50:22 -0800121 /**
122 * common webview initialization
123 * @param w the webview to initialize
124 */
125 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700126 w.setScrollbarFadingEnabled(true);
127 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
128 w.setMapTrackballToArrowKeys(false); // use trackball directly
129 // Enable the built-in zoom
130 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700131
132 // Add this WebView to the settings observer list and update the
133 // settings
134 final BrowserSettings s = BrowserSettings.getInstance();
135 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 }
137
138 private void cancelStopToast() {
139 if (mStopToast != null) {
140 mStopToast.cancel();
141 mStopToast = null;
142 }
143 }
144
145 // lifecycle
146
147 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800148 if (isCustomViewShowing()) {
149 onHideCustomView();
150 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700151 cancelStopToast();
152 mActivityPaused = true;
153 }
154
155 public void onResume() {
156 mActivityPaused = false;
157 }
158
Michael Kolb66706532010-12-12 19:50:22 -0800159 protected boolean isActivityPaused() {
160 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700161 }
162
163 public void onConfigurationChanged(Configuration config) {
164 }
165
166 // key handling
167
168 @Override
169 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700170 if (mComboView != null) {
171 if (!mComboView.onBackPressed()) {
172 mUiController.removeComboView();
173 }
174 return true;
175 }
176 if (mCustomView != null) {
177 mUiController.hideCustomView();
178 return true;
179 }
180 return false;
181 }
182
John Reck30c714c2010-12-16 17:30:34 -0800183 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700184 @Override
John Reck30c714c2010-12-16 17:30:34 -0800185 public void onTabDataChanged(Tab tab) {
186 setUrlTitle(tab);
187 setFavicon(tab);
188 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800189 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 }
191
192 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500193 public void bookmarkedStatusHasChanged(Tab tab) {
Michael Kolb66706532010-12-12 19:50:22 -0800194 // no op in base case
Leon Scroggins4cd97792010-12-03 15:31:56 -0500195 }
196
197 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 public void onPageStopped(Tab tab) {
199 cancelStopToast();
200 if (tab.inForeground()) {
201 mStopToast = Toast
202 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
203 mStopToast.show();
204 }
205 }
206
207 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800208 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800209 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800210 }
211
212 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700213 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700214 }
215
216 @Override
217 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800218 if ((tab != mActiveTab) && (mActiveTab != null)) {
219 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 }
Michael Kolb77df4562010-11-19 14:49:34 -0800221 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 attachTabToContentView(tab);
223 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800224 onTabDataChanged(tab);
225 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800226 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800227 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 }
229
Michael Kolbcfa3af52010-12-14 10:36:11 -0800230 Tab getActiveTab() {
231 return mActiveTab;
232 }
233
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800235 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800236 }
237
238 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700239 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800240 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800242 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 }
245
246 @Override
247 public void detachTab(Tab tab) {
248 removeTabFromContentView(tab);
249 }
250
251 @Override
252 public void attachTab(Tab tab) {
253 attachTabToContentView(tab);
254 }
255
256 private void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800257 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700258 return;
259 }
260 View container = tab.getViewContainer();
261 WebView mainView = tab.getWebView();
262 // Attach the WebView to the container and then attach the
263 // container to the content view.
264 FrameLayout wrapper =
265 (FrameLayout) container.findViewById(R.id.webview_wrapper);
266 ViewGroup parent = (ViewGroup) mainView.getParent();
267 if (parent != wrapper) {
268 if (parent != null) {
269 Log.w(LOGTAG, "mMainView already has a parent in"
270 + " attachTabToContentView!");
271 parent.removeView(mainView);
272 }
273 wrapper.addView(mainView);
274 } else {
275 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
276 + " attachTabToContentView!");
277 }
278 parent = (ViewGroup) container.getParent();
279 if (parent != mContentView) {
280 if (parent != null) {
281 Log.w(LOGTAG, "mContainer already has a parent in"
282 + " attachTabToContentView!");
283 parent.removeView(container);
284 }
285 mContentView.addView(container, COVER_SCREEN_PARAMS);
286 } else {
287 Log.w(LOGTAG, "mContainer is already attached to content in"
288 + " attachTabToContentView!");
289 }
Michael Kolba4183062011-01-16 10:43:21 -0800290 mainView.setNextFocusUpId(R.id.url_focused);
291 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700292 mUiController.attachSubWindow(tab);
293 }
294
295 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800296 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700297 // Remove the container that contains the main WebView.
298 WebView mainView = tab.getWebView();
299 View container = tab.getViewContainer();
300 if (mainView == null) {
301 return;
302 }
303 // Remove the container from the content and then remove the
304 // WebView from the container. This will trigger a focus change
305 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800306 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700307 FrameLayout wrapper =
308 (FrameLayout) container.findViewById(R.id.webview_wrapper);
309 wrapper.removeView(mainView);
310 mContentView.removeView(container);
311 mUiController.endActionMode();
312 mUiController.removeSubWindow(tab);
313 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
314 if (errorConsole != null) {
315 mErrorConsoleContainer.removeView(errorConsole);
316 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700317 }
318
Michael Kolba713ec82010-11-29 17:27:06 -0800319 @Override
320 public void onSetWebView(Tab tab, WebView webView) {
321 View container = tab.getViewContainer();
322 if (container == null) {
323 // The tab consists of a container view, which contains the main
324 // WebView, as well as any other UI elements associated with the tab.
325 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
326 null);
327 tab.setViewContainer(container);
328 }
329 if (tab.getWebView() != webView) {
330 // Just remove the old one.
331 FrameLayout wrapper =
332 (FrameLayout) container.findViewById(R.id.webview_wrapper);
333 wrapper.removeView(tab.getWebView());
334 }
335 }
336
Michael Kolb8233fac2010-10-26 16:08:53 -0700337 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800338 * create a sub window container and webview for the tab
339 * Note: this methods operates through side-effects for now
340 * it sets both the subView and subViewContainer for the given tab
341 * @param tab tab to create the sub window for
342 * @param subView webview to be set as a subwindow for the tab
343 */
344 @Override
345 public void createSubWindow(Tab tab, WebView subView) {
346 View subViewContainer = mActivity.getLayoutInflater().inflate(
347 R.layout.browser_subwindow, null);
348 ViewGroup inner = (ViewGroup) subViewContainer
349 .findViewById(R.id.inner_container);
350 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
351 LayoutParams.MATCH_PARENT));
352 final ImageButton cancel = (ImageButton) subViewContainer
353 .findViewById(R.id.subwindow_close);
354 final WebView cancelSubView = subView;
355 cancel.setOnClickListener(new OnClickListener() {
356 public void onClick(View v) {
357 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
358 }
359 });
360 tab.setSubWebView(subView);
361 tab.setSubViewContainer(subViewContainer);
362 }
363
364 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700365 * Remove the sub window from the content view.
366 */
367 @Override
368 public void removeSubWindow(View subviewContainer) {
369 mContentView.removeView(subviewContainer);
370 mUiController.endActionMode();
371 }
372
373 /**
374 * Attach the sub window to the content view.
375 */
376 @Override
377 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800378 if (container.getParent() != null) {
379 // already attached, remove first
380 ((ViewGroup) container.getParent()).removeView(container);
381 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 mContentView.addView(container, COVER_SCREEN_PARAMS);
383 }
384
Michael Kolb7cdc4902011-02-03 17:54:40 -0800385 boolean canShowTitleBar() {
386 return !isTitleBarShowing()
387 && !isActivityPaused()
388 && (getActiveTab() != null)
389 && (getActiveTab().getWebView() != null)
390 && !mUiController.isInCustomActionMode();
391 }
392
393 void showTitleBar() {
394 mTitleShowing = true;
395 }
396
397 protected void hideTitleBar() {
398 mTitleShowing = false;
399 }
400
401 protected boolean isTitleBarShowing() {
402 return mTitleShowing;
403 }
404
405 protected abstract TitleBarBase getTitleBar();
406
407 protected void setTitleGravity(int gravity) {
408 getTitleBar().setTitleGravity(gravity);
409 Tab tab = getActiveTab();
410 if ((tab != null) && (tab.getWebView() != null)) {
411 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700412 }
413 }
414
Michael Kolb66706532010-12-12 19:50:22 -0800415 @Override
416 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800417 getTitleBar().setInVoiceMode(true);
418 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700419 }
420
Michael Kolb66706532010-12-12 19:50:22 -0800421 @Override
422 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800423 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800424 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800425 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427
428 @Override
429 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800430 if (mComboView != null) {
431 return;
432 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700433 mComboView = new CombinedBookmarkHistoryView(mActivity,
434 mUiController,
435 startWithHistory ?
436 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
437 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
438 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800439 FrameLayout wrapper =
440 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
441 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800442 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800443 dismissIME();
444 if (mActiveTab != null) {
445 WebView web = mActiveTab.getWebView();
446 mActiveTab.putInBackground();
447 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700448 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
449 }
450
451 /**
452 * dismiss the ComboPage
453 */
454 @Override
455 public void hideComboView() {
456 if (mComboView != null) {
457 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800458 FrameLayout wrapper =
459 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
460 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700461 mComboView = null;
462 }
Michael Kolb3a696282010-12-05 13:23:24 -0800463 if (mActiveTab != null) {
464 mActiveTab.putInForeground();
465 }
John Reckb3417f02011-01-14 11:01:05 -0800466 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 }
468
469 @Override
470 public void showCustomView(View view,
471 WebChromeClient.CustomViewCallback callback) {
472 // if a view already exists then immediately terminate the new one
473 if (mCustomView != null) {
474 callback.onCustomViewHidden();
475 return;
476 }
477
478 // Add the custom view to its container.
479 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
480 mCustomView = view;
481 mCustomViewCallback = callback;
482 // Hide the content view.
483 mContentView.setVisibility(View.GONE);
484 // Finally show the custom view container.
485 setStatusBarVisibility(false);
486 mCustomViewContainer.setVisibility(View.VISIBLE);
487 mCustomViewContainer.bringToFront();
488 }
489
490 @Override
491 public void onHideCustomView() {
492 if (mCustomView == null)
493 return;
494
495 // Hide the custom view.
496 mCustomView.setVisibility(View.GONE);
497 // Remove the custom view from its container.
498 mCustomViewContainer.removeView(mCustomView);
499 mCustomView = null;
500 mCustomViewContainer.setVisibility(View.GONE);
501 mCustomViewCallback.onCustomViewHidden();
502 // Show the content view.
503 setStatusBarVisibility(true);
504 mContentView.setVisibility(View.VISIBLE);
505 }
506
507 @Override
508 public boolean isCustomViewShowing() {
509 return mCustomView != null;
510 }
511
Michael Kolb66706532010-12-12 19:50:22 -0800512 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800513 if (mInputManager.isActive()) {
514 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
515 0);
516 }
517 }
518
Michael Kolb66706532010-12-12 19:50:22 -0800519 @Override
520 public boolean showsWeb() {
521 return mCustomView == null
522 && mComboView == null;
523 }
524
Michael Kolb8233fac2010-10-26 16:08:53 -0700525 // -------------------------------------------------------------------------
526
Michael Kolb5a72f182011-01-13 20:35:06 -0800527 protected void updateNavigationState(Tab tab) {
528 }
529
Michael Kolb8233fac2010-10-26 16:08:53 -0700530 /**
531 * Update the lock icon to correspond to our latest state.
532 */
Michael Kolb66706532010-12-12 19:50:22 -0800533 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800534 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700535 updateLockIconImage(t.getLockIconType());
536 }
537 }
538
539 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700540 * Updates the lock-icon image in the title-bar.
541 */
John Reck30c714c2010-12-16 17:30:34 -0800542 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700543 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800544 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800546 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700547 d = mMixLockIcon;
548 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800549 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700550 }
551
John Reck30c714c2010-12-16 17:30:34 -0800552 protected void setUrlTitle(Tab tab) {
553 String url = tab.getUrl();
554 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800555 if (TextUtils.isEmpty(title)) {
556 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800557 }
Michael Kolb66706532010-12-12 19:50:22 -0800558 if (tab.isInVoiceSearchMode()) return;
559 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800560 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800561 }
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();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800568 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800569 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700570 }
571
572 @Override
573 public void onActionModeFinished(boolean inLoad) {
574 if (inLoad) {
575 // the titlebar was removed when the CAB was shown
576 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800577 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700578 }
579 }
580
Michael Kolb66706532010-12-12 19:50:22 -0800581 // active tabs page
582
583 public void showActiveTabsPage() {
584 }
585
586 /**
587 * Remove the active tabs page.
588 */
589 public void removeActiveTabsPage() {
590 }
591
Michael Kolb8233fac2010-10-26 16:08:53 -0700592 // menu handling callbacks
593
594 @Override
595 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 }
597
598 @Override
599 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700600 }
601
602 @Override
603 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700604 }
605
606 @Override
607 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 }
609
610 @Override
611 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 }
613
614 @Override
615 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 }
617
618 // error console
619
620 @Override
621 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
622 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
623 if (flag) {
624 // Setting the show state of the console will cause it's the layout
625 // to be inflated.
626 if (errorConsole.numberOfErrors() > 0) {
627 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
628 } else {
629 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
630 }
631 if (errorConsole.getParent() != null) {
632 mErrorConsoleContainer.removeView(errorConsole);
633 }
634 // Now we can add it to the main view.
635 mErrorConsoleContainer.addView(errorConsole,
636 new LinearLayout.LayoutParams(
637 ViewGroup.LayoutParams.MATCH_PARENT,
638 ViewGroup.LayoutParams.WRAP_CONTENT));
639 } else {
640 mErrorConsoleContainer.removeView(errorConsole);
641 }
642 }
643
644 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800645 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
646 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
647 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 }
649
Michael Kolb8233fac2010-10-26 16:08:53 -0700650 // -------------------------------------------------------------------------
651 // Helper function for WebChromeClient
652 // -------------------------------------------------------------------------
653
654 @Override
655 public Bitmap getDefaultVideoPoster() {
656 if (mDefaultVideoPoster == null) {
657 mDefaultVideoPoster = BitmapFactory.decodeResource(
658 mActivity.getResources(), R.drawable.default_video_poster);
659 }
660 return mDefaultVideoPoster;
661 }
662
663 @Override
664 public View getVideoLoadingProgressView() {
665 if (mVideoProgressView == null) {
666 LayoutInflater inflater = LayoutInflater.from(mActivity);
667 mVideoProgressView = inflater.inflate(
668 R.layout.video_loading_progress, null);
669 }
670 return mVideoProgressView;
671 }
672
Michael Kolb843510f2010-12-09 10:51:49 -0800673 @Override
674 public void showMaxTabsWarning() {
675 Toast warning = Toast.makeText(mActivity,
676 mActivity.getString(R.string.max_tabs_warning),
677 Toast.LENGTH_SHORT);
678 warning.show();
679 }
680
Michael Kolb8233fac2010-10-26 16:08:53 -0700681}