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
|
// Copyright 2022 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_WEB_FILE_HANDLERS_INFO_H_
#define EXTENSIONS_COMMON_MANIFEST_HANDLERS_WEB_FILE_HANDLERS_INFO_H_
#include <string>
#include <vector>
#include "extensions/common/api/file_handlers.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handler.h"
namespace extensions {
using FileHandler = api::file_handlers::FileHandler;
struct WebFileHandler {
enum class LaunchType {
kSingleClient,
kMultipleClients,
};
FileHandler file_handler;
LaunchType launch_type = LaunchType::kSingleClient;
// Return an enum type instead of the idl string type. This value is currently
// set to `single-client` if it or nothing is provided, set to
// `multiple-clients` if that's provided, or errors in any other case.
LaunchType GetLaunchType() const { return launch_type; }
};
using WebFileHandlersInfo = std::vector<WebFileHandler>;
// Structured contents of the `file_handlers` manifest key.
struct WebFileHandlers : public Extension::ManifestData {
WebFileHandlers();
~WebFileHandlers() override;
// The list of entries for the web-accessible resources of the extension.
WebFileHandlersInfo file_handlers;
static const WebFileHandlersInfo* GetFileHandlers(const Extension& extension);
// Return an enum type instead of the idl string type. This value is currently
// set to `single-client` if it or nothing is provided, set to
// `multiple-clients` if that's provided, or errors in any other case.
// TODO(crbug.com/40269541): Store enum instead of the string on manifest
// parse.
static WebFileHandler::LaunchType GetLaunchType(
const std::optional<std::string>& launch_type);
// Determine if this extension has any web file handlers associated with it.
static bool HasFileHandlers(const Extension& extension);
// Support for web file handlers, introduced in MV3 based on the web API named
// `File Handling Explainer`.
// TODO(crbug.com/40169582): Remove after MV2 deprecation.
static bool SupportsWebFileHandlers(const Extension& extension);
// Determine if this extension can bypass the permission dialog, e.g.
// extension in allowlist or default installed.
static bool CanBypassPermissionDialog(const Extension& extension);
};
// Parses the `file_handlers` manifest key.
class WebFileHandlersParser : public ManifestHandler {
public:
WebFileHandlersParser();
WebFileHandlersParser(const WebFileHandlersParser&) = delete;
WebFileHandlersParser& operator=(const WebFileHandlersParser&) = delete;
~WebFileHandlersParser() override;
bool Parse(Extension* extension, std::u16string* error) override;
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_WEB_FILE_HANDLERS_INFO_H_
|