2017-12-04 23:59:15 -07:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 14:46:59 -06:00
|
|
|
#include "shell/browser/session_preferences.h"
|
2017-12-04 23:59:15 -07:00
|
|
|
|
2020-07-13 19:13:34 -06:00
|
|
|
#include "base/logging.h"
|
2019-09-18 13:58:00 -06:00
|
|
|
#include "base/memory/ptr_util.h"
|
2021-07-01 18:51:37 -06:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2019-09-18 13:58:00 -06:00
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
namespace electron {
|
2017-12-04 23:59:15 -07:00
|
|
|
|
|
|
|
// static
|
|
|
|
int SessionPreferences::kLocatorKey = 0;
|
|
|
|
|
2023-06-09 10:20:43 -06:00
|
|
|
// static
|
|
|
|
void SessionPreferences::CreateForBrowserContext(
|
|
|
|
content::BrowserContext* context) {
|
|
|
|
DCHECK(context);
|
|
|
|
context->SetUserData(&kLocatorKey,
|
|
|
|
base::WrapUnique(new SessionPreferences{}));
|
2017-12-04 23:59:15 -07:00
|
|
|
}
|
|
|
|
|
2023-06-09 10:20:43 -06:00
|
|
|
SessionPreferences::SessionPreferences() = default;
|
2019-09-16 16:12:00 -06:00
|
|
|
SessionPreferences::~SessionPreferences() = default;
|
2017-12-04 23:59:15 -07:00
|
|
|
|
|
|
|
// static
|
|
|
|
SessionPreferences* SessionPreferences::FromBrowserContext(
|
|
|
|
content::BrowserContext* context) {
|
|
|
|
return static_cast<SessionPreferences*>(context->GetUserData(&kLocatorKey));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-11-10 10:06:03 -07:00
|
|
|
std::vector<base::FilePath> SessionPreferences::GetValidPreloads(
|
2019-07-03 09:05:45 -06:00
|
|
|
content::BrowserContext* context) {
|
2020-11-10 10:06:03 -07:00
|
|
|
std::vector<base::FilePath> result;
|
2019-07-03 09:05:45 -06:00
|
|
|
|
|
|
|
if (auto* self = FromBrowserContext(context)) {
|
|
|
|
for (const auto& preload : self->preloads()) {
|
2020-11-10 10:06:03 -07:00
|
|
|
if (preload.IsAbsolute()) {
|
2019-07-03 09:05:45 -06:00
|
|
|
result.emplace_back(preload);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "preload script must have absolute path: " << preload;
|
|
|
|
}
|
2017-12-04 23:59:15 -07:00
|
|
|
}
|
|
|
|
}
|
2019-07-03 09:05:45 -06:00
|
|
|
|
|
|
|
return result;
|
2017-12-04 23:59:15 -07:00
|
|
|
}
|
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
} // namespace electron
|