blob: 2a03893aefa90e60f2dfd94f71af773d5a8b3793 [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
John Reck74830e12011-03-14 11:43:05 -070021import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070023import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070024import android.content.res.Configuration;
25import android.content.res.Resources;
26import android.graphics.Bitmap;
27import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
29import android.os.Bundle;
30import android.text.TextUtils;
31import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070032import android.view.Gravity;
33import android.view.LayoutInflater;
34import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080036import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080038import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080040import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.webkit.WebView;
43import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080044import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070045import android.widget.LinearLayout;
46import android.widget.Toast;
47
Michael Kolb1bf23132010-11-19 12:55:12 -080048import java.util.List;
49
Michael Kolb8233fac2010-10-26 16:08:53 -070050/**
51 * UI interface definitions
52 */
Michael Kolb66706532010-12-12 19:50:22 -080053public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070054
55 private static final String LOGTAG = "BaseUi";
56
Michael Kolb66706532010-12-12 19:50:22 -080057 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070058 new FrameLayout.LayoutParams(
59 ViewGroup.LayoutParams.MATCH_PARENT,
60 ViewGroup.LayoutParams.MATCH_PARENT);
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT,
66 Gravity.CENTER);
67
68 Activity mActivity;
69 UiController mUiController;
70 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080071 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080072 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070073
74 private Drawable mSecLockIcon;
75 private Drawable mMixLockIcon;
76
Michael Kolb8233fac2010-10-26 16:08:53 -070077 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080078 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070079 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070080
81 private View mCustomView;
82 private WebChromeClient.CustomViewCallback mCustomViewCallback;
83
84 private CombinedBookmarkHistoryView mComboView;
85
86 private LinearLayout mErrorConsoleContainer = null;
87
88 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070089
Michael Kolb7cdc4902011-02-03 17:54:40 -080090 private boolean mTitleShowing;
91
Michael Kolb8233fac2010-10-26 16:08:53 -070092 // the default <video> poster
93 private Bitmap mDefaultVideoPoster;
94 // the video progress view
95 private View mVideoProgressView;
96
Michael Kolb8233fac2010-10-26 16:08:53 -070097 private boolean mActivityPaused;
98
99 public BaseUi(Activity browser, UiController controller) {
100 mActivity = browser;
101 mUiController = controller;
102 mTabControl = controller.getTabControl();
103 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800104 mInputManager = (InputMethodManager)
105 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800106 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
108
Michael Kolb8233fac2010-10-26 16:08:53 -0700109 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
110 .getDecorView().findViewById(android.R.id.content);
111 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
112 .inflate(R.layout.custom_screen, null);
113 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
114 R.id.main_content);
115 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
116 .findViewById(R.id.error_console);
117 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
118 .findViewById(R.id.fullscreen_custom_content);
119 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800120 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700121 }
122
John Reckb9a051b2011-03-18 11:55:48 -0700123 @Override
124 public WebView createWebView(boolean privateBrowsing) {
125 // Create a new WebView
126 BrowserWebView w = new BrowserWebView(mActivity, null,
127 android.R.attr.webViewStyle, privateBrowsing);
128 initWebViewSettings(w);
129 return w;
130 }
131
132 @Override
133 public WebView createSubWebView(boolean privateBrowsing) {
134 return createWebView(privateBrowsing);
135 }
136
Michael Kolb66706532010-12-12 19:50:22 -0800137 /**
138 * common webview initialization
139 * @param w the webview to initialize
140 */
141 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700142 w.setScrollbarFadingEnabled(true);
143 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
144 w.setMapTrackballToArrowKeys(false); // use trackball directly
145 // Enable the built-in zoom
146 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700147 boolean supportsMultiTouch = mActivity.getPackageManager()
148 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
149 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
150 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700151
152 // Add this WebView to the settings observer list and update the
153 // settings
154 final BrowserSettings s = BrowserSettings.getInstance();
155 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700156 }
157
158 private void cancelStopToast() {
159 if (mStopToast != null) {
160 mStopToast.cancel();
161 mStopToast = null;
162 }
163 }
164
165 // lifecycle
166
167 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800168 if (isCustomViewShowing()) {
169 onHideCustomView();
170 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700171 cancelStopToast();
172 mActivityPaused = true;
173 }
174
175 public void onResume() {
176 mActivityPaused = false;
177 }
178
Michael Kolb66706532010-12-12 19:50:22 -0800179 protected boolean isActivityPaused() {
180 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700181 }
182
183 public void onConfigurationChanged(Configuration config) {
184 }
185
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800186 public abstract void editUrl(boolean clearInput);
187
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 // key handling
189
190 @Override
191 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700192 if (mComboView != null) {
193 if (!mComboView.onBackPressed()) {
194 mUiController.removeComboView();
195 }
196 return true;
197 }
198 if (mCustomView != null) {
199 mUiController.hideCustomView();
200 return true;
201 }
202 return false;
203 }
204
John Reck30c714c2010-12-16 17:30:34 -0800205 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700206 @Override
John Reck30c714c2010-12-16 17:30:34 -0800207 public void onTabDataChanged(Tab tab) {
208 setUrlTitle(tab);
209 setFavicon(tab);
210 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800211 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 }
213
214 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500215 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800216 if (tab.inForeground()) {
217 boolean isBookmark = tab.isBookmarkedSite();
218 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
219 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500220 }
221
222 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 public void onPageStopped(Tab tab) {
224 cancelStopToast();
225 if (tab.inForeground()) {
226 mStopToast = Toast
227 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
228 mStopToast.show();
229 }
230 }
231
232 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800233 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800234 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800235 }
236
237 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700239 }
240
241 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800242 public void setActiveTab(final Tab tab) {
243 setActiveTab(tab, true);
244 }
245
246 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800247 if ((tab != mActiveTab) && (mActiveTab != null)) {
248 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 }
Michael Kolb77df4562010-11-19 14:49:34 -0800250 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800251 if (needsAttaching) {
252 attachTabToContentView(tab);
253 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800255 onTabDataChanged(tab);
256 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800257 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800258 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500259 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700260 }
261
Michael Kolbcfa3af52010-12-14 10:36:11 -0800262 Tab getActiveTab() {
263 return mActiveTab;
264 }
265
Michael Kolb8233fac2010-10-26 16:08:53 -0700266 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800267 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800268 }
269
270 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800272 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700273 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800274 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700275 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700276 }
277
278 @Override
279 public void detachTab(Tab tab) {
280 removeTabFromContentView(tab);
281 }
282
283 @Override
284 public void attachTab(Tab tab) {
285 attachTabToContentView(tab);
286 }
287
Michael Kolb377ea312011-02-17 14:36:56 -0800288 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800289 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700290 return;
291 }
292 View container = tab.getViewContainer();
293 WebView mainView = tab.getWebView();
294 // Attach the WebView to the container and then attach the
295 // container to the content view.
296 FrameLayout wrapper =
297 (FrameLayout) container.findViewById(R.id.webview_wrapper);
298 ViewGroup parent = (ViewGroup) mainView.getParent();
299 if (parent != wrapper) {
300 if (parent != null) {
301 Log.w(LOGTAG, "mMainView already has a parent in"
302 + " attachTabToContentView!");
303 parent.removeView(mainView);
304 }
305 wrapper.addView(mainView);
306 } else {
307 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
308 + " attachTabToContentView!");
309 }
310 parent = (ViewGroup) container.getParent();
311 if (parent != mContentView) {
312 if (parent != null) {
313 Log.w(LOGTAG, "mContainer already has a parent in"
314 + " attachTabToContentView!");
315 parent.removeView(container);
316 }
317 mContentView.addView(container, COVER_SCREEN_PARAMS);
318 } else {
319 Log.w(LOGTAG, "mContainer is already attached to content in"
320 + " attachTabToContentView!");
321 }
322 mUiController.attachSubWindow(tab);
323 }
324
325 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800326 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700327 // Remove the container that contains the main WebView.
328 WebView mainView = tab.getWebView();
329 View container = tab.getViewContainer();
330 if (mainView == null) {
331 return;
332 }
333 // Remove the container from the content and then remove the
334 // WebView from the container. This will trigger a focus change
335 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800336 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700337 FrameLayout wrapper =
338 (FrameLayout) container.findViewById(R.id.webview_wrapper);
339 wrapper.removeView(mainView);
340 mContentView.removeView(container);
341 mUiController.endActionMode();
342 mUiController.removeSubWindow(tab);
343 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
344 if (errorConsole != null) {
345 mErrorConsoleContainer.removeView(errorConsole);
346 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700347 }
348
Michael Kolba713ec82010-11-29 17:27:06 -0800349 @Override
350 public void onSetWebView(Tab tab, WebView webView) {
351 View container = tab.getViewContainer();
352 if (container == null) {
353 // The tab consists of a container view, which contains the main
354 // WebView, as well as any other UI elements associated with the tab.
355 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
356 null);
357 tab.setViewContainer(container);
358 }
359 if (tab.getWebView() != webView) {
360 // Just remove the old one.
361 FrameLayout wrapper =
362 (FrameLayout) container.findViewById(R.id.webview_wrapper);
363 wrapper.removeView(tab.getWebView());
364 }
365 }
366
Michael Kolb8233fac2010-10-26 16:08:53 -0700367 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800368 * create a sub window container and webview for the tab
369 * Note: this methods operates through side-effects for now
370 * it sets both the subView and subViewContainer for the given tab
371 * @param tab tab to create the sub window for
372 * @param subView webview to be set as a subwindow for the tab
373 */
374 @Override
375 public void createSubWindow(Tab tab, WebView subView) {
376 View subViewContainer = mActivity.getLayoutInflater().inflate(
377 R.layout.browser_subwindow, null);
378 ViewGroup inner = (ViewGroup) subViewContainer
379 .findViewById(R.id.inner_container);
380 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
381 LayoutParams.MATCH_PARENT));
382 final ImageButton cancel = (ImageButton) subViewContainer
383 .findViewById(R.id.subwindow_close);
384 final WebView cancelSubView = subView;
385 cancel.setOnClickListener(new OnClickListener() {
386 public void onClick(View v) {
387 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
388 }
389 });
390 tab.setSubWebView(subView);
391 tab.setSubViewContainer(subViewContainer);
392 }
393
394 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700395 * Remove the sub window from the content view.
396 */
397 @Override
398 public void removeSubWindow(View subviewContainer) {
399 mContentView.removeView(subviewContainer);
400 mUiController.endActionMode();
401 }
402
403 /**
404 * Attach the sub window to the content view.
405 */
406 @Override
407 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800408 if (container.getParent() != null) {
409 // already attached, remove first
410 ((ViewGroup) container.getParent()).removeView(container);
411 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700412 mContentView.addView(container, COVER_SCREEN_PARAMS);
413 }
414
Michael Kolb11d19782011-03-20 10:17:40 -0700415 protected void refreshWebView() {
416 Tab tab = getActiveTab();
417 if ((tab != null) && (tab.getWebView() != null)) {
418 tab.getWebView().invalidate();
419 }
420 }
421
Michael Kolb7cdc4902011-02-03 17:54:40 -0800422 boolean canShowTitleBar() {
423 return !isTitleBarShowing()
424 && !isActivityPaused()
425 && (getActiveTab() != null)
426 && (getActiveTab().getWebView() != null)
427 && !mUiController.isInCustomActionMode();
428 }
429
430 void showTitleBar() {
431 mTitleShowing = true;
432 }
433
434 protected void hideTitleBar() {
435 mTitleShowing = false;
436 }
437
438 protected boolean isTitleBarShowing() {
439 return mTitleShowing;
440 }
441
442 protected abstract TitleBarBase getTitleBar();
443
444 protected void setTitleGravity(int gravity) {
445 getTitleBar().setTitleGravity(gravity);
446 Tab tab = getActiveTab();
447 if ((tab != null) && (tab.getWebView() != null)) {
448 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700449 }
450 }
451
Michael Kolb66706532010-12-12 19:50:22 -0800452 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700453 public void showVoiceTitleBar(String title, List<String> results) {
454 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800455 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700456 }
457
Michael Kolb66706532010-12-12 19:50:22 -0800458 @Override
459 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700460 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800461 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800462 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700463 }
464
465 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700466 public void registerDropdownChangeListener(DropdownChangeListener d) {
467 getTitleBar().registerDropdownChangeListener(d);
468 }
469
470 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700471 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800472 if (mComboView != null) {
473 return;
474 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700475 mComboView = new CombinedBookmarkHistoryView(mActivity,
476 mUiController,
477 startWithHistory ?
478 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
479 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
480 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800481 FrameLayout wrapper =
482 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
483 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700484 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800485 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700486 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800487 if (mActiveTab != null) {
488 WebView web = mActiveTab.getWebView();
489 mActiveTab.putInBackground();
490 }
John Reck74830e12011-03-14 11:43:05 -0700491 mComboView.setAlpha(0f);
492 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
493 Resources res = mActivity.getResources();
494 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
495 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700496 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
497 }
498
Michael Kolbba238702011-03-08 10:40:50 -0800499 public boolean isComboViewShowing() {
500 return (mComboView != null);
501 }
502
Michael Kolb8233fac2010-10-26 16:08:53 -0700503 /**
504 * dismiss the ComboPage
505 */
506 @Override
507 public void hideComboView() {
508 if (mComboView != null) {
509 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800510 FrameLayout wrapper =
511 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
512 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700513 mComboView = null;
514 }
Michael Kolb3a696282010-12-05 13:23:24 -0800515 if (mActiveTab != null) {
516 mActiveTab.putInForeground();
517 }
John Reckb3417f02011-01-14 11:01:05 -0800518 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700519 }
520
521 @Override
522 public void showCustomView(View view,
523 WebChromeClient.CustomViewCallback callback) {
524 // if a view already exists then immediately terminate the new one
525 if (mCustomView != null) {
526 callback.onCustomViewHidden();
527 return;
528 }
529
530 // Add the custom view to its container.
531 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
532 mCustomView = view;
533 mCustomViewCallback = callback;
534 // Hide the content view.
535 mContentView.setVisibility(View.GONE);
536 // Finally show the custom view container.
537 setStatusBarVisibility(false);
538 mCustomViewContainer.setVisibility(View.VISIBLE);
539 mCustomViewContainer.bringToFront();
540 }
541
542 @Override
543 public void onHideCustomView() {
544 if (mCustomView == null)
545 return;
546
547 // Hide the custom view.
548 mCustomView.setVisibility(View.GONE);
549 // Remove the custom view from its container.
550 mCustomViewContainer.removeView(mCustomView);
551 mCustomView = null;
552 mCustomViewContainer.setVisibility(View.GONE);
553 mCustomViewCallback.onCustomViewHidden();
554 // Show the content view.
555 setStatusBarVisibility(true);
556 mContentView.setVisibility(View.VISIBLE);
557 }
558
559 @Override
560 public boolean isCustomViewShowing() {
561 return mCustomView != null;
562 }
563
Michael Kolb66706532010-12-12 19:50:22 -0800564 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800565 if (mInputManager.isActive()) {
566 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
567 0);
568 }
569 }
570
Michael Kolb66706532010-12-12 19:50:22 -0800571 @Override
572 public boolean showsWeb() {
573 return mCustomView == null
574 && mComboView == null;
575 }
576
Patrick Scott92066772011-03-10 08:46:27 -0500577 @Override
578 public void showAutoLogin(Tab tab) {
579 updateAutoLogin(tab, true);
580 }
581
582 @Override
583 public void hideAutoLogin(Tab tab) {
584 updateAutoLogin(tab, true);
585 }
586
Michael Kolb8233fac2010-10-26 16:08:53 -0700587 // -------------------------------------------------------------------------
588
Michael Kolb5a72f182011-01-13 20:35:06 -0800589 protected void updateNavigationState(Tab tab) {
590 }
591
Michael Kolb11d19782011-03-20 10:17:40 -0700592 protected void updateAutoLogin(Tab tab, boolean animate) {
593 getTitleBar().updateAutoLogin(tab, animate);
594 }
Patrick Scott92066772011-03-10 08:46:27 -0500595
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 /**
597 * Update the lock icon to correspond to our latest state.
598 */
Michael Kolb66706532010-12-12 19:50:22 -0800599 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800600 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 updateLockIconImage(t.getLockIconType());
602 }
603 }
604
605 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 * Updates the lock-icon image in the title-bar.
607 */
John Reck30c714c2010-12-16 17:30:34 -0800608 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800610 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800612 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700613 d = mMixLockIcon;
614 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800615 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 }
617
John Reck30c714c2010-12-16 17:30:34 -0800618 protected void setUrlTitle(Tab tab) {
619 String url = tab.getUrl();
620 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800621 if (TextUtils.isEmpty(title)) {
622 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800623 }
Michael Kolb66706532010-12-12 19:50:22 -0800624 if (tab.isInVoiceSearchMode()) return;
625 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800626 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800627 }
628 }
629
630 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800631 protected void setFavicon(Tab tab) {
632 if (tab.inForeground()) {
633 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800634 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800635 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700636 }
637
638 @Override
639 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700640 }
641
Michael Kolb66706532010-12-12 19:50:22 -0800642 // active tabs page
643
644 public void showActiveTabsPage() {
645 }
646
647 /**
648 * Remove the active tabs page.
649 */
650 public void removeActiveTabsPage() {
651 }
652
Michael Kolb8233fac2010-10-26 16:08:53 -0700653 // menu handling callbacks
654
655 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800656 public boolean onPrepareOptionsMenu(Menu menu) {
657 return true;
658 }
659
660 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 }
663
664 @Override
665 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700666 }
667
668 @Override
669 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700670 }
671
672 @Override
673 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700674 }
675
676 @Override
677 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700678 }
679
680 @Override
681 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700682 }
683
684 // error console
685
686 @Override
687 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800688 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700689 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
690 if (flag) {
691 // Setting the show state of the console will cause it's the layout
692 // to be inflated.
693 if (errorConsole.numberOfErrors() > 0) {
694 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
695 } else {
696 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
697 }
698 if (errorConsole.getParent() != null) {
699 mErrorConsoleContainer.removeView(errorConsole);
700 }
701 // Now we can add it to the main view.
702 mErrorConsoleContainer.addView(errorConsole,
703 new LinearLayout.LayoutParams(
704 ViewGroup.LayoutParams.MATCH_PARENT,
705 ViewGroup.LayoutParams.WRAP_CONTENT));
706 } else {
707 mErrorConsoleContainer.removeView(errorConsole);
708 }
709 }
710
711 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800712 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
713 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
714 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700715 }
716
Michael Kolb8233fac2010-10-26 16:08:53 -0700717 // -------------------------------------------------------------------------
718 // Helper function for WebChromeClient
719 // -------------------------------------------------------------------------
720
721 @Override
722 public Bitmap getDefaultVideoPoster() {
723 if (mDefaultVideoPoster == null) {
724 mDefaultVideoPoster = BitmapFactory.decodeResource(
725 mActivity.getResources(), R.drawable.default_video_poster);
726 }
727 return mDefaultVideoPoster;
728 }
729
730 @Override
731 public View getVideoLoadingProgressView() {
732 if (mVideoProgressView == null) {
733 LayoutInflater inflater = LayoutInflater.from(mActivity);
734 mVideoProgressView = inflater.inflate(
735 R.layout.video_loading_progress, null);
736 }
737 return mVideoProgressView;
738 }
739
Michael Kolb843510f2010-12-09 10:51:49 -0800740 @Override
741 public void showMaxTabsWarning() {
742 Toast warning = Toast.makeText(mActivity,
743 mActivity.getString(R.string.max_tabs_warning),
744 Toast.LENGTH_SHORT);
745 warning.show();
746 }
747
Michael Kolbfdb70242011-03-24 09:41:11 -0700748 protected void captureTab(final Tab tab) {
749 captureTab(tab,
750 (int) mActivity.getResources()
751 .getDimension(R.dimen.qc_thumb_width),
752 (int) mActivity.getResources()
753 .getDimension(R.dimen.qc_thumb_height));
754 }
755
756 protected void captureTab(final Tab tab, int width, int height) {
757 if ((tab == null) || (tab.getWebView() == null)) return;
758 Bitmap sshot = Controller.createScreenshot(tab, width, height);
759 tab.setScreenshot(sshot);
760 }
761
762 void showTitleBarAndEdit() {
763 showTitleBar();
764 getTitleBar().startEditingUrl(false);
765 }
766
Michael Kolb8233fac2010-10-26 16:08:53 -0700767}