context_menu_params.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 3// found in the LICENSE file. 4 5#include "content/public/common/context_menu_params.h" 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 13namespace content { 14 15const int32 CustomContextMenuContext::kCurrentRenderWidget = kint32max; 16 17CustomContextMenuContext::CustomContextMenuContext() 18 : is_pepper_menu(false), 19 request_id(0), 20 render_widget_id(kCurrentRenderWidget) { 21} 22 23ContextMenuParams::ContextMenuParams() 24 : media_type(WebKit::WebContextMenuData::MediaTypeNone), 25 x(0), 26 y(0), 27 is_image_blocked(false), 28 frame_id(0), 29 media_flags(0), 30 speech_input_enabled(false), 31 spellcheck_enabled(false), 32 is_editable(false), 33 edit_flags(0), 34 referrer_policy(WebKit::WebReferrerPolicyDefault) { 35} 36 37ContextMenuParams::~ContextMenuParams() { 38} 39 40ContextMenuParams::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 108