File: file_handler.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (97 lines) | stat: -rw-r--r-- 3,211 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_FILE_HANDLER_H_
#define COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_FILE_HANDLER_H_

#include <ostream>
#include <set>
#include <string>
#include <vector>

#include "base/containers/flat_set.h"
#include "base/values.h"
#include "components/services/app_service/public/cpp/icon_info.h"
#include "url/gurl.h"

namespace apps {

struct FileHandler {
  FileHandler();
  ~FileHandler();
  FileHandler(const FileHandler& file_handler);

  // Represents a single file handler "accept" entry, mapping a MIME type to a
  // set of file extensions that can be handled by the handler.
  struct AcceptEntry {
    AcceptEntry();
    ~AcceptEntry();
    AcceptEntry(const AcceptEntry& accept_entry);

    friend bool operator==(const AcceptEntry&, const AcceptEntry&) = default;

    base::Value AsDebugValue() const;

    // A MIME type that can be handled by the file handler.
    std::string mime_type;

    // A set of one or more file extensions that can be handled by the file
    // handler, corresponding to the MIME type.
    base::flat_set<std::string> file_extensions;
  };

  base::Value AsDebugValue() const;

  // The URL that will be navigated to when dispatching on a file with a
  // matching MIME type or file extension.
  GURL action;

  // The user-visible name for the file type, e.g. "ACME Word Processor document
  // file". May be empty.
  std::u16string display_name;

  // A collection of MIME type to file extensions mappings that the handler
  // will match on.
  using Accept = std::vector<AcceptEntry>;
  Accept accept;

  // The icons defined for this file handler, to be used as file type
  // association icons in OS surfaces. The sizes in `downloaded_icons`, when
  // present, represent the actual size of a bitmap that was downloaded.
  std::vector<IconInfo> downloaded_icons;

  // How the app should be launched in the case where there are multiple files
  // being opened.
  enum class LaunchType {
    kSingleClient,
    kMultipleClients,
  };
  LaunchType launch_type = LaunchType::kSingleClient;
};
using FileHandlers = std::vector<FileHandler>;

// Get a set of all MIME types supported by any of |file_handlers|.
std::set<std::string> GetMimeTypesFromFileHandlers(
    const FileHandlers& file_handlers);

// Get a set of all MIME types supported by |file_handler|.
std::set<std::string> GetMimeTypesFromFileHandler(
    const FileHandler& file_handler);

// Get a set of all file extensions supported by any of |file_handlers|.
// Note: These are always transformed to lower-case.
std::set<std::string> GetFileExtensionsFromFileHandlers(
    const FileHandlers& file_handlers);

// Get a set of all file extensions supported by |file_handler|.
// Note: These are always transformed to lower-case.
std::set<std::string> GetFileExtensionsFromFileHandler(
    const FileHandler& file_handler);

bool operator==(const FileHandler& file_handler1,
                const FileHandler& file_handler2);

}  // namespace apps

#endif  // COMPONENTS_SERVICES_APP_SERVICE_PUBLIC_CPP_FILE_HANDLER_H_