diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-25 08:31:17 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-25 08:31:17 +0000 |
commit | be77f0a531fda9ce5b911831f11848a7a87e4fb7 (patch) | |
tree | c677fd5f3b000180c33997f4dea4c4d152e86c46 | |
parent | a6ec2b5503d4914c03eb4439ba3ab3958eeccb9b (diff) | |
download | chromium_src-be77f0a531fda9ce5b911831f11848a7a87e4fb7.zip chromium_src-be77f0a531fda9ce5b911831f11848a7a87e4fb7.tar.gz chromium_src-be77f0a531fda9ce5b911831f11848a7a87e4fb7.tar.bz2 |
Try again to commit r24174: Change the way json_schema.js is loaded.
TBR=mpcomplete@chromium.org
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24224 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/chrome.gyp | 4 | ||||
-rw-r--r-- | chrome/renderer/extensions/event_bindings.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/extensions/js_only_v8_extensions.cc (renamed from chrome/renderer/js_only_v8_extensions.cc) | 10 | ||||
-rw-r--r-- | chrome/renderer/extensions/js_only_v8_extensions.h (renamed from chrome/renderer/js_only_v8_extensions.h) | 4 | ||||
-rw-r--r-- | chrome/renderer/extensions/json_schema_unittest.cc | 16 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/renderer_resources.grd | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/extension_process_bindings.js | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/json_schema.js | 61 | ||||
-rw-r--r-- | chrome/test/data/extensions/json_schema_test.js | 6 | ||||
-rw-r--r-- | chrome/test/render_view_test.cc | 2 |
12 files changed, 63 insertions, 50 deletions
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index bd42785..3bfdf95 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -2714,6 +2714,8 @@ 'renderer/extensions/event_bindings.h', 'renderer/extensions/extension_process_bindings.cc', 'renderer/extensions/extension_process_bindings.h', + 'renderer/extensions/js_only_v8_extensions.cc', + 'renderer/extensions/js_only_v8_extensions.h', 'renderer/extensions/renderer_extension_bindings.cc', 'renderer/extensions/renderer_extension_bindings.h', 'renderer/loadtimes_extension_bindings.h', @@ -2746,8 +2748,6 @@ 'renderer/external_host_bindings.h', 'renderer/external_extension.cc', 'renderer/external_extension.h', - 'renderer/js_only_v8_extensions.cc', - 'renderer/js_only_v8_extensions.h', 'renderer/localized_error.cc', 'renderer/localized_error.h', 'renderer/navigation_state.h', diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index b2cecdc..416ab2c 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -10,7 +10,7 @@ #include "chrome/common/url_constants.h" #include "chrome/renderer/extensions/bindings_utils.h" #include "chrome/renderer/extensions/event_bindings.h" -#include "chrome/renderer/js_only_v8_extensions.h" +#include "chrome/renderer/extensions/js_only_v8_extensions.h" #include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_view.h" #include "grit/renderer_resources.h" diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index ed56ba5..7fc6bda 100644 --- a/chrome/renderer/extensions/extension_process_bindings.cc +++ b/chrome/renderer/extensions/extension_process_bindings.cc @@ -11,8 +11,8 @@ #include "chrome/common/url_constants.h" #include "chrome/renderer/extensions/bindings_utils.h" #include "chrome/renderer/extensions/event_bindings.h" +#include "chrome/renderer/extensions/js_only_v8_extensions.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" -#include "chrome/renderer/js_only_v8_extensions.h" #include "chrome/renderer/render_view.h" #include "grit/common_resources.h" #include "grit/renderer_resources.h" diff --git a/chrome/renderer/js_only_v8_extensions.cc b/chrome/renderer/extensions/js_only_v8_extensions.cc index ff36a2b..986e656 100644 --- a/chrome/renderer/js_only_v8_extensions.cc +++ b/chrome/renderer/extensions/js_only_v8_extensions.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/js_only_v8_extensions.h" +#include "chrome/renderer/extensions/js_only_v8_extensions.h" #include "chrome/renderer/extensions/bindings_utils.h" #include "grit/renderer_resources.h" @@ -14,8 +14,8 @@ using bindings_utils::GetStringResource; const char* BaseJsV8Extension::kName = "chrome/base"; v8::Extension* BaseJsV8Extension::Get() { static v8::Extension* extension = - new v8::Extension(kName, GetStringResource<IDR_DEVTOOLS_BASE_JS>(), - 0, NULL); + new bindings_utils::ExtensionBase( + kName, GetStringResource<IDR_DEVTOOLS_BASE_JS>(), 0, NULL); return extension; } @@ -23,7 +23,7 @@ v8::Extension* BaseJsV8Extension::Get() { const char* JsonSchemaJsV8Extension::kName = "chrome/jsonschema"; v8::Extension* JsonSchemaJsV8Extension::Get() { static v8::Extension* extension = - new v8::Extension(kName, GetStringResource<IDR_JSON_SCHEMA_JS>(), - 0, NULL); + new bindings_utils::ExtensionBase( + kName, GetStringResource<IDR_JSON_SCHEMA_JS>(), 0, NULL); return extension; } diff --git a/chrome/renderer/js_only_v8_extensions.h b/chrome/renderer/extensions/js_only_v8_extensions.h index 2fdb8af..58f9861 100644 --- a/chrome/renderer/js_only_v8_extensions.h +++ b/chrome/renderer/extensions/js_only_v8_extensions.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_RENDERER_JS_ONLY_V8_EXTENSIONS_H_ -#define CHROME_RENDERER_JS_ONLY_V8_EXTENSIONS_H_ +#ifndef CHROME_RENDERER_EXTENSIONS_JS_ONLY_V8_EXTENSIONS_H_ +#define CHROME_RENDERER_EXTENSIONS_JS_ONLY_V8_EXTENSIONS_H_ #include "v8/include/v8.h" diff --git a/chrome/renderer/extensions/json_schema_unittest.cc b/chrome/renderer/extensions/json_schema_unittest.cc index 9b53094..a83693a 100644 --- a/chrome/renderer/extensions/json_schema_unittest.cc +++ b/chrome/renderer/extensions/json_schema_unittest.cc @@ -23,9 +23,19 @@ class JsonSchemaTest : public V8UnitTest { V8UnitTest::SetUp(); // Add the json schema code to the context. - StringPiece js = ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_JSON_SCHEMA_JS); - ExecuteScriptInContext(js, kJsonSchema); + std::string code = ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_JSON_SCHEMA_JS).as_string(); + + // This is a nasty hack, but it is easier to test the code if we don't use + // it as a v8 extension. So replace the only bit that relies on that with a + // more easily testable implementation. + ReplaceFirstSubstringAfterOffset(&code, 0, + "native function GetChromeHidden();", + "function GetChromeHidden() {\n" + " if (!this.chromeHidden) this.chromeHidden = {};\n" + " return this.chromeHidden;\n" + "}"); + ExecuteScriptInContext(code, kJsonSchema); // Add the test functions to the context. FilePath test_js_file_path; diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 1492e9d..4b6c60a 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -30,9 +30,9 @@ #include "chrome/renderer/extension_groups.h" #include "chrome/renderer/extensions/event_bindings.h" #include "chrome/renderer/extensions/extension_process_bindings.h" +#include "chrome/renderer/extensions/js_only_v8_extensions.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" #include "chrome/renderer/external_extension.h" -#include "chrome/renderer/js_only_v8_extensions.h" #include "chrome/renderer/loadtimes_extension_bindings.h" #include "chrome/renderer/net/render_dns_master.h" #include "chrome/renderer/render_process.h" diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index 5640a3c..b426d6e 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. rw2b --> +without changes to the corresponding grd file. aa4 --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/renderer_resources.h" type="rc_header"> diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index 63d99cc..697e0a7 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -33,7 +33,7 @@ var chrome = chrome || {}; for (var i = 0; i < schemas.length; i++) { if (i in args && args[i] !== null && args[i] !== undefined) { - var validator = new chrome.JSONSchemaValidator(); + var validator = new chromeHidden.JSONSchemaValidator(); validator.addTypes(chromeHidden.validationTypes); validator.validate(args[i], schemas[i]); if (validator.errors.length == 0) diff --git a/chrome/renderer/resources/json_schema.js b/chrome/renderer/resources/json_schema.js index 70dd26f..dcdfec8 100644 --- a/chrome/renderer/resources/json_schema.js +++ b/chrome/renderer/resources/json_schema.js @@ -36,12 +36,14 @@ // - made additionalProperties default to false //============================================================================== -var chrome = chrome || {}; +(function() { +native function GetChromeHidden(); +var chromeHidden = GetChromeHidden(); /** * Validates an instance against a schema and accumulates errors. Usage: * - * var validator = new chrome.JSONSchemaValidator(); + * var validator = new chromeHidden.JSONSchemaValidator(); * validator.validate(inst, schema); * if (validator.errors.length == 0) * console.log("Valid!"); @@ -53,12 +55,12 @@ var chrome = chrome || {}; * the key that had the problem, and the "message" property contains a sentence * describing the error. */ -chrome.JSONSchemaValidator = function() { +chromeHidden.JSONSchemaValidator = function() { this.errors = []; this.types = []; }; -chrome.JSONSchemaValidator.messages = { +chromeHidden.JSONSchemaValidator.messages = { invalidEnum: "Value must be one of: [*].", propertyRequired: "Property is required.", unexpectedProperty: "Unexpected property.", @@ -82,7 +84,7 @@ chrome.JSONSchemaValidator.messages = { * Builds an error message. Key is the property in the |errors| object, and * |opt_replacements| is an array of values to replace "*" characters with. */ -chrome.JSONSchemaValidator.formatError = function(key, opt_replacements) { +chromeHidden.JSONSchemaValidator.formatError = function(key, opt_replacements) { var message = this.messages[key]; if (opt_replacements) { for (var i = 0; i < opt_replacements.length; i++) { @@ -97,7 +99,7 @@ chrome.JSONSchemaValidator.formatError = function(key, opt_replacements) { * don't explicitly disallow 'function', because we want to allow functions in * the input values. */ -chrome.JSONSchemaValidator.getType = function(value) { +chromeHidden.JSONSchemaValidator.getType = function(value) { var s = typeof value; if (s == "object") { @@ -121,7 +123,7 @@ chrome.JSONSchemaValidator.getType = function(value) { * with "$ref": <typeId>. Each type must be a valid schema and define an * "id" property. */ -chrome.JSONSchemaValidator.prototype.addTypes = function(typeOrTypeList) { +chromeHidden.JSONSchemaValidator.prototype.addTypes = function(typeOrTypeList) { function addType(validator, type) { if(!type.id) throw "Attempt to addType with missing 'id' property"; @@ -142,8 +144,8 @@ chrome.JSONSchemaValidator.prototype.addTypes = function(typeOrTypeList) { * value and will be validated recursively. When this method returns, the * |errors| property will contain a list of errors, if any. */ -chrome.JSONSchemaValidator.prototype.validate = function(instance, schema, - opt_path) { +chromeHidden.JSONSchemaValidator.prototype.validate = function( + instance, schema, opt_path) { var path = opt_path || ""; if (!schema) { @@ -210,9 +212,8 @@ chrome.JSONSchemaValidator.prototype.validate = function(instance, schema, * Validates an instance against a choices schema. The instance must match at * least one of the provided choices. */ -chrome.JSONSchemaValidator.prototype.validateChoices = function(instance, - schema, - path) { +chromeHidden.JSONSchemaValidator.prototype.validateChoices = function( + instance, schema, path) { var originalErrors = this.errors; for (var i = 0; i < schema.choices.length; i++) { @@ -233,8 +234,8 @@ chrome.JSONSchemaValidator.prototype.validateChoices = function(instance, * |errors| property, and returns a boolean indicating whether the instance * validates. */ -chrome.JSONSchemaValidator.prototype.validateEnum = function(instance, schema, - path) { +chromeHidden.JSONSchemaValidator.prototype.validateEnum = function( + instance, schema, path) { for (var i = 0; i < schema.enum.length; i++) { if (instance === schema.enum[i]) return true; @@ -248,8 +249,8 @@ chrome.JSONSchemaValidator.prototype.validateEnum = function(instance, schema, * Validates an instance against an object schema and populates the errors * property. */ -chrome.JSONSchemaValidator.prototype.validateObject = function(instance, - schema, path) { +chromeHidden.JSONSchemaValidator.prototype.validateObject = function( + instance, schema, path) { for (var prop in schema.properties) { var propPath = path ? path + "." + prop : prop; if (schema.properties[prop] == undefined) { @@ -281,9 +282,9 @@ chrome.JSONSchemaValidator.prototype.validateObject = function(instance, * Validates an instance against an array schema and populates the errors * property. */ -chrome.JSONSchemaValidator.prototype.validateArray = function(instance, - schema, path) { - var typeOfItems = chrome.JSONSchemaValidator.getType(schema.items); +chromeHidden.JSONSchemaValidator.prototype.validateArray = function( + instance, schema, path) { + var typeOfItems = chromeHidden.JSONSchemaValidator.getType(schema.items); if (typeOfItems == 'object') { if (schema.minItems && instance.length < schema.minItems) { @@ -328,8 +329,8 @@ chrome.JSONSchemaValidator.prototype.validateArray = function(instance, /** * Validates a string and populates the errors property. */ -chrome.JSONSchemaValidator.prototype.validateString = function(instance, - schema, path) { +chromeHidden.JSONSchemaValidator.prototype.validateString = function( + instance, schema, path) { if (schema.minLength && instance.length < schema.minLength) this.addError(path, "stringMinLength", [schema.minLength]); @@ -344,8 +345,8 @@ chrome.JSONSchemaValidator.prototype.validateString = function(instance, * Validates a number and populates the errors property. The instance is * assumed to be a number. */ -chrome.JSONSchemaValidator.prototype.validateNumber = function(instance, - schema, path) { +chromeHidden.JSONSchemaValidator.prototype.validateNumber = function( + instance, schema, path) { if (schema.minimum && instance < schema.minimum) this.addError(path, "numberMinValue", [schema.minimum]); @@ -360,9 +361,9 @@ chrome.JSONSchemaValidator.prototype.validateNumber = function(instance, * Validates the primitive type of an instance and populates the errors * property. Returns true if the instance validates, false otherwise. */ -chrome.JSONSchemaValidator.prototype.validateType = function(instance, schema, - path) { - var actualType = chrome.JSONSchemaValidator.getType(instance); +chromeHidden.JSONSchemaValidator.prototype.validateType = function( + instance, schema, path) { + var actualType = chromeHidden.JSONSchemaValidator.getType(instance); if (schema.type != actualType && !(schema.type == "number" && actualType == "integer")) { this.addError(path, "invalidType", [schema.type, actualType]); @@ -377,10 +378,12 @@ chrome.JSONSchemaValidator.prototype.validateType = function(instance, schema, * |replacements| is an array of values to replace '*' characters in the * message. */ -chrome.JSONSchemaValidator.prototype.addError = function(path, key, - replacements) { +chromeHidden.JSONSchemaValidator.prototype.addError = function( + path, key, replacements) { this.errors.push({ path: path, - message: chrome.JSONSchemaValidator.formatError(key, replacements) + message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) }); }; + +})(); diff --git a/chrome/test/data/extensions/json_schema_test.js b/chrome/test/data/extensions/json_schema_test.js index 4231888..1713b27 100644 --- a/chrome/test/data/extensions/json_schema_test.js +++ b/chrome/test/data/extensions/json_schema_test.js @@ -8,7 +8,7 @@ function assert(truth) { } function assertValid(type, instance, schema, types) { - var validator = new chrome.JSONSchemaValidator(); + var validator = new chromeHidden.JSONSchemaValidator(); if (types) validator.addTypes(types); validator["validate" + type](instance, schema, ""); @@ -20,7 +20,7 @@ function assertValid(type, instance, schema, types) { } function assertNotValid(type, instance, schema, errors, types) { - var validator = new chrome.JSONSchemaValidator(); + var validator = new chromeHidden.JSONSchemaValidator(); if (types) validator.addTypes(types); validator["validate" + type](instance, schema, ""); @@ -38,7 +38,7 @@ function assertNotValid(type, instance, schema, errors, types) { } function formatError(key, replacements) { - return chrome.JSONSchemaValidator.formatError(key, replacements); + return chromeHidden.JSONSchemaValidator.formatError(key, replacements); } function testFormatError() { diff --git a/chrome/test/render_view_test.cc b/chrome/test/render_view_test.cc index 134256b..cf3a90b 100644 --- a/chrome/test/render_view_test.cc +++ b/chrome/test/render_view_test.cc @@ -11,8 +11,8 @@ #include "chrome/common/renderer_preferences.h" #include "chrome/renderer/extensions/event_bindings.h" #include "chrome/renderer/extensions/extension_process_bindings.h" +#include "chrome/renderer/extensions/js_only_v8_extensions.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" -#include "chrome/renderer/js_only_v8_extensions.h" #include "chrome/renderer/renderer_main_platform_delegate.h" #include "webkit/api/public/WebFrame.h" #include "webkit/api/public/WebInputEvent.h" |