blob: b20e661ffefda33c3bd48f40c88e0d77a705cad0 [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;
Michael Kolbfedb4922011-04-20 16:45:33 -070020import com.android.internal.view.menu.MenuBuilder;
John Reck30c714c2010-12-16 17:30:34 -080021
John Reck74830e12011-03-14 11:43:05 -070022import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070024import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.res.Configuration;
26import android.content.res.Resources;
27import android.graphics.Bitmap;
28import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.Color;
30import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070032import android.graphics.drawable.LayerDrawable;
33import android.graphics.drawable.PaintDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.os.Bundle;
35import android.text.TextUtils;
36import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.Gravity;
38import android.view.LayoutInflater;
39import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080041import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.webkit.WebView;
48import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080049import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.LinearLayout;
51import android.widget.Toast;
52
Michael Kolb1bf23132010-11-19 12:55:12 -080053import java.util.List;
54
Michael Kolb8233fac2010-10-26 16:08:53 -070055/**
56 * UI interface definitions
57 */
Michael Kolb66706532010-12-12 19:50:22 -080058public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070059
60 private static final String LOGTAG = "BaseUi";
61
Michael Kolb66706532010-12-12 19:50:22 -080062 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070063 new FrameLayout.LayoutParams(
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 ViewGroup.LayoutParams.MATCH_PARENT);
66
Michael Kolb66706532010-12-12 19:50:22 -080067 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070068 new FrameLayout.LayoutParams(
69 ViewGroup.LayoutParams.MATCH_PARENT,
70 ViewGroup.LayoutParams.MATCH_PARENT,
71 Gravity.CENTER);
72
73 Activity mActivity;
74 UiController mUiController;
75 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080076 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080077 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070078
79 private Drawable mSecLockIcon;
80 private Drawable mMixLockIcon;
Michael Kolb5a4372f2011-04-29 13:53:10 -070081 protected Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080084 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070085 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070086
87 private View mCustomView;
88 private WebChromeClient.CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040089 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070090
91 private CombinedBookmarkHistoryView mComboView;
92
93 private LinearLayout mErrorConsoleContainer = null;
94
95 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070096
Michael Kolb5a4372f2011-04-29 13:53:10 -070097
Michael Kolb8233fac2010-10-26 16:08:53 -070098 // the default <video> poster
99 private Bitmap mDefaultVideoPoster;
100 // the video progress view
101 private View mVideoProgressView;
102
Michael Kolb8233fac2010-10-26 16:08:53 -0700103 private boolean mActivityPaused;
104
105 public BaseUi(Activity browser, UiController controller) {
106 mActivity = browser;
107 mUiController = controller;
108 mTabControl = controller.getTabControl();
109 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800110 mInputManager = (InputMethodManager)
111 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800112 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700113 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
114
Michael Kolb8233fac2010-10-26 16:08:53 -0700115 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
116 .getDecorView().findViewById(android.R.id.content);
117 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
118 .inflate(R.layout.custom_screen, null);
119 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
120 R.id.main_content);
121 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
122 .findViewById(R.id.error_console);
123 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
124 .findViewById(R.id.fullscreen_custom_content);
125 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolbc38c6042011-04-27 10:46:06 -0700126 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700127 mGenericFavicon = res.getDrawable(
128 R.drawable.app_web_browser_sm);
Michael Kolb8233fac2010-10-26 16:08:53 -0700129 }
130
John Reckb9a051b2011-03-18 11:55:48 -0700131 @Override
132 public WebView createWebView(boolean privateBrowsing) {
133 // Create a new WebView
134 BrowserWebView w = new BrowserWebView(mActivity, null,
135 android.R.attr.webViewStyle, privateBrowsing);
136 initWebViewSettings(w);
137 return w;
138 }
139
140 @Override
141 public WebView createSubWebView(boolean privateBrowsing) {
142 return createWebView(privateBrowsing);
143 }
144
Michael Kolb66706532010-12-12 19:50:22 -0800145 /**
146 * common webview initialization
147 * @param w the webview to initialize
148 */
149 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700150 w.setScrollbarFadingEnabled(true);
151 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
152 w.setMapTrackballToArrowKeys(false); // use trackball directly
153 // Enable the built-in zoom
154 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700155 boolean supportsMultiTouch = mActivity.getPackageManager()
156 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
157 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
158 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700159
160 // Add this WebView to the settings observer list and update the
161 // settings
162 final BrowserSettings s = BrowserSettings.getInstance();
John Reck35e9dd62011-04-25 09:01:54 -0700163 s.startManagingSettings(w.getSettings());
Michael Kolb8233fac2010-10-26 16:08:53 -0700164 }
165
166 private void cancelStopToast() {
167 if (mStopToast != null) {
168 mStopToast.cancel();
169 mStopToast = null;
170 }
171 }
172
173 // lifecycle
174
175 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800176 if (isCustomViewShowing()) {
177 onHideCustomView();
178 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700179 cancelStopToast();
180 mActivityPaused = true;
181 }
182
183 public void onResume() {
184 mActivityPaused = false;
185 }
186
Michael Kolb66706532010-12-12 19:50:22 -0800187 protected boolean isActivityPaused() {
188 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 }
190
191 public void onConfigurationChanged(Configuration config) {
192 }
193
194 // key handling
195
196 @Override
197 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 if (mComboView != null) {
199 if (!mComboView.onBackPressed()) {
200 mUiController.removeComboView();
201 }
202 return true;
203 }
204 if (mCustomView != null) {
205 mUiController.hideCustomView();
206 return true;
207 }
208 return false;
209 }
210
Michael Kolb2814a362011-05-19 15:49:41 -0700211 @Override
212 public boolean onMenuKey() {
213 return false;
214 }
215
John Reck30c714c2010-12-16 17:30:34 -0800216 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 @Override
John Reck30c714c2010-12-16 17:30:34 -0800218 public void onTabDataChanged(Tab tab) {
219 setUrlTitle(tab);
220 setFavicon(tab);
221 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800222 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 }
224
225 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500226 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800227 if (tab.inForeground()) {
228 boolean isBookmark = tab.isBookmarkedSite();
229 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
230 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500231 }
232
233 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 public void onPageStopped(Tab tab) {
235 cancelStopToast();
236 if (tab.inForeground()) {
237 mStopToast = Toast
238 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
239 mStopToast.show();
240 }
241 }
242
243 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800244 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700245 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800246 }
247
248 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700250 }
251
252 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800253 public void setActiveTab(final Tab tab) {
254 setActiveTab(tab, true);
255 }
256
257 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800258 if ((tab != mActiveTab) && (mActiveTab != null)) {
259 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700260 }
Michael Kolb77df4562010-11-19 14:49:34 -0800261 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800262 if (needsAttaching) {
263 attachTabToContentView(tab);
264 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800266 onTabDataChanged(tab);
267 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800268 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800269 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500270 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 }
272
Michael Kolbcfa3af52010-12-14 10:36:11 -0800273 Tab getActiveTab() {
274 return mActiveTab;
275 }
276
Michael Kolb8233fac2010-10-26 16:08:53 -0700277 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800278 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800279 }
280
281 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700282 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800283 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700284 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800285 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700286 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700287 }
288
289 @Override
290 public void detachTab(Tab tab) {
291 removeTabFromContentView(tab);
292 }
293
294 @Override
295 public void attachTab(Tab tab) {
296 attachTabToContentView(tab);
297 }
298
Michael Kolb377ea312011-02-17 14:36:56 -0800299 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800300 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700301 return;
302 }
303 View container = tab.getViewContainer();
304 WebView mainView = tab.getWebView();
305 // Attach the WebView to the container and then attach the
306 // container to the content view.
307 FrameLayout wrapper =
308 (FrameLayout) container.findViewById(R.id.webview_wrapper);
309 ViewGroup parent = (ViewGroup) mainView.getParent();
310 if (parent != wrapper) {
311 if (parent != null) {
312 Log.w(LOGTAG, "mMainView already has a parent in"
313 + " attachTabToContentView!");
314 parent.removeView(mainView);
315 }
316 wrapper.addView(mainView);
317 } else {
318 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
319 + " attachTabToContentView!");
320 }
321 parent = (ViewGroup) container.getParent();
322 if (parent != mContentView) {
323 if (parent != null) {
324 Log.w(LOGTAG, "mContainer already has a parent in"
325 + " attachTabToContentView!");
326 parent.removeView(container);
327 }
328 mContentView.addView(container, COVER_SCREEN_PARAMS);
329 } else {
330 Log.w(LOGTAG, "mContainer is already attached to content in"
331 + " attachTabToContentView!");
332 }
333 mUiController.attachSubWindow(tab);
334 }
335
336 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800337 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700338 // Remove the container that contains the main WebView.
339 WebView mainView = tab.getWebView();
340 View container = tab.getViewContainer();
341 if (mainView == null) {
342 return;
343 }
344 // Remove the container from the content and then remove the
345 // WebView from the container. This will trigger a focus change
346 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800347 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700348 FrameLayout wrapper =
349 (FrameLayout) container.findViewById(R.id.webview_wrapper);
350 wrapper.removeView(mainView);
351 mContentView.removeView(container);
352 mUiController.endActionMode();
353 mUiController.removeSubWindow(tab);
354 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
355 if (errorConsole != null) {
356 mErrorConsoleContainer.removeView(errorConsole);
357 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700358 }
359
Michael Kolba713ec82010-11-29 17:27:06 -0800360 @Override
361 public void onSetWebView(Tab tab, WebView webView) {
362 View container = tab.getViewContainer();
363 if (container == null) {
364 // The tab consists of a container view, which contains the main
365 // WebView, as well as any other UI elements associated with the tab.
366 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
367 null);
368 tab.setViewContainer(container);
369 }
370 if (tab.getWebView() != webView) {
371 // Just remove the old one.
372 FrameLayout wrapper =
373 (FrameLayout) container.findViewById(R.id.webview_wrapper);
374 wrapper.removeView(tab.getWebView());
375 }
376 }
377
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800379 * create a sub window container and webview for the tab
380 * Note: this methods operates through side-effects for now
381 * it sets both the subView and subViewContainer for the given tab
382 * @param tab tab to create the sub window for
383 * @param subView webview to be set as a subwindow for the tab
384 */
385 @Override
386 public void createSubWindow(Tab tab, WebView subView) {
387 View subViewContainer = mActivity.getLayoutInflater().inflate(
388 R.layout.browser_subwindow, null);
389 ViewGroup inner = (ViewGroup) subViewContainer
390 .findViewById(R.id.inner_container);
391 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
392 LayoutParams.MATCH_PARENT));
393 final ImageButton cancel = (ImageButton) subViewContainer
394 .findViewById(R.id.subwindow_close);
395 final WebView cancelSubView = subView;
396 cancel.setOnClickListener(new OnClickListener() {
397 public void onClick(View v) {
398 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
399 }
400 });
401 tab.setSubWebView(subView);
402 tab.setSubViewContainer(subViewContainer);
403 }
404
405 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700406 * Remove the sub window from the content view.
407 */
408 @Override
409 public void removeSubWindow(View subviewContainer) {
410 mContentView.removeView(subviewContainer);
411 mUiController.endActionMode();
412 }
413
414 /**
415 * Attach the sub window to the content view.
416 */
417 @Override
418 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800419 if (container.getParent() != null) {
420 // already attached, remove first
421 ((ViewGroup) container.getParent()).removeView(container);
422 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700423 mContentView.addView(container, COVER_SCREEN_PARAMS);
424 }
425
Michael Kolb11d19782011-03-20 10:17:40 -0700426 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700427 WebView web = getWebView();
428 if (web != null) {
429 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700430 }
431 }
432
Michael Kolb46f987e2011-04-05 10:39:10 -0700433 public void editUrl(boolean clearInput) {
434 if (mUiController.isInCustomActionMode()) {
435 mUiController.endActionMode();
436 }
437 showTitleBar();
438 getTitleBar().startEditingUrl(clearInput);
439 }
440
Michael Kolb7cdc4902011-02-03 17:54:40 -0800441 boolean canShowTitleBar() {
442 return !isTitleBarShowing()
443 && !isActivityPaused()
444 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700445 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800446 && !mUiController.isInCustomActionMode();
447 }
448
449 void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700450 if (canShowTitleBar()) {
451 getTitleBar().show();
452 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800453 }
454
455 protected void hideTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700456 if (getTitleBar().isShowing()) {
457 getTitleBar().hide();
458 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800459 }
460
461 protected boolean isTitleBarShowing() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700462 return getTitleBar().isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800463 }
464
465 protected abstract TitleBarBase getTitleBar();
466
467 protected void setTitleGravity(int gravity) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700468 WebView web = getWebView();
469 if (web != null) {
470 web.setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700471 }
472 }
473
Michael Kolb66706532010-12-12 19:50:22 -0800474 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700475 public void showVoiceTitleBar(String title, List<String> results) {
476 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800477 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700478 }
479
Michael Kolb66706532010-12-12 19:50:22 -0800480 @Override
481 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700482 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800483 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800484 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700485 }
486
487 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700488 public void registerDropdownChangeListener(DropdownChangeListener d) {
489 getTitleBar().registerDropdownChangeListener(d);
490 }
491
492 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700493 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800494 if (mComboView != null) {
495 return;
496 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700497 mComboView = new CombinedBookmarkHistoryView(mActivity,
498 mUiController,
499 startWithHistory ?
500 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
501 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
502 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800503 FrameLayout wrapper =
504 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
505 wrapper.setVisibility(View.GONE);
Michael Kolbc16c5952011-03-29 15:37:03 -0700506 getTitleBar().stopEditingUrl();
Michael Kolb3a696282010-12-05 13:23:24 -0800507 dismissIME();
Michael Kolbc16c5952011-03-29 15:37:03 -0700508 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800509 if (mActiveTab != null) {
510 WebView web = mActiveTab.getWebView();
511 mActiveTab.putInBackground();
512 }
John Reck74830e12011-03-14 11:43:05 -0700513 mComboView.setAlpha(0f);
514 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
515 Resources res = mActivity.getResources();
516 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
517 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700518 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
519 }
520
Michael Kolbba238702011-03-08 10:40:50 -0800521 public boolean isComboViewShowing() {
522 return (mComboView != null);
523 }
524
Michael Kolb8233fac2010-10-26 16:08:53 -0700525 /**
526 * dismiss the ComboPage
527 */
528 @Override
529 public void hideComboView() {
530 if (mComboView != null) {
531 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800532 FrameLayout wrapper =
533 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
534 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700535 mComboView = null;
536 }
Michael Kolb3a696282010-12-05 13:23:24 -0800537 if (mActiveTab != null) {
538 mActiveTab.putInForeground();
539 }
John Reckb3417f02011-01-14 11:01:05 -0800540 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700541 }
542
543 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400544 public void showCustomView(View view, int requestedOrientation,
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 WebChromeClient.CustomViewCallback callback) {
546 // if a view already exists then immediately terminate the new one
547 if (mCustomView != null) {
548 callback.onCustomViewHidden();
549 return;
550 }
551
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400552 mOriginalOrientation = mActivity.getRequestedOrientation();
553
Michael Kolb8233fac2010-10-26 16:08:53 -0700554 // Add the custom view to its container.
555 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
556 mCustomView = view;
557 mCustomViewCallback = callback;
558 // Hide the content view.
559 mContentView.setVisibility(View.GONE);
560 // Finally show the custom view container.
561 setStatusBarVisibility(false);
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400562 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700563 mCustomViewContainer.setVisibility(View.VISIBLE);
564 mCustomViewContainer.bringToFront();
565 }
566
567 @Override
568 public void onHideCustomView() {
569 if (mCustomView == null)
570 return;
571
572 // Hide the custom view.
573 mCustomView.setVisibility(View.GONE);
574 // Remove the custom view from its container.
575 mCustomViewContainer.removeView(mCustomView);
576 mCustomView = null;
577 mCustomViewContainer.setVisibility(View.GONE);
578 mCustomViewCallback.onCustomViewHidden();
579 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400580 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700581 setStatusBarVisibility(true);
582 mContentView.setVisibility(View.VISIBLE);
583 }
584
585 @Override
586 public boolean isCustomViewShowing() {
587 return mCustomView != null;
588 }
589
Michael Kolb66706532010-12-12 19:50:22 -0800590 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800591 if (mInputManager.isActive()) {
592 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
593 0);
594 }
595 }
596
Michael Kolb66706532010-12-12 19:50:22 -0800597 @Override
598 public boolean showsWeb() {
599 return mCustomView == null
600 && mComboView == null;
601 }
602
Patrick Scott92066772011-03-10 08:46:27 -0500603 @Override
604 public void showAutoLogin(Tab tab) {
605 updateAutoLogin(tab, true);
606 }
607
608 @Override
609 public void hideAutoLogin(Tab tab) {
610 updateAutoLogin(tab, true);
611 }
612
Michael Kolb8233fac2010-10-26 16:08:53 -0700613 // -------------------------------------------------------------------------
614
Michael Kolb5a72f182011-01-13 20:35:06 -0800615 protected void updateNavigationState(Tab tab) {
616 }
617
Michael Kolb11d19782011-03-20 10:17:40 -0700618 protected void updateAutoLogin(Tab tab, boolean animate) {
619 getTitleBar().updateAutoLogin(tab, animate);
620 }
Patrick Scott92066772011-03-10 08:46:27 -0500621
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 /**
623 * Update the lock icon to correspond to our latest state.
624 */
Michael Kolb66706532010-12-12 19:50:22 -0800625 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800626 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700627 updateLockIconImage(t.getLockIconType());
628 }
629 }
630
631 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700632 * Updates the lock-icon image in the title-bar.
633 */
John Reck30c714c2010-12-16 17:30:34 -0800634 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800636 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700637 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800638 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 d = mMixLockIcon;
640 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800641 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 }
643
John Reck30c714c2010-12-16 17:30:34 -0800644 protected void setUrlTitle(Tab tab) {
645 String url = tab.getUrl();
646 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800647 if (TextUtils.isEmpty(title)) {
648 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800649 }
Michael Kolb66706532010-12-12 19:50:22 -0800650 if (tab.isInVoiceSearchMode()) return;
651 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800652 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800653 }
654 }
655
656 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800657 protected void setFavicon(Tab tab) {
658 if (tab.inForeground()) {
659 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800660 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800661 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 }
663
664 @Override
665 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700666 }
667
Michael Kolb66706532010-12-12 19:50:22 -0800668 // active tabs page
669
670 public void showActiveTabsPage() {
671 }
672
673 /**
674 * Remove the active tabs page.
675 */
676 public void removeActiveTabsPage() {
677 }
678
Michael Kolb8233fac2010-10-26 16:08:53 -0700679 // menu handling callbacks
680
681 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800682 public boolean onPrepareOptionsMenu(Menu menu) {
683 return true;
684 }
685
686 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700687 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700688 }
689
690 @Override
691 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700692 }
693
694 @Override
695 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700696 }
697
698 @Override
699 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 }
701
702 @Override
703 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 }
705
706 @Override
707 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700708 }
709
710 // error console
711
712 @Override
713 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800714 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700715 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
716 if (flag) {
717 // Setting the show state of the console will cause it's the layout
718 // to be inflated.
719 if (errorConsole.numberOfErrors() > 0) {
720 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
721 } else {
722 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
723 }
724 if (errorConsole.getParent() != null) {
725 mErrorConsoleContainer.removeView(errorConsole);
726 }
727 // Now we can add it to the main view.
728 mErrorConsoleContainer.addView(errorConsole,
729 new LinearLayout.LayoutParams(
730 ViewGroup.LayoutParams.MATCH_PARENT,
731 ViewGroup.LayoutParams.WRAP_CONTENT));
732 } else {
733 mErrorConsoleContainer.removeView(errorConsole);
734 }
735 }
736
737 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800738 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
739 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
740 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700741 }
742
Michael Kolb8233fac2010-10-26 16:08:53 -0700743 // -------------------------------------------------------------------------
744 // Helper function for WebChromeClient
745 // -------------------------------------------------------------------------
746
747 @Override
748 public Bitmap getDefaultVideoPoster() {
749 if (mDefaultVideoPoster == null) {
750 mDefaultVideoPoster = BitmapFactory.decodeResource(
751 mActivity.getResources(), R.drawable.default_video_poster);
752 }
753 return mDefaultVideoPoster;
754 }
755
756 @Override
757 public View getVideoLoadingProgressView() {
758 if (mVideoProgressView == null) {
759 LayoutInflater inflater = LayoutInflater.from(mActivity);
760 mVideoProgressView = inflater.inflate(
761 R.layout.video_loading_progress, null);
762 }
763 return mVideoProgressView;
764 }
765
Michael Kolb843510f2010-12-09 10:51:49 -0800766 @Override
767 public void showMaxTabsWarning() {
768 Toast warning = Toast.makeText(mActivity,
769 mActivity.getString(R.string.max_tabs_warning),
770 Toast.LENGTH_SHORT);
771 warning.show();
772 }
773
Michael Kolbfdb70242011-03-24 09:41:11 -0700774 protected void captureTab(final Tab tab) {
775 captureTab(tab,
776 (int) mActivity.getResources()
777 .getDimension(R.dimen.qc_thumb_width),
778 (int) mActivity.getResources()
779 .getDimension(R.dimen.qc_thumb_height));
780 }
781
782 protected void captureTab(final Tab tab, int width, int height) {
783 if ((tab == null) || (tab.getWebView() == null)) return;
784 Bitmap sshot = Controller.createScreenshot(tab, width, height);
785 tab.setScreenshot(sshot);
786 }
787
Michael Kolb46f987e2011-04-05 10:39:10 -0700788 protected WebView getWebView() {
789 if (mActiveTab != null) {
790 return mActiveTab.getWebView();
791 } else {
792 return null;
793 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700794 }
795
Michael Kolbfedb4922011-04-20 16:45:33 -0700796 protected Menu getMenu() {
797 MenuBuilder menu = new MenuBuilder(mActivity);
798 mActivity.getMenuInflater().inflate(R.menu.browser, menu);
799 return menu;
800 }
801
Michael Kolbc38c6042011-04-27 10:46:06 -0700802 public void setFullscreen(boolean enabled) {
803 if (enabled) {
804 mActivity.getWindow().setFlags(
805 WindowManager.LayoutParams.FLAG_FULLSCREEN,
806 WindowManager.LayoutParams.FLAG_FULLSCREEN);
807 } else {
808 mActivity.getWindow().clearFlags(
809 WindowManager.LayoutParams.FLAG_FULLSCREEN);
810 }
811 }
812
Michael Kolb5a4372f2011-04-29 13:53:10 -0700813 protected Drawable getFaviconDrawable(Bitmap icon) {
814 Drawable[] array = new Drawable[3];
815 array[0] = new PaintDrawable(Color.BLACK);
816 PaintDrawable p = new PaintDrawable(Color.WHITE);
817 array[1] = p;
818 if (icon == null) {
819 array[2] = mGenericFavicon;
820 } else {
821 array[2] = new BitmapDrawable(icon);
822 }
823 LayerDrawable d = new LayerDrawable(array);
824 d.setLayerInset(1, 1, 1, 1, 1);
825 d.setLayerInset(2, 2, 2, 2, 2);
826 return d;
827 }
828
Michael Kolb8233fac2010-10-26 16:08:53 -0700829}