| 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; | 7 import android.content.Context; |
| 8 import android.content.pm.ResolveInfo; | 8 import android.content.pm.ResolveInfo; |
| 9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.graphics.PorterDuff; | 10 import android.graphics.PorterDuff; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // * file:// - After API 24, file: URIs are not supported in VIEW in
tents and thus | 171 // * file:// - After API 24, file: URIs are not supported in VIEW in
tents and thus |
| 172 // can not be added to the homescreen. | 172 // can not be added to the homescreen. |
| 173 // * content:// - Accessing external content URIs requires the calli
ng app to grant | 173 // * content:// - Accessing external content URIs requires the calli
ng app to grant |
| 174 // access to the resource via FLAG_GRANT_READ_URI_PER
MISSION, and that | 174 // access to the resource via FLAG_GRANT_READ_URI_PER
MISSION, and that |
| 175 // is not persisted when adding to the homescreen. | 175 // is not persisted when adding to the homescreen. |
| 176 // * If creating shortcuts it not supported by the current home scre
en. | 176 // * If creating shortcuts it not supported by the current home scre
en. |
| 177 boolean canShowHomeScreenMenuItem = ShortcutHelper.isAddToHomeIntent
Supported() | 177 boolean canShowHomeScreenMenuItem = ShortcutHelper.isAddToHomeIntent
Supported() |
| 178 && !isChromeScheme && !isFileScheme && !isContentScheme && !
isIncognito; | 178 && !isChromeScheme && !isFileScheme && !isContentScheme && !
isIncognito; |
| 179 prepareAddToHomescreenMenuItem(menu, currentTab, canShowHomeScreenMe
nuItem); | 179 prepareAddToHomescreenMenuItem(menu, currentTab, canShowHomeScreenMe
nuItem); |
| 180 | 180 |
| 181 // Hide request desktop site on all chrome:// pages except for the N
TP. Check request | 181 updateRequestDesktopSiteMenuItem(menu, currentTab); |
| 182 // desktop site if it's activated on this page. | |
| 183 MenuItem requestItem = menu.findItem(R.id.request_desktop_site_id); | |
| 184 updateRequestDesktopSiteMenuItem(requestItem, currentTab); | |
| 185 | 182 |
| 186 // Only display reader mode settings menu option if the current page
is in reader mode. | 183 // Only display reader mode settings menu option if the current page
is in reader mode. |
| 187 menu.findItem(R.id.reader_mode_prefs_id) | 184 menu.findItem(R.id.reader_mode_prefs_id) |
| 188 .setVisible(DomDistillerUrlUtils.isDistilledPage(currentTab.
getUrl())); | 185 .setVisible(DomDistillerUrlUtils.isDistilledPage(currentTab.
getUrl())); |
| 189 | 186 |
| 190 // Only display the Enter VR button if VR Shell Dev environment is e
nabled. | 187 // Only display the Enter VR button if VR Shell Dev environment is e
nabled. |
| 191 menu.findItem(R.id.enter_vr_id).setVisible( | 188 menu.findItem(R.id.enter_vr_id).setVisible( |
| 192 CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR
_SHELL_DEV)); | 189 CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_VR
_SHELL_DEV)); |
| 193 | 190 |
| 194 if (FeatureUtilities.isChromeHomeEnabled()) { | 191 if (FeatureUtilities.isChromeHomeEnabled()) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 bookmarkMenuItem.setChecked(true); | 357 bookmarkMenuItem.setChecked(true); |
| 361 bookmarkMenuItem.setTitleCondensed(mActivity.getString(R.string.edit
_bookmark)); | 358 bookmarkMenuItem.setTitleCondensed(mActivity.getString(R.string.edit
_bookmark)); |
| 362 } else { | 359 } else { |
| 363 bookmarkMenuItem.setIcon(R.drawable.btn_star); | 360 bookmarkMenuItem.setIcon(R.drawable.btn_star); |
| 364 bookmarkMenuItem.setChecked(false); | 361 bookmarkMenuItem.setChecked(false); |
| 365 bookmarkMenuItem.setTitleCondensed(null); | 362 bookmarkMenuItem.setTitleCondensed(null); |
| 366 } | 363 } |
| 367 } | 364 } |
| 368 | 365 |
| 369 /** | 366 /** |
| 370 * Updates the request desktop site item's visibility | 367 * Updates the request desktop site item's state. |
| 371 * | 368 * |
| 372 * @param requstMenuItem {@link MenuItem} for request desktop site. | 369 * @param requstMenuItem {@link MenuItem} for request desktop site. |
| 373 * @param currentTab Current tab being displayed. | 370 * @param currentTab Current tab being displayed. |
| 374 */ | 371 */ |
| 375 protected void updateRequestDesktopSiteMenuItem( | 372 protected void updateRequestDesktopSiteMenuItem(Menu menu, Tab currentTab) { |
| 376 MenuItem requstMenuItem, Tab currentTab) { | 373 MenuItem requestMenuRow = menu.findItem(R.id.request_desktop_site_row_me
nu_id); |
| 374 MenuItem requestMenuLabel = menu.findItem(R.id.request_desktop_site_id); |
| 375 MenuItem requestMenuCheck = menu.findItem(R.id.request_desktop_site_chec
k_id); |
| 376 |
| 377 // Hide request desktop site on all chrome:// pages except for the NTP. |
| 377 String url = currentTab.getUrl(); | 378 String url = currentTab.getUrl(); |
| 378 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX) | 379 boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX) |
| 379 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); | 380 || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); |
| 380 requstMenuItem.setVisible(!isChromeScheme || currentTab.isNativePage()); | 381 requestMenuRow.setVisible(!isChromeScheme || currentTab.isNativePage()); |
| 381 requstMenuItem.setChecked(currentTab.getUseDesktopUserAgent()); | 382 |
| 382 requstMenuItem.setTitleCondensed(requstMenuItem.isChecked() | 383 // Mark the checkbox if RDS is activated on this page. |
| 383 ? mActivity.getString(R.string.menu_request_desktop_site_on) | 384 requestMenuCheck.setChecked(currentTab.getUseDesktopUserAgent()); |
| 384 : mActivity.getString(R.string.menu_request_desktop_site_off)); | 385 |
| 386 // This title doesn't seem to be displayed by Android, but it is used to
set up |
| 387 // accessibility text in {@link AppMenuAdapter#setupMenuButton}. |
| 388 requestMenuLabel.setTitleCondensed(requestMenuLabel.isChecked() |
| 389 ? mActivity.getString(R.string.menu_request_desktop_site
_on) |
| 390 : mActivity.getString(R.string.menu_request_desktop_site
_off)); |
| 385 } | 391 } |
| 386 } | 392 } |
| OLD | NEW |