OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 * Construct an ExtensionLoadError around the given |div|. | |
10 * @param {HTMLDivElement} div The HTML div for the extension load error. | |
11 * @constructor | |
12 */ | |
13 function ExtensionLoadError(div) { | |
14 div.__proto__ = ExtensionLoadError.prototype; | |
15 div.init(); | |
16 return div; | |
17 } | |
18 | |
19 ExtensionLoadError.prototype = { | |
20 __proto__: HTMLDivElement.prototype, | |
21 | |
22 /** | |
23 * Initialize the ExtensionLoadError div. | |
24 */ | |
25 init: function() { | |
26 this.path_ = this.querySelector('#extension-load-error-path'); | |
27 this.reason_ = this.querySelector('#extension-load-error-reason'); | |
28 this.manifest_ = this.querySelector('#extension-load-error-manifest'); | |
29 | |
30 this.querySelector('#extension-load-error-retry-button').addEventListener( | |
31 'click', function(e) { | |
32 chrome.send('extensionLoaderRetry'); | |
33 this.hide_(); | |
34 }.bind(this)); | |
35 | |
36 this.querySelector('#extension-load-error-give-up-button'). | |
37 addEventListener('click', function(e) { | |
38 this.hide_(); | |
39 }.bind(this)); | |
40 }, | |
41 | |
42 /** | |
43 * Display the load error to the user. | |
44 * @param {string} path The path from which the extension was loaded. | |
45 * @param {string} reason The reason the extension failed to load. | |
46 * @param {string} manifest The manifest object, with highlighted regions. | |
47 */ | |
48 show: function(path, reason, manifest) { | |
49 this.path_.textContent = path; | |
50 this.reason_.textContent = reason; | |
51 | |
52 manifest.message = reason; | |
53 extensions.ExtensionUtil.populateCodeDiv( | |
54 this.manifest_, | |
55 manifest, | |
56 loadTimeData.getString('extensionLoadCouldNotLoadManifest')); | |
57 this.hidden = false; | |
58 | |
59 var errorSpan = | |
60 this.manifest_.querySelector('.extension-code-highlighted-source'); | |
61 if (errorSpan) | |
62 errorSpan.scrollIntoView(false); | |
63 }, | |
64 | |
65 /** | |
66 * Hide the extension load error. | |
67 * @private | |
68 */ | |
69 hide_: function() { | |
70 this.hidden = true; | |
71 } | |
72 }; | |
73 | |
74 /** | |
75 * The ExtensionLoader is the class in charge of loading unpacked extensions. | |
76 * @constructor | |
77 */ | |
78 function ExtensionLoader() { | |
79 this.__proto__ = ExtensionLoader.prototype; | |
not at google - send to devlin
2014/04/25 20:15:52
don't need this here
Devlin
2014/04/25 20:48:40
Done.
| |
80 this.init(); | |
not at google - send to devlin
2014/04/25 20:15:52
and it seems like you might as well inline init()
Devlin
2014/04/25 20:48:40
It's small enough. Sure.
| |
81 } | |
82 | |
83 cr.addSingletonGetter(ExtensionLoader); | |
84 | |
85 ExtensionLoader.prototype = { | |
86 /** | |
87 * Perform first-time initialization. | |
88 */ | |
89 init: function() { | |
90 /** | |
91 * The ExtensionLoadError to show any errors from loading an unpacked | |
92 * extension. | |
93 * @type {ExtensionLoadError} | |
94 * @private | |
95 */ | |
96 this.loadError_ = new ExtensionLoadError($('extension-load-error')); | |
97 }, | |
98 | |
99 /** | |
100 * Begin the sequence of loading an unpacked extension. If an error is | |
101 * encountered, this object will get notified via notifyFailed(). | |
102 */ | |
103 loadUnpacked: function() { | |
104 chrome.send('extensionLoaderLoadUnpacked'); | |
105 }, | |
106 | |
107 /** | |
108 * Notify the ExtensionLoader that loading an unpacked extension failed. | |
109 * Show the ExtensionLoadError. | |
110 * @param {string} filePath The path to the unpacked extension. | |
111 * @param {string} reason The reason the extension failed to load. | |
112 * @param {Object} manifest An object with three strings: beforeHighlight, | |
113 * afterHighlight, and highlight. These represent three portions of the | |
114 * file's content to display - the portion which is most relevant and | |
115 * should be emphasized (highlight), and the parts both before and after | |
116 * this portion. These may be empty. | |
117 */ | |
118 notifyFailed: function(filePath, reason, manifest) { | |
119 this.loadError_.show(filePath, reason, manifest); | |
120 } | |
121 }; | |
122 | |
123 /* | |
124 * A static forwarding function for ExtensionLoader.notifyFailed. | |
125 * @param {string} filePath The path to the unpacked extension. | |
126 * @param {string} reason The reason the extension failed to load. | |
127 * @param {Object} manifest The manifest of the failed extension. | |
128 * @see ExtensionLoader.notifyFailed | |
129 */ | |
130 ExtensionLoader.notifyLoadFailed = function(filePath, reason, manifest) { | |
131 ExtensionLoader.getInstance().notifyFailed(filePath, reason, manifest); | |
132 }; | |
133 | |
134 return { | |
135 ExtensionLoader: ExtensionLoader | |
136 }; | |
137 }); | |
OLD | NEW |