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

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

Issue 2018113002: Upstream: Do not show the add-to-homescreen/install-native-app infobar for WebAPKs (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
(Empty)
1 // Copyright 2016 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.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 by a
22 * {@link FullScreenActivity}.
23 */
24 public class WebappDelegateFactory extends FullScreenDelegateFactory {
25 private static class WebappWebContentsDelegateAndroid extends TabWebContents DelegateAndroid {
26 private final WebappActivity mActivity;
27
28 public WebappWebContentsDelegateAndroid(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.setPackage(mActivity.getPackageName());
44 mActivity.getWebappInfo().setWebappIntentExtras(intent);
45
46 intent.putExtra(
47 ShortcutHelper.EXTRA_MAC, ShortcutHelper.getEncodedMac(mActi vity, startUrl));
48 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
49 ContextUtils.getApplicationContext().startActivity(intent);
50 }
51 }
52
53 @VisibleForTesting
54 static class TopControlsDelegate extends TopControlsVisibilityDelegate {
55 private final WebappActivity mActivity;
56
57 public TopControlsDelegate(WebappActivity activity, Tab tab) {
58 super(tab);
59 mActivity = activity;
60 }
61
62 @Override
63 public boolean isShowingTopControlsEnabled() {
64 if (!super.isShowingTopControlsEnabled()) return false;
65
66 String webappStartUrl = mActivity.getWebappInfo().uri().toString();
67 return shouldShowTopControls(webappStartUrl, mTab.getUrl(), mTab.get SecurityLevel());
68 }
69
70 @Override
71 public boolean isHidingTopControlsEnabled() {
72 return !isShowingTopControlsEnabled();
73 }
74
75 /**
76 * Returns whether the top controls should be shown when a webapp is nav igated to
77 * {@link url}.
78 * @param webappStartUrl The webapp's URL when it is opened from the hom e screen.
79 * @param url The webapp's current URL
80 * @param securityLevel The security level for the webapp's current URL.
81 * @return Whether the top controls should be shown for {@link url}.
82 */
83 public static boolean shouldShowTopControls(
84 String webappStartUrl, String url, int securityLevel) {
85 // Do not show top controls when URL is not ready yet.
86 boolean visible = false;
87 if (TextUtils.isEmpty(url)) return false;
88
89 boolean isSameWebsite =
90 UrlUtilities.sameDomainOrHost(webappStartUrl, url, true);
91 visible = !isSameWebsite || securityLevel == ConnectionSecurityLevel .SECURITY_ERROR
92 || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING ;
93 return visible;
94 }
95 }
96
97 private final WebappActivity mActivity;
98
99 public WebappDelegateFactory(WebappActivity activity) {
100 mActivity = activity;
101 }
102
103 @Override
104 public TabWebContentsDelegateAndroid createWebContentsDelegate(Tab tab) {
105 return new WebappWebContentsDelegateAndroid(mActivity, tab);
106 }
107
108 @Override
109 public TopControlsVisibilityDelegate createTopControlsVisibilityDelegate(Tab tab) {
110 return new TopControlsDelegate(mActivity, tab);
111 }
112 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698