OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.appmenu; | 5 package org.chromium.chrome.browser.appmenu; |
6 | 6 |
7 import android.content.Context; | |
8 import android.content.pm.ResolveInfo; | |
7 import android.graphics.PorterDuff; | 9 import android.graphics.PorterDuff; |
8 import android.graphics.drawable.Drawable; | 10 import android.graphics.drawable.Drawable; |
9 import android.view.Menu; | 11 import android.view.Menu; |
10 import android.view.MenuItem; | 12 import android.view.MenuItem; |
11 | 13 |
12 import org.chromium.base.ApiCompatibilityUtils; | 14 import org.chromium.base.ApiCompatibilityUtils; |
13 import org.chromium.base.CommandLine; | 15 import org.chromium.base.CommandLine; |
16 import org.chromium.base.ContextUtils; | |
17 import org.chromium.base.metrics.RecordHistogram; | |
14 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
15 import org.chromium.chrome.browser.ChromeActivity; | 19 import org.chromium.chrome.browser.ChromeActivity; |
16 import org.chromium.chrome.browser.ChromeFeatureList; | 20 import org.chromium.chrome.browser.ChromeFeatureList; |
17 import org.chromium.chrome.browser.ChromeSwitches; | 21 import org.chromium.chrome.browser.ChromeSwitches; |
18 import org.chromium.chrome.browser.ShortcutHelper; | 22 import org.chromium.chrome.browser.ShortcutHelper; |
19 import org.chromium.chrome.browser.UrlConstants; | 23 import org.chromium.chrome.browser.UrlConstants; |
20 import org.chromium.chrome.browser.banners.AppBannerManager; | 24 import org.chromium.chrome.browser.banners.AppBannerManager; |
21 import org.chromium.chrome.browser.bookmarks.BookmarkBridge; | 25 import org.chromium.chrome.browser.bookmarks.BookmarkBridge; |
22 import org.chromium.chrome.browser.download.DownloadUtils; | 26 import org.chromium.chrome.browser.download.DownloadUtils; |
23 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 27 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
24 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; | 28 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; |
25 import org.chromium.chrome.browser.preferences.ManagedPreferencesUtils; | 29 import org.chromium.chrome.browser.preferences.ManagedPreferencesUtils; |
26 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 30 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
27 import org.chromium.chrome.browser.share.ShareHelper; | 31 import org.chromium.chrome.browser.share.ShareHelper; |
28 import org.chromium.chrome.browser.tab.Tab; | 32 import org.chromium.chrome.browser.tab.Tab; |
29 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; | 33 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; |
30 import org.chromium.ui.base.DeviceFormFactor; | 34 import org.chromium.ui.base.DeviceFormFactor; |
35 import org.chromium.webapk.lib.client.WebApkValidator; | |
36 | |
37 import java.util.concurrent.TimeUnit; | |
31 | 38 |
32 /** | 39 /** |
33 * App Menu helper that handles hiding and showing menu items based on activity state. | 40 * App Menu helper that handles hiding and showing menu items based on activity state. |
34 */ | 41 */ |
35 public class AppMenuPropertiesDelegate { | 42 public class AppMenuPropertiesDelegate { |
dominickn
2017/02/21 23:04:42
You also need to change CustomTabAppMenuProperties
gonzalon
2017/02/22 15:50:49
Done.
| |
36 // Indices for different levels in drawable.btn_reload_stop. | 43 // Indices for different levels in drawable.btn_reload_stop. |
37 // Used only when preparing menu and refresh reload button in menu when tab | 44 // Used only when preparing menu and refresh reload button in menu when tab |
38 // page load status changes. | 45 // page load status changes. |
39 private static final int RELOAD_BUTTON_LEVEL_RELOAD = 0; | 46 private static final int RELOAD_BUTTON_LEVEL_RELOAD = 0; |
40 private static final int RELOAD_BUTTON_LEVEL_STOP_LOADING = 1; | 47 private static final int RELOAD_BUTTON_LEVEL_STOP_LOADING = 1; |
41 | 48 |
42 protected MenuItem mReloadMenuItem; | 49 protected MenuItem mReloadMenuItem; |
43 | 50 |
44 protected final ChromeActivity mActivity; | 51 protected final ChromeActivity mActivity; |
45 | 52 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 // Hide 'Add to homescreen' for the following: | 162 // Hide 'Add to homescreen' for the following: |
156 // * chrome:// pages - Android doesn't know how to direct those URLs . | 163 // * chrome:// pages - Android doesn't know how to direct those URLs . |
157 // * incognito pages - To avoid problems where users create shortcut s in incognito | 164 // * incognito pages - To avoid problems where users create shortcut s in incognito |
158 // mode and then open the webapp in regular mod e. | 165 // mode and then open the webapp in regular mod e. |
159 // * file:// - After API 24, file: URIs are not supported in VIEW in tents and thus | 166 // * file:// - After API 24, file: URIs are not supported in VIEW in tents and thus |
160 // can not be added to the homescreen. | 167 // can not be added to the homescreen. |
161 // * content:// - Accessing external content URIs requires the calli ng app to grant | 168 // * content:// - Accessing external content URIs requires the calli ng app to grant |
162 // access to the resource via FLAG_GRANT_READ_URI_PER MISSION, and that | 169 // access to the resource via FLAG_GRANT_READ_URI_PER MISSION, and that |
163 // is not persisted when adding to the homescreen. | 170 // is not persisted when adding to the homescreen. |
164 // * If creating shortcuts it not supported by the current home scre en. | 171 // * If creating shortcuts it not supported by the current home scre en. |
172 long addToHomeScreenStart = System.currentTimeMillis(); | |
dominickn
2017/02/21 23:04:42
This timing is currently mixing in the work needed
gonzalon
2017/02/22 15:50:49
Done.
| |
165 MenuItem homescreenItem = menu.findItem(R.id.add_to_homescreen_id); | 173 MenuItem homescreenItem = menu.findItem(R.id.add_to_homescreen_id); |
166 boolean homescreenItemVisible = ShortcutHelper.isAddToHomeIntentSupp orted(mActivity) | 174 MenuItem openWebApkItem = menu.findItem(R.id.open_webapk_id); |
pkotwicz
2017/02/21 22:52:32
Based on reading the discussion on the bug (and co
dominickn
2017/02/21 23:04:42
I thought that we were going to display "Open appn
pkotwicz
2017/02/22 15:04:51
Yes Dominick you are right. I somehow missed Comme
| |
175 boolean canBeAddedToHomeScreen = ShortcutHelper.isAddToHomeIntentSup ported(mActivity) | |
167 && !isChromeScheme && !isFileScheme && !isContentScheme && ! isIncognito; | 176 && !isChromeScheme && !isFileScheme && !isContentScheme && ! isIncognito; |
168 if (homescreenItemVisible) { | 177 Context context = ContextUtils.getApplicationContext(); |
178 ResolveInfo resolveInfo = WebApkValidator.queryWebApk(context, curre ntTab.getUrl()); | |
179 boolean openWebApkItemVisible = canBeAddedToHomeScreen && resolveInf o != null | |
180 && resolveInfo.activityInfo.packageName != null; | |
181 if (canBeAddedToHomeScreen && !openWebApkItemVisible) { | |
dominickn
2017/02/21 23:04:42
I think the logic here is more clearly expressed l
gonzalon
2017/02/22 15:50:49
Done.
| |
169 homescreenItem.setTitle(AppBannerManager.getHomescreenLanguageOp tion()); | 182 homescreenItem.setTitle(AppBannerManager.getHomescreenLanguageOp tion()); |
170 } | 183 } |
171 homescreenItem.setVisible(homescreenItemVisible); | 184 if (openWebApkItemVisible) { |
185 String appName = resolveInfo.loadLabel(context.getPackageManager ()).toString(); | |
186 openWebApkItem.setTitle(context.getString(R.string.menu_open_web apk, appName)); | |
187 } | |
188 homescreenItem.setVisible(canBeAddedToHomeScreen && !openWebApkItemV isible); | |
189 openWebApkItem.setVisible(openWebApkItemVisible); | |
190 RecordHistogram.recordTimesHistogram("AndroidPrepareMenu.OpenWebAPK" , | |
pkotwicz
2017/02/21 22:52:32
How about "Android.PrepareMenu.DisableAddToHomescr
dominickn
2017/02/21 23:04:42
+1 to all Peter's comments
gonzalon
2017/02/22 15:50:49
Done.
| |
191 System.currentTimeMillis() - addToHomeScreenStart, TimeUnit. MILLISECONDS); | |
pkotwicz
2017/02/21 22:52:32
From looking at the codebase, it looks like we pre
gonzalon
2017/02/22 15:50:49
Done.
| |
172 | 192 |
173 // Hide request desktop site on all chrome:// pages except for the N TP. Check request | 193 // Hide request desktop site on all chrome:// pages except for the N TP. Check request |
174 // desktop site if it's activated on this page. | 194 // desktop site if it's activated on this page. |
175 MenuItem requestItem = menu.findItem(R.id.request_desktop_site_id); | 195 MenuItem requestItem = menu.findItem(R.id.request_desktop_site_id); |
176 updateRequestDesktopSiteMenuItem(requestItem, currentTab); | 196 updateRequestDesktopSiteMenuItem(requestItem, currentTab); |
177 | 197 |
178 // Only display reader mode settings menu option if the current page is in reader mode. | 198 // Only display reader mode settings menu option if the current page is in reader mode. |
179 menu.findItem(R.id.reader_mode_prefs_id) | 199 menu.findItem(R.id.reader_mode_prefs_id) |
180 .setVisible(DomDistillerUrlUtils.isDistilledPage(currentTab. getUrl())); | 200 .setVisible(DomDistillerUrlUtils.isDistilledPage(currentTab. getUrl())); |
181 | 201 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 String url = currentTab.getUrl(); | 321 String url = currentTab.getUrl(); |
302 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX) | 322 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX) |
303 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); | 323 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); |
304 requstMenuItem.setVisible(!isChromeScheme || currentTab.isNativePage()); | 324 requstMenuItem.setVisible(!isChromeScheme || currentTab.isNativePage()); |
305 requstMenuItem.setChecked(currentTab.getUseDesktopUserAgent()); | 325 requstMenuItem.setChecked(currentTab.getUseDesktopUserAgent()); |
306 requstMenuItem.setTitleCondensed(requstMenuItem.isChecked() | 326 requstMenuItem.setTitleCondensed(requstMenuItem.isChecked() |
307 ? mActivity.getString(R.string.menu_request_desktop_site_on) | 327 ? mActivity.getString(R.string.menu_request_desktop_site_on) |
308 : mActivity.getString(R.string.menu_request_desktop_site_off)); | 328 : mActivity.getString(R.string.menu_request_desktop_site_off)); |
309 } | 329 } |
310 } | 330 } |
OLD | NEW |