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 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 5 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
6 var lastError = require('lastError'); | 6 var lastError = require('lastError'); |
7 var natives = requireNative('sendRequest'); | 7 var natives = requireNative('sendRequest'); |
8 var validate = require('schemaUtils').validate; | 8 var validate = require('schemaUtils').validate; |
9 | 9 |
10 // Callback handling. | 10 // Callback handling. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 // TODO(asargent) - convert all optional native functions to accept raw | 108 // TODO(asargent) - convert all optional native functions to accept raw |
109 // v8 values instead of expecting JSON strings. | 109 // v8 values instead of expecting JSON strings. |
110 var doStringify = false; | 110 var doStringify = false; |
111 if (opt_args.nativeFunction && !opt_args.noStringify) | 111 if (opt_args.nativeFunction && !opt_args.noStringify) |
112 doStringify = true; | 112 doStringify = true; |
113 var requestArgs = doStringify ? | 113 var requestArgs = doStringify ? |
114 chromeHidden.JSON.stringify(request.args) : request.args; | 114 chromeHidden.JSON.stringify(request.args) : request.args; |
115 var nativeFunction = opt_args.nativeFunction || natives.StartRequest; | 115 var nativeFunction = opt_args.nativeFunction || natives.StartRequest; |
116 | 116 |
117 var requestId = natives.GetNextRequestId(); | 117 var hasCallback = !!(request.callback || opt_args.customCallback); |
118 request.id = requestId; | 118 var requestId = nativeFunction(functionName, |
119 requests[requestId] = request; | 119 requestArgs, |
120 var hasCallback = | 120 hasCallback, |
121 (request.callback || opt_args.customCallback) ? true : false; | 121 opt_args.forIOThread); |
122 return nativeFunction(functionName, requestArgs, requestId, hasCallback, | 122 if (typeof(requestId) == 'number' && requestId >= 0) { |
123 opt_args.forIOThread); | 123 request.id = requestId; |
| 124 requests[requestId] = request; |
| 125 } |
124 } | 126 } |
125 | 127 |
126 exports.sendRequest = sendRequest; | 128 exports.sendRequest = sendRequest; |
OLD | NEW |