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

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: Keep only Verb enum in file_manager_private.js. Created 4 years, 7 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 <memory> 9 #include <memory>
10 10
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "extensions/common/error_utils.h" 15 #include "extensions/common/error_utils.h"
16 #include "extensions/common/manifest.h" 16 #include "extensions/common/manifest.h"
17 #include "extensions/common/manifest_constants.h" 17 #include "extensions/common/manifest_constants.h"
18 18
19 namespace extensions { 19 namespace extensions {
20 20
21 namespace keys = manifest_keys; 21 namespace keys = manifest_keys;
22 namespace errors = manifest_errors; 22 namespace errors = manifest_errors;
23 23
24 namespace file_handler_verbs {
25
26 const char kOpenWith[] = "open with";
Devlin 2016/05/20 21:08:16 https://codereview.chromium.org/1872223002/diff/12
cmihail 2016/05/23 02:46:13 Done.
27 const char kAddTo[] = "add to";
28 const char kPackWith[] = "pack with";
29
30 } // namespace file_handler_verbs
31
24 namespace { 32 namespace {
33
25 const int kMaxTypeAndExtensionHandlers = 200; 34 const int kMaxTypeAndExtensionHandlers = 200;
26 const char kNotRecognized[] = "'%s' is not a recognized file handler property."; 35 const char kNotRecognized[] = "'%s' is not a recognized file handler property.";
36
37 bool IsSupportedVerb(const std::string& verb) {
38 return verb == file_handler_verbs::kOpenWith ||
39 verb == file_handler_verbs::kAddTo ||
40 verb == file_handler_verbs::kPackWith;
27 } 41 }
28 42
29 FileHandlerInfo::FileHandlerInfo() : include_directories(false) {} 43 } // namespace
44
45 FileHandlerInfo::FileHandlerInfo()
46 : include_directories(false), verb(file_handler_verbs::kOpenWith) {}
30 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default; 47 FileHandlerInfo::FileHandlerInfo(const FileHandlerInfo& other) = default;
31 FileHandlerInfo::~FileHandlerInfo() {} 48 FileHandlerInfo::~FileHandlerInfo() {}
32 49
33 FileHandlers::FileHandlers() {} 50 FileHandlers::FileHandlers() {}
34 FileHandlers::~FileHandlers() {} 51 FileHandlers::~FileHandlers() {}
35 52
36 // static 53 // static
37 const FileHandlersInfo* FileHandlers::GetFileHandlers( 54 const FileHandlersInfo* FileHandlers::GetFileHandlers(
38 const Extension* extension) { 55 const Extension* extension) {
39 FileHandlers* info = static_cast<FileHandlers*>( 56 FileHandlers* info = static_cast<FileHandlers*>(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 92
76 handler.include_directories = false; 93 handler.include_directories = false;
77 if (handler_info.HasKey("include_directories") && 94 if (handler_info.HasKey("include_directories") &&
78 !handler_info.GetBoolean("include_directories", 95 !handler_info.GetBoolean("include_directories",
79 &handler.include_directories)) { 96 &handler.include_directories)) {
80 *error = ErrorUtils::FormatErrorMessageUTF16( 97 *error = ErrorUtils::FormatErrorMessageUTF16(
81 errors::kInvalidFileHandlerIncludeDirectories, handler_id); 98 errors::kInvalidFileHandlerIncludeDirectories, handler_id);
82 return false; 99 return false;
83 } 100 }
84 101
102 handler.verb = file_handler_verbs::kOpenWith;
103 if (handler_info.HasKey(keys::kFileHandlerVerb) &&
104 !handler_info.GetString(keys::kFileHandlerVerb, &handler.verb) &&
Devlin 2016/05/20 21:08:16 This is wrong - it should be an || on this line, r
cmihail 2016/05/23 02:46:13 Done.
105 !IsSupportedVerb(handler.verb)) {
106 *error = ErrorUtils::FormatErrorMessageUTF16(
107 errors::kInvalidFileHandlerVerb, handler_id);
108 return false;
109 }
110
85 if ((!mime_types || mime_types->empty()) && 111 if ((!mime_types || mime_types->empty()) &&
86 (!file_extensions || file_extensions->empty()) && 112 (!file_extensions || file_extensions->empty()) &&
87 !handler.include_directories) { 113 !handler.include_directories) {
88 *error = ErrorUtils::FormatErrorMessageUTF16( 114 *error = ErrorUtils::FormatErrorMessageUTF16(
89 errors::kInvalidFileHandlerNoTypeOrExtension, 115 errors::kInvalidFileHandlerNoTypeOrExtension,
90 handler_id); 116 handler_id);
91 return false; 117 return false;
92 } 118 }
93 119
94 if (mime_types) { 120 if (mime_types) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 extension->SetManifestData(keys::kFileHandlers, info.release()); 204 extension->SetManifestData(keys::kFileHandlers, info.release());
179 extension->AddInstallWarnings(install_warnings); 205 extension->AddInstallWarnings(install_warnings);
180 return true; 206 return true;
181 } 207 }
182 208
183 const std::vector<std::string> FileHandlersParser::Keys() const { 209 const std::vector<std::string> FileHandlersParser::Keys() const {
184 return SingleKey(keys::kFileHandlers); 210 return SingleKey(keys::kFileHandlers);
185 } 211 }
186 212
187 } // namespace extensions 213 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698