OLD | NEW |
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/dom_utils.h" |
10 #include "content/renderer/history_serialization.h" | 11 #include "content/renderer/history_serialization.h" |
11 #include "content/renderer/menu_item_builder.h" | 12 #include "content/renderer/menu_item_builder.h" |
12 #include "third_party/WebKit/public/web/WebElement.h" | 13 #include "third_party/WebKit/public/web/WebElement.h" |
13 #include "third_party/WebKit/public/web/WebNode.h" | 14 #include "third_party/WebKit/public/web/WebNode.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 // static | 18 // static |
18 ContextMenuParams ContextMenuParamsBuilder::Build( | 19 ContextMenuParams ContextMenuParamsBuilder::Build( |
19 const blink::WebContextMenuData& data) { | 20 const blink::WebContextMenuData& data) { |
(...skipping 28 matching lines...) Expand all Loading... |
48 params.custom_context.is_pepper_menu = false; | 49 params.custom_context.is_pepper_menu = false; |
49 for (size_t i = 0; i < data.customItems.size(); ++i) | 50 for (size_t i = 0; i < data.customItems.size(); ++i) |
50 params.custom_items.push_back(MenuItemBuilder::Build(data.customItems[i])); | 51 params.custom_items.push_back(MenuItemBuilder::Build(data.customItems[i])); |
51 | 52 |
52 if (!data.frameHistoryItem.isNull()) { | 53 if (!data.frameHistoryItem.isNull()) { |
53 params.frame_page_state = | 54 params.frame_page_state = |
54 SingleHistoryItemToPageState(data.frameHistoryItem); | 55 SingleHistoryItemToPageState(data.frameHistoryItem); |
55 } | 56 } |
56 | 57 |
57 if (!params.link_url.is_empty()) { | 58 if (!params.link_url.is_empty()) { |
58 blink::WebNode selectedNode = data.node; | 59 blink::WebNode selectedNode = DomUtils::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>(); | 60 blink::WebElement selectedElement = selectedNode.to<blink::WebElement>(); |
67 if (selectedNode.isLink() && !selectedElement.isNull()) { | 61 if (selectedNode.isLink() && !selectedElement.isNull()) { |
68 params.link_text = selectedElement.innerText(); | 62 params.link_text = selectedElement.innerText(); |
69 } else { | 63 } else { |
70 LOG(ERROR) << "Creating a ContextMenuParams for a node that has a link" | 64 LOG(ERROR) << "Creating a ContextMenuParams for a node that has a link" |
71 << "url but is not an ElementNode or does not have an" | 65 << "url but is not an ElementNode or does not have an" |
72 << "ancestor that is a link."; | 66 << "ancestor that is a link."; |
73 } | 67 } |
74 } | 68 } |
75 | 69 |
76 // Deserialize the SSL info. | 70 // Deserialize the SSL info. |
77 if (!data.securityInfo.isEmpty()) { | 71 if (!data.securityInfo.isEmpty()) { |
78 DeserializeSecurityInfo(data.securityInfo, | 72 DeserializeSecurityInfo(data.securityInfo, |
79 ¶ms.security_info.cert_id, ¶ms.security_info.cert_status, | 73 ¶ms.security_info.cert_id, ¶ms.security_info.cert_status, |
80 ¶ms.security_info.security_bits, | 74 ¶ms.security_info.security_bits, |
81 ¶ms.security_info.connection_status, | 75 ¶ms.security_info.connection_status, |
82 ¶ms.security_info.signed_certificate_timestamp_ids); | 76 ¶ms.security_info.signed_certificate_timestamp_ids); |
83 } | 77 } |
84 | 78 |
85 return params; | 79 return params; |
86 } | 80 } |
87 | 81 |
88 } // namespace content | 82 } // namespace content |
OLD | NEW |