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

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

Issue 2005053002: WebAPKs: Open links which are outside of WebAPK scope in Chrome not in WebAPK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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.externalnav; 5 package org.chromium.chrome.browser.externalnav;
6 6
7 import android.content.ActivityNotFoundException; 7 import android.content.ActivityNotFoundException;
8 import android.content.ComponentName; 8 import android.content.ComponentName;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.pm.ResolveInfo; 10 import android.content.pm.ResolveInfo;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 /* We should override the URL loading and clobber the current tab. */ 57 /* We should override the URL loading and clobber the current tab. */
58 OVERRIDE_WITH_CLOBBERING_TAB, 58 OVERRIDE_WITH_CLOBBERING_TAB,
59 /* We should override the URL loading. The desired action will be deter mined 59 /* We should override the URL loading. The desired action will be deter mined
60 * asynchronously (e.g. by requiring user confirmation). */ 60 * asynchronously (e.g. by requiring user confirmation). */
61 OVERRIDE_WITH_ASYNC_ACTION, 61 OVERRIDE_WITH_ASYNC_ACTION,
62 /* We shouldn't override the URL loading. */ 62 /* We shouldn't override the URL loading. */
63 NO_OVERRIDE, 63 NO_OVERRIDE,
64 } 64 }
65 65
66 /** 66 /**
67 * A constructor for UrlHandler. 67 * Creates {@link ExternalNavigationHandler} with default arguments.
68 * 68 * @param tab The associated tab.
69 * @param tab The tab that initiated the external intent. 69 * @return The ExternalNavigationHandler.
70 */ 70 */
71 public ExternalNavigationHandler(Tab tab) { 71 public static ExternalNavigationHandler createDefault(Tab tab) {
72 this(new ExternalNavigationDelegateImpl(tab)); 72 return new ExternalNavigationHandler(new ExternalNavigationDelegateImpl( tab, null));
73 } 73 }
74 74
75 /** 75 /**
76 * Constructs a new instance of {@link ExternalNavigationHandler}, using the injected 76 * Constructs a new instance of {@link ExternalNavigationHandler}, using the injected
77 * {@link ExternalNavigationDelegate}. 77 * {@link ExternalNavigationDelegate}.
78 */ 78 */
79 public ExternalNavigationHandler(ExternalNavigationDelegate delegate) { 79 public ExternalNavigationHandler(ExternalNavigationDelegate delegate) {
80 mDelegate = delegate; 80 mDelegate = delegate;
81 } 81 }
82 82
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // whether we can download it from the Market. 291 // whether we can download it from the Market.
292 if (!canResolveActivity) { 292 if (!canResolveActivity) {
293 if (hasBrowserFallbackUrl) { 293 if (hasBrowserFallbackUrl) {
294 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, para ms); 294 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, para ms);
295 } 295 }
296 String packagename = intent.getPackage(); 296 String packagename = intent.getPackage();
297 if (packagename != null) { 297 if (packagename != null) {
298 try { 298 try {
299 intent = new Intent(Intent.ACTION_VIEW, Uri.parse( 299 intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
300 "market://details?id=" + packagename 300 "market://details?id=" + packagename
301 + "&referrer=" + mDelegate.getPackageName())); 301 + "&referrer=" + mDelegate.getBrowserPackageName())) ;
302 intent.addCategory(Intent.CATEGORY_BROWSABLE); 302 intent.addCategory(Intent.CATEGORY_BROWSABLE);
303 intent.setPackage("com.android.vending"); 303 intent.setPackage("com.android.vending");
304 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 304 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
305 mDelegate.startActivity(intent); 305 mDelegate.startActivity(intent);
306 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T; 306 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T;
307 } catch (ActivityNotFoundException ex) { 307 } catch (ActivityNotFoundException ex) {
308 // ignore the error on devices that does not have 308 // ignore the error on devices that does not have
309 // play market installed. 309 // play market installed.
310 return OverrideUrlLoadingResult.NO_OVERRIDE; 310 return OverrideUrlLoadingResult.NO_OVERRIDE;
311 } 311 }
312 } else { 312 } else {
313 return OverrideUrlLoadingResult.NO_OVERRIDE; 313 return OverrideUrlLoadingResult.NO_OVERRIDE;
314 } 314 }
315 } 315 }
316 316
317 if (hasBrowserFallbackUrl) { 317 if (hasBrowserFallbackUrl) {
318 intent.removeExtra(EXTRA_BROWSER_FALLBACK_URL); 318 intent.removeExtra(EXTRA_BROWSER_FALLBACK_URL);
319 } 319 }
320 320
321 if (intent.getPackage() == null) { 321 if (intent.getPackage() == null) {
322 final Uri uri = intent.getData(); 322 final Uri uri = intent.getData();
323 if (uri != null && SCHEME_SMS.equals(uri.getScheme())) { 323 if (uri != null && SCHEME_SMS.equals(uri.getScheme())) {
324 intent.setPackage(getDefaultSmsPackageName(resolvingInfos)); 324 intent.setPackage(getDefaultSmsPackageName(resolvingInfos));
325 } 325 }
326 } 326 }
327 327
328 // Set the Browser application ID to us in case the user chooses Chrome 328 // Set the Browser application ID to us in case the user chooses Chrome
329 // as the app. This will make sure the link is opened in the same tab 329 // as the app. This will make sure the link is opened in the same tab
330 // instead of making a new one. 330 // instead of making a new one.
331 intent.putExtra(Browser.EXTRA_APPLICATION_ID, mDelegate.getPackageName() ); 331 intent.putExtra(Browser.EXTRA_APPLICATION_ID, mDelegate.getBrowserPackag eName());
332 if (params.isOpenInNewTab()) intent.putExtra(Browser.EXTRA_CREATE_NEW_TA B, true); 332 if (params.isOpenInNewTab()) intent.putExtra(Browser.EXTRA_CREATE_NEW_TA B, true);
333 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 333 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
334 mDelegate.maybeSetWindowId(intent); 334 mDelegate.maybeSetWindowId(intent);
335 335
336 if (params.getReferrerUrl() != null) { 336 if (params.getReferrerUrl() != null) {
337 IntentHandler.setPendingReferrer(intent, params.getReferrerUrl()); 337 IntentHandler.setPendingReferrer(intent, params.getReferrerUrl());
338 } 338 }
339 339
340 // Make sure webkit can handle it internally before checking for special ized 340 // Make sure webkit can handle it internally before checking for special ized
341 // handlers. If webkit can't handle it internally, we need to call 341 // handlers. If webkit can't handle it internally, we need to call
342 // startActivityIfNeeded or startActivity. 342 // startActivityIfNeeded or startActivity.
343 if (!isExternalProtocol) { 343 if (!isExternalProtocol) {
344 if (!mDelegate.isSpecializedHandlerAvailable(resolvingInfos)) { 344 if (!mDelegate.isSpecializedHandlerAvailable(resolvingInfos)) {
345 if (mDelegate.getWebApkPackageName() != null) {
346 mDelegate.startChromeActivity(params.getUrl());
Maria 2016/05/31 23:31:21 We shouldn't be re-creating the logic for generati
347 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T;
348 }
345 return OverrideUrlLoadingResult.NO_OVERRIDE; 349 return OverrideUrlLoadingResult.NO_OVERRIDE;
346 } else if (params.getReferrerUrl() != null && (isLink || isFormSubmi t)) { 350 } else if (params.getReferrerUrl() != null && (isLink || isFormSubmi t)) {
347 // Current URL has at least one specialized handler available. F or navigations 351 // Current URL has at least one specialized handler available. F or navigations
348 // within the same host, keep the navigation inside the browser unless the set of 352 // within the same host, keep the navigation inside the browser unless the set of
349 // available apps to handle the new navigation is different. htt p://crbug.com/463138 353 // available apps to handle the new navigation is different. htt p://crbug.com/463138
350 URI currentUri; 354 URI currentUri;
351 URI previousUri; 355 URI previousUri;
352 try { 356 try {
353 currentUri = new URI(params.getUrl()); 357 currentUri = new URI(params.getUrl());
354 previousUri = new URI(params.getReferrerUrl()); 358 previousUri = new URI(params.getReferrerUrl());
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (defaultSmsPackageName == null) return null; 473 if (defaultSmsPackageName == null) return null;
470 // Makes sure that the default SMS app actually resolves the intent. 474 // Makes sure that the default SMS app actually resolves the intent.
471 for (ResolveInfo resolveInfo : resolvingComponentNames) { 475 for (ResolveInfo resolveInfo : resolvingComponentNames) {
472 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam e)) { 476 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam e)) {
473 return defaultSmsPackageName; 477 return defaultSmsPackageName;
474 } 478 }
475 } 479 }
476 return null; 480 return null;
477 } 481 }
478 } 482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698