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']; |
| 22 this.permissionsLookup = { |
| 23 'geolocation': 'Location', |
| 24 'notifications': 'Notifications', |
| 25 'media-stream': 'MediaStream', |
| 26 'cookies': 'Cookies', |
| 27 'multiple-automatic-downloads': 'Downloads', |
| 28 'images': 'Images', |
| 29 'plugins': 'Plugins', |
| 30 'popups': 'Popups', |
| 31 'javascript': 'Javascript' |
| 32 }; |
21 } | 33 } |
22 | 34 |
23 cr.addSingletonGetter(WebsiteSettingsEditor); | 35 cr.addSingletonGetter(WebsiteSettingsEditor); |
24 | 36 |
25 WebsiteSettingsEditor.prototype = { | 37 WebsiteSettingsEditor.prototype = { |
26 __proto__: Page.prototype, | 38 __proto__: Page.prototype, |
27 | 39 |
28 | 40 |
29 /** @override */ | 41 /** @override */ |
30 initializePage: function() { | 42 initializePage: function() { |
31 Page.prototype.initializePage.call(this); | 43 Page.prototype.initializePage.call(this); |
32 | 44 |
33 $('website-settings-storage-delete-button').onclick = function(event) { | 45 $('website-settings-storage-delete-button').onclick = function(event) { |
34 chrome.send('deleteLocalStorage'); | 46 chrome.send('deleteLocalStorage'); |
35 }; | 47 }; |
36 | 48 |
37 $('website-settings-battery-stop-button').onclick = function(event) { | 49 $('website-settings-battery-stop-button').onclick = function(event) { |
38 chrome.send('stopOrigin'); | 50 chrome.send('stopOrigin'); |
39 }; | 51 }; |
40 | 52 |
41 $('websiteSettingsEditorCancelButton').onclick = | 53 $('websiteSettingsEditorCancelButton').onclick = |
42 PageManager.closeOverlay.bind(PageManager); | 54 PageManager.closeOverlay.bind(PageManager); |
43 | 55 |
44 $('websiteSettingsEditorDoneButton').onclick = function(event) { | 56 $('websiteSettingsEditorDoneButton').onclick = function(event) { |
45 WebsiteSettingsEditor.getInstance().updatePermissions(); | 57 WebsiteSettingsEditor.getInstance().updatePermissions(); |
46 PageManager.closeOverlay.bind(PageManager)(); | 58 PageManager.closeOverlay.bind(PageManager)(); |
47 }; | 59 }; |
| 60 |
| 61 var permissionList = |
| 62 this.pageDiv.querySelector('.origin-permission-list'); |
| 63 for (var key in this.permissions) { |
| 64 permissionList.appendChild( |
| 65 this.makePermissionOption_(this.permissions[key])); |
| 66 } |
48 }, | 67 }, |
49 | 68 |
50 /** | 69 /** |
51 * Populates the page with the proper information for a given URL. | 70 * Populates the page with the proper information for a given URL. |
52 * @param {string} url The URL of the page. | 71 * @param {string} url The URL of the page. |
53 * @private | 72 * @private |
54 */ | 73 */ |
55 populatePage: function(url) { | 74 populatePage: function(url) { |
56 this.url = url; | 75 this.url = url; |
57 | 76 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 115 |
97 updatePermissions: function() { | 116 updatePermissions: function() { |
98 for (var key in this.permissions) { | 117 for (var key in this.permissions) { |
99 var selection = $(this.permissions[key] + '-select-option'); | 118 var selection = $(this.permissions[key] + '-select-option'); |
100 if (selection.value != selection.originalValue) { | 119 if (selection.value != selection.originalValue) { |
101 chrome.send('setOriginPermission', | 120 chrome.send('setOriginPermission', |
102 [this.permissions[key], selection.value]); | 121 [this.permissions[key], selection.value]); |
103 } | 122 } |
104 } | 123 } |
105 }, | 124 }, |
| 125 |
| 126 /** |
| 127 * Populates the origin permission list with the different usable |
| 128 * permissions. |
| 129 * @param {string} permissionName A string with the permission name. |
| 130 * @return {Element} The element with the usable permission setting. |
| 131 */ |
| 132 makePermissionOption_: function(permissionName) { |
| 133 var permissionOption = cr.doc.createElement('div'); |
| 134 permissionOption.className = 'permission-option'; |
| 135 |
| 136 var permissionNameSpan = cr.doc.createElement('span'); |
| 137 permissionNameSpan.className = 'permission-name'; |
| 138 permissionNameSpan.textContent = loadTimeData.getString('websites' + |
| 139 this.permissionsLookup[permissionName] + 'Description'); |
| 140 permissionOption.appendChild(permissionNameSpan); |
| 141 |
| 142 var permissionSelector = cr.doc.createElement('select'); |
| 143 permissionSelector.setAttribute('id', permissionName + '-select-option'); |
| 144 permissionSelector.className = 'weaktrl permission-selection-option'; |
| 145 permissionOption.appendChild(permissionSelector); |
| 146 return permissionOption; |
| 147 }, |
106 }; | 148 }; |
107 | 149 |
108 WebsiteSettingsEditor.populateOrigin = function(localStorage, batteryUsage, | 150 WebsiteSettingsEditor.populateOrigin = function(localStorage, batteryUsage, |
109 permissions, showPage) { | 151 permissions, showPage) { |
110 WebsiteSettingsEditor.getInstance().populateOrigin_(localStorage, | 152 WebsiteSettingsEditor.getInstance().populateOrigin_(localStorage, |
111 batteryUsage, | 153 batteryUsage, |
112 permissions, | 154 permissions, |
113 showPage); | 155 showPage); |
114 }; | 156 }; |
115 | 157 |
116 // Export | 158 // Export |
117 return { | 159 return { |
118 WebsiteSettingsEditor: WebsiteSettingsEditor | 160 WebsiteSettingsEditor: WebsiteSettingsEditor |
119 }; | 161 }; |
120 | 162 |
121 }); | 163 }); |
OLD | NEW |