Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: extensions/renderer/resources/send_request.js

Issue 855813002: Mark create/update/clear callbacks of notification API as optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 &&
77 !lastError.hasAccessed(chrome) && 77 !lastError.hasAccessed(chrome) &&
78 !lastError.hasAccessed(callerChrome)) { 78 !lastError.hasAccessed(callerChrome)) {
79 // The native call caused an error, but the developer didn't check 79 // The native call caused an error, but the developer didn't check
80 // runtime.lastError. 80 // runtime.lastError.
81 // Notify the developer of the error via the (error) console. 81 lastError.reportUncheckedLastError(name, error, request.stack);
82 console.error("Unchecked runtime.lastError while running " +
83 (name || "unknown") + ": " + error +
84 (request.stack ? "\n" + request.stack : ""));
85 } 82 }
86 } finally { 83 } finally {
87 delete requests[requestId]; 84 delete requests[requestId];
88 lastError.clear(chrome); 85 lastError.clear(chrome);
89 if (callerChrome !== chrome) 86 if (callerChrome !== chrome)
90 lastError.clear(callerChrome); 87 lastError.clear(callerChrome);
91 } 88 }
92 } 89 }
93 90
94 function prepareRequest(args, argSchemas) { 91 function prepareRequest(args, argSchemas) {
(...skipping 18 matching lines...) Expand all
113 110
114 // Send an API request and optionally register a callback. 111 // Send an API request and optionally register a callback.
115 // |optArgs| is an object with optional parameters as follows: 112 // |optArgs| is an object with optional parameters as follows:
116 // - customCallback: a callback that should be called instead of the standard 113 // - customCallback: a callback that should be called instead of the standard
117 // callback. 114 // callback.
118 // - nativeFunction: the v8 native function to handle the request, or 115 // - nativeFunction: the v8 native function to handle the request, or
119 // StartRequest if missing. 116 // StartRequest if missing.
120 // - forIOThread: true if this function should be handled on the browser IO 117 // - forIOThread: true if this function should be handled on the browser IO
121 // thread. 118 // thread.
122 // - preserveNullInObjects: true if it is safe for null to be in objects. 119 // - preserveNullInObjects: true if it is safe for null to be in objects.
120 // - stack: An optional string that contains the stack trace, to be displayed
121 // to the user if an error occurs.
123 function sendRequest(functionName, args, argSchemas, optArgs) { 122 function sendRequest(functionName, args, argSchemas, optArgs) {
124 calledSendRequest = true; 123 calledSendRequest = true;
125 if (!optArgs) 124 if (!optArgs)
126 optArgs = {}; 125 optArgs = {};
127 var request = prepareRequest(args, argSchemas); 126 var request = prepareRequest(args, argSchemas);
128 request.stack = exceptionHandler.getExtensionStackTrace(); 127 request.stack = optArgs.stack || exceptionHandler.getExtensionStackTrace();
129 if (optArgs.customCallback) { 128 if (optArgs.customCallback) {
130 request.customCallback = optArgs.customCallback; 129 request.customCallback = optArgs.customCallback;
131 } 130 }
132 131
133 var nativeFunction = optArgs.nativeFunction || natives.StartRequest; 132 var nativeFunction = optArgs.nativeFunction || natives.StartRequest;
134 133
135 var requestId = natives.GetNextRequestId(); 134 var requestId = natives.GetNextRequestId();
136 request.id = requestId; 135 request.id = requestId;
137 requests[requestId] = request; 136 requests[requestId] = request;
138 137
(...skipping 14 matching lines...) Expand all
153 calledSendRequest = false; 152 calledSendRequest = false;
154 } 153 }
155 154
156 exports.sendRequest = sendRequest; 155 exports.sendRequest = sendRequest;
157 exports.getCalledSendRequest = getCalledSendRequest; 156 exports.getCalledSendRequest = getCalledSendRequest;
158 exports.clearCalledSendRequest = clearCalledSendRequest; 157 exports.clearCalledSendRequest = clearCalledSendRequest;
159 exports.safeCallbackApply = safeCallbackApply; 158 exports.safeCallbackApply = safeCallbackApply;
160 159
161 // Called by C++. 160 // Called by C++.
162 exports.handleResponse = handleResponse; 161 exports.handleResponse = handleResponse;
OLDNEW
« extensions/renderer/resources/last_error.js ('K') | « extensions/renderer/resources/last_error.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698