OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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, |
brettw
2011/03/18 16:20:55
You accidentally added some extra space before thi
| |
1181 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, | |
brettw
2011/03/18 16:20:55
The indentation rule is align all arguments to aft
| |
1178 source_tab_contents_->delegate() && | 1182 source_tab_contents_->delegate() && |
1179 source_tab_contents_->delegate()->IsApplication() ? | 1183 source_tab_contents_->delegate()->IsApplication() ? |
1180 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, | 1184 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, |
1181 PageTransition::LINK); | 1185 PageTransition::LINK); |
1182 break; | 1186 break; |
1183 | 1187 |
1184 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: | 1188 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: |
1185 OpenURL(params_.link_url, NEW_WINDOW, PageTransition::LINK); | 1189 OpenURL(params_.link_url, |
brettw
2011/03/18 16:20:55
The indentation here should match above.
| |
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(), |
brettw
2011/03/18 16:20:55
I think this still fits on one line.
| |
1196 OFF_THE_RECORD, PageTransition::LINK); | |
1190 break; | 1197 break; |
1191 | 1198 |
1192 case IDC_CONTENT_CONTEXT_SAVEAVAS: | 1199 case IDC_CONTENT_CONTEXT_SAVEAVAS: |
1193 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: | 1200 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: |
1194 case IDC_CONTENT_CONTEXT_SAVELINKAS: { | 1201 case IDC_CONTENT_CONTEXT_SAVELINKAS: { |
1195 const GURL& referrer = | 1202 const GURL& referrer = |
1196 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; | 1203 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; |
1197 const GURL& url = | 1204 const GURL& url = |
1198 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url : | 1205 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url : |
1199 params_.src_url); | 1206 params_.src_url); |
(...skipping 11 matching lines...) Expand all Loading... | |
1211 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: | 1218 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: |
1212 WriteURLToClipboard(params_.src_url); | 1219 WriteURLToClipboard(params_.src_url); |
1213 break; | 1220 break; |
1214 | 1221 |
1215 case IDC_CONTENT_CONTEXT_COPYIMAGE: | 1222 case IDC_CONTENT_CONTEXT_COPYIMAGE: |
1216 CopyImageAt(params_.x, params_.y); | 1223 CopyImageAt(params_.x, params_.y); |
1217 break; | 1224 break; |
1218 | 1225 |
1219 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: | 1226 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
1220 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: | 1227 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: |
1221 OpenURL(params_.src_url, NEW_BACKGROUND_TAB, PageTransition::LINK); | 1228 OpenURL(params_.src_url, |
1229 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, | |
brettw
2011/03/18 16:20:55
Same as above.
| |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 // Check security policy to prevent referrer being sent |
1526 // in https to http transition. | |
1527 bool hide_referrer = WebSecurityPolicy::shouldHideReferrer( | |
1528 WebURL::WebURL(url), | |
1529 WebString::fromUTF8(WebURL::WebURL(referrer).spec())); | |
1530 source_tab_contents_->OpenURL(url, hide_referrer ? GURL() : referrer, | |
1531 disposition, transition); | |
1516 } | 1532 } |
1517 | 1533 |
1518 void RenderViewContextMenu::CopyImageAt(int x, int y) { | 1534 void RenderViewContextMenu::CopyImageAt(int x, int y) { |
1519 source_tab_contents_->render_view_host()->CopyImageAt(x, y); | 1535 source_tab_contents_->render_view_host()->CopyImageAt(x, y); |
1520 } | 1536 } |
1521 | 1537 |
1522 void RenderViewContextMenu::Inspect(int x, int y) { | 1538 void RenderViewContextMenu::Inspect(int x, int y) { |
1523 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"), | 1539 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"), |
1524 profile_); | 1540 profile_); |
1525 DevToolsManager::GetInstance()->InspectElement( | 1541 DevToolsManager::GetInstance()->InspectElement( |
1526 source_tab_contents_->render_view_host(), x, y); | 1542 source_tab_contents_->render_view_host(), x, y); |
1527 } | 1543 } |
1528 | 1544 |
1529 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { | 1545 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { |
1530 chrome_browser_net::WriteURLToClipboard( | 1546 chrome_browser_net::WriteURLToClipboard( |
1531 url, | 1547 url, |
1532 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1548 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
1533 g_browser_process->clipboard()); | 1549 g_browser_process->clipboard()); |
1534 } | 1550 } |
1535 | 1551 |
1536 void RenderViewContextMenu::MediaPlayerActionAt( | 1552 void RenderViewContextMenu::MediaPlayerActionAt( |
1537 const gfx::Point& location, | 1553 const gfx::Point& location, |
1538 const WebMediaPlayerAction& action) { | 1554 const WebMediaPlayerAction& action) { |
1539 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1555 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
1540 location, action); | 1556 location, action); |
1541 } | 1557 } |
OLD | NEW |