Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / resources_private / resources_private_api.cc
blobbfaa40f7f400f3c49a414b282cb953404dc6713b
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.
5 #include "chrome/browser/extensions/api/resources_private/resources_private_api.h"
7 #include <string>
9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/common/extensions/api/resources_private.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "components/strings/grit/components_strings.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/webui/web_ui_util.h"
17 // To add a new component to this API, simply:
18 // 1. Add your component to the Component enum in
19 // chrome/common/extensions/api/resources_private.idl
20 // 2. Create an AddStringsForMyComponent(base::DictionaryValue * dict) method.
21 // 3. Tie in that method to the switch statement in Run()
23 namespace extensions {
25 namespace {
27 void AddStringsForIdentity(base::DictionaryValue* dict) {
28 dict->SetString("window-title",
29 l10n_util::GetStringUTF16(IDS_EXTENSION_CONFIRM_PERMISSIONS));
32 void AddStringsForPdf(base::DictionaryValue* dict) {
33 dict->SetString("passwordPrompt",
34 l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD));
35 dict->SetString("pageLoading",
36 l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOADING));
37 dict->SetString("pageLoadFailed",
38 l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED));
41 } // namespace
43 namespace get_strings = api::resources_private::GetStrings;
45 ResourcesPrivateGetStringsFunction::ResourcesPrivateGetStringsFunction() {}
47 ResourcesPrivateGetStringsFunction::~ResourcesPrivateGetStringsFunction() {}
49 ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() {
50 scoped_ptr<get_strings::Params> params(get_strings::Params::Create(*args_));
51 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
53 api::resources_private::Component component = params->component;
55 switch (component) {
56 case api::resources_private::COMPONENT_IDENTITY:
57 AddStringsForIdentity(dict.get());
58 break;
59 case api::resources_private::COMPONENT_PDF:
60 AddStringsForPdf(dict.get());
61 break;
62 case api::resources_private::COMPONENT_NONE:
63 NOTREACHED();
66 const std::string& app_locale = g_browser_process->GetApplicationLocale();
67 webui::SetLoadTimeDataDefaults(app_locale, dict.get());
69 return RespondNow(OneArgument(dict.Pass()));
72 } // namespace extensions