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

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

Issue 2829943002: Redirecting off-origin navigations in PWAs to CCT. (Closed)
Patch Set: Relaxed the WebApkIntegrationTest Created 3 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.webapps;
6
7 import android.net.Uri;
8 import android.support.customtabs.CustomTabsIntent;
9
10 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl;
11 import org.chromium.chrome.browser.tab.Tab;
12 import org.chromium.chrome.browser.util.UrlUtilities;
13 import org.chromium.components.navigation_interception.NavigationParams;
14
15 /**
16 * Intercepts navigations made by the Web App and sends off-origin http(s) ones to a Custom Tab.
17 */
18 public class WebappInterceptNavigationDelegate extends InterceptNavigationDelega teImpl {
19 private final WebappActivity mActivity;
20
21 public WebappInterceptNavigationDelegate(WebappActivity activity, Tab tab) {
22 super(tab);
23 this.mActivity = activity;
24 }
25
26 @Override
27 public boolean shouldIgnoreNavigation(NavigationParams navigationParams) {
28 if (super.shouldIgnoreNavigation(navigationParams)) {
29 return true;
30 }
31
32 if (UrlUtilities.isValidForIntentFallbackNavigation(navigationParams.url )
33 && isUrlOutsideWebappScope(mActivity.mWebappInfo, navigationPara ms.url)) {
34 CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builde r();
35 intentBuilder.setShowTitle(true);
36 if (mActivity.mWebappInfo.hasValidThemeColor()) {
37 // Need to cast as themeColor is a long to contain possible erro r results.
38 intentBuilder.setToolbarColor((int) mActivity.mWebappInfo.themeC olor());
39 }
40 CustomTabsIntent customTabIntent = intentBuilder.build();
41 customTabIntent.intent.setPackage(mActivity.getPackageName());
42 customTabIntent.launchUrl(mActivity, Uri.parse(navigationParams.url) );
43 return true;
44 }
45
46 return false;
47 }
48
49 // Note that WebApks override this with a rule based on web manifest scope.
50 protected boolean isUrlOutsideWebappScope(WebappInfo info, String url) {
51 return !UrlUtilities.sameDomainOrHost(info.uri().toString(), url, true);
52 }
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698