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