diff options
Diffstat (limited to 'chrome/renderer/resources')
-rw-r--r-- | chrome/renderer/resources/event_bindings.js | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/extension_process_bindings.js | 44 |
2 files changed, 3 insertions, 43 deletions
diff --git a/chrome/renderer/resources/event_bindings.js b/chrome/renderer/resources/event_bindings.js index de5b3a9..42f1175 100644 --- a/chrome/renderer/resources/event_bindings.js +++ b/chrome/renderer/resources/event_bindings.js @@ -25,7 +25,7 @@ var chromium = chromium || {}; chromium.Event.dispatchJSON_ = function(name, data) { if (chromium.Event.attached_[name]) { if (data) { - data = chromium.json.deserialize_(data); + data = chromium.json.parse(data); } chromium.Event.attached_[name].dispatch_(data); } diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index 221f3fd..85d4d53 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -6,53 +6,13 @@ var chromium; // callback handling var callbacks = []; chromium._dispatchCallback = function(callbackId, str) { - // We shouldn't be receiving evil JSON unless the browser is owned, but just - // to be safe, we sanitize it. This regex mania was borrowed from json2, - // from json.org. - if (!/^[\],:{}\s]*$/.test( - str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). - replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). - replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) - throw new Error("Unexpected characters in incoming JSON response."); - - // This is lame. V8 disallows direct access to eval() in extensions (see: - // v8::internal::Parser::ParseLeftHandSideExpression()). So we must use - // this supa-jank hack instead. We really need native JSON. - str = 'return ' + str; - callbacks[callbackId](new Function(str)()); + callbacks[callbackId](goog.json.parse(str)); delete callbacks[callbackId]; }; - // Quick and dirty json serialization. - // TODO(aa): Did I mention we need native JSON? - function serialize(thing) { - switch (typeof thing) { - case 'string': - return '\"' + thing.replace('\\', '\\\\').replace('\"', '\\\"') + '\"'; - case 'boolean': - case 'number': - return String(thing); - case 'object': - if (thing === null) - return String(thing) - var items = []; - if (thing.constructor == Array) { - for (var i = 0; i < thing.length; i++) - items.push(serialize(thing[i])); - return '[' + items.join(',') + ']'; - } else { - for (var p in thing) - items.push(serialize(p) + ':' + serialize(thing[p])); - return '{' + items.join(',') + '}'; - } - default: - return ''; - } - } - // Send an API request and optionally register a callback. function sendRequest(request, args, callback) { - var sargs = serialize(args); + var sargs = goog.json.serialize(args); var callbackId = -1; if (callback) { native function GetNextCallbackId(); |