cef/libcef/browser/alloy/chrome_profile_alloy.cc

169 lines
4.1 KiB
C++
Raw Normal View History

// Copyright (c) 2015 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2012 The Chromium 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/alloy/chrome_profile_alloy.h"
#include "base/no_destructor.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/variations/variations_client.h"
#include "components/variations/variations_ids_provider.h"
#include "net/url_request/url_request_context.h"
namespace {
class CefVariationsClient : public variations::VariationsClient {
public:
explicit CefVariationsClient(content::BrowserContext* browser_context)
: browser_context_(browser_context) {}
~CefVariationsClient() override = default;
bool IsOffTheRecord() const override {
return browser_context_->IsOffTheRecord();
}
variations::mojom::VariationsHeadersPtr GetVariationsHeaders()
const override {
return variations::VariationsIdsProvider::GetInstance()
->GetClientDataHeaders(false /* is_signed_in */);
}
private:
content::BrowserContext* browser_context_;
};
} // namespace
ChromeProfileAlloy::ChromeProfileAlloy() {
profile_metrics::SetBrowserProfileType(
this, profile_metrics::BrowserProfileType::kRegular);
}
ChromeProfileAlloy::~ChromeProfileAlloy() = default;
bool ChromeProfileAlloy::IsOffTheRecord() {
return false;
}
bool ChromeProfileAlloy::IsOffTheRecord() const {
// Alloy contexts are never flagged as off-the-record. It causes problems
// for the extension system.
return false;
}
const Profile::OTRProfileID& ChromeProfileAlloy::GetOTRProfileID() const {
DCHECK(false);
static base::NoDestructor<Profile::OTRProfileID> otr_profile_id(
Profile::OTRProfileID::PrimaryID());
return *otr_profile_id;
}
variations::VariationsClient* ChromeProfileAlloy::GetVariationsClient() {
2023-01-02 23:59:03 +01:00
if (!variations_client_) {
variations_client_ = std::make_unique<CefVariationsClient>(this);
2023-01-02 23:59:03 +01:00
}
return variations_client_.get();
}
scoped_refptr<base::SequencedTaskRunner> ChromeProfileAlloy::GetIOTaskRunner() {
DCHECK(false);
return scoped_refptr<base::SequencedTaskRunner>();
}
std::string ChromeProfileAlloy::GetProfileUserName() const {
DCHECK(false);
return std::string();
}
Profile* ChromeProfileAlloy::GetOffTheRecordProfile(
const Profile::OTRProfileID& otr_profile_id,
bool create_if_needed) {
DCHECK(false);
return nullptr;
}
std::vector<Profile*> ChromeProfileAlloy::GetAllOffTheRecordProfiles() {
return {};
}
void ChromeProfileAlloy::DestroyOffTheRecordProfile(Profile* otr_profile) {
DCHECK(false);
}
bool ChromeProfileAlloy::HasOffTheRecordProfile(
const Profile::OTRProfileID& otr_profile_id) {
return false;
}
bool ChromeProfileAlloy::HasAnyOffTheRecordProfile() {
return false;
}
Profile* ChromeProfileAlloy::GetOriginalProfile() {
return this;
}
const Profile* ChromeProfileAlloy::GetOriginalProfile() const {
return this;
}
bool ChromeProfileAlloy::IsChild() const {
return false;
}
ExtensionSpecialStoragePolicy*
ChromeProfileAlloy::GetExtensionSpecialStoragePolicy() {
DCHECK(false);
return nullptr;
}
bool ChromeProfileAlloy::IsSameOrParent(Profile* profile) {
DCHECK(false);
return false;
}
base::Time ChromeProfileAlloy::GetStartTime() const {
DCHECK(false);
return base::Time();
}
base::FilePath ChromeProfileAlloy::last_selected_directory() {
Use Chrome file dialogs on all platforms and runtimes (fixes issue #3314) All file dialogs irrespective of source, platform and runtime will now be routed through CefFileDialogManager and trigger CefDialogHandler callbacks (see issue #3293). Adds Chrome runtime support for CefBrowserHost::RunFileDialog and CefDialogHandler callbacks. Adds Alloy runtime support for internal GTK file and print dialogs on Linux subject to the following limitations: 1. Internal GTK implementation: - Cannot be used with multi-threaded-message-loop because Chromium's internal GTK implementation is not thread-safe (does not use GDK threads). - Dialogs will not be modal to application windows when used with off-screen rendering due to lack of access to the client's top-level GtkWindow. 2. Cefclient CefDialogHandler implementation: - Cannot be used with Views because it requires a top-level GtkWindow. Due to the above limitations no dialog implementation is currently provided for Views + multi-threaded-message-loop on Linux. In cases where both implementations are supported the cefclient version is now behind an optional `--use-client-dialogs` command-line flag. Expressly forbids multiple simultaneous file dialogs with the internal platform implementation which uses modal dialogs. CefDialogHandler will still be notified and can optionally handle each request without a modal dialog (see issue #3154). Removes some RunFileDialog parameters that are not supported by the Chrome file dialog implementation (selected_accept_filter parameter, cef_file_dialog_mode_t overwrite/read-only flags).
2022-04-15 21:55:23 +02:00
return last_selected_directory_;
}
void ChromeProfileAlloy::set_last_selected_directory(
const base::FilePath& path) {
Use Chrome file dialogs on all platforms and runtimes (fixes issue #3314) All file dialogs irrespective of source, platform and runtime will now be routed through CefFileDialogManager and trigger CefDialogHandler callbacks (see issue #3293). Adds Chrome runtime support for CefBrowserHost::RunFileDialog and CefDialogHandler callbacks. Adds Alloy runtime support for internal GTK file and print dialogs on Linux subject to the following limitations: 1. Internal GTK implementation: - Cannot be used with multi-threaded-message-loop because Chromium's internal GTK implementation is not thread-safe (does not use GDK threads). - Dialogs will not be modal to application windows when used with off-screen rendering due to lack of access to the client's top-level GtkWindow. 2. Cefclient CefDialogHandler implementation: - Cannot be used with Views because it requires a top-level GtkWindow. Due to the above limitations no dialog implementation is currently provided for Views + multi-threaded-message-loop on Linux. In cases where both implementations are supported the cefclient version is now behind an optional `--use-client-dialogs` command-line flag. Expressly forbids multiple simultaneous file dialogs with the internal platform implementation which uses modal dialogs. CefDialogHandler will still be notified and can optionally handle each request without a modal dialog (see issue #3154). Removes some RunFileDialog parameters that are not supported by the Chrome file dialog implementation (selected_accept_filter parameter, cef_file_dialog_mode_t overwrite/read-only flags).
2022-04-15 21:55:23 +02:00
last_selected_directory_ = path;
}
GURL ChromeProfileAlloy::GetHomePage() {
DCHECK(false);
return GURL();
}
bool ChromeProfileAlloy::WasCreatedByVersionOrLater(
const std::string& version) {
DCHECK(false);
return false;
}
base::Time ChromeProfileAlloy::GetCreationTime() const {
DCHECK(false);
return base::Time();
}
void ChromeProfileAlloy::SetCreationTimeForTesting(base::Time creation_time) {
DCHECK(false);
}
void ChromeProfileAlloy::RecordPrimaryMainFrameNavigation() {
DCHECK(false);
}
bool ChromeProfileAlloy::IsSignedIn() {
DCHECK(false);
return false;
}