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
3 // found in the LICENSE file.
5 #include "content/renderer/context_menu_params_builder.h"
7 #include "base/logging.h"
8 #include "content/common/ssl_status_serialization.h"
9 #include "content/public/common/context_menu_params.h"
10 #include "content/public/renderer/content_renderer_client.h"
11 #include "content/renderer/dom_utils.h"
12 #include "content/renderer/history_serialization.h"
13 #include "content/renderer/menu_item_builder.h"
14 #include "third_party/WebKit/public/web/WebElement.h"
15 #include "third_party/WebKit/public/web/WebInputElement.h"
16 #include "third_party/WebKit/public/web/WebNode.h"
21 ContextMenuParams
ContextMenuParamsBuilder::Build(
22 const blink::WebContextMenuData
& data
) {
23 ContextMenuParams params
;
24 params
.media_type
= data
.mediaType
;
25 params
.x
= data
.mousePosition
.x
;
26 params
.y
= data
.mousePosition
.y
;
27 params
.link_url
= data
.linkURL
;
28 params
.unfiltered_link_url
= data
.linkURL
;
29 params
.src_url
= data
.srcURL
;
30 params
.has_image_contents
= data
.hasImageContents
;
31 params
.page_url
= data
.pageURL
;
32 params
.keyword_url
= data
.keywordURL
;
33 params
.frame_url
= data
.frameURL
;
34 params
.media_flags
= data
.mediaFlags
;
35 params
.selection_text
= data
.selectedText
;
36 params
.title_text
= data
.titleText
;
37 params
.misspelled_word
= data
.misspelledWord
;
38 params
.misspelling_hash
= data
.misspellingHash
;
39 params
.spellcheck_enabled
= data
.isSpellCheckingEnabled
;
40 params
.is_editable
= data
.isEditable
;
41 params
.writing_direction_default
= data
.writingDirectionDefault
;
42 params
.writing_direction_left_to_right
= data
.writingDirectionLeftToRight
;
43 params
.writing_direction_right_to_left
= data
.writingDirectionRightToLeft
;
44 params
.edit_flags
= data
.editFlags
;
45 params
.frame_charset
= data
.frameEncoding
.utf8();
46 params
.referrer_policy
= data
.referrerPolicy
;
47 params
.suggested_filename
= data
.suggestedFilename
;
48 params
.input_field_type
= data
.inputFieldType
;
50 if (!data
.imageResponse
.isNull()) {
51 GetContentClient()->renderer()->AddImageContextMenuProperties(
52 data
.imageResponse
, ¶ms
.properties
);
55 for (size_t i
= 0; i
< data
.dictionarySuggestions
.size(); ++i
)
56 params
.dictionary_suggestions
.push_back(data
.dictionarySuggestions
[i
]);
58 params
.custom_context
.is_pepper_menu
= false;
59 for (size_t i
= 0; i
< data
.customItems
.size(); ++i
)
60 params
.custom_items
.push_back(MenuItemBuilder::Build(data
.customItems
[i
]));
62 if (!data
.frameHistoryItem
.isNull()) {
63 params
.frame_page_state
=
64 SingleHistoryItemToPageState(data
.frameHistoryItem
);
67 if (!params
.link_url
.is_empty()) {
68 blink::WebNode selectedNode
= DomUtils::ExtractParentAnchorNode(data
.node
);
69 blink::WebElement selectedElement
= selectedNode
.to
<blink::WebElement
>();
70 if (!selectedElement
.isNull() && selectedNode
.isLink()) {
71 params
.link_text
= selectedElement
.textContent();
73 LOG(ERROR
) << "Creating a ContextMenuParams for a node that has a link"
74 << "url but is not an ElementNode or does not have an"
75 << "ancestor that is a link.";
79 // Deserialize the SSL info.
80 if (!data
.securityInfo
.isEmpty()) {
81 DeserializeSecurityInfo(data
.securityInfo
,
82 ¶ms
.security_info
.cert_id
, ¶ms
.security_info
.cert_status
,
83 ¶ms
.security_info
.security_bits
,
84 ¶ms
.security_info
.connection_status
,
85 ¶ms
.security_info
.signed_certificate_timestamp_ids
);
91 } // namespace content