OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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('options.WebsiteSettings', function() { | 5 cr.define('options.WebsiteSettings', function() { |
6 /** @const */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
7 | 7 |
8 ///////////////////////////////////////////////////////////////////////////// | 8 ///////////////////////////////////////////////////////////////////////////// |
9 // WebsiteSettingsEditor class: | 9 // WebsiteSettingsEditor class: |
10 | 10 |
11 /** | 11 /** |
12 * Encapsulated handling of the website settings editor page. | 12 * Encapsulated handling of the website settings editor page. |
13 * @constructor | 13 * @constructor |
14 */ | 14 */ |
15 function WebsiteSettingsEditor() { | 15 function WebsiteSettingsEditor() { |
16 Page.call(this, 'websiteEdit', | 16 Page.call(this, 'websiteEdit', |
17 loadTimeData.getString('websitesOptionsPageTabTitle'), | 17 loadTimeData.getString('websitesOptionsPageTabTitle'), |
18 'website-settings-edit-page'); | 18 'website-settings-edit-page'); |
19 this.permissions = ['geolocation', 'notifications', 'media-stream', | 19 this.permissions = ['geolocation', 'notifications', 'media-stream', |
20 'cookies']; | 20 'cookies', 'multiple-automatic-downloads', 'images', |
21 'plugins', 'popups', 'javascript']; | |
21 } | 22 } |
22 | 23 |
23 cr.addSingletonGetter(WebsiteSettingsEditor); | 24 cr.addSingletonGetter(WebsiteSettingsEditor); |
24 | 25 |
25 WebsiteSettingsEditor.prototype = { | 26 WebsiteSettingsEditor.prototype = { |
26 __proto__: Page.prototype, | 27 __proto__: Page.prototype, |
27 | 28 |
28 | 29 |
29 /** @override */ | 30 /** @override */ |
30 initializePage: function() { | 31 initializePage: function() { |
31 Page.prototype.initializePage.call(this); | 32 Page.prototype.initializePage.call(this); |
32 | 33 |
33 $('website-settings-storage-delete-button').onclick = function(event) { | 34 $('website-settings-storage-delete-button').onclick = function(event) { |
34 chrome.send('deleteLocalStorage'); | 35 chrome.send('deleteLocalStorage'); |
35 }; | 36 }; |
36 | 37 |
37 $('website-settings-battery-stop-button').onclick = function(event) { | 38 $('website-settings-battery-stop-button').onclick = function(event) { |
38 chrome.send('stopOrigin'); | 39 chrome.send('stopOrigin'); |
39 }; | 40 }; |
40 | 41 |
41 $('websiteSettingsEditorCancelButton').onclick = | 42 $('websiteSettingsEditorCancelButton').onclick = |
42 PageManager.closeOverlay.bind(PageManager); | 43 PageManager.closeOverlay.bind(PageManager); |
43 | 44 |
44 $('websiteSettingsEditorDoneButton').onclick = function(event) { | 45 $('websiteSettingsEditorDoneButton').onclick = function(event) { |
45 WebsiteSettingsEditor.getInstance().updatePermissions(); | 46 WebsiteSettingsEditor.getInstance().updatePermissions(); |
46 PageManager.closeOverlay.bind(PageManager)(); | 47 PageManager.closeOverlay.bind(PageManager)(); |
47 }; | 48 }; |
49 | |
50 var permissionList = | |
51 this.pageDiv.querySelector('.origin-permission-list'); | |
52 for (var key in this.permissions) { | |
53 permissionList.appendChild( | |
54 this.makePermissionOption_(this.permissions[key])); | |
55 } | |
48 }, | 56 }, |
49 | 57 |
50 /** | 58 /** |
51 * Populates the page with the proper information for a given URL. | 59 * Populates the page with the proper information for a given URL. |
52 * @param {string} url The URL of the page. | 60 * @param {string} url The URL of the page. |
53 * @private | 61 * @private |
54 */ | 62 */ |
55 populatePage: function(url) { | 63 populatePage: function(url) { |
56 this.url = url; | 64 this.url = url; |
57 | 65 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 104 |
97 updatePermissions: function() { | 105 updatePermissions: function() { |
98 for (var key in this.permissions) { | 106 for (var key in this.permissions) { |
99 var selection = $(this.permissions[key] + '-select-option'); | 107 var selection = $(this.permissions[key] + '-select-option'); |
100 if (selection.value != selection.originalValue) { | 108 if (selection.value != selection.originalValue) { |
101 chrome.send('setOriginPermission', | 109 chrome.send('setOriginPermission', |
102 [this.permissions[key], selection.value]); | 110 [this.permissions[key], selection.value]); |
103 } | 111 } |
104 } | 112 } |
105 }, | 113 }, |
114 | |
115 /** | |
116 * Populates the origin permission list with the different usable | |
117 * permissions. | |
118 * @param {string} permissionName A string with the permission name. | |
119 * @return {Element} The element with the usable permission setting. | |
120 */ | |
121 makePermissionOption_: function(permissionName) { | |
122 var permissionNameWithoutDash = permissionName.replace(/-/g, ''); | |
123 var permissionOption = cr.doc.createElement('div'); | |
124 permissionOption.className = 'permission-option'; | |
125 | |
126 var permissionNameSpan = cr.doc.createElement('span'); | |
127 permissionNameSpan.className = 'permission-name'; | |
128 permissionNameSpan.textContent = loadTimeData.getString('websites' + | |
Bernhard Bauer
2014/09/05 08:56:18
At this point it might be easier to either
a) writ
Daniel Nishi
2014/09/05 18:02:39
I've gone with b so we can have the flexibility to
| |
129 permissionNameWithoutDash[0].toUpperCase() + | |
130 permissionNameWithoutDash.slice(1) + 'Description'); | |
131 permissionOption.appendChild(permissionNameSpan); | |
132 | |
133 var permissionSelector = cr.doc.createElement('select'); | |
134 permissionSelector.setAttribute('id', permissionName + '-select-option'); | |
135 permissionSelector.className = 'weaktrl permission-selection-option'; | |
136 permissionOption.appendChild(permissionSelector); | |
137 return permissionOption; | |
138 }, | |
106 }; | 139 }; |
107 | 140 |
108 WebsiteSettingsEditor.populateOrigin = function(localStorage, batteryUsage, | 141 WebsiteSettingsEditor.populateOrigin = function(localStorage, batteryUsage, |
109 permissions, showPage) { | 142 permissions, showPage) { |
110 WebsiteSettingsEditor.getInstance().populateOrigin_(localStorage, | 143 WebsiteSettingsEditor.getInstance().populateOrigin_(localStorage, |
111 batteryUsage, | 144 batteryUsage, |
112 permissions, | 145 permissions, |
113 showPage); | 146 showPage); |
114 }; | 147 }; |
115 | 148 |
116 // Export | 149 // Export |
117 return { | 150 return { |
118 WebsiteSettingsEditor: WebsiteSettingsEditor | 151 WebsiteSettingsEditor: WebsiteSettingsEditor |
119 }; | 152 }; |
120 | 153 |
121 }); | 154 }); |
OLD | NEW |