OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 exceptionHandler = require('uncaught_exception_handler'); | 5 var exceptionHandler = require('uncaught_exception_handler'); |
6 var lastError = require('lastError'); | 6 var lastError = require('lastError'); |
7 var logging = requireNative('logging'); | 7 var logging = requireNative('logging'); |
8 var natives = requireNative('sendRequest'); | 8 var natives = requireNative('sendRequest'); |
9 var validate = require('schemaUtils').validate; | 9 var validate = require('schemaUtils').validate; |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 // calls may not return data if they observe the caller | 66 // calls may not return data if they observe the caller |
67 // has not provided a callback. | 67 // has not provided a callback. |
68 if (logging.DCHECK_IS_ON() && !error) { | 68 if (logging.DCHECK_IS_ON() && !error) { |
69 if (!request.callbackSchema.parameters) | 69 if (!request.callbackSchema.parameters) |
70 throw new Error(name + ": no callback schema defined"); | 70 throw new Error(name + ": no callback schema defined"); |
71 validate(responseList, request.callbackSchema.parameters); | 71 validate(responseList, request.callbackSchema.parameters); |
72 } | 72 } |
73 safeCallbackApply(name, request, request.callback, responseList); | 73 safeCallbackApply(name, request, request.callback, responseList); |
74 } | 74 } |
75 | 75 |
76 if (error && | 76 if (error && !lastError.hasAccessed(chrome)) { |
not at google - send to devlin
2015/01/22 18:01:33
The second part of this condition is unnecessary g
robwu
2015/01/22 18:07:22
Look at the original code, there is a check for |c
not at google - send to devlin
2015/01/22 18:12:53
Ok, add a comment.
robwu
2015/01/22 18:19:33
The purpose of |chrome| and |callerChrome| is alre
| |
77 !lastError.hasAccessed(chrome) && | 77 // The native call caused an error, but the developer might not have |
78 !lastError.hasAccessed(callerChrome)) { | 78 // checked runtime.lastError. |
79 // The native call caused an error, but the developer didn't check | 79 lastError.reportIfUnchecked(name, targetChrome, request.stack); |
80 // runtime.lastError. | |
81 // Notify the developer of the error via the (error) console. | |
82 console.error("Unchecked runtime.lastError while running " + | |
83 (name || "unknown") + ": " + error + | |
84 (request.stack ? "\n" + request.stack : "")); | |
85 } | 80 } |
86 } finally { | 81 } finally { |
87 delete requests[requestId]; | 82 delete requests[requestId]; |
88 lastError.clear(chrome); | 83 lastError.clear(chrome); |
89 if (callerChrome !== chrome) | 84 if (callerChrome !== chrome) |
90 lastError.clear(callerChrome); | 85 lastError.clear(callerChrome); |
91 } | 86 } |
92 } | 87 } |
93 | 88 |
94 function prepareRequest(args, argSchemas) { | 89 function prepareRequest(args, argSchemas) { |
(...skipping 18 matching lines...) Expand all Loading... | |
113 | 108 |
114 // Send an API request and optionally register a callback. | 109 // Send an API request and optionally register a callback. |
115 // |optArgs| is an object with optional parameters as follows: | 110 // |optArgs| is an object with optional parameters as follows: |
116 // - customCallback: a callback that should be called instead of the standard | 111 // - customCallback: a callback that should be called instead of the standard |
117 // callback. | 112 // callback. |
118 // - nativeFunction: the v8 native function to handle the request, or | 113 // - nativeFunction: the v8 native function to handle the request, or |
119 // StartRequest if missing. | 114 // StartRequest if missing. |
120 // - forIOThread: true if this function should be handled on the browser IO | 115 // - forIOThread: true if this function should be handled on the browser IO |
121 // thread. | 116 // thread. |
122 // - preserveNullInObjects: true if it is safe for null to be in objects. | 117 // - preserveNullInObjects: true if it is safe for null to be in objects. |
118 // - stack: An optional string that contains the stack trace, to be displayed | |
119 // to the user if an error occurs. | |
123 function sendRequest(functionName, args, argSchemas, optArgs) { | 120 function sendRequest(functionName, args, argSchemas, optArgs) { |
124 calledSendRequest = true; | 121 calledSendRequest = true; |
125 if (!optArgs) | 122 if (!optArgs) |
126 optArgs = {}; | 123 optArgs = {}; |
127 var request = prepareRequest(args, argSchemas); | 124 var request = prepareRequest(args, argSchemas); |
128 request.stack = exceptionHandler.getExtensionStackTrace(); | 125 request.stack = optArgs.stack || exceptionHandler.getExtensionStackTrace(); |
129 if (optArgs.customCallback) { | 126 if (optArgs.customCallback) { |
130 request.customCallback = optArgs.customCallback; | 127 request.customCallback = optArgs.customCallback; |
131 } | 128 } |
132 | 129 |
133 var nativeFunction = optArgs.nativeFunction || natives.StartRequest; | 130 var nativeFunction = optArgs.nativeFunction || natives.StartRequest; |
134 | 131 |
135 var requestId = natives.GetNextRequestId(); | 132 var requestId = natives.GetNextRequestId(); |
136 request.id = requestId; | 133 request.id = requestId; |
137 requests[requestId] = request; | 134 requests[requestId] = request; |
138 | 135 |
(...skipping 14 matching lines...) Expand all Loading... | |
153 calledSendRequest = false; | 150 calledSendRequest = false; |
154 } | 151 } |
155 | 152 |
156 exports.sendRequest = sendRequest; | 153 exports.sendRequest = sendRequest; |
157 exports.getCalledSendRequest = getCalledSendRequest; | 154 exports.getCalledSendRequest = getCalledSendRequest; |
158 exports.clearCalledSendRequest = clearCalledSendRequest; | 155 exports.clearCalledSendRequest = clearCalledSendRequest; |
159 exports.safeCallbackApply = safeCallbackApply; | 156 exports.safeCallbackApply = safeCallbackApply; |
160 | 157 |
161 // Called by C++. | 158 // Called by C++. |
162 exports.handleResponse = handleResponse; | 159 exports.handleResponse = handleResponse; |
OLD | NEW |