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

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: Remove unused internationalization function on C++ code. 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/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "extensions/common/error_utils.h" 14 #include "extensions/common/error_utils.h"
15 #include "extensions/common/manifest.h" 15 #include "extensions/common/manifest.h"
16 #include "extensions/common/manifest_constants.h" 16 #include "extensions/common/manifest_constants.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 namespace keys = manifest_keys; 20 namespace keys = manifest_keys;
21 namespace errors = manifest_errors; 21 namespace errors = manifest_errors;
22 22
23 namespace file_handler_verbs {
24
25 const char kOpenWith[] = "OPEN_WITH";
26 const char kAddTo[] = "ADD_TO";
27 const char kPackWith[] = "PACK_WITH";
28
29 } // namespace file_handler_verbs
30
23 namespace { 31 namespace {
32
24 const int kMaxTypeAndExtensionHandlers = 200; 33 const int kMaxTypeAndExtensionHandlers = 200;
25 const char kNotRecognized[] = "'%s' is not a recognized file handler property."; 34 const char kNotRecognized[] = "'%s' is not a recognized file handler property.";
35
36 bool IsSupportedVerb(const std::string& verb) {
37 std::set<std::string> supported_verbs;
38 supported_verbs.emplace(file_handler_verbs::kOpenWith);
39 supported_verbs.emplace(file_handler_verbs::kAddTo);
40 supported_verbs.emplace(file_handler_verbs::kPackWith);
41 return supported_verbs.find(verb) != supported_verbs.end();
26 } 42 }
27 43
28 FileHandlerInfo::FileHandlerInfo() : include_directories(false) {} 44 } // namespace
45
46 FileHandlerInfo::FileHandlerInfo()
47 : include_directories(false), verb(file_handler_verbs::kOpenWith) {}
29 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default; 48 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default;
30 FileHandlerInfo::~FileHandlerInfo() {} 49 FileHandlerInfo::~FileHandlerInfo() {}
31 50
32 FileHandlers::FileHandlers() {} 51 FileHandlers::FileHandlers() {}
33 FileHandlers::~FileHandlers() {} 52 FileHandlers::~FileHandlers() {}
34 53
35 // static 54 // static
36 const FileHandlersInfo* FileHandlers::GetFileHandlers( 55 const FileHandlersInfo* FileHandlers::GetFileHandlers(
37 const Extension* extension) { 56 const Extension* extension) {
38 FileHandlers* info = static_cast<FileHandlers*>( 57 FileHandlers* info = static_cast<FileHandlers*>(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 93
75 handler.include_directories = false; 94 handler.include_directories = false;
76 if (handler_info.HasKey("include_directories") && 95 if (handler_info.HasKey("include_directories") &&
77 !handler_info.GetBoolean("include_directories", 96 !handler_info.GetBoolean("include_directories",
78 &handler.include_directories)) { 97 &handler.include_directories)) {
79 *error = ErrorUtils::FormatErrorMessageUTF16( 98 *error = ErrorUtils::FormatErrorMessageUTF16(
80 errors::kInvalidFileHandlerIncludeDirectories, handler_id); 99 errors::kInvalidFileHandlerIncludeDirectories, handler_id);
81 return false; 100 return false;
82 } 101 }
83 102
103 handler.verb = file_handler_verbs::kOpenWith;
104 if (handler_info.HasKey(keys::kFileHandlerVerb) &&
105 !handler_info.GetString(keys::kFileHandlerVerb, &handler.verb) &&
106 !IsSupportedVerb(handler.verb)) {
107 *error = ErrorUtils::FormatErrorMessageUTF16(
108 errors::kInvalidFileHandlerVerb, handler_id);
109 return false;
110 }
111
84 if ((!mime_types || mime_types->empty()) && 112 if ((!mime_types || mime_types->empty()) &&
85 (!file_extensions || file_extensions->empty()) && 113 (!file_extensions || file_extensions->empty()) &&
86 !handler.include_directories) { 114 !handler.include_directories) {
87 *error = ErrorUtils::FormatErrorMessageUTF16( 115 *error = ErrorUtils::FormatErrorMessageUTF16(
88 errors::kInvalidFileHandlerNoTypeOrExtension, 116 errors::kInvalidFileHandlerNoTypeOrExtension,
89 handler_id); 117 handler_id);
90 return false; 118 return false;
91 } 119 }
92 120
93 if (mime_types) { 121 if (mime_types) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 extension->SetManifestData(keys::kFileHandlers, info.release()); 205 extension->SetManifestData(keys::kFileHandlers, info.release());
178 extension->AddInstallWarnings(install_warnings); 206 extension->AddInstallWarnings(install_warnings);
179 return true; 207 return true;
180 } 208 }
181 209
182 const std::vector<std::string> FileHandlersParser::Keys() const { 210 const std::vector<std::string> FileHandlersParser::Keys() const {
183 return SingleKey(keys::kFileHandlers); 211 return SingleKey(keys::kFileHandlers);
184 } 212 }
185 213
186 } // namespace extensions 214 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698