Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 'use strict'; | |
| 6 | |
| 7 // This object provides a similar API to chrome.networkingPrivate. It simulates | |
| 8 // the extension callback model by storing callbacks in a member object and | |
| 9 // invoking them when the corresponding method is called by Chrome in response | |
| 10 // to a chrome.send call. | |
| 11 | |
| 12 var networkConfig = { | |
| 13 // ONC types | |
| 14 Type: { | |
| 15 All: 'All', | |
| 16 Cellular: 'Cellular', | |
| 17 Ethernet: 'Ethernet', | |
| 18 VPN: 'VPN', | |
| 19 WiFi: 'WiFi' | |
| 20 }, | |
| 21 | |
| 22 // ONC Service properties | |
| 23 Service: { | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
The term 'Service' doesn't appear in ONC (so far).
stevenjb
2014/05/02 22:07:38
Or 'ONC'?
pneubeck (no reviews)
2014/05/08 09:21:43
Fine with me, but then there should at least be a
| |
| 24 Address: 'Address', | |
| 25 Cellular: { | |
| 26 NetworkTechnology: 'Cellular.NetworkTechnology', | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
optional:
since an access by path of a property d
stevenjb
2014/05/02 22:07:38
I think the implementation of that would be more c
| |
| 27 ActivationState: 'Cellular.ActivationState', | |
| 28 RoamingState: 'Cellular.RoamingState', | |
| 29 OutOfCredits: 'Cellular.OutOfCredits' | |
| 30 }, | |
| 31 Connectable: 'Connectable', | |
| 32 ConnectionState: 'ConnectionState', | |
| 33 EAP: { | |
| 34 EAP: 'EAP.EAP' | |
| 35 }, | |
| 36 ErrorState: 'ErrorState', | |
| 37 GUID: 'GUID', | |
| 38 Name: 'Name', | |
| 39 OncSource: 'onc_source', | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
add a comment: 'temporary'
in the future we shoul
stevenjb
2014/05/02 22:07:38
Done.
| |
| 40 Profile: 'Profile', | |
| 41 WiFi: { | |
| 42 Security: 'WiFi.Security', | |
| 43 SignalStrength: 'WiFi.SignalStrength' | |
| 44 }, | |
| 45 ServicePath: 'ServicePath', | |
| 46 Type: 'Type' | |
| 47 }, | |
| 48 | |
| 49 /** | |
| 50 * Associate the callback with |id| | |
| 51 * | |
| 52 * @param {function} callback The associated callback | |
| 53 * @return {integer} The id of the callback | |
| 54 */ | |
| 55 callbackId: 1, | |
| 56 callbackMap: {}, | |
| 57 rememberCallback: function(callback) { | |
| 58 var id = networkConfig.callbackId++; | |
| 59 networkConfig.callbackMap[id] = callback; | |
| 60 return id; | |
| 61 }, | |
| 62 | |
| 63 /** | |
| 64 * Return the callback associated with |id| | |
| 65 * | |
| 66 * @param {integer} id The id of the callback | |
| 67 * @return {function} The associated callback | |
| 68 */ | |
| 69 getCallback: function(id) { | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
get -> pop/take/remove
stevenjb
2014/05/02 22:07:38
remember/get -> store/retrieve
| |
| 70 var callback = networkConfig.callbackMap[id]; | |
| 71 delete networkConfig.callbackMap[id]; | |
| 72 return callback; | |
| 73 }, | |
| 74 | |
| 75 /** | |
| 76 * Callback invoked by Chrome | |
| 77 * | |
| 78 * @param {string} data A list of arguments passed to the callback | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
optional: mention, first entry of list is callback
stevenjb
2014/05/02 22:07:38
Done.
| |
| 79 */ | |
| 80 chromeCallback: function(data) { | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
unify the naming of chromeCallback vs. chromeError
stevenjb
2014/05/02 22:07:38
chromeCallbackSuccess / chromeCallbackError
| |
| 81 var callbackId = data.shift(); | |
| 82 var callback = networkConfig.getCallback(callbackId); | |
| 83 if (callback) | |
| 84 callback(data); | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
callback.apply(null, data)
stevenjb
2014/05/02 22:07:38
Interesting. I'll need to change the callbacks to
| |
| 85 else | |
| 86 console.log('Callback not found for id: ' + callbackId); | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
log -> error
stevenjb
2014/05/02 22:07:38
Done.
| |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * Error Callback invoked by Chrome | |
| 91 * | |
| 92 * @param {string} data A list of arguments passed to the callback | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
optional: mention, first entry of list is callback
stevenjb
2014/05/02 22:07:38
Done.
| |
| 93 */ | |
| 94 chromeError: function(data) { | |
| 95 var callbackId = data.shift(); | |
| 96 var error = data.shift(); | |
| 97 // Get the callback so that it is deleted from the map. | |
| 98 networkConfig.getCallback(callbackId); | |
| 99 console.log('Callback error: '' + error + '' for id: ' + callbackId); | |
|
pneubeck (no reviews)
2014/05/02 09:43:46
log -> error
In case of an error, ext. APIs usual
stevenjb
2014/05/02 22:07:38
Hmm, I'd assumed that was an 'Extensions' mechanis
pneubeck (no reviews)
2014/05/08 09:21:43
The global is only for reporting an error to the c
| |
| 100 }, | |
| 101 | |
| 102 /** | |
| 103 * Implement networkingPrivate.getProperties | |
| 104 * | |
| 105 * @param {string} type The type of networks to return | |
| 106 */ | |
| 107 getProperties: function(guid, callback) { | |
| 108 var callbackId = networkConfig.rememberCallback(callback); | |
| 109 chrome.send('networkConfig.getProperties', [callbackId, guid]); | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * Implement networkingPrivate.getVisibleNetworks | |
| 114 * | |
| 115 * @param {string} type The type of networks to return | |
| 116 */ | |
| 117 getVisibleNetworks: function(type, callback) { | |
| 118 var callbackId = networkConfig.rememberCallback(callback); | |
| 119 chrome.send('networkConfig.getVisibleNetworks', [callbackId, type]); | |
| 120 } | |
| 121 | |
| 122 }; | |
| OLD | NEW |