resources_private_api.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/extensions/api/resources_private/resources_private_api.h"
  5. #include <string>
  6. #include <utility>
  7. #include "base/values.h"
  8. #include "chrome/browser/browser_process.h"
  9. #include "chrome/common/extensions/api/resources_private.h"
  10. #include "chrome/grit/generated_resources.h"
  11. #include "components/strings/grit/components_strings.h"
  12. #include "components/zoom/page_zoom_constants.h"
  13. #include "electron/buildflags/buildflags.h"
  14. #include "ui/base/l10n/l10n_util.h"
  15. #include "ui/base/webui/web_ui_util.h"
  16. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  17. #include "chrome/browser/pdf/pdf_extension_util.h"
  18. #include "pdf/pdf_features.h"
  19. #endif // BUILDFLAG(ENABLE_PDF_VIEWER)
  20. // To add a new component to this API, simply:
  21. // 1. Add your component to the Component enum in
  22. // shell/common/extensions/api/resources_private.idl
  23. // 2. Create an AddStringsForMyComponent(base::Value::Dict* dict) method.
  24. // 3. Tie in that method to the switch statement in Run()
  25. namespace extensions {
  26. namespace get_strings = api::resources_private::GetStrings;
  27. ResourcesPrivateGetStringsFunction::ResourcesPrivateGetStringsFunction() =
  28. default;
  29. ResourcesPrivateGetStringsFunction::~ResourcesPrivateGetStringsFunction() =
  30. default;
  31. ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() {
  32. std::optional<get_strings::Params> params(
  33. get_strings::Params::Create(args()));
  34. base::Value::Dict dict;
  35. api::resources_private::Component component = params->component;
  36. switch (component) {
  37. case api::resources_private::Component::kPdf:
  38. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  39. pdf_extension_util::AddStrings(
  40. pdf_extension_util::PdfViewerContext::kPdfViewer, &dict);
  41. pdf_extension_util::AddAdditionalData(true, false, &dict);
  42. #endif
  43. break;
  44. case api::resources_private::Component::kIdentity:
  45. NOTREACHED();
  46. case api::resources_private::Component::kNone:
  47. NOTREACHED();
  48. }
  49. const std::string& app_locale = g_browser_process->GetApplicationLocale();
  50. webui::SetLoadTimeDataDefaults(app_locale, &dict);
  51. return RespondNow(WithArguments(std::move(dict)));
  52. }
  53. } // namespace extensions