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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_BROWSER_INFO_MANAGER_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_BROWSER_INFO_MANAGER_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "include/cef_client.h"
|
|
|
|
|
2021-11-10 22:57:31 +01:00
|
|
|
#include <list>
|
2019-05-24 22:23:43 +02:00
|
|
|
#include <map>
|
2017-07-27 01:19:27 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
#include "libcef/browser/browser_info.h"
|
|
|
|
|
|
|
|
#include "base/synchronization/lock.h"
|
2021-11-10 22:57:31 +01:00
|
|
|
#include "base/task/sequenced_task_runner.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "cef/libcef/common/mojom/cef.mojom.h"
|
2021-08-19 23:07:44 +02:00
|
|
|
#include "content/public/browser/global_routing_id.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "content/public/browser/render_process_host_observer.h"
|
2019-04-16 16:38:48 +02:00
|
|
|
#include "third_party/blink/public/mojom/window_features/window_features.mojom.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "ui/base/window_open_disposition.h"
|
|
|
|
#include "url/gurl.h"
|
|
|
|
|
|
|
|
namespace blink {
|
|
|
|
struct WebWindowFeatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace content {
|
2020-07-23 20:41:56 +02:00
|
|
|
struct OpenURLParams;
|
2015-11-17 19:20:13 +01:00
|
|
|
struct Referrer;
|
2017-05-31 17:33:30 +02:00
|
|
|
class RenderFrameHost;
|
2015-11-17 19:20:13 +01:00
|
|
|
class RenderViewHostDelegateView;
|
|
|
|
class WebContents;
|
|
|
|
class WebContentsView;
|
2017-07-27 01:19:27 +02:00
|
|
|
} // namespace content
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
class CefBrowserHostBase;
|
2015-11-17 19:20:13 +01:00
|
|
|
class CefBrowserPlatformDelegate;
|
|
|
|
|
|
|
|
// Singleton object for managing BrowserInfo instances.
|
|
|
|
class CefBrowserInfoManager : public content::RenderProcessHostObserver {
|
|
|
|
public:
|
|
|
|
CefBrowserInfoManager();
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefBrowserInfoManager(const CefBrowserInfoManager&) = delete;
|
|
|
|
CefBrowserInfoManager& operator=(const CefBrowserInfoManager&) = delete;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
~CefBrowserInfoManager() override;
|
|
|
|
|
|
|
|
// Returns this singleton instance of this class.
|
|
|
|
static CefBrowserInfoManager* GetInstance();
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Called immediately before a new CefBrowserHost implementation is created
|
2015-11-17 19:20:13 +01:00
|
|
|
// directly. In this case |is_popup| will be true only for DevTools browsers.
|
2019-03-19 10:42:54 +01:00
|
|
|
scoped_refptr<CefBrowserInfo> CreateBrowserInfo(
|
|
|
|
bool is_popup,
|
|
|
|
bool is_windowless,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Called from WebContentsDelegate::WebContentsCreated when a new browser is
|
2015-11-17 19:20:13 +01:00
|
|
|
// being created for a traditional popup (e.g. window.open() or targeted
|
|
|
|
// link). If any OnGetNewBrowserInfo requests are pending for the popup the
|
|
|
|
// response will be sent when this method is called.
|
|
|
|
scoped_refptr<CefBrowserInfo> 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
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Called from ContentBrowserClient::CanCreateWindow. See comments on
|
2015-11-17 19:20:13 +01:00
|
|
|
// PendingPopup for more information.
|
2017-05-31 17:33:30 +02:00
|
|
|
bool CanCreateWindow(content::RenderFrameHost* opener,
|
|
|
|
const GURL& target_url,
|
2017-05-17 11:29:28 +02:00
|
|
|
const content::Referrer& referrer,
|
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Called from WebContentsDelegate::GetCustomWebContentsView (alloy runtime
|
|
|
|
// only). See comments on PendingPopup for more information.
|
2017-02-10 23:44:11 +01:00
|
|
|
void GetCustomWebContentsView(
|
2017-05-17 11:29:28 +02:00
|
|
|
const GURL& target_url,
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& opener_global_id,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::WebContentsView** view,
|
|
|
|
content::RenderViewHostDelegateView** delegate_view);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
// Called from WebContentsDelegate::WebContentsCreated. See comments on
|
2015-11-17 19:20:13 +01:00
|
|
|
// PendingPopup for more information.
|
|
|
|
void WebContentsCreated(
|
|
|
|
const GURL& target_url,
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& opener_global_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,
|
2023-02-09 19:15:15 +01:00
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
|
|
|
content::WebContents* new_contents);
|
|
|
|
|
|
|
|
// Called from ChromeBrowserDelegate::AddWebContents. See comments on
|
|
|
|
// PendingPopup for more information. Returns true for custom handling.
|
|
|
|
bool AddWebContents(content::WebContents* source_contents);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Called from CefBrowserManager::GetNewBrowserInfo for delivering
|
2015-11-17 19:20:13 +01:00
|
|
|
// browser info to the renderer process. If the browser info already exists
|
|
|
|
// the response will be sent immediately. Otherwise, the response will be sent
|
|
|
|
// when CreatePopupBrowserInfo creates the browser info. The info will already
|
|
|
|
// exist for explicitly created browsers and guest views. It may sometimes
|
|
|
|
// already exist for traditional popup browsers depending on timing. See
|
|
|
|
// comments on PendingPopup for more information.
|
2021-05-14 18:58:55 +02:00
|
|
|
void OnGetNewBrowserInfo(
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
2021-05-14 18:58:55 +02:00
|
|
|
cef::mojom::BrowserManager::GetNewBrowserInfoCallback callback);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Called from CefBrowserHostBase::DestroyBrowser() when a browser is
|
2015-11-17 19:20:13 +01:00
|
|
|
// destroyed.
|
|
|
|
void RemoveBrowserInfo(scoped_refptr<CefBrowserInfo> browser_info);
|
|
|
|
|
|
|
|
// Called from CefContext::FinishShutdownOnUIThread() to destroy all browsers.
|
|
|
|
void DestroyAllBrowsers();
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
// Returns the CefBrowserInfo matching the specified ID or nullptr if no
|
2019-05-24 22:23:43 +02:00
|
|
|
// match is found. It is allowed to add new callers of this method but
|
2021-08-19 23:07:44 +02:00
|
|
|
// consider using CefBrowserHostBase::GetBrowserForGlobalId() or
|
|
|
|
// extensions::GetOwnerBrowserForGlobalId() instead. If |is_guest_view| is
|
|
|
|
// non-nullptr it will be set to true if the ID matches a guest view
|
|
|
|
// associated with the returned browser info instead of the browser itself.
|
|
|
|
scoped_refptr<CefBrowserInfo> GetBrowserInfo(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
2019-05-24 22:23:43 +02:00
|
|
|
bool* is_guest_view = nullptr);
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Returns all existing CefBrowserInfo objects.
|
2021-11-10 22:57:31 +01:00
|
|
|
using BrowserInfoList = std::list<scoped_refptr<CefBrowserInfo>>;
|
2019-05-24 22:23:43 +02:00
|
|
|
BrowserInfoList GetBrowserInfoList();
|
2016-07-20 20:03:38 +02:00
|
|
|
|
2020-07-23 20:41:56 +02:00
|
|
|
// Returns true if the navigation should be allowed to proceed, or false if
|
|
|
|
// the navigation will instead be sent via OpenURLFromTab. If allowed,
|
2020-07-23 21:46:57 +02:00
|
|
|
// |browser| will be set to the target browser if any.
|
2020-07-23 20:41:56 +02:00
|
|
|
bool MaybeAllowNavigation(content::RenderFrameHost* opener,
|
|
|
|
const content::OpenURLParams& params,
|
2020-09-25 03:40:47 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase>& browser) const;
|
2020-07-23 20:41:56 +02:00
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
static bool ShouldCreateViewsHostedPopup(CefRefPtr<CefBrowserHostBase> opener,
|
|
|
|
bool use_default_browser_creation);
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
private:
|
|
|
|
// RenderProcessHostObserver methods:
|
|
|
|
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
|
|
|
|
|
|
|
|
// Store state information about pending popups. Call order is:
|
2020-09-25 03:40:47 +02:00
|
|
|
// - CanCreateWindow (UIT):
|
2015-11-17 19:20:13 +01:00
|
|
|
// Provides an opportunity to cancel the popup (calls OnBeforePopup) and
|
|
|
|
// creates the new platform delegate for the popup. If the popup owner is
|
|
|
|
// an extension guest view then the popup is canceled and
|
2020-09-25 03:40:47 +02:00
|
|
|
// WebContentsDelegate::OpenURLFromTab is called via the
|
|
|
|
// CefBrowserHostBase::MaybeAllowNavigation implementation.
|
2015-11-17 19:20:13 +01:00
|
|
|
// And then the following calls may occur at the same time:
|
2020-09-25 03:40:47 +02:00
|
|
|
// - GetCustomWebContentsView (UIT) (alloy runtime only):
|
2015-11-17 19:20:13 +01:00
|
|
|
// Creates the OSR views for windowless popups.
|
2020-09-25 03:40:47 +02:00
|
|
|
// - WebContentsCreated (UIT):
|
|
|
|
// Creates the CefBrowserHost representation for the popup.
|
2023-02-09 19:15:15 +01:00
|
|
|
// - AddWebContents (UIT) (chrome runtime only):
|
|
|
|
// Creates the Browser or tab representation for the popup.
|
2021-05-14 18:58:55 +02:00
|
|
|
// - CefBrowserManager::GetNewBrowserInfo (IOT)
|
2015-11-17 19:20:13 +01:00
|
|
|
// Passes information about the popup to the renderer process.
|
|
|
|
struct PendingPopup {
|
|
|
|
// Track the last method that modified this PendingPopup instance. There may
|
|
|
|
// be multiple pending popups with the same identifiers and this allows us
|
|
|
|
// to differentiate between them at different processing steps.
|
|
|
|
enum Step {
|
|
|
|
CAN_CREATE_WINDOW,
|
2017-02-10 23:44:11 +01:00
|
|
|
GET_CUSTOM_WEB_CONTENTS_VIEW,
|
2023-02-09 19:15:15 +01:00
|
|
|
WEB_CONTENTS_CREATED,
|
2015-11-17 19:20:13 +01:00
|
|
|
} step;
|
|
|
|
|
|
|
|
// Initial state from ViewHostMsg_CreateWindow.
|
2015-12-03 19:41:40 +01:00
|
|
|
// |target_url| will be empty if a popup is created via window.open() and
|
|
|
|
// never navigated. For example: javascript:window.open();
|
2021-08-19 23:07:44 +02:00
|
|
|
content::GlobalRenderFrameHostId opener_global_id;
|
2015-11-17 19:20:13 +01:00
|
|
|
GURL target_url;
|
|
|
|
std::string target_frame_name;
|
|
|
|
|
|
|
|
// Values specified by OnBeforePopup.
|
|
|
|
CefBrowserSettings settings;
|
|
|
|
CefRefPtr<CefClient> client;
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Platform delegate specific to the new popup.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate;
|
2023-02-09 19:15:15 +01:00
|
|
|
|
|
|
|
// True if default Browser or tab creation should proceed from
|
|
|
|
// AddWebContents (chrome runtime only).
|
|
|
|
bool use_default_browser_creation = false;
|
|
|
|
|
|
|
|
// The newly created WebContents (set in WebContentsCreated).
|
|
|
|
content::WebContents* new_contents = nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
};
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
// Manage pending popups. Only called on the UI thread.
|
2016-04-27 22:38:52 +02:00
|
|
|
void PushPendingPopup(std::unique_ptr<PendingPopup> popup);
|
2023-02-09 19:15:15 +01:00
|
|
|
|
|
|
|
// Used after CanCreateWindow is called.
|
2021-08-19 23:07:44 +02:00
|
|
|
std::unique_ptr<PendingPopup> PopPendingPopup(
|
2023-02-09 19:15:15 +01:00
|
|
|
PendingPopup::Step previous_step,
|
2021-08-19 23:07:44 +02:00
|
|
|
const content::GlobalRenderFrameHostId& opener_global_id,
|
|
|
|
const GURL& target_url);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2023-02-09 19:15:15 +01:00
|
|
|
// Used after WebContentsCreated is called.
|
|
|
|
std::unique_ptr<PendingPopup> PopPendingPopup(
|
|
|
|
PendingPopup::Step previous_step,
|
|
|
|
content::WebContents* new_contents);
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
// Retrieves the BrowserInfo matching the specified ID.
|
|
|
|
scoped_refptr<CefBrowserInfo> GetBrowserInfoInternal(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
|
|
|
bool* is_guest_view);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Send the response for a pending OnGetNewBrowserInfo request.
|
2017-07-27 01:19:27 +02:00
|
|
|
static void SendNewBrowserInfoResponse(
|
|
|
|
scoped_refptr<CefBrowserInfo> browser_info,
|
|
|
|
bool is_guest_view,
|
2021-05-14 18:58:55 +02:00
|
|
|
cef::mojom::BrowserManager::GetNewBrowserInfoCallback callback,
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> callback_runner);
|
2020-01-23 22:58:01 +01:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Pending request for OnGetNewBrowserInfo.
|
|
|
|
struct PendingNewBrowserInfo {
|
2021-08-19 23:07:44 +02:00
|
|
|
content::GlobalRenderFrameHostId global_id;
|
2020-01-23 22:58:01 +01:00
|
|
|
int timeout_id;
|
2021-05-14 18:58:55 +02:00
|
|
|
cef::mojom::BrowserManager::GetNewBrowserInfoCallback callback;
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> callback_runner;
|
2015-11-17 19:20:13 +01:00
|
|
|
};
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Cancel a response that is still pending.
|
|
|
|
static void CancelNewBrowserInfoResponse(PendingNewBrowserInfo* pending_info);
|
|
|
|
|
|
|
|
// Time out a response if it's still pending.
|
2021-08-19 23:07:44 +02:00
|
|
|
static void TimeoutNewBrowserInfoResponse(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
|
|
|
int timeout_id);
|
2021-05-14 18:58:55 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
mutable base::Lock browser_info_lock_;
|
|
|
|
|
|
|
|
// Access to the below members must be protected by |browser_info_lock_|.
|
|
|
|
|
|
|
|
BrowserInfoList browser_info_list_;
|
2020-01-23 22:58:01 +01:00
|
|
|
int next_browser_id_ = 0;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
// Map of global ID to info. These IDs are guaranteed to uniquely
|
|
|
|
// identify a RFH for its complete lifespan. See documentation on
|
|
|
|
// RenderFrameHost::GetFrameTreeNodeId() for background.
|
2019-05-24 22:23:43 +02:00
|
|
|
using PendingNewBrowserInfoMap =
|
2021-08-19 23:07:44 +02:00
|
|
|
std::map<content::GlobalRenderFrameHostId,
|
|
|
|
std::unique_ptr<PendingNewBrowserInfo>>;
|
2019-05-24 22:23:43 +02:00
|
|
|
PendingNewBrowserInfoMap pending_new_browser_info_map_;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
// Only accessed on the UI thread.
|
2017-07-27 01:19:27 +02:00
|
|
|
using PendingPopupList = std::vector<std::unique_ptr<PendingPopup>>;
|
2015-11-17 19:20:13 +01:00
|
|
|
PendingPopupList pending_popup_list_;
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
int next_timeout_id_ = 0;
|
2015-11-17 19:20:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_BROWSER_INFO_H_
|