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 extensions.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 document.querySelector( |
| 57 '#extension-error-overlay .extension-error-overlay-title'). |
| 58 innerText = result.title; |
| 59 |
| 60 var createSpan = function(source, isHighlighted) { |
| 61 var span = document.createElement('span'); |
| 62 span.className = isHighlighted ? 'highlighted-source' : 'normal-source'; |
| 63 source = source.replace(/ /g, ' ').replace(/\n|\r/g, '<br>'); |
| 64 span.innerHTML = source; |
| 65 return span; |
| 66 }; |
| 67 |
| 68 if (result.beforeHighlight) |
| 69 content.appendChild(createSpan(result.beforeHighlight, false)); |
| 70 if (result.highlight) { |
| 71 var highlightSpan = createSpan(result.highlight, true); |
| 72 highlightSpan.title = result.message; |
| 73 content.appendChild(highlightSpan); |
| 74 } |
| 75 if (result.afterHighlight) |
| 76 content.appendChild(createSpan(result.afterHighlight, false)); |
| 77 |
| 78 extensions.ExtensionSettings.showOverlay($('extension-error-overlay')); |
| 79 }; |
| 80 |
| 81 // Export |
| 82 return { |
| 83 ExtensionErrorOverlay: ExtensionErrorOverlay |
| 84 }; |
| 85 }); |
OLD | NEW |