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.
5 cr
.define('options.WebsiteSettings', function() {
6 /** @const */ var Page
= cr
.ui
.pageManager
.Page
;
8 /////////////////////////////////////////////////////////////////////////////
9 // WebsiteSettingsEditor class:
12 * Encapsulated handling of the website settings editor page.
14 * @extends {cr.ui.pageManager.Page}
16 function WebsiteSettingsEditor() {
17 Page
.call(this, 'websiteEdit',
18 loadTimeData
.getString('websitesOptionsPageTabTitle'),
19 'website-settings-edit-page');
20 this.permissions
= ['geolocation', 'notifications', 'media-stream',
21 'cookies', 'multiple-automatic-downloads', 'images',
22 'plugins', 'popups', 'javascript'];
23 this.permissionsLookup
= {
24 'geolocation': 'Location',
25 'notifications': 'Notifications',
26 'media-stream': 'MediaStream',
28 'multiple-automatic-downloads': 'Downloads',
32 'javascript': 'Javascript'
36 cr
.addSingletonGetter(WebsiteSettingsEditor
);
38 WebsiteSettingsEditor
.prototype = {
39 __proto__
: Page
.prototype,
43 initializePage: function() {
44 Page
.prototype.initializePage
.call(this);
46 $('website-settings-storage-delete-button').onclick = function(event
) {
47 chrome
.send('deleteLocalStorage');
50 $('website-settings-battery-stop-button').onclick = function(event
) {
51 chrome
.send('stopOrigin');
54 $('websiteSettingsEditorCancelButton').onclick
=
55 PageManager
.closeOverlay
.bind(PageManager
);
57 $('websiteSettingsEditorDoneButton').onclick = function(event
) {
58 WebsiteSettingsEditor
.getInstance().updatePermissions();
59 PageManager
.closeOverlay
.bind(PageManager
)();
63 this.pageDiv
.querySelector('.origin-permission-list');
64 for (var key
in this.permissions
) {
65 permissionList
.appendChild(
66 this.makePermissionOption_(this.permissions
[key
]));
71 * Populates the page with the proper information for a given URL.
72 * @param {string} url The URL of the page.
75 populatePage: function(url
) {
78 var titleEl
= $('website-title');
79 titleEl
.textContent
= url
;
80 titleEl
.style
.backgroundImage
= getFaviconImageSet(url
);
82 chrome
.send('getOriginInfo', [url
]);
86 * Populates and displays the page with given origin information.
87 * @param {string} localStorage A string describing the local storage use.
88 * @param {string} batteryUsage A string describing the battery use.
89 * @param {Object} permissions A dictionary of permissions to their
90 * available and current settings, and if it is editable.
91 * @param {boolean} showPage If the page should raised.
94 populateOrigin_: function(localStorage
, batteryUsage
, permissions
,
96 $('local-storage-title').textContent
= localStorage
;
97 $('battery-title').textContent
= batteryUsage
;
98 for (var key
in permissions
) {
99 var selector
= $(key
+ '-select-option');
101 var options
= permissions
[key
].options
;
102 selector
.options
.length
= 0;
103 for (var option
in options
) {
104 selector
.options
[selector
.options
.length
] =
105 new Option(loadTimeData
.getString(options
[option
] + 'Exception'),
109 selector
.value
= permissions
[key
].setting
;
110 selector
.originalValue
= permissions
[key
].setting
;
111 selector
.disabled
= !permissions
[key
].editable
;
114 PageManager
.showPageByName('websiteEdit', false);
117 updatePermissions: function() {
118 for (var key
in this.permissions
) {
119 var selection
= $(this.permissions
[key
] + '-select-option');
120 if (selection
.value
!= selection
.originalValue
) {
121 chrome
.send('setOriginPermission',
122 [this.permissions
[key
], selection
.value
]);
128 * Populates the origin permission list with the different usable
130 * @param {string} permissionName A string with the permission name.
131 * @return {Element} The element with the usable permission setting.
133 makePermissionOption_: function(permissionName
) {
134 var permissionOption
= cr
.doc
.createElement('div');
135 permissionOption
.className
= 'permission-option';
137 var permissionNameSpan
= cr
.doc
.createElement('span');
138 permissionNameSpan
.className
= 'permission-name';
139 permissionNameSpan
.textContent
= loadTimeData
.getString('websites' +
140 this.permissionsLookup
[permissionName
] + 'Description');
141 permissionOption
.appendChild(permissionNameSpan
);
143 var permissionSelector
= cr
.doc
.createElement('select');
144 permissionSelector
.setAttribute('id', permissionName
+ '-select-option');
145 permissionSelector
.className
= 'weaktrl permission-selection-option';
146 permissionOption
.appendChild(permissionSelector
);
147 return permissionOption
;
151 WebsiteSettingsEditor
.populateOrigin = function(localStorage
, batteryUsage
,
152 permissions
, showPage
) {
153 WebsiteSettingsEditor
.getInstance().populateOrigin_(localStorage
,
159 WebsiteSettingsEditor
.showEditPage = function(url
) {
160 WebsiteSettingsEditor
.getInstance().populatePage(url
);
165 WebsiteSettingsEditor
: WebsiteSettingsEditor