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

Side by Side Diff: content/renderer/context_menu_params_builder.cc

Issue 384243004: Make <a ping> work for context menus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/renderer/context_menu_params_builder.h" 5 #include "content/renderer/context_menu_params_builder.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/ssl_status_serialization.h" 8 #include "content/common/ssl_status_serialization.h"
9 #include "content/public/common/context_menu_params.h" 9 #include "content/public/common/context_menu_params.h"
10 #include "content/renderer/history_serialization.h" 10 #include "content/renderer/history_serialization.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 params.custom_context.is_pepper_menu = false; 48 params.custom_context.is_pepper_menu = false;
49 for (size_t i = 0; i < data.customItems.size(); ++i) 49 for (size_t i = 0; i < data.customItems.size(); ++i)
50 params.custom_items.push_back(MenuItemBuilder::Build(data.customItems[i])); 50 params.custom_items.push_back(MenuItemBuilder::Build(data.customItems[i]));
51 51
52 if (!data.frameHistoryItem.isNull()) { 52 if (!data.frameHistoryItem.isNull()) {
53 params.frame_page_state = 53 params.frame_page_state =
54 SingleHistoryItemToPageState(data.frameHistoryItem); 54 SingleHistoryItemToPageState(data.frameHistoryItem);
55 } 55 }
56 56
57 if (!params.link_url.is_empty()) { 57 if (!params.link_url.is_empty()) {
58 blink::WebNode selectedNode = data.node; 58 blink::WebNode selectedNode = extractParentAnchorNode(data.node);
59
60 // If there are other embedded tags (like <a ..>Some <b>text</b></a>)
61 // we need to extract the parent <a/> node.
62 while (!selectedNode.isLink() && !selectedNode.parentNode().isNull()) {
63 selectedNode = selectedNode.parentNode();
64 }
65
66 blink::WebElement selectedElement = selectedNode.to<blink::WebElement>(); 59 blink::WebElement selectedElement = selectedNode.to<blink::WebElement>();
67 if (selectedNode.isLink() && !selectedElement.isNull()) { 60 if (selectedNode.isLink() && !selectedElement.isNull()) {
68 params.link_text = selectedElement.innerText(); 61 params.link_text = selectedElement.innerText();
69 } else { 62 } else {
70 LOG(ERROR) << "Creating a ContextMenuParams for a node that has a link" 63 LOG(ERROR) << "Creating a ContextMenuParams for a node that has a link"
71 << "url but is not an ElementNode or does not have an" 64 << "url but is not an ElementNode or does not have an"
72 << "ancestor that is a link."; 65 << "ancestor that is a link.";
73 } 66 }
74 } 67 }
75 68
76 // Deserialize the SSL info. 69 // Deserialize the SSL info.
77 if (!data.securityInfo.isEmpty()) { 70 if (!data.securityInfo.isEmpty()) {
78 DeserializeSecurityInfo(data.securityInfo, 71 DeserializeSecurityInfo(data.securityInfo,
79 &params.security_info.cert_id, &params.security_info.cert_status, 72 &params.security_info.cert_id, &params.security_info.cert_status,
80 &params.security_info.security_bits, 73 &params.security_info.security_bits,
81 &params.security_info.connection_status, 74 &params.security_info.connection_status,
82 &params.security_info.signed_certificate_timestamp_ids); 75 &params.security_info.signed_certificate_timestamp_ids);
83 } 76 }
84 77
85 return params; 78 return params;
86 } 79 }
87 80
81 blink::WebNode ContextMenuParamsBuilder::extractParentAnchorNode(
82 const blink::WebNode& node) {
83 blink::WebNode selectedNode = node;
darin (slow to review) 2014/07/22 17:34:39 nit: selectedNode -> selected_node
Nate Chapin 2014/07/22 18:19:55 Done.
84
85 // If there are other embedded tags (like <a ..>Some <b>text</b></a>)
86 // we need to extract the parent <a/> node.
87 while (!selectedNode.isLink() && !selectedNode.parentNode().isNull())
88 selectedNode = selectedNode.parentNode();
89 return selectedNode;
90 }
91
88 } // namespace content 92 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698