Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3624)

Unified Diff: chrome/common/extensions/mime_types_handler.cc

Issue 12381035: Move Mime type handling to streamsPrivate API, so that it works on Desktop Chrome. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Initialize test variable Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/mime_types_handler.cc
diff --git a/chrome/common/extensions/mime_types_handler.cc b/chrome/common/extensions/mime_types_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2d5214e3d4415dfa2343421b43f4f695cabf1b43
--- /dev/null
+++ b/chrome/common/extensions/mime_types_handler.cc
@@ -0,0 +1,116 @@
+// Copyright (c) 2012 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/mime_types_handler.h"
+
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest.h"
+#include "content/public/common/url_constants.h"
+#include "extensions/common/error_utils.h"
+#include "extensions/common/url_pattern.h"
+#include "googleurl/src/gurl.h"
+#include "googleurl/src/url_util.h"
+
+namespace keys = extension_manifest_keys;
+namespace errors = extension_manifest_errors;
+
+namespace {
+
+const char* const kMIMETypeHandlersWhitelist[] = {
+ extension_misc::kQuickOfficeExtensionId,
+ extension_misc::kQuickOfficeDevExtensionId,
+ extension_misc::kStreamsPrivateTestExtensionId
+};
+
+// Stored on the Extension.
+struct MimeTypesHandlerInfo : public extensions::Extension::ManifestData {
+ MimeTypesHandler handler_;
+
+ MimeTypesHandlerInfo();
+ virtual ~MimeTypesHandlerInfo();
+};
+
+MimeTypesHandlerInfo::MimeTypesHandlerInfo() {
+}
+
+MimeTypesHandlerInfo::~MimeTypesHandlerInfo() {
+}
+
+} // namespace
+
+// static
+std::vector<std::string> MimeTypesHandler::GetMIMETypeWhitelist() {
+ std::vector<std::string> whitelist;
+ if (g_test_extension_id_)
+ whitelist.push_back(*g_test_extension_id_);
+ for (size_t i = 0; i < arraysize(kMIMETypeHandlersWhitelist); ++i)
+ whitelist.push_back(kMIMETypeHandlersWhitelist[i]);
+ return whitelist;
+}
+
+MimeTypesHandler::MimeTypesHandler() {
+}
+
+MimeTypesHandler::~MimeTypesHandler() {
+}
+
+void MimeTypesHandler::AddMIMEType(const std::string& mime_type) {
+ mime_type_set_.insert(mime_type);
+}
+
+bool MimeTypesHandler::CanHandleMIMEType(const std::string& mime_type) const {
+ return mime_type_set_.find(mime_type) != mime_type_set_.end();
+}
+
+// static
+MimeTypesHandler* MimeTypesHandler::GetHandler(
+ const extensions::Extension* extension) {
+ MimeTypesHandlerInfo* info = static_cast<MimeTypesHandlerInfo*>(
+ extension->GetManifestData(keys::kMimeTypesHandler));
+ if (info)
+ return &info->handler_;
+ return NULL;
+}
+
+std::string* MimeTypesHandler::g_test_extension_id_ = NULL;
+
+MimeTypesHandlerParser::MimeTypesHandlerParser() {
+}
+
+MimeTypesHandlerParser::~MimeTypesHandlerParser() {
+}
+
+bool MimeTypesHandlerParser::Parse(extensions::Extension* extension,
+ string16* error) {
+ const ListValue* mime_types_value = NULL;
+ if (!extension->manifest()->GetList(keys::kMIMETypes,
+ &mime_types_value)) {
+ *error = ASCIIToUTF16(errors::kInvalidMimeTypesHandler);
+ return false;
+ }
+
+ scoped_ptr<MimeTypesHandlerInfo> info(new MimeTypesHandlerInfo);
+ info->handler_.set_extension_id(extension->id());
+ for (size_t i = 0; i < mime_types_value->GetSize(); ++i) {
+ std::string filter;
+ if (!mime_types_value->GetString(i, &filter)) {
+ *error = ASCIIToUTF16(errors::kInvalidMIMETypes);
+ return false;
+ }
+ info->handler_.AddMIMEType(filter);
+ }
+
+ extension->SetManifestData(keys::kMimeTypesHandler, info.release());
+ return true;
+}
+
+const std::vector<std::string> MimeTypesHandlerParser::Keys() const {
+ return SingleKey(keys::kMIMETypes);
+}
« no previous file with comments | « chrome/common/extensions/mime_types_handler.h ('k') | chrome/common/extensions/permissions/api_permission.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698