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 DCHECK = requireNative('logging').DCHECK; | 6 var DCHECK = requireNative('logging').DCHECK; |
7 var forEach = require('utils').forEach; | 7 var forEach = require('utils').forEach; |
8 var json = require('json'); | 8 var json = require('json'); |
9 var lastError = require('lastError'); | 9 var lastError = require('lastError'); |
10 var natives = requireNative('sendRequest'); | 10 var natives = requireNative('sendRequest'); |
11 var validate = require('schemaUtils').validate; | 11 var validate = require('schemaUtils').validate; |
12 | 12 |
13 // All outstanding requests from sendRequest(). | 13 // All outstanding requests from sendRequest(). |
14 var requests = {}; | 14 var requests = {}; |
15 | 15 |
16 // Used to prevent double Activity Logging for API calls that use both custom | |
17 // bindings and ExtensionFunctions (via sendRequest). | |
18 var requestStatus = false; | |
Matt Perry
2013/03/15 23:33:21
nit: I wouldn't guess what this for based on the n
felt
2013/03/15 23:40:17
Done.
| |
19 | |
16 // Callback handling. | 20 // Callback handling. |
17 chromeHidden.handleResponse = function(requestId, name, | 21 chromeHidden.handleResponse = function(requestId, name, |
18 success, responseList, error) { | 22 success, responseList, error) { |
19 // The chrome objects we will set lastError on. Really we should only be | 23 // The chrome objects we will set lastError on. Really we should only be |
20 // setting this on the callback's chrome object, but set on ours too since | 24 // setting this on the callback's chrome object, but set on ours too since |
21 // it's conceivable that something relies on that. | 25 // it's conceivable that something relies on that. |
22 var chromesForLastError = [chrome]; | 26 var chromesForLastError = [chrome]; |
23 | 27 |
24 try { | 28 try { |
25 var request = requests[requestId]; | 29 var request = requests[requestId]; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 // |optArgs| is an object with optional parameters as follows: | 100 // |optArgs| is an object with optional parameters as follows: |
97 // - noStringify: true if we should not stringify the request arguments. | 101 // - noStringify: true if we should not stringify the request arguments. |
98 // - customCallback: a callback that should be called instead of the standard | 102 // - customCallback: a callback that should be called instead of the standard |
99 // callback. | 103 // callback. |
100 // - nativeFunction: the v8 native function to handle the request, or | 104 // - nativeFunction: the v8 native function to handle the request, or |
101 // StartRequest if missing. | 105 // StartRequest if missing. |
102 // - forIOThread: true if this function should be handled on the browser IO | 106 // - forIOThread: true if this function should be handled on the browser IO |
103 // thread. | 107 // thread. |
104 // - preserveNullInObjects: true if it is safe for null to be in objects. | 108 // - preserveNullInObjects: true if it is safe for null to be in objects. |
105 function sendRequest(functionName, args, argSchemas, optArgs) { | 109 function sendRequest(functionName, args, argSchemas, optArgs) { |
110 requestStatus = true; | |
106 if (!optArgs) | 111 if (!optArgs) |
107 optArgs = {}; | 112 optArgs = {}; |
108 var request = prepareRequest(args, argSchemas); | 113 var request = prepareRequest(args, argSchemas); |
109 if (optArgs.customCallback) { | 114 if (optArgs.customCallback) { |
110 request.customCallback = optArgs.customCallback; | 115 request.customCallback = optArgs.customCallback; |
111 } | 116 } |
112 // json.stringify doesn't support a root object which is undefined. | 117 // json.stringify doesn't support a root object which is undefined. |
113 if (request.args === undefined) | 118 if (request.args === undefined) |
114 request.args = null; | 119 request.args = null; |
115 | 120 |
(...skipping 11 matching lines...) Expand all Loading... | |
127 | 132 |
128 var hasCallback = request.callback || optArgs.customCallback; | 133 var hasCallback = request.callback || optArgs.customCallback; |
129 return nativeFunction(functionName, | 134 return nativeFunction(functionName, |
130 requestArgs, | 135 requestArgs, |
131 requestId, | 136 requestId, |
132 hasCallback, | 137 hasCallback, |
133 optArgs.forIOThread, | 138 optArgs.forIOThread, |
134 optArgs.preserveNullInObjects); | 139 optArgs.preserveNullInObjects); |
135 } | 140 } |
136 | 141 |
142 function getRequestStatus() { | |
143 return requestStatus; | |
144 } | |
145 | |
146 function setRequestStatus(status) { | |
147 requestStatus = status; | |
148 } | |
149 | |
137 exports.sendRequest = sendRequest; | 150 exports.sendRequest = sendRequest; |
151 exports.requestStatus = requestStatus; | |
152 exports.getRequestStatus = getRequestStatus; | |
153 exports.setRequestStatus = setRequestStatus; | |
Matt Perry
2013/03/15 23:33:21
nit: better to expose a clearRequestStatus that al
felt
2013/03/15 23:40:17
Done.
| |
OLD | NEW |