OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/toolbar/action_box_button_controller.h" | 5 #include "chrome/browser/ui/toolbar/action_box_button_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_intents_dispatcher.h" | 26 #include "content/public/browser/web_intents_dispatcher.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "webkit/glue/web_intent_data.h" | 28 #include "webkit/glue/web_intent_data.h" |
29 #include "webkit/glue/webkit_glue.h" | 29 #include "webkit/glue/webkit_glue.h" |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
| 33 #if defined(ENABLE_WEB_INTENTS) |
33 // This indicates we need to send UMA data about the number of | 34 // This indicates we need to send UMA data about the number of |
34 // "Share with X" commands shown in the menu after user tried to | 35 // "Share with X" commands shown in the menu after user tried to |
35 // find share extensions from web store or the first use of action | 36 // find share extensions from web store or the first use of action |
36 // box after browser starts. | 37 // box after browser starts. |
37 static bool send_uma_share_command_count = true; | 38 static bool send_uma_share_command_count = true; |
| 39 #endif |
38 | 40 |
39 // Share intents get command IDs that are beyond the maximal valid command ID | 41 // Share intents get command IDs that are beyond the maximal valid command ID |
40 // (0xDFFF) so that they are not confused with actual commands that appear in | 42 // (0xDFFF) so that they are not confused with actual commands that appear in |
41 // the menu. Extensions get a reserved block of commands after share handlers. | 43 // the menu. Extensions get a reserved block of commands after share handlers. |
42 // For more details see: chrome/app/chrome_command_ids.h | 44 // For more details see: chrome/app/chrome_command_ids.h |
43 const int kMaxShareItemsToShow = 20; // TODO(skare): Show extras in submenu. | 45 const int kMaxShareItemsToShow = 20; // TODO(skare): Show extras in submenu. |
44 enum ActionBoxLocalCommandIds { | 46 enum ActionBoxLocalCommandIds { |
45 CWS_FIND_SHARE_INTENTS_COMMAND = 0xE000, | 47 CWS_FIND_SHARE_INTENTS_COMMAND = 0xE000, |
46 SHARE_COMMAND_FIRST, | 48 SHARE_COMMAND_FIRST, |
47 SHARE_COMMAND_LAST = | 49 SHARE_COMMAND_LAST = |
(...skipping 20 matching lines...) Expand all Loading... |
68 content::Source<Profile>(browser->profile())); | 70 content::Source<Profile>(browser->profile())); |
69 } | 71 } |
70 | 72 |
71 ActionBoxButtonController::~ActionBoxButtonController() {} | 73 ActionBoxButtonController::~ActionBoxButtonController() {} |
72 | 74 |
73 void ActionBoxButtonController::OnButtonClicked() { | 75 void ActionBoxButtonController::OnButtonClicked() { |
74 // Build a menu model and display the menu. | 76 // Build a menu model and display the menu. |
75 scoped_ptr<ActionBoxMenuModel> menu_model( | 77 scoped_ptr<ActionBoxMenuModel> menu_model( |
76 new ActionBoxMenuModel(browser_, this)); | 78 new ActionBoxMenuModel(browser_, this)); |
77 | 79 |
78 // Add share intent triggers and a link to the web store. | |
79 // Web Intents are not currently supported in Incognito mode. | |
80 ExtensionService* extension_service = | 80 ExtensionService* extension_service = |
81 extensions::ExtensionSystem::Get(browser_->profile())-> | 81 extensions::ExtensionSystem::Get(browser_->profile())-> |
82 extension_service(); | 82 extension_service(); |
| 83 |
| 84 #if defined(ENABLE_WEB_INTENTS) |
| 85 // Add share intent triggers and a link to the web store. |
| 86 // Web Intents are not currently supported in Incognito mode. |
83 if (!browser_->profile()->IsOffTheRecord()) { | 87 if (!browser_->profile()->IsOffTheRecord()) { |
84 int next_share_intent_command_id = SHARE_COMMAND_FIRST; | 88 int next_share_intent_command_id = SHARE_COMMAND_FIRST; |
85 share_intent_service_ids_.clear(); | 89 share_intent_service_ids_.clear(); |
86 const ExtensionSet* extension_set = extension_service->extensions(); | 90 const ExtensionSet* extension_set = extension_service->extensions(); |
87 WebIntentsRegistry* intents_registry = | 91 WebIntentsRegistry* intents_registry = |
88 WebIntentsRegistryFactory::GetForProfile(browser_->profile()); | 92 WebIntentsRegistryFactory::GetForProfile(browser_->profile()); |
89 for (ExtensionSet::const_iterator it = extension_set->begin(); | 93 for (ExtensionSet::const_iterator it = extension_set->begin(); |
90 it != extension_set->end(); ++it) { | 94 it != extension_set->end(); ++it) { |
91 const extensions::Extension* extension = *it; | 95 const extensions::Extension* extension = *it; |
92 WebIntentsRegistry::IntentServiceList services; | 96 WebIntentsRegistry::IntentServiceList services; |
(...skipping 19 matching lines...) Expand all Loading... |
112 IDS_FIND_SHARE_INTENTS); | 116 IDS_FIND_SHARE_INTENTS); |
113 | 117 |
114 content::RecordAction(UserMetricsAction("ActionBox.ClickButton")); | 118 content::RecordAction(UserMetricsAction("ActionBox.ClickButton")); |
115 if (send_uma_share_command_count) { | 119 if (send_uma_share_command_count) { |
116 UMA_HISTOGRAM_ENUMERATION("ActionBox.ShareCommandCount", | 120 UMA_HISTOGRAM_ENUMERATION("ActionBox.ShareCommandCount", |
117 next_share_intent_command_id - SHARE_COMMAND_FIRST, | 121 next_share_intent_command_id - SHARE_COMMAND_FIRST, |
118 kMaxShareItemsToShow + 1); | 122 kMaxShareItemsToShow + 1); |
119 send_uma_share_command_count = false; | 123 send_uma_share_command_count = false; |
120 } | 124 } |
121 } | 125 } |
| 126 #endif |
122 | 127 |
123 // Add Extensions. | 128 // Add Extensions. |
124 next_extension_command_id_ = EXTENSION_COMMAND_FIRST; | 129 next_extension_command_id_ = EXTENSION_COMMAND_FIRST; |
125 extension_command_ids_.clear(); | 130 extension_command_ids_.clear(); |
126 const extensions::ExtensionList& extensions = | 131 const extensions::ExtensionList& extensions = |
127 extension_service->toolbar_model()->action_box_menu_items(); | 132 extension_service->toolbar_model()->action_box_menu_items(); |
128 for (extensions::ExtensionList::const_iterator it = extensions.begin(); | 133 for (extensions::ExtensionList::const_iterator it = extensions.begin(); |
129 it != extensions.end(); ++it) { | 134 it != extensions.end(); ++it) { |
130 menu_model->AddExtension(**it, GetCommandIdForExtension(**it)); | 135 menu_model->AddExtension(**it, GetCommandIdForExtension(**it)); |
131 } | 136 } |
(...skipping 16 matching lines...) Expand all Loading... |
148 return false; | 153 return false; |
149 } | 154 } |
150 | 155 |
151 void ActionBoxButtonController::ExecuteCommand(int command_id) { | 156 void ActionBoxButtonController::ExecuteCommand(int command_id) { |
152 // Handle explicit intent triggers for share intent commands. | 157 // Handle explicit intent triggers for share intent commands. |
153 if (share_intent_service_ids_.count(command_id) > 0) { | 158 if (share_intent_service_ids_.count(command_id) > 0) { |
154 TriggerExplicitShareIntent(share_intent_service_ids_[command_id]); | 159 TriggerExplicitShareIntent(share_intent_service_ids_[command_id]); |
155 return; | 160 return; |
156 } | 161 } |
157 | 162 |
| 163 #if defined(ENABLE_WEB_INTENTS) |
158 // Handle link to the CWS web store. | 164 // Handle link to the CWS web store. |
159 if (command_id == CWS_FIND_SHARE_INTENTS_COMMAND) { | 165 if (command_id == CWS_FIND_SHARE_INTENTS_COMMAND) { |
160 NavigateToWebStoreShareIntentsList(); | 166 NavigateToWebStoreShareIntentsList(); |
161 return; | 167 return; |
162 } | 168 } |
| 169 #endif |
163 | 170 |
164 // Handle commands associated with extensions. | 171 // Handle commands associated with extensions. |
165 // Note that the extension might have been uninstalled or disabled while the | 172 // Note that the extension might have been uninstalled or disabled while the |
166 // menu was open (sync perhaps?) but that will just fall through safely. | 173 // menu was open (sync perhaps?) but that will just fall through safely. |
167 const extensions::Extension* extension = | 174 const extensions::Extension* extension = |
168 GetExtensionForCommandId(command_id); | 175 GetExtensionForCommandId(command_id); |
169 if (extension) { | 176 if (extension) { |
170 // TODO(kalman): do something with the result. | 177 // TODO(kalman): do something with the result. |
171 extensions::ExtensionSystem::Get(browser_->profile())-> | 178 extensions::ExtensionSystem::Get(browser_->profile())-> |
172 extension_service()->toolbar_model()->ExecuteBrowserAction( | 179 extension_service()->toolbar_model()->ExecuteBrowserAction( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 const extensions::Extension* extension = | 225 const extensions::Extension* extension = |
219 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | 226 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
220 | 227 |
221 // TODO(kalman): if there's a menu open, remove it from that too. | 228 // TODO(kalman): if there's a menu open, remove it from that too. |
222 // We may also want to listen to EXTENSION_LOADED to do the opposite. | 229 // We may also want to listen to EXTENSION_LOADED to do the opposite. |
223 extension_command_ids_.erase(extension->id()); | 230 extension_command_ids_.erase(extension->id()); |
224 } | 231 } |
225 | 232 |
226 void ActionBoxButtonController::TriggerExplicitShareIntent( | 233 void ActionBoxButtonController::TriggerExplicitShareIntent( |
227 const GURL& share_service_url) { | 234 const GURL& share_service_url) { |
| 235 #if defined(ENABLE_WEB_INTENTS) |
228 const GURL& current_url = | 236 const GURL& current_url = |
229 browser_->tab_strip_model()->GetActiveWebContents()->GetURL(); | 237 browser_->tab_strip_model()->GetActiveWebContents()->GetURL(); |
230 webkit_glue::WebIntentData intent_data( | 238 webkit_glue::WebIntentData intent_data( |
231 ASCIIToUTF16(kShareIntentAction), | 239 ASCIIToUTF16(kShareIntentAction), |
232 ASCIIToUTF16(kShareIntentMimeType), | 240 ASCIIToUTF16(kShareIntentMimeType), |
233 UTF8ToUTF16(current_url.spec())); | 241 UTF8ToUTF16(current_url.spec())); |
234 intent_data.service = share_service_url; | 242 intent_data.service = share_service_url; |
235 static_cast<content::WebContentsDelegate*>(browser_)->WebIntentDispatch( | 243 static_cast<content::WebContentsDelegate*>(browser_)->WebIntentDispatch( |
236 NULL, content::WebIntentsDispatcher::Create(intent_data)); | 244 NULL, content::WebIntentsDispatcher::Create(intent_data)); |
| 245 #endif |
237 } | 246 } |
238 | 247 |
239 void ActionBoxButtonController::NavigateToWebStoreShareIntentsList() { | 248 void ActionBoxButtonController::NavigateToWebStoreShareIntentsList() { |
| 249 #if defined(ENABLE_WEB_INTENTS) |
240 const GURL& query_url = extension_urls::GetWebstoreIntentQueryURL( | 250 const GURL& query_url = extension_urls::GetWebstoreIntentQueryURL( |
241 kShareIntentAction, | 251 kShareIntentAction, |
242 kShareIntentMimeType); | 252 kShareIntentMimeType); |
243 chrome::NavigateParams params(browser_->profile(), query_url, | 253 chrome::NavigateParams params(browser_->profile(), query_url, |
244 content::PAGE_TRANSITION_LINK); | 254 content::PAGE_TRANSITION_LINK); |
245 params.disposition = NEW_FOREGROUND_TAB; | 255 params.disposition = NEW_FOREGROUND_TAB; |
246 chrome::Navigate(¶ms); | 256 chrome::Navigate(¶ms); |
247 | 257 |
248 content::RecordAction(UserMetricsAction("ActionBox.FindShareHandlers")); | 258 content::RecordAction(UserMetricsAction("ActionBox.FindShareHandlers")); |
249 send_uma_share_command_count = true; | 259 send_uma_share_command_count = true; |
| 260 #endif |
250 } | 261 } |
OLD | NEW |