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

Side by Side Diff: trunk/src/extensions/renderer/resources/messaging_utils.js

Issue 309413002: Revert 274558 "Move some extensions renderer resources to extens..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Routines used to normalize arguments to messaging functions.
6
7 function alignSendMessageArguments(args, hasOptionsArgument) {
8 // Align missing (optional) function arguments with the arguments that
9 // schema validation is expecting, e.g.
10 // extension.sendRequest(req) -> extension.sendRequest(null, req)
11 // extension.sendRequest(req, cb) -> extension.sendRequest(null, req, cb)
12 if (!args || !args.length)
13 return null;
14 var lastArg = args.length - 1;
15
16 // responseCallback (last argument) is optional.
17 var responseCallback = null;
18 if (typeof args[lastArg] == 'function')
19 responseCallback = args[lastArg--];
20
21 var options = null;
22 if (hasOptionsArgument && lastArg >= 1) {
23 // options (third argument) is optional. It can also be ambiguous which
24 // argument it should match. If there are more than two arguments remaining,
25 // options is definitely present:
26 if (lastArg > 1) {
27 options = args[lastArg--];
28 } else {
29 // Exactly two arguments remaining. If the first argument is a string,
30 // it should bind to targetId, and the second argument should bind to
31 // request, which is required. In other words, when two arguments remain,
32 // only bind options when the first argument cannot bind to targetId.
33 if (!(args[0] === null || typeof args[0] == 'string'))
34 options = args[lastArg--];
35 }
36 }
37
38 // request (second argument) is required.
39 var request = args[lastArg--];
40
41 // targetId (first argument, extensionId in the manifest) is optional.
42 var targetId = null;
43 if (lastArg >= 0)
44 targetId = args[lastArg--];
45
46 if (lastArg != -1)
47 return null;
48 if (hasOptionsArgument)
49 return [targetId, request, options, responseCallback];
50 return [targetId, request, responseCallback];
51 }
52
53 exports.alignSendMessageArguments = alignSendMessageArguments;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698