Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('extensions', function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 /** | |
| 9 * The ExtensionErrorOverlay will show the contents of a file which pertains | |
| 10 * to the ExtensionError; this is either the manifest file (for manifest | |
| 11 * errors) or a source file (for runtime errors). If possible, the portion | |
| 12 * of the file which caused the error will be highlighted. | |
| 13 * @constructor | |
| 14 */ | |
| 15 function ExtensionErrorOverlay() { | |
| 16 } | |
| 17 | |
| 18 cr.addSingletonGetter(ExtensionErrorOverlay); | |
| 19 | |
| 20 ExtensionErrorOverlay.prototype = { | |
| 21 /** | |
| 22 * Initialize the page. | |
| 23 */ | |
| 24 initializePage: function() { | |
| 25 var overlay = $('overlay'); | |
| 26 cr.ui.overlay.setupOverlay(overlay); | |
| 27 cr.ui.overlay.globalInitialization(); | |
| 28 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); | |
| 29 | |
| 30 $('extension-error-overlay-dismiss').addEventListener( | |
| 31 'click', this.handleDismiss_.bind(this)); | |
| 32 }, | |
| 33 | |
| 34 /** | |
| 35 * Handles a click on the dismiss button. | |
| 36 * @param {Event} e The click event. | |
| 37 * @private | |
| 38 */ | |
| 39 handleDismiss_: function(e) { | |
| 40 $('extension-error-overlay-content').innerHTML = ''; | |
| 41 ExtensionSettings.showOverlay(null); | |
| 42 }, | |
| 43 }; | |
| 44 | |
| 45 /** | |
| 46 * Called by the ExtensionErrorHandler responding to the request for a file's | |
| 47 * source. Populate the content area of the overlay and display the overlay. | |
| 48 * @param {Object} result An object with four strings - the title, | |
| 49 * beforeHighlight, afterHighlight, and highlight. The three 'highlight' | |
| 50 * strings represent three portions of the file's content to display - the | |
| 51 * portion which is most relevant and should be emphasized (highlight), | |
| 52 * and the parts both before and after this portion. These may be empty. | |
| 53 */ | |
| 54 ExtensionErrorOverlay.requestFileSourceResponse = function(result) { | |
| 55 var content = $('extension-error-overlay-content'); | |
| 56 $('extension-error-overlay').querySelector( | |
| 57 '.extension-error-overlay-title').innerText = result.title; | |
| 58 | |
| 59 var createSpan = function(source, isHighlighted) { | |
| 60 var span = document.createElement('span'); | |
| 61 span.className = isHighlighted ? 'highlighted-source' : 'normal-source'; | |
| 62 source = source.replace(/ /g, ' ').replace(/\n/g, '<br/>'); | |
|
Dan Beam
2013/08/21 23:41:03
s/<br\/>/<br>/, also what about \r or \n\n?
Devlin
2013/08/22 18:29:06
\r addressed. What's the issue with \n\n? Isn't d
Dan Beam
2013/08/29 00:24:30
oh, sorry, \n\n should be fine because of /g flag,
| |
| 63 span.innerHTML = source; | |
| 64 return span; | |
| 65 }; | |
| 66 | |
| 67 if (result.beforeHighlight) | |
| 68 content.appendChild(createSpan(result.beforeHighlight, false)); | |
| 69 if (result.highlight) { | |
| 70 var highlightSpan = createSpan(result.highlight, true); | |
| 71 highlightSpan.title = result.errorMessage; | |
| 72 content.appendChild(highlightSpan); | |
| 73 } | |
| 74 if (result.afterHighlight) | |
| 75 content.appendChild(createSpan(result.afterHighlight, false)); | |
| 76 | |
| 77 ExtensionSettings.showOverlay($('extension-error-overlay')); | |
| 78 }; | |
| 79 | |
| 80 // Export | |
| 81 return { | |
| 82 ExtensionErrorOverlay: ExtensionErrorOverlay | |
| 83 }; | |
| 84 }); | |
| OLD | NEW |