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>
|
|
|
|
|
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
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
#include "base/memory/ref_counted.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
|
|
|
|
|
|
|
class CefBrowserHostImpl;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
|
|
|
// CefBrowserInfo is used to associate a browser ID and render view/process
|
|
|
|
// IDs with a particular CefBrowserHostImpl. Render view/process IDs may change
|
|
|
|
// during the lifetime of a single CefBrowserHostImpl.
|
|
|
|
//
|
|
|
|
// CefBrowserInfo objects are managed by CefContentBrowserClient and should not
|
|
|
|
// be created directly.
|
|
|
|
class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
|
|
|
|
public:
|
2015-10-21 20:17:09 +02:00
|
|
|
class RenderIDManager {
|
|
|
|
public:
|
|
|
|
explicit RenderIDManager(base::Lock* lock);
|
|
|
|
|
|
|
|
// Adds an ID pair if it doesn't already exist.
|
|
|
|
void add_render_frame_id(int render_process_id, int render_routing_id);
|
|
|
|
|
|
|
|
// Remove an ID pair if it exists.
|
|
|
|
void remove_render_frame_id(int render_process_id, int render_routing_id);
|
|
|
|
|
|
|
|
// Returns true if this browser matches the specified ID pair.
|
2015-11-17 19:20:13 +01:00
|
|
|
bool is_render_frame_id_match(int render_process_id,
|
2017-05-17 11:29:28 +02:00
|
|
|
int render_routing_id) const;
|
2015-10-21 20:17:09 +02:00
|
|
|
|
|
|
|
private:
|
2017-05-17 11:29:28 +02:00
|
|
|
typedef std::set<std::pair<int, int>> RenderIdSet;
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2017-10-26 20:17:00 +02:00
|
|
|
// Access to |render_frame_id_set_| must be protected by |lock_|.
|
2015-11-17 19:20:13 +01:00
|
|
|
mutable base::Lock* lock_;
|
2015-10-21 20:17:09 +02:00
|
|
|
|
|
|
|
// Set of mapped (process_id, routing_id) pairs. Keeping this set is
|
|
|
|
// necessary for the following reasons:
|
2017-10-26 20:17:00 +02:00
|
|
|
// 1. When navigating cross-origin the new (pending) RenderFrameHost will be
|
|
|
|
// created before the old (current) RenderFrameHost is destroyed.
|
2015-10-21 20:17:09 +02:00
|
|
|
// 2. When canceling and asynchronously continuing navigation of the same
|
2017-10-26 20:17:00 +02:00
|
|
|
// URL a new RenderFrameHost may be created for the first (canceled)
|
2015-10-21 20:17:09 +02:00
|
|
|
// navigation and then destroyed as a result of the second (allowed)
|
|
|
|
// navigation.
|
|
|
|
// 3. Out-of-process iframes have their own render IDs which must also be
|
|
|
|
// associated with the host browser.
|
|
|
|
RenderIdSet render_frame_id_set_;
|
|
|
|
};
|
|
|
|
|
2017-10-26 20:17:00 +02:00
|
|
|
class FrameTreeNodeIDManager {
|
|
|
|
public:
|
|
|
|
explicit FrameTreeNodeIDManager(base::Lock* lock);
|
|
|
|
|
|
|
|
// Adds an ID if it doesn't already exist.
|
|
|
|
void add_frame_tree_node_id(int frame_tree_node_id);
|
|
|
|
|
|
|
|
// Remove an ID if it exists.
|
|
|
|
void remove_frame_tree_node_id(int frame_tree_node_id);
|
|
|
|
|
|
|
|
// Returns true if this browser matches the specified ID.
|
|
|
|
bool is_frame_tree_node_id_match(int frame_tree_node_id) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::set<int> FrameTreeNodeIdSet;
|
|
|
|
|
|
|
|
// Access to |request_id_set_| must be protected by |lock_|.
|
|
|
|
mutable base::Lock* lock_;
|
|
|
|
|
|
|
|
// Set of mapped frame_tree_node_id values. Keeping this set is necessary
|
|
|
|
// because, when navigating the main frame, a new (pre-commit) URLRequest
|
|
|
|
// will be created before the RenderFrameHost. Consequently we can't rely
|
|
|
|
// on ResourceRequestInfo::GetRenderFrameForRequest returning a valid frame
|
|
|
|
// ID. See https://crbug.com/776884 for background.
|
|
|
|
FrameTreeNodeIdSet frame_tree_node_id_set_;
|
|
|
|
};
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
CefBrowserInfo(int browser_id,
|
|
|
|
bool is_popup,
|
|
|
|
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_; }
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void set_windowless(bool windowless);
|
2013-04-16 21:23:00 +02:00
|
|
|
|
2015-10-21 20:17:09 +02:00
|
|
|
// Returns the render ID manager for this browser.
|
2017-05-17 11:29:28 +02:00
|
|
|
RenderIDManager* render_id_manager() { return &render_id_manager_; }
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2015-10-21 20:17:09 +02:00
|
|
|
// Returns the render ID manager for guest views owned by this browser.
|
|
|
|
RenderIDManager* guest_render_id_manager() {
|
|
|
|
return &guest_render_id_manager_;
|
|
|
|
}
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2017-10-26 20:17:00 +02:00
|
|
|
// Returns the frame tree node ID manager for this browser.
|
|
|
|
FrameTreeNodeIDManager* frame_tree_node_id_manager() {
|
|
|
|
return &frame_tree_node_id_manager_;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser() const;
|
2012-12-30 12:17:49 +01:00
|
|
|
void set_browser(CefRefPtr<CefBrowserHostImpl> browser);
|
|
|
|
|
|
|
|
private:
|
2014-11-12 20:25:15 +01:00
|
|
|
friend class base::RefCountedThreadSafe<CefBrowserInfo>;
|
|
|
|
|
|
|
|
~CefBrowserInfo();
|
|
|
|
|
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_;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
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
|
|
|
|
2015-10-21 20:17:09 +02:00
|
|
|
RenderIDManager render_id_manager_;
|
|
|
|
RenderIDManager guest_render_id_manager_;
|
2012-12-30 12:17:49 +01:00
|
|
|
|
2017-10-26 20:17:00 +02:00
|
|
|
FrameTreeNodeIDManager frame_tree_node_id_manager_;
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
// May be NULL if the browser has not yet been created or if the browser has
|
|
|
|
// been destroyed.
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser_;
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info_;
|
|
|
|
|
2012-12-30 12:17:49 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefBrowserInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_BROWSER_INFO_H_
|