Fix link navigation from PDF files (fixes issue #2952)
Navigations initiated from a guest view will now be routed to the OpenURLFromTab callback.
This commit is contained in:
parent
99d66db930
commit
ac99621829
|
@ -450,10 +450,21 @@ bool NavigationOnUIThread(
|
||||||
const navigation_interception::NavigationParams& params) {
|
const navigation_interception::NavigationParams& params) {
|
||||||
CEF_REQUIRE_UIT();
|
CEF_REQUIRE_UIT();
|
||||||
|
|
||||||
|
content::OpenURLParams open_params(
|
||||||
|
params.url(), params.referrer(), WindowOpenDisposition::CURRENT_TAB,
|
||||||
|
params.transition_type(), params.is_renderer_initiated());
|
||||||
|
open_params.user_gesture = params.has_user_gesture();
|
||||||
|
open_params.initiator_origin = params.initiator_origin();
|
||||||
|
|
||||||
|
CefRefPtr<CefBrowserHostImpl> browser;
|
||||||
|
if (!CefBrowserInfoManager::GetInstance()->MaybeAllowNavigation(
|
||||||
|
source->GetMainFrame(), open_params, browser)) {
|
||||||
|
// Cancel the navigation.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ignore_navigation = false;
|
bool ignore_navigation = false;
|
||||||
|
|
||||||
CefRefPtr<CefBrowserHostImpl> browser =
|
|
||||||
CefBrowserHostImpl::GetBrowserForContents(source);
|
|
||||||
if (browser.get()) {
|
if (browser.get()) {
|
||||||
CefRefPtr<CefClient> client = browser->GetClient();
|
CefRefPtr<CefClient> client = browser->GetClient();
|
||||||
if (client.get()) {
|
if (client.get()) {
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
#include "content/public/common/child_process_host.h"
|
#include "content/public/common/child_process_host.h"
|
||||||
|
#include "extensions/common/constants.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -115,26 +116,13 @@ bool CefBrowserInfoManager::CanCreateWindow(
|
||||||
bool* no_javascript_access) {
|
bool* no_javascript_access) {
|
||||||
CEF_REQUIRE_UIT();
|
CEF_REQUIRE_UIT();
|
||||||
|
|
||||||
bool is_guest_view = false;
|
content::OpenURLParams params(target_url, referrer, disposition,
|
||||||
CefRefPtr<CefBrowserHostImpl> browser =
|
ui::PAGE_TRANSITION_LINK,
|
||||||
extensions::GetOwnerBrowserForHost(opener, &is_guest_view);
|
/*is_renderer_initiated=*/true);
|
||||||
DCHECK(browser.get());
|
params.user_gesture = user_gesture;
|
||||||
if (!browser.get()) {
|
|
||||||
// Cancel the popup.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_guest_view) {
|
|
||||||
content::OpenURLParams params(target_url, referrer, disposition,
|
|
||||||
ui::PAGE_TRANSITION_LINK, true);
|
|
||||||
params.user_gesture = user_gesture;
|
|
||||||
|
|
||||||
// Pass navigation to the owner browser.
|
|
||||||
CEF_POST_TASK(
|
|
||||||
CEF_UIT,
|
|
||||||
base::Bind(base::IgnoreResult(&CefBrowserHostImpl::OpenURLFromTab),
|
|
||||||
browser.get(), nullptr, params));
|
|
||||||
|
|
||||||
|
CefRefPtr<CefBrowserHostImpl> browser;
|
||||||
|
if (!MaybeAllowNavigation(opener, params, browser)) {
|
||||||
// Cancel the popup.
|
// Cancel the popup.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -369,6 +357,34 @@ CefBrowserInfoManager::GetBrowserInfoForFrameRoute(int render_process_id,
|
||||||
return GetBrowserInfo(render_process_id, render_routing_id, is_guest_view);
|
return GetBrowserInfo(render_process_id, render_routing_id, is_guest_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefBrowserInfoManager::MaybeAllowNavigation(
|
||||||
|
content::RenderFrameHost* opener,
|
||||||
|
const content::OpenURLParams& params,
|
||||||
|
CefRefPtr<CefBrowserHostImpl>& browser_out) const {
|
||||||
|
CEF_REQUIRE_UIT();
|
||||||
|
|
||||||
|
bool is_guest_view = false;
|
||||||
|
CefRefPtr<CefBrowserHostImpl> browser =
|
||||||
|
extensions::GetOwnerBrowserForHost(opener, &is_guest_view);
|
||||||
|
DCHECK(browser);
|
||||||
|
if (!browser)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (is_guest_view && !params.url.SchemeIs(extensions::kExtensionScheme)) {
|
||||||
|
// The PDF viewer will load an extension in the guest view. All other
|
||||||
|
// navigations are passed to the owner browser.
|
||||||
|
CEF_POST_TASK(
|
||||||
|
CEF_UIT,
|
||||||
|
base::Bind(base::IgnoreResult(&CefBrowserHostImpl::OpenURLFromTab),
|
||||||
|
browser.get(), nullptr, params));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
browser_out = browser;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
scoped_refptr<CefBrowserInfo>
|
scoped_refptr<CefBrowserInfo>
|
||||||
CefBrowserInfoManager::GetBrowserInfoForFrameTreeNode(int frame_tree_node_id,
|
CefBrowserInfoManager::GetBrowserInfoForFrameTreeNode(int frame_tree_node_id,
|
||||||
bool* is_guest_view) {
|
bool* is_guest_view) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ struct WebWindowFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
|
struct OpenURLParams;
|
||||||
struct Referrer;
|
struct Referrer;
|
||||||
class RenderFrameHost;
|
class RenderFrameHost;
|
||||||
class RenderViewHostDelegateView;
|
class RenderViewHostDelegateView;
|
||||||
|
@ -138,6 +139,13 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
|
||||||
typedef std::list<scoped_refptr<CefBrowserInfo>> BrowserInfoList;
|
typedef std::list<scoped_refptr<CefBrowserInfo>> BrowserInfoList;
|
||||||
BrowserInfoList GetBrowserInfoList();
|
BrowserInfoList GetBrowserInfoList();
|
||||||
|
|
||||||
|
// Returns true if the navigation should be allowed to proceed, or false if
|
||||||
|
// the navigation will instead be sent via OpenURLFromTab. If allowed,
|
||||||
|
// |browser| will be set to the target browser.
|
||||||
|
bool MaybeAllowNavigation(content::RenderFrameHost* opener,
|
||||||
|
const content::OpenURLParams& params,
|
||||||
|
CefRefPtr<CefBrowserHostImpl>& browser) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// RenderProcessHostObserver methods:
|
// RenderProcessHostObserver methods:
|
||||||
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
|
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
|
||||||
|
|
Loading…
Reference in New Issue