| Index: extensions/common/manifest_handlers/file_handler_info.cc
|
| diff --git a/extensions/common/manifest_handlers/file_handler_info.cc b/extensions/common/manifest_handlers/file_handler_info.cc
|
| index c95a5e4687410c5c562f162ef80f2b7148ea36dd..3d70e61a9837bcbbb979373ea3f3f6758ae1b3a6 100644
|
| --- a/extensions/common/manifest_handlers/file_handler_info.cc
|
| +++ b/extensions/common/manifest_handlers/file_handler_info.cc
|
| @@ -8,12 +8,15 @@
|
|
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/values.h"
|
| +#include "chrome/grit/generated_resources.h"
|
| #include "extensions/common/error_utils.h"
|
| #include "extensions/common/manifest.h"
|
| #include "extensions/common/manifest_constants.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
|
|
| namespace extensions {
|
|
|
| @@ -25,7 +28,8 @@ const int kMaxTypeAndExtensionHandlers = 200;
|
| const char kNotRecognized[] = "'%s' is not a recognized file handler property.";
|
| }
|
|
|
| -FileHandlerInfo::FileHandlerInfo() : include_directories(false) {}
|
| +FileHandlerInfo::FileHandlerInfo()
|
| + : include_directories(false), verb(file_handler_verbs::kOpenWith) {}
|
| FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default;
|
| FileHandlerInfo::~FileHandlerInfo() {}
|
|
|
| @@ -81,6 +85,15 @@ bool LoadFileHandler(const std::string& handler_id,
|
| return false;
|
| }
|
|
|
| + handler.verb = file_handler_verbs::kOpenWith;
|
| + if (handler_info.HasKey(keys::kFileHandlerVerb) &&
|
| + !handler_info.GetString(keys::kFileHandlerVerb, &handler.verb) &&
|
| + !file_handler_verbs::IsSupportedVerb(handler.verb)) {
|
| + *error = ErrorUtils::FormatErrorMessageUTF16(
|
| + errors::kInvalidFileHandlerVerb, handler_id);
|
| + return false;
|
| + }
|
| +
|
| if ((!mime_types || mime_types->empty()) &&
|
| (!file_extensions || file_extensions->empty()) &&
|
| !handler.include_directories) {
|
| @@ -183,4 +196,43 @@ const std::vector<std::string> FileHandlersParser::Keys() const {
|
| return SingleKey(keys::kFileHandlers);
|
| }
|
|
|
| +namespace file_handler_verbs {
|
| +
|
| +const char kOpenWith[] = "OPEN_WITH";
|
| +const char kAddTo[] = "ADD_TO";
|
| +const char kPackWith[] = "PACK_WITH";
|
| +
|
| +bool IsSupportedVerb(const std::string& verb) {
|
| + std::set<std::string> supported_verbs;
|
| + supported_verbs.emplace(kOpenWith);
|
| + supported_verbs.emplace(kAddTo);
|
| + supported_verbs.emplace(kPackWith);
|
| + return supported_verbs.find(verb) != supported_verbs.end();
|
| +}
|
| +
|
| +// Gets the internationlized title for an extension based on the extension name
|
| +// and the associated handler verb.
|
| +base::string16 GetTitleForExtensionAndVerb(const std::string& extension_name,
|
| + const std::string& handler_verb) {
|
| + int button_label;
|
| + if (handler_verb == kOpenWith) {
|
| + button_label = IDS_FILE_BROWSER_OPEN_WITH_VERB_BUTTON_LABEL;
|
| + } else if (handler_verb == kAddTo) {
|
| + button_label = IDS_FILE_BROWSER_ADD_TO_VERB_BUTTON_LABEL;
|
| + } else if (handler_verb == kPackWith) {
|
| + button_label = IDS_FILE_BROWSER_PACK_WITH_VERB_BUTTON_LABEL;
|
| + } else {
|
| + // Should never reach this code if IsSupportedVerb is in sync.
|
| + DCHECK(false);
|
| + // Fallback to OPEN_WITH.
|
| + button_label = IDS_FILE_BROWSER_OPEN_WITH_VERB_BUTTON_LABEL;
|
| + }
|
| +
|
| + return base::ReplaceStringPlaceholders(
|
| + l10n_util::GetStringUTF16(button_label),
|
| + base::UTF8ToUTF16(extension_name), nullptr);
|
| +}
|
| +
|
| +} // namespace file_handler_verbs
|
| +
|
| } // namespace extensions
|
|
|