summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorcmihail <cmihail@chromium.org>2016-02-24 18:15:21 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-25 02:16:28 +0000
commit20232c23c12a81d98b69d10c9e18c0b4292606cb (patch)
tree669678e9e8b9e74461c8d963710f64018f04b277 /extensions
parent3d3507bd86994743e974e04ecfc97db4f640a007 (diff)
downloadchromium_src-20232c23c12a81d98b69d10c9e18c0b4292606cb.zip
chromium_src-20232c23c12a81d98b69d10c9e18c0b4292606cb.tar.gz
chromium_src-20232c23c12a81d98b69d10c9e18c0b4292606cb.tar.bz2
Add directories handling support for apps/extensions.
The change introduces a "include_directories" entry in the manifest file for file_handlers. In case the value is true, the file handler becomes a generic handler and adds the given extension to the right click menu. BUG=415897 R=mtomasz@chromium.org Review URL: https://codereview.chromium.org/1407473003 Cr-Commit-Position: refs/heads/master@{#377467}
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/api/app_runtime/app_runtime_api.cc8
-rw-r--r--extensions/browser/api/app_runtime/app_runtime_api.h3
-rw-r--r--extensions/browser/entry_info.h28
-rw-r--r--extensions/common/api/app_runtime.idl6
-rw-r--r--extensions/common/manifest_constants.cc5
-rw-r--r--extensions/common/manifest_constants.h1
-rw-r--r--extensions/common/manifest_handlers/file_handler_info.cc14
-rw-r--r--extensions/common/manifest_handlers/file_handler_info.h3
-rw-r--r--extensions/renderer/resources/app_runtime_custom_bindings.js21
9 files changed, 73 insertions, 16 deletions
diff --git a/extensions/browser/api/app_runtime/app_runtime_api.cc b/extensions/browser/api/app_runtime/app_runtime_api.cc
index 67f3ead..fca709b 100644
--- a/extensions/browser/api/app_runtime/app_runtime_api.cc
+++ b/extensions/browser/api/app_runtime/app_runtime_api.cc
@@ -11,6 +11,7 @@
#include "base/metrics/histogram.h"
#include "base/time/time.h"
#include "base/values.h"
+#include "extensions/browser/entry_info.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extensions_browser_client.h"
@@ -162,7 +163,7 @@ void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries(
BrowserContext* context,
const Extension* extension,
const std::string& handler_id,
- const std::vector<std::string>& mime_types,
+ const std::vector<EntryInfo>& entries,
const std::vector<GrantedFileEntry>& file_entries) {
// TODO(sergeygs): Use the same way of creating an event (using the generated
// boilerplate) as below in DispatchOnLaunchedEventWithUrl.
@@ -176,14 +177,15 @@ void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries(
}
scoped_ptr<base::ListValue> items(new base::ListValue);
- DCHECK(file_entries.size() == mime_types.size());
+ DCHECK(file_entries.size() == entries.size());
for (size_t i = 0; i < file_entries.size(); ++i) {
scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue);
launch_item->SetString("fileSystemId", file_entries[i].filesystem_id);
launch_item->SetString("baseName", file_entries[i].registered_name);
- launch_item->SetString("mimeType", mime_types[i]);
+ launch_item->SetString("mimeType", entries[i].mime_type);
launch_item->SetString("entryId", file_entries[i].id);
+ launch_item->SetBoolean("isDirectory", entries[i].is_directory);
items->Append(launch_item.release());
}
launch_data->Set("items", items.release());
diff --git a/extensions/browser/api/app_runtime/app_runtime_api.h b/extensions/browser/api/app_runtime/app_runtime_api.h
index 38f6fd6..35a28d2 100644
--- a/extensions/browser/api/app_runtime/app_runtime_api.h
+++ b/extensions/browser/api/app_runtime/app_runtime_api.h
@@ -25,6 +25,7 @@ class WebContents;
namespace extensions {
class Extension;
+struct EntryInfo;
struct GrantedFileEntry;
class AppRuntimeEventRouter {
@@ -64,7 +65,7 @@ class AppRuntimeEventRouter {
content::BrowserContext* context,
const Extension* extension,
const std::string& handler_id,
- const std::vector<std::string>& mime_types,
+ const std::vector<EntryInfo>& entries,
const std::vector<GrantedFileEntry>& file_entries);
// |handler_id| corresponds to the id of the url_handlers item
diff --git a/extensions/browser/entry_info.h b/extensions/browser/entry_info.h
new file mode 100644
index 0000000..eb5f5d5
--- /dev/null
+++ b/extensions/browser/entry_info.h
@@ -0,0 +1,28 @@
+// Copyright 2016 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.
+
+#ifndef EXTENSIONS_BROWSER_ENTRY_INFO_H_
+#define EXTENSIONS_BROWSER_ENTRY_INFO_H_
+
+#include <string>
+
+#include "base/files/file_path.h"
+
+namespace extensions {
+
+// Contains information about files and directories.
+struct EntryInfo {
+ EntryInfo(const base::FilePath& path,
+ const std::string& mime_type,
+ bool is_directory)
+ : path(path), mime_type(mime_type), is_directory(is_directory) {}
+
+ base::FilePath path;
+ std::string mime_type; // Useful only if is_directory = false.
+ bool is_directory;
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_BROWSER_ENTRY_INFO_H_
diff --git a/extensions/common/api/app_runtime.idl b/extensions/common/api/app_runtime.idl
index e3339bd..daf953c 100644
--- a/extensions/common/api/app_runtime.idl
+++ b/extensions/common/api/app_runtime.idl
@@ -8,11 +8,11 @@
namespace app.runtime {
[inline_doc] dictionary LaunchItem {
- // FileEntry for the file.
- [instanceOf=FileEntry] object entry;
+ // Entry for the item.
+ [instanceOf=Entry] object entry;
// The MIME type of the file.
- DOMString type;
+ DOMString? type;
};
// Enumeration of app launch sources.
diff --git a/extensions/common/manifest_constants.cc b/extensions/common/manifest_constants.cc
index 7195dda..85775ef 100644
--- a/extensions/common/manifest_constants.cc
+++ b/extensions/common/manifest_constants.cc
@@ -392,8 +392,11 @@ const char kInvalidFileHandlerExtension[] =
"Invalid value for 'file_handlers[*].extensions'.";
const char kInvalidFileHandlerExtensionElement[] =
"Invalid value for 'file_handlers[*].extensions[*]'.";
+const char kInvalidFileHandlerIncludeDirectories[] =
+ "Invalid value for 'include_directories'.";
const char kInvalidFileHandlerNoTypeOrExtension[] =
- "'file_handlers[*]' must contain a non-empty 'types' or 'extensions'.";
+ "'file_handlers[*]' must contain a non-empty 'types', 'extensions' "
+ "or 'include_directories'.";
const char kInvalidFileHandlerType[] =
"Invalid value for 'file_handlers[*].types'.";
const char kInvalidFileHandlerTypeElement[] =
diff --git a/extensions/common/manifest_constants.h b/extensions/common/manifest_constants.h
index 9051aa8..81f8fc5 100644
--- a/extensions/common/manifest_constants.h
+++ b/extensions/common/manifest_constants.h
@@ -318,6 +318,7 @@ extern const char kInvalidFileHandlers[];
extern const char kInvalidFileHandlersTooManyTypesAndExtensions[];
extern const char kInvalidFileHandlerExtension[];
extern const char kInvalidFileHandlerExtensionElement[];
+extern const char kInvalidFileHandlerIncludeDirectories[];
extern const char kInvalidFileHandlerNoTypeOrExtension[];
extern const char kInvalidFileHandlerType[];
extern const char kInvalidFileHandlerTypeElement[];
diff --git a/extensions/common/manifest_handlers/file_handler_info.cc b/extensions/common/manifest_handlers/file_handler_info.cc
index 9b0989a..b525c14 100644
--- a/extensions/common/manifest_handlers/file_handler_info.cc
+++ b/extensions/common/manifest_handlers/file_handler_info.cc
@@ -25,7 +25,7 @@ const int kMaxTypeAndExtensionHandlers = 200;
const char kNotRecognized[] = "'%s' is not a recognized file handler property.";
}
-FileHandlerInfo::FileHandlerInfo() {}
+FileHandlerInfo::FileHandlerInfo() : include_directories(false) {}
FileHandlerInfo::~FileHandlerInfo() {}
FileHandlers::FileHandlers() {}
@@ -71,8 +71,18 @@ bool LoadFileHandler(const std::string& handler_id,
return false;
}
+ handler.include_directories = false;
+ if (handler_info.HasKey("include_directories") &&
+ !handler_info.GetBoolean("include_directories",
+ &handler.include_directories)) {
+ *error = ErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidFileHandlerIncludeDirectories, handler_id);
+ return false;
+ }
+
if ((!mime_types || mime_types->empty()) &&
- (!file_extensions || file_extensions->empty())) {
+ (!file_extensions || file_extensions->empty()) &&
+ !handler.include_directories) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidFileHandlerNoTypeOrExtension,
handler_id);
diff --git a/extensions/common/manifest_handlers/file_handler_info.h b/extensions/common/manifest_handlers/file_handler_info.h
index ac458e1..ac9e51d 100644
--- a/extensions/common/manifest_handlers/file_handler_info.h
+++ b/extensions/common/manifest_handlers/file_handler_info.h
@@ -27,6 +27,9 @@ struct FileHandlerInfo {
// MIME types associated with this handler.
std::set<std::string> types;
+
+ // True if the handler can manage directories.
+ bool include_directories;
};
typedef std::vector<FileHandlerInfo> FileHandlersInfo;
diff --git a/extensions/renderer/resources/app_runtime_custom_bindings.js b/extensions/renderer/resources/app_runtime_custom_bindings.js
index 0364b66..3f0dbd2 100644
--- a/extensions/renderer/resources/app_runtime_custom_bindings.js
+++ b/extensions/renderer/resources/app_runtime_custom_bindings.js
@@ -57,12 +57,21 @@ eventBindings.registerArgumentMassager('app.runtime.onLaunched',
};
$Array.forEach(launchData.items, function(item) {
var fs = GetIsolatedFileSystem(item.fileSystemId);
- fs.root.getFile(item.baseName, {}, function(fileEntry) {
- entryIdManager.registerEntry(item.entryId, fileEntry);
- itemLoaded(null, { entry: fileEntry, type: item.mimeType });
- }, function(fileError) {
- itemLoaded(fileError);
- });
+ if (item.isDirectory) {
+ fs.root.getDirectory(item.baseName, {}, function(dirEntry) {
+ entryIdManager.registerEntry(item.entryId, dirEntry);
+ itemLoaded(null, {entry: dirEntry});
+ }, function(fileError) {
+ itemLoaded(fileError);
+ });
+ } else {
+ fs.root.getFile(item.baseName, {}, function(fileEntry) {
+ entryIdManager.registerEntry(item.entryId, fileEntry);
+ itemLoaded(null, {entry: fileEntry, type: item.mimeType});
+ }, function(fileError) {
+ itemLoaded(fileError);
+ });
+ }
});
} else {
// Default case. This currently covers an onLaunched corresponding to