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
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_FILE_HANDLER_INFO_H_
#define EXTENSIONS_COMMON_MANIFEST_HANDLERS_FILE_HANDLER_INFO_H_
#include <set>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "components/services/app_service/public/cpp/file_handler_info.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handler.h"
namespace extensions {
using FileHandlersInfo = std::vector<apps::FileHandlerInfo>;
// When setting up the menus for file open, if a file type has default Chrome
// extension set as the default we used to try to choose a default handler by
// matching against any sniffed MIME type or its file name extension.
//
// If there was no clear 'winner' for being set as the default handler for the
// file type, we'd prefer one of our allowlisted handlers over a handler that
// explicitly matches the file name extension. e.g. an '.ica' file contains
// plain text, but if there is a Chrome extension registered that lists '.ica'
// in its 'file_handlers' in the manifest, it fails to be chosen as default if
// there is a text editor installed that can process MIME types of text/plain.
struct FileHandlerMatch {
FileHandlerMatch();
~FileHandlerMatch();
raw_ptr<const apps::FileHandlerInfo> handler = nullptr;
// True if the handler matched on MIME type
bool matched_mime = false;
// True if the handler matched on file extension
bool matched_file_extension = false;
};
struct FileHandlers : public Extension::ManifestData {
FileHandlers();
~FileHandlers() override;
FileHandlersInfo file_handlers;
static const FileHandlersInfo* GetFileHandlers(const Extension* extension);
};
// Parses the "file_handlers" manifest key.
class FileHandlersParser : public ManifestHandler {
public:
FileHandlersParser();
FileHandlersParser(const FileHandlersParser&) = delete;
FileHandlersParser& operator=(const FileHandlersParser&) = delete;
~FileHandlersParser() override;
bool Parse(Extension* extension, std::u16string* error) override;
// Validation for Web File Handlers. This method was added for MV3 to enable
// successful loading with warnings, instead of failing to load with errors.
bool Validate(const Extension& extension,
std::string* error,
std::vector<InstallWarning>* warnings) const override;
private:
base::span<const char* const> Keys() const override;
};
} // namespace extensions
#endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_FILE_HANDLER_INFO_H_
|