| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 20 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete_match.h" | 21 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/child_process_security_policy.h" | 23 #include "chrome/browser/child_process_security_policy.h" |
| 23 #include "chrome/browser/debugger/devtools_manager.h" | 24 #include "chrome/browser/debugger/devtools_manager.h" |
| 24 #include "chrome/browser/debugger/devtools_window.h" | 25 #include "chrome/browser/debugger/devtools_window.h" |
| 25 #include "chrome/browser/download/download_manager.h" | 26 #include "chrome/browser/download/download_manager.h" |
| 26 #include "chrome/browser/extensions/extension_event_router.h" | 27 #include "chrome/browser/extensions/extension_event_router.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 569 } |
| 569 | 570 |
| 570 void RenderViewContextMenu::AppendSearchProvider() { | 571 void RenderViewContextMenu::AppendSearchProvider() { |
| 571 DCHECK(profile_); | 572 DCHECK(profile_); |
| 572 | 573 |
| 573 TrimWhitespace(params_.selection_text, TRIM_ALL, ¶ms_.selection_text); | 574 TrimWhitespace(params_.selection_text, TRIM_ALL, ¶ms_.selection_text); |
| 574 if (params_.selection_text.empty()) | 575 if (params_.selection_text.empty()) |
| 575 return; | 576 return; |
| 576 | 577 |
| 577 AutocompleteMatch match; | 578 AutocompleteMatch match; |
| 578 profile_->GetAutocompleteClassifier()->Classify(params_.selection_text, | 579 profile_->GetAutocompleteClassifier()->Classify( |
| 580 UTF16ToWideHack(params_.selection_text), |
| 579 std::wstring(), false, &match, NULL); | 581 std::wstring(), false, &match, NULL); |
| 580 selection_navigation_url_ = match.destination_url; | 582 selection_navigation_url_ = match.destination_url; |
| 581 if (!selection_navigation_url_.is_valid()) | 583 if (!selection_navigation_url_.is_valid()) |
| 582 return; | 584 return; |
| 583 | 585 |
| 584 string16 printable_selection_text = PrintableSelectionText(); | 586 string16 printable_selection_text = PrintableSelectionText(); |
| 585 // Escape "&" as "&&". | 587 // Escape "&" as "&&". |
| 586 for (size_t i = printable_selection_text.find('&'); i != string16::npos; | 588 for (size_t i = printable_selection_text.find('&'); i != string16::npos; |
| 587 i = printable_selection_text.find('&', i + 2)) | 589 i = printable_selection_text.find('&', i + 2)) |
| 588 printable_selection_text.insert(i, 1, '&'); | 590 printable_selection_text.insert(i, 1, '&'); |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 // Don't enable the web inspector if the developer tools are disabled via | 1425 // Don't enable the web inspector if the developer tools are disabled via |
| 1424 // the preference dev-tools-disabled. | 1426 // the preference dev-tools-disabled. |
| 1425 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 1427 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 1426 return false; | 1428 return false; |
| 1427 } | 1429 } |
| 1428 | 1430 |
| 1429 return true; | 1431 return true; |
| 1430 } | 1432 } |
| 1431 | 1433 |
| 1432 string16 RenderViewContextMenu::PrintableSelectionText() { | 1434 string16 RenderViewContextMenu::PrintableSelectionText() { |
| 1433 return l10n_util::TruncateString(WideToUTF16Hack(params_.selection_text), | 1435 return l10n_util::TruncateString(params_.selection_text, |
| 1434 kMaxSelectionTextLength); | 1436 kMaxSelectionTextLength); |
| 1435 } | 1437 } |
| 1436 | 1438 |
| 1437 // Controller functions -------------------------------------------------------- | 1439 // Controller functions -------------------------------------------------------- |
| 1438 | 1440 |
| 1439 void RenderViewContextMenu::OpenURL( | 1441 void RenderViewContextMenu::OpenURL( |
| 1440 const GURL& url, | 1442 const GURL& url, |
| 1441 WindowOpenDisposition disposition, | 1443 WindowOpenDisposition disposition, |
| 1442 PageTransition::Type transition) { | 1444 PageTransition::Type transition) { |
| 1443 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); | 1445 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1460 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1462 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 1461 g_browser_process->clipboard()); | 1463 g_browser_process->clipboard()); |
| 1462 } | 1464 } |
| 1463 | 1465 |
| 1464 void RenderViewContextMenu::MediaPlayerActionAt( | 1466 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1465 const gfx::Point& location, | 1467 const gfx::Point& location, |
| 1466 const WebMediaPlayerAction& action) { | 1468 const WebMediaPlayerAction& action) { |
| 1467 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1469 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
| 1468 location, action); | 1470 location, action); |
| 1469 } | 1471 } |
| OLD | NEW |