diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 17:54:31 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 17:54:31 +0000 |
commit | 0b004da852f6c01fecba4b1e2a6ffab221061a63 (patch) | |
tree | 78bb10cf8f5b0a7b09a77179b8c7902b1ab104cb /chrome/browser/extensions | |
parent | 9d31dc62c63cdad2abb25ecef8753dbc65bd223a (diff) | |
download | chromium_src-0b004da852f6c01fecba4b1e2a6ffab221061a63.zip chromium_src-0b004da852f6c01fecba4b1e2a6ffab221061a63.tar.gz chromium_src-0b004da852f6c01fecba4b1e2a6ffab221061a63.tar.bz2 |
Add support for omnibox.onInputStarted and onInputCancelled.
Also fix a bug where we'd keep an extension's old keyword even if it changed
on upgrade/reload.
BUG=46475
BUG=48091
Review URL: http://codereview.chromium.org/2807033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51540 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
6 files changed, 76 insertions, 12 deletions
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index 5790290..55cf6fd 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -454,7 +454,8 @@ void ExtensionBrowserEventRouter::PageActionExecuted( NULL, NULL, &tab_contents, NULL)) { return; } - std::string event_name = std::string("pageAction/") + extension_id; + std::string event_name = ExtensionMessageService::GetPerExtensionEventName( + "pageAction.onClicked", extension_id); DispatchEventWithTab(profile, event_name.c_str(), tab_contents); } @@ -464,6 +465,7 @@ void ExtensionBrowserEventRouter::BrowserActionExecuted( int tab_id = 0; if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) return; - std::string event_name = std::string("browserAction/") + extension_id; + std::string event_name = ExtensionMessageService::GetPerExtensionEventName( + "browserAction.onClicked", extension_id); DispatchEventWithTab(profile, event_name.c_str(), tab_contents); } diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc index 2c7f693..979437a 100644 --- a/chrome/browser/extensions/extension_message_service.cc +++ b/chrome/browser/extensions/extension_message_service.cc @@ -114,6 +114,14 @@ const char ExtensionMessageService::kDispatchOnMessage[] = const char ExtensionMessageService::kDispatchEvent[] = "Event.dispatchJSON"; +// static +std::string ExtensionMessageService::GetPerExtensionEventName( + const std::string& event_name, const std::string& extension_id) { + // This should match the method we use in extension_process_binding.js when + // setting up the corresponding chrome.Event object. + return event_name + "/" + extension_id; +} + ExtensionMessageService::ExtensionMessageService(Profile* profile) : profile_(profile), extension_devtools_manager_(NULL), @@ -485,6 +493,14 @@ void ExtensionMessageService::DispatchEventToRenderers( } } +void ExtensionMessageService::DispatchEventToExtension( + const std::string& extension_id, + const std::string& event_name, const std::string& event_args, + bool has_incognito_data, const GURL& event_url) { + DispatchEventToRenderers(GetPerExtensionEventName(event_name, extension_id), + event_args, has_incognito_data, event_url); +} + void ExtensionMessageService::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h index bf49948..fa89786 100644 --- a/chrome/browser/extensions/extension_message_service.h +++ b/chrome/browser/extensions/extension_message_service.h @@ -62,6 +62,10 @@ class ExtensionMessageService struct MessageChannel; struct MessagePort; + // Returns the event name for an event that is extension-specific. + static std::string GetPerExtensionEventName(const std::string& event_name, + const std::string& extension_id); + // --- UI thread only: explicit ExtensionMessageService(Profile* profile); @@ -92,6 +96,13 @@ class ExtensionMessageService const std::string& event_name, const std::string& event_args, bool has_incognito_data, const GURL& event_url); + // Same as above, except use the extension-specific naming scheme for the + // event. This is used by events that are per-extension. + void DispatchEventToExtension( + const std::string& extension_id, + const std::string& event_name, const std::string& event_args, + bool has_incognito_data, const GURL& event_url); + // Given an extension ID, opens a channel between the given // automation "port" or DevTools service and that extension. the // channel will be open to the extension process hosting the diff --git a/chrome/browser/extensions/extension_omnibox_api.cc b/chrome/browser/extensions/extension_omnibox_api.cc index 5c046a3..2f3f8f1 100644 --- a/chrome/browser/extensions/extension_omnibox_api.cc +++ b/chrome/browser/extensions/extension_omnibox_api.cc @@ -12,8 +12,10 @@ #include "chrome/common/notification_service.h" namespace events { -const char kOnInputChanged[] = "experimental.omnibox.onInputChanged/"; -const char kOnInputEntered[] = "experimental.omnibox.onInputEntered/"; +const char kOnInputStarted[] = "experimental.omnibox.onInputStarted"; +const char kOnInputChanged[] = "experimental.omnibox.onInputChanged"; +const char kOnInputEntered[] = "experimental.omnibox.onInputEntered"; +const char kOnInputCancelled[] = "experimental.omnibox.onInputCancelled"; }; // namespace events namespace { @@ -31,10 +33,19 @@ const wchar_t kDescriptionStylesOffset[] = L"offset"; }; // namespace // static +void ExtensionOmniboxEventRouter::OnInputStarted( + Profile* profile, const std::string& extension_id) { + profile->GetExtensionMessageService()->DispatchEventToExtension( + extension_id, events::kOnInputStarted, "[]", profile->IsOffTheRecord(), + GURL()); +} + +// static bool ExtensionOmniboxEventRouter::OnInputChanged( Profile* profile, const std::string& extension_id, const std::string& input, int suggest_id) { - std::string event_name = events::kOnInputChanged + extension_id; + std::string event_name = ExtensionMessageService::GetPerExtensionEventName( + events::kOnInputChanged, extension_id); if (!profile->GetExtensionMessageService()->HasEventListener(event_name)) return false; @@ -44,8 +55,9 @@ bool ExtensionOmniboxEventRouter::OnInputChanged( std::string json_args; base::JSONWriter::Write(&args, false, &json_args); - profile->GetExtensionMessageService()->DispatchEventToRenderers( - event_name, json_args, profile->IsOffTheRecord(), GURL()); + profile->GetExtensionMessageService()->DispatchEventToExtension( + extension_id, events::kOnInputChanged, json_args, + profile->IsOffTheRecord(), GURL()); return true; } @@ -60,8 +72,21 @@ void ExtensionOmniboxEventRouter::OnInputEntered( std::string json_args; base::JSONWriter::Write(&args, false, &json_args); - profile->GetExtensionMessageService()->DispatchEventToRenderers( - event_name, json_args, profile->IsOffTheRecord(), GURL()); + profile->GetExtensionMessageService()->DispatchEventToExtension( + extension_id, events::kOnInputEntered, json_args, + profile->IsOffTheRecord(), GURL()); + + NotificationService::current()->Notify( + NotificationType::EXTENSION_OMNIBOX_INPUT_ENTERED, + Source<Profile>(profile), NotificationService::NoDetails()); +} + +// static +void ExtensionOmniboxEventRouter::OnInputCancelled( + Profile* profile, const std::string& extension_id) { + profile->GetExtensionMessageService()->DispatchEventToExtension( + extension_id, events::kOnInputCancelled, "[]", profile->IsOffTheRecord(), + GURL()); } bool OmniboxSendSuggestionsFunction::RunImpl() { diff --git a/chrome/browser/extensions/extension_omnibox_api.h b/chrome/browser/extensions/extension_omnibox_api.h index 4af9ee5..320b40a 100644 --- a/chrome/browser/extensions/extension_omnibox_api.h +++ b/chrome/browser/extensions/extension_omnibox_api.h @@ -12,6 +12,11 @@ // Event router class for events related to the omnibox API. class ExtensionOmniboxEventRouter { public: + // The user has just typed the omnibox keyword. This is sent exactly once in + // a given input session, before any OnInputChanged events. + static void OnInputStarted( + Profile* profile, const std::string& extension_id); + // The user has changed what is typed into the omnibox while in an extension // keyword session. Returns true if someone is listening to this event, and // thus we have some degree of confidence we'll get a response. @@ -24,6 +29,11 @@ class ExtensionOmniboxEventRouter { Profile* profile, const std::string& extension_id, const std::string& input); + // The user has cleared the keyword, or closed the omnibox popup. This is + // sent at most once in a give input session, after any OnInputChanged events. + static void OnInputCancelled( + Profile* profile, const std::string& extension_id); + private: DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxEventRouter); }; diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 81c56f3..78c600f 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -901,6 +901,9 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension, extension->set_being_upgraded(false); UpdateActiveExtensionsInCrashReporter(); + + if (profile_->GetTemplateURLModel()) + profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension); } void ExtensionsService::UpdateActiveExtensionsInCrashReporter() { @@ -976,9 +979,6 @@ void ExtensionsService::OnExtensionInstalled(Extension* extension, Details<Extension>(extension)); } - if (profile_->GetTemplateURLModel()) - profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension); - // Transfer ownership of |extension| to OnExtensionLoaded. OnExtensionLoaded(scoped_extension.release(), allow_privilege_increase); } |