| 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/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 page_url.DomainIs(kFileBrowserDomain)) | 222 page_url.DomainIs(kFileBrowserDomain)) |
| 223 return false; | 223 return false; |
| 224 #endif | 224 #endif |
| 225 | 225 |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| 228 | 228 |
| 229 void DevToolsInspectElementAt(RenderViewHost* rvh, int x, int y) { | 229 void DevToolsInspectElementAt(RenderViewHost* rvh, int x, int y) { |
| 230 DevToolsWindow::InspectElement(rvh, x, y); | 230 DevToolsWindow::InspectElement(rvh, x, y); |
| 231 } | 231 } |
| 232 |
| 233 // Helper function to escape "&" as "&&". |
| 234 void EscapeAmpersands(string16& text) { |
| 235 const char16 ampersand[] = {'&', 0}; |
| 236 ReplaceChars(text, ampersand, ASCIIToUTF16("&&"), &text); |
| 237 } |
| 238 |
| 232 } // namespace | 239 } // namespace |
| 233 | 240 |
| 234 // static | 241 // static |
| 235 const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; | 242 const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; |
| 236 | 243 |
| 237 // static | 244 // static |
| 238 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { | 245 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { |
| 239 return url.SchemeIs(chrome::kChromeDevToolsScheme) && | 246 return url.SchemeIs(chrome::kChromeDevToolsScheme) && |
| 240 url.host() == chrome::kChromeUIDevToolsHost; | 247 url.host() == chrome::kChromeUIDevToolsHost; |
| 241 } | 248 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 388 |
| 382 if (sorted_ids.empty()) | 389 if (sorted_ids.empty()) |
| 383 return; | 390 return; |
| 384 | 391 |
| 385 int index = 0; | 392 int index = 0; |
| 386 base::TimeTicks begin = base::TimeTicks::Now(); | 393 base::TimeTicks begin = base::TimeTicks::Now(); |
| 387 std::vector<std::pair<std::string, std::string> >::const_iterator i; | 394 std::vector<std::pair<std::string, std::string> >::const_iterator i; |
| 388 for (i = sorted_ids.begin(); | 395 for (i = sorted_ids.begin(); |
| 389 i != sorted_ids.end(); ++i) { | 396 i != sorted_ids.end(); ++i) { |
| 390 string16 printable_selection_text = PrintableSelectionText(); | 397 string16 printable_selection_text = PrintableSelectionText(); |
| 391 // Escape "&" as "&&". | 398 EscapeAmpersands(printable_selection_text); |
| 392 for (size_t position = printable_selection_text.find('&'); | |
| 393 position != string16::npos; | |
| 394 position = printable_selection_text.find('&', position + 2)) | |
| 395 printable_selection_text.insert(position, 1, '&'); | |
| 396 | 399 |
| 397 extension_items_.AppendExtensionItems(i->second, printable_selection_text, | 400 extension_items_.AppendExtensionItems(i->second, printable_selection_text, |
| 398 &index); | 401 &index); |
| 399 } | 402 } |
| 400 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 403 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 401 base::TimeTicks::Now() - begin); | 404 base::TimeTicks::Now() - begin); |
| 402 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 405 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 403 } | 406 } |
| 404 | 407 |
| 405 void RenderViewContextMenu::InitMenu() { | 408 void RenderViewContextMenu::InitMenu() { |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 ASCIIToUTF16(" "), ¶ms_.selection_text); | 825 ASCIIToUTF16(" "), ¶ms_.selection_text); |
| 823 | 826 |
| 824 AutocompleteMatch match; | 827 AutocompleteMatch match; |
| 825 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( | 828 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( |
| 826 params_.selection_text, string16(), false, false, &match, NULL); | 829 params_.selection_text, string16(), false, false, &match, NULL); |
| 827 selection_navigation_url_ = match.destination_url; | 830 selection_navigation_url_ = match.destination_url; |
| 828 if (!selection_navigation_url_.is_valid()) | 831 if (!selection_navigation_url_.is_valid()) |
| 829 return; | 832 return; |
| 830 | 833 |
| 831 string16 printable_selection_text = PrintableSelectionText(); | 834 string16 printable_selection_text = PrintableSelectionText(); |
| 832 // Escape "&" as "&&". | 835 EscapeAmpersands(printable_selection_text); |
| 833 for (size_t i = printable_selection_text.find('&'); i != string16::npos; | |
| 834 i = printable_selection_text.find('&', i + 2)) | |
| 835 printable_selection_text.insert(i, 1, '&'); | |
| 836 | 836 |
| 837 if (AutocompleteMatch::IsSearchType(match.type)) { | 837 if (AutocompleteMatch::IsSearchType(match.type)) { |
| 838 const TemplateURL* const default_provider = | 838 const TemplateURL* const default_provider = |
| 839 TemplateURLServiceFactory::GetForProfile(profile_)-> | 839 TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 840 GetDefaultSearchProvider(); | 840 GetDefaultSearchProvider(); |
| 841 if (!default_provider) | 841 if (!default_provider) |
| 842 return; | 842 return; |
| 843 menu_model_.AddItem( | 843 menu_model_.AddItem( |
| 844 IDC_CONTENT_CONTEXT_SEARCHWEBFOR, | 844 IDC_CONTENT_CONTEXT_SEARCHWEBFOR, |
| 845 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, | 845 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1872 source_web_contents_->GetRenderViewHost()-> | 1872 source_web_contents_->GetRenderViewHost()-> |
| 1873 ExecuteMediaPlayerActionAtLocation(location, action); | 1873 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1874 } | 1874 } |
| 1875 | 1875 |
| 1876 void RenderViewContextMenu::PluginActionAt( | 1876 void RenderViewContextMenu::PluginActionAt( |
| 1877 const gfx::Point& location, | 1877 const gfx::Point& location, |
| 1878 const WebPluginAction& action) { | 1878 const WebPluginAction& action) { |
| 1879 source_web_contents_->GetRenderViewHost()-> | 1879 source_web_contents_->GetRenderViewHost()-> |
| 1880 ExecutePluginActionAtLocation(location, action); | 1880 ExecutePluginActionAtLocation(location, action); |
| 1881 } | 1881 } |
| OLD | NEW |