diff options
| author | skare@chromium.org <skare@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 01:40:14 +0000 |
|---|---|---|
| committer | skare@chromium.org <skare@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 01:40:14 +0000 |
| commit | c7aa87dd258247dd771e9538e418ec4d3050d87b (patch) | |
| tree | 17b3dfcbb3635b685ee4e02611dd97b26ba098e0 | |
| parent | 7c98b11705e7ce52d0ec0e27a9e2699cffba5428 (diff) | |
| download | chromium_src-c7aa87dd258247dd771e9538e418ec4d3050d87b.zip chromium_src-c7aa87dd258247dd771e9538e418ec4d3050d87b.tar.gz chromium_src-c7aa87dd258247dd771e9538e418ec4d3050d87b.tar.bz2 | |
Skips the picker step for the action box by including individual share intent menu items and a webstore link. Removes the command this deprecates from browser_commands.
BUG=137953
Review URL: https://chromiumcodereview.appspot.com/11073009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162032 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/app/chrome_command_ids.h | 1 | ||||
| -rw-r--r-- | chrome/app/generated_resources.grd | 4 | ||||
| -rw-r--r-- | chrome/browser/ui/browser_command_controller.cc | 4 | ||||
| -rw-r--r-- | chrome/browser/ui/browser_commands.cc | 12 | ||||
| -rw-r--r-- | chrome/browser/ui/browser_commands.h | 1 | ||||
| -rw-r--r-- | chrome/browser/ui/toolbar/action_box_button_controller.cc | 109 | ||||
| -rw-r--r-- | chrome/browser/ui/toolbar/action_box_button_controller.h | 11 | ||||
| -rw-r--r-- | chrome/browser/ui/toolbar/action_box_menu_model.cc | 9 |
8 files changed, 114 insertions, 37 deletions
diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h index 02c79f1..d6c7718 100644 --- a/chrome/app/chrome_command_ids.h +++ b/chrome/app/chrome_command_ids.h @@ -81,7 +81,6 @@ #define IDC_ADVANCED_PRINT 35007 #define IDC_CHROME_TO_MOBILE_PAGE 35008 #define IDC_PRINT_TO_DESTINATION 35009 -#define IDC_SHARE_PAGE 35010 // When adding a new encoding to this list, be sure to append it to the // EncodingMenuController::kValidEncodingIds array in diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index b386312..3e5e642 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6958,8 +6958,8 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_CHROME_TO_MOBILE" desc="The text for chrome to mobile menu item"> Send tab to device </message> - <message name="IDS_SHARE_PAGE" desc="The text for the Share Page action box menu item"> - Share this page + <message name="IDS_FIND_SHARE_INTENTS" desc="The text for the 'Find places to share' action box menu item"> + Find places to share </message> <!--Accessible name/action strings--> diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index aa9fd71..7ad7d34 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -444,9 +444,6 @@ void BrowserCommandController::ExecuteCommandWithDisposition( case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(browser_); break; - case IDC_SHARE_PAGE: - ShareCurrentPage(browser_); - break; case IDC_PIN_TO_START_SCREEN: TogglePagePinnedToStartScreen(browser_); break; @@ -836,7 +833,6 @@ void BrowserCommandController::InitCommandState() { command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true); command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); - command_updater_.UpdateCommandEnabled(IDC_SHARE_PAGE, true); // Zoom command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index cd5676a..ca12cb9 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -694,18 +694,6 @@ void ShowChromeToMobileBubble(Browser* browser) { browser->window()->ShowChromeToMobileBubble(); } -void ShareCurrentPage(Browser* browser) { - const GURL& current_url = chrome::GetActiveWebContents(browser)->GetURL(); - webkit_glue::WebIntentData intent_data( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("text/uri-list"), - UTF8ToUTF16(current_url.spec())); - scoped_ptr<content::WebIntentsDispatcher> dispatcher( - content::WebIntentsDispatcher::Create(intent_data)); - static_cast<content::WebContentsDelegate*>(browser)-> - WebIntentDispatch(NULL, dispatcher.release()); -} - void Print(Browser* browser) { printing::PrintViewManager* print_view_manager = printing::PrintViewManager::FromWebContents( diff --git a/chrome/browser/ui/browser_commands.h b/chrome/browser/ui/browser_commands.h index c36661b..607c72b 100644 --- a/chrome/browser/ui/browser_commands.h +++ b/chrome/browser/ui/browser_commands.h @@ -103,7 +103,6 @@ void ShowPageInfo(Browser* browser, const content::SSLStatus& ssl, bool show_history); void ShowChromeToMobileBubble(Browser* browser); -void ShareCurrentPage(Browser* browser); void Print(Browser* browser); bool CanPrint(const Browser* browser); void AdvancedPrint(Browser* browser); diff --git a/chrome/browser/ui/toolbar/action_box_button_controller.cc b/chrome/browser/ui/toolbar/action_box_button_controller.cc index 9dd0b0b..9010131a 100644 --- a/chrome/browser/ui/toolbar/action_box_button_controller.cc +++ b/chrome/browser/ui/toolbar/action_box_button_controller.cc @@ -5,22 +5,44 @@ #include "chrome/browser/ui/toolbar/action_box_button_controller.h" #include "base/logging.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" +#include "chrome/browser/intents/web_intents_registry_factory.h" +#include "chrome/browser/intents/web_intents_registry.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" +#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/toolbar/action_box_menu_model.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_set.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_intents_dispatcher.h" +#include "grit/generated_resources.h" +#include "webkit/glue/web_intent_data.h" +#include "webkit/glue/webkit_glue.h" namespace { -// Extensions get command IDs that are beyond the maximal valid command ID +// Share intents get command IDs that are beyond the maximal valid command ID // (0xDFFF) so that they are not confused with actual commands that appear in -// the menu. For more details see: chrome/app/chrome_command_ids.h -const int kFirstExtensionCommandId = 0xE000; +// the menu. Extensions get a reserved block of commands after share handlers. +// For more details see: chrome/app/chrome_command_ids.h +const int kMaxShareItemsToShow = 20; // TODO(skare): Show extras in submenu. +enum ActionBoxLocalCommandIds { + CWS_FIND_SHARE_INTENTS_COMMAND = 0xE000, + SHARE_COMMAND_FIRST, + SHARE_COMMAND_LAST = + SHARE_COMMAND_FIRST + kMaxShareItemsToShow - 1, + EXTENSION_COMMAND_FIRST +}; + +const char kShareIntentAction[] = "http://webintents.org/share"; +const char kShareIntentMimeType[] = "text/uri-list"; } // namespace @@ -28,7 +50,7 @@ ActionBoxButtonController::ActionBoxButtonController(Browser* browser, Delegate* delegate) : browser_(browser), delegate_(delegate), - next_extension_command_id_(kFirstExtensionCommandId) { + next_extension_command_id_(EXTENSION_COMMAND_FIRST) { DCHECK(browser_); DCHECK(delegate_); registrar_.Add(this, @@ -39,15 +61,50 @@ ActionBoxButtonController::ActionBoxButtonController(Browser* browser, ActionBoxButtonController::~ActionBoxButtonController() {} void ActionBoxButtonController::OnButtonClicked() { - // Creating the action box menu will populate it with the bookmark star etc, - // but no extensions. + // Build a menu model and display the menu. scoped_ptr<ActionBoxMenuModel> menu_model( new ActionBoxMenuModel(browser_, this)); - // Add the extensions. + // Add share intent triggers and a link to the web store. + // Web Intents are not currently supported in Incognito mode. ExtensionService* extension_service = extensions::ExtensionSystem::Get(browser_->profile())-> extension_service(); + if (!browser_->profile()->IsOffTheRecord()) { + int next_share_intent_command_id = SHARE_COMMAND_FIRST; + share_intent_service_ids_.clear(); + const ExtensionSet* extension_set = extension_service->extensions(); + WebIntentsRegistry* intents_registry = + WebIntentsRegistryFactory::GetForProfile(browser_->profile()); + for (ExtensionSet::const_iterator it = extension_set->begin(); + it != extension_set->end(); ++it) { + const extensions::Extension* extension = *it; + WebIntentsRegistry::IntentServiceList services; + intents_registry->GetIntentServicesForExtensionFilter( + ASCIIToUTF16(kShareIntentAction), + ASCIIToUTF16(kShareIntentMimeType), + extension->id(), + &services); + if (!services.empty()) { + int command_id = next_share_intent_command_id++; + if (command_id > SHARE_COMMAND_LAST) + break; + // TODO(skare): If an intent supports multiple services, be able to + // disambiguate. Choosing the first matches the picker behavior; see + // TODO in WebIntentPickerController::DispatchToInstalledExtension. + share_intent_service_ids_[command_id] = services[0].service_url; + menu_model->AddItem(command_id, services[0].title); + } + } + + // Add link to the Web Store to find additional share intents. + menu_model->AddItemWithStringId(CWS_FIND_SHARE_INTENTS_COMMAND, + IDS_FIND_SHARE_INTENTS); + } + + // Add Extensions. + next_extension_command_id_ = EXTENSION_COMMAND_FIRST; + extension_command_ids_.clear(); const extensions::ExtensionList& extensions = extension_service->toolbar_model()->action_box_menu_items(); for (extensions::ExtensionList::const_iterator it = extensions.begin(); @@ -55,6 +112,7 @@ void ActionBoxButtonController::OnButtonClicked() { menu_model->AddExtension(**it, GetCommandIdForExtension(**it)); } + // And show the menu. delegate_->ShowMenu(menu_model.Pass()); } @@ -73,7 +131,19 @@ bool ActionBoxButtonController::GetAcceleratorForCommandId( } void ActionBoxButtonController::ExecuteCommand(int command_id) { - // It might be a command associated with an extension. + // Handle explicit intent triggers for share intent commands. + if (share_intent_service_ids_.count(command_id) > 0) { + TriggerExplicitShareIntent(share_intent_service_ids_[command_id]); + return; + } + + // Handle link to the CWS web store. + if (command_id == CWS_FIND_SHARE_INTENTS_COMMAND) { + NavigateToWebStoreShareIntentsList(); + return; + } + + // Handle commands associated with extensions. // Note that the extension might have been uninstalled or disabled while the // menu was open (sync perhaps?) but that will just fall through safely. const extensions::Extension* extension = @@ -86,6 +156,7 @@ void ActionBoxButtonController::ExecuteCommand(int command_id) { return; } + // Otherwise, let the browser handle the command. chrome::ExecuteCommand(browser_, command_id); } @@ -133,3 +204,25 @@ void ActionBoxButtonController::Observe( // We may also want to listen to EXTENSION_LOADED to do the opposite. extension_command_ids_.erase(extension->id()); } + +void ActionBoxButtonController::TriggerExplicitShareIntent( + const GURL& share_service_url) { + const GURL& current_url = chrome::GetActiveWebContents(browser_)->GetURL(); + webkit_glue::WebIntentData intent_data( + ASCIIToUTF16(kShareIntentAction), + ASCIIToUTF16(kShareIntentMimeType), + UTF8ToUTF16(current_url.spec())); + intent_data.service = share_service_url; + static_cast<content::WebContentsDelegate*>(browser_)->WebIntentDispatch( + NULL, content::WebIntentsDispatcher::Create(intent_data)); +} + +void ActionBoxButtonController::NavigateToWebStoreShareIntentsList() { + const GURL& query_url = extension_urls::GetWebstoreIntentQueryURL( + kShareIntentAction, + kShareIntentMimeType); + chrome::NavigateParams params(browser_->profile(), query_url, + content::PAGE_TRANSITION_LINK); + params.disposition = NEW_FOREGROUND_TAB; + chrome::Navigate(¶ms); +} diff --git a/chrome/browser/ui/toolbar/action_box_button_controller.h b/chrome/browser/ui/toolbar/action_box_button_controller.h index 45c5692..13872e0 100644 --- a/chrome/browser/ui/toolbar/action_box_button_controller.h +++ b/chrome/browser/ui/toolbar/action_box_button_controller.h @@ -68,10 +68,21 @@ class ActionBoxButtonController : public ui::SimpleMenuModel::Delegate, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // Handles "share with X" commands. + void TriggerExplicitShareIntent(const GURL& share_service_url); + + // Handles the "Find places to share" command. Navigates the browser to the + // web store to find extensions with share intents. + void NavigateToWebStoreShareIntentsList(); + Browser* browser_; Delegate* delegate_; + // The share service strings that have commands associated with them. + typedef std::map<int, GURL> ShareIntentServiceCommandMap; + ShareIntentServiceCommandMap share_intent_service_ids_; + // The command ID to assign to the next extension that needs one. int next_extension_command_id_; diff --git a/chrome/browser/ui/toolbar/action_box_menu_model.cc b/chrome/browser/ui/toolbar/action_box_menu_model.cc index dfb3ec3..f661e34 100644 --- a/chrome/browser/ui/toolbar/action_box_menu_model.cc +++ b/chrome/browser/ui/toolbar/action_box_menu_model.cc @@ -52,15 +52,6 @@ ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser, starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); SetIcon(GetIndexOfCommandId(IDC_BOOKMARK_PAGE), rb.GetNativeImageNamed(starred ? IDR_STAR_LIT : IDR_STAR)); - - // Since web intents are not working in incognito window (issue 142463), - // hide "share this page" menu item in incognito mode - // till the issue gets fixed. - if (!browser_->profile()->IsOffTheRecord()) { - AddItemWithStringId(IDC_SHARE_PAGE, IDS_SHARE_PAGE); - SetIcon(GetIndexOfCommandId(IDC_SHARE_PAGE), - rb.GetNativeImageNamed(IDR_SHARE)); - } } ActionBoxMenuModel::~ActionBoxMenuModel() { |
