Get foreground tab on Android
[chromium-blink-merge.git] / content / renderer / context_menu_params_builder.cc
bloba7783d00a681723de11049b3e342fb0725a27a2f
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/history_item_serialization.h"
11 #include "content/renderer/menu_item_builder.h"
12 #include "third_party/WebKit/public/web/WebElement.h"
13 #include "third_party/WebKit/public/web/WebNode.h"
15 namespace content {
17 // static
18 ContextMenuParams ContextMenuParamsBuilder::Build(
19 const blink::WebContextMenuData& data) {
20 ContextMenuParams params;
21 params.media_type = data.mediaType;
22 params.x = data.mousePosition.x;
23 params.y = data.mousePosition.y;
24 params.link_url = data.linkURL;
25 params.unfiltered_link_url = data.linkURL;
26 params.src_url = data.srcURL;
27 params.has_image_contents = data.hasImageContents;
28 params.page_url = data.pageURL;
29 params.keyword_url = data.keywordURL;
30 params.frame_url = data.frameURL;
31 params.media_flags = data.mediaFlags;
32 params.selection_text = data.selectedText;
33 params.misspelled_word = data.misspelledWord;
34 params.misspelling_hash = data.misspellingHash;
35 params.speech_input_enabled = data.isSpeechInputEnabled;
36 params.spellcheck_enabled = data.isSpellCheckingEnabled;
37 params.is_editable = data.isEditable;
38 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
39 params.writing_direction_default = data.writingDirectionDefault;
40 params.writing_direction_left_to_right = data.writingDirectionLeftToRight;
41 params.writing_direction_right_to_left = data.writingDirectionRightToLeft;
42 #endif // OS_MACOSX || defined(TOOLKIT_GTK)
43 params.edit_flags = data.editFlags;
44 params.frame_charset = data.frameEncoding.utf8();
45 params.referrer_policy = data.referrerPolicy;
47 for (size_t i = 0; i < data.dictionarySuggestions.size(); ++i)
48 params.dictionary_suggestions.push_back(data.dictionarySuggestions[i]);
50 params.custom_context.is_pepper_menu = false;
51 for (size_t i = 0; i < data.customItems.size(); ++i)
52 params.custom_items.push_back(MenuItemBuilder::Build(data.customItems[i]));
54 if (!data.frameHistoryItem.isNull())
55 params.frame_page_state = HistoryItemToPageState(data.frameHistoryItem);
57 if (!params.link_url.is_empty()) {
58 blink::WebNode selectedNode = data.node;
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();
66 blink::WebElement selectedElement = selectedNode.to<blink::WebElement>();
67 if (selectedNode.isLink() && !selectedElement.isNull()) {
68 params.link_text = selectedElement.innerText();
69 } else {
70 LOG(ERROR) << "Creating a ContextMenuParams for a node that has a link"
71 << "url but is not an ElementNode or does not have an"
72 << "ancestor that is a link.";
76 // Deserialize the SSL info.
77 if (!data.securityInfo.isEmpty()) {
78 DeserializeSecurityInfo(data.securityInfo,
79 &params.security_info.cert_id,
80 &params.security_info.cert_status,
81 &params.security_info.security_bits,
82 &params.security_info.connection_status);
85 return params;
88 } // namespace content