1 // Copyright (c) 2013 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('network.config', function() {
6 var NetworkConfig
= cr
.ui
.define('div');
8 NetworkConfig
.prototype = {
9 __proto__
: HTMLDivElement
.prototype,
10 decorate: function() {
11 var params
= parseQueryParams(window
.location
);
12 this.networkId_
= params
.network
;
13 this.activeArea_
= null;
14 this.userArea_
= null;
15 this.managedArea_
= null;
16 this.stateArea_
= null;
18 this.fetchProperties_();
21 fetchProperties_: function() {
22 chrome
.networkingPrivate
.getProperties(
24 this.updateActiveSettings_
.bind(this));
25 chrome
.networkingPrivate
.getManagedProperties(
27 this.updateManagedSettings_
.bind(this));
28 chrome
.networkingPrivate
.getState(
30 this.updateState_
.bind(this));
33 stringifyJSON_: function(properties
) {
34 return JSON
.stringify(properties
, undefined, 2);
37 updateActiveSettings_: function(properties
) {
38 this.activeArea_
.value
= this.stringifyJSON_(properties
);
41 updateManagedSettings_: function(properties
) {
42 var error
= chrome
.runtime
.lastError
;
44 this.managedArea_
.value
= error
.message
;
45 this.userArea_
.value
= 'undefined';
47 this.managedArea_
.value
= this.stringifyJSON_(properties
);
48 this.userArea_
.value
= this.stringifyJSON_(
49 this.extractUserSettings_(properties
));
53 updateState_: function(properties
) {
54 this.stateArea_
.value
= this.stringifyJSON_(properties
);
57 extractUserSettings_: function(properties
) {
58 if ('UserSetting' in properties
)
59 return properties
['UserSetting'];
61 if ('SharedSetting' in properties
)
62 return properties
['SharedSetting'];
65 for (var fieldName
in properties
) {
66 var entry
= properties
[fieldName
];
67 if (typeof entry
=== 'object') {
68 var nestedResult
= this.extractUserSettings_(entry
);
70 result
[fieldName
] = nestedResult
;
73 if (Object
.keys(result
).length
)
79 updateDom_: function() {
80 var div
= document
.createElement('div');
82 this.activeArea_ = function() {
83 var label
= document
.createElement('h4');
84 label
.textContent
= 'Active Settings (getProperties)';
85 div
.appendChild(label
);
86 var area
= document
.createElement('textarea');
87 div
.appendChild(area
);
91 this.userArea_ = function() {
92 var label
= document
.createElement('h4');
93 label
.textContent
= 'User Settings';
94 div
.appendChild(label
);
95 var area
= document
.createElement('textarea');
96 div
.appendChild(area
);
100 this.managedArea_ = function() {
101 var label
= document
.createElement('h4');
102 label
.textContent
= 'Managed Settings (getManagedProperties)';
103 div
.appendChild(label
);
104 var area
= document
.createElement('textarea');
105 div
.appendChild(area
);
109 this.stateArea_ = function() {
110 var label
= document
.createElement('h4');
111 label
.textContent
= 'State (getState)';
112 div
.appendChild(label
);
113 var area
= document
.createElement('textarea');
114 div
.appendChild(area
);
118 this.appendChild(div
);
122 return JSON
.parse(this.userArea_
.value
);
126 return this.networkId_
;
131 NetworkConfig
: NetworkConfig