• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/renderer/context_menu_params_builder.h"
6 
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/renderer/dom_utils.h"
11 #include "content/renderer/history_serialization.h"
12 #include "content/renderer/menu_item_builder.h"
13 #include "third_party/WebKit/public/web/WebElement.h"
14 #include "third_party/WebKit/public/web/WebNode.h"
15 
16 namespace content {
17 
18 // static
Build(const blink::WebContextMenuData & data)19 ContextMenuParams ContextMenuParamsBuilder::Build(
20     const blink::WebContextMenuData& data) {
21   ContextMenuParams params;
22   params.media_type = data.mediaType;
23   params.x = data.mousePosition.x;
24   params.y = data.mousePosition.y;
25   params.link_url = data.linkURL;
26   params.unfiltered_link_url = data.linkURL;
27   params.src_url = data.srcURL;
28   params.has_image_contents = data.hasImageContents;
29   params.page_url = data.pageURL;
30   params.keyword_url = data.keywordURL;
31   params.frame_url = data.frameURL;
32   params.media_flags = data.mediaFlags;
33   params.selection_text = data.selectedText;
34   params.misspelled_word = data.misspelledWord;
35   params.misspelling_hash = data.misspellingHash;
36   params.spellcheck_enabled = data.isSpellCheckingEnabled;
37   params.is_editable = data.isEditable;
38   params.writing_direction_default = data.writingDirectionDefault;
39   params.writing_direction_left_to_right = data.writingDirectionLeftToRight;
40   params.writing_direction_right_to_left = data.writingDirectionRightToLeft;
41   params.edit_flags = data.editFlags;
42   params.frame_charset = data.frameEncoding.utf8();
43   params.referrer_policy = data.referrerPolicy;
44   params.suggested_filename = data.suggestedFilename;
45 
46   for (size_t i = 0; i < data.dictionarySuggestions.size(); ++i)
47     params.dictionary_suggestions.push_back(data.dictionarySuggestions[i]);
48 
49   params.custom_context.is_pepper_menu = false;
50   for (size_t i = 0; i < data.customItems.size(); ++i)
51     params.custom_items.push_back(MenuItemBuilder::Build(data.customItems[i]));
52 
53   if (!data.frameHistoryItem.isNull()) {
54     params.frame_page_state =
55         SingleHistoryItemToPageState(data.frameHistoryItem);
56   }
57 
58   if (!params.link_url.is_empty()) {
59     blink::WebNode selectedNode = DomUtils::ExtractParentAnchorNode(data.node);
60     blink::WebElement selectedElement = selectedNode.to<blink::WebElement>();
61     if (!selectedElement.isNull() && selectedNode.isLink()) {
62       params.link_text = selectedElement.innerText();
63     } else {
64       LOG(ERROR) << "Creating a ContextMenuParams for a node that has a link"
65                  << "url but is not an ElementNode or does not have an"
66                  << "ancestor that is a link.";
67     }
68   }
69 
70   // Deserialize the SSL info.
71   if (!data.securityInfo.isEmpty()) {
72     DeserializeSecurityInfo(data.securityInfo,
73         &params.security_info.cert_id, &params.security_info.cert_status,
74         &params.security_info.security_bits,
75         &params.security_info.connection_status,
76         &params.security_info.signed_certificate_timestamp_ids);
77   }
78 
79   return params;
80 }
81 
82 }  // namespace content
83