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

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

Issue 11360026: Add the "file_handlers" manifest key for platform apps to replace "intents". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index c15bcd2624f82748e1d852396edd482c69a1b6d9..43bd5637da01fbc7f8c6e3ab32931638ebe0dc03 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -15,10 +15,10 @@
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/stl_util.h"
-#include "base/string16.h"
#include "base/string_number_conversions.h"
#include "base/string_piece.h"
#include "base/string_util.h"
+#include "base/string16.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -35,8 +35,8 @@
#include "chrome/common/extensions/features/simple_feature_provider.h"
#include "chrome/common/extensions/file_browser_handler.h"
#include "chrome/common/extensions/manifest.h"
-#include "chrome/common/extensions/permissions/permissions_info.h"
#include "chrome/common/extensions/permissions/permission_set.h"
+#include "chrome/common/extensions/permissions/permissions_info.h"
#include "chrome/common/extensions/url_pattern_set.h"
#include "chrome/common/extensions/user_script.h"
#include "chrome/common/url_constants.h"
@@ -2108,6 +2108,79 @@ bool Extension::LoadWebIntentServices(string16* error) {
return true;
}
+bool Extension::LoadFileHandler(const std::string& handler_id,
+ const DictionaryValue& handler_info,
+ string16* error) {
+ DCHECK(error);
+ DCHECK(is_platform_app());
+ webkit_glue::WebIntentServiceData service;
+ std::string value;
+
+ service.action = ASCIIToUTF16("http://webintents.org/view");
benwells 2012/11/01 04:00:55 Add a TODO to create new fields to map this to and
jeremya 2012/11/01 04:21:41 Done.
+
+ const ListValue* mime_types = NULL;
+ if (!handler_info.HasKey(keys::kFileHandlerTypes) ||
+ !handler_info.GetList(keys::kFileHandlerTypes, &mime_types) ||
+ mime_types->GetSize() == 0) {
+ *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidFileHandlerType, handler_id);
+ return false;
+ }
+
+ service.service_url = GetBackgroundURL();
+
+ if (handler_info.HasKey(keys::kIntentTitle) &&
+ !handler_info.GetString(keys::kFileHandlerTitle, &service.title)) {
+ *error = ASCIIToUTF16(errors::kInvalidFileHandlerTitle);
+ return false;
+ }
+
+ for (size_t i = 0; i < mime_types->GetSize(); ++i) {
+ if (!mime_types->GetString(i, &service.type)) {
+ *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidFileHandlerTypeElement, handler_id,
+ std::string(base::IntToString(i)));
+ return false;
+ }
+ intents_services_.push_back(service);
+ }
+ return true;
+}
+
+bool Extension::LoadFileHandlers(string16* error) {
+ DCHECK(error);
+
+ if (!manifest_->HasKey(keys::kFileHandlers))
+ return true;
+
+ if (!is_platform_app()) {
+ // XXX isn't this handled somehow by _manifest_features.json?
benwells 2012/11/01 04:00:55 Should be. Feel free to remove.
jeremya 2012/11/01 04:21:41 Done.
+ *error = ASCIIToUTF16(errors::kInvalidFileHandlers);
+ return false;
+ }
+
+ DictionaryValue* all_handlers = NULL;
+ if (!manifest_->GetDictionary(keys::kFileHandlers, &all_handlers)) {
+ *error = ASCIIToUTF16(errors::kInvalidFileHandlers);
+ return false;
+ }
+
+ for (DictionaryValue::key_iterator iter(all_handlers->begin_keys());
+ iter != all_handlers->end_keys(); ++iter) {
+ // A file handler entry is a title, optional icons, and either a list of
benwells 2012/11/01 04:00:55 This isn't yet true, let's make the comment match
jeremya 2012/11/01 04:21:41 Done.
+ // MIME types to handle or a list of file extensions (or both).
+ DictionaryValue* handler = NULL;
+ if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) {
+ if (!LoadFileHandler(*iter, *handler, error))
+ return false;
+ } else {
+ *error = ASCIIToUTF16(errors::kInvalidIntent);
+ return false;
+ }
+ }
+ return true;
+}
+
bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions,
string16* error) {
if (manifest_->HasKey(keys::kConvertedFromUserScript))
@@ -2125,6 +2198,7 @@ bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions,
!LoadOmnibox(error) ||
!LoadTextToSpeechVoices(error) ||
!LoadIncognitoMode(error) ||
+ !LoadFileHandlers(error) ||
!LoadContentSecurityPolicy(error))
return false;

Powered by Google App Engine
This is Rietveld 408576698