OLD | NEW |
| (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 } | |
OLD | NEW |