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