diff options
46 files changed, 427 insertions, 152 deletions
diff --git a/chrome/common/extensions/api/browserAction.json b/chrome/common/extensions/api/browserAction.json index 6288fab..b21cc99 100644 --- a/chrome/common/extensions/api/browserAction.json +++ b/chrome/common/extensions/api/browserAction.json @@ -263,7 +263,7 @@ "parameters": [ { "name": "tab", - "$ref": "Tab" + "$ref": "tabs.Tab" } ] } diff --git a/chrome/common/extensions/api/contextMenus.json b/chrome/common/extensions/api/contextMenus.json index efebc34..17c6f27 100644 --- a/chrome/common/extensions/api/contextMenus.json +++ b/chrome/common/extensions/api/contextMenus.json @@ -109,7 +109,7 @@ }, { "name": "tab", - "$ref": "Tab", + "$ref": "tabs.Tab", "description": "The details of the tab where the click took place." } ] diff --git a/chrome/common/extensions/api/declarativeWebRequest.json b/chrome/common/extensions/api/declarativeWebRequest.json index 5b65657..c3d19dd 100644 --- a/chrome/common/extensions/api/declarativeWebRequest.json +++ b/chrome/common/extensions/api/declarativeWebRequest.json @@ -13,7 +13,7 @@ "description": "Matches network events by various criteria.", "properties": { "url": { - "$ref": "UrlFilter", + "$ref": "declarative.UrlFilter", "description": "Matches if the condition of the UrlFilter are fulfilled for the URL of the request.", "optional": true }, @@ -52,8 +52,11 @@ "options": { "supportsListeners": false, "supportsRules": true, - "conditions": ["RequestMatcher"], - "actions": ["CancelRequest", "RedirectRequest"] + "conditions": ["declarativeWebRequest.RequestMatcher"], + "actions": [ + "declarativeWebRequest.CancelRequest", + "declarativeWebRequest.RedirectRequest" + ] } } ] diff --git a/chrome/common/extensions/api/devtools_api.json b/chrome/common/extensions/api/devtools_api.json index 4d21eed..f10e0c8 100644 --- a/chrome/common/extensions/api/devtools_api.json +++ b/chrome/common/extensions/api/devtools_api.json @@ -490,7 +490,7 @@ "description": "A function that is called when the user clicks on a valid resource link in Developer Tools window. Note that if the user clicks an invalid URL or an XHR, this function is not called.", "parameters": [ { - "name": "Resource", + "name": "devtools.inspectedWindow.Resource", "type": "object", "description": "A <a href=\"devtools.inspectedWindow.html#type-Resource\">Resource</a> object for the resource that was clicked." } diff --git a/chrome/common/extensions/api/experimental.bookmarkManager.json b/chrome/common/extensions/api/experimental.bookmarkManager.json index 9d130c8..4ad1415 100644 --- a/chrome/common/extensions/api/experimental.bookmarkManager.json +++ b/chrome/common/extensions/api/experimental.bookmarkManager.json @@ -194,7 +194,7 @@ "name": "callback", "type": "function", "parameters": [ - {"name": "results", "type": "array", "items": { "$ref": "BookmarkTreeNode"} } + {"name": "results", "type": "array", "items": { "$ref": "bookmarks.BookmarkTreeNode"} } ] } ] diff --git a/chrome/common/extensions/api/experimental.infobars.json b/chrome/common/extensions/api/experimental.infobars.json index f7d797d..c8e161e 100644 --- a/chrome/common/extensions/api/experimental.infobars.json +++ b/chrome/common/extensions/api/experimental.infobars.json @@ -40,7 +40,7 @@ "optional": true, "parameters": [ { - "name": "window", "$ref": "Window", "description": "Contains details about the window in which the infobar was created." + "name": "window", "$ref": "windows.Window", "description": "Contains details about the window in which the infobar was created." } ] } diff --git a/chrome/common/extensions/api/extension.json b/chrome/common/extensions/api/extension.json index 59f497c..1e735ad 100644 --- a/chrome/common/extensions/api/extension.json +++ b/chrome/common/extensions/api/extension.json @@ -13,7 +13,7 @@ "type": "object", "description": "An object containing information about the script context that sent a message or request.", "properties": { - "tab": {"$ref": "Tab", "optional": true, "description":"This property will <b>only</b> be present when the connection was opened from a tab or content script."}, + "tab": {"$ref": "tabs.Tab", "optional": true, "description":"This property will <b>only</b> be present when the connection was opened from a tab or content script."}, "id": {"type": "string", "description": "The extension ID of the extension that opened the connection."} } }, diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc index 5c2ba8b..d315a64 100644 --- a/chrome/common/extensions/api/extension_api.cc +++ b/chrome/common/extensions/api/extension_api.cc @@ -125,6 +125,69 @@ struct Static { base::LazyInstance<Static> g_lazy_instance = LAZY_INSTANCE_INITIALIZER; +// If it exists and does not already specify a namespace, then the value stored +// with key |key| in |schema| will be updated to |schema_namespace| + "." + +// |schema[key]|. +void MaybePrefixFieldWithNamespace(const std::string& schema_namespace, + DictionaryValue* schema, + const std::string& key) { + if (!schema->HasKey(key)) + return; + + std::string old_id; + CHECK(schema->GetString(key, &old_id)); + if (old_id.find(".") == std::string::npos) + schema->SetString(key, schema_namespace + "." + old_id); +} + +// Modify all "$ref" keys anywhere in |schema| to be prefxied by +// |schema_namespace| if they do not already specify a namespace. +void PrefixRefsWithNamespace(const std::string& schema_namespace, + Value* value) { + if (value->IsType(Value::TYPE_LIST)) { + ListValue* list; + CHECK(value->GetAsList(&list)); + for (ListValue::iterator i = list->begin(); i != list->end(); ++i) { + PrefixRefsWithNamespace(schema_namespace, *i); + } + } else if (value->IsType(Value::TYPE_DICTIONARY)) { + DictionaryValue* dict; + CHECK(value->GetAsDictionary(&dict)); + MaybePrefixFieldWithNamespace(schema_namespace, dict, "$ref"); + for (DictionaryValue::key_iterator i = dict->begin_keys(); + i != dict->end_keys(); ++i) { + Value* next_value; + CHECK(dict->GetWithoutPathExpansion(*i, &next_value)); + PrefixRefsWithNamespace(schema_namespace, next_value); + } + } +} + +// Modify all objects in the "types" section of the schema to be prefixed by +// |schema_namespace| if they do not already specify a namespace. +void PrefixTypesWithNamespace(const std::string& schema_namespace, + DictionaryValue* schema) { + if (!schema->HasKey("types")) + return; + + // Add the namespace to all of the types defined in this schema + ListValue *types; + CHECK(schema->GetList("types", &types)); + for (size_t i = 0; i < types->GetSize(); ++i) { + DictionaryValue *type; + CHECK(types->GetDictionary(i, &type)); + MaybePrefixFieldWithNamespace(schema_namespace, type, "id"); + MaybePrefixFieldWithNamespace(schema_namespace, type, "customBindings"); + } +} + +// Modify the schema so that all types are fully qualified. +void PrefixWithNamespace(const std::string& schema_namespace, + DictionaryValue* schema) { + PrefixTypesWithNamespace(schema_namespace, schema); + PrefixRefsWithNamespace(schema_namespace, schema); +} + } // namespace // static @@ -161,15 +224,16 @@ void ExtensionAPI::LoadSchema(const std::string& name, std::string schema_namespace; while (!schema_list->empty()) { - const DictionaryValue* schema = NULL; + DictionaryValue* schema = NULL; { Value* value = NULL; schema_list->Remove(schema_list->GetSize() - 1, &value); CHECK(value->IsType(Value::TYPE_DICTIONARY)); - schema = static_cast<const DictionaryValue*>(value); + schema = static_cast<DictionaryValue*>(value); } CHECK(schema->GetString("namespace", &schema_namespace)); + PrefixWithNamespace(schema_namespace, schema); schemas_[schema_namespace] = make_linked_ptr(schema); CHECK_EQ(1u, unloaded_schemas_.erase(schema_namespace)); diff --git a/chrome/common/extensions/api/extension_api_unittest.cc b/chrome/common/extensions/api/extension_api_unittest.cc index e25adb0..a0a94e5 100644 --- a/chrome/common/extensions/api/extension_api_unittest.cc +++ b/chrome/common/extensions/api/extension_api_unittest.cc @@ -416,5 +416,74 @@ TEST(ExtensionAPI, FeaturesRequireContexts) { } } +static void GetDictionaryFromList(const DictionaryValue* schema, + const std::string& list_name, + const int list_index, + DictionaryValue** out) { + ListValue* list; + EXPECT_TRUE(schema->GetList(list_name, &list)); + EXPECT_TRUE(list->GetDictionary(list_index, out)); +} + +TEST(ExtensionAPI, TypesHaveNamespace) { + FilePath manifest_path; + PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); + manifest_path = manifest_path.AppendASCII("extensions") + .AppendASCII("extension_api_unittest") + .AppendASCII("types_have_namespace.json"); + + std::string manifest_str; + ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) + << "Failed to load: " << manifest_path.value(); + + ExtensionAPI api; + api.RegisterSchema("test.foo", manifest_str); + api.LoadAllSchemas(); + + const DictionaryValue* schema = api.GetSchema("test.foo"); + + DictionaryValue* dict; + DictionaryValue* sub_dict; + std::string type; + + GetDictionaryFromList(schema, "types", 0, &dict); + EXPECT_TRUE(dict->GetString("id", &type)); + EXPECT_EQ("test.foo.TestType", type); + EXPECT_TRUE(dict->GetString("customBindings", &type)); + EXPECT_EQ("test.foo.TestType", type); + EXPECT_TRUE(dict->GetDictionary("properties", &sub_dict)); + DictionaryValue* property; + EXPECT_TRUE(sub_dict->GetDictionary("foo", &property)); + EXPECT_TRUE(property->GetString("$ref", &type)); + EXPECT_EQ("test.foo.OtherType", type); + EXPECT_TRUE(sub_dict->GetDictionary("bar", &property)); + EXPECT_TRUE(property->GetString("$ref", &type)); + EXPECT_EQ("fully.qualified.Type", type); + + GetDictionaryFromList(schema, "functions", 0, &dict); + GetDictionaryFromList(dict, "parameters", 0, &sub_dict); + EXPECT_TRUE(sub_dict->GetString("$ref", &type)); + EXPECT_EQ("test.foo.TestType", type); + EXPECT_TRUE(dict->GetDictionary("returns", &sub_dict)); + EXPECT_TRUE(sub_dict->GetString("$ref", &type)); + EXPECT_EQ("fully.qualified.Type", type); + + GetDictionaryFromList(schema, "functions", 1, &dict); + GetDictionaryFromList(dict, "parameters", 0, &sub_dict); + EXPECT_TRUE(sub_dict->GetString("$ref", &type)); + EXPECT_EQ("fully.qualified.Type", type); + EXPECT_TRUE(dict->GetDictionary("returns", &sub_dict)); + EXPECT_TRUE(sub_dict->GetString("$ref", &type)); + EXPECT_EQ("test.foo.TestType", type); + + GetDictionaryFromList(schema, "events", 0, &dict); + GetDictionaryFromList(dict, "parameters", 0, &sub_dict); + EXPECT_TRUE(sub_dict->GetString("$ref", &type)); + EXPECT_EQ("test.foo.TestType", type); + GetDictionaryFromList(dict, "parameters", 1, &sub_dict); + EXPECT_TRUE(sub_dict->GetString("$ref", &type)); + EXPECT_EQ("fully.qualified.Type", type); +} + } // namespace } // namespace extensions diff --git a/chrome/common/extensions/api/pageAction.json b/chrome/common/extensions/api/pageAction.json index c25a540..5f0031a 100644 --- a/chrome/common/extensions/api/pageAction.json +++ b/chrome/common/extensions/api/pageAction.json @@ -152,7 +152,7 @@ "parameters": [ { "name": "tab", - "$ref": "Tab" + "$ref": "tabs.Tab" } ] } diff --git a/chrome/common/extensions/api/privacy.json b/chrome/common/extensions/api/privacy.json index c3e144b..721ec0c 100644 --- a/chrome/common/extensions/api/privacy.json +++ b/chrome/common/extensions/api/privacy.json @@ -13,7 +13,7 @@ "description": "Settings that influence Chrome's handling of network connections in general.", "properties": { "networkPredictionEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["networkPredictionEnabled", {"type":"boolean"}], "description": "If enabled, Chrome attempts to speed up your web browsing experience by pre-resolving DNS entries, prerendering sites (<code><link rel='prefetch' ...></code>), and preemptively opening TCP and SSL connections to servers. This preference's value is a boolean, defaulting to <code>true</code>." } @@ -25,37 +25,37 @@ "description": "Settings that enable or disable features that require third-party network services provided by Google and your default search provider.", "properties": { "alternateErrorPagesEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["alternateErrorPagesEnabled", {"type":"boolean"}], "description": "If enabled, Chrome uses a web service to help resolve navigation errors. This preference's value is a boolean, defaulting to <code>true</code>." }, "autofillEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["autofillEnabled", {"type":"boolean"}], "description": "If enabled, Chrome offers to automatically fill in forms. This preference's value is a boolean, defaulting to <code>true</code>." }, "instantEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["instantEnabled", {"type":"boolean"}], "description": "If enabled, Chrome automatically performs and displays search requests for text you type into the Omnibox as you type it. This preference's value is a boolean, defaulting to <code>true</code>." }, "safeBrowsingEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["safeBrowsingEnabled", {"type":"boolean"}], "description": "If enabled, Chrome does its best to protect you from phishing and malware. This preference's value is a boolean, defaulting to <code>true</code>." }, "searchSuggestEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["searchSuggestEnabled", {"type":"boolean"}], "description": "If enabled, Chrome sends the text you type into the Omnibox to your default search engine, which provides predictions of websites and searches that are likely completions of what you've typed so far. This preference's value is a boolean, defaulting to <code>true</code>." }, "spellingServiceEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["spellingServiceEnabled", {"type":"boolean"}], "description": "If enabled, Chrome uses a web service to help correct spelling errors. This preference's value is a boolean, defaulting to <code>false</code>." }, "translationServiceEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["translationServiceEnabled", {"type":"boolean"}], "description": "If enabled, Chrome offers to translate pages that aren't in a language you read. This preference's value is a boolean, defaulting to <code>true</code>." } @@ -67,17 +67,17 @@ "description": "Settings that determine what information Chrome makes available to websites.", "properties": { "thirdPartyCookiesAllowed": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["thirdPartyCookiesAllowed", {"type": "boolean"}], "description": "If disabled, Chrome blocks third-party sites from setting cookies. The value of this preference is of type boolean, and the default value is <code>true</code>." }, "hyperlinkAuditingEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["hyperlinkAuditingEnabled", {"type":"boolean"}], "description": "If enabled, Chrome sends auditing pings when requested by a website (<code><a ping></code>). The value of this preference is of type boolean, and the default value is <code>true</code>." }, "referrersEnabled": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "value": ["referrersEnabled", {"type":"boolean"}], "description": "If enabled, Chrome sends <code>referer</code> headers with your requests. Yes, the name of this preference doesn't match the misspelled header. No, we're not going to change it. The value of this preference is of type boolean, and the default value is <code>true</code>." }, diff --git a/chrome/common/extensions/api/proxy.json b/chrome/common/extensions/api/proxy.json index ef8d38a..eeb957a 100644 --- a/chrome/common/extensions/api/proxy.json +++ b/chrome/common/extensions/api/proxy.json @@ -57,7 +57,7 @@ ], "properties": { "settings": { - "$ref": "ChromeSetting", + "$ref": "types.ChromeSetting", "description": "Proxy settings to be used. The value of this setting is a ProxyConfig object.", "value": [ "proxy", diff --git a/chrome/common/extensions/api/tabs.json b/chrome/common/extensions/api/tabs.json index 9d7282d..69a63c7 100644 --- a/chrome/common/extensions/api/tabs.json +++ b/chrome/common/extensions/api/tabs.json @@ -86,7 +86,7 @@ } ], "returns": { - "$ref": "Port", + "$ref": "extension.Port", "description": "A port that can be used to communicate with the content scripts running in the specified tab. The port's <a href='extension.html#type-Port'>onDisconnect</a> event is fired if the tab closes or does not exist. " } }, @@ -372,7 +372,7 @@ "parameters": [ { "name": "window", - "$ref": "Window", + "$ref": "windows.Window", "description": "Contains details about the window whose tabs were highlighted." } ] diff --git a/chrome/common/extensions/api/ttsEngine.json b/chrome/common/extensions/api/ttsEngine.json index 0fbabb9..6279ccc 100644 --- a/chrome/common/extensions/api/ttsEngine.json +++ b/chrome/common/extensions/api/ttsEngine.json @@ -19,7 +19,7 @@ }, { "name": "event", - "$ref": "TtsEvent", + "$ref": "tts.TtsEvent", "description": "The update event from the text-to-speech engine indicating the status of this utterance." } ] @@ -87,7 +87,7 @@ "parameters": [ { "name": "event", - "$ref": "TtsEvent", + "$ref": "tts.TtsEvent", "description": "The event from the text-to-speech engine indicating the status of this utterance." } ] diff --git a/chrome/common/extensions/api/windows.json b/chrome/common/extensions/api/windows.json index 80fe9cf..58b6cf2 100644 --- a/chrome/common/extensions/api/windows.json +++ b/chrome/common/extensions/api/windows.json @@ -17,7 +17,7 @@ "left": {"type": "integer", "description": "The offset of the window from the left edge of the screen in pixels."}, "width": {"type": "integer", "description": "The width of the window in pixels."}, "height": {"type": "integer", "description": "The height of the window in pixels."}, - "tabs": {"type": "array", "items": { "$ref": "Tab" }, "optional": true, "description": "Array of $ref:Tab objects representing the current tabs in the window."}, + "tabs": {"type": "array", "items": { "$ref": "tabs.Tab" }, "optional": true, "description": "Array of $ref:tabs.Tab objects representing the current tabs in the window."}, "incognito": {"type": "boolean", "description": "Whether the window is incognito."}, "type": { "type": "string", @@ -56,7 +56,7 @@ "optional": true, "description": "", "properties": { - "populate": {"type": "boolean", "optional": true, "description": "If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:Tab objects" } + "populate": {"type": "boolean", "optional": true, "description": "If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects" } } }, { @@ -81,7 +81,7 @@ "optional": true, "description": "", "properties": { - "populate": {"type": "boolean", "optional": true, "description": "If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:Tab objects" } + "populate": {"type": "boolean", "optional": true, "description": "If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects" } } }, { @@ -106,7 +106,7 @@ "optional": true, "description": "", "properties": { - "populate": {"type": "boolean", "optional": true, "description": "If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:Tab objects" } + "populate": {"type": "boolean", "optional": true, "description": "If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects" } } }, { @@ -131,7 +131,7 @@ "optional": true, "description": "", "properties": { - "populate": {"type": "boolean", "optional": true, "description": "If true, each window object will have a <var>tabs</var> property that contains a list of the $ref:Tab objects for that window." } + "populate": {"type": "boolean", "optional": true, "description": "If true, each window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects for that window." } } }, { diff --git a/chrome/common/extensions/docs/browserAction.html b/chrome/common/extensions/docs/browserAction.html index 7a2c5b1..341ef27 100644 --- a/chrome/common/extensions/docs/browserAction.html +++ b/chrome/common/extensions/docs/browserAction.html @@ -1502,7 +1502,7 @@ For other examples and for help in viewing the source code, see <h4>onClicked</h4> <div class="summary"> <!-- Note: intentionally longer 80 columns --> - <span class="subdued">chrome.browserAction.</span><span>onClicked</span><span class="subdued">.addListener</span>(function(<span>Tab tab</span>) <span class="subdued">{...}</span><span></span>); + <span class="subdued">chrome.browserAction.</span><span>onClicked</span><span class="subdued">.addListener</span>(function(<span>tabs.Tab tab</span>) <span class="subdued">{...}</span><span></span>); </div> <div class="description"> <p>Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.</p> @@ -1520,7 +1520,7 @@ For other examples and for help in viewing the source code, see ( <span id="typeTemplate"> <span> - <a href="tabs.html#type-Tab">Tab</a> + <a>tabs.Tab</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/contextMenus.html b/chrome/common/extensions/docs/contextMenus.html index 50825e5..6f146c5 100644 --- a/chrome/common/extensions/docs/contextMenus.html +++ b/chrome/common/extensions/docs/contextMenus.html @@ -504,7 +504,7 @@ You can find samples of this API on the ( <span id="typeTemplate"> <span> - <a href="tabs.html#type-Tab">Tab</a> + <a>tabs.Tab</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/declarativeWebRequest.html b/chrome/common/extensions/docs/declarativeWebRequest.html index f39906d..dbf8450 100644 --- a/chrome/common/extensions/docs/declarativeWebRequest.html +++ b/chrome/common/extensions/docs/declarativeWebRequest.html @@ -462,7 +462,7 @@ very fast URL matching algorithm for hundreds of thousands of URLs. <span class="optional">optional</span> <span id="typeTemplate"> <span> - <a href="declarative.html#type-UrlFilter">UrlFilter</a> + <a>experimental.declarative.UrlFilter</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/devtools.panels.html b/chrome/common/extensions/docs/devtools.panels.html index 94593a0..7acbe14f 100644 --- a/chrome/common/extensions/docs/devtools.panels.html +++ b/chrome/common/extensions/docs/devtools.panels.html @@ -629,12 +629,12 @@ You can find examples that use this API in specify a function that looks like this: </p> <!-- Note: intentionally longer 80 columns --> - <pre>function(<span>object Resource</span>) <span class="subdued">{...}</span>;</pre> + <pre>function(<span>object devtools.inspectedWindow.Resource</span>) <span class="subdued">{...}</span>;</pre> <dl> <div> <div> <dt> - <var>Resource</var> + <var>devtools.inspectedWindow.Resource</var> <em> <!-- TYPE --> <div style="display:inline"> diff --git a/chrome/common/extensions/docs/experimental.alarms.html b/chrome/common/extensions/docs/experimental.alarms.html index b020cd1..994bee2 100644 --- a/chrome/common/extensions/docs/experimental.alarms.html +++ b/chrome/common/extensions/docs/experimental.alarms.html @@ -222,11 +222,11 @@ <a href="#types">Types</a> <ol> <li> - <a href="#type-Alarm">Alarm</a> + <a href="#type-experimental.alarms.Alarm">experimental.alarms.Alarm</a> <ol> </ol> </li><li> - <a href="#type-AlarmCreateInfo">AlarmCreateInfo</a> + <a href="#type-experimental.alarms.AlarmCreateInfo">experimental.alarms.AlarmCreateInfo</a> <ol> </ol> </li> @@ -321,7 +321,7 @@ <div class="summary"> <!-- Note: intentionally longer 80 columns --> <span>chrome.experimental.alarms.create</span>(<span class="optional"><span>string</span> - <var><span>name</span></var></span><span class="null"><span>, </span><span>AlarmCreateInfo</span> + <var><span>name</span></var></span><span class="null"><span>, </span><span>experimental.alarms.AlarmCreateInfo</span> <var><span>alarmInfo</span></var></span>)</div> <div class="description"> <p>Creates an alarm. After the delay is elapsed, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm. string.</p> @@ -362,7 +362,7 @@ ( <span id="typeTemplate"> <span> - <a href="experimental.alarms.html#type-AlarmCreateInfo">AlarmCreateInfo</a> + <a href="experimental.alarms.html#type-experimental.alarms.AlarmCreateInfo">experimental.alarms.AlarmCreateInfo</a> </span> </span> ) @@ -460,7 +460,7 @@ ( <span id="typeTemplate"> <span> - <a href="experimental.alarms.html#type-Alarm">Alarm</a> + <a href="experimental.alarms.html#type-experimental.alarms.Alarm">experimental.alarms.Alarm</a> </span> </span> ) @@ -494,7 +494,7 @@ that looks like this: </p> <!-- Note: intentionally longer 80 columns --> - <pre>function(<span>Alarm alarm</span>) <span class="subdued">{...}</span>;</pre> + <pre>function(<span>experimental.alarms.Alarm alarm</span>) <span class="subdued">{...}</span>;</pre> <dl> <div> <div> @@ -506,7 +506,7 @@ ( <span id="typeTemplate"> <span> - <a href="experimental.alarms.html#type-Alarm">Alarm</a> + <a href="experimental.alarms.html#type-experimental.alarms.Alarm">experimental.alarms.Alarm</a> </span> </span> ) @@ -580,7 +580,7 @@ <span> array of <span><span> <span> - <a href="experimental.alarms.html#type-Alarm">Alarm</a> + <a href="experimental.alarms.html#type-experimental.alarms.Alarm">experimental.alarms.Alarm</a> </span> </span></span> </span> @@ -617,7 +617,7 @@ that looks like this: </p> <!-- Note: intentionally longer 80 columns --> - <pre>function(<span>array of Alarm alarms</span>) <span class="subdued">{...}</span>;</pre> + <pre>function(<span>array of experimental.alarms.Alarm alarms</span>) <span class="subdued">{...}</span>;</pre> <dl> <div> <div> @@ -632,7 +632,7 @@ <span> array of <span><span> <span> - <a href="experimental.alarms.html#type-Alarm">Alarm</a> + <a href="experimental.alarms.html#type-experimental.alarms.Alarm">experimental.alarms.Alarm</a> </span> </span></span> </span> @@ -668,7 +668,7 @@ <h4>onAlarm</h4> <div class="summary"> <!-- Note: intentionally longer 80 columns --> - <span class="subdued">chrome.experimental.alarms.</span><span>onAlarm</span><span class="subdued">.addListener</span>(function(<span>Alarm alarm</span>) <span class="subdued">{...}</span><span></span>); + <span class="subdued">chrome.experimental.alarms.</span><span>onAlarm</span><span class="subdued">.addListener</span>(function(<span>experimental.alarms.Alarm alarm</span>) <span class="subdued">{...}</span><span></span>); </div> <div class="description"> <p>Fired when an alarm has elapsed. Useful for transient background pages.</p> @@ -686,7 +686,7 @@ ( <span id="typeTemplate"> <span> - <a href="experimental.alarms.html#type-Alarm">Alarm</a> + <a href="experimental.alarms.html#type-experimental.alarms.Alarm">experimental.alarms.Alarm</a> </span> </span> ) @@ -715,8 +715,8 @@ <h3 id="types">Types</h3> <!-- iterates over all types --> <div class="apiItem"> - <a name="type-Alarm"></a> - <h4>Alarm</h4> + <a name="type-experimental.alarms.Alarm"></a> + <h4>experimental.alarms.Alarm</h4> <div> <dt> <em> @@ -815,8 +815,8 @@ <!-- FUNCTION PARAMETERS --> </div> </div><div class="apiItem"> - <a name="type-AlarmCreateInfo"></a> - <h4>AlarmCreateInfo</h4> + <a name="type-experimental.alarms.AlarmCreateInfo"></a> + <h4>experimental.alarms.AlarmCreateInfo</h4> <div> <dt> <em> diff --git a/chrome/common/extensions/docs/experimental.infobars.html b/chrome/common/extensions/docs/experimental.infobars.html index a7bb557..467440a 100644 --- a/chrome/common/extensions/docs/experimental.infobars.html +++ b/chrome/common/extensions/docs/experimental.infobars.html @@ -423,7 +423,7 @@ For example: specify a function that looks like this: </p> <!-- Note: intentionally longer 80 columns --> - <pre>function(<span>Window window</span>) <span class="subdued">{...}</span>;</pre> + <pre>function(<span>windows.Window window</span>) <span class="subdued">{...}</span>;</pre> <dl> <div> <div> @@ -435,7 +435,7 @@ For example: ( <span id="typeTemplate"> <span> - <a href="windows.html#type-Window">Window</a> + <a>windows.Window</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/extension.html b/chrome/common/extensions/docs/extension.html index fbcad44..4c19a17 100644 --- a/chrome/common/extensions/docs/extension.html +++ b/chrome/common/extensions/docs/extension.html @@ -1605,7 +1605,7 @@ For details, see <span class="optional">optional</span> <span id="typeTemplate"> <span> - <a href="tabs.html#type-Tab">Tab</a> + <a>tabs.Tab</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/pageAction.html b/chrome/common/extensions/docs/pageAction.html index 4bd5254..19ecd8f 100644 --- a/chrome/common/extensions/docs/pageAction.html +++ b/chrome/common/extensions/docs/pageAction.html @@ -1060,7 +1060,7 @@ For other examples and for help in viewing the source code, see <h4>onClicked</h4> <div class="summary"> <!-- Note: intentionally longer 80 columns --> - <span class="subdued">chrome.pageAction.</span><span>onClicked</span><span class="subdued">.addListener</span>(function(<span>Tab tab</span>) <span class="subdued">{...}</span><span></span>); + <span class="subdued">chrome.pageAction.</span><span>onClicked</span><span class="subdued">.addListener</span>(function(<span>tabs.Tab tab</span>) <span class="subdued">{...}</span><span></span>); </div> <div class="description"> <p>Fired when a page action icon is clicked. This event will not fire if the page action has a popup.</p> @@ -1078,7 +1078,7 @@ For other examples and for help in viewing the source code, see ( <span id="typeTemplate"> <span> - <a href="tabs.html#type-Tab">Tab</a> + <a>tabs.Tab</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/privacy.html b/chrome/common/extensions/docs/privacy.html index ccb5867..d5f83fc 100644 --- a/chrome/common/extensions/docs/privacy.html +++ b/chrome/common/extensions/docs/privacy.html @@ -469,7 +469,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -526,7 +526,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -549,7 +549,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -572,7 +572,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -595,7 +595,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -618,7 +618,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -641,7 +641,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -664,7 +664,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -721,7 +721,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -744,7 +744,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) @@ -767,7 +767,7 @@ ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/proxy.html b/chrome/common/extensions/docs/proxy.html index 5eba638..01ae0f0 100644 --- a/chrome/common/extensions/docs/proxy.html +++ b/chrome/common/extensions/docs/proxy.html @@ -468,7 +468,7 @@ identical to the <code>value</code> object passed to callback function of ( <span id="typeTemplate"> <span> - <a href="types.html#type-ChromeSetting">ChromeSetting</a> + <a>types.ChromeSetting</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/tabs.html b/chrome/common/extensions/docs/tabs.html index bca8cec..134d542 100644 --- a/chrome/common/extensions/docs/tabs.html +++ b/chrome/common/extensions/docs/tabs.html @@ -520,7 +520,7 @@ For other examples and for help in viewing the source code, see </div><div class="apiItem"> <a name="method-connect"></a> <!-- method-anchor --> <h4>connect</h4> - <div class="summary"><span>Port</span> + <div class="summary"><span>extension.Port</span> <!-- Note: intentionally longer 80 columns --> <span>chrome.tabs.connect</span>(<span class="null"><span>integer</span> <var><span>tabId</span></var></span><span class="optional"><span>, </span><span>object</span> @@ -624,7 +624,7 @@ For other examples and for help in viewing the source code, see ( <span id="typeTemplate"> <span> - <a href="extension.html#type-Port">Port</a> + <a>extension.Port</a> </span> </span> ) @@ -1540,7 +1540,7 @@ For other examples and for help in viewing the source code, see that looks like this: </p> <!-- Note: intentionally longer 80 columns --> - <pre>function(<span>Window window</span>) <span class="subdued">{...}</span>;</pre> + <pre>function(<span>windows.Window window</span>) <span class="subdued">{...}</span>;</pre> <dl> <div> <div> @@ -1552,7 +1552,7 @@ For other examples and for help in viewing the source code, see ( <span id="typeTemplate"> <span> - <a href="windows.html#type-Window">Window</a> + <a>windows.Window</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/ttsEngine.html b/chrome/common/extensions/docs/ttsEngine.html index 95ed74c..dc81ae5 100644 --- a/chrome/common/extensions/docs/ttsEngine.html +++ b/chrome/common/extensions/docs/ttsEngine.html @@ -611,7 +611,7 @@ dynamically decide whether to handle it.</p> ( <span id="typeTemplate"> <span> - <a href="tts.html#type-TtsEvent">TtsEvent</a> + <a>tts.TtsEvent</a> </span> </span> ) diff --git a/chrome/common/extensions/docs/windows.html b/chrome/common/extensions/docs/windows.html index 48ce56c..56b9a65 100644 --- a/chrome/common/extensions/docs/windows.html +++ b/chrome/common/extensions/docs/windows.html @@ -812,7 +812,7 @@ For other examples and for help in viewing the source code, see </div> </em> </dt> - <dd>If true, the window object will have a <var>tabs</var> property that contains a list of the <a href="tabs.html#type-Tab">Tab</a> objects</dd> + <dd>If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects</dd> <!-- OBJECT PROPERTIES --> <!-- OBJECT METHODS --> <!-- OBJECT EVENT FIELDS --> @@ -952,7 +952,7 @@ For other examples and for help in viewing the source code, see </div> </em> </dt> - <dd>If true, each window object will have a <var>tabs</var> property that contains a list of the <a href="tabs.html#type-Tab">Tab</a> objects for that window.</dd> + <dd>If true, each window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects for that window.</dd> <!-- OBJECT PROPERTIES --> <!-- OBJECT METHODS --> <!-- OBJECT EVENT FIELDS --> @@ -1098,7 +1098,7 @@ For other examples and for help in viewing the source code, see </div> </em> </dt> - <dd>If true, the window object will have a <var>tabs</var> property that contains a list of the <a href="tabs.html#type-Tab">Tab</a> objects</dd> + <dd>If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects</dd> <!-- OBJECT PROPERTIES --> <!-- OBJECT METHODS --> <!-- OBJECT EVENT FIELDS --> @@ -1238,7 +1238,7 @@ For other examples and for help in viewing the source code, see </div> </em> </dt> - <dd>If true, the window object will have a <var>tabs</var> property that contains a list of the <a href="tabs.html#type-Tab">Tab</a> objects</dd> + <dd>If true, the window object will have a <var>tabs</var> property that contains a list of the $ref:tabs.Tab objects</dd> <!-- OBJECT PROPERTIES --> <!-- OBJECT METHODS --> <!-- OBJECT EVENT FIELDS --> @@ -2045,7 +2045,7 @@ For other examples and for help in viewing the source code, see <span> array of <span><span> <span> - <a href="tabs.html#type-Tab">Tab</a> + <a>tabs.Tab</a> </span> </span></span> </span> @@ -2055,7 +2055,7 @@ For other examples and for help in viewing the source code, see </div> </em> </dt> - <dd>Array of <a href="tabs.html#type-Tab">Tab</a> objects representing the current tabs in the window.</dd> + <dd>Array of $ref:tabs.Tab objects representing the current tabs in the window.</dd> <!-- OBJECT PROPERTIES --> <!-- OBJECT METHODS --> <!-- OBJECT EVENT FIELDS --> diff --git a/chrome/renderer/resources/extensions/content_settings_custom_bindings.js b/chrome/renderer/resources/extensions/content_settings_custom_bindings.js index d07cb69..826ff45 100644 --- a/chrome/renderer/resources/extensions/content_settings_custom_bindings.js +++ b/chrome/renderer/resources/extensions/content_settings_custom_bindings.js @@ -7,7 +7,7 @@ var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); var sendRequest = require('sendRequest').sendRequest; -chromeHidden.registerCustomType('ContentSetting', function() { +chromeHidden.registerCustomType('contentSettings.ContentSetting', function() { function extendSchema(schema) { var extendedSchema = schema.slice(); extendedSchema.unshift({'type': 'string'}); diff --git a/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js b/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js index 9ae24cc..27b70c4 100644 --- a/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js +++ b/chrome/renderer/resources/extensions/declarative_webrequest_custom_bindings.js @@ -11,7 +11,9 @@ chromeHidden.registerCustomHook('declarativeWebRequest', function(api) { function getSchema(namespace, typeId) { var filterNamespace = function(val) {return val.namespace === namespace;}; var apiSchema = api.apiDefinitions.filter(filterNamespace)[0]; - var filterTypeId = function (val) {return val.id === typeId;}; + var filterTypeId = function (val) { + return val.id === namespace + "." + typeId; + }; var resultSchema = apiSchema.types.filter(filterTypeId)[0]; return resultSchema; } diff --git a/chrome/renderer/resources/extensions/storage_custom_bindings.js b/chrome/renderer/resources/extensions/storage_custom_bindings.js index 027017f..7d8eaa1 100644 --- a/chrome/renderer/resources/extensions/storage_custom_bindings.js +++ b/chrome/renderer/resources/extensions/storage_custom_bindings.js @@ -7,7 +7,7 @@ var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); var sendRequest = require('sendRequest').sendRequest; -chromeHidden.registerCustomType('StorageArea', function() { +chromeHidden.registerCustomType('storage.StorageArea', function() { function extendSchema(schema) { var extendedSchema = schema.slice(); extendedSchema.unshift({'type': 'string'}); diff --git a/chrome/renderer/resources/extensions/types_custom_bindings.js b/chrome/renderer/resources/extensions/types_custom_bindings.js index 55c88eb..daf029a 100644 --- a/chrome/renderer/resources/extensions/types_custom_bindings.js +++ b/chrome/renderer/resources/extensions/types_custom_bindings.js @@ -7,7 +7,7 @@ var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); var sendRequest = require('sendRequest').sendRequest; -chromeHidden.registerCustomType('ChromeSetting', function() { +chromeHidden.registerCustomType('types.ChromeSetting', function() { function extendSchema(schema) { var extendedSchema = schema.slice(); diff --git a/chrome/test/data/extensions/extension_api_unittest/types_have_namespace.json b/chrome/test/data/extensions/extension_api_unittest/types_have_namespace.json new file mode 100644 index 0000000..6b83542 --- /dev/null +++ b/chrome/test/data/extensions/extension_api_unittest/types_have_namespace.json @@ -0,0 +1,38 @@ +[{ + "namespace":"test.foo", + "types": [ + { + "id": "TestType", + "type": "object", + "customBindings": "TestType", + "properties": { + "foo": {"$ref": "OtherType"}, + "bar": {"$ref": "fully.qualified.Type"} + } + } + ], + "functions": [ + { + "name": "doFoo", + "type": "function", + "parameters": [ { "name": "t", "$ref": "TestType" } ], + "returns": { "$ref": "fully.qualified.Type" } + }, + { + "name": "doBar", + "type": "function", + "parameters": [ { "name": "t", "$ref": "fully.qualified.Type" } ], + "returns": { "$ref": "TestType" } + } + ], + "events": [ + { + "name": "onFoo", + "type": "function", + "parameters": [ + { "name": "t1", "$ref": "TestType" }, + { "name": "t2", "$ref": "fully.qualified.Type" } + ] + } + ] +}] diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py index 3efad84..508e0f2 100644 --- a/tools/json_schema_compiler/cc_generator.py +++ b/tools/json_schema_compiler/cc_generator.py @@ -7,6 +7,7 @@ from model import PropertyType import any_helper import cpp_util import model +import schema_util import sys import util_cc_helper @@ -71,8 +72,8 @@ class CCGenerator(object): .Append() ) for type_ in self._namespace.types.values(): - (c.Concat(self._GenerateType(type_.name, type_)) - .Append() + (c.Concat(self._GenerateType( + schema_util.StripSchemaNamespace(type_.name), type_)).Append() ) if self._namespace.functions: (c.Append('//') @@ -95,7 +96,7 @@ class CCGenerator(object): def _GenerateType(self, cpp_namespace, type_): """Generates the function definitions for a type. """ - classname = cpp_util.Classname(type_.name) + classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) c = Code() if type_.functions: @@ -174,7 +175,7 @@ class CCGenerator(object): E.g for type "Foo", generates Foo::Populate() """ - classname = cpp_util.Classname(type_.name) + classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) c = Code() (c.Append('// static') .Sblock('bool %(namespace)s::Populate' diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index 5afc915..1d3ac303 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -6,6 +6,8 @@ from code import Code from model import PropertyType import any_helper import cpp_util +import schema_util +import string class CppTypeGenerator(object): """Manages the types of properties and provides utilities for getting the @@ -28,12 +30,10 @@ class CppTypeGenerator(object): beneath the root namespace. """ for type_ in namespace.types: - qualified_name = self._QualifyName(namespace, type_) - if qualified_name in self._type_namespaces: + if type_ in self._type_namespaces: raise ValueError('Type %s is declared in both %s and %s' % - (qualified_name, namespace.name, - self._type_namespaces[qualified_name].name)) - self._type_namespaces[qualified_name] = namespace + (type_, namespace.name, self._type_namespaces[type_].name)) + self._type_namespaces[type_] = namespace self._cpp_namespaces[namespace] = cpp_namespace def GetExpandedChoicesInParams(self, params): @@ -125,9 +125,9 @@ class CppTypeGenerator(object): raise KeyError('Cannot find referenced type: %s' % prop.ref_type) if self._namespace != dependency_namespace: cpp_type = '%s::%s' % (self._cpp_namespaces[dependency_namespace], - prop.ref_type) + schema_util.StripSchemaNamespace(prop.ref_type)) else: - cpp_type = prop.ref_type + cpp_type = schema_util.StripSchemaNamespace(prop.ref_type) elif prop.type_ == PropertyType.BOOLEAN: cpp_type = 'bool' elif prop.type_ == PropertyType.INTEGER: @@ -175,20 +175,21 @@ class CppTypeGenerator(object): for namespace, types in sorted(self._NamespaceTypeDependencies().items()): c.Append('namespace %s {' % namespace.name) for type_ in types: + type_name = schema_util.StripSchemaNamespace(type_) if namespace.types[type_].type_ == PropertyType.STRING: - c.Append('typedef std::string %s;' % type_) + c.Append('typedef std::string %s;' % type_name) elif namespace.types[type_].type_ == PropertyType.ARRAY: c.Append('typedef std::vector<%(item_type)s> %(name)s;') - c.Substitute({'name': type_, 'item_type': + c.Substitute({'name': type_name, 'item_type': self.GetType(namespace.types[type_].item_type, wrap_optional=True)}) else: - c.Append('struct %s;' % type_) + c.Append('struct %s;' % type_name) c.Append('}') c.Concat(self.GetNamespaceStart()) for (name, type_) in self._namespace.types.items(): if not type_.functions and type_.type_ == PropertyType.OBJECT: - c.Append('struct %s;' % name) + c.Append('struct %s;' % schema_util.StripSchemaNamespace(name)) c.Concat(self.GetNamespaceEnd()) return c @@ -203,23 +204,13 @@ class CppTypeGenerator(object): return c def _ResolveTypeNamespace(self, ref_type): - """Resolves a type name to its enclosing namespace. - - Searches for the ref_type first as an explicitly qualified name, then within - the enclosing namespace, then within other namespaces that the current - namespace depends upon. + """Resolves a type, which must be explicitly qualified, to its enclosing + namespace. """ if ref_type in self._type_namespaces: return self._type_namespaces[ref_type] - - qualified_name = self._QualifyName(self._namespace, ref_type) - if qualified_name in self._type_namespaces: - return self._type_namespaces[qualified_name] - - for (type_name, namespace) in self._type_namespaces.items(): - if type_name == self._QualifyName(namespace, ref_type): - return namespace - + raise KeyError(('Cannot resolve type: %s.' % ref_type) + + 'Maybe it needs a namespace prefix if it comes from another namespace?') return None def GetReferencedProperty(self, prop): @@ -233,9 +224,6 @@ class CppTypeGenerator(object): return self._ResolveTypeNamespace(prop.ref_type).types.get(prop.ref_type, None) - def _QualifyName(self, namespace, name): - return '.'.join([namespace.name, name]) - def _NamespaceTypeDependencies(self): """Returns a dict containing a mapping of model.Namespace to the C++ type of type dependencies for self._namespace. diff --git a/tools/json_schema_compiler/cpp_type_generator_test.py b/tools/json_schema_compiler/cpp_type_generator_test.py index 708bd46..46b10a2 100755 --- a/tools/json_schema_compiler/cpp_type_generator_test.py +++ b/tools/json_schema_compiler/cpp_type_generator_test.py @@ -119,27 +119,27 @@ class CppTypeGeneratorTest(unittest.TestCase): manager = CppTypeGenerator('', self.tabs, self.tabs.unix_name) self.assertEquals('int', manager.GetType( - self.tabs.types['Tab'].properties['id'])) + self.tabs.types['tabs.Tab'].properties['id'])) self.assertEquals('std::string', manager.GetType( - self.tabs.types['Tab'].properties['status'])) + self.tabs.types['tabs.Tab'].properties['status'])) self.assertEquals('bool', manager.GetType( - self.tabs.types['Tab'].properties['selected'])) + self.tabs.types['tabs.Tab'].properties['selected'])) def testStringAsType(self): manager = CppTypeGenerator('', self.font_settings, self.font_settings.unix_name) self.assertEquals('std::string', manager.GetType( - self.font_settings.types['ScriptCode'])) + self.font_settings.types['fontSettings.ScriptCode'])) def testArrayAsType(self): manager = CppTypeGenerator('', self.browser_action, self.browser_action.unix_name) self.assertEquals('std::vector<int>', manager.GetType( - self.browser_action.types['ColorArray'])) + self.browser_action.types['browserAction.ColorArray'])) def testGetTypeArray(self): manager = CppTypeGenerator('', self.windows, self.windows.unix_name) @@ -147,9 +147,8 @@ class CppTypeGeneratorTest(unittest.TestCase): manager.GetType( self.windows.functions['getAll'].callback.params[0])) manager = CppTypeGenerator('', self.permissions, self.permissions.unix_name) - self.assertEquals('std::vector<std::string>', - manager.GetType( - self.permissions.types['Permissions'].properties['origins'])) + self.assertEquals('std::vector<std::string>', manager.GetType( + self.permissions.types['permissions.Permissions'].properties['origins'])) def testGetTypeLocalRef(self): manager = CppTypeGenerator('', self.tabs, self.tabs.unix_name) @@ -162,16 +161,16 @@ class CppTypeGeneratorTest(unittest.TestCase): manager.AddNamespace(self.tabs, self.tabs.unix_name) self.assertEquals('std::vector<linked_ptr<tabs::Tab> >', manager.GetType( - self.windows.types['Window'].properties['tabs'])) + self.windows.types['windows.Window'].properties['tabs'])) def testGetTypeNotfound(self): - prop = self.windows.types['Window'].properties['tabs'].item_type + prop = self.windows.types['windows.Window'].properties['tabs'].item_type prop.ref_type = 'Something' manager = CppTypeGenerator('', self.windows, self.windows.unix_name) self.assertRaises(KeyError, manager.GetType, prop) def testGetTypeNotimplemented(self): - prop = self.windows.types['Window'].properties['tabs'].item_type + prop = self.windows.types['windows.Window'].properties['tabs'].item_type prop.type_ = 10 manager = CppTypeGenerator('', self.windows, self.windows.unix_name) self.assertRaises(NotImplementedError, manager.GetType, prop) @@ -180,7 +179,7 @@ class CppTypeGeneratorTest(unittest.TestCase): manager = CppTypeGenerator('', self.permissions, self.permissions.unix_name) self.assertEquals('std::vector<std::string> ', manager.GetType( - self.permissions.types['Permissions'].properties['origins'], + self.permissions.types['permissions.Permissions'].properties['origins'], pad_for_generics=True)) self.assertEquals('bool', manager.GetType( diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py index 9ce2868..a028813 100644 --- a/tools/json_schema_compiler/h_generator.py +++ b/tools/json_schema_compiler/h_generator.py @@ -7,6 +7,7 @@ from model import PropertyType import cpp_util import model import os +import schema_util class HGenerator(object): """A .h generator for a namespace. @@ -156,7 +157,7 @@ class HGenerator(object): def _GenerateType(self, type_): """Generates a struct for a type. """ - classname = cpp_util.Classname(type_.name) + classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) c = Code() if type_.functions: diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py index 31a8890..09794b2 100644 --- a/tools/json_schema_compiler/idl_schema.py +++ b/tools/json_schema_compiler/idl_schema.py @@ -5,8 +5,10 @@ import json import os.path -import sys import re +import sys + +import schema_util # This file is a peer to json_schema.py. Each of these files understands a # certain format describing APIs (either JSON or IDL), reads files written @@ -258,6 +260,7 @@ class IDLSchema(object): continue else: sys.exit("Did not process %s %s" % (node.cls, node)) + schema_util.PrefixSchemasWithNamespace(namespaces) return namespaces def Load(filename): diff --git a/tools/json_schema_compiler/idl_schema_test.py b/tools/json_schema_compiler/idl_schema_test.py index d045f62..024f408 100755 --- a/tools/json_schema_compiler/idl_schema_test.py +++ b/tools/json_schema_compiler/idl_schema_test.py @@ -33,14 +33,14 @@ class IdlSchemaTest(unittest.TestCase): self.assertEquals(expected, getParams(schema, 'function5')) expected = [{'type':'function', 'name':'Callback3', - 'parameters':[{'name':'arg', '$ref':'MyType1'}]}] + 'parameters':[{'name':'arg', '$ref':'idl_basics.MyType1'}]}] self.assertEquals(expected, getParams(schema, 'function6')) def testCallbackWithArrayArgument(self): schema = self.idl_basics expected = [{'type':'function', 'name':'Callback4', 'parameters':[{'name':'arg', 'type':'array', - 'items':{'$ref':'MyType2'}}]}] + 'items':{'$ref':'idl_basics.MyType2'}}]}] self.assertEquals(expected, getParams(schema, 'function12')) diff --git a/tools/json_schema_compiler/json_schema.py b/tools/json_schema_compiler/json_schema.py index f51cece..636f837 100644 --- a/tools/json_schema_compiler/json_schema.py +++ b/tools/json_schema_compiler/json_schema.py @@ -10,6 +10,7 @@ import sys _script_path = os.path.realpath(__file__) sys.path.insert(0, os.path.normpath(_script_path + "/../../")) import json_comment_eater +import schema_util def DeleteNocompileNodes(item): def HasNocompile(thing): @@ -32,9 +33,10 @@ def DeleteNocompileNodes(item): def Load(filename): with open(filename, 'r') as handle: - return DeleteNocompileNodes( + schemas = DeleteNocompileNodes( json.loads(json_comment_eater.Nom(handle.read()))) - + schema_util.PrefixSchemasWithNamespace(schemas) + return schemas # A dictionary mapping |filename| to the object resulting from loading the JSON # at |filename|. diff --git a/tools/json_schema_compiler/model_test.py b/tools/json_schema_compiler/model_test.py index 577b3ca..0a15187 100755 --- a/tools/json_schema_compiler/model_test.py +++ b/tools/json_schema_compiler/model_test.py @@ -32,25 +32,26 @@ class ModelTest(unittest.TestCase): sorted(self.permissions.functions.keys())) def testHasTypes(self): - self.assertEquals(['Tab'], self.tabs.types.keys()) - self.assertEquals(['Permissions'], self.permissions.types.keys()) - self.assertEquals(['Window'], self.windows.types.keys()) + self.assertEquals(['tabs.Tab'], self.tabs.types.keys()) + self.assertEquals(['permissions.Permissions'], + self.permissions.types.keys()) + self.assertEquals(['windows.Window'], self.windows.types.keys()) def testHasProperties(self): self.assertEquals(["active", "favIconUrl", "highlighted", "id", "incognito", "index", "pinned", "selected", "status", "title", "url", "windowId"], - sorted(self.tabs.types['Tab'].properties.keys())) + sorted(self.tabs.types['tabs.Tab'].properties.keys())) def testProperties(self): - string_prop = self.tabs.types['Tab'].properties['status'] + string_prop = self.tabs.types['tabs.Tab'].properties['status'] self.assertEquals(model.PropertyType.STRING, string_prop.type_) - integer_prop = self.tabs.types['Tab'].properties['id'] + integer_prop = self.tabs.types['tabs.Tab'].properties['id'] self.assertEquals(model.PropertyType.INTEGER, integer_prop.type_) - array_prop = self.windows.types['Window'].properties['tabs'] + array_prop = self.windows.types['windows.Window'].properties['tabs'] self.assertEquals(model.PropertyType.ARRAY, array_prop.type_) self.assertEquals(model.PropertyType.REF, array_prop.item_type.type_) - self.assertEquals('Tab', array_prop.item_type.ref_type) + self.assertEquals('tabs.Tab', array_prop.item_type.ref_type) object_prop = self.tabs.functions['query'].params[0] self.assertEquals(model.PropertyType.OBJECT, object_prop.type_) self.assertEquals( diff --git a/tools/json_schema_compiler/schema_util.py b/tools/json_schema_compiler/schema_util.py new file mode 100644 index 0000000..289d24d --- /dev/null +++ b/tools/json_schema_compiler/schema_util.py @@ -0,0 +1,37 @@ +# Copyright (c) 2012 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. +"""Utilies for the processing of schema python structures. +""" + +def StripSchemaNamespace(s): + last_dot = s.rfind('.') + if not last_dot == -1: + return s[last_dot + 1:] + return s + +def PrefixSchemasWithNamespace(schemas): + for s in schemas: + _PrefixWithNamespace(s.get("namespace"), s) + +def _MaybePrefixFieldWithNamespace(namespace, schema, key): + if type(schema) == dict and key in schema: + old_value = schema[key] + if not "." in old_value: + schema[key] = namespace + "." + old_value + +def _PrefixTypesWithNamespace(namespace, types): + for t in types: + _MaybePrefixFieldWithNamespace(namespace, t, "id") + _MaybePrefixFieldWithNamespace(namespace, t, "customBindings") + +def _PrefixWithNamespace(namespace, schema): + if type(schema) == dict: + if "types" in schema: + _PrefixTypesWithNamespace(namespace, schema.get("types")) + _MaybePrefixFieldWithNamespace(namespace, schema, "$ref") + for s in schema: + _PrefixWithNamespace(namespace, schema[s]) + elif type(schema) == list: + for s in schema: + _PrefixWithNamespace(namespace, s) diff --git a/tools/json_schema_compiler/schema_util_test.py b/tools/json_schema_compiler/schema_util_test.py new file mode 100755 index 0000000..ecdd17c --- /dev/null +++ b/tools/json_schema_compiler/schema_util_test.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# Copyright (c) 2012 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. + +import schema_util +import unittest + +class SchemaUtilTest(unittest.TestCase): + def testStripSchemaNamespace(self): + self.assertEquals('Bar', schema_util.StripSchemaNamespace('foo.Bar')) + self.assertEquals('Baz', schema_util.StripSchemaNamespace('Baz')) + + def testPrefixSchemasWithNamespace(self): + schemas = [ + { 'namespace': 'n1', + 'types': [ + { + 'id': 'T1', + 'customBindings': 'T1', + 'properties': { + 'p1': {'$ref': 'T1'}, + 'p2': {'$ref': 'fully.qualified.T'}, + } + } + ], + 'functions': [ + { + 'parameters': [ + { '$ref': 'T1' }, + { '$ref': 'fully.qualified.T' }, + ], + 'returns': { '$ref': 'T1' } + }, + ], + 'events': [ + { + 'parameters': [ + { '$ref': 'T1' }, + { '$ref': 'fully.qualified.T' }, + ], + }, + ], + }, + ] + schema_util.PrefixSchemasWithNamespace(schemas) + self.assertEquals('n1.T1', schemas[0]['types'][0]['id']) + self.assertEquals('n1.T1', schemas[0]['types'][0]['customBindings']) + self.assertEquals('n1.T1', + schemas[0]['types'][0]['properties']['p1']['$ref']) + self.assertEquals('fully.qualified.T', + schemas[0]['types'][0]['properties']['p2']['$ref']) + + self.assertEquals('n1.T1', + schemas[0]['functions'][0]['parameters'][0]['$ref']) + self.assertEquals('fully.qualified.T', + schemas[0]['functions'][0]['parameters'][1]['$ref']) + self.assertEquals('n1.T1', + schemas[0]['functions'][0]['returns']['$ref']) + + self.assertEquals('n1.T1', + schemas[0]['events'][0]['parameters'][0]['$ref']) + self.assertEquals('fully.qualified.T', + schemas[0]['events'][0]['parameters'][1]['$ref']) + +if __name__ == '__main__': + unittest.main() diff --git a/tools/json_schema_compiler/test/crossref.json b/tools/json_schema_compiler/test/crossref.json index 02e5c94..9d3f905 100644 --- a/tools/json_schema_compiler/test/crossref.json +++ b/tools/json_schema_compiler/test/crossref.json @@ -8,7 +8,7 @@ "type": "object", "properties": { "testType": { - "$ref": "TestType", + "$ref": "simple_api.TestType", "optional": true } } @@ -22,7 +22,7 @@ "parameters": [ { "name": "testType", - "$ref": "TestType", + "$ref": "simple_api.TestType", "optional": true }, { @@ -43,7 +43,7 @@ "parameters": [ { "name": "result", - "$ref": "TestType", + "$ref": "simple_api.TestType", "description": "A TestType." } ] @@ -59,7 +59,7 @@ "name": "paramObject", "type": "object", "properties": { - "testType": {"$ref": "TestType", "optional": true}, + "testType": {"$ref": "simple_api.TestType", "optional": true}, "boolean": {"type": "boolean"} } }, diff --git a/tools/json_schema_compiler/test/dependencyTester.json b/tools/json_schema_compiler/test/dependencyTester.json index 43b145a..aec4c15 100644 --- a/tools/json_schema_compiler/test/dependencyTester.json +++ b/tools/json_schema_compiler/test/dependencyTester.json @@ -18,10 +18,10 @@ "type": "object", "properties": { "color": { - "$ref": "ColorArray" + "$ref": "browserAction.ColorArray" }, "scriptCode": { - "$ref": "ScriptCode" + "$ref": "fontSettings.ScriptCode" } } } diff --git a/tools/json_schema_compiler/test/windows.json b/tools/json_schema_compiler/test/windows.json index 52fc683d..f6062d4 100644 --- a/tools/json_schema_compiler/test/windows.json +++ b/tools/json_schema_compiler/test/windows.json @@ -12,7 +12,7 @@ "left": {"type": "integer", "description": "The offset of the window from the left edge of the screen in pixels."}, "width": {"type": "integer", "description": "The width of the window in pixels."}, "height": {"type": "integer", "description": "The height of the window in pixels."}, - "tabs": {"type": "array", "items": { "$ref": "Tab" }, "optional": true, "description": "Array of $ref:Tab objects representing the current tabs in the window."}, + "tabs": {"type": "array", "items": { "$ref": "tabs.Tab" }, "optional": true, "description": "Array of $ref:Tab objects representing the current tabs in the window."}, "incognito": {"type": "boolean", "description": "Whether the window is incognito."}, "type": { "type": "string", |