John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 16 | package com.android.browser; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 17 | |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 18 | import android.animation.ArgbEvaluator; |
| 19 | import android.animation.ValueAnimator; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 20 | import android.app.Activity; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 21 | import android.app.SearchManager; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 22 | import android.content.ActivityNotFoundException; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 25 | import android.content.SharedPreferences; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 26 | import android.graphics.Bitmap; |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 27 | import android.graphics.BitmapFactory; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 28 | import android.graphics.Color; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 29 | import android.net.Uri; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 30 | import android.net.http.SslCertificate; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 31 | import android.os.Build; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 32 | import android.os.Bundle; |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
| 34 | import android.os.Message; |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 35 | import android.text.Editable; |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 36 | import android.text.TextUtils; |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 37 | import android.text.TextWatcher; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 38 | import android.util.AttributeSet; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 39 | import android.util.Log; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 40 | import android.view.KeyEvent; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 41 | import android.view.Menu; |
| 42 | import android.view.MenuItem; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 43 | import android.view.View; |
| 44 | import android.view.View.OnClickListener; |
| 45 | import android.view.View.OnFocusChangeListener; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 46 | import android.widget.ImageView; |
| 47 | import android.widget.LinearLayout; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 48 | import android.widget.PopupMenu; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 49 | import android.widget.Toast; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 50 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 51 | import com.android.browser.UrlInputView.UrlInputListener; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 52 | import com.android.browser.preferences.SiteSpecificPreferencesFragment; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 53 | |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 54 | import java.io.ByteArrayOutputStream; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 55 | import java.io.UnsupportedEncodingException; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 56 | import java.net.MalformedURLException; |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 57 | import java.net.URISyntaxException; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 58 | import java.net.URL; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 59 | |
Dany Rybnikov | bcd37da | 2015-04-20 11:43:15 +0300 | [diff] [blame] | 60 | import org.codeaurora.net.NetworkServices; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 61 | import org.codeaurora.swe.WebRefiner; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 62 | import org.codeaurora.swe.WebView; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 63 | import org.codeaurora.swe.util.ColorUtils; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 64 | |
John Reck | 42229bc | 2011-08-19 13:26:43 -0700 | [diff] [blame] | 65 | public class NavigationBarBase extends LinearLayout implements |
| 66 | OnClickListener, UrlInputListener, OnFocusChangeListener, |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 67 | TextWatcher, UrlInputView.StateListener, |
| 68 | PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 69 | |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 70 | private final static String TAG = "NavigationBarBase"; |
| 71 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 72 | protected BaseUi mBaseUi; |
| 73 | protected TitleBar mTitleBar; |
| 74 | protected UiController mUiController; |
| 75 | protected UrlInputView mUrlInput; |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 76 | protected ImageView mStopButton; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 77 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 78 | private SiteTileView mFaviconTile; |
jrizzoli | a62318b | 2015-09-08 21:44:50 +0200 | [diff] [blame] | 79 | private View mSeparator; |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 80 | private View mVoiceButton; |
| 81 | private ImageView mClearButton; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 82 | private View mMore; |
| 83 | private PopupMenu mPopupMenu; |
| 84 | private boolean mOverflowMenuShowing; |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 85 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 86 | private static Bitmap mDefaultFavicon; |
| 87 | |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 88 | private int mStatusBarColor; |
| 89 | private static int mDefaultStatusBarColor = -1; |
| 90 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 91 | private static final int WEBREFINER_COUNTER_MSG = 4242; |
| 92 | private static final int WEBREFINER_COUNTER_MSG_DELAY = 3000; |
| 93 | private Handler mHandler; |
| 94 | |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 95 | protected int mTrustLevel = SiteTileView.TRUST_UNKNOWN; |
| 96 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 97 | private static final String noSitePrefs[] = { |
Axesh R. Ajmera | 6fc7369 | 2015-08-11 16:32:10 -0700 | [diff] [blame] | 98 | "chrome://", |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 99 | "about:", |
| 100 | "content:", |
| 101 | }; |
| 102 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 103 | public NavigationBarBase(Context context) { |
| 104 | super(context); |
| 105 | } |
| 106 | |
| 107 | public NavigationBarBase(Context context, AttributeSet attrs) { |
| 108 | super(context, attrs); |
| 109 | } |
| 110 | |
| 111 | public NavigationBarBase(Context context, AttributeSet attrs, int defStyle) { |
| 112 | super(context, attrs, defStyle); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | protected void onFinishInflate() { |
| 117 | super.onFinishInflate(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 118 | mUrlInput = (UrlInputView) findViewById(R.id.url); |
| 119 | mUrlInput.setUrlInputListener(this); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 120 | mUrlInput.setOnFocusChangeListener(this); |
| 121 | mUrlInput.setSelectAllOnFocus(true); |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 122 | mUrlInput.addTextChangedListener(this); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 123 | mMore = findViewById(R.id.more_browser_settings); |
| 124 | mMore.setOnClickListener(this); |
jrizzoli | a62318b | 2015-09-08 21:44:50 +0200 | [diff] [blame] | 125 | mSeparator = findViewById(R.id.separator); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 126 | mFaviconTile = (SiteTileView) findViewById(R.id.favicon_view); |
| 127 | mFaviconTile.setOnClickListener(this); |
| 128 | mVoiceButton = findViewById(R.id.voice); |
| 129 | mVoiceButton.setOnClickListener(this); |
| 130 | mClearButton = (ImageView) findViewById(R.id.clear); |
| 131 | mClearButton.setOnClickListener(this); |
| 132 | mStopButton = (ImageView) findViewById(R.id.stop); |
| 133 | mStopButton.setOnClickListener(this); |
| 134 | |
| 135 | mDefaultFavicon = BitmapFactory.decodeResource(getResources(), |
| 136 | R.drawable.ic_deco_favicon_normal); |
| 137 | |
| 138 | mHandler = new Handler() { |
| 139 | @Override |
| 140 | public void handleMessage(Message m) { |
| 141 | switch (m.what) { |
| 142 | case WEBREFINER_COUNTER_MSG: |
| 143 | WebView wv = mUiController.getCurrentTopWebView(); |
| 144 | if (wv != null && WebRefiner.isInitialized()) { |
| 145 | int count = WebRefiner.getInstance().getBlockedURLCount(wv); |
| 146 | if (count > 0) { |
Pankaj Garg | 07b2fd9 | 2015-07-15 12:07:37 -0700 | [diff] [blame] | 147 | mFaviconTile.setBadgeBlockedObjectsCount(count); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | mHandler.sendEmptyMessageDelayed(WEBREFINER_COUNTER_MSG, |
| 151 | WEBREFINER_COUNTER_MSG_DELAY); |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | }; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | public void setTitleBar(TitleBar titleBar) { |
| 159 | mTitleBar = titleBar; |
| 160 | mBaseUi = mTitleBar.getUi(); |
| 161 | mUiController = mTitleBar.getUiController(); |
Michael Kolb | b2e91fd | 2011-07-14 13:47:29 -0700 | [diff] [blame] | 162 | mUrlInput.setController(mUiController); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 165 | public void setSecurityState(Tab.SecurityState securityState) { |
Pankaj Garg | 96d0ccd | 2015-07-30 16:49:47 -0700 | [diff] [blame] | 166 | switch (securityState) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 167 | case SECURITY_STATE_SECURE: |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 168 | mTrustLevel = SiteTileView.TRUST_TRUSTED; |
Pankaj Garg | 07b2fd9 | 2015-07-15 12:07:37 -0700 | [diff] [blame] | 169 | mFaviconTile.setBadgeHasCertIssues(false); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 170 | break; |
| 171 | case SECURITY_STATE_MIXED: |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 172 | mTrustLevel = SiteTileView.TRUST_UNTRUSTED; |
Pankaj Garg | 07b2fd9 | 2015-07-15 12:07:37 -0700 | [diff] [blame] | 173 | mFaviconTile.setBadgeHasCertIssues(true); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 174 | mTitleBar.showTopControls(false); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 175 | break; |
| 176 | case SECURITY_STATE_BAD_CERTIFICATE: |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 177 | mTrustLevel = SiteTileView.TRUST_AVOID; |
Pankaj Garg | 07b2fd9 | 2015-07-15 12:07:37 -0700 | [diff] [blame] | 178 | mFaviconTile.setBadgeHasCertIssues(true); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 179 | mTitleBar.showTopControls(false); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 180 | break; |
| 181 | case SECURITY_STATE_NOT_SECURE: |
| 182 | default: |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 183 | mTrustLevel = SiteTileView.TRUST_UNKNOWN; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 184 | } |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 185 | mFaviconTile.setTrustLevel(mTrustLevel); |
| 186 | } |
| 187 | |
| 188 | public int getTrustLevel() { |
| 189 | return mTrustLevel; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 192 | public static int adjustColor(int color, float hueMultiplier, |
| 193 | float saturationMultiplier, float valueMultiplier) { |
| 194 | float[] hsv = new float[3]; |
| 195 | Color.colorToHSV(color, hsv); |
| 196 | hsv[0] *= hueMultiplier; |
| 197 | hsv[1] *= saturationMultiplier; |
| 198 | hsv[2] *= valueMultiplier; |
| 199 | return Color.HSVToColor(Color.alpha(color), hsv); |
| 200 | } |
| 201 | |
| 202 | public static void setStatusAndNavigationBarColor(final Activity activity, int color) { |
Sagar Dhawan | eecefa3 | 2015-09-25 12:02:34 -0700 | [diff] [blame] | 203 | // The flag that allows coloring is disabled in PowerSaveMode, no point in trying to color. |
| 204 | if (BrowserSettings.getInstance().isPowerSaveModeEnabled()) |
| 205 | return; |
jrizzoli | be2afc5 | 2015-10-28 18:43:00 +0100 | [diff] [blame] | 206 | // Disable colored statusbar if user asked so |
| 207 | if (! BrowserSettings.getInstance().isColoredSBEnabled()) |
| 208 | return; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 209 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 210 | int currentColor = activity.getWindow().getStatusBarColor(); |
| 211 | Integer from = currentColor; |
| 212 | Integer to = color; |
| 213 | ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), from, to); |
| 214 | |
| 215 | if (mDefaultStatusBarColor == -1) { |
| 216 | mDefaultStatusBarColor = activity.getWindow().getStatusBarColor(); |
| 217 | } |
| 218 | |
| 219 | animator.addUpdateListener( |
| 220 | new ValueAnimator.AnimatorUpdateListener() { |
| 221 | @Override |
| 222 | public void onAnimationUpdate(ValueAnimator animation) { |
| 223 | Integer value = (Integer) animation.getAnimatedValue(); |
| 224 | activity.getWindow().setStatusBarColor(value.intValue()); |
| 225 | //activity.getWindow().setNavigationBarColor(value.intValue()); |
| 226 | } |
| 227 | } |
| 228 | ); |
| 229 | animator.start(); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | private void updateSiteIconColor(String urlString, int color) { |
| 234 | try { |
| 235 | URL url = new URL(urlString); |
| 236 | String host = url.getHost(); |
| 237 | SharedPreferences prefs = BrowserSettings.getInstance().getPreferences(); |
| 238 | int currentColor = prefs.getInt(host + ":color", 0); |
| 239 | if (currentColor != color) { |
| 240 | SharedPreferences.Editor editor = prefs.edit(); |
| 241 | editor.remove(host + ":color"); |
| 242 | editor.putInt(host + ":color", color); |
| 243 | editor.commit(); |
| 244 | } |
| 245 | } catch (MalformedURLException e) { |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | public static int getSiteIconColor(String urlString) { |
| 250 | try { |
| 251 | URL url = new URL(urlString); |
| 252 | String host = url.getHost(); |
| 253 | SharedPreferences prefs = BrowserSettings.getInstance().getPreferences(); |
| 254 | return prefs.getInt(host + ":color", 0); |
| 255 | } catch (MalformedURLException e) { |
| 256 | return 0; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | public static int getDefaultStatusBarColor() { |
| 261 | return mDefaultStatusBarColor; |
| 262 | } |
| 263 | |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 264 | // Sets the favicon for the given tab if it's in the foreground |
| 265 | // If the tab doesn't have a favicon, it sets the default favicon |
| 266 | public void showCurrentFavicon(Tab tab) { |
| 267 | int color; |
| 268 | if (tab == null) { return; } |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 269 | |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 270 | if (tab.inForeground()) { |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 271 | if (tab.hasFavicon()) { |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 272 | color = ColorUtils.getDominantColorForBitmap(tab.getFavicon()); |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 273 | updateSiteIconColor(tab.getUrl(), color); |
| 274 | setStatusAndNavigationBarColor(mUiController.getActivity(), |
| 275 | adjustColor(color, 1, 1, 0.7f)); |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 276 | |
| 277 | } else { |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 278 | color = getSiteIconColor(tab.getUrl()); |
| 279 | if (color != 0) { |
| 280 | setStatusAndNavigationBarColor(mUiController.getActivity(), |
| 281 | adjustColor(color, 1, 1, 0.7f)); |
| 282 | } else { |
| 283 | setStatusAndNavigationBarColor(mUiController.getActivity(), |
| 284 | mDefaultStatusBarColor); |
| 285 | } |
| 286 | } |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 287 | if (mFaviconTile != null) { |
| 288 | mFaviconTile.replaceFavicon(tab.getFavicon()); // Always set the tab's favicon |
| 289 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 290 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 293 | protected void showSiteSpecificSettings() { |
| 294 | WebView wv = mUiController.getCurrentTopWebView(); |
Pankaj Garg | dbdf5aa | 2015-07-16 15:22:37 -0700 | [diff] [blame] | 295 | int ads = 0; |
| 296 | int tracker = 0; |
| 297 | int malware = 0; |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 298 | |
Pankaj Garg | dbdf5aa | 2015-07-16 15:22:37 -0700 | [diff] [blame] | 299 | WebRefiner webRefiner = WebRefiner.getInstance(); |
| 300 | if (wv != null && webRefiner != null) { |
| 301 | WebRefiner.PageInfo pageInfo = webRefiner.getPageInfo(wv); |
| 302 | if (pageInfo != null) { |
| 303 | for (WebRefiner.MatchedURLInfo urlInfo : pageInfo.mMatchedURLInfoList) { |
Pankaj Garg | ee99203 | 2015-07-24 15:59:36 -0700 | [diff] [blame] | 304 | if (urlInfo.mActionTaken == WebRefiner.MatchedURLInfo.ACTION_BLOCKED) { |
| 305 | switch (urlInfo.mMatchedFilterCategory) { |
| 306 | case WebRefiner.RuleSet.CATEGORY_ADS: |
| 307 | ads++; |
| 308 | break; |
| 309 | case WebRefiner.RuleSet.CATEGORY_TRACKERS: |
| 310 | tracker++; |
| 311 | break; |
| 312 | case WebRefiner.RuleSet.CATEGORY_MALWARE_DOMAINS: |
| 313 | malware++; |
| 314 | break; |
| 315 | } |
Pankaj Garg | dbdf5aa | 2015-07-16 15:22:37 -0700 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | Bundle bundle = new Bundle(); |
| 322 | bundle.putCharSequence(SiteSpecificPreferencesFragment.EXTRA_SITE, |
| 323 | mUiController.getCurrentTab().getUrl()); |
Sagar Dhawan | e28023a | 2015-08-13 16:40:25 -0700 | [diff] [blame] | 324 | bundle.putCharSequence(SiteSpecificPreferencesFragment.EXTRA_SITE_TITLE, |
| 325 | mUiController.getCurrentTab().getTitle()); |
Pankaj Garg | dbdf5aa | 2015-07-16 15:22:37 -0700 | [diff] [blame] | 326 | bundle.putInt(SiteSpecificPreferencesFragment.EXTRA_WEB_REFINER_ADS_INFO, ads); |
| 327 | bundle.putInt(SiteSpecificPreferencesFragment.EXTRA_WEB_REFINER_TRACKER_INFO, tracker); |
| 328 | bundle.putInt(SiteSpecificPreferencesFragment.EXTRA_WEB_REFINER_MALWARE_INFO, malware); |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 329 | |
| 330 | bundle.putParcelable(SiteSpecificPreferencesFragment.EXTRA_SECURITY_CERT, |
| 331 | SslCertificate.saveState(wv.getCertificate())); |
| 332 | |
Pankaj Garg | 96d0ccd | 2015-07-30 16:49:47 -0700 | [diff] [blame] | 333 | Tab.SecurityState securityState = Tab.getWebViewSecurityState( |
| 334 | mUiController.getCurrentTab().getWebView()); |
| 335 | if (securityState == Tab.SecurityState.SECURITY_STATE_MIXED) { |
| 336 | bundle.putBoolean(SiteSpecificPreferencesFragment.EXTRA_SECURITY_CERT_MIXED, true); |
| 337 | } else if (securityState == Tab.SecurityState.SECURITY_STATE_BAD_CERTIFICATE) { |
| 338 | bundle.putBoolean(SiteSpecificPreferencesFragment.EXTRA_SECURITY_CERT_BAD, true); |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Pankaj Garg | 68faf1c | 2015-06-26 17:07:37 -0700 | [diff] [blame] | 341 | Bitmap favicon = mUiController.getCurrentTopWebView().getFavicon(); |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 342 | if (favicon != null) { |
| 343 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 344 | favicon.compress(Bitmap.CompressFormat.PNG, 100, baos); |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 345 | bundle.putByteArray(SiteSpecificPreferencesFragment.EXTRA_FAVICON, |
| 346 | baos.toByteArray()); |
| 347 | } |
| 348 | BrowserPreferencesPage.startPreferenceFragmentExtraForResult( |
Pankaj Garg | 75273bb | 2015-08-20 11:43:49 -0700 | [diff] [blame] | 349 | mUiController.getActivity(), SiteSpecificPreferencesFragment.class.getName(), |
| 350 | bundle, Controller.PREFERENCES_PAGE); |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 351 | } |
| 352 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 353 | @Override |
| 354 | public void onClick(View v) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 355 | Tab currentTab = mUiController.getCurrentTab(); |
| 356 | String url = null; |
Sagar Dhawan | 20b1deb | 2015-10-12 11:13:18 -0700 | [diff] [blame] | 357 | WebView wv = null; |
| 358 | if (currentTab != null) { |
| 359 | wv = currentTab.getWebView(); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 360 | url = currentTab.getUrl(); |
| 361 | } |
Sagar Dhawan | 20b1deb | 2015-10-12 11:13:18 -0700 | [diff] [blame] | 362 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 363 | if (mMore == v) { |
| 364 | showMenu(mMore); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 365 | } else if (mFaviconTile == v) { |
Vivek Sekhar | ae3b179 | 2015-08-03 12:26:41 -0700 | [diff] [blame] | 366 | if (urlHasSitePrefs(url) && (wv != null && !wv.isShowingInterstitialPage()) ){ |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 367 | showSiteSpecificSettings(); |
| 368 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 369 | } else if (mVoiceButton == v) { |
| 370 | mUiController.startVoiceRecognizer(); |
| 371 | } else if (mStopButton == v) { |
| 372 | stopOrRefresh(); |
| 373 | } else if (mClearButton == v) { |
| 374 | clearOrClose(); |
| 375 | mUrlInput.setText(""); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | private static boolean urlHasSitePrefs(String url) { |
| 380 | if (TextUtils.isEmpty(url)) { |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | for (int i = 0; i < noSitePrefs.length; i++) { |
| 385 | if (url.startsWith(noSitePrefs[i])) { |
| 386 | return false; |
| 387 | } |
| 388 | } |
| 389 | return true; |
| 390 | } |
| 391 | |
| 392 | private void stopOrRefresh() { |
| 393 | if (mUiController == null) return; |
| 394 | if (mTitleBar.isInLoad()) { |
| 395 | mUiController.stopLoading(); |
| 396 | } else { |
| 397 | if (mUiController.getCurrentTopWebView() != null) { |
| 398 | stopEditingUrl(); |
| 399 | mUiController.getCurrentTopWebView().reload(); |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | private void clearOrClose() { |
| 405 | if (TextUtils.isEmpty(mUrlInput.getText())) { |
| 406 | // close |
| 407 | mUrlInput.clearFocus(); |
| 408 | } else { |
| 409 | // clear |
| 410 | mUrlInput.setText(""); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | void showMenu(View anchor) { |
| 415 | Activity activity = mUiController.getActivity(); |
| 416 | if (mPopupMenu == null) { |
| 417 | mPopupMenu = new PopupMenu(getContext(), anchor); |
| 418 | mPopupMenu.setOnMenuItemClickListener(this); |
| 419 | mPopupMenu.setOnDismissListener(this); |
| 420 | if (!activity.onCreateOptionsMenu(mPopupMenu.getMenu())) { |
| 421 | mPopupMenu = null; |
| 422 | return; |
| 423 | } |
| 424 | } |
| 425 | Menu menu = mPopupMenu.getMenu(); |
| 426 | |
| 427 | if (mUiController instanceof Controller) { |
| 428 | Controller controller = (Controller) mUiController; |
| 429 | if (controller.onPrepareOptionsMenu(menu)) { |
| 430 | mOverflowMenuShowing = true; |
| 431 | } |
| 432 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | @Override |
| 436 | public void onFocusChange(View view, boolean hasFocus) { |
| 437 | // if losing focus and not in touch mode, leave as is |
| 438 | if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) { |
| 439 | setFocusState(hasFocus); |
| 440 | } |
| 441 | if (hasFocus) { |
| 442 | mBaseUi.showTitleBar(); |
Dany Rybnikov | bcd37da | 2015-04-20 11:43:15 +0300 | [diff] [blame] | 443 | if (!BrowserSettings.getInstance().isPowerSaveModeEnabled()) { |
| 444 | //Notify about anticipated network activity |
| 445 | NetworkServices.hintUpcomingUserActivity(); |
| 446 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 447 | } else if (!mUrlInput.needsUpdate()) { |
| 448 | mUrlInput.dismissDropDown(); |
| 449 | mUrlInput.hideIME(); |
| 450 | if (mUrlInput.getText().length() == 0) { |
| 451 | Tab currentTab = mUiController.getTabControl().getCurrentTab(); |
| 452 | if (currentTab != null) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 453 | setDisplayTitle(currentTab.getTitle(), currentTab.getUrl()); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 454 | } |
| 455 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 456 | } |
| 457 | mUrlInput.clearNeedsUpdate(); |
| 458 | } |
| 459 | |
| 460 | protected void setFocusState(boolean focus) { |
| 461 | } |
| 462 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 463 | public boolean isEditingUrl() { |
| 464 | return mUrlInput.hasFocus(); |
| 465 | } |
| 466 | |
| 467 | void stopEditingUrl() { |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 468 | WebView currentTopWebView = mUiController.getCurrentTopWebView(); |
| 469 | if (currentTopWebView != null) { |
| 470 | currentTopWebView.requestFocus(); |
| 471 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 474 | void setDisplayTitle(String title, String url) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 475 | if (!isEditingUrl()) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 476 | if (!TextUtils.isEmpty(title)) { |
| 477 | if (mTrustLevel == SiteTileView.TRUST_TRUSTED) { |
| 478 | if (!title.equals(mUrlInput.getText().toString())) { |
| 479 | mUrlInput.setText(title, false); |
| 480 | } |
| 481 | return; |
| 482 | } |
| 483 | } |
| 484 | if (!url.equals(mUrlInput.getText().toString())) { |
| 485 | mUrlInput.setText(url, false); |
Michael Kolb | 29aab40 | 2012-05-29 17:22:35 -0700 | [diff] [blame] | 486 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 490 | void setIncognitoMode(boolean incognito) { |
| 491 | mUrlInput.setIncognitoMode(incognito); |
| 492 | } |
| 493 | |
| 494 | void clearCompletions() { |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 495 | mUrlInput.dismissDropDown(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | // UrlInputListener implementation |
| 499 | |
| 500 | /** |
| 501 | * callback from suggestion dropdown |
| 502 | * user selected a suggestion |
| 503 | */ |
| 504 | @Override |
| 505 | public void onAction(String text, String extra, String source) { |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 506 | stopEditingUrl(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 507 | if (UrlInputView.TYPED.equals(source)) { |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 508 | String url = null; |
Panos Thomas | 4bdb525 | 2014-11-13 16:20:11 -0800 | [diff] [blame] | 509 | boolean wap2estore = BrowserConfig.getInstance(getContext()) |
| 510 | .hasFeature(BrowserConfig.Feature.WAP2ESTORE); |
Vivek Sekhar | 5e63147 | 2014-03-31 23:59:10 -0700 | [diff] [blame] | 511 | if ((wap2estore && isEstoreTypeUrl(text)) || isRtspTypeUrl(text) |
| 512 | || isMakeCallTypeUrl(text)) { |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 513 | url = text; |
| 514 | } else { |
| 515 | url = UrlUtils.smartUrlFilter(text, false); |
| 516 | } |
| 517 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 518 | Tab t = mBaseUi.getActiveTab(); |
| 519 | // Only shortcut javascript URIs for now, as there is special |
| 520 | // logic in UrlHandler for other schemas |
Axesh R. Ajmera | 6fc7369 | 2015-08-11 16:32:10 -0700 | [diff] [blame] | 521 | if (url != null && t != null && url.startsWith("javascript:")) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 522 | mUiController.loadUrl(t, url); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 523 | setDisplayTitle(null, text); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 524 | return; |
| 525 | } |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 526 | |
| 527 | // add for carrier wap2estore feature |
| 528 | if (url != null && t != null && wap2estore && isEstoreTypeUrl(url)) { |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 529 | if (handleEstoreTypeUrl(url)) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 530 | setDisplayTitle(null, text); |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 531 | return; |
| 532 | } |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 533 | } |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 534 | // add for rtsp scheme feature |
| 535 | if (url != null && t != null && isRtspTypeUrl(url)) { |
| 536 | if (handleRtspTypeUrl(url)) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 537 | setDisplayTitle(null, text); |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 538 | return; |
| 539 | } |
| 540 | } |
Vivek Sekhar | 5e63147 | 2014-03-31 23:59:10 -0700 | [diff] [blame] | 541 | // add for "wtai://wp/mc;" scheme feature |
| 542 | if (url != null && t != null && isMakeCallTypeUrl(url)) { |
| 543 | if (handleMakeCallTypeUrl(url)) { |
| 544 | return; |
| 545 | } |
| 546 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 547 | } |
| 548 | Intent i = new Intent(); |
Michael Kolb | 5ff5c8b | 2012-05-03 11:37:58 -0700 | [diff] [blame] | 549 | String action = Intent.ACTION_SEARCH; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 550 | i.setAction(action); |
| 551 | i.putExtra(SearchManager.QUERY, text); |
| 552 | if (extra != null) { |
| 553 | i.putExtra(SearchManager.EXTRA_DATA_KEY, extra); |
| 554 | } |
| 555 | if (source != null) { |
| 556 | Bundle appData = new Bundle(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 557 | appData.putString("source", source); |
| 558 | i.putExtra("source", appData); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 559 | } |
| 560 | mUiController.handleNewIntent(i); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 561 | setDisplayTitle(null, text); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Vivek Sekhar | 5e63147 | 2014-03-31 23:59:10 -0700 | [diff] [blame] | 564 | private boolean isMakeCallTypeUrl(String url) { |
| 565 | String utf8Url = null; |
| 566 | try { |
| 567 | utf8Url = new String(url.getBytes("UTF-8"), "UTF-8"); |
| 568 | } catch (UnsupportedEncodingException e) { |
| 569 | Log.e(TAG, "err " + e); |
| 570 | } |
| 571 | if (utf8Url != null && utf8Url.startsWith(UrlHandler.SCHEME_WTAI_MC)) { |
| 572 | return true; |
| 573 | } |
| 574 | return false; |
| 575 | } |
| 576 | |
| 577 | private boolean handleMakeCallTypeUrl(String url) { |
| 578 | // wtai://wp/mc;number |
| 579 | // number=string(phone-number) |
| 580 | if (url.startsWith(UrlHandler.SCHEME_WTAI_MC)) { |
| 581 | Intent intent = new Intent(Intent.ACTION_VIEW, |
| 582 | Uri.parse(WebView.SCHEME_TEL + |
Vivek Sekhar | cb3f723 | 2015-12-10 20:02:46 -0800 | [diff] [blame] | 583 | Uri.encode(url.substring(UrlHandler.SCHEME_WTAI_MC.length())))); |
Vivek Sekhar | 5e63147 | 2014-03-31 23:59:10 -0700 | [diff] [blame] | 584 | getContext().startActivity(intent); |
| 585 | // before leaving BrowserActivity, close the empty child tab. |
| 586 | // If a new tab is created through JavaScript open to load this |
| 587 | // url, we would like to close it as we will load this url in a |
| 588 | // different Activity. |
| 589 | Tab current = mUiController.getCurrentTab(); |
| 590 | if (current != null |
| 591 | && current.getWebView().copyBackForwardList().getSize() == 0) { |
| 592 | mUiController.closeCurrentTab(); |
| 593 | } |
| 594 | return true; |
| 595 | } |
| 596 | return false; |
| 597 | } |
| 598 | |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 599 | private boolean isEstoreTypeUrl(String url) { |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 600 | if (url != null && url.startsWith("estore:")) { |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 601 | return true; |
| 602 | } |
| 603 | return false; |
| 604 | } |
| 605 | |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 606 | private boolean handleEstoreTypeUrl(String url) { |
| 607 | if (url.getBytes().length > 256) { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 608 | Toast.makeText(getContext(), R.string.estore_url_warning, Toast.LENGTH_LONG).show(); |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 609 | return false; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 610 | } |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 611 | |
| 612 | Intent intent; |
| 613 | // perform generic parsing of the URI to turn it into an Intent. |
| 614 | try { |
| 615 | intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| 616 | } catch (URISyntaxException ex) { |
| 617 | Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage()); |
| 618 | return false; |
| 619 | } |
| 620 | |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 621 | try { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 622 | getContext().startActivity(intent); |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 623 | } catch (ActivityNotFoundException ex) { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 624 | String downloadUrl = getContext().getResources().getString(R.string.estore_homepage); |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 625 | mUiController.loadUrl(mBaseUi.getActiveTab(), downloadUrl); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 626 | Toast.makeText(getContext(), R.string.download_estore_app, Toast.LENGTH_LONG).show(); |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 627 | } |
Vivek Sekhar | b54614f | 2014-05-01 19:03:37 -0700 | [diff] [blame] | 628 | |
| 629 | return true; |
kaiyiz | c4ada32 | 2013-07-30 09:58:07 +0800 | [diff] [blame] | 630 | } |
| 631 | |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 632 | private boolean isRtspTypeUrl(String url) { |
| 633 | String utf8Url = null; |
| 634 | try { |
| 635 | utf8Url = new String(url.getBytes("UTF-8"), "UTF-8"); |
| 636 | } catch (UnsupportedEncodingException e) { |
| 637 | Log.e(TAG, "err " + e); |
| 638 | } |
| 639 | if (utf8Url != null && utf8Url.startsWith("rtsp://")) { |
| 640 | return true; |
| 641 | } |
| 642 | return false; |
| 643 | } |
| 644 | |
| 645 | private boolean handleRtspTypeUrl(String url) { |
| 646 | Intent intent; |
| 647 | // perform generic parsing of the URI to turn it into an Intent. |
| 648 | try { |
| 649 | intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| 650 | } catch (URISyntaxException ex) { |
| 651 | Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage()); |
| 652 | return false; |
| 653 | } |
| 654 | |
| 655 | try { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 656 | getContext().startActivity(intent); |
kaiyiz | 950eca2 | 2013-08-08 11:01:28 +0800 | [diff] [blame] | 657 | } catch (ActivityNotFoundException ex) { |
| 658 | Log.w("Browser", "No resolveActivity " + url); |
| 659 | return false; |
| 660 | } |
| 661 | return true; |
| 662 | } |
| 663 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 664 | @Override |
| 665 | public void onDismiss() { |
| 666 | final Tab currentTab = mBaseUi.getActiveTab(); |
| 667 | mBaseUi.hideTitleBar(); |
| 668 | post(new Runnable() { |
| 669 | public void run() { |
| 670 | clearFocus(); |
Michael Kolb | 5ff5c8b | 2012-05-03 11:37:58 -0700 | [diff] [blame] | 671 | if (currentTab != null) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 672 | setDisplayTitle(currentTab.getTitle(), currentTab.getUrl()); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | }); |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * callback from the suggestion dropdown |
| 680 | * copy text to input field and stay in edit mode |
| 681 | */ |
| 682 | @Override |
| 683 | public void onCopySuggestion(String text) { |
| 684 | mUrlInput.setText(text, true); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
| 688 | } |
| 689 | |
| 690 | @Override |
| 691 | public boolean dispatchKeyEventPreIme(KeyEvent evt) { |
| 692 | if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
Sagar Dhawan | 5a5d01f | 2015-07-30 17:16:21 -0700 | [diff] [blame] | 693 | if (mUiController.getCurrentTab() != null && |
| 694 | mUiController.getCurrentTab().isKeyboardShowing()){ |
| 695 | stopEditingUrl(); |
| 696 | return true; |
| 697 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 698 | // catch back key in order to do slightly more cleanup than usual |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 699 | stopEditingUrl(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 700 | } |
| 701 | return super.dispatchKeyEventPreIme(evt); |
| 702 | } |
| 703 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 704 | /** |
| 705 | * called from the Ui when the user wants to edit |
| 706 | * @param clearInput clear the input field |
| 707 | */ |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 708 | void startEditingUrl(boolean clearInput, boolean forceIME) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 709 | // editing takes preference of progress |
| 710 | setVisibility(View.VISIBLE); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 711 | if (clearInput) { |
| 712 | mUrlInput.setText(""); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 713 | } |
Tarun Nainani | aa58682 | 2015-08-20 14:59:33 -0700 | [diff] [blame] | 714 | if (!mUrlInput.hasFocus()) { |
| 715 | mUrlInput.requestFocus(); |
| 716 | } |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 717 | if (forceIME) { |
Michael Kolb | 4bb6fcb | 2012-04-13 14:25:27 -0700 | [diff] [blame] | 718 | mUrlInput.showIME(); |
| 719 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | public void onProgressStarted() { |
Pankaj Garg | 07b2fd9 | 2015-07-15 12:07:37 -0700 | [diff] [blame] | 723 | mFaviconTile.setBadgeBlockedObjectsCount(0); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 724 | mFaviconTile.setTrustLevel(SiteTileView.TRUST_UNKNOWN); |
Pankaj Garg | 07b2fd9 | 2015-07-15 12:07:37 -0700 | [diff] [blame] | 725 | mFaviconTile.setBadgeHasCertIssues(false); |
Pankaj Garg | 96d0ccd | 2015-07-30 16:49:47 -0700 | [diff] [blame] | 726 | setSecurityState(Tab.SecurityState.SECURITY_STATE_NOT_SECURE); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 727 | mHandler.removeMessages(WEBREFINER_COUNTER_MSG); |
| 728 | mHandler.sendEmptyMessageDelayed(WEBREFINER_COUNTER_MSG, |
| 729 | WEBREFINER_COUNTER_MSG_DELAY); |
| 730 | mStopButton.setImageResource(R.drawable.ic_action_stop); |
| 731 | mStopButton.setContentDescription(getResources(). |
| 732 | getString(R.string.accessibility_button_stop)); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | public void onProgressStopped() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 736 | if (!isEditingUrl()) { |
| 737 | mFaviconTile.setVisibility(View.VISIBLE); |
| 738 | } |
| 739 | mStopButton.setImageResource(R.drawable.ic_action_reload); |
| 740 | mStopButton.setContentDescription(getResources(). |
| 741 | getString(R.string.accessibility_button_refresh)); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 742 | } |
| 743 | |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 744 | public void onTabDataChanged(Tab tab) { |
| 745 | } |
| 746 | |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 747 | public void onVoiceResult(String s) { |
| 748 | startEditingUrl(true, true); |
| 749 | onCopySuggestion(s); |
| 750 | } |
| 751 | |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 752 | @Override |
| 753 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { } |
| 754 | |
| 755 | @Override |
Michael Kolb | 5ff5c8b | 2012-05-03 11:37:58 -0700 | [diff] [blame] | 756 | public void onTextChanged(CharSequence s, int start, int before, int count) { } |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 757 | |
| 758 | @Override |
| 759 | public void afterTextChanged(Editable s) { } |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 760 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 761 | @Override |
| 762 | public void onStateChanged(int state) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 763 | mVoiceButton.setVisibility(View.GONE); |
Sagar Dhawan | 84ef444 | 2015-07-29 12:08:10 -0700 | [diff] [blame] | 764 | mClearButton.setVisibility(View.GONE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 765 | switch(state) { |
| 766 | case STATE_NORMAL: |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 767 | mFaviconTile.setVisibility(View.VISIBLE); |
jrizzoli | a62318b | 2015-09-08 21:44:50 +0200 | [diff] [blame] | 768 | mSeparator.setVisibility(View.VISIBLE); |
Sagar Dhawan | aff56c9 | 2015-07-13 15:57:11 -0700 | [diff] [blame] | 769 | mMore.setVisibility(View.VISIBLE); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 770 | if (mUiController != null) { |
| 771 | Tab currentTab = mUiController.getCurrentTab(); |
| 772 | if (currentTab != null){ |
| 773 | if (TextUtils.isEmpty(currentTab.getUrl())) { |
| 774 | mFaviconTile.setVisibility(View.GONE); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 775 | } |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 776 | setDisplayTitle(currentTab.getTitle(), currentTab.getUrl()); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 777 | } |
| 778 | mUiController.setWindowDimming(0.0f); |
| 779 | } |
| 780 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 781 | break; |
| 782 | case STATE_HIGHLIGHTED: |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 783 | mFaviconTile.setVisibility(View.GONE); |
jrizzoli | a62318b | 2015-09-08 21:44:50 +0200 | [diff] [blame] | 784 | mSeparator.setVisibility(View.GONE); |
Sagar Dhawan | 84ef444 | 2015-07-29 12:08:10 -0700 | [diff] [blame] | 785 | mClearButton.setVisibility(View.VISIBLE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 786 | mMore.setVisibility(View.GONE); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 787 | if (mUiController != null) { |
| 788 | mUiController.setWindowDimming(0.75f); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 789 | if (mTrustLevel == SiteTileView.TRUST_TRUSTED) { |
| 790 | Tab currentTab = mUiController.getCurrentTab(); |
| 791 | if (currentTab != null) { |
| 792 | mUrlInput.setText(currentTab.getUrl(), false); |
| 793 | mUrlInput.selectAll(); |
| 794 | } |
| 795 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 796 | } |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 797 | break; |
| 798 | case STATE_EDITED: |
Sagar Dhawan | 84ef444 | 2015-07-29 12:08:10 -0700 | [diff] [blame] | 799 | if (TextUtils.isEmpty(mUrlInput.getText()) && |
| 800 | mUiController != null && |
| 801 | mUiController.supportsVoice()) { |
| 802 | mVoiceButton.setVisibility(View.VISIBLE); |
| 803 | } |
| 804 | else { |
| 805 | mClearButton.setVisibility(View.VISIBLE); |
| 806 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 807 | mFaviconTile.setVisibility(View.GONE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 808 | mMore.setVisibility(View.GONE); |
| 809 | break; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | public boolean isMenuShowing() { |
| 814 | return mOverflowMenuShowing; |
| 815 | } |
| 816 | |
| 817 | |
| 818 | @Override |
| 819 | public void onDismiss(PopupMenu popupMenu) { |
| 820 | if (popupMenu == mPopupMenu) { |
| 821 | onMenuHidden(); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | private void onMenuHidden() { |
| 826 | mOverflowMenuShowing = false; |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | |
| 830 | @Override |
| 831 | public boolean onMenuItemClick(MenuItem item) { |
| 832 | return mUiController.onOptionsItemSelected(item); |
| 833 | } |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 834 | } |