plugin_info.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 "chrome/common/pdf_util.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(kPDFMimeType, "pdf", "Portable Document Format");
  30. return info;
  31. }
  32. #endif // BUILDFLAG(ENABLE_PDF_VIEWER)
  33. } // namespace electron