mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add |extra_info| parameter for browser creation (fixes issue #1088)
The optional |extra_info| parameter provides an opportunity to specify extra information specific to the created browser that will be passed to CefRenderProcessHandler::OnBrowserCreated() in the render process.
This commit is contained in:
committed by
Marshall Greenblatt
parent
ad4ce5f441
commit
473c29a70d
@@ -127,24 +127,27 @@ class CreateBrowserHelper {
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context)
|
||||
: window_info_(windowInfo),
|
||||
client_(client),
|
||||
url_(url),
|
||||
settings_(settings),
|
||||
extra_info_(extra_info),
|
||||
request_context_(request_context) {}
|
||||
|
||||
CefWindowInfo window_info_;
|
||||
CefRefPtr<CefClient> client_;
|
||||
CefString url_;
|
||||
CefBrowserSettings settings_;
|
||||
CefRefPtr<CefDictionaryValue> extra_info_;
|
||||
CefRefPtr<CefRequestContext> request_context_;
|
||||
};
|
||||
|
||||
void CreateBrowserWithHelper(CreateBrowserHelper* helper) {
|
||||
CefBrowserHost::CreateBrowserSync(helper->window_info_, helper->client_,
|
||||
helper->url_, helper->settings_,
|
||||
helper->request_context_);
|
||||
CefBrowserHost::CreateBrowserSync(
|
||||
helper->window_info_, helper->client_, helper->url_, helper->settings_,
|
||||
helper->extra_info_, helper->request_context_);
|
||||
delete helper;
|
||||
}
|
||||
|
||||
@@ -207,6 +210,7 @@ bool CefBrowserHost::CreateBrowser(
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context) {
|
||||
// Verify that the context is in a valid state.
|
||||
if (!CONTEXT_STATE_VALID()) {
|
||||
@@ -236,7 +240,7 @@ bool CefBrowserHost::CreateBrowser(
|
||||
|
||||
// Create the browser on the UI thread.
|
||||
CreateBrowserHelper* helper = new CreateBrowserHelper(
|
||||
windowInfo, client, url, settings, request_context);
|
||||
windowInfo, client, url, settings, extra_info, request_context);
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(CreateBrowserWithHelper, helper));
|
||||
|
||||
return true;
|
||||
@@ -248,6 +252,7 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context) {
|
||||
// Verify that the context is in a valid state.
|
||||
if (!CONTEXT_STATE_VALID()) {
|
||||
@@ -284,6 +289,7 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
|
||||
create_params.url = GURL(new_url);
|
||||
}
|
||||
create_params.settings = settings;
|
||||
create_params.extra_info = extra_info;
|
||||
create_params.request_context = request_context;
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
@@ -305,7 +311,8 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
|
||||
|
||||
scoped_refptr<CefBrowserInfo> info =
|
||||
CefBrowserInfoManager::GetInstance()->CreateBrowserInfo(
|
||||
is_devtools_popup, platform_delegate->IsWindowless());
|
||||
is_devtools_popup, platform_delegate->IsWindowless(),
|
||||
create_params.extra_info);
|
||||
|
||||
// Get or create the request context and browser context.
|
||||
CefRefPtr<CefRequestContextImpl> request_context_impl =
|
||||
@@ -2549,14 +2556,15 @@ void CefBrowserHostImpl::WebContentsCreated(
|
||||
CefBrowserSettings settings;
|
||||
CefRefPtr<CefClient> client;
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate;
|
||||
CefRefPtr<CefDictionaryValue> extra_info;
|
||||
|
||||
CefBrowserInfoManager::GetInstance()->WebContentsCreated(
|
||||
target_url, opener_render_process_id, opener_render_frame_id, settings,
|
||||
client, platform_delegate);
|
||||
client, platform_delegate, extra_info);
|
||||
|
||||
scoped_refptr<CefBrowserInfo> info =
|
||||
CefBrowserInfoManager::GetInstance()->CreatePopupBrowserInfo(
|
||||
new_contents, platform_delegate->IsWindowless());
|
||||
new_contents, platform_delegate->IsWindowless(), extra_info);
|
||||
DCHECK(info.get());
|
||||
DCHECK(info->is_popup());
|
||||
|
||||
|
@@ -135,6 +135,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
||||
// request context will be used.
|
||||
CefRefPtr<CefRequestContext> request_context;
|
||||
|
||||
CefRefPtr<CefDictionaryValue> extra_info;
|
||||
|
||||
// Used when explicitly creating the browser as an extension host via
|
||||
// ProcessManager::CreateBackgroundHost.
|
||||
const extensions::Extension* extension = nullptr;
|
||||
|
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/values_impl.h"
|
||||
|
||||
#include "ipc/ipc_message.h"
|
||||
|
||||
@@ -118,13 +119,16 @@ bool CefBrowserInfo::FrameTreeNodeIDManager::is_frame_tree_node_id_match(
|
||||
|
||||
// CefBrowserInfo
|
||||
|
||||
CefBrowserInfo::CefBrowserInfo(int browser_id, bool is_popup)
|
||||
CefBrowserInfo::CefBrowserInfo(int browser_id,
|
||||
bool is_popup,
|
||||
CefRefPtr<CefDictionaryValue> extra_info)
|
||||
: browser_id_(browser_id),
|
||||
is_popup_(is_popup),
|
||||
is_windowless_(false),
|
||||
render_id_manager_(&lock_),
|
||||
guest_render_id_manager_(&lock_),
|
||||
frame_tree_node_id_manager_(&lock_) {
|
||||
frame_tree_node_id_manager_(&lock_),
|
||||
extra_info_(extra_info) {
|
||||
DCHECK_GT(browser_id, 0);
|
||||
}
|
||||
|
||||
|
@@ -9,9 +9,11 @@
|
||||
#include <set>
|
||||
|
||||
#include "include/internal/cef_ptr.h"
|
||||
#include "libcef/common/values_impl.h"
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "base/values.h"
|
||||
|
||||
class CefBrowserHostImpl;
|
||||
|
||||
@@ -83,12 +85,16 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
|
||||
FrameTreeNodeIdSet frame_tree_node_id_set_;
|
||||
};
|
||||
|
||||
CefBrowserInfo(int browser_id, bool is_popup);
|
||||
CefBrowserInfo(int browser_id,
|
||||
bool is_popup,
|
||||
CefRefPtr<CefDictionaryValue> extra_info);
|
||||
|
||||
int browser_id() const { return browser_id_; }
|
||||
bool is_popup() const { return is_popup_; }
|
||||
bool is_windowless() const { return is_windowless_; }
|
||||
|
||||
CefRefPtr<CefDictionaryValue> extra_info() const { return extra_info_; }
|
||||
|
||||
void set_windowless(bool windowless);
|
||||
|
||||
// Returns the render ID manager for this browser.
|
||||
@@ -129,6 +135,8 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
|
||||
// been destroyed.
|
||||
CefRefPtr<CefBrowserHostImpl> browser_;
|
||||
|
||||
CefRefPtr<CefDictionaryValue> extra_info_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefBrowserInfo);
|
||||
};
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/extensions/extensions_util.h"
|
||||
#include "libcef/common/values_impl.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "content/common/view_messages.h"
|
||||
@@ -60,11 +61,12 @@ CefBrowserInfoManager* CefBrowserInfoManager::GetInstance() {
|
||||
|
||||
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreateBrowserInfo(
|
||||
bool is_popup,
|
||||
bool is_windowless) {
|
||||
bool is_windowless,
|
||||
CefRefPtr<CefDictionaryValue> extra_info) {
|
||||
base::AutoLock lock_scope(browser_info_lock_);
|
||||
|
||||
scoped_refptr<CefBrowserInfo> browser_info =
|
||||
new CefBrowserInfo(++next_browser_id_, is_popup);
|
||||
new CefBrowserInfo(++next_browser_id_, is_popup, extra_info);
|
||||
browser_info_list_.push_back(browser_info);
|
||||
|
||||
if (is_windowless)
|
||||
@@ -75,7 +77,8 @@ scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreateBrowserInfo(
|
||||
|
||||
scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreatePopupBrowserInfo(
|
||||
content::WebContents* new_contents,
|
||||
bool is_windowless) {
|
||||
bool is_windowless,
|
||||
CefRefPtr<CefDictionaryValue> extra_info) {
|
||||
base::AutoLock lock_scope(browser_info_lock_);
|
||||
|
||||
content::RenderFrameHost* frame_host = new_contents->GetMainFrame();
|
||||
@@ -83,7 +86,7 @@ scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::CreatePopupBrowserInfo(
|
||||
const int render_frame_routing_id = frame_host->GetRoutingID();
|
||||
|
||||
scoped_refptr<CefBrowserInfo> browser_info =
|
||||
new CefBrowserInfo(++next_browser_id_, true);
|
||||
new CefBrowserInfo(++next_browser_id_, true, extra_info);
|
||||
browser_info->render_id_manager()->add_render_frame_id(
|
||||
render_process_id, render_frame_routing_id);
|
||||
browser_info_list_.push_back(browser_info);
|
||||
@@ -191,7 +194,8 @@ bool CefBrowserInfoManager::CanCreateWindow(
|
||||
pending_popup->target_frame_name,
|
||||
static_cast<cef_window_open_disposition_t>(disposition), user_gesture,
|
||||
cef_features, *window_info, pending_popup->client,
|
||||
pending_popup->settings, no_javascript_access);
|
||||
pending_popup->settings, pending_popup->extra_info,
|
||||
no_javascript_access);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +207,7 @@ bool CefBrowserInfoManager::CanCreateWindow(
|
||||
|
||||
create_params.settings = pending_popup->settings;
|
||||
create_params.client = pending_popup->client;
|
||||
create_params.extra_info = pending_popup->extra_info;
|
||||
|
||||
pending_popup->platform_delegate =
|
||||
CefBrowserPlatformDelegate::Create(create_params);
|
||||
@@ -252,7 +257,8 @@ void CefBrowserInfoManager::WebContentsCreated(
|
||||
int opener_render_frame_id,
|
||||
CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient>& client,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate>& platform_delegate) {
|
||||
std::unique_ptr<CefBrowserPlatformDelegate>& platform_delegate,
|
||||
CefRefPtr<CefDictionaryValue>& extra_info) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
std::unique_ptr<CefBrowserInfoManager::PendingPopup> pending_popup =
|
||||
@@ -265,6 +271,7 @@ void CefBrowserInfoManager::WebContentsCreated(
|
||||
settings = pending_popup->settings;
|
||||
client = pending_popup->client;
|
||||
platform_delegate = std::move(pending_popup->platform_delegate);
|
||||
extra_info = pending_popup->extra_info;
|
||||
}
|
||||
|
||||
void CefBrowserInfoManager::OnGetNewBrowserInfo(int render_process_id,
|
||||
@@ -513,6 +520,14 @@ void CefBrowserInfoManager::SendNewBrowserInfoResponse(
|
||||
params.is_popup = browser_info->is_popup();
|
||||
params.is_guest_view = is_guest_view;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
CefProcessHostMsg_GetNewBrowserInfo::WriteReplyParams(reply_msg, params);
|
||||
host->Send(reply_msg);
|
||||
}
|
||||
|
@@ -49,8 +49,10 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
|
||||
|
||||
// Called from CefBrowserHostImpl::Create when a new browser is being created
|
||||
// directly. In this case |is_popup| will be true only for DevTools browsers.
|
||||
scoped_refptr<CefBrowserInfo> CreateBrowserInfo(bool is_popup,
|
||||
bool is_windowless);
|
||||
scoped_refptr<CefBrowserInfo> CreateBrowserInfo(
|
||||
bool is_popup,
|
||||
bool is_windowless,
|
||||
CefRefPtr<CefDictionaryValue> extra_info);
|
||||
|
||||
// Called from CefBrowserHostImpl::WebContentsCreated when a new browser is
|
||||
// being created for a traditional popup (e.g. window.open() or targeted
|
||||
@@ -58,7 +60,8 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
|
||||
// response will be sent when this method is called.
|
||||
scoped_refptr<CefBrowserInfo> CreatePopupBrowserInfo(
|
||||
content::WebContents* new_contents,
|
||||
bool is_windowless);
|
||||
bool is_windowless,
|
||||
CefRefPtr<CefDictionaryValue> extra_info);
|
||||
|
||||
// Called from CefContentBrowserClient::CanCreateWindow. See comments on
|
||||
// PendingPopup for more information.
|
||||
@@ -89,7 +92,8 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
|
||||
int opener_render_frame_id,
|
||||
CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient>& client,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate>& platform_delegate);
|
||||
std::unique_ptr<CefBrowserPlatformDelegate>& platform_delegate,
|
||||
CefRefPtr<CefDictionaryValue>& extra_info);
|
||||
|
||||
// Called from CefBrowserMessageFilter::OnGetNewBrowserInfo for delivering
|
||||
// browser info to the renderer process. If the browser info already exists
|
||||
@@ -168,6 +172,7 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
|
||||
// Values specified by OnBeforePopup.
|
||||
CefBrowserSettings settings;
|
||||
CefRefPtr<CefClient> client;
|
||||
CefRefPtr<CefDictionaryValue> extra_info;
|
||||
|
||||
// Platform delegate specific to the new popup.
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate;
|
||||
|
@@ -18,10 +18,11 @@ CefRefPtr<CefBrowserView> CefBrowserView::CreateBrowserView(
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context,
|
||||
CefRefPtr<CefBrowserViewDelegate> delegate) {
|
||||
return CefBrowserViewImpl::Create(client, url, settings, request_context,
|
||||
delegate);
|
||||
return CefBrowserViewImpl::Create(client, url, settings, extra_info,
|
||||
request_context, delegate);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -40,11 +41,12 @@ CefRefPtr<CefBrowserViewImpl> CefBrowserViewImpl::Create(
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context,
|
||||
CefRefPtr<CefBrowserViewDelegate> delegate) {
|
||||
CEF_REQUIRE_UIT_RETURN(nullptr);
|
||||
CefRefPtr<CefBrowserViewImpl> browser_view = new CefBrowserViewImpl(delegate);
|
||||
browser_view->SetPendingBrowserCreateParams(client, url, settings,
|
||||
browser_view->SetPendingBrowserCreateParams(client, url, settings, extra_info,
|
||||
request_context);
|
||||
browser_view->Initialize();
|
||||
browser_view->SetDefaults(settings);
|
||||
@@ -171,12 +173,14 @@ void CefBrowserViewImpl::SetPendingBrowserCreateParams(
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context) {
|
||||
DCHECK(!pending_browser_create_params_);
|
||||
pending_browser_create_params_.reset(new CefBrowserHostImpl::CreateParams());
|
||||
pending_browser_create_params_->client = client;
|
||||
pending_browser_create_params_->url = GURL(url.ToString());
|
||||
pending_browser_create_params_->settings = settings;
|
||||
pending_browser_create_params_->extra_info = extra_info;
|
||||
pending_browser_create_params_->request_context = request_context;
|
||||
}
|
||||
|
||||
|
@@ -31,6 +31,7 @@ class CefBrowserViewImpl : public CefViewImpl<CefBrowserViewView,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context,
|
||||
CefRefPtr<CefBrowserViewDelegate> delegate);
|
||||
|
||||
@@ -76,6 +77,7 @@ class CefBrowserViewImpl : public CefViewImpl<CefBrowserViewView,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefString& url,
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue> extra_info,
|
||||
CefRefPtr<CefRequestContext> request_context);
|
||||
|
||||
void SetDefaults(const CefBrowserSettings& settings);
|
||||
|
@@ -188,6 +188,7 @@ IPC_STRUCT_BEGIN(CefProcessHostMsg_GetNewBrowserInfo_Params)
|
||||
IPC_STRUCT_MEMBER(bool, is_popup)
|
||||
IPC_STRUCT_MEMBER(bool, is_windowless)
|
||||
IPC_STRUCT_MEMBER(bool, is_guest_view)
|
||||
IPC_STRUCT_MEMBER(base::DictionaryValue, extra_info)
|
||||
IPC_STRUCT_END()
|
||||
|
||||
// Retrieve information about a newly created browser.
|
||||
|
@@ -679,8 +679,12 @@ void CefContentRendererClient::BrowserCreated(
|
||||
if (application.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
application->GetRenderProcessHandler();
|
||||
if (handler.get())
|
||||
handler->OnBrowserCreated(browser.get());
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefDictionaryValueImpl> dictValuePtr(
|
||||
new CefDictionaryValueImpl(¶ms.extra_info, false, true));
|
||||
handler->OnBrowserCreated(browser.get(), dictValuePtr.get());
|
||||
dictValuePtr->Detach(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user