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 final String webappUrl = mActivity.mWebappInfo.uri().toString(); | |
33 if (UrlUtilities.isValidForIntentFallbackNavigation(navigationParams.url ) | |
34 && !UrlUtilities.sameDomainOrHost(webappUrl, navigationParams.ur l, true)) { | |
pkotwicz
2017/05/10 04:52:21
The logic for whether to open the CCT is different
dominickn
2017/05/10 05:15:11
Oh, that's a good catch Peter, thanks. This is twi
piotrs
2017/05/10 05:40:26
Thanks a lot and fixed now. We definitely need sep
| |
35 CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builde r(); | |
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 } | |
OLD | NEW |