Bug 1334111 - Move MediaKeySystemConfig to-string helper to MediaKeySystemAccess. r=gerald
This will enable us to re-use the logging code in MediaKeySystemAccess to log
the configuration we end up instantiating the MediaKeySystemAccess with.
MozReview-Commit-ID: AMnauhMLJ1R
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1899,114 +1899,25 @@ Navigator::GetUserAgent(nsPIDOMWindowInn
return rv;
}
CopyASCIItoUTF16(userAgent, aUserAgent);
}
return NS_OK;
}
static nsCString
-ToCString(const nsString& aString)
-{
- nsCString str("'");
- str.Append(NS_ConvertUTF16toUTF8(aString));
- str.AppendLiteral("'");
- return str;
-}
-
-static nsCString
-ToCString(const MediaKeysRequirement aValue)
-{
- nsCString str("'");
- str.Append(nsDependentCString(MediaKeysRequirementValues::strings[static_cast<uint32_t>(aValue)].value));
- str.AppendLiteral("'");
- return str;
-}
-
-static nsCString
-ToCString(const MediaKeySystemMediaCapability& aValue)
-{
- nsCString str;
- str.AppendLiteral("{contentType=");
- str.Append(ToCString(aValue.mContentType));
- str.AppendLiteral(", robustness=");
- str.Append(ToCString(aValue.mRobustness));
- str.AppendLiteral("}");
- return str;
-}
-
-template<class Type>
-static nsCString
-ToCString(const Sequence<Type>& aSequence)
-{
- nsCString str;
- str.AppendLiteral("[");
- for (size_t i = 0; i < aSequence.Length(); i++) {
- if (i != 0) {
- str.AppendLiteral(",");
- }
- str.Append(ToCString(aSequence[i]));
- }
- str.AppendLiteral("]");
- return str;
-}
-
-template<class Type>
-static nsCString
-ToCString(const Optional<Sequence<Type>>& aOptional)
-{
- nsCString str;
- if (aOptional.WasPassed()) {
- str.Append(ToCString(aOptional.Value()));
- } else {
- str.AppendLiteral("[]");
- }
- return str;
-}
-
-static nsCString
-ToCString(const MediaKeySystemConfiguration& aConfig)
-{
- nsCString str;
- str.AppendLiteral("{label=");
- str.Append(ToCString(aConfig.mLabel));
-
- str.AppendLiteral(", initDataTypes=");
- str.Append(ToCString(aConfig.mInitDataTypes));
-
- str.AppendLiteral(", audioCapabilities=");
- str.Append(ToCString(aConfig.mAudioCapabilities));
-
- str.AppendLiteral(", videoCapabilities=");
- str.Append(ToCString(aConfig.mVideoCapabilities));
-
- str.AppendLiteral(", distinctiveIdentifier=");
- str.Append(ToCString(aConfig.mDistinctiveIdentifier));
-
- str.AppendLiteral(", persistentState=");
- str.Append(ToCString(aConfig.mPersistentState));
-
- str.AppendLiteral(", sessionTypes=");
- str.Append(ToCString(aConfig.mSessionTypes));
-
- str.AppendLiteral("}");
-
- return str;
-}
-
-static nsCString
RequestKeySystemAccessLogString(
const nsAString& aKeySystem,
const Sequence<MediaKeySystemConfiguration>& aConfigs,
bool aIsSecureContext)
{
nsCString str;
str.AppendPrintf("Navigator::RequestMediaKeySystemAccess(keySystem='%s' options=",
NS_ConvertUTF16toUTF8(aKeySystem).get());
- str.Append(ToCString(aConfigs));
+ str.Append(MediaKeySystemAccess::ToCString(aConfigs));
str.AppendLiteral(") secureContext=");
str.AppendInt(aIsSecureContext);
return str;
}
already_AddRefed<Promise>
Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem,
const Sequence<MediaKeySystemConfiguration>& aConfigs,
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -1091,10 +1091,108 @@ MediaKeySystemAccess::NotifyObservers(ns
data.ToJSON(json);
EME_LOG("MediaKeySystemAccess::NotifyObservers() %s", NS_ConvertUTF16toUTF8(json).get());
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
obs->NotifyObservers(aWindow, "mediakeys-request", json.get());
}
}
+static nsCString
+ToCString(const nsString& aString)
+{
+ nsCString str("'");
+ str.Append(NS_ConvertUTF16toUTF8(aString));
+ str.AppendLiteral("'");
+ return str;
+}
+
+static nsCString
+ToCString(const MediaKeysRequirement aValue)
+{
+ nsCString str("'");
+ str.Append(nsDependentCString(
+ MediaKeysRequirementValues::strings[static_cast<uint32_t>(aValue)].value));
+ str.AppendLiteral("'");
+ return str;
+}
+
+static nsCString
+ToCString(const MediaKeySystemMediaCapability& aValue)
+{
+ nsCString str;
+ str.AppendLiteral("{contentType=");
+ str.Append(ToCString(aValue.mContentType));
+ str.AppendLiteral(", robustness=");
+ str.Append(ToCString(aValue.mRobustness));
+ str.AppendLiteral("}");
+ return str;
+}
+
+template<class Type>
+static nsCString
+ToCString(const Sequence<Type>& aSequence)
+{
+ nsCString str;
+ str.AppendLiteral("[");
+ for (size_t i = 0; i < aSequence.Length(); i++) {
+ if (i != 0) {
+ str.AppendLiteral(",");
+ }
+ str.Append(ToCString(aSequence[i]));
+ }
+ str.AppendLiteral("]");
+ return str;
+}
+
+template<class Type>
+static nsCString
+ToCString(const Optional<Sequence<Type>>& aOptional)
+{
+ nsCString str;
+ if (aOptional.WasPassed()) {
+ str.Append(ToCString(aOptional.Value()));
+ } else {
+ str.AppendLiteral("[]");
+ }
+ return str;
+}
+
+static nsCString
+ToCString(const MediaKeySystemConfiguration& aConfig)
+{
+ nsCString str;
+ str.AppendLiteral("{label=");
+ str.Append(ToCString(aConfig.mLabel));
+
+ str.AppendLiteral(", initDataTypes=");
+ str.Append(ToCString(aConfig.mInitDataTypes));
+
+ str.AppendLiteral(", audioCapabilities=");
+ str.Append(ToCString(aConfig.mAudioCapabilities));
+
+ str.AppendLiteral(", videoCapabilities=");
+ str.Append(ToCString(aConfig.mVideoCapabilities));
+
+ str.AppendLiteral(", distinctiveIdentifier=");
+ str.Append(ToCString(aConfig.mDistinctiveIdentifier));
+
+ str.AppendLiteral(", persistentState=");
+ str.Append(ToCString(aConfig.mPersistentState));
+
+ str.AppendLiteral(", sessionTypes=");
+ str.Append(ToCString(aConfig.mSessionTypes));
+
+ str.AppendLiteral("}");
+
+ return str;
+}
+
+/* static */
+nsCString
+MediaKeySystemAccess::ToCString(
+ const Sequence<MediaKeySystemConfiguration>& aConfig)
+{
+ return mozilla::dom::ToCString(aConfig);
+}
+
} // namespace dom
} // namespace mozilla
--- a/dom/media/eme/MediaKeySystemAccess.h
+++ b/dom/media/eme/MediaKeySystemAccess.h
@@ -66,16 +66,19 @@ public:
const Sequence<MediaKeySystemConfiguration>& aConfigs,
MediaKeySystemConfiguration& aOutConfig,
DecoderDoctorDiagnostics* aDiagnostics,
bool aIsPrivateBrowsing);
static bool KeySystemSupportsInitDataType(const nsAString& aKeySystem,
const nsAString& aInitDataType);
+ static nsCString ToCString(
+ const Sequence<MediaKeySystemConfiguration>& aConfig);
+
private:
nsCOMPtr<nsPIDOMWindowInner> mParent;
const nsString mKeySystem;
const MediaKeySystemConfiguration mConfig;
};
} // namespace dom
} // namespace mozilla