Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/ui/toolbar/action_box_button_controller.cc

Issue 12262050: Send selected text and page title to pageLauncher.OnClicked. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/renderer_host/render_widget_host_view_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/extensions/api/page_launcher/page_launcher_api.h" 11 #include "chrome/browser/extensions/api/page_launcher/page_launcher_api.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" 18 #include "chrome/browser/ui/toolbar/action_box_menu_model.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/extensions/api/extension_action/action_info.h" 20 #include "chrome/common/extensions/api/extension_action/action_info.h"
21 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/extensions/extension_set.h" 22 #include "chrome/common/extensions/extension_set.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
25 #include "content/public/browser/render_widget_host_view.h"
25 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 28
28 using content::UserMetricsAction; 29 using content::UserMetricsAction;
29 using content::WebContents; 30 using content::WebContents;
30 using extensions::ActionInfo; 31 using extensions::ActionInfo;
31 32
32 void ActionBoxButtonController::Delegate::ShowMenu( 33 void ActionBoxButtonController::Delegate::ShowMenu(
33 scoped_ptr<ActionBoxMenuModel> menu_model) { 34 scoped_ptr<ActionBoxMenuModel> menu_model) {
34 } 35 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 85 }
85 86
86 void ActionBoxButtonController::ExecuteCommand(int command_id) { 87 void ActionBoxButtonController::ExecuteCommand(int command_id) {
87 // If the command id belongs to an extension, dispatch an onClicked event 88 // If the command id belongs to an extension, dispatch an onClicked event
88 // to its pageLauncher. 89 // to its pageLauncher.
89 ExtensionIdCommandMap::const_iterator it = 90 ExtensionIdCommandMap::const_iterator it =
90 extension_command_ids_.find(command_id); 91 extension_command_ids_.find(command_id);
91 if (it != extension_command_ids_.end()) { 92 if (it != extension_command_ids_.end()) {
92 WebContents* web_contents = 93 WebContents* web_contents =
93 browser_->tab_strip_model()->GetActiveWebContents(); 94 browser_->tab_strip_model()->GetActiveWebContents();
94 // TODO(rfevang): Send page title and selected text. 95
96 std::string page_title = UTF16ToUTF8(web_contents->GetTitle());
97 std::string selected_text =
98 UTF16ToUTF8(web_contents->GetRenderWidgetHostView()->GetSelectedText());
95 extensions::PageLauncherAPI::DispatchOnClickedEvent( 99 extensions::PageLauncherAPI::DispatchOnClickedEvent(
96 browser_->profile(), 100 browser_->profile(),
97 it->second, 101 it->second,
98 web_contents->GetURL(), 102 web_contents->GetURL(),
99 web_contents->GetContentsMimeType(), 103 web_contents->GetContentsMimeType(),
100 NULL, 104 page_title.empty() ? NULL : &page_title,
101 NULL); 105 selected_text.empty() ? NULL : &selected_text);
102 return; 106 return;
103 } 107 }
104 108
105 // Otherwise, let the browser handle the command. 109 // Otherwise, let the browser handle the command.
106 chrome::ExecuteCommand(browser_, command_id); 110 chrome::ExecuteCommand(browser_, command_id);
107 } 111 }
108 112
109 int ActionBoxButtonController::GetCommandIdForExtension( 113 int ActionBoxButtonController::GetCommandIdForExtension(
110 const extensions::Extension& extension) { 114 const extensions::Extension& extension) {
111 for (ExtensionIdCommandMap::const_iterator it = 115 for (ExtensionIdCommandMap::const_iterator it =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 for (ExtensionIdCommandMap::iterator it = extension_command_ids_.begin(); 152 for (ExtensionIdCommandMap::iterator it = extension_command_ids_.begin();
149 it != extension_command_ids_.end();) { 153 it != extension_command_ids_.end();) {
150 if (it->second== extension->id()) 154 if (it->second== extension->id())
151 extension_command_ids_.erase(it++); 155 extension_command_ids_.erase(it++);
152 else 156 else
153 ++it; 157 ++it;
154 } 158 }
155 // TODO(kalman): if there's a menu open, remove it from that too. 159 // TODO(kalman): if there's a menu open, remove it from that too.
156 // We may also want to listen to EXTENSION_LOADED to do the opposite. 160 // We may also want to listen to EXTENSION_LOADED to do the opposite.
157 } 161 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_widget_host_view_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698