chromium/third_party/blink/renderer/modules/manifest/manifest_parser.cc

// 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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/modules/manifest/manifest_parser.h"

#include <string>

#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "net/base/mime_util.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/common/manifest/manifest_util.h"
#include "third_party/blink/public/common/mime_util/mime_util.h"
#include "third_party/blink/public/common/permissions_policy/origin_with_possible_wildcards.h"
#include "third_party/blink/public/common/permissions_policy/permissions_policy.h"
#include "third_party/blink/public/common/safe_url_pattern.h"
#include "third_party/blink/public/common/security/protocol_handler_security_level.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink.h"
#include "third_party/blink/public/platform/url_conversion.h"
#include "third_party/blink/public/platform/web_icon_sizes_parser.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/core/css/media_list.h"
#include "third_party/blink/renderer/core/css/media_query_evaluator.h"
#include "third_party/blink/renderer/core/css/media_values.h"
#include "third_party/blink/renderer/core/css/media_values_cached.h"
#include "third_party/blink/renderer/core/css/parser/css_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/permissions_policy/permissions_policy_parser.h"
#include "third_party/blink/renderer/modules/navigatorcontentutils/navigator_content_utils.h"
#include "third_party/blink/renderer/platform/json/json_parser.h"
#include "third_party/blink/renderer/platform/json/json_values.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "third_party/blink/renderer/platform/wtf/text/string_view.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/liburlpattern/parse.h"
#include "third_party/liburlpattern/pattern.h"
#include "third_party/liburlpattern/utils.h"
#include "url/url_constants.h"
#include "url/url_util.h"

namespace blink {

namespace {

static constexpr char kOriginWildcardPrefix[] =;
// Keep in sync with web_app_origin_association_task.cc.
static wtf_size_t kMaxUrlHandlersSize =;
static wtf_size_t kMaxScopeExtensionsSize =;
static wtf_size_t kMaxShortcutsSize =;
static wtf_size_t kMaxOriginLength =;

// The max number of file extensions an app can handle via the File Handling
// API.
const int kFileHandlerExtensionLimit =;
int g_file_handler_extension_limit_for_testing =;

bool IsValidMimeType(const String& mime_type) {}

bool VerifyFiles(const Vector<mojom::blink::ManifestFileFilterPtr>& files) {}

// Determines whether |url| is within scope of |scope|.
bool URLIsWithinScope(const KURL& url, const KURL& scope) {}

bool IsHostValidForScopeExtension(String host) {}

static bool IsCrLfOrTabChar(UChar c) {}

std::optional<mojom::blink::ManifestFileHandler::LaunchType>
FileHandlerLaunchTypeFromString(const std::string& launch_type) {}

static const char kUMAIdParseResult[] =;

// Record that the Manifest was successfully parsed. If it is an empty
// Manifest, it will recorded as so and nothing will happen. Otherwise, the
// presence of each properties will be recorded.
void ParseSucceeded(const mojom::blink::ManifestPtr& manifest) {}

// Returns a liburlpattern::Part list obtained from running
// liburlpattern::Parse on a UrlPatternInit field. The list will be empty if the
// field is empty. Returns std::nullopt if the field should be rejected or the
// parse failed, e.g. if it contains custom (or ill-formed) regex.
std::optional<std::vector<liburlpattern::Part>> ParsePatternInitField(
    const std::optional<String>& field,
    const String default_field_value) {}

String EscapePatternString(String input) {}

// Utility function to determine if a pathname is absolute or not. We do some
// additional checking for escaped or grouped slashes.
//
// Note: This is partially copied from
// third_party/blink/renderer/core/url_pattern/url_pattern.cc
bool IsAbsolutePathname(String pathname) {}

String ResolveRelativePathnamePattern(const KURL& base_url, String pathname) {}

}  // anonymous namespace

ManifestParser::ManifestParser(const String& data,
                               const KURL& manifest_url,
                               const KURL& document_url,
                               ExecutionContext* execution_context)
    :{}

ManifestParser::~ManifestParser() {}

// static
void ManifestParser::SetFileHandlerExtensionLimitForTesting(int limit) {}

bool ManifestParser::Parse() {}

mojom::blink::ManifestPtr ManifestParser::TakeManifest() {}

void ManifestParser::TakeErrors(
    Vector<mojom::blink::ManifestErrorPtr>* errors) {}

bool ManifestParser::failed() const {}

ManifestParser::PatternInit::PatternInit(std::optional<String> protocol,
                                         std::optional<String> username,
                                         std::optional<String> password,
                                         std::optional<String> hostname,
                                         std::optional<String> port,
                                         std::optional<String> pathname,
                                         std::optional<String> search,
                                         std::optional<String> hash,
                                         KURL base_url)
    :{}
ManifestParser::PatternInit::~PatternInit() = default;
ManifestParser::PatternInit::PatternInit(PatternInit&&) = default;
ManifestParser::PatternInit& ManifestParser::PatternInit::operator=(
    PatternInit&&) = default;

bool ManifestParser::PatternInit::IsAbsolute() const {}

bool ManifestParser::ParseBoolean(const JSONObject* object,
                                  const String& key,
                                  bool default_value) {}

std::optional<String> ManifestParser::ParseString(const JSONObject* object,
                                                  const String& key,
                                                  Trim trim) {}

std::optional<String> ManifestParser::ParseStringForMember(
    const JSONObject* object,
    const String& member_name,
    const String& key,
    bool required,
    Trim trim) {}

std::optional<RGBA32> ManifestParser::ParseColor(const JSONObject* object,
                                                 const String& key) {}

KURL ManifestParser::ParseURL(const JSONObject* object,
                              const String& key,
                              const KURL& base_url,
                              ParseURLRestrictions origin_restriction,
                              bool ignore_empty_string) {}

template <typename Enum>
Enum ManifestParser::ParseFirstValidEnum(const JSONObject* object,
                                         const String& key,
                                         Enum (*parse_enum)(const std::string&),
                                         Enum invalid_value) {}

String ManifestParser::ParseName(const JSONObject* object) {}

String ManifestParser::ParseShortName(const JSONObject* object) {}

String ManifestParser::ParseDescription(const JSONObject* object) {}

std::pair<KURL, ManifestParser::ParseIdResultType> ManifestParser::ParseId(
    const JSONObject* object,
    const KURL& start_url) {}

std::pair<KURL, ManifestParser::ParseStartUrlResult>
ManifestParser::ParseStartURL(const JSONObject* object,
                              const KURL& document_url) {}

KURL ManifestParser::ParseScope(const JSONObject* object,
                                const KURL& start_url) {}

blink::mojom::DisplayMode ManifestParser::ParseDisplay(
    const JSONObject* object) {}

Vector<mojom::blink::DisplayMode> ManifestParser::ParseDisplayOverride(
    const JSONObject* object) {}

device::mojom::blink::ScreenOrientationLockType
ManifestParser::ParseOrientation(const JSONObject* object) {}

KURL ManifestParser::ParseIconSrc(const JSONObject* icon) {}

String ManifestParser::ParseIconType(const JSONObject* icon) {}

Vector<gfx::Size> ManifestParser::ParseIconSizes(const JSONObject* icon) {}

std::optional<Vector<mojom::blink::ManifestImageResource::Purpose>>
ManifestParser::ParseIconPurpose(const JSONObject* icon) {}

mojom::blink::ManifestScreenshot::FormFactor
ManifestParser::ParseScreenshotFormFactor(const JSONObject* screenshot) {}

String ManifestParser::ParseScreenshotLabel(const JSONObject* object) {}

Vector<mojom::blink::ManifestImageResourcePtr> ManifestParser::ParseIcons(
    const JSONObject* object) {}

Vector<mojom::blink::ManifestScreenshotPtr> ManifestParser::ParseScreenshots(
    const JSONObject* object) {}

Vector<mojom::blink::ManifestImageResourcePtr>
ManifestParser::ParseImageResourceArray(const String& key,
                                        const JSONObject* object) {}

std::optional<mojom::blink::ManifestImageResourcePtr>
ManifestParser::ParseImageResource(const JSONValue* object) {}

String ManifestParser::ParseShortcutName(const JSONObject* shortcut) {}

String ManifestParser::ParseShortcutShortName(const JSONObject* shortcut) {}

String ManifestParser::ParseShortcutDescription(const JSONObject* shortcut) {}

KURL ManifestParser::ParseShortcutUrl(const JSONObject* shortcut) {}

Vector<mojom::blink::ManifestShortcutItemPtr> ManifestParser::ParseShortcuts(
    const JSONObject* object) {}

String ManifestParser::ParseFileFilterName(const JSONObject* file) {}

Vector<String> ManifestParser::ParseFileFilterAccept(const JSONObject* object) {}

Vector<mojom::blink::ManifestFileFilterPtr> ManifestParser::ParseTargetFiles(
    const String& key,
    const JSONObject* from) {}

void ManifestParser::ParseFileFilter(
    const JSONObject* file_object,
    Vector<mojom::blink::ManifestFileFilterPtr>* files) {}

std::optional<mojom::blink::ManifestShareTarget::Method>
ManifestParser::ParseShareTargetMethod(const JSONObject* share_target_object) {}

std::optional<mojom::blink::ManifestShareTarget::Enctype>
ManifestParser::ParseShareTargetEnctype(const JSONObject* share_target_object) {}

mojom::blink::ManifestShareTargetParamsPtr
ManifestParser::ParseShareTargetParams(const JSONObject* share_target_params) {}

std::optional<mojom::blink::ManifestShareTargetPtr>
ManifestParser::ParseShareTarget(const JSONObject* object) {}

Vector<mojom::blink::ManifestFileHandlerPtr> ManifestParser::ParseFileHandlers(
    const JSONObject* object) {}

std::optional<mojom::blink::ManifestFileHandlerPtr>
ManifestParser::ParseFileHandler(const JSONObject* file_handler) {}

HashMap<String, Vector<String>> ManifestParser::ParseFileHandlerAccept(
    const JSONObject* accept) {}

bool ManifestParser::ParseFileHandlerAcceptExtension(const JSONValue* extension,
                                                     String* output) {}

Vector<mojom::blink::ManifestProtocolHandlerPtr>
ManifestParser::ParseProtocolHandlers(const JSONObject* from) {}

std::optional<mojom::blink::ManifestProtocolHandlerPtr>
ManifestParser::ParseProtocolHandler(const JSONObject* object) {}

Vector<mojom::blink::ManifestUrlHandlerPtr> ManifestParser::ParseUrlHandlers(
    const JSONObject* from) {}

std::optional<mojom::blink::ManifestUrlHandlerPtr>
ManifestParser::ParseUrlHandler(const JSONObject* object) {}

Vector<mojom::blink::ManifestScopeExtensionPtr>
ManifestParser::ParseScopeExtensions(const JSONObject* from) {}

std::optional<mojom::blink::ManifestScopeExtensionPtr>
ManifestParser::ParseScopeExtension(const JSONObject* object) {}

std::optional<mojom::blink::ManifestScopeExtensionPtr>
ManifestParser::ParseScopeExtensionOrigin(const String& origin_string) {}

KURL ManifestParser::ParseLockScreenStartUrl(const JSONObject* lock_screen) {}

mojom::blink::ManifestLockScreenPtr ManifestParser::ParseLockScreen(
    const JSONObject* manifest) {}

KURL ManifestParser::ParseNoteTakingNewNoteUrl(const JSONObject* note_taking) {}

mojom::blink::ManifestNoteTakingPtr ManifestParser::ParseNoteTaking(
    const JSONObject* manifest) {}

String ManifestParser::ParseRelatedApplicationPlatform(
    const JSONObject* application) {}

std::optional<KURL> ManifestParser::ParseRelatedApplicationURL(
    const JSONObject* application) {}

String ManifestParser::ParseRelatedApplicationId(
    const JSONObject* application) {}

Vector<mojom::blink::ManifestRelatedApplicationPtr>
ManifestParser::ParseRelatedApplications(const JSONObject* object) {}

bool ManifestParser::ParsePreferRelatedApplications(const JSONObject* object) {}

std::optional<RGBA32> ManifestParser::ParseThemeColor(
    const JSONObject* object) {}

std::optional<RGBA32> ManifestParser::ParseBackgroundColor(
    const JSONObject* object) {}

String ManifestParser::ParseGCMSenderID(const JSONObject* object) {}

Vector<blink::ParsedPermissionsPolicyDeclaration>
ManifestParser::ParseIsolatedAppPermissions(const JSONObject* object) {}

Vector<String> ManifestParser::ParseOriginAllowlist(
    const JSONArray* json_allowlist,
    const String& feature) {}

mojom::blink::ManifestLaunchHandlerPtr ManifestParser::ParseLaunchHandler(
    const JSONObject* object) {}

HashMap<String, mojom::blink::ManifestTranslationItemPtr>
ManifestParser::ParseTranslations(const JSONObject* object) {}

mojom::blink::ManifestTabStripPtr ManifestParser::ParseTabStrip(
    const JSONObject* object) {}

mojom::blink::TabStripMemberVisibility
ManifestParser::ParseTabStripMemberVisibility(const JSONValue* json_value) {}

Vector<SafeUrlPattern> ManifestParser::ParseScopePatterns(
    const JSONObject* object) {}

std::optional<SafeUrlPattern> ManifestParser::ParseScopePattern(
    const PatternInit& init,
    const KURL& base_url) {}

std::optional<ManifestParser::PatternInit>
ManifestParser::MaybeCreatePatternInit(const JSONObject* pattern_object) {}

String ManifestParser::ParseVersion(const JSONObject* object) {}

void ManifestParser::AddErrorInfo(const String& error_msg,
                                  bool critical,
                                  int error_line,
                                  int error_column) {}

}  // namespace blink