forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add chrome.i18nPrivate.getStrings for translations in component exten…
…sions This common API will allow the deduplication of several existing getStrings APIs. This CL also replaces the existing chrome.identityPrivate.getStrings API with the common API. BUG=529546 NOPRESUBMIT=true (Disabling to allow a rename in the histogram enum) Review URL: https://codereview.chromium.org/1319293004 Cr-Commit-Position: refs/heads/master@{#349341}
- Loading branch information
1 parent
47d5ce8
commit e420a14
Showing
23 changed files
with
183 additions
and
74 deletions.
There are no files selected for viewing
30 changes: 0 additions & 30 deletions
30
chrome/browser/extensions/api/identity_private/identity_private_api.cc
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
chrome/browser/extensions/api/identity_private/identity_private_api.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tsergeant@chromium.org |
59 changes: 59 additions & 0 deletions
59
chrome/browser/extensions/api/resources_private/resources_private_api.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/extensions/api/resources_private/resources_private_api.h" | ||
|
||
#include <string> | ||
|
||
#include "base/values.h" | ||
#include "chrome/browser/browser_process.h" | ||
#include "chrome/common/extensions/api/resources_private.h" | ||
#include "chrome/grit/generated_resources.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/base/webui/web_ui_util.h" | ||
|
||
// To add a new component to this API, simply: | ||
// 1. Add your component to the Component enum in | ||
// chrome/common/extensions/api/resources_private.idl | ||
// 2. Create an AddStringsForMyComponent(base::DictionaryValue * dict) method. | ||
// 3. Tie in that method to the switch statement in Run() | ||
|
||
namespace extensions { | ||
|
||
namespace { | ||
|
||
void AddStringsForIdentity(base::DictionaryValue* dict) { | ||
dict->SetString("window-title", | ||
l10n_util::GetStringUTF16(IDS_EXTENSION_CONFIRM_PERMISSIONS)); | ||
} | ||
|
||
} // namespace | ||
|
||
namespace get_strings = api::resources_private::GetStrings; | ||
|
||
ResourcesPrivateGetStringsFunction::ResourcesPrivateGetStringsFunction() {} | ||
|
||
ResourcesPrivateGetStringsFunction::~ResourcesPrivateGetStringsFunction() {} | ||
|
||
ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() { | ||
scoped_ptr<get_strings::Params> params(get_strings::Params::Create(*args_)); | ||
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | ||
|
||
api::resources_private::Component component = params->component; | ||
|
||
switch (component) { | ||
case api::resources_private::COMPONENT_IDENTITY: | ||
AddStringsForIdentity(dict.get()); | ||
break; | ||
case api::resources_private::COMPONENT_NONE: | ||
NOTREACHED(); | ||
} | ||
|
||
const std::string& app_locale = g_browser_process->GetApplicationLocale(); | ||
webui::SetLoadTimeDataDefaults(app_locale, dict.get()); | ||
|
||
return RespondNow(OneArgument(dict.Pass())); | ||
} | ||
|
||
} // namespace extensions |
30 changes: 30 additions & 0 deletions
30
chrome/browser/extensions/api/resources_private/resources_private_api.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_EXTENSIONS_API_RESOURCES_PRIVATE_RESOURCES_PRIVATE_API_H_ | ||
#define CHROME_BROWSER_EXTENSIONS_API_RESOURCES_PRIVATE_RESOURCES_PRIVATE_API_H_ | ||
|
||
#include "extensions/browser/extension_function.h" | ||
|
||
namespace extensions { | ||
|
||
class ResourcesPrivateGetStringsFunction : public UIThreadExtensionFunction { | ||
public: | ||
DECLARE_EXTENSION_FUNCTION("resourcesPrivate.getStrings", | ||
RESOURCESPRIVATE_GETSTRINGS); | ||
ResourcesPrivateGetStringsFunction(); | ||
|
||
protected: | ||
~ResourcesPrivateGetStringsFunction() override; | ||
|
||
// Override from ExtensionFunction: | ||
ExtensionFunction::ResponseAction Run() override; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(ResourcesPrivateGetStringsFunction); | ||
}; | ||
|
||
} // namespace extensions | ||
|
||
#endif // CHROME_BROWSER_EXTENSIONS_API_RESOURCES_PRIVATE_RESOURCES_PRIVATE_API_H_ |
17 changes: 17 additions & 0 deletions
17
chrome/browser/extensions/api/resources_private/resources_private_apitest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/extensions/extension_apitest.h" | ||
|
||
class ResourcesPrivateApiTest : public ExtensionApiTest { | ||
public: | ||
ResourcesPrivateApiTest() {} | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(ResourcesPrivateApiTest); | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(ResourcesPrivateApiTest, GetStrings) { | ||
ASSERT_TRUE(RunComponentExtensionTest("resources_private/get_strings")); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"permissions": [ | ||
"chrome://theme/", | ||
"identityPrivate", | ||
"resourcesPrivate", | ||
"webview" | ||
], | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// resourcesPrivate. | ||
namespace resourcesPrivate { | ||
enum Component { identity }; | ||
|
||
callback GetStringsCallback = void (object result); | ||
|
||
interface Functions { | ||
// Gets localized strings for a component extension. Includes default WebUI | ||
// loadTimeData values for text and language settings (fontsize, fontfamily, | ||
// language, textdirection). See | ||
// chrome/browser/extensions/api/resources_private/resources_private_api.cc | ||
// for instructions on adding a new component to this API. | ||
// | ||
// |component| : Internal chrome component to get strings for. | ||
// |callback| : Called with a dictionary mapping names to strings. | ||
static void getStrings(Component component, | ||
GetStringsCallback callback); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
chrome/test/data/extensions/api_test/resources_private/get_strings/background.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
chrome.test.runTests([ | ||
function testGetStrings() { | ||
chrome.resourcesPrivate.getStrings( | ||
"identity", chrome.test.callbackPass(function(data) { | ||
// String from the identity component. | ||
chrome.test.assertTrue('window-title' in data); | ||
// String from the loadTimeData defaults. | ||
chrome.test.assertTrue('language' in data); | ||
chrome.test.succeed(); | ||
})); | ||
} | ||
]); |
10 changes: 10 additions & 0 deletions
10
chrome/test/data/extensions/api_test/resources_private/get_strings/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHKqRS2RUwmWJCzsOFjSRfd7f69w/yEWuddTD61QwwfeOpaA2+ZiQugaMb5HpLCbFNVBwHXKO1UxWF18YPHYMzMtDfbgjIxtQg3YRPCuicHR0qoo4jfzn9gY+6KW4csS4AH6/Tj700s5SvG25Ty6P6v9p9ZHPEVX9DeYeSllCWdwIDAQAB", | ||
"name": "chrome.resourcesPrivate.getStrings test", | ||
"version": "1", | ||
"manifest_version": 2, | ||
"background": { | ||
"scripts": ["background.js"] | ||
}, | ||
"permissions": ["resourcesPrivate"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters