1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('options', function() {
var OptionsPage = options.OptionsPage;
var Preferences = options.Preferences;
/////////////////////////////////////////////////////////////////////////////
// ProxyOptions class:
/**
* Encapsulated handling of ChromeOS proxy options page.
* @constructor
*/
function ProxyOptions(model) {
OptionsPage.call(this, 'proxy', localStrings.getString('proxyPage'),
'proxyPage');
}
cr.addSingletonGetter(ProxyOptions);
/**
* UI pref change handler.
*/
function handlePrefUpdate(e) {
ProxyOptions.getInstance().updateControls();
}
/**
* Monitor pref change of given element.
*/
function observePrefsUI(el) {
Preferences.getInstance().addEventListener(el.pref, handlePrefUpdate);
}
ProxyOptions.prototype = {
// Inherit ProxyOptions from OptionsPage.
__proto__: OptionsPage.prototype,
/**
* Initializes ProxyOptions page.
*/
initializePage: function() {
// Call base class implementation to starts preference initialization.
OptionsPage.prototype.initializePage.call(this);
// Set up ignored page.
options.proxyexceptions.ProxyExceptions.decorate($('ignoredHostList'));
this.addEventListener('visibleChange', this.handleVisibleChange_);
$('removeHost').addEventListener('click', this.handleRemoveExceptions_);
$('addHost').addEventListener('click', this.handleAddException_);
$('directProxy').addEventListener('click', this.disableManual_);
$('manualProxy').addEventListener('click', this.enableManual_);
$('autoProxy').addEventListener('click', this.disableManual_);
$('proxyAllProtocols').addEventListener('click', this.toggleSingle_);
observePrefsUI($('directProxy'));
observePrefsUI($('manualProxy'));
observePrefsUI($('autoProxy'));
observePrefsUI($('proxyAllProtocols'));
},
proxyListInitalized_: false,
/**
* Update controls state.
* @public
*/
updateControls: function() {
this.toggleSingle_();
if ($('manualProxy').checked) {
this.enableManual_();
} else {
this.disableManual_();
}
if (!this.proxyListInitalized_ && this.visible) {
this.proxyListInitalized_ = true;
$('ignoredHostList').redraw();
}
},
/**
* Handler for OptionsPage's visible property change event.
* @private
* @param {Event} e Property change event.
*/
handleVisibleChange_: function(e) {
this.updateControls();
},
/**
* Handler for when the user clicks on the checkbox to allow a
* single proxy usage.
* @private
* @param {Event} e Click Event.
*/
toggleSingle_: function(e) {
if ($('proxyAllProtocols').checked) {
$('multiProxy').style.display = 'none';
$('singleProxy').style.display = 'block';
} else {
$('multiProxy').style.display = 'block';
$('singleProxy').style.display = 'none';
}
},
/**
* Handler for selecting a radio button that will disable the manual
* controls.
* @private
* @param {Event} e Click event.
*/
disableManual_: function(e) {
$('proxyAllProtocols').disabled = true;
$('proxyHostName').disabled = true;
$('proxyHostPort').disabled = true;
$('proxyHostSingleName').disabled = true;
$('proxyHostSinglePort').disabled = true;
$('secureProxyHostName').disabled = true;
$('secureProxyPort').disabled = true;
$('ftpProxy').disabled = true;
$('ftpProxyPort').disabled = true;
$('socksHost').disabled = true;
$('socksPort').disabled = true;
$('newHost').disabled = true;
$('removeHost').disabled = true;
$('addHost').disabled = true;
$('advancedConfig').style.display = 'none';
$('proxyConfig').disabled = !$('autoProxy').checked;
},
/**
* Handler for selecting a radio button that will enable the manual
* controls.
* @private
* @param {Event} e Click event.
*/
enableManual_: function(e) {
$('proxyAllProtocols').disabled = false;
$('proxyHostName').disabled = false;
$('proxyHostPort').disabled = false;
$('proxyHostSingleName').disabled = false;
$('proxyHostSinglePort').disabled = false;
$('secureProxyHostName').disabled = false;
$('secureProxyPort').disabled = false;
$('ftpProxy').disabled = false;
$('ftpProxyPort').disabled = false;
$('socksHost').disabled = false;
$('socksPort').disabled = false;
$('newHost').disabled = false;
$('removeHost').disabled = false;
$('addHost').disabled = false;
$('advancedConfig').style.display = '-webkit-box';
$('ignoredHostList').redraw();
$('proxyConfig').disabled = true;
},
/**
* Handler for "add" event fired from userNameEdit.
* @private
* @param {Event} e Add event fired from userNameEdit.
*/
handleAddException_: function(e) {
var exception = $('newHost').value;
$('newHost').value = '';
exception = exception.trim();
if (exception)
$('ignoredHostList').addException(exception);
},
/**
* Handler for when the remove button is clicked
* @private
*/
handleRemoveExceptions_: function(e) {
var selectedItems = $('ignoredHostList').selectedItems;
for (var x = 0; x < selectedItems.length; x++) {
$('ignoredHostList').removeException(selectedItems[x]);
}
},
/**
* Sets proxy page title using given network name.
* @param {string} network The network name to use in page title.
* @public
*/
setNetworkName: function(network) {
$('proxy-page-title').textContent =
localStrings.getStringF('proxyPageTitleFormat', network);
}
};
ProxyOptions.setNetworkName = function(network) {
ProxyOptions.getInstance().setNetworkName(network);
};
// Export
return {
ProxyOptions: ProxyOptions
};
});
|