2012-12-30 12:17:49 +01:00
|
|
|
// Copyright (c) 2012 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_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_BROWSER_INFO_H_
|
|
|
|
#pragma once
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
#include <set>
|
2019-05-24 22:23:43 +02:00
|
|
|
#include <unordered_map>
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2015-10-21 20:17:09 +02:00
|
|
|
#include "include/internal/cef_ptr.h"
|
2019-03-19 10:42:54 +01:00
|
|
|
#include "libcef/common/values_impl.h"
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
#include "base/callback.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "base/containers/unique_ptr_adapters.h"
|
2012-12-30 12:17:49 +01:00
|
|
|
#include "base/memory/ref_counted.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2015-10-21 20:17:09 +02:00
|
|
|
#include "base/synchronization/lock.h"
|
2019-03-19 10:42:54 +01:00
|
|
|
#include "base/values.h"
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
|
|
|
}
|
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
class CefBrowserHostBase;
|
2019-05-24 22:23:43 +02:00
|
|
|
class CefFrameHostImpl;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
|
|
|
// CefBrowserInfo is used to associate a browser ID and render view/process
|
2020-09-18 00:24:08 +02:00
|
|
|
// IDs with a particular CefBrowserHostBase. Render view/process IDs may change
|
|
|
|
// during the lifetime of a single CefBrowserHostBase.
|
2012-12-30 12:17:49 +01:00
|
|
|
//
|
2019-05-24 22:23:43 +02:00
|
|
|
// CefBrowserInfo objects are managed by CefBrowserInfoManager and should not be
|
|
|
|
// created directly.
|
2012-12-30 12:17:49 +01:00
|
|
|
class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
|
|
|
|
public:
|
2019-03-19 10:42:54 +01:00
|
|
|
CefBrowserInfo(int browser_id,
|
|
|
|
bool is_popup,
|
2019-05-24 22:23:43 +02:00
|
|
|
bool is_windowless,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info);
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-03-13 22:27:37 +01:00
|
|
|
int browser_id() const { return browser_id_; }
|
2012-12-30 12:17:49 +01:00
|
|
|
bool is_popup() const { return is_popup_; }
|
2014-07-01 00:30:29 +02:00
|
|
|
bool is_windowless() const { return is_windowless_; }
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info() const { return extra_info_; }
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// May return NULL if the browser has not yet been created or if the browser
|
|
|
|
// has been destroyed.
|
2020-09-18 00:24:08 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser() const;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Set or clear the browser. Called from CefBrowserHostBase InitializeBrowser
|
2019-05-24 22:23:43 +02:00
|
|
|
// (to set) and DestroyBrowser (to clear).
|
2020-09-18 00:24:08 +02:00
|
|
|
void SetBrowser(CefRefPtr<CefBrowserHostBase> browser);
|
2019-05-24 22:23:43 +02:00
|
|
|
|
|
|
|
// Ensure that a frame record exists for |host|. Called for the main frame
|
|
|
|
// when the RenderView is created, or for a sub-frame when the associated
|
|
|
|
// RenderFrame is created in the renderer process.
|
2020-09-18 00:24:08 +02:00
|
|
|
// Called from CefBrowserContentsDelegate::RenderFrameCreated (is_guest_view =
|
|
|
|
// false) or CefMimeHandlerViewGuestDelegate::OnGuestAttached (is_guest_view =
|
|
|
|
// true).
|
2019-05-24 22:23:43 +02:00
|
|
|
void MaybeCreateFrame(content::RenderFrameHost* host, bool is_guest_view);
|
|
|
|
|
|
|
|
// Remove the frame record for |host|. Called for the main frame when the
|
|
|
|
// RenderView is destroyed, or for a sub-frame when the associated RenderFrame
|
|
|
|
// is destroyed in the renderer process.
|
2020-09-18 00:24:08 +02:00
|
|
|
// Called from CefBrowserContentsDelegate::RenderFrameDeleted or
|
2019-05-24 22:23:43 +02:00
|
|
|
// CefMimeHandlerViewGuestDelegate::OnGuestDetached.
|
|
|
|
void RemoveFrame(content::RenderFrameHost* host);
|
|
|
|
|
|
|
|
// Returns the main frame object. This object will remain valid until the
|
|
|
|
// browser is destroyed even though the indentifier may change with cross-
|
|
|
|
// origin navigations. Furthermore, calling LoadURL on this object will always
|
|
|
|
// behave as expected because the call is routed through the browser's
|
|
|
|
// NavigationController.
|
|
|
|
CefRefPtr<CefFrameHostImpl> GetMainFrame();
|
|
|
|
|
|
|
|
// Creates a temporary sub-frame object for situations during navigation or
|
|
|
|
// resource loading where a RFH does not yet exist. If |parent_frame_id|
|
|
|
|
// is invalid the current main frame will be specified as the parent.
|
|
|
|
// Temporary frame objects are not tracked but will be implicitly detached
|
|
|
|
// on browser destruction.
|
|
|
|
CefRefPtr<CefFrameHostImpl> CreateTempSubFrame(int64_t parent_frame_id);
|
|
|
|
|
|
|
|
// Returns the frame object matching the specified host or nullptr if no match
|
|
|
|
// is found. Nullptr will also be returned if a guest view match is found
|
|
|
|
// because we don't create frame objects for guest views. If |is_guest_view|
|
|
|
|
// is non-nullptr it will be set to true in this case. Must be called on the
|
|
|
|
// UI thread.
|
|
|
|
CefRefPtr<CefFrameHostImpl> GetFrameForHost(
|
|
|
|
const content::RenderFrameHost* host,
|
|
|
|
bool* is_guest_view = nullptr) const;
|
|
|
|
|
|
|
|
// Returns the frame object matching the specified IDs or nullptr if no match
|
|
|
|
// is found. Nullptr will also be returned if a guest view match is found
|
|
|
|
// because we don't create frame objects for guest views. If |is_guest_view|
|
|
|
|
// is non-nullptr it will be set to true in this case. Safe to call from any
|
|
|
|
// thread.
|
|
|
|
CefRefPtr<CefFrameHostImpl> GetFrameForRoute(
|
|
|
|
int32_t render_process_id,
|
|
|
|
int32_t render_routing_id,
|
|
|
|
bool* is_guest_view = nullptr) const;
|
|
|
|
|
|
|
|
// Returns the frame object matching the specified ID or nullptr if no match
|
|
|
|
// is found. Nullptr will also be returned if a guest view match is found
|
|
|
|
// because we don't create frame objects for guest views. If |is_guest_view|
|
|
|
|
// is non-nullptr it will be set to true in this case. Safe to call from any
|
|
|
|
// thread.
|
|
|
|
CefRefPtr<CefFrameHostImpl> GetFrameForId(
|
|
|
|
int64_t frame_id,
|
|
|
|
bool* is_guest_view = nullptr) const;
|
|
|
|
|
|
|
|
// Returns the frame object matching the specified ID or nullptr if no match
|
|
|
|
// is found. Nullptr will also be returned if a guest view match is found
|
|
|
|
// because we don't create frame objects for guest views. If |is_guest_view|
|
|
|
|
// is non-nullptr it will be set to true in this case. Safe to call from any
|
|
|
|
// thread.
|
|
|
|
CefRefPtr<CefFrameHostImpl> GetFrameForFrameTreeNode(
|
|
|
|
int frame_tree_node_id,
|
|
|
|
bool* is_guest_view = nullptr) const;
|
|
|
|
|
|
|
|
// Returns all non-speculative frame objects that currently exist. Guest views
|
|
|
|
// will be excluded because they don't have a frame object. Safe to call from
|
|
|
|
// any thread.
|
|
|
|
typedef std::set<CefRefPtr<CefFrameHostImpl>> FrameHostList;
|
|
|
|
FrameHostList GetAllFrames() const;
|
2013-04-16 21:23:00 +02:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
class NavigationLock final : public base::RefCounted<NavigationLock> {
|
|
|
|
private:
|
|
|
|
friend class CefBrowserInfo;
|
|
|
|
friend class base::RefCounted<NavigationLock>;
|
|
|
|
|
|
|
|
NavigationLock();
|
|
|
|
~NavigationLock();
|
|
|
|
|
|
|
|
base::OnceClosure pending_action_;
|
|
|
|
base::WeakPtrFactory<NavigationLock> weak_ptr_factory_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Block navigation actions on NavigationLock life span. Must be called on the
|
|
|
|
// UI thread.
|
|
|
|
scoped_refptr<NavigationLock> CreateNavigationLock();
|
|
|
|
|
|
|
|
// Returns true if navigation actions are currently blocked. If this method
|
|
|
|
// returns true the most recent |pending_action| will be executed on the UI
|
|
|
|
// thread once the navigation lock is released. Must be called on the UI
|
|
|
|
// thread.
|
|
|
|
bool IsNavigationLocked(base::OnceClosure pending_action);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
private:
|
|
|
|
friend class base::RefCountedThreadSafe<CefBrowserInfo>;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
virtual ~CefBrowserInfo();
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
struct FrameInfo {
|
|
|
|
~FrameInfo();
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
content::RenderFrameHost* host_;
|
|
|
|
int64_t frame_id_; // Combination of render_process_id + render_routing_id.
|
|
|
|
int frame_tree_node_id_;
|
|
|
|
bool is_guest_view_;
|
|
|
|
bool is_main_frame_;
|
|
|
|
bool is_speculative_;
|
|
|
|
CefRefPtr<CefFrameHostImpl> frame_;
|
|
|
|
};
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
void MaybeUpdateFrameTreeNodeIdMap(FrameInfo* info);
|
2014-11-12 20:25:15 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> GetFrameForFrameTreeNodeInternal(
|
|
|
|
int frame_tree_node_id,
|
|
|
|
bool* is_guest_view = nullptr) const;
|
|
|
|
|
|
|
|
void RemoveAllFrames();
|
2014-11-12 20:25:15 +01:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
int browser_id_;
|
|
|
|
bool is_popup_;
|
2014-07-01 00:30:29 +02:00
|
|
|
bool is_windowless_;
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info_;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
// Navigation will be blocked while |navigation_lock_| exists.
|
|
|
|
// Only accessed on the UI thread.
|
|
|
|
base::WeakPtr<NavigationLock> navigation_lock_;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
mutable base::Lock lock_;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
|
|
|
// The below members must be protected by |lock_|.
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2020-09-18 00:24:08 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser_;
|
2019-05-24 22:23:43 +02:00
|
|
|
|
|
|
|
// Owner of FrameInfo structs.
|
|
|
|
typedef std::set<std::unique_ptr<FrameInfo>, base::UniquePtrComparator>
|
|
|
|
FrameInfoSet;
|
|
|
|
FrameInfoSet frame_info_set_;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Map a frame ID (e.g. MakeFrameId(process_id, routing_id)) to one frame.
|
|
|
|
typedef std::unordered_map<int64_t, FrameInfo*> FrameIDMap;
|
|
|
|
FrameIDMap frame_id_map_;
|
2017-10-26 20:17:00 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Map a frame_tree_node_id to one frame.
|
|
|
|
typedef std::unordered_map<int, FrameInfo*> FrameTreeNodeIDMap;
|
|
|
|
FrameTreeNodeIDMap frame_tree_node_id_map_;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// The current main frame.
|
|
|
|
CefRefPtr<CefFrameHostImpl> main_frame_;
|
2019-03-19 10:42:54 +01:00
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefBrowserInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_BROWSER_INFO_H_
|