зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1015521: Bing translation service will now uses available credentials. r=felipe
This commit is contained in:
Родитель
0fa4d64fa1
Коммит
0078888ef0
|
@ -8,6 +8,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
|||
|
||||
this.EXPORTED_SYMBOLS = [ "BingTranslation" ];
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Log.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
|
@ -327,8 +328,10 @@ let BingTokenManager = {
|
|||
let params = [
|
||||
"grant_type=client_credentials",
|
||||
"scope=" + encodeURIComponent("http://api.microsofttranslator.com"),
|
||||
"client_id=",
|
||||
"client_secret="
|
||||
"client_id=" +
|
||||
getAuthTokenParam("%BING_API_CLIENTID%", "browser.translation.bing.clientIdOverride"),
|
||||
"client_secret=" +
|
||||
getAuthTokenParam("%BING_API_KEY%", "browser.translation.bing.apiKeyOverride")
|
||||
];
|
||||
|
||||
let deferred = Promise.defer();
|
||||
|
@ -367,3 +370,16 @@ function escapeXML(aStr) {
|
|||
.replace("<", "<", "g")
|
||||
.replace(">", ">", "g");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an auth token (clientID or client secret), which may be overridden by
|
||||
* a pref if it's set.
|
||||
*/
|
||||
function getAuthTokenParam(key, prefName) {
|
||||
let val;
|
||||
try {
|
||||
val = Services.prefs.getCharPref(prefName);
|
||||
} catch(ex) {}
|
||||
|
||||
return encodeURIComponent(Services.urlFormatter.formatURL(val || key));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче