From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Mon, 13 Jul 2020 00:37:06 +0200
Subject: Add menu item to view source
---
chrome/android/java/res/menu/custom_tabs_menu.xml | 3 +++
chrome/android/java/res/menu/main_menu.xml | 3 +++
chrome/android/java/res/menu/main_menu_regroup.xml | 3 +++
.../chrome/browser/ChromeTabbedActivity.java | 2 ++
.../chrome/browser/app/ChromeActivity.java | 5 +++++
.../app/appmenu/AppMenuPropertiesDelegateImpl.java | 14 ++++++++++++++
.../CustomTabAppMenuPropertiesDelegate.java | 1 +
.../ui/android/strings/android_chrome_strings.grd | 3 +++
8 files changed, 34 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
@@ -46,6 +46,9 @@
+
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
@@ -94,6 +94,9 @@
+
diff --git a/chrome/android/java/res/menu/main_menu_regroup.xml b/chrome/android/java/res/menu/main_menu_regroup.xml
--- a/chrome/android/java/res/menu/main_menu_regroup.xml
+++ b/chrome/android/java/res/menu/main_menu_regroup.xml
@@ -145,6 +145,9 @@
+
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
@@ -1881,6 +1881,8 @@ public class ChromeTabbedActivity extends ChromeActivity
return true;
}
+ if (id == R.id.view_source_id) {
+ currentTab.getWebContents().getNavigationController().loadUrl(new LoadUrlParams("view-source:"+currentTab.getUrlString()));
+ 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
@@ -537,6 +537,7 @@ public class AppMenuPropertiesDelegateImpl implements AppMenuPropertiesDelegate
}
updateRequestDesktopSiteMenuItem(menu, currentTab, true /* can show */);
+ updateViewSourceMenuItem(menu, currentTab);
// Only display reader mode settings menu option if the current page is in reader mode.
menu.findItem(R.id.reader_mode_prefs_id).setVisible(shouldShowReaderModePrefs(currentTab));
@@ -950,6 +951,19 @@ 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);
+ String url = currentTab.getUrlString();
+ viewSourceMenuItem.setVisible(!url.isEmpty() && !url.startsWith("view-source:"));
+ }
+
/**
* 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
@@ -228,6 +228,7 @@ public class CustomTabAppMenuPropertiesDelegate extends AppMenuPropertiesDelegat
updateRequestDesktopSiteMenuItem(menu, currentTab, requestDesktopSiteVisible);
MenuItem homescreenItem = menu.findItem(R.id.add_to_homescreen_id);
MenuItem openWebApkItem = menu.findItem(R.id.open_webapk_id);
+ updateViewSourceMenuItem(menu, currentTab);
prepareAddToHomescreenMenuItem(
homescreenItem, null, openWebApkItem, 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
@@ -344,6 +344,9 @@ CHAR-LIMIT guidelines:
Other Google services
+
+ View source
+
Google services
--
2.17.1