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

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

Issue 12287011: Move the chromeHidden.toJSON paranoia out of event.js and into json.js, a new (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fixup Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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 json = require('json');
6 var lastError = require('lastError'); 7 var lastError = require('lastError');
7 var natives = requireNative('sendRequest'); 8 var natives = requireNative('sendRequest');
8 var validate = require('schemaUtils').validate; 9 var validate = require('schemaUtils').validate;
9 10
10 // Callback handling. 11 // Callback handling.
11 var requests = []; 12 var requests = [];
12 chromeHidden.handleResponse = function(requestId, name, 13 chromeHidden.handleResponse = function(requestId, name,
13 success, responseList, error) { 14 success, responseList, error) {
14 try { 15 try {
15 var request = requests[requestId]; 16 var request = requests[requestId];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // - forIOThread: true if this function should be handled on the browser IO 87 // - forIOThread: true if this function should be handled on the browser IO
87 // thread. 88 // thread.
88 // - preserveNullInObjects: true if it is safe for null to be in objects. 89 // - preserveNullInObjects: true if it is safe for null to be in objects.
89 function sendRequest(functionName, args, argSchemas, optArgs) { 90 function sendRequest(functionName, args, argSchemas, optArgs) {
90 if (!optArgs) 91 if (!optArgs)
91 optArgs = {}; 92 optArgs = {};
92 var request = prepareRequest(args, argSchemas); 93 var request = prepareRequest(args, argSchemas);
93 if (optArgs.customCallback) { 94 if (optArgs.customCallback) {
94 request.customCallback = optArgs.customCallback; 95 request.customCallback = optArgs.customCallback;
95 } 96 }
96 // JSON.stringify doesn't support a root object which is undefined. 97 // json.stringify doesn't support a root object which is undefined.
97 if (request.args === undefined) 98 if (request.args === undefined)
98 request.args = null; 99 request.args = null;
99 100
100 // TODO(asargent) - convert all optional native functions to accept raw 101 // TODO(asargent) - convert all optional native functions to accept raw
101 // v8 values instead of expecting JSON strings. 102 // v8 values instead of expecting JSON strings.
102 var doStringify = false; 103 var doStringify = false;
103 if (optArgs.nativeFunction && !optArgs.noStringify) 104 if (optArgs.nativeFunction && !optArgs.noStringify)
104 doStringify = true; 105 doStringify = true;
105 var requestArgs = doStringify ? 106 var requestArgs = doStringify ? json.stringify(request.args) : request.args;
106 chromeHidden.JSON.stringify(request.args) : request.args;
107 var nativeFunction = optArgs.nativeFunction || natives.StartRequest; 107 var nativeFunction = optArgs.nativeFunction || natives.StartRequest;
108 108
109 var requestId = natives.GetNextRequestId(); 109 var requestId = natives.GetNextRequestId();
110 request.id = requestId; 110 request.id = requestId;
111 requests[requestId] = request; 111 requests[requestId] = request;
112 var hasCallback = request.callback || optArgs.customCallback; 112 var hasCallback = request.callback || optArgs.customCallback;
113 return nativeFunction(functionName, 113 return nativeFunction(functionName,
114 requestArgs, 114 requestArgs,
115 requestId, 115 requestId,
116 hasCallback, 116 hasCallback,
117 optArgs.forIOThread, 117 optArgs.forIOThread,
118 optArgs.preserveNullInObjects); 118 optArgs.preserveNullInObjects);
119 } 119 }
120 120
121 exports.sendRequest = sendRequest; 121 exports.sendRequest = sendRequest;
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/miscellaneous_bindings.js ('k') | chrome/renderer/resources/renderer_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698