blob: 7c8707645793c90e60b54161568a68fd45e50c73 [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "modules/encryptedmedia/EncryptedMediaUtils.h"
namespace blink {
namespace {
const char kTemporary[] = "temporary";
const char kPersistentLicense[] = "persistent-license";
} // namespace
WebEncryptedMediaInitDataType EncryptedMediaUtils::ConvertToInitDataType(
const String& init_data_type) {
if (init_data_type == "cenc")
return WebEncryptedMediaInitDataType::kCenc;
if (init_data_type == "keyids")
return WebEncryptedMediaInitDataType::kKeyids;
if (init_data_type == "webm")
return WebEncryptedMediaInitDataType::kWebm;
// |initDataType| is not restricted in the idl, so anything is possible.
return WebEncryptedMediaInitDataType::kUnknown;
}
String EncryptedMediaUtils::ConvertFromInitDataType(
WebEncryptedMediaInitDataType init_data_type) {
switch (init_data_type) {
case WebEncryptedMediaInitDataType::kCenc:
return "cenc";
case WebEncryptedMediaInitDataType::kKeyids:
return "keyids";
case WebEncryptedMediaInitDataType::kWebm:
return "webm";
case WebEncryptedMediaInitDataType::kUnknown:
// Chromium should not use Unknown, but we use it in Blink when the
// actual value has been blocked for non-same-origin or mixed content.
return String();
}
NOTREACHED();
return String();
}
WebEncryptedMediaSessionType EncryptedMediaUtils::ConvertToSessionType(
const String& session_type) {
if (session_type == kTemporary)
return WebEncryptedMediaSessionType::kTemporary;
if (session_type == kPersistentLicense)
return WebEncryptedMediaSessionType::kPersistentLicense;
// |sessionType| is not restricted in the idl, so anything is possible.
return WebEncryptedMediaSessionType::kUnknown;
}
String EncryptedMediaUtils::ConvertFromSessionType(
WebEncryptedMediaSessionType session_type) {
switch (session_type) {
case WebEncryptedMediaSessionType::kTemporary:
return kTemporary;
case WebEncryptedMediaSessionType::kPersistentLicense:
return kPersistentLicense;
// FIXME: Remove once removed from Chromium (crbug.com/448888).
case WebEncryptedMediaSessionType::kPersistentReleaseMessage:
case WebEncryptedMediaSessionType::kUnknown:
// Chromium should not use Unknown.
NOTREACHED();
return String();
}
NOTREACHED();
return String();
}
} // namespace blink