Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/IntentHandler.java

Issue 1243253004: Pass user gesture bit when chrome handles an intent fired by itself (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix findbugs warning Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.app.KeyguardManager; 7 import android.app.KeyguardManager;
8 import android.app.PendingIntent; 8 import android.app.PendingIntent;
9 import android.app.SearchManager; 9 import android.app.SearchManager;
10 import android.content.ComponentName; 10 import android.content.ComponentName;
11 import android.content.Context; 11 import android.content.Context;
12 import android.content.Intent; 12 import android.content.Intent;
13 import android.content.pm.PackageManager; 13 import android.content.pm.PackageManager;
14 import android.content.pm.ResolveInfo; 14 import android.content.pm.ResolveInfo;
15 import android.net.Uri; 15 import android.net.Uri;
16 import android.os.Bundle; 16 import android.os.Bundle;
17 import android.os.SystemClock; 17 import android.os.SystemClock;
18 import android.provider.Browser; 18 import android.provider.Browser;
19 import android.provider.MediaStore; 19 import android.provider.MediaStore;
20 import android.speech.RecognizerResultsIntent; 20 import android.speech.RecognizerResultsIntent;
21 import android.text.TextUtils; 21 import android.text.TextUtils;
22 import android.util.Pair; 22 import android.util.Pair;
23 23
24 import org.chromium.base.ApiCompatibilityUtils; 24 import org.chromium.base.ApiCompatibilityUtils;
25 import org.chromium.base.Log; 25 import org.chromium.base.Log;
26 import org.chromium.base.VisibleForTesting; 26 import org.chromium.base.VisibleForTesting;
27 import org.chromium.base.metrics.RecordHistogram; 27 import org.chromium.base.metrics.RecordHistogram;
28 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; 28 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
29 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler;
29 import org.chromium.chrome.browser.omnibox.AutocompleteController; 30 import org.chromium.chrome.browser.omnibox.AutocompleteController;
30 import org.chromium.chrome.browser.search_engines.TemplateUrlService; 31 import org.chromium.chrome.browser.search_engines.TemplateUrlService;
31 import org.chromium.chrome.browser.tab.Tab; 32 import org.chromium.chrome.browser.tab.Tab;
32 import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; 33 import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate;
33 import org.chromium.chrome.browser.util.IntentUtils; 34 import org.chromium.chrome.browser.util.IntentUtils;
34 import org.chromium.content_public.browser.LoadUrlParams; 35 import org.chromium.content_public.browser.LoadUrlParams;
35 import org.chromium.content_public.common.Referrer; 36 import org.chromium.content_public.common.Referrer;
36 37
37 import java.util.ArrayList; 38 import java.util.ArrayList;
38 import java.util.Iterator; 39 import java.util.Iterator;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 211
211 /** 212 /**
212 * A delegate interface for users of IntentHandler. 213 * A delegate interface for users of IntentHandler.
213 */ 214 */
214 public static interface IntentHandlerDelegate { 215 public static interface IntentHandlerDelegate {
215 /** 216 /**
216 * Processes a URL VIEW Intent. 217 * Processes a URL VIEW Intent.
217 */ 218 */
218 void processUrlViewIntent(String url, String referer, String headers, 219 void processUrlViewIntent(String url, String referer, String headers,
219 TabOpenType tabOpenType, String externalAppId, int tabIdToBringT oFront, 220 TabOpenType tabOpenType, String externalAppId, int tabIdToBringT oFront,
220 Intent intent); 221 boolean hasUserGesture, Intent intent);
221 222
222 void processWebSearchIntent(String query); 223 void processWebSearchIntent(String query);
223 } 224 }
224 225
225 /** Sets whether or not test intents are enabled. */ 226 /** Sets whether or not test intents are enabled. */
226 @VisibleForTesting 227 @VisibleForTesting
227 public static void setTestIntentsEnabled(boolean enabled) { 228 public static void setTestIntentsEnabled(boolean enabled) {
228 sTestIntentsEnabled = enabled; 229 sTestIntentsEnabled = enabled;
229 } 230 }
230 231
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 /** 283 /**
283 * Handles an Intent after the ChromeTabbedActivity decides that it shouldn' t ignore the 284 * Handles an Intent after the ChromeTabbedActivity decides that it shouldn' t ignore the
284 * Intent. 285 * Intent.
285 * 286 *
286 * @return Whether the Intent was successfully handled. 287 * @return Whether the Intent was successfully handled.
287 * TODO(mariakhomenko): make package protected after ChromeTabbedActivity is upstreamed. 288 * TODO(mariakhomenko): make package protected after ChromeTabbedActivity is upstreamed.
288 */ 289 */
289 public boolean onNewIntent(Context context, Intent intent) { 290 public boolean onNewIntent(Context context, Intent intent) {
290 assert intentHasValidUrl(intent); 291 assert intentHasValidUrl(intent);
291 String url = getUrlFromIntent(intent); 292 String url = getUrlFromIntent(intent);
292 293 boolean hasUserGesture =
294 IntentWithGesturesHandler.getInstance().getUserGestureAndClear(i ntent);
293 TabOpenType tabOpenType = getTabOpenType(intent); 295 TabOpenType tabOpenType = getTabOpenType(intent);
294 int tabIdToBringToFront = IntentUtils.safeGetIntExtra( 296 int tabIdToBringToFront = IntentUtils.safeGetIntExtra(
295 intent, TabOpenType.BRING_TAB_TO_FRONT.name(), Tab.INVALID_TAB_I D); 297 intent, TabOpenType.BRING_TAB_TO_FRONT.name(), Tab.INVALID_TAB_I D);
296 if (url == null && tabIdToBringToFront == Tab.INVALID_TAB_ID 298 if (url == null && tabIdToBringToFront == Tab.INVALID_TAB_ID
297 && tabOpenType != TabOpenType.OPEN_NEW_INCOGNITO_TAB) { 299 && tabOpenType != TabOpenType.OPEN_NEW_INCOGNITO_TAB) {
298 return handleWebSearchIntent(intent); 300 return handleWebSearchIntent(intent);
299 } 301 }
300 302
301 String referrerUrl = getReferrerUrlIncludingExtraHeaders(intent, context ); 303 String referrerUrl = getReferrerUrlIncludingExtraHeaders(intent, context );
302 String extraHeaders = getExtraHeadersFromIntent(intent); 304 String extraHeaders = getExtraHeadersFromIntent(intent);
303 305
304 // TODO(joth): Presumably this should check the action too. 306 // TODO(joth): Presumably this should check the action too.
305 mDelegate.processUrlViewIntent(url, referrerUrl, extraHeaders, tabOpenTy pe, 307 mDelegate.processUrlViewIntent(url, referrerUrl, extraHeaders, tabOpenTy pe,
306 IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION _ID), 308 IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION _ID),
307 tabIdToBringToFront, intent); 309 tabIdToBringToFront, hasUserGesture, intent);
308 recordExternalIntentSourceUMA(intent); 310 recordExternalIntentSourceUMA(intent);
309 return true; 311 return true;
310 } 312 }
311 313
312 /** 314 /**
313 * Extracts referrer Uri from intent, if supplied. 315 * Extracts referrer Uri from intent, if supplied.
314 * @param intent The intent to use. 316 * @param intent The intent to use.
315 * @return The referrer Uri. 317 * @return The referrer Uri.
316 */ 318 */
317 private static Uri getReferrer(Intent intent) { 319 private static Uri getReferrer(Intent intent) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 * Sets TRUSTED_APPLICATION_CODE_EXTRA on the provided intent to identify it as coming from 507 * Sets TRUSTED_APPLICATION_CODE_EXTRA on the provided intent to identify it as coming from
506 * a trusted source. 508 * a trusted source.
507 */ 509 */
508 public static void addTrustedIntentExtras(Intent intent, Context context) { 510 public static void addTrustedIntentExtras(Intent intent, Context context) {
509 if (willChromeHandleIntent(intent, context)) { 511 if (willChromeHandleIntent(intent, context)) {
510 // The PendingIntent functions as an authentication token --- it cou ld only have come 512 // The PendingIntent functions as an authentication token --- it cou ld only have come
511 // from us. Stash it in the real Intent as an extra. shouldIgnoreInt ent will retrieve it 513 // from us. Stash it in the real Intent as an extra. shouldIgnoreInt ent will retrieve it
512 // and check it with isIntentChromeInternal. 514 // and check it with isIntentChromeInternal.
513 intent.putExtra(TRUSTED_APPLICATION_CODE_EXTRA, 515 intent.putExtra(TRUSTED_APPLICATION_CODE_EXTRA,
514 getAuthenticationToken(context.getApplicationContext())); 516 getAuthenticationToken(context.getApplicationContext()));
515
516 // It is crucial that we never leak the authentication token to othe r packages, because 517 // It is crucial that we never leak the authentication token to othe r packages, because
517 // then the other package could be used to impersonate us/do things as us. Therefore, 518 // then the other package could be used to impersonate us/do things as us. Therefore,
518 // scope the real Intent to our package. 519 // scope the real Intent to our package.
519 intent.setPackage(context.getApplicationContext().getPackageName()); 520 intent.setPackage(context.getApplicationContext().getPackageName());
520 } 521 }
521 } 522 }
522 523
523 /** 524 /**
524 * Determine if Chrome is the default or only handler for a given intent. If 525 * Determine if Chrome is the default or only handler for a given intent. If
525 * true, Chrome will handle the intent when started. 526 * true, Chrome will handle the intent when started.
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 * @param id The referrer id. 867 * @param id The referrer id.
867 * @return The URL for the referrer or null if none found. 868 * @return The URL for the referrer or null if none found.
868 */ 869 */
869 public static String getPendingReferrerUrl(int id) { 870 public static String getPendingReferrerUrl(int id) {
870 if (sPendingReferrer != null && (sPendingReferrer.first == id)) { 871 if (sPendingReferrer != null && (sPendingReferrer.first == id)) {
871 return sPendingReferrer.second; 872 return sPendingReferrer.second;
872 } 873 }
873 return null; 874 return null;
874 } 875 }
875 } 876 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698