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

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

Issue 10890002: Make V8ValueConverter.FromV8Value behave similarly to JSON.stringify (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no more function Created 8 years, 3 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 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 request.args = []; 71 request.args = [];
72 for (var k = 0; k < argCount; k++) { 72 for (var k = 0; k < argCount; k++) {
73 request.args[k] = args[k]; 73 request.args[k] = args[k];
74 } 74 }
75 75
76 return request; 76 return request;
77 } 77 }
78 78
79 // Send an API request and optionally register a callback. 79 // Send an API request and optionally register a callback.
80 // |opt_args| is an object with optional parameters as follows: 80 // |optArgs| is an object with optional parameters as follows:
81 // - noStringify: true if we should not stringify the request arguments. 81 // - noStringify: true if we should not stringify the request arguments.
82 // - customCallback: a callback that should be called instead of the standard 82 // - customCallback: a callback that should be called instead of the standard
83 // callback. 83 // callback.
84 // - nativeFunction: the v8 native function to handle the request, or 84 // - nativeFunction: the v8 native function to handle the request, or
85 // StartRequest if missing. 85 // StartRequest if missing.
86 // - forIOThread: true if this function should be handled on the browser IO 86 // - forIOThread: true if this function should be handled on the browser IO
87 // thread. 87 // thread.
88 function sendRequest(functionName, args, argSchemas, opt_args) { 88 // - preserveNullInObjects: true if it is safe for null to be in objects.
89 if (!opt_args) 89 function sendRequest(functionName, args, argSchemas, optArgs) {
90 opt_args = {}; 90 if (!optArgs)
91 optArgs = {};
91 var request = prepareRequest(args, argSchemas); 92 var request = prepareRequest(args, argSchemas);
92 if (opt_args.customCallback) { 93 if (optArgs.customCallback) {
93 request.customCallback = opt_args.customCallback; 94 request.customCallback = optArgs.customCallback;
94 } 95 }
95 // JSON.stringify doesn't support a root object which is undefined. 96 // JSON.stringify doesn't support a root object which is undefined.
96 if (request.args === undefined) 97 if (request.args === undefined)
97 request.args = null; 98 request.args = null;
98 99
99 // TODO(asargent) - convert all optional native functions to accept raw 100 // TODO(asargent) - convert all optional native functions to accept raw
100 // v8 values instead of expecting JSON strings. 101 // v8 values instead of expecting JSON strings.
101 var doStringify = false; 102 var doStringify = false;
102 if (opt_args.nativeFunction && !opt_args.noStringify) 103 if (optArgs.nativeFunction && !optArgs.noStringify)
103 doStringify = true; 104 doStringify = true;
104 var requestArgs = doStringify ? 105 var requestArgs = doStringify ?
105 chromeHidden.JSON.stringify(request.args) : request.args; 106 chromeHidden.JSON.stringify(request.args) : request.args;
106 var nativeFunction = opt_args.nativeFunction || natives.StartRequest; 107 var nativeFunction = optArgs.nativeFunction || natives.StartRequest;
107 108
108 var requestId = natives.GetNextRequestId(); 109 var requestId = natives.GetNextRequestId();
109 request.id = requestId; 110 request.id = requestId;
110 requests[requestId] = request; 111 requests[requestId] = request;
111 var hasCallback = 112 var hasCallback = request.callback || optArgs.customCallback;
112 (request.callback || opt_args.customCallback) ? true : false; 113 return nativeFunction(functionName,
113 return nativeFunction(functionName, requestArgs, requestId, hasCallback, 114 requestArgs,
114 opt_args.forIOThread); 115 requestId,
116 hasCallback,
117 optArgs.forIOThread,
118 optArgs.preserveNullInObjects);
115 } 119 }
116 120
117 exports.sendRequest = sendRequest; 121 exports.sendRequest = sendRequest;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698