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

Side by Side Diff: chrome/browser/resources/plugins.js

Issue 7086003: Apply content-security-policy to chrome://plugins page. This involves (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1
2 /**
3 * This variable structure is here to document the structure that the template
4 * expects to correctly populate the page.
5 */
6 var pluginDataFormat = {
7 'plugins': [
8 {
9 'name': 'Group Name',
10 'description': 'description',
11 'version': 'version',
12 'update_url': 'http://update/',
13 'critical': true,
14 'enabled': true,
15 'plugin_files': [
16 {
17 'path': '/blahblah/blahblah/MyCrappyPlugin.plugin',
18 'name': 'MyCrappyPlugin',
19 'version': '1.2.3',
20 'description': 'My crappy plugin',
21 'mimeTypes': [
22 { 'description': 'Foo Media',
23 'fileExtensions': [ 'foo' ],
24 'mimeType': 'application/x-my-foo' },
25 { 'description': 'Bar Stuff',
26 'fileExtensions': [ 'bar','baz' ],
27 'mimeType': 'application/my-bar' }
28 ],
29 'enabledMode': 'enabledByUser'
30 },
31 {
32 'path': '/tmp/MyFirst.plugin',
33 'name': 'MyFirstPlugin',
34 'version': '3.14r15926',
35 'description': 'My first plugin',
36 'mimeTypes': [
37 { 'description': 'New Guy Media',
38 'fileExtensions': [ 'mfp' ],
39 'mimeType': 'application/x-my-first' }
40 ],
41 'enabledMode': 'enabledByPolicy'
42 },
43 {
44 'path': '/foobar/baz/YourGreatPlugin.plugin',
45 'name': 'YourGreatPlugin',
46 'version': '4.5',
47 'description': 'Your great plugin',
48 'mimeTypes': [
49 { 'description': 'Baz Stuff',
50 'fileExtensions': [ 'baz' ],
51 'mimeType': 'application/x-your-baz' }
52 ],
53 'enabledMode': 'disabledByUser'
54 },
55 {
56 'path': '/foobiz/bar/HisGreatPlugin.plugin',
57 'name': 'HisGreatPlugin',
58 'version': '1.2',
59 'description': 'His great plugin',
60 'mimeTypes': [
61 { 'description': 'More baz Stuff',
62 'fileExtensions': [ 'bor' ],
63 'mimeType': 'application/x-his-bor' }
64 ],
65 'enabledMode': 'disabledByPolicy'
66 }
67 ]
68 }
69 ]
70 };
71
72 /**
73 * Takes the |pluginsData| input argument which represents data about the
74 * currently installed/running plugins and populates the html jstemplate with
75 * that data. It expects an object structure like the above.
76 * @param {Object} pluginsData Detailed info about installed plugins
77 */
78 function renderTemplate(pluginsData) {
79 // This is the javascript code that processes the template:
80 var input = new JsEvalContext(pluginsData);
81 var output = document.getElementById('pluginTemplate');
82 jstProcess(input, output);
83 }
84
85 /**
86 * Asks the C++ PluginsDOMHandler to get details about the installed plugins and
87 * return detailed data about the configuration. The PluginsDOMHandler should
88 * reply to returnPluginsData() (below).
89 */
90 function requestPluginsData() {
91 chrome.send('requestPluginsData', []);
92 chrome.send('getShowDetails', []);
93 }
94
95 function loadShowDetailsFromPrefs(show_details) {
96 tmiModeExpanded = show_details;
97 document.getElementById('collapse').style.display =
98 show_details ? 'inline' : 'none';
99 document.getElementById('expand').style.display =
100 show_details ? 'none' : 'inline';
101
102 document.body.className =
103 show_details ? 'showTmiMode' : 'hideTmiMode';
104 }
105
106 /**
107 * Asks the C++ PluginsDOMHandler to show the terms of service (about:terms).
108 */
109 function showTermsOfService() {
110 chrome.send('showTermsOfService', []);
111 }
112
113 /**
114 * Called by the web_ui_ to re-populate the page with data representing the
115 * current state of installed plugins.
116 */
117 function returnPluginsData(pluginsData){
118 var bodyContainer = document.getElementById('body-container');
119 var body = document.body;
120
121 // Set all page content to be visible so we can measure heights.
122 bodyContainer.style.visibility = 'hidden';
123 body.className = '';
124 var slidables = document.getElementsByClassName('showInTmiMode');
125 for (var i = 0; i < slidables.length; i++)
126 slidables[i].style.height = 'auto';
127
128 renderTemplate(pluginsData);
129
130 // Add handlers to dynamically created HTML elements.
131 var links = document.getElementsByClassName('disable-plugin-link');
132 for (var i = 0; i < links.length; ++i) {
133 links[i].onclick = function () {
134 handleEnablePlugin(this, false, false);
135 return false;
136 };
137 }
138 links = document.getElementsByClassName('enable-plugin-link');
139 for (var i = 0; i < links.length; ++i) {
140 links[i].onclick = function () {
141 handleEnablePlugin(this, true, false);
142 return false;
143 };
144 }
145 links = document.getElementsByClassName('disable-group-link');
146 for (var i = 0; i < links.length; ++i) {
147 links[i].onclick = function () {
148 handleEnablePlugin(this, false, true);
149 return false;
150 };
151 }
152 links = document.getElementsByClassName('enable-group-link');
153 for (var i = 0; i < links.length; ++i) {
154 links[i].onclick = function () {
155 handleEnablePlugin(this, true, true);
156 return false;
157 };
158 }
159
160 // Make sure the left column (with "Description:", "Location:", etc.) is the
161 // same size for all plugins.
162 var labels = document.getElementsByClassName('plugin-details-label');
163 var maxLabelWidth = 0;
164 for (var i = 0; i < labels.length; i++)
165 labels[i].style.width = 'auto';
166 for (var i = 0; i < labels.length; i++)
167 maxLabelWidth = Math.max(maxLabelWidth, labels[i].offsetWidth);
168 for (var i = 0; i < labels.length; i++)
169 labels[i].style.width = maxLabelWidth + 'px';
170
171 // Explicitly set the height for each element that wants to be "slid" in and
172 // out when the tmiModeExpanded is toggled.
173 var slidables = document.getElementsByClassName('showInTmiMode');
174 for (var i = 0; i < slidables.length; i++)
175 slidables[i].style.height = slidables[i].offsetHeight + 'px';
176
177 // Reset visibility of page based on the current tmi mode.
178 document.getElementById('collapse').style.display =
179 tmiModeExpanded ? 'inline' : 'none';
180 document.getElementById('expand').style.display =
181 tmiModeExpanded ? 'none' : 'inline';
182 bodyContainer.style.visibility = 'visible';
183 body.className = tmiModeExpanded ?
184 'showTmiModeInitial' : 'hideTmiModeInitial';
185 }
186
187 /**
188 * Handles a 'enable' or 'disable' button getting clicked.
189 */
190 function handleEnablePlugin(node, enable, isGroup) {
191 // Tell the C++ PluginsDOMHandler to enable/disable the plugin.
192 chrome.send('enablePlugin', [String(node.path), String(enable),
193 String(isGroup)]);
194 }
195
196 // Keeps track of whether details have been made visible (expanded) or not.
197 var tmiModeExpanded = false;
198
199 /*
200 * Toggles visibility of details.
201 */
202 function toggleTmiMode() {
203 tmiModeExpanded = !tmiModeExpanded;
204
205 document.getElementById('collapse').style.display =
206 tmiModeExpanded ? 'inline' : 'none';
207 document.getElementById('expand').style.display =
208 tmiModeExpanded ? 'none' : 'inline';
209
210 document.body.className =
211 tmiModeExpanded ? 'showTmiMode' : 'hideTmiMode';
212
213 chrome.send('saveShowDetailsToPrefs', [String(tmiModeExpanded)]);
214 }
215
216 /**
217 * Determines whether a plugin's version should be displayed.
218 */
219 function shouldDisplayPluginVersion(plugin) {
220 return !!plugin.version && plugin.version != '0';
221 }
222
223 /**
224 * Determines whether a plugin's description should be displayed.
225 */
226 function shouldDisplayPluginDescription(plugin) {
227 // Only display the description if it's not blank and if it's not just the
228 // name, version, or combination thereof.
229 return plugin.description &&
230 plugin.description != plugin.name &&
231 plugin.description != plugin.version &&
232 plugin.description != 'Version ' + plugin.version &&
233 plugin.description != plugin.name + ' ' + plugin.version;
234 }
235
236 /**
237 * Determines whether a plugin is enabled or not.
238 */
239 function isPluginEnabled(plugin) {
240 return plugin.enabledMode == 'enabledByUser' ||
241 plugin.enabledMode == 'enabledByPolicy';
242 }
243
244 // Unfortunately, we don't have notifications for plugin (list) status changes
245 // (yet), so in the meanwhile just update regularly.
246 setInterval(requestPluginsData, 30000);
247
248 // Get data and have it displayed upon loading.
249 document.addEventListener('DOMContentLoaded', requestPluginsData);
250
251 // Add handlers to static HTML elements.
252 document.getElementById('collapse').onclick = toggleTmiMode;
253 document.getElementById('expand').onclick = toggleTmiMode;
254 document.getElementById('details-link').onclick = toggleTmiMode;
255
OLDNEW
« no previous file with comments | « chrome/browser/resources/plugins.html ('k') | chrome/browser/resources/shared/js/jstemplate_compiled.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698