From 1f2597dca11cd07de86e56f84ef351ba7d2d612e Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Sun, 13 Aug 2017 16:15:26 +0200 Subject: [PATCH] Bug 1389829 - Part 1 - Add "View Page Source" to the Page menu in the UI. r=nechen The Page menu is disabled when no tab is open, so not doing a null-check on the currently selected tab in the menu click handler is safe. MozReview-Commit-ID: CYKHJ5N1q8I --HG-- extra : rebase_source : 3ec7b1a9708a905785850feb44b48723c24f1363 --- .../src/main/res/menu-large/browser_app_menu.xml | 3 +++ .../src/main/res/menu-xlarge/browser_app_menu.xml | 3 +++ .../app/src/main/res/menu/browser_app_menu.xml | 3 +++ .../base/java/org/mozilla/gecko/BrowserApp.java | 15 +++++++++++++-- .../base/locales/en-US/android_strings.dtd | 1 + mobile/android/base/strings.xml.in | 1 + 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mobile/android/app/src/main/res/menu-large/browser_app_menu.xml b/mobile/android/app/src/main/res/menu-large/browser_app_menu.xml index f6492f7ee5f4..4210149fd0c4 100644 --- a/mobile/android/app/src/main/res/menu-large/browser_app_menu.xml +++ b/mobile/android/app/src/main/res/menu-large/browser_app_menu.xml @@ -86,6 +86,9 @@ + + diff --git a/mobile/android/app/src/main/res/menu-xlarge/browser_app_menu.xml b/mobile/android/app/src/main/res/menu-xlarge/browser_app_menu.xml index 065b900e06a5..c95255a9316c 100644 --- a/mobile/android/app/src/main/res/menu-xlarge/browser_app_menu.xml +++ b/mobile/android/app/src/main/res/menu-xlarge/browser_app_menu.xml @@ -87,6 +87,9 @@ + + diff --git a/mobile/android/app/src/main/res/menu/browser_app_menu.xml b/mobile/android/app/src/main/res/menu/browser_app_menu.xml index a12e54874ee9..439b9e9f117c 100644 --- a/mobile/android/app/src/main/res/menu/browser_app_menu.xml +++ b/mobile/android/app/src/main/res/menu/browser_app_menu.xml @@ -86,6 +86,9 @@ + + diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java index f1368c99fe3c..840f9a1c645b 100644 --- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java @@ -3540,6 +3540,7 @@ public class BrowserApp extends GeckoApp final MenuItem historyList = aMenu.findItem(R.id.history_list); final MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf); final MenuItem print = aMenu.findItem(R.id.print); + final MenuItem viewPageSource = aMenu.findItem(R.id.view_page_source); final MenuItem charEncoding = aMenu.findItem(R.id.char_encoding); final MenuItem findInPage = aMenu.findItem(R.id.find_in_page); final MenuItem desktopMode = aMenu.findItem(R.id.desktop_mode); @@ -3568,6 +3569,7 @@ public class BrowserApp extends GeckoApp saveAsPDF.setEnabled(false); print.setEnabled(false); findInPage.setEnabled(false); + viewPageSource.setEnabled(false); // NOTE: Use MenuUtils.safeSetEnabled because some actions might // be on the BrowserToolbar context menu. @@ -3730,8 +3732,10 @@ public class BrowserApp extends GeckoApp print.setEnabled(allowPDF); print.setVisible(Versions.feature19Plus); - // Disable find in page for about:home, since it won't work on Java content. - findInPage.setEnabled(!isAboutHome(tab)); + // Disable find in page and view source for about:home, since it won't work on Java content. + final boolean notInAboutHome = !isAboutHome(tab); + findInPage.setEnabled(notInAboutHome); + viewPageSource.setEnabled(notInAboutHome); charEncoding.setVisible(GeckoPreferences.getCharEncodingState()); @@ -3929,6 +3933,13 @@ public class BrowserApp extends GeckoApp return true; } + if (itemId == R.id.view_page_source) { + tab = Tabs.getInstance().getSelectedTab(); + final GeckoBundle args = new GeckoBundle(1); + args.putInt("tabId", tab.getId()); + getAppEventDispatcher().dispatch("Tab:ViewSource", args); + } + if (itemId == R.id.settings) { intent = new Intent(this, GeckoPreferences.class); diff --git a/mobile/android/base/locales/en-US/android_strings.dtd b/mobile/android/base/locales/en-US/android_strings.dtd index 393bca743039..4ea2a29b0092 100644 --- a/mobile/android/base/locales/en-US/android_strings.dtd +++ b/mobile/android/base/locales/en-US/android_strings.dtd @@ -453,6 +453,7 @@ + diff --git a/mobile/android/base/strings.xml.in b/mobile/android/base/strings.xml.in index d7db3e25ddf5..af101b0b8175 100644 --- a/mobile/android/base/strings.xml.in +++ b/mobile/android/base/strings.xml.in @@ -107,6 +107,7 @@ &share_image_failed; &save_as_pdf; &print; + &view_page_source; &find_in_page; &desktop_mode; &page;