Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 6681030: Requesting Review for BugFix Chromium:1935 (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "chrome/common/chrome_constants.h" 45 #include "chrome/common/chrome_constants.h"
46 #include "chrome/common/chrome_switches.h" 46 #include "chrome/common/chrome_switches.h"
47 #include "chrome/common/content_restriction.h" 47 #include "chrome/common/content_restriction.h"
48 #include "chrome/common/pref_names.h" 48 #include "chrome/common/pref_names.h"
49 #include "chrome/common/url_constants.h" 49 #include "chrome/common/url_constants.h"
50 #include "grit/generated_resources.h" 50 #include "grit/generated_resources.h"
51 #include "net/base/escape.h" 51 #include "net/base/escape.h"
52 #include "net/url_request/url_request.h" 52 #include "net/url_request/url_request.h"
53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction. h" 54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction. h"
55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
56 #include "ui/base/l10n/l10n_util.h" 55 #include "ui/base/l10n/l10n_util.h"
57 #include "ui/gfx/favicon_size.h" 56 #include "ui/gfx/favicon_size.h"
58 #include "webkit/glue/webmenuitem.h" 57 #include "webkit/glue/webmenuitem.h"
59 58
60 using WebKit::WebContextMenuData; 59 using WebKit::WebContextMenuData;
61 using WebKit::WebMediaPlayerAction; 60 using WebKit::WebMediaPlayerAction;
61 using WebKit::WebURL;
62 using WebKit::WebString;
62 63
63 namespace { 64 namespace {
64 65
65 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) { 66 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) {
66 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && 67 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST &&
67 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST); 68 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST);
68 for (size_t i = 0; i < items.size(); ++i) { 69 for (size_t i = 0; i < items.size(); ++i) {
69 int action_id = IDC_CONTENT_CONTEXT_CUSTOM_FIRST + items[i].action; 70 int action_id = IDC_CONTENT_CONTEXT_CUSTOM_FIRST + items[i].action;
70 if (action_id == id) 71 if (action_id == id)
71 return items[i].enabled; 72 return items[i].enabled;
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 if (i != extension_item_map_.end()) { 1168 if (i != extension_item_map_.end()) {
1168 manager->ExecuteCommand(profile_, source_tab_contents_, params_, 1169 manager->ExecuteCommand(profile_, source_tab_contents_, params_,
1169 i->second); 1170 i->second);
1170 } 1171 }
1171 return; 1172 return;
1172 } 1173 }
1173 1174
1174 1175
1175 switch (id) { 1176 switch (id) {
1176 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: 1177 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
1177 OpenURL(params_.link_url, 1178 OpenURL(
1178 source_tab_contents_->delegate() && 1179 params_.link_url,
1180 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url,
1181 source_tab_contents_->delegate() &&
1179 source_tab_contents_->delegate()->IsApplication() ? 1182 source_tab_contents_->delegate()->IsApplication() ?
1180 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, 1183 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB,
1181 PageTransition::LINK); 1184 PageTransition::LINK);
1182 break; 1185 break;
1183 1186
1184 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: 1187 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
1185 OpenURL(params_.link_url, NEW_WINDOW, PageTransition::LINK); 1188 OpenURL(
1189 params_.link_url,
1190 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url,
1191 NEW_WINDOW, PageTransition::LINK);
1186 break; 1192 break;
1187 1193
1188 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: 1194 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
1189 OpenURL(params_.link_url, OFF_THE_RECORD, PageTransition::LINK); 1195 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, PageTransition::LINK);
1190 break; 1196 break;
1191 1197
1192 case IDC_CONTENT_CONTEXT_SAVEAVAS: 1198 case IDC_CONTENT_CONTEXT_SAVEAVAS:
1193 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: 1199 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS:
1194 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1200 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
1195 const GURL& referrer = 1201 const GURL& referrer =
1196 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; 1202 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
1197 const GURL& url = 1203 const GURL& url =
1198 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url : 1204 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url :
1199 params_.src_url); 1205 params_.src_url);
(...skipping 11 matching lines...) Expand all
1211 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: 1217 case IDC_CONTENT_CONTEXT_COPYAVLOCATION:
1212 WriteURLToClipboard(params_.src_url); 1218 WriteURLToClipboard(params_.src_url);
1213 break; 1219 break;
1214 1220
1215 case IDC_CONTENT_CONTEXT_COPYIMAGE: 1221 case IDC_CONTENT_CONTEXT_COPYIMAGE:
1216 CopyImageAt(params_.x, params_.y); 1222 CopyImageAt(params_.x, params_.y);
1217 break; 1223 break;
1218 1224
1219 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: 1225 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
1220 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: 1226 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB:
1221 OpenURL(params_.src_url, NEW_BACKGROUND_TAB, PageTransition::LINK); 1227 OpenURL(
1228 params_.src_url,
1229 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url,
1230 NEW_BACKGROUND_TAB, PageTransition::LINK);
1222 break; 1231 break;
1223 1232
1224 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { 1233 case IDC_CONTENT_CONTEXT_PLAYPAUSE: {
1225 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); 1234 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused);
1226 if (play) { 1235 if (play) {
1227 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Play"), 1236 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Play"),
1228 profile_); 1237 profile_);
1229 } else { 1238 } else {
1230 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Pause"), 1239 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Pause"),
1231 profile_); 1240 profile_);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 source_tab_contents_, original_lang, target_lang); 1341 source_tab_contents_, original_lang, target_lang);
1333 break; 1342 break;
1334 } 1343 }
1335 1344
1336 case IDC_CONTENT_CONTEXT_RELOADFRAME: 1345 case IDC_CONTENT_CONTEXT_RELOADFRAME:
1337 source_tab_contents_->render_view_host()->ReloadFrame(); 1346 source_tab_contents_->render_view_host()->ReloadFrame();
1338 break; 1347 break;
1339 1348
1340 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: 1349 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE:
1341 OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") + 1350 OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") +
1342 params_.frame_url.spec()), NEW_FOREGROUND_TAB, PageTransition::LINK); 1351 params_.frame_url.spec()), GURL(),
1352 NEW_FOREGROUND_TAB, PageTransition::LINK);
1343 break; 1353 break;
1344 1354
1345 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: { 1355 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: {
1346 // Deserialize the SSL info. 1356 // Deserialize the SSL info.
1347 NavigationEntry::SSLStatus ssl; 1357 NavigationEntry::SSLStatus ssl;
1348 if (!params_.security_info.empty()) { 1358 if (!params_.security_info.empty()) {
1349 int cert_id, cert_status, security_bits, connection_status; 1359 int cert_id, cert_status, security_bits, connection_status;
1350 SSLManager::DeserializeSecurityInfo(params_.security_info, 1360 SSLManager::DeserializeSecurityInfo(params_.security_info,
1351 &cert_id, 1361 &cert_id,
1352 &cert_status, 1362 &cert_status,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 case IDC_CONTENT_CONTEXT_DELETE: 1395 case IDC_CONTENT_CONTEXT_DELETE:
1386 source_tab_contents_->render_view_host()->Delete(); 1396 source_tab_contents_->render_view_host()->Delete();
1387 break; 1397 break;
1388 1398
1389 case IDC_CONTENT_CONTEXT_SELECTALL: 1399 case IDC_CONTENT_CONTEXT_SELECTALL:
1390 source_tab_contents_->render_view_host()->SelectAll(); 1400 source_tab_contents_->render_view_host()->SelectAll();
1391 break; 1401 break;
1392 1402
1393 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: 1403 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR:
1394 case IDC_CONTENT_CONTEXT_GOTOURL: { 1404 case IDC_CONTENT_CONTEXT_GOTOURL: {
1395 OpenURL(selection_navigation_url_, NEW_FOREGROUND_TAB, 1405 OpenURL(selection_navigation_url_, GURL(), NEW_FOREGROUND_TAB,
1396 PageTransition::LINK); 1406 PageTransition::LINK);
1397 break; 1407 break;
1398 } 1408 }
1399 1409
1400 case IDC_SPELLCHECK_SUGGESTION_0: 1410 case IDC_SPELLCHECK_SUGGESTION_0:
1401 case IDC_SPELLCHECK_SUGGESTION_1: 1411 case IDC_SPELLCHECK_SUGGESTION_1:
1402 case IDC_SPELLCHECK_SUGGESTION_2: 1412 case IDC_SPELLCHECK_SUGGESTION_2:
1403 case IDC_SPELLCHECK_SUGGESTION_3: 1413 case IDC_SPELLCHECK_SUGGESTION_3:
1404 case IDC_SPELLCHECK_SUGGESTION_4: 1414 case IDC_SPELLCHECK_SUGGESTION_4:
1405 source_tab_contents_->render_view_host()->Replace( 1415 source_tab_contents_->render_view_host()->Replace(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 } 1512 }
1503 1513
1504 string16 RenderViewContextMenu::PrintableSelectionText() { 1514 string16 RenderViewContextMenu::PrintableSelectionText() {
1505 return l10n_util::TruncateString(params_.selection_text, 1515 return l10n_util::TruncateString(params_.selection_text,
1506 kMaxSelectionTextLength); 1516 kMaxSelectionTextLength);
1507 } 1517 }
1508 1518
1509 // Controller functions -------------------------------------------------------- 1519 // Controller functions --------------------------------------------------------
1510 1520
1511 void RenderViewContextMenu::OpenURL( 1521 void RenderViewContextMenu::OpenURL(
1512 const GURL& url, 1522 const GURL& url, const GURL& referrer,
1513 WindowOpenDisposition disposition, 1523 WindowOpenDisposition disposition,
1514 PageTransition::Type transition) { 1524 PageTransition::Type transition) {
1515 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); 1525 source_tab_contents_->OpenURL(url, referrer, disposition, transition);
1516 } 1526 }
1517 1527
1518 void RenderViewContextMenu::CopyImageAt(int x, int y) { 1528 void RenderViewContextMenu::CopyImageAt(int x, int y) {
1519 source_tab_contents_->render_view_host()->CopyImageAt(x, y); 1529 source_tab_contents_->render_view_host()->CopyImageAt(x, y);
1520 } 1530 }
1521 1531
1522 void RenderViewContextMenu::Inspect(int x, int y) { 1532 void RenderViewContextMenu::Inspect(int x, int y) {
1523 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"), 1533 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"),
1524 profile_); 1534 profile_);
1525 DevToolsManager::GetInstance()->InspectElement( 1535 DevToolsManager::GetInstance()->InspectElement(
1526 source_tab_contents_->render_view_host(), x, y); 1536 source_tab_contents_->render_view_host(), x, y);
1527 } 1537 }
1528 1538
1529 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { 1539 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) {
1530 chrome_browser_net::WriteURLToClipboard( 1540 chrome_browser_net::WriteURLToClipboard(
1531 url, 1541 url,
1532 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1542 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1533 g_browser_process->clipboard()); 1543 g_browser_process->clipboard());
1534 } 1544 }
1535 1545
1536 void RenderViewContextMenu::MediaPlayerActionAt( 1546 void RenderViewContextMenu::MediaPlayerActionAt(
1537 const gfx::Point& location, 1547 const gfx::Point& location,
1538 const WebMediaPlayerAction& action) { 1548 const WebMediaPlayerAction& action) {
1539 source_tab_contents_->render_view_host()->MediaPlayerActionAt( 1549 source_tab_contents_->render_view_host()->MediaPlayerActionAt(
1540 location, action); 1550 location, action);
1541 } 1551 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698