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
|
|
|
|
2019-09-18 19:58:00 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
|
|
|
|
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
|
2019-07-03 15:05:45 +00:00
|
|
|
std::vector<base::FilePath::StringType> SessionPreferences::GetValidPreloads(
|
|
|
|
content::BrowserContext* context) {
|
|
|
|
std::vector<base::FilePath::StringType> result;
|
|
|
|
|
|
|
|
if (auto* self = FromBrowserContext(context)) {
|
|
|
|
for (const auto& preload : self->preloads()) {
|
|
|
|
if (base::FilePath(preload).IsAbsolute()) {
|
|
|
|
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
|