diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 17:45:33 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 17:45:33 +0000 |
commit | 56ad3797dc8ea7d757dc2b12d606c14cedd564e1 (patch) | |
tree | 26fab7c6d4cbb0358b404ca3eb488aae75ebe1d3 /chrome/common/extensions | |
parent | 79b663c6e6ddf89e85cdc566b5d4f368465bb858 (diff) | |
download | chromium_src-56ad3797dc8ea7d757dc2b12d606c14cedd564e1.zip chromium_src-56ad3797dc8ea7d757dc2b12d606c14cedd564e1.tar.gz chromium_src-56ad3797dc8ea7d757dc2b12d606c14cedd564e1.tar.bz2 |
First pass at experimental omnibox API. There are plenty of rough edges and features to work on, but it's in a usable state.
When an extension is installed that specifies an omnibox keyword in its manifest, we add that keyword to the user's list of Search Engines. The user can then edit this keyword later.
I'm leveraging most of the original search engine keyword code. An extension keyword has a special URL that identifies it as an extension keyword. There is some special case code to treat these keywords slightly differently throughout
the omnibox code.
BUG=38884
Review URL: http://codereview.chromium.org/2078021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48503 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r-- | chrome/common/extensions/api/extension_api.json | 67 | ||||
-rw-r--r-- | chrome/common/extensions/docs/examples/api/omnibox/background.html | 19 | ||||
-rw-r--r-- | chrome/common/extensions/docs/examples/api/omnibox/manifest.json | 7 | ||||
-rw-r--r-- | chrome/common/extensions/docs/experimental.html | 1 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 12 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 5 | ||||
-rw-r--r-- | chrome/common/extensions/extension_constants.cc | 6 | ||||
-rw-r--r-- | chrome/common/extensions/extension_constants.h | 3 |
8 files changed, 120 insertions, 0 deletions
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index c387aaaf..c6094b6 100644 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -3015,5 +3015,72 @@ } ], "events": [] + }, + { + "namespace": "experimental.omnibox", + "types": [], + "functions": [ + { + "name": "sendSuggestions", + "nodoc": true, + "type": "function", + "description": "", + "parameters": [ + {"type": "integer", "name": "requestId"}, + { + "type": "array", + "description": "Array of suggest results", + "items": { + "type": "object", + "properties": { + "content": {"type": "string"}, + "description": {"type": "string"} + } + } + } + ] + } + ], + "events": [ + { + "name": "onInputChanged", + "type": "function", + "description": "User has changed what is typed into the omnibox.", + "parameters": [ + { + "type": "string", + "name": "text" + }, + { + "type": "function", + "name": "suggest", + "parameters": [ + { + "type": "array", + "description": "Array of suggest results", + "items": { + "type": "object", + "properties": { + "content": {"type": "string"}, + "description": {"type": "string"} + } + } + } + ] + } + ] + }, + { + "name": "onInputEntered", + "type": "function", + "description": "User has accepted what is typed into the omnibox.", + "parameters": [ + { + "type": "string", + "name": "text" + } + ] + } + ] } ] diff --git a/chrome/common/extensions/docs/examples/api/omnibox/background.html b/chrome/common/extensions/docs/examples/api/omnibox/background.html new file mode 100644 index 0000000..ff83ff2 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/omnibox/background.html @@ -0,0 +1,19 @@ +<script> +// This event is fired each time the user updates the text in the omnibox, +// as long as the extension's keyword mode is still active. +chrome.experimental.omnibox.onInputChanged.addListener( + function(text, suggest) { + console.log('inputChanged: ' + text); + suggest([ + {content: text + " one", description: "the first one"}, + {content: text + " number two", description: "the second entry"} + ]); + }); + +// This event is fired with the user accepts the input in the omnibox. +chrome.experimental.omnibox.onInputEntered.addListener( + function(text) { + console.log('inputEntered: ' + text); + alert('You just typed "' + text + '"'); + }); +</script> diff --git a/chrome/common/extensions/docs/examples/api/omnibox/manifest.json b/chrome/common/extensions/docs/examples/api/omnibox/manifest.json new file mode 100644 index 0000000..2b63ca2 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/omnibox/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "Omnibox Example", + "version": "1.0", + "permissions": [ "experimental" ], + "background_page": "background.html", + "omnibox_keyword": "omnix" +} diff --git a/chrome/common/extensions/docs/experimental.html b/chrome/common/extensions/docs/experimental.html index 8dd43e7..49a7aa4 100644 --- a/chrome/common/extensions/docs/experimental.html +++ b/chrome/common/extensions/docs/experimental.html @@ -265,6 +265,7 @@ on the following experimental APIs: <a href="experimental.contextMenu.html">experimental.contextMenu</a></li><li> <a href="experimental.cookies.html">experimental.cookies</a></li><li> <a href="experimental.infobars.html">experimental.infobars</a></li><li> + <a href="experimental.omnibox.html">experimental.omnibox</a></li><li> <a href="experimental.processes.html">experimental.processes</a></li> </ul> diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 89d7095..f68445e 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -1456,6 +1456,18 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, } } + if (source.HasKey(keys::kOmniboxKeyword)) { + if (!source.GetString(keys::kOmniboxKeyword, &omnibox_keyword_) || + omnibox_keyword_.empty()) { + *error = errors::kInvalidOmniboxKeyword; + return false; + } + if (!HasApiPermission(Extension::kExperimentalPermission)) { + *error = errors::kOmniboxExperimental; + return false; + } + } + if (!CheckAppsAreEnabled(manifest_value_.get(), error) || !LoadWebContentEnabled(manifest_value_.get(), error) || !LoadWebOrigin(manifest_value_.get(), error) || diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index a135df5..49d6288 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -327,6 +327,8 @@ class Extension { return chrome_url_overrides_; } + const std::string omnibox_keyword() const { return omnibox_keyword_; } + bool web_content_enabled() const { return web_content_enabled_; } const ExtensionExtent& web_extent() const { return web_extent_; } @@ -528,6 +530,9 @@ class Extension { // resource to the cached image. ImageCache image_cache_; + // The omnibox keyword for this extension, or empty if there is none. + std::string omnibox_keyword_; + // Runtime data: // True if the background page is ready. diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index 174701c..d0a64e1 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -62,6 +62,7 @@ const wchar_t* kWebContent = L"web_content"; const wchar_t* kWebContentEnabled = L"web_content.enabled"; const wchar_t* kWebOrigin = L"web_content.origin"; const wchar_t* kWebPaths = L"web_content.paths"; +const wchar_t* kOmniboxKeyword = L"omnibox_keyword"; } // namespace extension_manifest_keys namespace extension_manifest_values { @@ -244,6 +245,11 @@ const char* kCannotAccessPage = "Cannot access contents of url \"*\". " const char* kCannotScriptGallery = "The extensions gallery cannot be scripted."; const char* kWebContentMustBeEnabled = "The 'web_content.enabled' property " "must be set to true in order to use any other web content features."; +const char* kInvalidOmniboxKeyword = + "Invalid value for 'omnibox_keyword'."; +const char* kOmniboxExperimental = + "You must request the 'experimental' permission in order to use the" + " omnibox API."; } // namespace extension_manifest_errors namespace extension_urls { diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h index 2353b35..35c4555 100644 --- a/chrome/common/extensions/extension_constants.h +++ b/chrome/common/extensions/extension_constants.h @@ -64,6 +64,7 @@ namespace extension_manifest_keys { extern const wchar_t* kWebLaunchUrl; extern const wchar_t* kWebOrigin; extern const wchar_t* kWebPaths; + extern const wchar_t* kOmniboxKeyword; } // namespace extension_manifest_keys // Some values expected in manifests. @@ -161,6 +162,8 @@ namespace extension_manifest_errors { extern const char* kCannotAccessPage; extern const char* kCannotScriptGallery; extern const char* kWebContentMustBeEnabled; + extern const char* kInvalidOmniboxKeyword; + extern const char* kOmniboxExperimental; } // namespace extension_manifest_errors namespace extension_urls { |