diff options
-rw-r--r-- | chrome/renderer/extensions/event_bindings.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_api_client_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/js_only_v8_extensions.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/js_only_v8_extensions.h | 6 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/renderer_resources.grd | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/event_bindings.js | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/extension_process_bindings.js | 7 | ||||
-rw-r--r-- | chrome/renderer/resources/renderer_extension_bindings.js | 9 | ||||
-rw-r--r-- | chrome/test/render_view_test.cc | 1 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools.html | 1 | ||||
-rw-r--r-- | webkit/glue/devtools/js/json.js | 328 | ||||
-rw-r--r-- | webkit/glue/webkit_resources.grd | 1 | ||||
-rw-r--r-- | webkit/webkit.gyp | 1 |
15 files changed, 15 insertions, 361 deletions
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index 06479dc..19a9245 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -41,8 +41,6 @@ int EventDecrementListenerCount(const std::string& event_name) { return --(data->listener_count[event_name]); } - -const char* kExtensionDeps[] = { JsonJsV8Extension::kName }; const char* kContextAttachCount = "chromium.attachCount"; class ExtensionImpl : public v8::Extension { @@ -50,7 +48,7 @@ class ExtensionImpl : public v8::Extension { ExtensionImpl() : v8::Extension(EventBindings::kName, GetStringResource<IDR_EVENT_BINDINGS_JS>(), - arraysize(kExtensionDeps), kExtensionDeps) { + 0, NULL) { } ~ExtensionImpl() {} diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc index 9689d95..ddc7c42 100644 --- a/chrome/renderer/extensions/extension_api_client_unittest.cc +++ b/chrome/renderer/extensions/extension_api_client_unittest.cc @@ -71,7 +71,7 @@ TEST_F(ExtensionAPIClientTest, CallbackDispatching) { "}" "function callback(result) {" " assert(typeof result == 'object', 'result not object');" - " assert(goog.json.serialize(result) == '{\"foo\":\"bar\"}', " + " assert(JSON.stringify(result) == '{\"foo\":\"bar\"}', " " 'incorrect result');" " console.log('pass')" "}" diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index 96f0256..6057a3e 100644 --- a/chrome/renderer/extensions/extension_process_bindings.cc +++ b/chrome/renderer/extensions/extension_process_bindings.cc @@ -25,7 +25,6 @@ const char kExtensionName[] = "chrome/ExtensionProcessBindings"; const char* kExtensionDeps[] = { BaseJsV8Extension::kName, EventBindings::kName, - JsonJsV8Extension::kName, JsonSchemaJsV8Extension::kName, RendererExtensionBindings::kName, }; diff --git a/chrome/renderer/js_only_v8_extensions.cc b/chrome/renderer/js_only_v8_extensions.cc index d304ef1..577f170 100644 --- a/chrome/renderer/js_only_v8_extensions.cc +++ b/chrome/renderer/js_only_v8_extensions.cc @@ -15,16 +15,6 @@ v8::Extension* BaseJsV8Extension::Get() { 0, NULL); } -// JsonJsV8Extension -const char* JsonJsV8Extension::kName = "chrome/json"; -v8::Extension* JsonJsV8Extension::Get() { - static const char* deps[] = { - BaseJsV8Extension::kName - }; - return new v8::Extension(kName, GetStringResource<IDR_DEVTOOLS_JSON_JS>(), - arraysize(deps), deps); -} - // JsonSchemaJsV8Extension const char* JsonSchemaJsV8Extension::kName = "chrome/jsonschema"; v8::Extension* JsonSchemaJsV8Extension::Get() { diff --git a/chrome/renderer/js_only_v8_extensions.h b/chrome/renderer/js_only_v8_extensions.h index 771103e..2fdb8af 100644 --- a/chrome/renderer/js_only_v8_extensions.h +++ b/chrome/renderer/js_only_v8_extensions.h @@ -16,12 +16,6 @@ class BaseJsV8Extension { static v8::Extension* Get(); }; -class JsonJsV8Extension { - public: - static const char* kName; - static v8::Extension* Get(); -}; - class JsonSchemaJsV8Extension { public: static const char* kName; diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 0412b94..844bd90 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -345,7 +345,6 @@ void RenderThread::EnsureWebKitInitialized() { // only so that we don't have to gate these on --enable-extensions. if (command_line.HasSwitch(switches::kEnableExtensions)) { WebKit::registerExtension(BaseJsV8Extension::Get()); - WebKit::registerExtension(JsonJsV8Extension::Get()); WebKit::registerExtension(JsonSchemaJsV8Extension::Get()); WebKit::registerExtension(EventBindings::Get()); WebKit::registerExtension(RendererExtensionBindings::Get()); diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index cda253b..c59e98c 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. --> +without changes to the corresponding grd file. --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/renderer_resources.h" type="rc_header"> diff --git a/chrome/renderer/resources/event_bindings.js b/chrome/renderer/resources/event_bindings.js index 6fcdd00..f11ec78 100644 --- a/chrome/renderer/resources/event_bindings.js +++ b/chrome/renderer/resources/event_bindings.js @@ -35,7 +35,7 @@ var chrome = chrome || {}; chrome.Event.dispatchJSON_ = function(name, args) { if (chrome.Event.attached_[name]) { if (args) { - args = goog.json.parse(args); + args = JSON.parse(args); } chrome.Event.attached_[name].dispatch.apply( chrome.Event.attached_[name], args); diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index 5a9fcf1..d025f7b 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -86,7 +86,7 @@ var chrome; if (callbacks[requestId]) { if (response) { - callbacks[requestId](goog.json.parse(response)); + callbacks[requestId](JSON.parse(response)); } else { callbacks[requestId](); } @@ -98,7 +98,10 @@ var chrome; // Send an API request and optionally register a callback. function sendRequest(request, args, callback) { - var sargs = goog.json.serialize(args); + // JSON.stringify doesn't support a root object which is undefined. + if (args === undefined) + args = null; + var sargs = JSON.stringify(args); var requestId = GetNextRequestId(); var hasCallback = false; if (callback) { diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js index 667b97d..cc232b4 100644 --- a/chrome/renderer/resources/renderer_extension_bindings.js +++ b/chrome/renderer/resources/renderer_extension_bindings.js @@ -33,7 +33,7 @@ var chrome = chrome || {}; chrome.Port.dispatchOnConnect_ = function(portId, tab) { var port = new chrome.Port(portId); if (tab) { - tab = goog.json.parse(tab); + tab = JSON.parse(tab); } port.tab = tab; chrome.Event.dispatch_("channel-connect", [port]); @@ -44,7 +44,7 @@ var chrome = chrome || {}; var port = chrome.Port.ports_[portId]; if (port) { if (msg) { - msg = goog.json.parse(msg); + msg = JSON.parse(msg); } port.onMessage.dispatch(msg, port); } @@ -53,7 +53,10 @@ var chrome = chrome || {}; // Sends a message asynchronously to the context on the other end of this // port. chrome.Port.prototype.postMessage = function(msg) { - PostMessage(this.portId_, goog.json.serialize(msg)); + // JSON.stringify doesn't support a root object which is undefined. + if (msg === undefined) + msg = null; + PostMessage(this.portId_, JSON.stringify(msg)); }; // Extension object. diff --git a/chrome/test/render_view_test.cc b/chrome/test/render_view_test.cc index 7eff1f9..20665f1 100644 --- a/chrome/test/render_view_test.cc +++ b/chrome/test/render_view_test.cc @@ -68,7 +68,6 @@ void RenderViewTest::SetUp() { WebKit::initialize(&webkitclient_); WebKit::registerExtension(BaseJsV8Extension::Get()); - WebKit::registerExtension(JsonJsV8Extension::Get()); WebKit::registerExtension(JsonSchemaJsV8Extension::Get()); WebKit::registerExtension(EventBindings::Get()); WebKit::registerExtension(ExtensionProcessBindings::Get()); diff --git a/webkit/glue/devtools/js/devtools.html b/webkit/glue/devtools/js/devtools.html index d01eb39..922b584 100644 --- a/webkit/glue/devtools/js/devtools.html +++ b/webkit/glue/devtools/js/devtools.html @@ -44,7 +44,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="inspector.css"> <script type="text/javascript" src="base.js"></script> - <script type="text/javascript" src="json.js"></script> <script type="text/javascript" src="utilities.js"></script> <script type="text/javascript" src="treeoutline.js"></script> <script type="text/javascript" src="devtools_callback.js"></script> diff --git a/webkit/glue/devtools/js/json.js b/webkit/glue/devtools/js/json.js deleted file mode 100644 index 252e4ac..0000000 --- a/webkit/glue/devtools/js/json.js +++ /dev/null @@ -1,328 +0,0 @@ -// Copyright 2006 Google Inc. -// All Rights Reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in -// the documentation and/or other materials provided with the -// distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -// NOTE: This file has been changed from the one on doctype. The following -// changes were made: -// - Modified unsafeParse() to use new Function() instead of eval() because eval -// is not allowed inside v8 extensions. -// - Modified parse() to delegate to unsafeParse() instead of calling eval() -// directly. - -/** - * @fileoverview JSON utility functions - */ - - - -goog.provide('goog.json'); -goog.provide('goog.json.Serializer'); - - -/** - * Tests if a string is an invalid JSON string. This only ensures that we are - * not using any invalid characters - * @param {string} s The string to test. - * @return {boolean} True if the input is a valid JSON string. - * @private - */ -goog.json.isValid_ = function(s) { - // All empty whitespace is not valid. - if (/^\s*$/.test(s)) { - return false; - } - - // This is taken from http://www.json.org/json2.js which is released to the - // public domain. - // Changes: We dissallow \u2028 Line separator and \u2029 Paragraph separator - // inside strings. We also treat \u2028 and \u2029 as whitespace which they - // are in the RFC but IE and Safari does not match \s to these so we need to - // include them in the reg exps in all places where whitespace is allowed. - - // Parsing happens in three stages. In the first stage, we run the text - // against regular expressions that look for non-JSON patterns. We are - // especially concerned with '()' and 'new' because they can cause invocation, - // and '=' because it can cause mutation. But just to be safe, we want to - // reject all unexpected forms. - - // We split the first stage into 4 regexp operations in order to work around - // crippling inefficiencies in IE's and Safari's regexp engines. First we - // replace all backslash pairs with '@' (a non-JSON character). Second, we - // replace all simple value tokens with ']' characters. Third, we delete all - // open brackets that follow a colon or comma or that begin the text. Finally, - // we look to see that the remaining characters are only whitespace or ']' or - // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. - - // Don't make these static since they have the global flag. - var backslashesRe = /\\["\\\/bfnrtu]/g; - var simpleValuesRe = - /"[^"\\\n\r\u2028\u2029\x00-\x1f\x7f-\x9f]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; - var openBracketsRe = /(?:^|:|,)(?:[\s\u2028\u2029]*\[)+/g; - var remainderRe = /^[\],:{}\s\u2028\u2029]*$/; - - return remainderRe.test(s.replace(backslashesRe, '@'). - replace(simpleValuesRe, ']'). - replace(openBracketsRe, '')); -}; - - -/** - * Parses a JSON string and returns the result. This throws an exception if - * the string is an invalid JSON string. - * - * If the user agent has built in support for parsing JSON (using - * <code>String.prototype.parseJSON</code>) that will be used. - * - * Note that this is very slow on large strings. If you trust the source of - * the string then you should use unsafeParse instead. - * - * @param {string} s The JSON string to parse. - * @return {Object} The object generated from the JSON string. - */ -goog.json.parse = function(s) { - s = String(s); - if (typeof s.parseJSON == 'function') { - return s.parseJSON(); - } - if (goog.json.isValid_(s)) { - /** @preserveTry */ - try { - return goog.json.unsafeParse(s); - } catch (ex) { - } - } - throw Error('Invalid JSON string: ' + s); -}; - - -/** - * Parses a JSON string and returns the result. This uses eval so it is open - * to security issues and it should only be used if you trust the source. - * - * @param {string} s The JSON string to parse. - * @return {Object} The object generated from the JSON string. - */ -goog.json.unsafeParse = function(s) { - // This is lame. V8 disallows direct access to eval() in extensions (see: - // v8::internal::Parser::ParseLeftHandSideExpression()). So we must use this - // nasty hack instead. - return new Function('return ('+ s + ')')(); -}; - - -/** - * Instance of the serializer object. - * @type {goog.json.Serializer} - * @private - */ -goog.json.serializer_ = null; - - -/** - * Serializes an object or a value to a JSON string. - * - * If the user agent has built in support for serializing JSON (using - * <code>Object.prototype.toJSONString</code>) that will be used. - * - * @param {Object} object The object to serialize. - * @throws Error if there are loops in the object graph. - * @return {string} A JSON string representation of the input. - */ -goog.json.serialize = function(object) { - if (!goog.json.serializer_) { - goog.json.serializer_ = new goog.json.Serializer; - } - return goog.json.serializer_.serialize(object); -}; - - - -/** - * Class that is used to serialize JSON objects to a string. - * @constructor - */ -goog.json.Serializer = function() { -}; - - -/** - * Serializes an object or a value to a JSON string. - * - * If the user agent has built in support for serializing JSON (using - * <code>Object.prototype.toJSONString</code>) that will be used. - * - * @param {Object?} object The object to serialize. - * @throws Error if there are loops in the object graph. - * @return {string} A JSON string representation of the input. - */ -goog.json.Serializer.prototype.serialize = function(object) { - // null and undefined cannot have properties. (null == undefined) - if (object != null && typeof object.toJSONString == 'function') { - return object.toJSONString(); - } - var sb = []; - this.serialize_(object, sb); - return sb.join(''); -}; - - -/** - * Serializes a generic value to a JSON string - * @private - * @param {Object?} object The object to serialize. - * @param {Array} sb Array used as a string builder. - * @throws Error if there are loops in the object graph. - */ -goog.json.Serializer.prototype.serialize_ = function(object, sb) { - switch (typeof object) { - case 'string': - this.serializeString_(object, sb); - break; - case 'number': - this.serializeNumber_(object, sb); - break; - case 'boolean': - sb.push(object); - break; - case 'undefined': - sb.push('null'); - break; - case 'object': - if (object == null) { - sb.push('null'); - break; - } - if (goog.isArray(object)) { - this.serializeArray_(object, sb); - break; - } - // should we allow new String, new Number and new Boolean to be treated - // as string, number and boolean? Most implementations do not and the - // need is not very big - this.serializeObject_(object, sb); - break; - default: - throw Error('Unknown type: ' + typeof object); - } -}; - - -/** - * Character mappings used internally for goog.string.quote - * @private - * @type {Object} - */ -goog.json.Serializer.charToJsonCharCache_ = { - '\"': '\\"', - '\\': '\\\\', - '/': '\\/', - '\b': '\\b', - '\f': '\\f', - '\n': '\\n', - '\r': '\\r', - '\t': '\\t', - - '\x0B': '\\u000b' // '\v' is not supported in JScript -}; - - -/** - * Serializes a string to a JSON string - * @private - * @param {string} s The string to serialize. - * @param {Array} sb Array used as a string builder. - */ -goog.json.Serializer.prototype.serializeString_ = function(s, sb) { - // The official JSON implementation does not work with international - // characters. - sb.push('"', s.replace(/[\\\"\x00-\x1f\x80-\uffff]/g, function(c) { - // caching the result improves performance by a factor 2-3 - if (c in goog.json.Serializer.charToJsonCharCache_) { - return goog.json.Serializer.charToJsonCharCache_[c]; - } - - var cc = c.charCodeAt(0); - var rv = '\\u'; - if (cc < 16) { - rv += '000'; - } else if (cc < 256) { - rv += '00'; - } else if (cc < 4096) { // \u1000 - rv += '0'; - } - return goog.json.Serializer.charToJsonCharCache_[c] = rv + cc.toString(16); - }), '"'); -}; - - -/** - * Serializes a number to a JSON string - * @private - * @param {number} n The number to serialize. - * @param {Array} sb Array used as a string builder. - */ -goog.json.Serializer.prototype.serializeNumber_ = function(n, sb) { - sb.push(isFinite(n) && !isNaN(n) ? n : 'null'); -}; - - -/** - * Serializes an array to a JSON string - * @private - * @param {Array} arr The array to serialize. - * @param {Array} sb Array used as a string builder. - */ -goog.json.Serializer.prototype.serializeArray_ = function(arr, sb) { - var l = arr.length; - sb.push('['); - var sep = ''; - for (var i = 0; i < l; i++) { - sb.push(sep) - this.serialize_(arr[i], sb); - sep = ','; - } - sb.push(']'); -}; - - -/** - * Serializes an object to a JSON string - * @private - * @param {Object} obj The object to serialize. - * @param {Array} sb Array used as a string builder. - */ -goog.json.Serializer.prototype.serializeObject_ = function(obj, sb) { - sb.push('{'); - var sep = ''; - for (var key in obj) { - sb.push(sep); - this.serializeString_(key, sb); - sb.push(':'); - this.serialize_(obj[key], sb); - sep = ','; - } - sb.push('}'); -}; diff --git a/webkit/glue/webkit_resources.grd b/webkit/glue/webkit_resources.grd index d07b8c3..8be239f 100644 --- a/webkit/glue/webkit_resources.grd +++ b/webkit/glue/webkit_resources.grd @@ -19,7 +19,6 @@ <include name="IDR_SEARCH_MAGNIFIER_RESULTS" file="resources\search_magnifier_results.png" type="BINDATA" /> <include name="IDR_TEXTAREA_RESIZER" file="resources\textarea_resize_corner.png" type="BINDATA" /> <include name="IDR_DEVTOOLS_BASE_JS" file="devtools\js\base.js" type="BINDATA" /> - <include name="IDR_DEVTOOLS_JSON_JS" file="devtools\js\json.js" type="BINDATA" /> <include name="IDR_DEVTOOLS_INJECT_DISPATCH_JS" file="devtools\js\inject_dispatch.js" type="BINDATA" /> <include name="IDR_DEVTOOLS_INJECT_JS" file="devtools\js\inject.js" type="BINDATA" /> <include name="IDR_MEDIA_PLAY_BUTTON" file="resources\media_play.png" type="BINDATA" /> diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 9160d1c..534ce7d 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -4673,7 +4673,6 @@ 'glue/devtools/js/inject.js', 'glue/devtools/js/inspector_controller.js', 'glue/devtools/js/inspector_controller_impl.js', - 'glue/devtools/js/json.js', 'glue/devtools/js/profiler_processor.js', 'inspector/debugger.css', 'inspector/debugger.html', |