This source file includes following definitions.
- LoadMediaGalleriesHandler
- LoadMediaGalleriesHandlers
- GetHandlers
- Keys
#include "chrome/common/extensions/api/media_galleries_private/media_galleries_handler.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
namespace keys = extensions::manifest_keys;
namespace errors = extensions::manifest_errors;
namespace {
struct MediaGalleriesHandlerInfo : public extensions::Extension::ManifestData {
MediaGalleriesHandler::List media_galleries_handlers;
MediaGalleriesHandlerInfo();
virtual ~MediaGalleriesHandlerInfo();
};
MediaGalleriesHandlerInfo::MediaGalleriesHandlerInfo() {
}
MediaGalleriesHandlerInfo::~MediaGalleriesHandlerInfo() {
}
MediaGalleriesHandler* LoadMediaGalleriesHandler(
const std::string& extension_id,
const base::DictionaryValue* media_galleries_handler,
base::string16* error) {
scoped_ptr<MediaGalleriesHandler> result(new MediaGalleriesHandler());
result->set_extension_id(extension_id);
std::string handler_id;
if (!media_galleries_handler->HasKey(keys::kPageActionId) ||
!media_galleries_handler->GetString(keys::kPageActionId, &handler_id)) {
*error = base::ASCIIToUTF16(errors::kInvalidPageActionId);
return NULL;
}
result->set_id(handler_id);
std::string title;
if (!media_galleries_handler->HasKey(keys::kPageActionDefaultTitle) ||
!media_galleries_handler->GetString(keys::kPageActionDefaultTitle,
&title)) {
*error = base::ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle);
return NULL;
}
result->set_title(title);
std::string default_icon;
if (media_galleries_handler->HasKey(keys::kPageActionDefaultIcon)) {
if (!media_galleries_handler->GetString(
keys::kPageActionDefaultIcon, &default_icon) ||
default_icon.empty()) {
*error = base::ASCIIToUTF16(errors::kInvalidPageActionIconPath);
return NULL;
}
result->set_icon_path(default_icon);
}
return result.release();
}
bool LoadMediaGalleriesHandlers(
const std::string& extension_id,
const base::ListValue* extension_actions,
MediaGalleriesHandler::List* result,
base::string16* error) {
for (base::ListValue::const_iterator iter = extension_actions->begin();
iter != extension_actions->end();
++iter) {
if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) {
*error = base::ASCIIToUTF16(errors::kInvalidMediaGalleriesHandler);
return false;
}
scoped_ptr<MediaGalleriesHandler> action(
LoadMediaGalleriesHandler(
extension_id,
reinterpret_cast<base::DictionaryValue*>(*iter), error));
if (!action)
return false;
result->push_back(linked_ptr<MediaGalleriesHandler>(action.release()));
}
return true;
}
}
MediaGalleriesHandler::MediaGalleriesHandler() {
}
MediaGalleriesHandler::~MediaGalleriesHandler() {
}
MediaGalleriesHandler::List*
MediaGalleriesHandler::GetHandlers(const extensions::Extension* extension) {
MediaGalleriesHandlerInfo* info = static_cast<MediaGalleriesHandlerInfo*>(
extension->GetManifestData(keys::kMediaGalleriesHandlers));
if (info)
return &info->media_galleries_handlers;
return NULL;
}
MediaGalleriesHandlerParser::MediaGalleriesHandlerParser() {
}
MediaGalleriesHandlerParser::~MediaGalleriesHandlerParser() {
}
bool MediaGalleriesHandlerParser::Parse(extensions::Extension* extension,
base::string16* error) {
const base::ListValue* media_galleries_handlers_value = NULL;
if (!extension->manifest()->GetList(keys::kMediaGalleriesHandlers,
&media_galleries_handlers_value)) {
*error = base::ASCIIToUTF16(errors::kInvalidMediaGalleriesHandler);
return false;
}
scoped_ptr<MediaGalleriesHandlerInfo> info(new MediaGalleriesHandlerInfo);
if (!LoadMediaGalleriesHandlers(extension->id(),
media_galleries_handlers_value,
&info->media_galleries_handlers,
error)) {
return false;
}
extension->SetManifestData(keys::kMediaGalleriesHandlers, info.release());
return true;
}
const std::vector<std::string> MediaGalleriesHandlerParser::Keys() const {
return SingleKey(keys::kMediaGalleriesHandlers);
}