| Index: chrome/common/extensions/api/mdns/mdns_manifest_handler.cc
|
| diff --git a/chrome/common/extensions/api/mdns/mdns_manifest_handler.cc b/chrome/common/extensions/api/mdns/mdns_manifest_handler.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1b29cd661029a83b6218c9910715c527c17cc4cb
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/api/mdns/mdns_manifest_handler.cc
|
| @@ -0,0 +1,66 @@
|
| +// Copyright (c) 2013 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 "chrome/common/extensions/api/mdns/mdns_manifest_handler.h"
|
| +
|
| +#include "base/lazy_instance.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "base/values.h"
|
| +#include "chrome/common/extensions/extension_manifest_constants.h"
|
| +#include "extensions/common/error_utils.h"
|
| +
|
| +namespace keys = extensions::manifest_keys;
|
| +namespace errors = extension_manifest_errors;
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace {
|
| +// Whitelisted MDns service types.
|
| +const char kCastDeviceType[] = "_googlecast._tcp.local";
|
| +}
|
| +
|
| +MDnsInfo::MDnsInfo() {}
|
| +MDnsInfo::~MDnsInfo() {}
|
| +
|
| +static base::LazyInstance<MDnsInfo> g_empty_mdns_info =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +// static
|
| +const MDnsInfo& MDnsInfo::GetMDnsInfo(const Extension* extension) {
|
| + MDnsInfo* info = static_cast<MDnsInfo*>(
|
| + extension->GetManifestData(keys::kMDnsServiceTypes));
|
| + return info ? *info : g_empty_mdns_info.Get();
|
| +}
|
| +
|
| +MDnsManifestHandler::MDnsManifestHandler() {}
|
| +MDnsManifestHandler::~MDnsManifestHandler() {}
|
| +
|
| +bool MDnsManifestHandler::Parse(Extension* extension, string16* error) {
|
| + scoped_ptr<MDnsInfo> info(new MDnsInfo);
|
| + const base::ListValue* list = NULL;
|
| + if (!extension->manifest()->GetList(keys::kMDnsServiceTypes, &list)) {
|
| + *error = ASCIIToUTF16(errors::kInvalidMDnsServiceTypes);
|
| + return false;
|
| + }
|
| +
|
| + for (size_t i = 0; i < list->GetSize(); ++i) {
|
| + std::string service_type;
|
| + if (!list->GetString(i, &service_type) ||
|
| + service_type != kCastDeviceType) {
|
| + *error = ASCIIToUTF16(errors::kInvalidMDnsServiceTypes);
|
| + return false;
|
| + }
|
| + info->service_types.push_back(service_type);
|
| + }
|
| +
|
| + extension->SetManifestData(keys::kMDnsServiceTypes, info.release());
|
| + return true;
|
| +}
|
| +
|
| +const std::vector<std::string> MDnsManifestHandler::Keys() const {
|
| + return SingleKey(keys::kMDnsServiceTypes);
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|