diff options
-rw-r--r-- | chrome/browser/renderer_context_menu/render_view_context_menu.cc | 3 | ||||
-rw-r--r-- | content/common/frame_messages.h | 1 | ||||
-rw-r--r-- | content/content_renderer.gypi | 2 | ||||
-rw-r--r-- | content/public/common/context_menu_params.h | 6 | ||||
-rw-r--r-- | content/renderer/context_menu_params_builder.cc | 10 | ||||
-rw-r--r-- | content/renderer/dom_utils.cc | 22 | ||||
-rw-r--r-- | content/renderer/dom_utils.h | 23 | ||||
-rw-r--r-- | content/renderer/render_frame_impl.cc | 6 |
8 files changed, 65 insertions, 8 deletions
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc index 79a2f0b..1eddc69 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -1943,6 +1943,9 @@ void RenderViewContextMenu::OpenURL( content::Referrer referrer(referring_url.GetAsReferrer(), params_.referrer_policy); + if (params_.link_url == url && disposition != OFF_THE_RECORD) + params_.custom_context.link_followed = url; + WebContents* new_contents = source_web_contents_->OpenURL(OpenURLParams( url, referrer, disposition, transition, false)); if (!new_contents) diff --git a/content/common/frame_messages.h b/content/common/frame_messages.h index 5c0a3df..c8a8715 100644 --- a/content/common/frame_messages.h +++ b/content/common/frame_messages.h @@ -81,6 +81,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::CustomContextMenuContext) IPC_STRUCT_TRAITS_MEMBER(is_pepper_menu) IPC_STRUCT_TRAITS_MEMBER(request_id) IPC_STRUCT_TRAITS_MEMBER(render_widget_id) + IPC_STRUCT_TRAITS_MEMBER(link_followed) IPC_STRUCT_TRAITS_END() IPC_STRUCT_BEGIN(FrameHostMsg_DidFailProvisionalLoadWithError_Params) diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 9877e5a..b6c09e3 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -188,6 +188,8 @@ 'renderer/dom_storage/webstoragearea_impl.h', 'renderer/dom_storage/webstoragenamespace_impl.cc', 'renderer/dom_storage/webstoragenamespace_impl.h', + 'renderer/dom_utils.cc', + 'renderer/dom_utils.h', 'renderer/drop_data_builder.cc', 'renderer/drop_data_builder.h', 'renderer/fetchers/image_resource_fetcher.cc', diff --git a/content/public/common/context_menu_params.h b/content/public/common/context_menu_params.h index b91d5a1..8849dae 100644 --- a/content/public/common/context_menu_params.h +++ b/content/public/common/context_menu_params.h @@ -36,6 +36,12 @@ struct CONTENT_EXPORT CustomContextMenuContext { // It could also be |kCurrentRenderWidget|, which means the render widget that // the corresponding ViewHostMsg_ContextMenu is sent to. int32 render_widget_id; + + // If the context menu was created for a link, and we navigated to that url, + // this will contain the url that was navigated. This field may not be set + // if, for example, we are transitioning to an incognito window, since we + // want to sever any connection to the old renderer. + GURL link_followed; }; // FIXME(beng): This would be more useful in the future and more efficient diff --git a/content/renderer/context_menu_params_builder.cc b/content/renderer/context_menu_params_builder.cc index 7cd34be..0d53dac 100644 --- a/content/renderer/context_menu_params_builder.cc +++ b/content/renderer/context_menu_params_builder.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "content/common/ssl_status_serialization.h" #include "content/public/common/context_menu_params.h" +#include "content/renderer/dom_utils.h" #include "content/renderer/history_serialization.h" #include "content/renderer/menu_item_builder.h" #include "third_party/WebKit/public/web/WebElement.h" @@ -55,14 +56,7 @@ ContextMenuParams ContextMenuParamsBuilder::Build( } if (!params.link_url.is_empty()) { - blink::WebNode selectedNode = data.node; - - // If there are other embedded tags (like <a ..>Some <b>text</b></a>) - // we need to extract the parent <a/> node. - while (!selectedNode.isLink() && !selectedNode.parentNode().isNull()) { - selectedNode = selectedNode.parentNode(); - } - + blink::WebNode selectedNode = DomUtils::ExtractParentAnchorNode(data.node); blink::WebElement selectedElement = selectedNode.to<blink::WebElement>(); if (selectedNode.isLink() && !selectedElement.isNull()) { params.link_text = selectedElement.innerText(); diff --git a/content/renderer/dom_utils.cc b/content/renderer/dom_utils.cc new file mode 100644 index 0000000..5cb08a3 --- /dev/null +++ b/content/renderer/dom_utils.cc @@ -0,0 +1,22 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/renderer/dom_utils.h" + +#include "third_party/WebKit/public/web/WebNode.h" + +namespace content { + +blink::WebNode DomUtils::ExtractParentAnchorNode( + const blink::WebNode& node) { + blink::WebNode selected_node = node; + + // If there are other embedded tags (like <a ..>Some <b>text</b></a>) + // we need to extract the parent <a/> node. + while (!selected_node.isLink() && !selected_node.parentNode().isNull()) + selected_node = selected_node.parentNode(); + return selected_node.isLink() ? selected_node : blink::WebNode(); +} + +} // namespace content diff --git a/content/renderer/dom_utils.h b/content/renderer/dom_utils.h new file mode 100644 index 0000000..0b047c3 --- /dev/null +++ b/content/renderer/dom_utils.h @@ -0,0 +1,23 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_RENDERER_DOM_UTILS_H_ +#define CONTENT_RENDERER_DOM_UTILS_H_ + +namespace blink { +class WebNode; +} + +namespace content { + +class DomUtils { + public: + // Walks up the DOM, looking for the first parent that represents an <a>. + // Returns a null WebNode if no such <a> exists. + static blink::WebNode ExtractParentAnchorNode(const blink::WebNode& node); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_DOM_UTILS_H_ diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index ba70043..8576e87 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -54,6 +54,7 @@ #include "content/renderer/context_menu_params_builder.h" #include "content/renderer/devtools/devtools_agent.h" #include "content/renderer/dom_automation_controller.h" +#include "content/renderer/dom_utils.h" #include "content/renderer/geolocation_dispatcher.h" #include "content/renderer/history_controller.h" #include "content/renderer/history_serialization.h" @@ -1028,6 +1029,11 @@ void RenderFrameImpl::OnContextMenuClosed( pending_context_menus_.Remove(custom_context.request_id); } } else { + if (custom_context.link_followed.is_valid()) { + frame_->sendPings( + DomUtils::ExtractParentAnchorNode(context_menu_node_), + custom_context.link_followed); + } // Internal request, forward to WebKit. context_menu_node_.reset(); } |