2016-07-18 23:22:22 +02:00
|
|
|
// Copyright (c) 2016 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.
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/browser/alloy/chrome_profile_manager_alloy.h"
|
2016-07-18 23:22:22 +02:00
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/browser/request_context_impl.h"
|
|
|
|
#include "libcef/common/app_manager.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Return the active browser context. This is primarily called from Chrome code
|
|
|
|
// that handles WebUI views and wishes to associate the view's data with a
|
|
|
|
// particular context (profile). Chrome stores multiple profiles in sub-
|
|
|
|
// directories of |user_data_dir| and then uses ProfileManager to track which
|
|
|
|
// profile (sub-directory name) was last active.
|
|
|
|
//
|
|
|
|
// TODO(cef): To most closely match Chrome behavior this should return the
|
|
|
|
// context for the currently active browser (e.g. the browser with input focus).
|
|
|
|
// Return the main context for now since we don't currently have a good way to
|
|
|
|
// determine that.
|
2019-03-22 23:11:51 +01:00
|
|
|
CefBrowserContext* GetActiveBrowserContext() {
|
2020-06-28 23:05:36 +02:00
|
|
|
auto request_context = static_cast<CefRequestContextImpl*>(
|
|
|
|
CefAppManager::Get()->GetGlobalRequestContext().get());
|
2020-07-01 02:57:00 +02:00
|
|
|
return request_context->GetBrowserContext();
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2016-07-18 23:22:22 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
ChromeProfileManagerAlloy::ChromeProfileManagerAlloy()
|
2017-05-17 11:29:28 +02:00
|
|
|
: ProfileManager(base::FilePath()) {}
|
2016-07-18 23:22:22 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
ChromeProfileManagerAlloy::~ChromeProfileManagerAlloy() {}
|
2016-07-18 23:22:22 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
Profile* ChromeProfileManagerAlloy::GetProfile(
|
2016-08-04 14:37:53 +02:00
|
|
|
const base::FilePath& profile_dir) {
|
2019-03-22 23:11:51 +01:00
|
|
|
CefBrowserContext* browser_context =
|
2020-07-01 02:57:00 +02:00
|
|
|
CefBrowserContext::FromCachePath(profile_dir);
|
2016-11-07 20:14:09 +01:00
|
|
|
if (!browser_context) {
|
|
|
|
// ProfileManager makes assumptions about profile directory paths that do
|
|
|
|
// not match CEF usage. For example, the default Chrome profile name is
|
|
|
|
// "Default" so it will append that sub-directory name to an empty
|
|
|
|
// |user_data_dir| value and then call this method. Use the active context
|
|
|
|
// in cases such as this where we don't understand what ProfileManager is
|
|
|
|
// asking for.
|
|
|
|
browser_context = GetActiveBrowserContext();
|
|
|
|
}
|
2020-07-01 02:57:00 +02:00
|
|
|
return browser_context->AsProfile();
|
2016-08-04 14:37:53 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
bool ChromeProfileManagerAlloy::IsValidProfile(const void* profile) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!profile) {
|
2016-07-18 23:22:22 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-01 02:57:00 +02:00
|
|
|
return !!CefBrowserContext::FromBrowserContext(
|
|
|
|
static_cast<const content::BrowserContext*>(profile));
|
2016-07-18 23:22:22 +02:00
|
|
|
}
|