From: csagan5 <32685696+csagan5@users.noreply.github.com> Date: Mon, 13 Jul 2020 00:37:06 +0200 Subject: Add menu item to view source License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html --- .../android/java/res/menu/custom_tabs_menu.xml | 3 +++ chrome/android/java/res/menu/main_menu.xml | 3 +++ .../chrome/browser/ChromeTabbedActivity.java | 2 ++ .../chrome/browser/app/ChromeActivity.java | 5 +++++ .../appmenu/AppMenuPropertiesDelegateImpl.java | 18 ++++++++++++++++++ .../CustomTabAppMenuPropertiesDelegate.java | 1 + .../android/strings/android_chrome_strings.grd | 4 ++++ 7 files changed, 36 insertions(+) diff --git a/chrome/android/java/res/menu/custom_tabs_menu.xml b/chrome/android/java/res/menu/custom_tabs_menu.xml --- a/chrome/android/java/res/menu/custom_tabs_menu.xml +++ b/chrome/android/java/res/menu/custom_tabs_menu.xml @@ -55,6 +55,9 @@ found in the LICENSE file. + diff --git a/chrome/android/java/res/menu/main_menu.xml b/chrome/android/java/res/menu/main_menu.xml --- a/chrome/android/java/res/menu/main_menu.xml +++ b/chrome/android/java/res/menu/main_menu.xml @@ -113,6 +113,9 @@ found in the LICENSE file. + diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java @@ -2319,6 +2319,8 @@ public class ChromeTabbedActivity extends ChromeActivity return doOpenWebApk(currentTab); } + if (id == R.id.view_source_id) { + currentTab.getWebContents().getNavigationController().loadUrl(new LoadUrlParams("view-source:"+currentTab.getUrl().getSpec())); + return true; + } + if (id == R.id.request_desktop_site_id || id == R.id.request_desktop_site_check_id) { boolean usingDesktopUserAgent = currentTab.getWebContents().getNavigationController().getUseDesktopUserAgent(); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/app/appmenu/AppMenuPropertiesDelegateImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/app/appmenu/AppMenuPropertiesDelegateImpl.java --- a/chrome/android/java/src/org/chromium/chrome/browser/app/appmenu/AppMenuPropertiesDelegateImpl.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/app/appmenu/AppMenuPropertiesDelegateImpl.java @@ -550,6 +550,7 @@ public class AppMenuPropertiesDelegateImpl implements AppMenuPropertiesDelegate isChromeScheme, isFileScheme, isContentScheme, isIncognito, url)); updateRequestDesktopSiteMenuItem(menu, currentTab, true /* can show */, isChromeScheme); + updateViewSourceMenuItem(menu, currentTab); updateAutoDarkMenuItem(menu, currentTab, isChromeScheme); @@ -1142,6 +1143,23 @@ public class AppMenuPropertiesDelegateImpl implements AppMenuPropertiesDelegate } } + /** + * Updates the view source menu item's state. + * + * @param menu {@link Menu} for view source. + * @param currentTab Current tab being displayed. + */ + protected void updateViewSourceMenuItem( + Menu menu, Tab currentTab) { + MenuItem viewSourceMenuItem = menu.findItem(R.id.view_source_id); + boolean visible = false; + if (currentTab != null) { + String url = currentTab.getUrl().getSpec(); + visible = !url.isEmpty() && !url.startsWith("view-source:"); + } + viewSourceMenuItem.setVisible(visible); + } + /** * Updates the request desktop site item's state. * diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabAppMenuPropertiesDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabAppMenuPropertiesDelegate.java --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabAppMenuPropertiesDelegate.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabAppMenuPropertiesDelegate.java @@ -241,6 +241,7 @@ public class CustomTabAppMenuPropertiesDelegate extends AppMenuPropertiesDelegat updateRequestDesktopSiteMenuItem( menu, currentTab, requestDesktopSiteVisible, isChromeScheme); + updateViewSourceMenuItem(menu, currentTab); prepareAddToHomescreenMenuItem(menu, currentTab, addToHomeScreenVisible); } } diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd --- a/chrome/browser/ui/android/strings/android_chrome_strings.grd +++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd @@ -314,6 +314,10 @@ CHAR_LIMIT guidelines: USB + + View source + + You and Google -- 2.25.1