resources_private_api.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "printing/buildflags/buildflags.h"
  15. #include "ui/base/l10n/l10n_util.h"
  16. #include "ui/base/webui/web_ui_util.h"
  17. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  18. #include "chrome/browser/pdf/pdf_extension_util.h"
  19. #include "pdf/pdf_features.h"
  20. #endif // BUILDFLAG(ENABLE_PDF_VIEWER)
  21. // To add a new component to this API, simply:
  22. // 1. Add your component to the Component enum in
  23. // shell/common/extensions/api/resources_private.idl
  24. // 2. Create an AddStringsForMyComponent(base::Value::Dict* dict) method.
  25. // 3. Tie in that method to the switch statement in Run()
  26. namespace extensions {
  27. namespace get_strings = api::resources_private::GetStrings;
  28. ResourcesPrivateGetStringsFunction::ResourcesPrivateGetStringsFunction() =
  29. default;
  30. ResourcesPrivateGetStringsFunction::~ResourcesPrivateGetStringsFunction() =
  31. default;
  32. ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() {
  33. absl::optional<get_strings::Params> params(
  34. get_strings::Params::Create(args()));
  35. base::Value::Dict dict;
  36. api::resources_private::Component component = params->component;
  37. switch (component) {
  38. case api::resources_private::Component::kPdf:
  39. #if BUILDFLAG(ENABLE_PDF_VIEWER)
  40. pdf_extension_util::AddStrings(
  41. pdf_extension_util::PdfViewerContext::kPdfViewer, &dict);
  42. pdf_extension_util::AddAdditionalData(true, false, &dict);
  43. #endif
  44. break;
  45. case api::resources_private::Component::kIdentity:
  46. NOTREACHED();
  47. break;
  48. case api::resources_private::Component::kNone:
  49. NOTREACHED();
  50. break;
  51. }
  52. const std::string& app_locale = g_browser_process->GetApplicationLocale();
  53. webui::SetLoadTimeDataDefaults(app_locale, &dict);
  54. return RespondNow(WithArguments(std::move(dict)));
  55. }
  56. } // namespace extensions