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.
5 cr.define('extensions', function() {
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.
15 function ExtensionErrorOverlay() {
18 cr.addSingletonGetter(ExtensionErrorOverlay);
20 ExtensionErrorOverlay.prototype = {
22 * Initialize the page.
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));
30 $('extension-error-overlay-dismiss').addEventListener(
31 'click', this.handleDismiss_.bind(this));
35 * Handles a click on the dismiss button.
36 * @param {Event} e The click event.
39 handleDismiss_: function(e) {
40 $('extension-error-overlay-content').innerHTML = '';
41 extensions.ExtensionSettings.showOverlay(null);
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.
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;
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;
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);
75 if (result.afterHighlight)
76 content.appendChild(createSpan(result.afterHighlight, false));
78 extensions.ExtensionSettings.showOverlay($('extension-error-overlay'));
83 ExtensionErrorOverlay: ExtensionErrorOverlay