OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
gone
2016/05/31 18:26:55
It's 2016.
| |
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.content.Intent; | |
8 import android.text.TextUtils; | |
9 | |
10 import org.chromium.base.ContextUtils; | |
11 import org.chromium.base.VisibleForTesting; | |
12 import org.chromium.chrome.browser.ShortcutHelper; | |
13 import org.chromium.chrome.browser.tab.Tab; | |
14 import org.chromium.chrome.browser.tab.TabDelegateFactory; | |
15 import org.chromium.chrome.browser.tab.TabWebContentsDelegateAndroid; | |
16 import org.chromium.chrome.browser.tab.TopControlsVisibilityDelegate; | |
17 import org.chromium.chrome.browser.util.UrlUtilities; | |
18 import org.chromium.components.security_state.ConnectionSecurityLevel; | |
19 | |
20 /** | |
21 * A {@link TabDelegateFactory} class to be used in all {@link Tab} instances ow ned | |
gone
2016/05/31 18:26:55
Wrap at 100 everywhere.
| |
22 * by a {@link FullScreenActivity}. | |
23 */ | |
24 public class WebappDelegateFactory extends FullScreenDelegateFactory { | |
25 private static class WebContentsDelegate extends TabWebContentsDelegateAndro id { | |
Xi Han
2016/05/30 21:26:55
Rename WebContentsDelegate to WebappContentsDelega
pkotwicz
2016/05/31 02:32:01
I named the class WebContentsDelegate as a shorten
Xi Han
2016/05/31 14:18:27
Usually the subclass name is more specific than th
gone
2016/05/31 18:26:55
Naming this WebContentsDelegate goes against both
| |
26 private final WebappActivity mActivity; | |
27 | |
28 public WebContentsDelegate(WebappActivity activity, Tab tab) { | |
29 super(tab); | |
30 mActivity = activity; | |
31 } | |
32 | |
33 @Override | |
34 public void activateContents() { | |
35 String startUrl = mActivity.getWebappInfo().uri().toString(); | |
36 | |
37 // Create an Intent that will be fired toward the WebappLauncherActi vity, which in turn | |
38 // will fire an Intent to launch the correct WebappActivity. On L+ this could probably | |
39 // be changed to call AppTask.moveToFront(), but for backwards compa tibility we relaunch | |
40 // it the hard way. | |
41 Intent intent = new Intent(); | |
42 intent.setAction(WebappLauncherActivity.ACTION_START_WEBAPP); | |
43 intent.setClassName(WebappLauncherActivity.class.getPackage().getNam e(), | |
44 WebappLauncherActivity.class.getName()); | |
45 mActivity.getWebappInfo().setWebappIntentExtras(intent); | |
46 | |
47 intent.putExtra( | |
48 ShortcutHelper.EXTRA_MAC, ShortcutHelper.getEncodedMac(mActi vity, startUrl)); | |
49 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
50 ContextUtils.getApplicationContext().startActivity(intent); | |
51 } | |
52 } | |
53 | |
54 @VisibleForTesting | |
55 static class TopControlsDelegate extends TopControlsVisibilityDelegate { | |
56 private final WebappActivity mActivity; | |
57 | |
58 public TopControlsDelegate(WebappActivity activity, Tab tab) { | |
59 super(tab); | |
60 mActivity = activity; | |
61 } | |
62 | |
63 @Override | |
64 public boolean isShowingTopControlsEnabled() { | |
65 if (!super.isShowingTopControlsEnabled()) return false; | |
66 | |
67 String webappStartUrl = mActivity.getWebappInfo().uri().toString(); | |
68 return shouldShowTopControls(webappStartUrl, mTab.getUrl(), mTab.get SecurityLevel()); | |
69 } | |
70 | |
71 @Override | |
72 public boolean isHidingTopControlsEnabled() { | |
73 return !isShowingTopControlsEnabled(); | |
74 } | |
75 | |
76 /** | |
77 * Returns whether the top controls should be shown when a webapp is nav igated to | |
78 * {@link url}. | |
79 * @param webappStartUrl The webapp's URL when it is opened from the hom e screen. | |
80 * @param url | |
gone
2016/05/31 18:26:56
Fill in these parameters.
| |
81 * @param securityLevel | |
82 * @return Whether the top controls should be shown for {@link url}. | |
83 */ | |
84 public static boolean shouldShowTopControls( | |
85 String webappStartUrl, String url, int securityLevel) { | |
86 // Do not show top controls when URL is not ready yet. | |
87 boolean visible = false; | |
88 if (TextUtils.isEmpty(url)) return false; | |
89 | |
90 boolean isSameWebsite = | |
91 UrlUtilities.sameDomainOrHost(webappStartUrl, url, true); | |
92 visible = !isSameWebsite || securityLevel == ConnectionSecurityLevel .SECURITY_ERROR | |
93 || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING ; | |
94 return visible; | |
95 } | |
96 } | |
97 | |
98 private final WebappActivity mActivity; | |
99 | |
100 public WebappDelegateFactory(WebappActivity activity) { | |
101 mActivity = activity; | |
102 } | |
103 | |
104 @Override | |
105 public TabWebContentsDelegateAndroid createWebContentsDelegate(Tab tab) { | |
106 return new WebContentsDelegate(mActivity, tab); | |
107 } | |
108 | |
109 @Override | |
110 public TopControlsVisibilityDelegate createTopControlsVisibilityDelegate(Tab tab) { | |
111 return new TopControlsDelegate(mActivity, tab); | |
112 } | |
113 } | |
OLD | NEW |