From 953706c173db261239e7d36ff442cba6e1e11db6 Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Tue, 25 Aug 2009 06:16:03 +0000 Subject: Revert r24217. TBR=mpcomplete@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24218 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/renderer/extensions/event_bindings.cc | 2 +- .../extensions/extension_process_bindings.cc | 2 +- .../renderer/extensions/js_only_v8_extensions.cc | 29 ---------- chrome/renderer/extensions/js_only_v8_extensions.h | 25 --------- chrome/renderer/js_only_v8_extensions.cc | 29 ++++++++++ chrome/renderer/js_only_v8_extensions.h | 25 +++++++++ chrome/renderer/render_thread.cc | 2 +- chrome/renderer/renderer_resources.grd | 2 +- .../resources/extension_process_bindings.js | 2 +- chrome/renderer/resources/json_schema.js | 61 ++++++++++------------ 10 files changed, 88 insertions(+), 91 deletions(-) delete mode 100644 chrome/renderer/extensions/js_only_v8_extensions.cc delete mode 100644 chrome/renderer/extensions/js_only_v8_extensions.h create mode 100644 chrome/renderer/js_only_v8_extensions.cc create mode 100644 chrome/renderer/js_only_v8_extensions.h (limited to 'chrome/renderer') diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index 416ab2c..b2cecdc 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/extensions/js_only_v8_extensions.h" +#include "chrome/renderer/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 7fc6bda..ed56ba5 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/extensions/js_only_v8_extensions.cc b/chrome/renderer/extensions/js_only_v8_extensions.cc deleted file mode 100644 index 986e656..0000000 --- a/chrome/renderer/extensions/js_only_v8_extensions.cc +++ /dev/null @@ -1,29 +0,0 @@ -// 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. - -#include "chrome/renderer/extensions/js_only_v8_extensions.h" - -#include "chrome/renderer/extensions/bindings_utils.h" -#include "grit/renderer_resources.h" -#include "grit/webkit_resources.h" - -using bindings_utils::GetStringResource; - -// BaseJsV8Extension -const char* BaseJsV8Extension::kName = "chrome/base"; -v8::Extension* BaseJsV8Extension::Get() { - static v8::Extension* extension = - new bindings_utils::ExtensionBase( - kName, GetStringResource(), 0, NULL); - return extension; -} - -// JsonSchemaJsV8Extension -const char* JsonSchemaJsV8Extension::kName = "chrome/jsonschema"; -v8::Extension* JsonSchemaJsV8Extension::Get() { - static v8::Extension* extension = - new bindings_utils::ExtensionBase( - kName, GetStringResource(), 0, NULL); - return extension; -} diff --git a/chrome/renderer/extensions/js_only_v8_extensions.h b/chrome/renderer/extensions/js_only_v8_extensions.h deleted file mode 100644 index 58f9861..0000000 --- a/chrome/renderer/extensions/js_only_v8_extensions.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#ifndef CHROME_RENDERER_EXTENSIONS_JS_ONLY_V8_EXTENSIONS_H_ -#define CHROME_RENDERER_EXTENSIONS_JS_ONLY_V8_EXTENSIONS_H_ - -#include "v8/include/v8.h" - -// This file contains various V8 Extensions that are JavaScript only, and -// don't have any C++ native functions. - -class BaseJsV8Extension { - public: - static const char* kName; - static v8::Extension* Get(); -}; - -class JsonSchemaJsV8Extension { - public: - static const char* kName; - static v8::Extension* Get(); -}; - -#endif // CHROME_RENDERER_JS_ONLY_V8_EXTENSIONS_H_ diff --git a/chrome/renderer/js_only_v8_extensions.cc b/chrome/renderer/js_only_v8_extensions.cc new file mode 100644 index 0000000..ff36a2b --- /dev/null +++ b/chrome/renderer/js_only_v8_extensions.cc @@ -0,0 +1,29 @@ +// 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. + +#include "chrome/renderer/js_only_v8_extensions.h" + +#include "chrome/renderer/extensions/bindings_utils.h" +#include "grit/renderer_resources.h" +#include "grit/webkit_resources.h" + +using bindings_utils::GetStringResource; + +// BaseJsV8Extension +const char* BaseJsV8Extension::kName = "chrome/base"; +v8::Extension* BaseJsV8Extension::Get() { + static v8::Extension* extension = + new v8::Extension(kName, GetStringResource(), + 0, NULL); + return extension; +} + +// JsonSchemaJsV8Extension +const char* JsonSchemaJsV8Extension::kName = "chrome/jsonschema"; +v8::Extension* JsonSchemaJsV8Extension::Get() { + static v8::Extension* extension = + new v8::Extension(kName, GetStringResource(), + 0, NULL); + return extension; +} diff --git a/chrome/renderer/js_only_v8_extensions.h b/chrome/renderer/js_only_v8_extensions.h new file mode 100644 index 0000000..2fdb8af --- /dev/null +++ b/chrome/renderer/js_only_v8_extensions.h @@ -0,0 +1,25 @@ +// 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. + +#ifndef CHROME_RENDERER_JS_ONLY_V8_EXTENSIONS_H_ +#define CHROME_RENDERER_JS_ONLY_V8_EXTENSIONS_H_ + +#include "v8/include/v8.h" + +// This file contains various V8 Extensions that are JavaScript only, and +// don't have any C++ native functions. + +class BaseJsV8Extension { + public: + static const char* kName; + static v8::Extension* Get(); +}; + +class JsonSchemaJsV8Extension { + public: + static const char* kName; + static v8::Extension* Get(); +}; + +#endif // CHROME_RENDERER_JS_ONLY_V8_EXTENSIONS_H_ diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index c6e5b17..af5e4c5 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 0334f6c..5640a3c 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -1,6 +1,6 @@ +without changes to the corresponding grd file. rw2b --> diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index 697e0a7..63d99cc 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 chromeHidden.JSONSchemaValidator(); + var validator = new chrome.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 dcdfec8..70dd26f 100644 --- a/chrome/renderer/resources/json_schema.js +++ b/chrome/renderer/resources/json_schema.js @@ -36,14 +36,12 @@ // - made additionalProperties default to false //============================================================================== -(function() { -native function GetChromeHidden(); -var chromeHidden = GetChromeHidden(); +var chrome = chrome || {}; /** * Validates an instance against a schema and accumulates errors. Usage: * - * var validator = new chromeHidden.JSONSchemaValidator(); + * var validator = new chrome.JSONSchemaValidator(); * validator.validate(inst, schema); * if (validator.errors.length == 0) * console.log("Valid!"); @@ -55,12 +53,12 @@ var chromeHidden = GetChromeHidden(); * the key that had the problem, and the "message" property contains a sentence * describing the error. */ -chromeHidden.JSONSchemaValidator = function() { +chrome.JSONSchemaValidator = function() { this.errors = []; this.types = []; }; -chromeHidden.JSONSchemaValidator.messages = { +chrome.JSONSchemaValidator.messages = { invalidEnum: "Value must be one of: [*].", propertyRequired: "Property is required.", unexpectedProperty: "Unexpected property.", @@ -84,7 +82,7 @@ chromeHidden.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. */ -chromeHidden.JSONSchemaValidator.formatError = function(key, opt_replacements) { +chrome.JSONSchemaValidator.formatError = function(key, opt_replacements) { var message = this.messages[key]; if (opt_replacements) { for (var i = 0; i < opt_replacements.length; i++) { @@ -99,7 +97,7 @@ chromeHidden.JSONSchemaValidator.formatError = function(key, opt_replacements) { * don't explicitly disallow 'function', because we want to allow functions in * the input values. */ -chromeHidden.JSONSchemaValidator.getType = function(value) { +chrome.JSONSchemaValidator.getType = function(value) { var s = typeof value; if (s == "object") { @@ -123,7 +121,7 @@ chromeHidden.JSONSchemaValidator.getType = function(value) { * with "$ref": . Each type must be a valid schema and define an * "id" property. */ -chromeHidden.JSONSchemaValidator.prototype.addTypes = function(typeOrTypeList) { +chrome.JSONSchemaValidator.prototype.addTypes = function(typeOrTypeList) { function addType(validator, type) { if(!type.id) throw "Attempt to addType with missing 'id' property"; @@ -144,8 +142,8 @@ chromeHidden.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. */ -chromeHidden.JSONSchemaValidator.prototype.validate = function( - instance, schema, opt_path) { +chrome.JSONSchemaValidator.prototype.validate = function(instance, schema, + opt_path) { var path = opt_path || ""; if (!schema) { @@ -212,8 +210,9 @@ chromeHidden.JSONSchemaValidator.prototype.validate = function( * Validates an instance against a choices schema. The instance must match at * least one of the provided choices. */ -chromeHidden.JSONSchemaValidator.prototype.validateChoices = function( - instance, schema, path) { +chrome.JSONSchemaValidator.prototype.validateChoices = function(instance, + schema, + path) { var originalErrors = this.errors; for (var i = 0; i < schema.choices.length; i++) { @@ -234,8 +233,8 @@ chromeHidden.JSONSchemaValidator.prototype.validateChoices = function( * |errors| property, and returns a boolean indicating whether the instance * validates. */ -chromeHidden.JSONSchemaValidator.prototype.validateEnum = function( - instance, schema, path) { +chrome.JSONSchemaValidator.prototype.validateEnum = function(instance, schema, + path) { for (var i = 0; i < schema.enum.length; i++) { if (instance === schema.enum[i]) return true; @@ -249,8 +248,8 @@ chromeHidden.JSONSchemaValidator.prototype.validateEnum = function( * Validates an instance against an object schema and populates the errors * property. */ -chromeHidden.JSONSchemaValidator.prototype.validateObject = function( - instance, schema, path) { +chrome.JSONSchemaValidator.prototype.validateObject = function(instance, + schema, path) { for (var prop in schema.properties) { var propPath = path ? path + "." + prop : prop; if (schema.properties[prop] == undefined) { @@ -282,9 +281,9 @@ chromeHidden.JSONSchemaValidator.prototype.validateObject = function( * Validates an instance against an array schema and populates the errors * property. */ -chromeHidden.JSONSchemaValidator.prototype.validateArray = function( - instance, schema, path) { - var typeOfItems = chromeHidden.JSONSchemaValidator.getType(schema.items); +chrome.JSONSchemaValidator.prototype.validateArray = function(instance, + schema, path) { + var typeOfItems = chrome.JSONSchemaValidator.getType(schema.items); if (typeOfItems == 'object') { if (schema.minItems && instance.length < schema.minItems) { @@ -329,8 +328,8 @@ chromeHidden.JSONSchemaValidator.prototype.validateArray = function( /** * Validates a string and populates the errors property. */ -chromeHidden.JSONSchemaValidator.prototype.validateString = function( - instance, schema, path) { +chrome.JSONSchemaValidator.prototype.validateString = function(instance, + schema, path) { if (schema.minLength && instance.length < schema.minLength) this.addError(path, "stringMinLength", [schema.minLength]); @@ -345,8 +344,8 @@ chromeHidden.JSONSchemaValidator.prototype.validateString = function( * Validates a number and populates the errors property. The instance is * assumed to be a number. */ -chromeHidden.JSONSchemaValidator.prototype.validateNumber = function( - instance, schema, path) { +chrome.JSONSchemaValidator.prototype.validateNumber = function(instance, + schema, path) { if (schema.minimum && instance < schema.minimum) this.addError(path, "numberMinValue", [schema.minimum]); @@ -361,9 +360,9 @@ chromeHidden.JSONSchemaValidator.prototype.validateNumber = function( * Validates the primitive type of an instance and populates the errors * property. Returns true if the instance validates, false otherwise. */ -chromeHidden.JSONSchemaValidator.prototype.validateType = function( - instance, schema, path) { - var actualType = chromeHidden.JSONSchemaValidator.getType(instance); +chrome.JSONSchemaValidator.prototype.validateType = function(instance, schema, + path) { + var actualType = chrome.JSONSchemaValidator.getType(instance); if (schema.type != actualType && !(schema.type == "number" && actualType == "integer")) { this.addError(path, "invalidType", [schema.type, actualType]); @@ -378,12 +377,10 @@ chromeHidden.JSONSchemaValidator.prototype.validateType = function( * |replacements| is an array of values to replace '*' characters in the * message. */ -chromeHidden.JSONSchemaValidator.prototype.addError = function( - path, key, replacements) { +chrome.JSONSchemaValidator.prototype.addError = function(path, key, + replacements) { this.errors.push({ path: path, - message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) + message: chrome.JSONSchemaValidator.formatError(key, replacements) }); }; - -})(); -- cgit v1.1