| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 // This is the shared code for security interstitials. It is used for both SSL | 5 // This is the shared code for security interstitials. It is used for both SSL |
| 6 // interstitials and Safe Browsing interstitials. | 6 // interstitials and Safe Browsing interstitials. |
| 7 | 7 |
| 8 // Should match security_interstitials::SecurityInterstitialCommands | 8 // Should match security_interstitials::SecurityInterstitialCommands |
| 9 /** @enum| {string} */ | 9 /** @enum| {string} */ |
| 10 var SecurityInterstitialCommandId = { | 10 var SecurityInterstitialCommandId = { |
| 11 CMD_DONT_PROCEED: 0, | 11 CMD_DONT_PROCEED: 0, |
| 12 CMD_PROCEED: 1, | 12 CMD_PROCEED: 1, |
| 13 // Ways for user to get more information | 13 // Ways for user to get more information |
| 14 CMD_SHOW_MORE_SECTION: 2, | 14 CMD_SHOW_MORE_SECTION: 2, |
| 15 CMD_OPEN_HELP_CENTER: 3, | 15 CMD_OPEN_HELP_CENTER: 3, |
| 16 CMD_OPEN_DIAGNOSTIC: 4, | 16 CMD_OPEN_DIAGNOSTIC: 4, |
| 17 // Primary button actions | 17 // Primary button actions |
| 18 CMD_RELOAD: 5, | 18 CMD_RELOAD: 5, |
| 19 CMD_OPEN_DATE_SETTINGS: 6, | 19 CMD_OPEN_DATE_SETTINGS: 6, |
| 20 CMD_OPEN_LOGIN: 7, | 20 CMD_OPEN_LOGIN: 7, |
| 21 // Safe Browsing Extended Reporting | 21 // Safe Browsing Extended Reporting |
| 22 CMD_DO_REPORT: 8, | 22 CMD_DO_REPORT: 8, |
| 23 CMD_DONT_REPORT: 9, | 23 CMD_DONT_REPORT: 9, |
| 24 CMD_OPEN_REPORTING_PRIVACY: 10, | 24 CMD_OPEN_REPORTING_PRIVACY: 10, |
| 25 CMD_OPEN_WHITEPAPER: 11, | 25 CMD_OPEN_WHITEPAPER: 11, |
| 26 // Report a phishing error. | 26 // Report a phishing error. |
| 27 CMD_REPORT_PHISHING_ERROR: 12 | 27 CMD_REPORT_PHISHING_ERROR: 12 |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 var HIDDEN_CLASS = 'hidden'; |
| 31 |
| 30 /** | 32 /** |
| 31 * A convenience method for sending commands to the parent page. | 33 * A convenience method for sending commands to the parent page. |
| 32 * @param {string} cmd The command to send. | 34 * @param {string} cmd The command to send. |
| 33 */ | 35 */ |
| 34 function sendCommand(cmd) { | 36 function sendCommand(cmd) { |
| 35 // <if expr="not is_ios"> | 37 // <if expr="not is_ios"> |
| 36 window.domAutomationController.setAutomationId(1); | 38 window.domAutomationController.setAutomationId(1); |
| 37 window.domAutomationController.send(cmd); | 39 window.domAutomationController.send(cmd); |
| 38 // </if> | 40 // </if> |
| 39 // <if expr="is_ios"> | 41 // <if expr="is_ios"> |
| 40 // TODO(crbug.com/565877): Revisit message passing for WKWebView. | 42 // TODO(crbug.com/565877): Revisit message passing for WKWebView. |
| 41 var iframe = document.createElement('IFRAME'); | 43 var iframe = document.createElement('IFRAME'); |
| 42 iframe.setAttribute('src', 'js-command:' + cmd); | 44 iframe.setAttribute('src', 'js-command:' + cmd); |
| 43 document.documentElement.appendChild(iframe); | 45 document.documentElement.appendChild(iframe); |
| 44 iframe.parentNode.removeChild(iframe); | 46 iframe.parentNode.removeChild(iframe); |
| 45 // </if> | 47 // </if> |
| 46 } | 48 } |
| 49 |
| 50 /** |
| 51 * Call this to stop clicks on <a href="#"> links from scrolling to the top of |
| 52 * the page (and possibly showing a # in the link). |
| 53 */ |
| 54 function preventDefaultOnPoundLinkClicks() { |
| 55 document.addEventListener('click', function(e) { |
| 56 var anchor = findAncestor(/** @type {Node} */ (e.target), function(el) { |
| 57 return el.tagName == 'A'; |
| 58 }); |
| 59 // Use getAttribute() to prevent URL normalization. |
| 60 if (anchor && anchor.getAttribute('href') == '#') |
| 61 e.preventDefault(); |
| 62 }); |
| 63 } |
| OLD | NEW |