2015-11-17 19:20:13 +01:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework 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 "libcef/browser/browser_info_manager.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "libcef/browser/browser_platform_delegate.h"
|
|
|
|
#include "libcef/browser/extensions/browser_extensions_util.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "libcef/common/cef_messages.h"
|
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2019-03-19 10:42:54 +01:00
|
|
|
#include "libcef/common/values_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "content/common/view_messages.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2016-05-11 18:18:43 +02:00
|
|
|
#include "content/public/common/child_process_host.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void TranslatePopupFeatures(const blink::mojom::WindowFeatures& webKitFeatures,
|
2015-11-17 19:20:13 +01:00
|
|
|
CefPopupFeatures& features) {
|
|
|
|
features.x = static_cast<int>(webKitFeatures.x);
|
2017-03-03 23:37:23 +01:00
|
|
|
features.xSet = webKitFeatures.has_x;
|
2015-11-17 19:20:13 +01:00
|
|
|
features.y = static_cast<int>(webKitFeatures.y);
|
2017-03-03 23:37:23 +01:00
|
|
|
features.ySet = webKitFeatures.has_y;
|
2015-11-17 19:20:13 +01:00
|
|
|
features.width = static_cast<int>(webKitFeatures.width);
|
2017-03-03 23:37:23 +01:00
|
|
|
features.widthSet = webKitFeatures.has_width;
|
2015-11-17 19:20:13 +01:00
|
|
|
features.height = static_cast<int>(webKitFeatures.height);
|
2017-05-17 11:29:28 +02:00
|
|
|
features.heightSet = webKitFeatures.has_height;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
features.menuBarVisible = webKitFeatures.menu_bar_visible;
|
|
|
|
features.statusBarVisible = webKitFeatures.status_bar_visible;
|
|
|
|
features.toolBarVisible = webKitFeatures.tool_bar_visible;
|
|
|
|
features.scrollbarsVisible = webKitFeatures.scrollbars_visible;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserInfoManager* g_info_manager = nullptr;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserInfoManager::CefBrowserInfoManager() : next_browser_id_(0) {
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(!g_info_manager);
|
|
|
|
g_info_manager = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserInfoManager::~CefBrowserInfoManager() {
|
|
|
|
DCHECK(browser_info_list_.empty());
|
|
|
|
g_info_manager = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefBrowserInfoManager* CefBrowserInfoManager::GetInstance() {
|
|
|
|
return g_info_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreateBrowserInfo(
|
|
|
|
bool is_popup,
|
2019-03-19 10:42:54 +01:00
|
|
|
bool is_windowless,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) {
|
2015-11-17 19:20:13 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info = new CefBrowserInfo(
|
|
|
|
++next_browser_id_, is_popup, is_windowless, extra_info);
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_info_list_.push_back(browser_info);
|
|
|
|
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreatePopupBrowserInfo(
|
|
|
|
content::WebContents* new_contents,
|
2019-03-19 10:42:54 +01:00
|
|
|
bool is_windowless,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info) {
|
2015-11-17 19:20:13 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
auto frame_host = new_contents->GetMainFrame();
|
2017-10-26 20:17:00 +02:00
|
|
|
const int render_process_id = frame_host->GetProcess()->GetID();
|
2019-05-24 22:23:43 +02:00
|
|
|
const auto frame_id = CefFrameHostImpl::MakeFrameId(frame_host);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
2019-05-24 22:23:43 +02:00
|
|
|
new CefBrowserInfo(++next_browser_id_, true, is_windowless, extra_info);
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_info_list_.push_back(browser_info);
|
|
|
|
|
|
|
|
// Continue any pending NewBrowserInfo requests.
|
2019-05-24 22:23:43 +02:00
|
|
|
auto it = pending_new_browser_info_map_.find(frame_id);
|
|
|
|
if (it != pending_new_browser_info_map_.end()) {
|
|
|
|
SendNewBrowserInfoResponse(render_process_id, browser_info, false,
|
|
|
|
it->second->reply_msg);
|
|
|
|
pending_new_browser_info_map_.erase(it);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserInfoManager::CanCreateWindow(
|
2017-05-31 17:33:30 +02:00
|
|
|
content::RenderFrameHost* opener,
|
2015-11-17 19:20:13 +01:00
|
|
|
const GURL& target_url,
|
|
|
|
const content::Referrer& referrer,
|
2016-10-21 21:52:29 +02:00
|
|
|
const std::string& frame_name,
|
2015-11-17 19:20:13 +01:00
|
|
|
WindowOpenDisposition disposition,
|
2017-03-03 23:37:23 +01:00
|
|
|
const blink::mojom::WindowFeatures& features,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
bool is_guest_view = false;
|
2017-05-31 17:33:30 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
extensions::GetOwnerBrowserForHost(opener, &is_guest_view);
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(browser.get());
|
|
|
|
if (!browser.get()) {
|
|
|
|
// Cancel the popup.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_guest_view) {
|
2017-05-17 11:29:28 +02:00
|
|
|
content::OpenURLParams params(target_url, referrer, disposition,
|
|
|
|
ui::PAGE_TRANSITION_LINK, true);
|
2015-11-17 19:20:13 +01:00
|
|
|
params.user_gesture = user_gesture;
|
|
|
|
|
|
|
|
// Pass navigation to the owner browser.
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2015-11-17 19:20:13 +01:00
|
|
|
base::Bind(base::IgnoreResult(&CefBrowserHostImpl::OpenURLFromTab),
|
|
|
|
browser.get(), nullptr, params));
|
|
|
|
|
|
|
|
// Cancel the popup.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
bool allow = true;
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefWindowInfo> window_info(new CefWindowInfo);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#if defined(OS_WIN)
|
2016-01-19 21:09:01 +01:00
|
|
|
window_info->SetAsPopup(NULL, CefString());
|
2015-11-17 19:20:13 +01:00
|
|
|
#endif
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
auto pending_popup = std::make_unique<CefBrowserInfoManager::PendingPopup>();
|
2016-10-21 21:52:29 +02:00
|
|
|
pending_popup->step = CefBrowserInfoManager::PendingPopup::CAN_CREATE_WINDOW;
|
2019-05-24 22:23:43 +02:00
|
|
|
pending_popup->opener_render_process_id = opener->GetProcess()->GetID();
|
|
|
|
pending_popup->opener_render_routing_id = opener->GetRoutingID();
|
2016-10-21 21:52:29 +02:00
|
|
|
pending_popup->target_url = target_url;
|
|
|
|
pending_popup->target_frame_name = frame_name;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Start with the current browser's settings.
|
|
|
|
pending_popup->client = client;
|
|
|
|
pending_popup->settings = browser->settings();
|
|
|
|
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
|
|
|
|
if (handler.get()) {
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> opener_frame = browser->GetFrameForHost(opener);
|
|
|
|
DCHECK(opener_frame);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
CefPopupFeatures cef_features;
|
|
|
|
TranslatePopupFeatures(features, cef_features);
|
|
|
|
|
|
|
|
#if (defined(OS_WIN) || defined(OS_MACOSX))
|
|
|
|
// Default to the size from the popup features.
|
|
|
|
if (cef_features.xSet)
|
2016-01-19 21:09:01 +01:00
|
|
|
window_info->x = cef_features.x;
|
2015-11-17 19:20:13 +01:00
|
|
|
if (cef_features.ySet)
|
2016-01-19 21:09:01 +01:00
|
|
|
window_info->y = cef_features.y;
|
2015-11-17 19:20:13 +01:00
|
|
|
if (cef_features.widthSet)
|
2016-01-19 21:09:01 +01:00
|
|
|
window_info->width = cef_features.width;
|
2015-11-17 19:20:13 +01:00
|
|
|
if (cef_features.heightSet)
|
2016-01-19 21:09:01 +01:00
|
|
|
window_info->height = cef_features.height;
|
2015-11-17 19:20:13 +01:00
|
|
|
#endif
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
allow = !handler->OnBeforePopup(
|
2019-05-24 22:23:43 +02:00
|
|
|
browser.get(), opener_frame, pending_popup->target_url.spec(),
|
2015-11-17 19:20:13 +01:00
|
|
|
pending_popup->target_frame_name,
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<cef_window_open_disposition_t>(disposition), user_gesture,
|
|
|
|
cef_features, *window_info, pending_popup->client,
|
2019-03-19 10:42:54 +01:00
|
|
|
pending_popup->settings, pending_popup->extra_info,
|
|
|
|
no_javascript_access);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allow) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserHostImpl::CreateParams create_params;
|
|
|
|
|
|
|
|
if (!browser->IsViewsHosted())
|
|
|
|
create_params.window_info = std::move(window_info);
|
|
|
|
|
|
|
|
create_params.settings = pending_popup->settings;
|
|
|
|
create_params.client = pending_popup->client;
|
2019-03-19 10:42:54 +01:00
|
|
|
create_params.extra_info = pending_popup->extra_info;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
pending_popup->platform_delegate =
|
2016-01-19 21:09:01 +01:00
|
|
|
CefBrowserPlatformDelegate::Create(create_params);
|
2015-11-17 19:20:13 +01:00
|
|
|
CHECK(pending_popup->platform_delegate.get());
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
// Between the calls to CanCreateWindow and GetCustomWebContentsView
|
|
|
|
// RenderViewHostImpl::CreateNewWindow() will call
|
|
|
|
// RenderProcessHostImpl::FilterURL() which, in the case of "javascript:"
|
|
|
|
// URIs, rewrites the URL to "about:blank". We need to apply the same filter
|
|
|
|
// otherwise GetCustomWebContentsView will fail to retrieve the PopupInfo.
|
|
|
|
opener->GetProcess()->FilterURL(false, &pending_popup->target_url);
|
|
|
|
|
|
|
|
PushPendingPopup(std::move(pending_popup));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return allow;
|
|
|
|
}
|
|
|
|
|
2017-02-10 23:44:11 +01:00
|
|
|
void CefBrowserInfoManager::GetCustomWebContentsView(
|
2015-11-17 19:20:13 +01:00
|
|
|
const GURL& target_url,
|
2017-03-15 23:04:16 +01:00
|
|
|
int opener_render_process_id,
|
2019-05-24 22:23:43 +02:00
|
|
|
int opener_render_routing_id,
|
2015-11-17 19:20:13 +01:00
|
|
|
content::WebContentsView** view,
|
|
|
|
content::RenderViewHostDelegateView** delegate_view) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserInfoManager::PendingPopup> pending_popup =
|
2015-11-17 19:20:13 +01:00
|
|
|
PopPendingPopup(CefBrowserInfoManager::PendingPopup::CAN_CREATE_WINDOW,
|
2019-05-24 22:23:43 +02:00
|
|
|
opener_render_process_id, opener_render_routing_id,
|
2015-11-17 19:20:13 +01:00
|
|
|
target_url);
|
|
|
|
DCHECK(pending_popup.get());
|
|
|
|
DCHECK(pending_popup->platform_delegate.get());
|
|
|
|
|
|
|
|
if (pending_popup->platform_delegate->IsWindowless()) {
|
|
|
|
pending_popup->platform_delegate->CreateViewForWebContents(view,
|
|
|
|
delegate_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
pending_popup->step =
|
2017-02-10 23:44:11 +01:00
|
|
|
CefBrowserInfoManager::PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW;
|
2016-01-06 20:20:54 +01:00
|
|
|
PushPendingPopup(std::move(pending_popup));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfoManager::WebContentsCreated(
|
|
|
|
const GURL& target_url,
|
2017-03-15 23:04:16 +01:00
|
|
|
int opener_render_process_id,
|
2019-05-24 22:23:43 +02:00
|
|
|
int opener_render_routing_id,
|
2015-11-17 19:20:13 +01:00
|
|
|
CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefClient>& client,
|
2019-03-19 10:42:54 +01:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate>& platform_delegate,
|
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserInfoManager::PendingPopup> pending_popup =
|
2015-11-17 19:20:13 +01:00
|
|
|
PopPendingPopup(
|
2017-02-10 23:44:11 +01:00
|
|
|
CefBrowserInfoManager::PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW,
|
2019-05-24 22:23:43 +02:00
|
|
|
opener_render_process_id, opener_render_routing_id, target_url);
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(pending_popup.get());
|
|
|
|
DCHECK(pending_popup->platform_delegate.get());
|
|
|
|
|
|
|
|
settings = pending_popup->settings;
|
|
|
|
client = pending_popup->client;
|
2016-01-06 20:20:54 +01:00
|
|
|
platform_delegate = std::move(pending_popup->platform_delegate);
|
2019-03-19 10:42:54 +01:00
|
|
|
extra_info = pending_popup->extra_info;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefBrowserInfoManager::OnGetNewBrowserInfo(int render_process_id,
|
2019-05-24 22:23:43 +02:00
|
|
|
int render_routing_id,
|
2017-05-17 11:29:28 +02:00
|
|
|
IPC::Message* reply_msg) {
|
2016-05-11 18:18:43 +02:00
|
|
|
DCHECK_NE(render_process_id, content::ChildProcessHost::kInvalidUniqueID);
|
2019-05-24 22:23:43 +02:00
|
|
|
DCHECK_GT(render_routing_id, 0);
|
2015-11-17 19:20:13 +01:00
|
|
|
DCHECK(reply_msg);
|
|
|
|
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
bool is_guest_view = false;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info =
|
|
|
|
GetBrowserInfo(render_process_id, render_routing_id, &is_guest_view);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
if (browser_info.get()) {
|
|
|
|
// Send the response immediately.
|
2017-07-27 01:19:27 +02:00
|
|
|
SendNewBrowserInfoResponse(render_process_id, browser_info, is_guest_view,
|
|
|
|
reply_msg);
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
const auto frame_id =
|
|
|
|
CefFrameHostImpl::MakeFrameId(render_process_id, render_routing_id);
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Verify that no request for the same route is currently queued.
|
2019-05-24 22:23:43 +02:00
|
|
|
DCHECK(pending_new_browser_info_map_.find(frame_id) ==
|
|
|
|
pending_new_browser_info_map_.end());
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Queue the request.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<PendingNewBrowserInfo> pending(new PendingNewBrowserInfo());
|
2016-05-11 18:18:43 +02:00
|
|
|
pending->render_process_id = render_process_id;
|
2019-05-24 22:23:43 +02:00
|
|
|
pending->render_routing_id = render_routing_id;
|
2015-11-17 19:20:13 +01:00
|
|
|
pending->reply_msg = reply_msg;
|
2019-05-24 22:23:43 +02:00
|
|
|
pending_new_browser_info_map_.insert(
|
|
|
|
std::make_pair(frame_id, std::move(pending)));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfoManager::RemoveBrowserInfo(
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info) {
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
|
|
|
BrowserInfoList::iterator it = browser_info_list_.begin();
|
|
|
|
for (; it != browser_info_list_.end(); ++it) {
|
|
|
|
if (*it == browser_info) {
|
|
|
|
browser_info_list_.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserInfoManager::DestroyAllBrowsers() {
|
|
|
|
BrowserInfoList list;
|
|
|
|
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
list = browser_info_list_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy any remaining browser windows.
|
|
|
|
if (!list.empty()) {
|
|
|
|
BrowserInfoList::iterator it = list.begin();
|
|
|
|
for (; it != list.end(); ++it) {
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser = (*it)->browser();
|
|
|
|
DCHECK(browser.get());
|
|
|
|
if (browser.get()) {
|
|
|
|
// DestroyBrowser will call RemoveBrowserInfo.
|
|
|
|
browser->DestroyBrowser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 13:24:30 +02:00
|
|
|
#if DCHECK_IS_ON()
|
2015-11-17 19:20:13 +01:00
|
|
|
{
|
|
|
|
// Verify that all browser windows have been destroyed.
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
DCHECK(browser_info_list_.empty());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
scoped_refptr<CefBrowserInfo>
|
|
|
|
CefBrowserInfoManager::GetBrowserInfoForFrameRoute(int render_process_id,
|
|
|
|
int render_routing_id,
|
|
|
|
bool* is_guest_view) {
|
2015-11-17 19:20:13 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
2017-10-26 20:17:00 +02:00
|
|
|
return GetBrowserInfo(render_process_id, render_routing_id, is_guest_view);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-10-26 20:17:00 +02:00
|
|
|
scoped_refptr<CefBrowserInfo>
|
2019-05-24 22:23:43 +02:00
|
|
|
CefBrowserInfoManager::GetBrowserInfoForFrameTreeNode(int frame_tree_node_id,
|
|
|
|
bool* is_guest_view) {
|
|
|
|
if (is_guest_view)
|
|
|
|
*is_guest_view = false;
|
|
|
|
|
2017-10-26 20:17:00 +02:00
|
|
|
if (frame_tree_node_id < 0)
|
|
|
|
return nullptr;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
for (const auto& browser_info : browser_info_list_) {
|
|
|
|
bool is_guest_view_tmp;
|
|
|
|
auto frame = browser_info->GetFrameForFrameTreeNode(frame_tree_node_id,
|
|
|
|
&is_guest_view_tmp);
|
|
|
|
if (frame || is_guest_view_tmp) {
|
|
|
|
if (is_guest_view)
|
|
|
|
*is_guest_view = is_guest_view_tmp;
|
2017-10-26 20:17:00 +02:00
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefBrowserInfoManager::BrowserInfoList
|
|
|
|
CefBrowserInfoManager::GetBrowserInfoList() {
|
2016-07-20 20:03:38 +02:00
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
2019-05-24 22:23:43 +02:00
|
|
|
BrowserInfoList copy;
|
|
|
|
copy.assign(browser_info_list_.begin(), browser_info_list_.end());
|
|
|
|
return copy;
|
2016-07-20 20:03:38 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserInfoManager::RenderProcessHostDestroyed(
|
|
|
|
content::RenderProcessHost* host) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2016-05-11 18:18:43 +02:00
|
|
|
const int render_process_id = host->GetID();
|
2017-05-09 22:45:57 +02:00
|
|
|
DCHECK_GT(render_process_id, 0);
|
2016-05-11 18:18:43 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Remove all pending requests that reference the destroyed host.
|
2017-05-09 22:45:57 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(browser_info_lock_);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
PendingNewBrowserInfoMap::iterator it =
|
|
|
|
pending_new_browser_info_map_.begin();
|
|
|
|
while (it != pending_new_browser_info_map_.end()) {
|
|
|
|
auto info = it->second.get();
|
2017-05-09 22:45:57 +02:00
|
|
|
if (info->render_process_id == render_process_id)
|
2019-05-24 22:23:43 +02:00
|
|
|
it = pending_new_browser_info_map_.erase(it);
|
2017-05-09 22:45:57 +02:00
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all pending popups that reference the destroyed host as the opener.
|
|
|
|
{
|
|
|
|
PendingPopupList::iterator it = pending_popup_list_.begin();
|
|
|
|
while (it != pending_popup_list_.end()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
PendingPopup* popup = it->get();
|
2019-05-24 22:23:43 +02:00
|
|
|
if (popup->opener_render_process_id == render_process_id) {
|
2017-05-09 22:45:57 +02:00
|
|
|
it = pending_popup_list_.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 22:45:57 +02:00
|
|
|
void CefBrowserInfoManager::PushPendingPopup(
|
|
|
|
std::unique_ptr<PendingPopup> popup) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2016-01-06 20:20:54 +01:00
|
|
|
pending_popup_list_.push_back(std::move(popup));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserInfoManager::PendingPopup>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserInfoManager::PopPendingPopup(PendingPopup::Step step,
|
2019-05-24 22:23:43 +02:00
|
|
|
int opener_render_process_id,
|
|
|
|
int opener_render_routing_id,
|
2017-05-17 11:29:28 +02:00
|
|
|
const GURL& target_url) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2019-05-24 22:23:43 +02:00
|
|
|
DCHECK_GT(opener_render_process_id, 0);
|
|
|
|
DCHECK_GT(opener_render_routing_id, 0);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
PendingPopupList::iterator it = pending_popup_list_.begin();
|
|
|
|
for (; it != pending_popup_list_.end(); ++it) {
|
2017-07-27 01:19:27 +02:00
|
|
|
PendingPopup* popup = it->get();
|
2019-05-24 22:23:43 +02:00
|
|
|
if (popup->step == step &&
|
|
|
|
popup->opener_render_process_id == opener_render_process_id &&
|
|
|
|
popup->opener_render_routing_id == opener_render_routing_id &&
|
2015-11-17 19:20:13 +01:00
|
|
|
popup->target_url == target_url) {
|
2017-07-27 01:19:27 +02:00
|
|
|
// Transfer ownership of the pointer.
|
|
|
|
it->release();
|
|
|
|
pending_popup_list_.erase(it);
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(popup);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::GetBrowserInfo(
|
2019-05-24 22:23:43 +02:00
|
|
|
int render_process_id,
|
|
|
|
int render_routing_id,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool* is_guest_view) {
|
|
|
|
browser_info_lock_.AssertAcquired();
|
|
|
|
|
|
|
|
if (is_guest_view)
|
|
|
|
*is_guest_view = false;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
if (render_process_id < 0 || render_routing_id < 0)
|
2017-10-26 20:17:00 +02:00
|
|
|
return nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
for (const auto& browser_info : browser_info_list_) {
|
|
|
|
bool is_guest_view_tmp;
|
|
|
|
auto frame = browser_info->GetFrameForRoute(
|
|
|
|
render_process_id, render_routing_id, &is_guest_view_tmp);
|
|
|
|
if (frame || is_guest_view_tmp) {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (is_guest_view)
|
2019-05-24 22:23:43 +02:00
|
|
|
*is_guest_view = is_guest_view_tmp;
|
2015-11-17 19:20:13 +01:00
|
|
|
return browser_info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefBrowserInfoManager::SendNewBrowserInfoResponse(
|
2016-05-11 18:18:43 +02:00
|
|
|
int render_process_id,
|
2017-07-27 01:19:27 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool is_guest_view,
|
|
|
|
IPC::Message* reply_msg) {
|
2016-05-11 18:18:43 +02:00
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2016-05-11 18:18:43 +02:00
|
|
|
base::Bind(&CefBrowserInfoManager::SendNewBrowserInfoResponse,
|
|
|
|
render_process_id, browser_info, is_guest_view, reply_msg));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::RenderProcessHost* host =
|
|
|
|
content::RenderProcessHost::FromID(render_process_id);
|
|
|
|
if (!host) {
|
|
|
|
delete reply_msg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefProcessHostMsg_GetNewBrowserInfo_Params params;
|
|
|
|
params.browser_id = browser_info->browser_id();
|
|
|
|
params.is_windowless = browser_info->is_windowless();
|
|
|
|
params.is_popup = browser_info->is_popup();
|
|
|
|
params.is_guest_view = is_guest_view;
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
auto extra_info = browser_info->extra_info();
|
|
|
|
if (extra_info) {
|
|
|
|
auto extra_info_impl =
|
|
|
|
static_cast<CefDictionaryValueImpl*>(extra_info.get());
|
|
|
|
auto extra_info_value = extra_info_impl->CopyValue();
|
|
|
|
extra_info_value->Swap(¶ms.extra_info);
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefProcessHostMsg_GetNewBrowserInfo::WriteReplyParams(reply_msg, params);
|
|
|
|
host->Send(reply_msg);
|
|
|
|
}
|