session_preferences.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/session_preferences.h"
  5. #include "base/logging.h"
  6. #include "base/memory/ptr_util.h"
  7. #include "content/public/browser/browser_context.h"
  8. namespace electron {
  9. // static
  10. int SessionPreferences::kLocatorKey = 0;
  11. SessionPreferences::SessionPreferences(content::BrowserContext* context) {
  12. context->SetUserData(&kLocatorKey, base::WrapUnique(this));
  13. }
  14. SessionPreferences::~SessionPreferences() = default;
  15. // static
  16. SessionPreferences* SessionPreferences::FromBrowserContext(
  17. content::BrowserContext* context) {
  18. return static_cast<SessionPreferences*>(context->GetUserData(&kLocatorKey));
  19. }
  20. // static
  21. std::vector<base::FilePath> SessionPreferences::GetValidPreloads(
  22. content::BrowserContext* context) {
  23. std::vector<base::FilePath> result;
  24. if (auto* self = FromBrowserContext(context)) {
  25. for (const auto& preload : self->preloads()) {
  26. if (preload.IsAbsolute()) {
  27. result.emplace_back(preload);
  28. } else {
  29. LOG(ERROR) << "preload script must have absolute path: " << preload;
  30. }
  31. }
  32. }
  33. return result;
  34. }
  35. } // namespace electron