2017-12-05 06:59:15 +00: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 20:46:59 +00:00
|
|
|
#include "shell/browser/session_preferences.h"
|
2017-12-05 06:59:15 +00:00
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "base/logging.h"
|
2019-09-18 19:58:00 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
2021-07-02 00:51:37 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2019-09-18 19:58:00 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2017-12-05 06:59:15 +00:00
|
|
|
|
|
|
|
// static
|
|
|
|
int SessionPreferences::kLocatorKey = 0;
|
|
|
|
|
|
|
|
SessionPreferences::SessionPreferences(content::BrowserContext* context) {
|
|
|
|
context->SetUserData(&kLocatorKey, base::WrapUnique(this));
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
SessionPreferences::~SessionPreferences() = default;
|
2017-12-05 06:59:15 +00:00
|
|
|
|
|
|
|
// static
|
|
|
|
SessionPreferences* SessionPreferences::FromBrowserContext(
|
|
|
|
content::BrowserContext* context) {
|
|
|
|
return static_cast<SessionPreferences*>(context->GetUserData(&kLocatorKey));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-11-10 17:06:03 +00:00
|
|
|
std::vector<base::FilePath> SessionPreferences::GetValidPreloads(
|
2019-07-03 15:05:45 +00:00
|
|
|
content::BrowserContext* context) {
|
2020-11-10 17:06:03 +00:00
|
|
|
std::vector<base::FilePath> result;
|
2019-07-03 15:05:45 +00:00
|
|
|
|
|
|
|
if (auto* self = FromBrowserContext(context)) {
|
|
|
|
for (const auto& preload : self->preloads()) {
|
2020-11-10 17:06:03 +00:00
|
|
|
if (preload.IsAbsolute()) {
|
2019-07-03 15:05:45 +00:00
|
|
|
result.emplace_back(preload);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "preload script must have absolute path: " << preload;
|
|
|
|
}
|
2017-12-05 06:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-03 15:05:45 +00:00
|
|
|
|
|
|
|
return result;
|
2017-12-05 06:59:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|