| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Custom bindings for the experimental.socket API. | 5 // Custom bindings for the experimental.socket API. |
| 6 | 6 |
| 7 var experimentalSocketNatives = requireNative('experimental_socket'); | 7 (function() { |
| 8 var GetNextSocketEventId = experimentalSocketNatives.GetNextSocketEventId; | 8 native function GetChromeHidden(); |
| 9 native function GetNextSocketEventId(); |
| 9 | 10 |
| 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 11 var chromeHidden = GetChromeHidden(); |
| 11 | 12 |
| 12 chromeHidden.registerCustomHook('experimental.socket', function(api) { | 13 chromeHidden.registerCustomHook('experimental.socket', function(api) { |
| 13 var apiFunctions = api.apiFunctions; | 14 var apiFunctions = api.apiFunctions; |
| 14 var sendRequest = api.sendRequest; | 15 var sendRequest = api.sendRequest; |
| 15 | 16 |
| 16 apiFunctions.setHandleRequest('create', function() { | 17 apiFunctions.setHandleRequest('create', function() { |
| 17 var args = arguments; | 18 var args = arguments; |
| 18 if (args.length > 3 && args[3] && args[3].onEvent) { | 19 if (args.length > 3 && args[3] && args[3].onEvent) { |
| 19 var id = GetNextSocketEventId(); | 20 var id = GetNextSocketEventId(); |
| 20 args[3].srcId = id; | 21 args[3].srcId = id; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 48 default: | 49 default: |
| 49 console.error('Unexpected SocketEvent, type ' + event.type); | 50 console.error('Unexpected SocketEvent, type ' + event.type); |
| 50 break; | 51 break; |
| 51 } | 52 } |
| 52 if (event.isFinalEvent) { | 53 if (event.isFinalEvent) { |
| 53 delete chromeHidden.socket.handlers[event.srcId]; | 54 delete chromeHidden.socket.handlers[event.srcId]; |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 }); | 57 }); |
| 57 }); | 58 }); |
| 59 |
| 60 })(); |
| OLD | NEW |