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

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, 9 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') | no next file » | 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" 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
56 #include "ui/base/l10n/l10n_util.h" 56 #include "ui/base/l10n/l10n_util.h"
57 #include "ui/gfx/favicon_size.h" 57 #include "ui/gfx/favicon_size.h"
58 #include "webkit/glue/webmenuitem.h" 58 #include "webkit/glue/webmenuitem.h"
59 59
60 using WebKit::WebContextMenuData; 60 using WebKit::WebContextMenuData;
61 using WebKit::WebMediaPlayerAction; 61 using WebKit::WebMediaPlayerAction;
62 using WebKit::WebSecurityPolicy;
63 using WebKit::WebURL;
64 using WebKit::WebString;
62 65
63 namespace { 66 namespace {
64 67
65 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) { 68 bool IsCustomItemEnabled(const std::vector<WebMenuItem>& items, int id) {
66 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && 69 DCHECK(id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST &&
67 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST); 70 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST);
68 for (size_t i = 0; i < items.size(); ++i) { 71 for (size_t i = 0; i < items.size(); ++i) {
69 int action_id = IDC_CONTENT_CONTEXT_CUSTOM_FIRST + items[i].action; 72 int action_id = IDC_CONTENT_CONTEXT_CUSTOM_FIRST + items[i].action;
70 if (action_id == id) 73 if (action_id == id)
71 return items[i].enabled; 74 return items[i].enabled;
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 if (i != extension_item_map_.end()) { 1170 if (i != extension_item_map_.end()) {
1168 manager->ExecuteCommand(profile_, source_tab_contents_, params_, 1171 manager->ExecuteCommand(profile_, source_tab_contents_, params_,
1169 i->second); 1172 i->second);
1170 } 1173 }
1171 return; 1174 return;
1172 } 1175 }
1173 1176
1174 1177
1175 switch (id) { 1178 switch (id) {
1176 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: 1179 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB:
1177 OpenURL(params_.link_url, 1180 OpenURL(params_.link_url, params_.page_url,
1178 source_tab_contents_->delegate() && 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(params_.link_url, params_.page_url,
1189 NEW_WINDOW, PageTransition::LINK);
1186 break; 1190 break;
1187 1191
1188 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: 1192 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:
1189 OpenURL(params_.link_url, OFF_THE_RECORD, PageTransition::LINK); 1193 OpenURL(params_.link_url, GURL(),
1194 OFF_THE_RECORD, PageTransition::LINK);
1190 break; 1195 break;
1191 1196
1192 case IDC_CONTENT_CONTEXT_SAVEAVAS: 1197 case IDC_CONTENT_CONTEXT_SAVEAVAS:
1193 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: 1198 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS:
1194 case IDC_CONTENT_CONTEXT_SAVELINKAS: { 1199 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
1195 const GURL& referrer = 1200 const GURL& referrer =
1196 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; 1201 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url;
1197 const GURL& url = 1202 const GURL& url =
1198 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url : 1203 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url :
1199 params_.src_url); 1204 params_.src_url);
(...skipping 11 matching lines...) Expand all
1211 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: 1216 case IDC_CONTENT_CONTEXT_COPYAVLOCATION:
1212 WriteURLToClipboard(params_.src_url); 1217 WriteURLToClipboard(params_.src_url);
1213 break; 1218 break;
1214 1219
1215 case IDC_CONTENT_CONTEXT_COPYIMAGE: 1220 case IDC_CONTENT_CONTEXT_COPYIMAGE:
1216 CopyImageAt(params_.x, params_.y); 1221 CopyImageAt(params_.x, params_.y);
1217 break; 1222 break;
1218 1223
1219 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: 1224 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
1220 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: 1225 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB:
1221 OpenURL(params_.src_url, NEW_BACKGROUND_TAB, PageTransition::LINK); 1226 OpenURL(params_.src_url, params_.page_url,
1227 NEW_BACKGROUND_TAB, PageTransition::LINK);
1222 break; 1228 break;
1223 1229
1224 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { 1230 case IDC_CONTENT_CONTEXT_PLAYPAUSE: {
1225 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); 1231 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused);
1226 if (play) { 1232 if (play) {
1227 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Play"), 1233 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Play"),
1228 profile_); 1234 profile_);
1229 } else { 1235 } else {
1230 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Pause"), 1236 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Pause"),
1231 profile_); 1237 profile_);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 source_tab_contents_, original_lang, target_lang); 1338 source_tab_contents_, original_lang, target_lang);
1333 break; 1339 break;
1334 } 1340 }
1335 1341
1336 case IDC_CONTENT_CONTEXT_RELOADFRAME: 1342 case IDC_CONTENT_CONTEXT_RELOADFRAME:
1337 source_tab_contents_->render_view_host()->ReloadFrame(); 1343 source_tab_contents_->render_view_host()->ReloadFrame();
1338 break; 1344 break;
1339 1345
1340 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: 1346 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE:
1341 OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") + 1347 OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") +
1342 params_.frame_url.spec()), NEW_FOREGROUND_TAB, PageTransition::LINK); 1348 params_.frame_url.spec()), GURL(),
1349 NEW_FOREGROUND_TAB, PageTransition::LINK);
1343 break; 1350 break;
1344 1351
1345 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: { 1352 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: {
1346 // Deserialize the SSL info. 1353 // Deserialize the SSL info.
1347 NavigationEntry::SSLStatus ssl; 1354 NavigationEntry::SSLStatus ssl;
1348 if (!params_.security_info.empty()) { 1355 if (!params_.security_info.empty()) {
1349 int cert_id, cert_status, security_bits, connection_status; 1356 int cert_id, cert_status, security_bits, connection_status;
1350 SSLManager::DeserializeSecurityInfo(params_.security_info, 1357 SSLManager::DeserializeSecurityInfo(params_.security_info,
1351 &cert_id, 1358 &cert_id,
1352 &cert_status, 1359 &cert_status,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 case IDC_CONTENT_CONTEXT_DELETE: 1392 case IDC_CONTENT_CONTEXT_DELETE:
1386 source_tab_contents_->render_view_host()->Delete(); 1393 source_tab_contents_->render_view_host()->Delete();
1387 break; 1394 break;
1388 1395
1389 case IDC_CONTENT_CONTEXT_SELECTALL: 1396 case IDC_CONTENT_CONTEXT_SELECTALL:
1390 source_tab_contents_->render_view_host()->SelectAll(); 1397 source_tab_contents_->render_view_host()->SelectAll();
1391 break; 1398 break;
1392 1399
1393 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: 1400 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR:
1394 case IDC_CONTENT_CONTEXT_GOTOURL: { 1401 case IDC_CONTENT_CONTEXT_GOTOURL: {
1395 OpenURL(selection_navigation_url_, NEW_FOREGROUND_TAB, 1402 OpenURL(selection_navigation_url_, GURL(), NEW_FOREGROUND_TAB,
1396 PageTransition::LINK); 1403 PageTransition::LINK);
1397 break; 1404 break;
1398 } 1405 }
1399 1406
1400 case IDC_SPELLCHECK_SUGGESTION_0: 1407 case IDC_SPELLCHECK_SUGGESTION_0:
1401 case IDC_SPELLCHECK_SUGGESTION_1: 1408 case IDC_SPELLCHECK_SUGGESTION_1:
1402 case IDC_SPELLCHECK_SUGGESTION_2: 1409 case IDC_SPELLCHECK_SUGGESTION_2:
1403 case IDC_SPELLCHECK_SUGGESTION_3: 1410 case IDC_SPELLCHECK_SUGGESTION_3:
1404 case IDC_SPELLCHECK_SUGGESTION_4: 1411 case IDC_SPELLCHECK_SUGGESTION_4:
1405 source_tab_contents_->render_view_host()->Replace( 1412 source_tab_contents_->render_view_host()->Replace(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 } 1509 }
1503 1510
1504 string16 RenderViewContextMenu::PrintableSelectionText() { 1511 string16 RenderViewContextMenu::PrintableSelectionText() {
1505 return l10n_util::TruncateString(params_.selection_text, 1512 return l10n_util::TruncateString(params_.selection_text,
1506 kMaxSelectionTextLength); 1513 kMaxSelectionTextLength);
1507 } 1514 }
1508 1515
1509 // Controller functions -------------------------------------------------------- 1516 // Controller functions --------------------------------------------------------
1510 1517
1511 void RenderViewContextMenu::OpenURL( 1518 void RenderViewContextMenu::OpenURL(
1512 const GURL& url, 1519 const GURL& url, const GURL& referrer,
1513 WindowOpenDisposition disposition, 1520 WindowOpenDisposition disposition,
1514 PageTransition::Type transition) { 1521 PageTransition::Type transition) {
1515 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); 1522 // Check security policy to prevent referrer being sent
brettw 2011/03/14 19:51:37 Should be indented 2 spaces.
1523 // in https to http transition.
1524 bool hideReferrer = WebSecurityPolicy::shouldHideReferrer(
brettw 2011/03/14 19:51:37 Should be "hide_referrer"
1525 WebURL::WebURL(url),
1526 WebString::fromUTF8(WebURL::WebURL(referrer).spec()));
1527 source_tab_contents_->OpenURL(url, hideReferrer ? GURL() : referrer,
1528 disposition, transition);
1516 } 1529 }
1517 1530
1518 void RenderViewContextMenu::CopyImageAt(int x, int y) { 1531 void RenderViewContextMenu::CopyImageAt(int x, int y) {
1519 source_tab_contents_->render_view_host()->CopyImageAt(x, y); 1532 source_tab_contents_->render_view_host()->CopyImageAt(x, y);
1520 } 1533 }
1521 1534
1522 void RenderViewContextMenu::Inspect(int x, int y) { 1535 void RenderViewContextMenu::Inspect(int x, int y) {
1523 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"), 1536 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"),
1524 profile_); 1537 profile_);
1525 DevToolsManager::GetInstance()->InspectElement( 1538 DevToolsManager::GetInstance()->InspectElement(
1526 source_tab_contents_->render_view_host(), x, y); 1539 source_tab_contents_->render_view_host(), x, y);
1527 } 1540 }
1528 1541
1529 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { 1542 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) {
1530 chrome_browser_net::WriteURLToClipboard( 1543 chrome_browser_net::WriteURLToClipboard(
1531 url, 1544 url,
1532 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1545 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1533 g_browser_process->clipboard()); 1546 g_browser_process->clipboard());
1534 } 1547 }
1535 1548
1536 void RenderViewContextMenu::MediaPlayerActionAt( 1549 void RenderViewContextMenu::MediaPlayerActionAt(
1537 const gfx::Point& location, 1550 const gfx::Point& location,
1538 const WebMediaPlayerAction& action) { 1551 const WebMediaPlayerAction& action) {
1539 source_tab_contents_->render_view_host()->MediaPlayerActionAt( 1552 source_tab_contents_->render_view_host()->MediaPlayerActionAt(
1540 location, action); 1553 location, action);
1541 } 1554 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698