mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Support usage of the Chrome toolbar from Views (see issue #2969)
This commit is contained in:
@ -34,7 +34,7 @@ void ChromeBrowserContext::InitializeAsync(base::OnceClosure initialized_cb) {
|
||||
|
||||
if (cache_path_ == user_data_dir) {
|
||||
// Use the default disk-based profile.
|
||||
auto profile = profile_manager->GetActiveUserProfile();
|
||||
auto profile = profile_manager->GetPrimaryUserProfile();
|
||||
ProfileCreated(profile, Profile::CreateStatus::CREATE_STATUS_CREATED);
|
||||
ProfileCreated(profile, Profile::CreateStatus::CREATE_STATUS_INITIALIZED);
|
||||
return;
|
||||
@ -63,7 +63,7 @@ void ChromeBrowserContext::Shutdown() {
|
||||
// |g_browser_process| may be nullptr during shutdown.
|
||||
if (should_destroy_ && g_browser_process) {
|
||||
g_browser_process->profile_manager()
|
||||
->GetActiveUserProfile()
|
||||
->GetPrimaryUserProfile()
|
||||
->DestroyOffTheRecordProfile(profile_);
|
||||
}
|
||||
profile_ = nullptr;
|
||||
@ -83,7 +83,7 @@ void ChromeBrowserContext::ProfileCreated(Profile* profile,
|
||||
// new/unique OffTheRecord profile instead.
|
||||
const auto& profile_id = Profile::OTRProfileID::CreateUniqueForCEF();
|
||||
parent_profile =
|
||||
g_browser_process->profile_manager()->GetActiveUserProfile();
|
||||
g_browser_process->profile_manager()->GetPrimaryUserProfile();
|
||||
profile_ = parent_profile->GetOffTheRecordProfile(profile_id);
|
||||
otr_profile = static_cast<OffTheRecordProfileImpl*>(profile_);
|
||||
status = Profile::CreateStatus::CREATE_STATUS_INITIALIZED;
|
||||
|
@ -68,3 +68,31 @@ void ChromeBrowserView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
|
||||
ParentClass::OnBoundsChanged(previous_bounds);
|
||||
browser_view_delegate_->OnBoundsChanged();
|
||||
}
|
||||
|
||||
ToolbarView* ChromeBrowserView::OverrideCreateToolbar(
|
||||
Browser* browser,
|
||||
BrowserView* browser_view) {
|
||||
if (cef_delegate()) {
|
||||
auto toolbar_type = cef_delegate()->GetChromeToolbarType();
|
||||
base::Optional<ToolbarView::DisplayMode> display_mode;
|
||||
switch (toolbar_type) {
|
||||
case CEF_CTT_NORMAL:
|
||||
display_mode = ToolbarView::DisplayMode::NORMAL;
|
||||
break;
|
||||
case CEF_CTT_LOCATION:
|
||||
display_mode = ToolbarView::DisplayMode::LOCATION;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (display_mode) {
|
||||
cef_toolbar_ = CefToolbarViewImpl::Create(nullptr, browser, browser_view,
|
||||
display_mode);
|
||||
// Ownership will be taken by BrowserView.
|
||||
view_util::PassOwnership(cef_toolbar_).release();
|
||||
return cef_toolbar_->root_view();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "include/views/cef_browser_view.h"
|
||||
#include "include/views/cef_browser_view_delegate.h"
|
||||
#include "libcef/browser/chrome/views/toolbar_view_impl.h"
|
||||
#include "libcef/browser/views/browser_view_view.h"
|
||||
#include "libcef/browser/views/view_view.h"
|
||||
|
||||
@ -42,6 +43,12 @@ class ChromeBrowserView
|
||||
void AddedToWidget() override;
|
||||
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
|
||||
|
||||
// BrowserView methods:
|
||||
ToolbarView* OverrideCreateToolbar(Browser* browser,
|
||||
BrowserView* browser_view) override;
|
||||
|
||||
CefRefPtr<CefToolbarViewImpl> cef_toolbar() const { return cef_toolbar_; }
|
||||
|
||||
private:
|
||||
// Not owned by this object.
|
||||
Delegate* browser_view_delegate_;
|
||||
@ -51,6 +58,8 @@ class ChromeBrowserView
|
||||
|
||||
bool destroyed_ = false;
|
||||
|
||||
CefRefPtr<CefToolbarViewImpl> cef_toolbar_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserView);
|
||||
};
|
||||
|
||||
|
40
libcef/browser/chrome/views/toolbar_view_impl.cc
Normal file
40
libcef/browser/chrome/views/toolbar_view_impl.cc
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2021 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/chrome/views/toolbar_view_impl.h"
|
||||
|
||||
// static
|
||||
CefRefPtr<CefToolbarViewImpl> CefToolbarViewImpl::Create(
|
||||
CefRefPtr<CefViewDelegate> delegate,
|
||||
Browser* browser,
|
||||
BrowserView* browser_view,
|
||||
base::Optional<ToolbarView::DisplayMode> display_mode) {
|
||||
CEF_REQUIRE_UIT_RETURN(nullptr);
|
||||
CefRefPtr<CefToolbarViewImpl> view =
|
||||
new CefToolbarViewImpl(delegate, browser, browser_view, display_mode);
|
||||
view->Initialize();
|
||||
return view;
|
||||
}
|
||||
|
||||
// static
|
||||
const char* const CefToolbarViewImpl::kTypeString = "ToolbarView";
|
||||
|
||||
CefToolbarViewImpl::CefToolbarViewImpl(
|
||||
CefRefPtr<CefViewDelegate> delegate,
|
||||
Browser* browser,
|
||||
BrowserView* browser_view,
|
||||
base::Optional<ToolbarView::DisplayMode> display_mode)
|
||||
: ParentClass(delegate),
|
||||
browser_(browser),
|
||||
browser_view_(browser_view),
|
||||
display_mode_(display_mode) {}
|
||||
|
||||
CefToolbarViewView* CefToolbarViewImpl::CreateRootView() {
|
||||
return new CefToolbarViewView(delegate(), browser_, browser_view_,
|
||||
display_mode_);
|
||||
}
|
||||
|
||||
void CefToolbarViewImpl::InitializeRootView() {
|
||||
static_cast<CefToolbarViewView*>(root_view())->Initialize();
|
||||
}
|
55
libcef/browser/chrome/views/toolbar_view_impl.h
Normal file
55
libcef/browser/chrome/views/toolbar_view_impl.h
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright 2021 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_CHROME_VIEWS_TOOLBAR_VIEW_IMPL_H_
|
||||
#define CEF_LIBCEF_BROWSER_CHROME_VIEWS_TOOLBAR_VIEW_IMPL_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/views/cef_view_delegate.h"
|
||||
|
||||
#include "libcef/browser/chrome/views/toolbar_view_view.h"
|
||||
#include "libcef/browser/views/view_impl.h"
|
||||
|
||||
class Browser;
|
||||
class BrowserView;
|
||||
|
||||
class CefToolbarViewImpl
|
||||
: public CefViewImpl<CefToolbarViewView, CefView, CefViewDelegate> {
|
||||
public:
|
||||
typedef CefViewImpl<CefToolbarViewView, CefView, CefViewDelegate> ParentClass;
|
||||
|
||||
// Create a new CefToolbarViewImpl instance. |delegate| may be nullptr.
|
||||
static CefRefPtr<CefToolbarViewImpl> Create(
|
||||
CefRefPtr<CefViewDelegate> delegate,
|
||||
Browser* browser,
|
||||
BrowserView* browser_view,
|
||||
base::Optional<ToolbarView::DisplayMode> display_mode);
|
||||
|
||||
static const char* const kTypeString;
|
||||
|
||||
// CefViewAdapter methods:
|
||||
std::string GetDebugType() override { return kTypeString; }
|
||||
|
||||
private:
|
||||
// Create a new implementation object.
|
||||
// Always call Initialize() after creation.
|
||||
// |delegate| may be nullptr.
|
||||
CefToolbarViewImpl(CefRefPtr<CefViewDelegate> delegate,
|
||||
Browser* browser,
|
||||
BrowserView* browser_view,
|
||||
base::Optional<ToolbarView::DisplayMode> display_mode);
|
||||
|
||||
// CefViewImpl methods:
|
||||
CefToolbarViewView* CreateRootView() override;
|
||||
void InitializeRootView() override;
|
||||
|
||||
Browser* const browser_;
|
||||
BrowserView* const browser_view_;
|
||||
base::Optional<ToolbarView::DisplayMode> const display_mode_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefToolbarViewImpl);
|
||||
DISALLOW_COPY_AND_ASSIGN(CefToolbarViewImpl);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_VIEWS_SCROLL_VIEW_IMPL_H_
|
11
libcef/browser/chrome/views/toolbar_view_view.cc
Normal file
11
libcef/browser/chrome/views/toolbar_view_view.cc
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2021 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/chrome/views/toolbar_view_view.h"
|
||||
|
||||
CefToolbarViewView::CefToolbarViewView(CefViewDelegate* cef_delegate,
|
||||
Browser* browser,
|
||||
BrowserView* browser_view,
|
||||
base::Optional<DisplayMode> display_mode)
|
||||
: ParentClass(cef_delegate, browser, browser_view, display_mode) {}
|
27
libcef/browser/chrome/views/toolbar_view_view.h
Normal file
27
libcef/browser/chrome/views/toolbar_view_view.h
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2021 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_CHROME_VIEWS_TOOLBAR_VIEW_VIEW_H_
|
||||
#define CEF_LIBCEF_BROWSER_CHROME_VIEWS_TOOLBAR_VIEW_VIEW_H_
|
||||
#pragma once
|
||||
|
||||
#include "libcef/browser/views/view_view.h"
|
||||
|
||||
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
|
||||
|
||||
class CefToolbarViewView : public CefViewView<ToolbarView, CefViewDelegate> {
|
||||
public:
|
||||
typedef CefViewView<ToolbarView, CefViewDelegate> ParentClass;
|
||||
|
||||
// |cef_delegate| may be nullptr.
|
||||
explicit CefToolbarViewView(CefViewDelegate* cef_delegate,
|
||||
Browser* browser,
|
||||
BrowserView* browser_view,
|
||||
base::Optional<DisplayMode> display_mode);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CefToolbarViewView);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_CHROME_VIEWS_TOOLBAR_VIEW_VIEW_H_
|
Reference in New Issue
Block a user