feat(extensions): add chrome.i18n API (#22455)
* feat(extensions): implement chrome.i18n API * refactor(extensions): use forward declaration for ScriptExecutor * fix(extensions): add message filter to handle i18n GetMessageBundle * test(extensions): add chrome.i18n tests * fix(extensions): message filter lint error * fix: remove exclusive test * fix(extensions): format api feature arrays Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net> * fix(extensions): uncomment chrome.i18n usage in old extensions test Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net>
This commit is contained in:
parent
1e9fa204ee
commit
d6701ff435
18 changed files with 502 additions and 3 deletions
|
@ -11,6 +11,7 @@ assert(enable_extensions,
|
|||
function_registration("api_registration") {
|
||||
sources = [
|
||||
"//electron/shell/common/extensions/api/extension.json",
|
||||
"//electron/shell/common/extensions/api/i18n.json",
|
||||
"//electron/shell/common/extensions/api/resources_private.idl",
|
||||
"//electron/shell/common/extensions/api/tabs.json",
|
||||
]
|
||||
|
|
24
shell/browser/extensions/api/i18n/i18n_api.cc
Normal file
24
shell/browser/extensions/api/i18n/i18n_api.cc
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2020 Samuel Maddock <sam@samuelmaddock.com>.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "shell/browser/extensions/api/i18n/i18n_api.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "shell/common/extensions/api/i18n.h"
|
||||
|
||||
namespace GetAcceptLanguages = extensions::api::i18n::GetAcceptLanguages;
|
||||
|
||||
namespace extensions {
|
||||
|
||||
ExtensionFunction::ResponseAction I18nGetAcceptLanguagesFunction::Run() {
|
||||
auto locale = g_browser_process->GetApplicationLocale();
|
||||
std::vector<std::string> accept_languages = {locale};
|
||||
return RespondNow(
|
||||
ArgumentList(GetAcceptLanguages::Results::Create(accept_languages)));
|
||||
}
|
||||
|
||||
} // namespace extensions
|
20
shell/browser/extensions/api/i18n/i18n_api.h
Normal file
20
shell/browser/extensions/api/i18n/i18n_api.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) 2020 Samuel Maddock <sam@samuelmaddock.com>.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
|
||||
#define SHELL_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
|
||||
|
||||
#include "extensions/browser/extension_function.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
class I18nGetAcceptLanguagesFunction : public ExtensionFunction {
|
||||
~I18nGetAcceptLanguagesFunction() override {}
|
||||
ResponseAction Run() override;
|
||||
DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES)
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // SHELL_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
|
Loading…
Add table
Add a link
Reference in a new issue