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 "content/public/common/context_menu_params.h" | 5 #include "content/public/common/context_menu_params.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "content/common/ssl_status_serialization.h" | |
9 #include "webkit/glue/glue_serialize.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | |
12 | |
13 namespace content { | 7 namespace content { |
14 | 8 |
15 const int32 CustomContextMenuContext::kCurrentRenderWidget = kint32max; | 9 const int32 CustomContextMenuContext::kCurrentRenderWidget = kint32max; |
16 | 10 |
17 CustomContextMenuContext::CustomContextMenuContext() | 11 CustomContextMenuContext::CustomContextMenuContext() |
18 : is_pepper_menu(false), | 12 : is_pepper_menu(false), |
19 request_id(0), | 13 request_id(0), |
20 render_widget_id(kCurrentRenderWidget) { | 14 render_widget_id(kCurrentRenderWidget) { |
21 } | 15 } |
22 | 16 |
23 ContextMenuParams::ContextMenuParams() | 17 ContextMenuParams::ContextMenuParams() |
24 : media_type(WebKit::WebContextMenuData::MediaTypeNone), | 18 : media_type(WebKit::WebContextMenuData::MediaTypeNone), |
25 x(0), | 19 x(0), |
26 y(0), | 20 y(0), |
27 is_image_blocked(false), | 21 is_image_blocked(false), |
28 frame_id(0), | 22 frame_id(0), |
29 media_flags(0), | 23 media_flags(0), |
30 speech_input_enabled(false), | 24 speech_input_enabled(false), |
31 spellcheck_enabled(false), | 25 spellcheck_enabled(false), |
32 is_editable(false), | 26 is_editable(false), |
| 27 #if defined(OS_MACOSX) |
| 28 writing_direction_default( |
| 29 WebKit::WebContextMenuData::CheckableMenuItemDisabled), |
| 30 writing_direction_left_to_right( |
| 31 WebKit::WebContextMenuData::CheckableMenuItemEnabled), |
| 32 writing_direction_right_to_left( |
| 33 WebKit::WebContextMenuData::CheckableMenuItemEnabled), |
| 34 #endif // OS_MACOSX |
33 edit_flags(0), | 35 edit_flags(0), |
34 referrer_policy(WebKit::WebReferrerPolicyDefault) { | 36 referrer_policy(WebKit::WebReferrerPolicyDefault) { |
35 } | 37 } |
36 | 38 |
37 ContextMenuParams::~ContextMenuParams() { | 39 ContextMenuParams::~ContextMenuParams() { |
38 } | 40 } |
39 | 41 |
40 ContextMenuParams::ContextMenuParams(const WebKit::WebContextMenuData& data) | |
41 : media_type(data.mediaType), | |
42 x(data.mousePosition.x), | |
43 y(data.mousePosition.y), | |
44 link_url(data.linkURL), | |
45 unfiltered_link_url(data.linkURL), | |
46 src_url(data.srcURL), | |
47 is_image_blocked(data.isImageBlocked), | |
48 page_url(data.pageURL), | |
49 keyword_url(data.keywordURL), | |
50 frame_url(data.frameURL), | |
51 frame_id(0), | |
52 media_flags(data.mediaFlags), | |
53 selection_text(data.selectedText), | |
54 misspelled_word(data.misspelledWord), | |
55 speech_input_enabled(data.isSpeechInputEnabled), | |
56 spellcheck_enabled(data.isSpellCheckingEnabled), | |
57 is_editable(data.isEditable), | |
58 #if defined(OS_MACOSX) | |
59 writing_direction_default(data.writingDirectionDefault), | |
60 writing_direction_left_to_right(data.writingDirectionLeftToRight), | |
61 writing_direction_right_to_left(data.writingDirectionRightToLeft), | |
62 #endif // OS_MACOSX | |
63 edit_flags(data.editFlags), | |
64 frame_charset(data.frameEncoding.utf8()), | |
65 referrer_policy(data.referrerPolicy) { | |
66 for (size_t i = 0; i < data.dictionarySuggestions.size(); ++i) | |
67 dictionary_suggestions.push_back(data.dictionarySuggestions[i]); | |
68 | |
69 custom_context.is_pepper_menu = false; | |
70 for (size_t i = 0; i < data.customItems.size(); ++i) | |
71 custom_items.push_back(WebMenuItem(data.customItems[i])); | |
72 | |
73 if (!data.frameHistoryItem.isNull()) { | |
74 frame_content_state = | |
75 webkit_glue::HistoryItemToString(data.frameHistoryItem); | |
76 } | |
77 | |
78 if (!link_url.is_empty()) { | |
79 WebKit::WebNode selectedNode = data.node; | |
80 | |
81 // If there are other embedded tags (like <a ..>Some <b>text</b></a>) | |
82 // we need to extract the parent <a/> node. | |
83 while (!selectedNode.isLink() && !selectedNode.parentNode().isNull()) { | |
84 selectedNode = selectedNode.parentNode(); | |
85 } | |
86 | |
87 WebKit::WebElement selectedElement = selectedNode.to<WebKit::WebElement>(); | |
88 if (selectedNode.isLink() && !selectedElement.isNull()) { | |
89 link_text = selectedElement.innerText(); | |
90 } else { | |
91 LOG(ERROR) << "Creating a ContextMenuParams for a node that has a link" | |
92 << "url but is not an ElementNode or does not have an" | |
93 << "ancestor that is a link."; | |
94 } | |
95 } | |
96 | |
97 // Deserialize the SSL info. | |
98 if (!data.securityInfo.isEmpty()) { | |
99 DeserializeSecurityInfo(data.securityInfo, | |
100 &security_info.cert_id, | |
101 &security_info.cert_status, | |
102 &security_info.security_bits, | |
103 &security_info.connection_status); | |
104 } | |
105 } | |
106 | |
107 } // namespace content | 42 } // namespace content |
OLD | NEW |