Bug 1015521: Bing translation service will now uses available credentials. r=felipe

This commit is contained in:
Mike de Boer 2014-06-03 12:43:12 +02:00
Родитель 0fa4d64fa1
Коммит 0078888ef0
1 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -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("<", "&lt;", "g")
.replace(">", "&gt;", "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));
}