mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 1501102 - Move hard-coded 'supportedRegions' array to a pref to allow developers outside US/CA to test PaymentRequest. r=baku
This commit is contained in:
parent
4d914524a2
commit
f65e9d610d
@ -65,24 +65,17 @@ bool
|
||||
PaymentRequest::PrefEnabled(JSContext* aCx, JSObject* aObj)
|
||||
{
|
||||
#if defined(NIGHTLY_BUILD)
|
||||
const char* supportedRegions[] = { "US", "CA" };
|
||||
|
||||
if (!XRE_IsContentProcess()) {
|
||||
return false;
|
||||
}
|
||||
if (!StaticPrefs::dom_payments_request_enabled()) {
|
||||
return false;
|
||||
}
|
||||
RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
|
||||
MOZ_ASSERT(manager);
|
||||
nsAutoString region;
|
||||
Preferences::GetString("browser.search.region", region);
|
||||
bool regionIsSupported = false;
|
||||
for (const char* each : supportedRegions) {
|
||||
if (region.EqualsASCII(each)) {
|
||||
regionIsSupported = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!regionIsSupported) {
|
||||
if (!manager->IsRegionSupported(region)) {
|
||||
return false;
|
||||
}
|
||||
nsAutoCString locale;
|
||||
|
@ -296,6 +296,42 @@ ConvertResponseData(const IPCPaymentResponseData& aIPCData,
|
||||
/* PaymentRequestManager */
|
||||
|
||||
StaticRefPtr<PaymentRequestManager> gPaymentManager;
|
||||
const char kSupportedRegionsPref[] = "dom.payments.request.supportedRegions";
|
||||
nsTArray<nsString> gSupportedRegions;
|
||||
|
||||
void
|
||||
SupportedRegionsPrefChangedCallback(const char* aPrefName, void* aClosure)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!strcmp(aPrefName, kSupportedRegionsPref));
|
||||
MOZ_ASSERT(!aClosure);
|
||||
|
||||
nsAutoString supportedRegions;
|
||||
Preferences::GetString(aPrefName, supportedRegions);
|
||||
gSupportedRegions.Clear();
|
||||
for (const nsAString& each : supportedRegions.Split(',')) {
|
||||
gSupportedRegions.AppendElement(each);
|
||||
}
|
||||
}
|
||||
|
||||
PaymentRequestManager::PaymentRequestManager()
|
||||
{
|
||||
Preferences::RegisterCallbackAndCall(SupportedRegionsPrefChangedCallback,
|
||||
kSupportedRegionsPref);
|
||||
}
|
||||
|
||||
PaymentRequestManager::~PaymentRequestManager()
|
||||
{
|
||||
MOZ_ASSERT(mActivePayments.Count() == 0);
|
||||
Preferences::UnregisterCallback(SupportedRegionsPrefChangedCallback,
|
||||
kSupportedRegionsPref);
|
||||
}
|
||||
|
||||
bool
|
||||
PaymentRequestManager::IsRegionSupported(const nsAString& region) const
|
||||
{
|
||||
return gSupportedRegions.Contains(region);
|
||||
}
|
||||
|
||||
PaymentRequestChild*
|
||||
PaymentRequestManager::GetPaymentChild(PaymentRequest* aRequest)
|
||||
|
@ -74,16 +74,15 @@ public:
|
||||
const nsAString& aPayerEmail,
|
||||
const nsAString& aPayerPhone);
|
||||
|
||||
bool IsRegionSupported(const nsAString& region) const;
|
||||
|
||||
// Called to ensure that we don't "leak" aRequest if we shut down while it had
|
||||
// an active request to the parent.
|
||||
void RequestIPCOver(PaymentRequest* aRequest);
|
||||
|
||||
private:
|
||||
PaymentRequestManager() = default;
|
||||
~PaymentRequestManager()
|
||||
{
|
||||
MOZ_ASSERT(mActivePayments.Count() == 0);
|
||||
}
|
||||
PaymentRequestManager();
|
||||
~PaymentRequestManager();
|
||||
|
||||
PaymentRequestChild* GetPaymentChild(PaymentRequest* aRequest);
|
||||
|
||||
|
@ -5881,6 +5881,7 @@ pref("dom.timeout.max_consecutive_callbacks_ms", 4);
|
||||
pref("dom.payments.loglevel", "Warn");
|
||||
pref("dom.payments.defaults.saveCreditCard", false);
|
||||
pref("dom.payments.defaults.saveAddress", true);
|
||||
pref("dom.payments.request.supportedRegions", "US,CA");
|
||||
|
||||
#ifdef MOZ_ASAN_REPORTER
|
||||
pref("asanreporter.apiurl", "https://anf1.fuzzing.mozilla.org/crashproxy/submit/");
|
||||
|
Loading…
Reference in New Issue
Block a user