| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <functional> | 5 #include <functional> |
| 6 | 6 |
| 7 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 7 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 8 | 8 |
| 9 #include "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
| 10 #include "app/clipboard/scoped_clipboard_writer.h" | 10 #include "app/clipboard/scoped_clipboard_writer.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "chrome/browser/spellchecker_platform_engine.h" | 34 #include "chrome/browser/spellchecker_platform_engine.h" |
| 35 #include "chrome/browser/tab_contents/navigation_entry.h" | 35 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 36 #include "chrome/browser/tab_contents/tab_contents.h" | 36 #include "chrome/browser/tab_contents/tab_contents.h" |
| 37 #include "chrome/browser/translate/translate_manager.h" | 37 #include "chrome/browser/translate/translate_manager.h" |
| 38 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 39 #include "chrome/browser/translate/translate_manager2.h" | 39 #include "chrome/browser/translate/translate_manager2.h" |
| 40 #endif | 40 #endif |
| 41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
| 44 #include "gfx/favicon_size.h" |
| 44 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 45 #include "net/base/escape.h" | 46 #include "net/base/escape.h" |
| 46 #include "net/url_request/url_request.h" | 47 #include "net/url_request/url_request.h" |
| 47 #include "webkit/glue/webmenuitem.h" | 48 #include "webkit/glue/webmenuitem.h" |
| 48 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 49 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
| 49 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" | 50 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" |
| 50 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" | 51 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" |
| 51 | 52 |
| 52 using WebKit::WebContextMenuData; | 53 using WebKit::WebContextMenuData; |
| 53 using WebKit::WebMediaPlayerAction; | 54 using WebKit::WebMediaPlayerAction; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 189 |
| 189 // Now add our item(s) to the menu_model_. | 190 // Now add our item(s) to the menu_model_. |
| 190 if (submenu_items.empty()) { | 191 if (submenu_items.empty()) { |
| 191 menu_model_.AddItem(menu_id, title); | 192 menu_model_.AddItem(menu_id, title); |
| 192 } else { | 193 } else { |
| 193 menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); | 194 menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); |
| 194 extension_menu_models_.push_back(submenu); | 195 extension_menu_models_.push_back(submenu); |
| 195 menu_model_.AddSubMenu(menu_id, title, submenu); | 196 menu_model_.AddSubMenu(menu_id, title, submenu); |
| 196 RecursivelyAppendExtensionItems(submenu_items, submenu, index); | 197 RecursivelyAppendExtensionItems(submenu_items, submenu, index); |
| 197 } | 198 } |
| 199 SetExtensionIcon(extension_id); |
| 198 } | 200 } |
| 199 | 201 |
| 200 void RenderViewContextMenu::RecursivelyAppendExtensionItems( | 202 void RenderViewContextMenu::RecursivelyAppendExtensionItems( |
| 201 const ExtensionMenuItem::List& items, | 203 const ExtensionMenuItem::List& items, |
| 202 menus::SimpleMenuModel* menu_model, | 204 menus::SimpleMenuModel* menu_model, |
| 203 int *index) { | 205 int *index) { |
| 204 string16 selection_text = PrintableSelectionText(); | 206 string16 selection_text = PrintableSelectionText(); |
| 205 ExtensionMenuItem::Type last_type = ExtensionMenuItem::NORMAL; | 207 ExtensionMenuItem::Type last_type = ExtensionMenuItem::NORMAL; |
| 206 int radio_group_id = 1; | 208 int radio_group_id = 1; |
| 207 | 209 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 248 } |
| 247 | 249 |
| 248 menu_model->AddRadioItem(menu_id, title, radio_group_id); | 250 menu_model->AddRadioItem(menu_id, title, radio_group_id); |
| 249 } else { | 251 } else { |
| 250 NOTREACHED(); | 252 NOTREACHED(); |
| 251 } | 253 } |
| 252 last_type = item->type(); | 254 last_type = item->type(); |
| 253 } | 255 } |
| 254 } | 256 } |
| 255 | 257 |
| 258 void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { |
| 259 ExtensionsService* service = profile_->GetExtensionsService(); |
| 260 ExtensionMenuManager* menu_manager = service->menu_manager(); |
| 261 |
| 262 int index = menu_model_.GetItemCount() - 1; |
| 263 DCHECK(index >= 0); |
| 264 |
| 265 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); |
| 266 DCHECK(icon.width() == kFavIconSize); |
| 267 DCHECK(icon.height() == kFavIconSize); |
| 268 |
| 269 menu_model_.SetIcon(index, icon); |
| 270 } |
| 271 |
| 256 void RenderViewContextMenu::AppendAllExtensionItems() { | 272 void RenderViewContextMenu::AppendAllExtensionItems() { |
| 257 extension_item_map_.clear(); | 273 extension_item_map_.clear(); |
| 258 ExtensionsService* service = profile_->GetExtensionsService(); | 274 ExtensionsService* service = profile_->GetExtensionsService(); |
| 259 if (!service) | 275 if (!service) |
| 260 return; // In unit-tests, we may not have an ExtensionService. | 276 return; // In unit-tests, we may not have an ExtensionService. |
| 261 ExtensionMenuManager* menu_manager = service->menu_manager(); | 277 ExtensionMenuManager* menu_manager = service->menu_manager(); |
| 262 | 278 |
| 263 // Get a list of extension id's that have context menu items, and sort it by | 279 // Get a list of extension id's that have context menu items, and sort it by |
| 264 // the extension's name. | 280 // the extension's name. |
| 265 std::set<std::string> ids = menu_manager->ExtensionIds(); | 281 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| (...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1375 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 1360 g_browser_process->clipboard()); | 1376 g_browser_process->clipboard()); |
| 1361 } | 1377 } |
| 1362 | 1378 |
| 1363 void RenderViewContextMenu::MediaPlayerActionAt( | 1379 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1364 const gfx::Point& location, | 1380 const gfx::Point& location, |
| 1365 const WebMediaPlayerAction& action) { | 1381 const WebMediaPlayerAction& action) { |
| 1366 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1382 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
| 1367 location, action); | 1383 location, action); |
| 1368 } | 1384 } |
| OLD | NEW |