Commit 627d6cb8 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Move GetSourceFrameForPopup() into an anonymous namespace.

It is only ever used within popup_blocker.cc.

Change-Id: I514eac14d05c8b844242ed93693841c291af4966
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1817661Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699064}
parent 0c7f224c
...@@ -71,6 +71,28 @@ PopupBlockType ShouldBlockPopup(content::WebContents* web_contents, ...@@ -71,6 +71,28 @@ PopupBlockType ShouldBlockPopup(content::WebContents* web_contents,
return PopupBlockType::kNotBlocked; return PopupBlockType::kNotBlocked;
} }
// Tries to get the opener from either the |params| or |open_url_params|,
// otherwise uses the focused frame from |web_contents| as a proxy.
content::RenderFrameHost* GetSourceFrameForPopup(
NavigateParams* params,
const content::OpenURLParams* open_url_params,
content::WebContents* web_contents) {
if (params->opener)
return params->opener;
// Make sure the source render frame host is alive before we attempt to
// retrieve it from |open_url_params|.
if (open_url_params) {
content::RenderFrameHost* source = content::RenderFrameHost::FromID(
open_url_params->source_render_frame_id,
open_url_params->source_render_process_id);
if (source)
return source;
}
// The focused frame is not always the frame initiating the popup navigation
// and is used as a fallback in case opener information is not available.
return web_contents->GetFocusedFrame();
}
} // namespace } // namespace
bool ConsiderForPopupBlocking(WindowOpenDisposition disposition) { bool ConsiderForPopupBlocking(WindowOpenDisposition disposition) {
...@@ -105,23 +127,3 @@ bool MaybeBlockPopup(content::WebContents* web_contents, ...@@ -105,23 +127,3 @@ bool MaybeBlockPopup(content::WebContents* web_contents,
} }
return false; return false;
} }
content::RenderFrameHost* GetSourceFrameForPopup(
NavigateParams* params,
const content::OpenURLParams* open_url_params,
content::WebContents* web_contents) {
if (params->opener)
return params->opener;
// Make sure the source render frame host is alive before we attempt to
// retrieve it from |open_url_params|.
if (open_url_params) {
content::RenderFrameHost* source = content::RenderFrameHost::FromID(
open_url_params->source_render_frame_id,
open_url_params->source_render_process_id);
if (source)
return source;
}
// The focused frame is not always the frame initiating the popup navigation
// and is used as a fallback in case opener information is not available.
return web_contents->GetFocusedFrame();
}
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "url/gurl.h" #include "url/gurl.h"
namespace content { namespace content {
class RenderFrameHost;
class WebContents; class WebContents;
struct OpenURLParams; struct OpenURLParams;
} // namespace content } // namespace content
...@@ -48,11 +47,4 @@ bool MaybeBlockPopup(content::WebContents* web_contents, ...@@ -48,11 +47,4 @@ bool MaybeBlockPopup(content::WebContents* web_contents,
const content::OpenURLParams* open_url_params, const content::OpenURLParams* open_url_params,
const blink::mojom::WindowFeatures& window_features); const blink::mojom::WindowFeatures& window_features);
// Tries to get the opener from either the |params| or |open_url_params|,
// otherwise uses the focused frame from |web_contents| as a proxy.
content::RenderFrameHost* GetSourceFrameForPopup(
NavigateParams* params,
const content::OpenURLParams* open_url_params,
content::WebContents* web_contents);
#endif // CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_H_ #endif // CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment