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

Unified Diff: extensions/common/manifest_handlers/file_handler_info.cc

Issue 1872223002: Add verbs API to file handlers. Modify the Chrome OS UI so that it displayes the internationalized … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments mentioned by fukino@. Created 4 years, 8 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: 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,
mtomasz 2016/04/13 09:17:06 I'm OK to translate in C++, but I'm not sure if th
cmihail 2016/04/18 01:28:10 The reason I kept it here was due to make it easie
+ 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);
mtomasz 2016/04/13 09:17:06 nit: DCHECK(false) -> NOTREACHED().
cmihail 2016/04/18 01:28:10 ACK. N/A as moved this logic to JS.
+ // 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

Powered by Google App Engine
This is Rietveld 408576698