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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/manifest_handlers/file_handler_info.h" 5 #include "extensions/common/manifest_handlers/file_handler_info.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/grit/generated_resources.h"
14 #include "extensions/common/error_utils.h" 16 #include "extensions/common/error_utils.h"
15 #include "extensions/common/manifest.h" 17 #include "extensions/common/manifest.h"
16 #include "extensions/common/manifest_constants.h" 18 #include "extensions/common/manifest_constants.h"
19 #include "ui/base/l10n/l10n_util.h"
17 20
18 namespace extensions { 21 namespace extensions {
19 22
20 namespace keys = manifest_keys; 23 namespace keys = manifest_keys;
21 namespace errors = manifest_errors; 24 namespace errors = manifest_errors;
22 25
23 namespace { 26 namespace {
24 const int kMaxTypeAndExtensionHandlers = 200; 27 const int kMaxTypeAndExtensionHandlers = 200;
25 const char kNotRecognized[] = "'%s' is not a recognized file handler property."; 28 const char kNotRecognized[] = "'%s' is not a recognized file handler property.";
26 } 29 }
27 30
28 FileHandlerInfo::FileHandlerInfo() : include_directories(false) {} 31 FileHandlerInfo::FileHandlerInfo()
32 : include_directories(false), verb(file_handler_verbs::kOpenWith) {}
29 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default; 33 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default;
30 FileHandlerInfo::~FileHandlerInfo() {} 34 FileHandlerInfo::~FileHandlerInfo() {}
31 35
32 FileHandlers::FileHandlers() {} 36 FileHandlers::FileHandlers() {}
33 FileHandlers::~FileHandlers() {} 37 FileHandlers::~FileHandlers() {}
34 38
35 // static 39 // static
36 const FileHandlersInfo* FileHandlers::GetFileHandlers( 40 const FileHandlersInfo* FileHandlers::GetFileHandlers(
37 const Extension* extension) { 41 const Extension* extension) {
38 FileHandlers* info = static_cast<FileHandlers*>( 42 FileHandlers* info = static_cast<FileHandlers*>(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 78
75 handler.include_directories = false; 79 handler.include_directories = false;
76 if (handler_info.HasKey("include_directories") && 80 if (handler_info.HasKey("include_directories") &&
77 !handler_info.GetBoolean("include_directories", 81 !handler_info.GetBoolean("include_directories",
78 &handler.include_directories)) { 82 &handler.include_directories)) {
79 *error = ErrorUtils::FormatErrorMessageUTF16( 83 *error = ErrorUtils::FormatErrorMessageUTF16(
80 errors::kInvalidFileHandlerIncludeDirectories, handler_id); 84 errors::kInvalidFileHandlerIncludeDirectories, handler_id);
81 return false; 85 return false;
82 } 86 }
83 87
88 handler.verb = file_handler_verbs::kOpenWith;
89 if (handler_info.HasKey(keys::kFileHandlerVerb) &&
90 !handler_info.GetString(keys::kFileHandlerVerb, &handler.verb) &&
91 !file_handler_verbs::IsSupportedVerb(handler.verb)) {
92 *error = ErrorUtils::FormatErrorMessageUTF16(
93 errors::kInvalidFileHandlerVerb, handler_id);
94 return false;
95 }
96
84 if ((!mime_types || mime_types->empty()) && 97 if ((!mime_types || mime_types->empty()) &&
85 (!file_extensions || file_extensions->empty()) && 98 (!file_extensions || file_extensions->empty()) &&
86 !handler.include_directories) { 99 !handler.include_directories) {
87 *error = ErrorUtils::FormatErrorMessageUTF16( 100 *error = ErrorUtils::FormatErrorMessageUTF16(
88 errors::kInvalidFileHandlerNoTypeOrExtension, 101 errors::kInvalidFileHandlerNoTypeOrExtension,
89 handler_id); 102 handler_id);
90 return false; 103 return false;
91 } 104 }
92 105
93 if (mime_types) { 106 if (mime_types) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 189
177 extension->SetManifestData(keys::kFileHandlers, info.release()); 190 extension->SetManifestData(keys::kFileHandlers, info.release());
178 extension->AddInstallWarnings(install_warnings); 191 extension->AddInstallWarnings(install_warnings);
179 return true; 192 return true;
180 } 193 }
181 194
182 const std::vector<std::string> FileHandlersParser::Keys() const { 195 const std::vector<std::string> FileHandlersParser::Keys() const {
183 return SingleKey(keys::kFileHandlers); 196 return SingleKey(keys::kFileHandlers);
184 } 197 }
185 198
199 namespace file_handler_verbs {
200
201 const char kOpenWith[] = "OPEN_WITH";
202 const char kAddTo[] = "ADD_TO";
203 const char kPackWith[] = "PACK_WITH";
204
205 bool IsSupportedVerb(const std::string& verb) {
206 std::set<std::string> supported_verbs;
207 supported_verbs.emplace(kOpenWith);
208 supported_verbs.emplace(kAddTo);
209 supported_verbs.emplace(kPackWith);
210 return supported_verbs.find(verb) != supported_verbs.end();
211 }
212
213 // Gets the internationlized title for an extension based on the extension name
214 // and the associated handler verb.
215 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
216 const std::string& handler_verb) {
217 int button_label;
218 if (handler_verb == kOpenWith) {
219 button_label = IDS_FILE_BROWSER_OPEN_WITH_VERB_BUTTON_LABEL;
220 } else if (handler_verb == kAddTo) {
221 button_label = IDS_FILE_BROWSER_ADD_TO_VERB_BUTTON_LABEL;
222 } else if (handler_verb == kPackWith) {
223 button_label = IDS_FILE_BROWSER_PACK_WITH_VERB_BUTTON_LABEL;
224 } else {
225 // Should never reach this code if IsSupportedVerb is in sync.
226 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.
227 // Fallback to OPEN_WITH.
228 button_label = IDS_FILE_BROWSER_OPEN_WITH_VERB_BUTTON_LABEL;
229 }
230
231 return base::ReplaceStringPlaceholders(
232 l10n_util::GetStringUTF16(button_label),
233 base::UTF8ToUTF16(extension_name), nullptr);
234 }
235
236 } // namespace file_handler_verbs
237
186 } // namespace extensions 238 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698