plugin_info.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) 2022 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/common/plugin_info.h"
  5. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  6. #include "base/strings/utf_string_conversions.h"
  7. #include "components/pdf/common/constants.h"
  8. #include "extensions/common/constants.h"
  9. #include "shell/common/electron_constants.h"
  10. #endif // BUILDFLAG(ENABLE_PDF_VIEWER)
  11. namespace electron {
  12. void GetInternalPlugins(std::vector<content::WebPluginInfo>* plugins) {
  13. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  14. // NB. in Chrome, this plugin isn't registered until the PDF extension is
  15. // loaded. However, in Electron, we load the PDF extension unconditionally
  16. // when it is enabled in the build, so we're OK to load the plugin eagerly
  17. // here.
  18. plugins->push_back(GetPDFPluginInfo());
  19. #endif
  20. }
  21. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  22. content::WebPluginInfo GetPDFPluginInfo() {
  23. content::WebPluginInfo info;
  24. info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN;
  25. info.name = base::ASCIIToUTF16(kPDFExtensionPluginName);
  26. // This isn't a real file path; it's just used as a unique identifier.
  27. info.path = base::FilePath::FromUTF8Unsafe(extension_misc::kPdfExtensionId);
  28. info.background_color = content::WebPluginInfo::kDefaultBackgroundColor;
  29. info.mime_types.emplace_back(pdf::kPDFMimeType, "pdf",
  30. "Portable Document Format");
  31. return info;
  32. }
  33. #endif // BUILDFLAG(ENABLE_PDF_VIEWER)
  34. } // namespace electron