| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "net/url_request/url_request.h" | 47 #include "net/url_request/url_request.h" |
| 48 #include "webkit/glue/webmenuitem.h" | 48 #include "webkit/glue/webmenuitem.h" |
| 49 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 49 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
| 50 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" | 50 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" |
| 51 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" | 51 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" |
| 52 | 52 |
| 53 using WebKit::WebContextMenuData; | 53 using WebKit::WebContextMenuData; |
| 54 using WebKit::WebMediaPlayerAction; | 54 using WebKit::WebMediaPlayerAction; |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 const size_t RenderViewContextMenu::kMaxExtensionItemTitleLength = 75; | |
| 58 // static | |
| 59 const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; | |
| 60 | |
| 61 // static | |
| 62 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { | 57 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { |
| 63 return url.SchemeIs(chrome::kChromeUIScheme) && | 58 return url.SchemeIs(chrome::kChromeUIScheme) && |
| 64 url.host() == chrome::kChromeUIDevToolsHost; | 59 url.host() == chrome::kChromeUIDevToolsHost; |
| 65 } | 60 } |
| 66 | 61 |
| 67 // static | 62 // static |
| 68 bool RenderViewContextMenu::IsSyncResourcesURL(const GURL& url) { | 63 bool RenderViewContextMenu::IsSyncResourcesURL(const GURL& url) { |
| 69 return url.SchemeIs(chrome::kChromeUIScheme) && | 64 return url.SchemeIs(chrome::kChromeUIScheme) && |
| 70 url.host() == chrome::kChromeUISyncResourcesHost; | 65 url.host() == chrome::kChromeUISyncResourcesHost; |
| 71 } | 66 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // checkbox item because we are going to put the extension icon next to it). | 195 // checkbox item because we are going to put the extension icon next to it). |
| 201 // If they have more than that, we automatically push them into a submenu. | 196 // If they have more than that, we automatically push them into a submenu. |
| 202 string16 title; | 197 string16 title; |
| 203 ExtensionMenuItem::List submenu_items; | 198 ExtensionMenuItem::List submenu_items; |
| 204 if (items.size() > 1 || items[0]->type() != ExtensionMenuItem::NORMAL) { | 199 if (items.size() > 1 || items[0]->type() != ExtensionMenuItem::NORMAL) { |
| 205 title = UTF8ToUTF16(extension->name()); | 200 title = UTF8ToUTF16(extension->name()); |
| 206 submenu_items = items; | 201 submenu_items = items; |
| 207 } else { | 202 } else { |
| 208 ExtensionMenuItem* item = items[0]; | 203 ExtensionMenuItem* item = items[0]; |
| 209 extension_item_map_[menu_id] = item->id(); | 204 extension_item_map_[menu_id] = item->id(); |
| 210 title = item->TitleWithReplacement(PrintableSelectionText(), | 205 title = item->TitleWithReplacement(PrintableSelectionText()); |
| 211 kMaxExtensionItemTitleLength); | |
| 212 submenu_items = GetRelevantExtensionItems(item->children(), params_); | 206 submenu_items = GetRelevantExtensionItems(item->children(), params_); |
| 213 } | 207 } |
| 214 | 208 |
| 215 // Now add our item(s) to the menu_model_. | 209 // Now add our item(s) to the menu_model_. |
| 216 if (submenu_items.empty()) { | 210 if (submenu_items.empty()) { |
| 217 menu_model_.AddItem(menu_id, title); | 211 menu_model_.AddItem(menu_id, title); |
| 218 } else { | 212 } else { |
| 219 menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); | 213 menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); |
| 220 extension_menu_models_.push_back(submenu); | 214 extension_menu_models_.push_back(submenu); |
| 221 menu_model_.AddSubMenu(menu_id, title, submenu); | 215 menu_model_.AddSubMenu(menu_id, title, submenu); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 242 item->type() != ExtensionMenuItem::SEPARATOR && | 236 item->type() != ExtensionMenuItem::SEPARATOR && |
| 243 last_type == ExtensionMenuItem::RADIO) { | 237 last_type == ExtensionMenuItem::RADIO) { |
| 244 menu_model->AddSeparator(); | 238 menu_model->AddSeparator(); |
| 245 radio_group_id++; | 239 radio_group_id++; |
| 246 } | 240 } |
| 247 | 241 |
| 248 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | 242 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; |
| 249 if (menu_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) | 243 if (menu_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) |
| 250 return; | 244 return; |
| 251 extension_item_map_[menu_id] = item->id(); | 245 extension_item_map_[menu_id] = item->id(); |
| 252 string16 title = item->TitleWithReplacement(selection_text, | 246 string16 title = item->TitleWithReplacement(selection_text); |
| 253 kMaxExtensionItemTitleLength); | |
| 254 if (item->type() == ExtensionMenuItem::NORMAL) { | 247 if (item->type() == ExtensionMenuItem::NORMAL) { |
| 255 ExtensionMenuItem::List children = | 248 ExtensionMenuItem::List children = |
| 256 GetRelevantExtensionItems(item->children(), params_); | 249 GetRelevantExtensionItems(item->children(), params_); |
| 257 if (children.size() == 0) { | 250 if (children.size() == 0) { |
| 258 menu_model->AddItem(menu_id, title); | 251 menu_model->AddItem(menu_id, title); |
| 259 } else { | 252 } else { |
| 260 menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); | 253 menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); |
| 261 extension_menu_models_.push_back(submenu); | 254 extension_menu_models_.push_back(submenu); |
| 262 menu_model->AddSubMenu(menu_id, title, submenu); | 255 menu_model->AddSubMenu(menu_id, title, submenu); |
| 263 RecursivelyAppendExtensionItems(children, submenu, index); | 256 RecursivelyAppendExtensionItems(children, submenu, index); |
| (...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 // per tab flag set. | 1360 // per tab flag set. |
| 1368 if (IsDevToolsURL(active_entry->url()) && | 1361 if (IsDevToolsURL(active_entry->url()) && |
| 1369 !command_line.HasSwitch(switches::kProcessPerTab)) | 1362 !command_line.HasSwitch(switches::kProcessPerTab)) |
| 1370 return false; | 1363 return false; |
| 1371 } | 1364 } |
| 1372 | 1365 |
| 1373 return true; | 1366 return true; |
| 1374 } | 1367 } |
| 1375 | 1368 |
| 1376 string16 RenderViewContextMenu::PrintableSelectionText() { | 1369 string16 RenderViewContextMenu::PrintableSelectionText() { |
| 1377 return WideToUTF16(l10n_util::TruncateString(params_.selection_text, | 1370 return WideToUTF16(l10n_util::TruncateString(params_.selection_text, 50)); |
| 1378 kMaxSelectionTextLength)); | |
| 1379 } | 1371 } |
| 1380 | 1372 |
| 1381 // Controller functions -------------------------------------------------------- | 1373 // Controller functions -------------------------------------------------------- |
| 1382 | 1374 |
| 1383 void RenderViewContextMenu::OpenURL( | 1375 void RenderViewContextMenu::OpenURL( |
| 1384 const GURL& url, | 1376 const GURL& url, |
| 1385 WindowOpenDisposition disposition, | 1377 WindowOpenDisposition disposition, |
| 1386 PageTransition::Type transition) { | 1378 PageTransition::Type transition) { |
| 1387 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); | 1379 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); |
| 1388 } | 1380 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1404 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), | 1396 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), |
| 1405 g_browser_process->clipboard()); | 1397 g_browser_process->clipboard()); |
| 1406 } | 1398 } |
| 1407 | 1399 |
| 1408 void RenderViewContextMenu::MediaPlayerActionAt( | 1400 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1409 const gfx::Point& location, | 1401 const gfx::Point& location, |
| 1410 const WebMediaPlayerAction& action) { | 1402 const WebMediaPlayerAction& action) { |
| 1411 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1403 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
| 1412 location, action); | 1404 location, action); |
| 1413 } | 1405 } |
| OLD | NEW |