Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: chrome/browser/resources/extensions/extension_error_overlay.js

Issue 252593003: Improve UI for unpacked extensions failing to load (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ExtensionCode js object Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 cr.define('extensions', function() { 5 cr.define('extensions', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Clear all the content of a given element. 9 * Clear all the content of a given element.
10 * @param {HTMLElement} element The element to be cleared. 10 * @param {HTMLElement} element The element to be cleared.
11 */ 11 */
12 function clearElement(element) { 12 function clearElement(element) {
13 while (element.firstChild) 13 while (element.firstChild)
14 element.removeChild(element.firstChild); 14 element.removeChild(element.firstChild);
15 } 15 };
not at google - send to devlin 2014/04/25 21:00:34 no ;
Devlin 2014/04/25 22:19:09 whoops, done.
16 16
17 /** 17 /**
18 * Get the url relative to the main extension url. If the url is 18 * Get the url relative to the main extension url. If the url is
19 * unassociated with the extension, this will be the full url. 19 * unassociated with the extension, this will be the full url.
20 * @param {string} url The url to make relative. 20 * @param {string} url The url to make relative.
21 * @param {string} extensionUrl The url for the extension resources, in the 21 * @param {string} extensionUrl The url for the extension resources, in the
22 * form "chrome-etxension://<extension_id>/". 22 * form "chrome-etxension://<extension_id>/".
23 * @return {string} The url relative to the host. 23 * @return {string} The url relative to the host.
24 */ 24 */
25 function getRelativeUrl(url, extensionUrl) { 25 function getRelativeUrl(url, extensionUrl) {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 /** 368 /**
369 * The element of the full overlay. 369 * The element of the full overlay.
370 * @type {HTMLDivElement} 370 * @type {HTMLDivElement}
371 * @private 371 * @private
372 */ 372 */
373 this.overlayDiv_ = $('extension-error-overlay'); 373 this.overlayDiv_ = $('extension-error-overlay');
374 374
375 /** 375 /**
376 * The portion of the overlay which shows the code relating to the error 376 * The portion of the overlay which shows the code relating to the error
377 * and the corresponding line numbers. 377 * and the corresponding line numbers.
378 * @type {HTMLElement} 378 * @type {ExtensionCode}
379 * @private 379 * @private
380 */ 380 */
381 this.codeDiv_ = $('extension-error-overlay-code'); 381 this.codeDiv_ =
382 382 new extensions.ExtensionCode($('extension-error-overlay-code'));
383 // Also initialize two properties of codeDiv for the section for the pure
384 // file content and the section for the line numbers.
385 this.codeDiv_.sourceDiv =
386 this.codeDiv_.querySelector('#extension-error-overlay-source');
387 this.codeDiv_.linesDiv =
388 this.codeDiv_.querySelector('#extension-error-overlay-line-numbers');
389 383
390 /** 384 /**
391 * The function to show or hide the ExtensionErrorOverlay. 385 * The function to show or hide the ExtensionErrorOverlay.
392 * @type {function} 386 * @type {function}
393 * @param {boolean} isVisible Whether the overlay should be visible. 387 * @param {boolean} isVisible Whether the overlay should be visible.
394 */ 388 */
395 this.setVisible = function(isVisible) { 389 this.setVisible = function(isVisible) {
396 showOverlay(isVisible ? this.overlayDiv_ : null); 390 showOverlay(isVisible ? this.overlayDiv_ : null);
397 }; 391 };
398 392
(...skipping 17 matching lines...) Expand all
416 handleDismiss_: function(e) { 410 handleDismiss_: function(e) {
417 this.setVisible(false); 411 this.setVisible(false);
418 412
419 // There's a chance that the overlay receives multiple dismiss events; in 413 // There's a chance that the overlay receives multiple dismiss events; in
420 // this case, handle it gracefully and return (since all necessary work 414 // this case, handle it gracefully and return (since all necessary work
421 // will already have been done). 415 // will already have been done).
422 if (!this.error_) 416 if (!this.error_)
423 return; 417 return;
424 418
425 // Remove all previous content. 419 // Remove all previous content.
426 clearElement(this.codeDiv_.sourceDiv); 420 clearElement(this.codeDiv_);
not at google - send to devlin 2014/04/25 21:00:34 this should be "this.codeDiv_.clear()" right?
Devlin 2014/04/25 22:19:09 They do the same thing, but probably cleaner that
427 clearElement(this.codeDiv_.linesDiv);
428 421
429 this.openDevtoolsButton_.hidden = true; 422 this.openDevtoolsButton_.hidden = true;
430 423
431 if (this.error_.type == ExtensionErrorOverlay.RUNTIME_ERROR_TYPE_) { 424 if (this.error_.type == ExtensionErrorOverlay.RUNTIME_ERROR_TYPE_) {
432 this.overlayDiv_.querySelector('.content-area').removeChild( 425 this.overlayDiv_.querySelector('.content-area').removeChild(
433 this.runtimeErrorContent_); 426 this.runtimeErrorContent_);
434 this.runtimeErrorContent_.clearError(); 427 this.runtimeErrorContent_.clearError();
435 } 428 }
436 429
437 this.error_ = undefined; 430 this.error_ = undefined;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 * Set the code to be displayed in the code portion of the overlay. 477 * Set the code to be displayed in the code portion of the overlay.
485 * @see ExtensionErrorOverlay.requestFileSourceResponse(). 478 * @see ExtensionErrorOverlay.requestFileSourceResponse().
486 * @param {?Object} code The code to be displayed. If |code| is null, then 479 * @param {?Object} code The code to be displayed. If |code| is null, then
487 * a "Could not display code" message will be displayed instead. 480 * a "Could not display code" message will be displayed instead.
488 */ 481 */
489 setCode: function(code) { 482 setCode: function(code) {
490 document.querySelector( 483 document.querySelector(
491 '#extension-error-overlay .extension-error-overlay-title'). 484 '#extension-error-overlay .extension-error-overlay-title').
492 textContent = code.title; 485 textContent = code.title;
493 486
494 // Remove all previous content. This should be done on close, but, just in 487 this.codeDiv_.populate(
495 // case we crashed, do it again. 488 code,
496 clearElement(this.codeDiv_.sourceDiv); 489 loadTimeData.getString('extensionErrorOverlayNoCodeToDisplay'));
497 clearElement(this.codeDiv_.linesDiv);
498
499 // If there's no code, then display an appropriate message.
500 if (!code) {
501 var span = document.createElement('span');
502 span.textContent =
503 loadTimeData.getString('extensionErrorOverlayNoCodeToDisplay');
504 this.codeDiv_.sourceDiv.appendChild(span);
505 return;
506 }
507
508 var lineCount = 0;
509 var createSpan = function(source, isHighlighted) {
510 lineCount += source.split('\n').length - 1;
511 var span = document.createElement('span');
512 span.className = isHighlighted ? 'highlighted-source' : 'normal-source';
513 span.textContent = source;
514 return span;
515 };
516
517 if (code.beforeHighlight) {
518 this.codeDiv_.sourceDiv.appendChild(
519 createSpan(code.beforeHighlight, false));
520 }
521
522 if (code.highlight) {
523 var highlightSpan = createSpan(code.highlight, true);
524 highlightSpan.title = code.message;
525 this.codeDiv_.sourceDiv.appendChild(highlightSpan);
526 }
527
528 if (code.afterHighlight) {
529 this.codeDiv_.sourceDiv.appendChild(
530 createSpan(code.afterHighlight, false));
531 }
532
533 // Make the line numbers. This should be the number of line breaks + 1
534 // (the last line doesn't break, but should still be numbered).
535 var content = '';
536 for (var i = 1; i < lineCount + 1; ++i)
537 content += i + '\n';
538 var span = document.createElement('span');
539 span.textContent = content;
540 this.codeDiv_.linesDiv.appendChild(span);
541 }, 490 },
542 }; 491 };
543 492
544 /** 493 /**
545 * Called by the ExtensionErrorHandler responding to the request for a file's 494 * Called by the ExtensionErrorHandler responding to the request for a file's
546 * source. Populate the content area of the overlay and display the overlay. 495 * source. Populate the content area of the overlay and display the overlay.
547 * @param {Object?} result An object with four strings - the title, 496 * @param {Object?} result An object with four strings - the title,
548 * beforeHighlight, afterHighlight, and highlight. The three 'highlight' 497 * beforeHighlight, afterHighlight, and highlight. The three 'highlight'
549 * strings represent three portions of the file's content to display - the 498 * strings represent three portions of the file's content to display - the
550 * portion which is most relevant and should be emphasized (highlight), 499 * portion which is most relevant and should be emphasized (highlight),
551 * and the parts both before and after this portion. These may be empty. 500 * and the parts both before and after this portion. These may be empty.
552 */ 501 */
553 ExtensionErrorOverlay.requestFileSourceResponse = function(result) { 502 ExtensionErrorOverlay.requestFileSourceResponse = function(result) {
554 var overlay = extensions.ExtensionErrorOverlay.getInstance(); 503 var overlay = extensions.ExtensionErrorOverlay.getInstance();
555 overlay.setCode(result); 504 overlay.setCode(result);
556 overlay.setVisible(true); 505 overlay.setVisible(true);
557 }; 506 };
558 507
559 // Export 508 // Export
560 return { 509 return {
561 ExtensionErrorOverlay: ExtensionErrorOverlay 510 ExtensionErrorOverlay: ExtensionErrorOverlay
562 }; 511 };
563 }); 512 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698