From 2b9b73bf49ee7de3c94aca85cf03bbf50138bbc8 Mon Sep 17 00:00:00 2001 From: Radoslav Vitanov Date: Sat, 27 Aug 2016 12:42:47 +0300 Subject: [PATCH 1/3] Add schortcut to view page source --- app/localShortcuts.js | 1 + js/contextMenus.js | 1 + 2 files changed, 2 insertions(+) diff --git a/app/localShortcuts.js b/app/localShortcuts.js index 455a79c6b12..6e472d5b746 100644 --- a/app/localShortcuts.js +++ b/app/localShortcuts.js @@ -22,6 +22,7 @@ module.exports.register = (win) => { ['Ctrl+PageUp', messages.SHORTCUT_PREV_TAB], ['CmdOrCtrl+9', messages.SHORTCUT_SET_ACTIVE_FRAME_TO_LAST], ['CmdOrCtrl+G', messages.SHORTCUT_ACTIVE_FRAME_FIND_NEXT], + ['CmdOrCtrl+U', messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE], ['CmdOrCtrl+Shift+G', messages.SHORTCUT_ACTIVE_FRAME_FIND_PREV], ['CmdOrCtrl+Alt+J', messages.SHORTCUT_ACTIVE_FRAME_TOGGLE_DEV_TOOLS], ['CmdOrCtrl+Shift+=', messages.SHORTCUT_ACTIVE_FRAME_ZOOM_IN], diff --git a/js/contextMenus.js b/js/contextMenus.js index 73a962a0e7f..0233fa656df 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -941,6 +941,7 @@ function mainTemplateInit (nodeProps, frame) { if (!isLink && !isImage) { template.push({ label: locale.translation('viewPageSource'), + accelerator: 'CmdOrCtrl+U', click: (item, focusedWindow) => { if (focusedWindow) { focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE) From 5c86359f52196dbf34cbb69af6bf7eebba7f6ad6 Mon Sep 17 00:00:00 2001 From: Radoslav Vitanov Date: Sat, 27 Aug 2016 14:54:06 +0300 Subject: [PATCH 2/3] Disable view source on non-web pages --- js/components/frame.js | 5 ++++- js/lib/urlutil.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/js/components/frame.js b/js/components/frame.js index aebd63170e0..313f9a61874 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -452,7 +452,10 @@ class Frame extends ImmutableComponent { break case 'view-source': const sourceLocation = UrlUtil.getViewSourceUrlFromUrl(this.webview.getURL()) - windowActions.newFrame({location: sourceLocation}, true) + let src = this.frame.get('src') + if (UrlUtil.isHttpAddress(src) && !UrlUtil.isImageAddress(src)) { + windowActions.newFrame({location: sourceLocation}, true) + } // TODO: Make the URL bar show the view-source: prefix break case 'save': diff --git a/js/lib/urlutil.js b/js/lib/urlutil.js index f6bcc56c491..ab933dd108a 100644 --- a/js/lib/urlutil.js +++ b/js/lib/urlutil.js @@ -81,6 +81,14 @@ const UrlUtil = { } }, + isImageAddress (url) { + return (url.match(/\.(jpeg|jpg|gif|png|svg|bmp)$/)) + }, + + isHttpAddress (url) { + return (url.match(/^https?:\/\/(.*)/)) + }, + /** * Checks if a string is not a URL. * @param {String} input The input value. From c368329e99a6e8cb5e7742dc6edb64b7201cb7f5 Mon Sep 17 00:00:00 2001 From: Radoslav Vitanov Date: Sat, 3 Sep 2016 06:42:47 +0300 Subject: [PATCH 3/3] Move view-source url type check --- js/components/frame.js | 3 +-- js/lib/urlutil.js | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/js/components/frame.js b/js/components/frame.js index 313f9a61874..2270b5c3417 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -452,8 +452,7 @@ class Frame extends ImmutableComponent { break case 'view-source': const sourceLocation = UrlUtil.getViewSourceUrlFromUrl(this.webview.getURL()) - let src = this.frame.get('src') - if (UrlUtil.isHttpAddress(src) && !UrlUtil.isImageAddress(src)) { + if (sourceLocation !== null) { windowActions.newFrame({location: sourceLocation}, true) } // TODO: Make the URL bar show the view-source: prefix diff --git a/js/lib/urlutil.js b/js/lib/urlutil.js index ab933dd108a..7862e467c53 100644 --- a/js/lib/urlutil.js +++ b/js/lib/urlutil.js @@ -226,6 +226,9 @@ const UrlUtil = { * @returns {String} The view-source URL. */ getViewSourceUrlFromUrl: function (input) { + if (this.isImageAddress(input) || !this.isHttpAddress(input)) { + return null + } if (this.isViewSourceUrl(input)) { return input }