Bug 1481971 - Enable PaymentRequest on Nightly for Windows/macOS for US/CA users on en-US builds r=MattN,baku,gandalf
authorDiego Pino Garcia <dpino@igalia.com>
Tue, 16 Oct 2018 16:14:12 -0700
changeset 500094 73912f1633a16370d8b9410ebd35e6dc2532eb3d
parent 500093 3e2b52df8b24f0faf0b1a1f7a32cd8040e53e240
child 500095 025fdcb0c798b7f633c17ce17b282b8f3029cbe5
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, baku, gandalf
bugs1481971
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481971 - Enable PaymentRequest on Nightly for Windows/macOS for US/CA users on en-US builds r=MattN,baku,gandalf
dom/payments/PaymentRequest.cpp
dom/tests/mochitest/general/test_interfaces.js
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
--- a/dom/payments/PaymentRequest.cpp
+++ b/dom/payments/PaymentRequest.cpp
@@ -5,25 +5,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "BasicCardPayment.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/FeaturePolicyUtils.h"
 #include "mozilla/dom/PaymentRequest.h"
 #include "mozilla/dom/PaymentRequestChild.h"
 #include "mozilla/dom/PaymentResponse.h"
+#include "mozilla/intl/LocaleService.h"
+#include "mozilla/intl/MozLocale.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/StaticPrefs.h"
 #include "nsContentUtils.h"
 #include "nsIScriptError.h"
 #include "nsIURLParser.h"
 #include "nsNetCID.h"
 #include "PaymentRequestManager.h"
 #include "mozilla/dom/MerchantValidationEvent.h"
 
+using mozilla::intl::LocaleService;
+
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(PaymentRequest)
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PaymentRequest,
                                                DOMEventTargetHelper)
   // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
@@ -55,21 +59,45 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(PaymentRequest, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(PaymentRequest, DOMEventTargetHelper)
 
 bool
 PaymentRequest::PrefEnabled(JSContext* aCx, JSObject* aObj)
 {
-#ifdef NIGHTLY_BUILD
+#if defined(NIGHTLY_BUILD)
+  const char* supportedRegions[] = { "US", "CA" };
+
   if (!XRE_IsContentProcess()) {
     return false;
   }
-  return StaticPrefs::dom_payments_request_enabled();
+  if (!StaticPrefs::dom_payments_request_enabled()) {
+    return false;
+  }
+  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) {
+    return false;
+  }
+  nsAutoCString locale;
+  LocaleService::GetInstance()->GetAppLocaleAsLangTag(locale);
+  mozilla::intl::Locale loc = mozilla::intl::Locale(locale);
+  if (!(loc.GetLanguage() == "en" && loc.GetRegion() == "US")) {
+    return false;
+  }
+
+  return true;
 #else
   return false;
 #endif
 }
 
 nsresult
 PaymentRequest::IsValidStandardizedPMI(const nsAString& aIdentifier,
                                        nsAString& aErrorMsg)
--- a/dom/tests/mochitest/general/test_interfaces.js
+++ b/dom/tests/mochitest/general/test_interfaces.js
@@ -654,16 +654,18 @@ var interfaceNamesInGlobalScope =
     {name: "MediaStreamAudioSourceNode", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MediaStreamEvent", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MediaStreamTrackEvent", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MediaStreamTrack", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "MerchantValidationEvent", insecureContext: false, desktop: true, nightly: true, linux: false},
+// IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MessageChannel", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MessageEvent", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MessagePort", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MIDIAccess", disabled: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
@@ -734,16 +736,26 @@ var interfaceNamesInGlobalScope =
     {name: "PaintRequest", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "PaintRequestList", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "PannerNode", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "Path2D", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "PaymentAddress", insecureContext: false, desktop: true, nightly: true, linux: false},
+// IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "PaymentMethodChangeEvent", insecureContext: false, desktop: true, nightly: true, linux: false},
+// IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "PaymentRequest", insecureContext: false, desktop: true, nightly: true, linux: false},
+// IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "PaymentRequestUpdateEvent", insecureContext: false, desktop: true, nightly: true, linux: false},
+// IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "PaymentResponse", insecureContext: false, desktop: true, nightly: true, linux: false},
+// IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "Performance", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "PerformanceEntry", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "PerformanceMark", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "PerformanceMeasure", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -218,17 +218,17 @@ VARCACHE_PREF(
 )
 
 // If true. then the service worker interception and the ServiceWorkerManager
 // will live in the parent process.  This only takes effect on browser start.
 // Note, this is not currently safe to use for normal browsing yet.
 PREF("dom.serviceWorkers.parent_intercept", bool, false)
 
 // Enable PaymentRequest API
-#ifdef NIGHTLY_BUILD
+#if defined(NIGHTLY_BUILD) && (defined(XP_WIN) || defined(XP_MACOSX))
 # define PREF_VALUE  true
 #else
 # define PREF_VALUE  false
 #endif
 VARCACHE_PREF(
   "dom.payments.request.enabled",
    dom_payments_request_enabled,
   bool, PREF_VALUE
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5842,18 +5842,17 @@ pref("dom.IntersectionObserver.enabled",
 
 // Whether module scripts (<script type="module">) are enabled for content.
 pref("dom.moduleScripts.enabled", true);
 
 // Maximum amount of time in milliseconds consecutive setTimeout()/setInterval()
 // callback are allowed to run before yielding the event loop.
 pref("dom.timeout.max_consecutive_callbacks_ms", 4);
 
-// Use this preference to house "Payment Request API" during development
-pref("dom.payments.request.enabled", false);
+// Payment Request API preferences
 pref("dom.payments.loglevel", "Warn");
 pref("dom.payments.defaults.saveCreditCard", false);
 pref("dom.payments.defaults.saveAddress", true);
 
 #ifdef MOZ_ASAN_REPORTER
 pref("asanreporter.apiurl", "https://anf1.fuzzing.mozilla.org/crashproxy/submit/");
 pref("asanreporter.clientid", "unknown");
 pref("toolkit.telemetry.overrideUpdateChannel", "nightly-asan");