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

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: fix tests 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_manifest_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index c15bcd2624f82748e1d852396edd482c69a1b6d9..cfd6714ceb5ed086dbc8913a65d7fea61d34be00 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,73 @@ 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;
+
+ // TODO(jeremya): use a file-handler-specific data structure instead of web
+ // intents.
+ service.action = ASCIIToUTF16("http://webintents.org/view");
+
+ 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::kFileHandlerTitle) &&
+ !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;
+
+ 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 and a list of MIME types to handle.
+ DictionaryValue* handler = NULL;
+ if (all_handlers->GetDictionaryWithoutPathExpansion(*iter, &handler)) {
+ if (!LoadFileHandler(*iter, *handler, error))
+ return false;
+ } else {
+ *error = ASCIIToUTF16(errors::kInvalidFileHandlers);
+ return false;
+ }
+ }
+ return true;
+}
+
bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions,
string16* error) {
if (manifest_->HasKey(keys::kConvertedFromUserScript))
@@ -2125,6 +2192,7 @@ bool Extension::LoadExtensionFeatures(const APIPermissionSet& api_permissions,
!LoadOmnibox(error) ||
!LoadTextToSpeechVoices(error) ||
!LoadIncognitoMode(error) ||
+ !LoadFileHandlers(error) ||
!LoadContentSecurityPolicy(error))
return false;
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_manifest_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698