Index: chrome/browser/ui/extensions/extension_installed_bubble.cc |
diff --git a/chrome/browser/ui/extensions/extension_installed_bubble.cc b/chrome/browser/ui/extensions/extension_installed_bubble.cc |
index ea6a68499a631b318c4e12844940f5d656f3b256..a9eacd018196cfa9280f1af3b9798021eb43d70d 100644 |
--- a/chrome/browser/ui/extensions/extension_installed_bubble.cc |
+++ b/chrome/browser/ui/extensions/extension_installed_bubble.cc |
@@ -8,18 +8,22 @@ |
#include "base/bind.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/extensions/api/commands/command_service.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/common/extensions/api/extension_action/action_info.h" |
#include "chrome/common/extensions/api/omnibox/omnibox_handler.h" |
+#include "chrome/common/extensions/command.h" |
+#include "chrome/grit/generated_resources.h" |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_source.h" |
#include "extensions/browser/extension_registry.h" |
#include "extensions/common/extension.h" |
+#include "ui/base/l10n/l10n_util.h" |
-using content::Details; |
using extensions::Extension; |
namespace { |
@@ -29,6 +33,29 @@ const int kAnimationWaitMs = 50; |
// How often we retry when waiting for browser action animation to end. |
const int kAnimationWaitRetries = 10; |
+// Returns the keybinding for an extension command, or an empty string if none |
Finnur
2015/02/18 09:40:41
Empty string?
Devlin
2015/02/18 18:08:41
Whoops, forgot to update that comment. Done.
|
+// exists. |
+scoped_ptr<extensions::Command> GetCommand( |
+ const std::string& extension_id, |
+ Profile* profile, |
+ ExtensionInstalledBubble::BubbleType type) { |
+ scoped_ptr<extensions::Command> result; |
+ extensions::Command command; |
+ extensions::CommandService* command_service = |
+ extensions::CommandService::Get(profile); |
+ bool has_command = false; |
+ if (type == ExtensionInstalledBubble::BROWSER_ACTION) { |
+ has_command = command_service->GetBrowserActionCommand( |
+ extension_id, extensions::CommandService::ACTIVE, &command, nullptr); |
+ } else if (type == ExtensionInstalledBubble::PAGE_ACTION) { |
+ has_command = command_service->GetPageActionCommand( |
+ extension_id, extensions::CommandService::ACTIVE, &command, nullptr); |
+ } |
+ if (has_command) |
+ result.reset(new extensions::Command(command)); |
+ return result.Pass(); |
+} |
+ |
} // namespace |
ExtensionInstalledBubble::ExtensionInstalledBubble(Delegate* delegate, |
@@ -71,6 +98,37 @@ void ExtensionInstalledBubble::IgnoreBrowserClosing() { |
content::Source<Browser>(browser_)); |
} |
+base::string16 ExtensionInstalledBubble::GetHowToUseDescription() const { |
+ int message_id = 0; |
+ base::string16 extra; |
+ if (action_command_) |
+ extra = action_command_->accelerator().GetShortcutText(); |
+ |
+ switch (type_) { |
+ case BROWSER_ACTION: |
+ message_id = extra.empty() ? IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO : |
+ IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT; |
+ break; |
+ case PAGE_ACTION: |
+ message_id = extra.empty() ? IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO : |
+ IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT; |
+ break; |
+ case OMNIBOX_KEYWORD: |
+ extra = |
+ base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(extension_)); |
+ message_id = IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO; |
+ break; |
+ case GENERIC: |
+ break; |
+ } |
+ |
+ if (message_id != 0) { |
+ return extra.empty() ? l10n_util::GetStringUTF16(message_id) : |
+ l10n_util::GetStringFUTF16(message_id, extra); |
+ } |
+ return base::string16(); |
Finnur
2015/02/18 09:40:41
nit: We generally prefer:
if (message_id == 0)
Devlin
2015/02/18 18:08:41
Done.
|
+} |
+ |
void ExtensionInstalledBubble::ShowInternal() { |
if (delegate_->MaybeShowNow()) |
return; |
@@ -87,6 +145,9 @@ void ExtensionInstalledBubble::OnExtensionLoaded( |
content::BrowserContext* browser_context, |
const extensions::Extension* extension) { |
if (extension == extension_) { |
+ // Parse the extension command, if one exists. |
Robert Sesek
2015/02/18 15:03:00
Can the command change over time?
Devlin
2015/02/18 18:08:41
Technically, yes. A user could customize an exten
|
+ action_command_ = GetCommand(extension_->id(), browser_->profile(), type_); |
+ |
animation_wait_retries_ = 0; |
// PostTask to ourself to allow all EXTENSION_LOADED Observers to run. |
base::MessageLoopForUI::current()->PostTask( |