blob: 0416676e3f526324b9ab3f5d31b957eed77da229 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Injects 'injected' object into the inspectable page.
*/
/**
* Dispatches host calls into the injected function calls.
*/
goog.require('devtools.Injected');
/**
* Injected singleton.
*/
var devtools$$obj = new devtools.Injected();
/**
* Main dispatch method, all calls from the host go through this one.
* @param {string} functionName Function to call
* @param {string} json_args JSON-serialized call parameters.
* @return {string} JSON-serialized result of the dispatched call.
*/
function devtools$$dispatch(functionName, json_args) {
var params = JSON.parse(json_args);
var result = devtools$$obj[functionName].apply(devtools$$obj, params);
return JSON.stringify(result);
};
/**
* This is called by the InspectorFrontend for serialization.
* We serialize the call and send it to the client over the IPC
* using dispatchOut bound method.
*/
var dispatch = function(method, var_args) {
// Handle all messages with non-primitieve arguments here.
var args = Array.prototype.slice.call(arguments);
// Serialize objects here.
if (method == 'addMessageToConsole') {
// Skip first argument since it is serializable.
// Method has index 0, first argument has index 1. Skip both.
for (var i = 2; i < args.length; ++i) {
args[i] = devtools$$obj.wrapConsoleObject(args[i]);
}
} else if (method == 'inspectedWindowCleared' ||
method == 'reset' ||
method == 'setAttachedWindow') {
// Filter out messages we don't need here.
// We do it on the sender side since they may have non-serializable
// parameters.
return;
}
var call = JSON.stringify(args);
DevToolsAgentHost.dispatch(call);
};
|