Chromium Code Reviews| 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( |
| 1178 source_tab_contents_->delegate() && | 1181 params_.link_url, |
| 1182 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, | |
| 1183 source_tab_contents_->delegate() && | |
| 1179 source_tab_contents_->delegate()->IsApplication() ? | 1184 source_tab_contents_->delegate()->IsApplication() ? |
| 1180 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, | 1185 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB, |
| 1181 PageTransition::LINK); | 1186 PageTransition::LINK); |
| 1182 break; | 1187 break; |
| 1183 | 1188 |
| 1184 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: | 1189 case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: |
| 1185 OpenURL(params_.link_url, NEW_WINDOW, PageTransition::LINK); | 1190 OpenURL( |
| 1191 params_.link_url, | |
| 1192 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, | |
| 1193 NEW_WINDOW, PageTransition::LINK); | |
| 1186 break; | 1194 break; |
| 1187 | 1195 |
| 1188 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: | 1196 case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: |
| 1189 OpenURL(params_.link_url, OFF_THE_RECORD, PageTransition::LINK); | 1197 OpenURL(params_.link_url, GURL(), OFF_THE_RECORD, PageTransition::LINK); |
| 1190 break; | 1198 break; |
| 1191 | 1199 |
| 1192 case IDC_CONTENT_CONTEXT_SAVEAVAS: | 1200 case IDC_CONTENT_CONTEXT_SAVEAVAS: |
| 1193 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: | 1201 case IDC_CONTENT_CONTEXT_SAVEIMAGEAS: |
| 1194 case IDC_CONTENT_CONTEXT_SAVELINKAS: { | 1202 case IDC_CONTENT_CONTEXT_SAVELINKAS: { |
| 1195 const GURL& referrer = | 1203 const GURL& referrer = |
| 1196 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; | 1204 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; |
| 1197 const GURL& url = | 1205 const GURL& url = |
| 1198 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url : | 1206 (id == IDC_CONTENT_CONTEXT_SAVELINKAS ? params_.link_url : |
| 1199 params_.src_url); | 1207 params_.src_url); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1211 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: | 1219 case IDC_CONTENT_CONTEXT_COPYAVLOCATION: |
| 1212 WriteURLToClipboard(params_.src_url); | 1220 WriteURLToClipboard(params_.src_url); |
| 1213 break; | 1221 break; |
| 1214 | 1222 |
| 1215 case IDC_CONTENT_CONTEXT_COPYIMAGE: | 1223 case IDC_CONTENT_CONTEXT_COPYIMAGE: |
| 1216 CopyImageAt(params_.x, params_.y); | 1224 CopyImageAt(params_.x, params_.y); |
| 1217 break; | 1225 break; |
| 1218 | 1226 |
| 1219 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: | 1227 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
| 1220 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: | 1228 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: |
| 1221 OpenURL(params_.src_url, NEW_BACKGROUND_TAB, PageTransition::LINK); | 1229 OpenURL( |
| 1230 params_.src_url, | |
| 1231 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url, | |
| 1232 NEW_BACKGROUND_TAB, PageTransition::LINK); | |
| 1222 break; | 1233 break; |
| 1223 | 1234 |
| 1224 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { | 1235 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { |
| 1225 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); | 1236 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); |
| 1226 if (play) { | 1237 if (play) { |
| 1227 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Play"), | 1238 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Play"), |
| 1228 profile_); | 1239 profile_); |
| 1229 } else { | 1240 } else { |
| 1230 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Pause"), | 1241 UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Pause"), |
| 1231 profile_); | 1242 profile_); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1332 source_tab_contents_, original_lang, target_lang); | 1343 source_tab_contents_, original_lang, target_lang); |
| 1333 break; | 1344 break; |
| 1334 } | 1345 } |
| 1335 | 1346 |
| 1336 case IDC_CONTENT_CONTEXT_RELOADFRAME: | 1347 case IDC_CONTENT_CONTEXT_RELOADFRAME: |
| 1337 source_tab_contents_->render_view_host()->ReloadFrame(); | 1348 source_tab_contents_->render_view_host()->ReloadFrame(); |
| 1338 break; | 1349 break; |
| 1339 | 1350 |
| 1340 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: | 1351 case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: |
| 1341 OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") + | 1352 OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") + |
| 1342 params_.frame_url.spec()), NEW_FOREGROUND_TAB, PageTransition::LINK); | 1353 params_.frame_url.spec()), GURL(), |
| 1354 NEW_FOREGROUND_TAB, PageTransition::LINK); | |
| 1343 break; | 1355 break; |
| 1344 | 1356 |
| 1345 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: { | 1357 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: { |
| 1346 // Deserialize the SSL info. | 1358 // Deserialize the SSL info. |
| 1347 NavigationEntry::SSLStatus ssl; | 1359 NavigationEntry::SSLStatus ssl; |
| 1348 if (!params_.security_info.empty()) { | 1360 if (!params_.security_info.empty()) { |
| 1349 int cert_id, cert_status, security_bits, connection_status; | 1361 int cert_id, cert_status, security_bits, connection_status; |
| 1350 SSLManager::DeserializeSecurityInfo(params_.security_info, | 1362 SSLManager::DeserializeSecurityInfo(params_.security_info, |
| 1351 &cert_id, | 1363 &cert_id, |
| 1352 &cert_status, | 1364 &cert_status, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1385 case IDC_CONTENT_CONTEXT_DELETE: | 1397 case IDC_CONTENT_CONTEXT_DELETE: |
| 1386 source_tab_contents_->render_view_host()->Delete(); | 1398 source_tab_contents_->render_view_host()->Delete(); |
| 1387 break; | 1399 break; |
| 1388 | 1400 |
| 1389 case IDC_CONTENT_CONTEXT_SELECTALL: | 1401 case IDC_CONTENT_CONTEXT_SELECTALL: |
| 1390 source_tab_contents_->render_view_host()->SelectAll(); | 1402 source_tab_contents_->render_view_host()->SelectAll(); |
| 1391 break; | 1403 break; |
| 1392 | 1404 |
| 1393 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: | 1405 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: |
| 1394 case IDC_CONTENT_CONTEXT_GOTOURL: { | 1406 case IDC_CONTENT_CONTEXT_GOTOURL: { |
| 1395 OpenURL(selection_navigation_url_, NEW_FOREGROUND_TAB, | 1407 OpenURL(selection_navigation_url_, GURL(), NEW_FOREGROUND_TAB, |
| 1396 PageTransition::LINK); | 1408 PageTransition::LINK); |
| 1397 break; | 1409 break; |
| 1398 } | 1410 } |
| 1399 | 1411 |
| 1400 case IDC_SPELLCHECK_SUGGESTION_0: | 1412 case IDC_SPELLCHECK_SUGGESTION_0: |
| 1401 case IDC_SPELLCHECK_SUGGESTION_1: | 1413 case IDC_SPELLCHECK_SUGGESTION_1: |
| 1402 case IDC_SPELLCHECK_SUGGESTION_2: | 1414 case IDC_SPELLCHECK_SUGGESTION_2: |
| 1403 case IDC_SPELLCHECK_SUGGESTION_3: | 1415 case IDC_SPELLCHECK_SUGGESTION_3: |
| 1404 case IDC_SPELLCHECK_SUGGESTION_4: | 1416 case IDC_SPELLCHECK_SUGGESTION_4: |
| 1405 source_tab_contents_->render_view_host()->Replace( | 1417 source_tab_contents_->render_view_host()->Replace( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1502 } | 1514 } |
| 1503 | 1515 |
| 1504 string16 RenderViewContextMenu::PrintableSelectionText() { | 1516 string16 RenderViewContextMenu::PrintableSelectionText() { |
| 1505 return l10n_util::TruncateString(params_.selection_text, | 1517 return l10n_util::TruncateString(params_.selection_text, |
| 1506 kMaxSelectionTextLength); | 1518 kMaxSelectionTextLength); |
| 1507 } | 1519 } |
| 1508 | 1520 |
| 1509 // Controller functions -------------------------------------------------------- | 1521 // Controller functions -------------------------------------------------------- |
| 1510 | 1522 |
| 1511 void RenderViewContextMenu::OpenURL( | 1523 void RenderViewContextMenu::OpenURL( |
| 1512 const GURL& url, | 1524 const GURL& url, const GURL& referrer, |
| 1513 WindowOpenDisposition disposition, | 1525 WindowOpenDisposition disposition, |
| 1514 PageTransition::Type transition) { | 1526 PageTransition::Type transition) { |
| 1515 source_tab_contents_->OpenURL(url, GURL(), disposition, transition); | 1527 // Check security policy to prevent referrer being sent |
| 1528 // in https to http transition. | |
| 1529 bool hide_referrer = WebSecurityPolicy::shouldHideReferrer( | |
|
darin (slow to review)
2011/04/13 16:38:32
we try to avoid using webkit on the main thread of
brettw
2011/04/13 17:43:20
I don't see this getting called in the new tab cas
| |
| 1530 WebURL::WebURL(url), | |
| 1531 WebString::fromUTF8(WebURL::WebURL(referrer).spec())); | |
| 1532 source_tab_contents_->OpenURL(url, hide_referrer ? GURL() : referrer, | |
| 1533 disposition, transition); | |
| 1516 } | 1534 } |
| 1517 | 1535 |
| 1518 void RenderViewContextMenu::CopyImageAt(int x, int y) { | 1536 void RenderViewContextMenu::CopyImageAt(int x, int y) { |
| 1519 source_tab_contents_->render_view_host()->CopyImageAt(x, y); | 1537 source_tab_contents_->render_view_host()->CopyImageAt(x, y); |
| 1520 } | 1538 } |
| 1521 | 1539 |
| 1522 void RenderViewContextMenu::Inspect(int x, int y) { | 1540 void RenderViewContextMenu::Inspect(int x, int y) { |
| 1523 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"), | 1541 UserMetrics::RecordAction(UserMetricsAction("DevTools_InspectElement"), |
| 1524 profile_); | 1542 profile_); |
| 1525 DevToolsManager::GetInstance()->InspectElement( | 1543 DevToolsManager::GetInstance()->InspectElement( |
| 1526 source_tab_contents_->render_view_host(), x, y); | 1544 source_tab_contents_->render_view_host(), x, y); |
| 1527 } | 1545 } |
| 1528 | 1546 |
| 1529 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { | 1547 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { |
| 1530 chrome_browser_net::WriteURLToClipboard( | 1548 chrome_browser_net::WriteURLToClipboard( |
| 1531 url, | 1549 url, |
| 1532 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1550 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 1533 g_browser_process->clipboard()); | 1551 g_browser_process->clipboard()); |
| 1534 } | 1552 } |
| 1535 | 1553 |
| 1536 void RenderViewContextMenu::MediaPlayerActionAt( | 1554 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1537 const gfx::Point& location, | 1555 const gfx::Point& location, |
| 1538 const WebMediaPlayerAction& action) { | 1556 const WebMediaPlayerAction& action) { |
| 1539 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 1557 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
| 1540 location, action); | 1558 location, action); |
| 1541 } | 1559 } |
| OLD | NEW |