#include "extensions/common/utils/content_script_utils.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <string_view>
#include "base/files/file_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/api/content_scripts.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/permissions_parser.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/url_pattern.h"
#include "extensions/common/url_pattern_set.h"
#include "extensions/strings/grit/extensions_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
namespace extensions {
errors;
namespace script_parsing {
namespace {
size_t g_max_script_length_in_bytes = …;
size_t g_max_scripts_length_per_extension_in_bytes = …;
const char kEmptyFilesFynamicScriptError[] = …;
constexpr char kEmptyMatchesDynamicScriptError[] = …;
constexpr char kInvalidExcludeMatchDynamicScriptError[] = …;
constexpr char kInvalidMatchDynamicScriptError[] = …;
constexpr char kForbiddenInlineCodeScriptError[] = …;
bool IsScriptValid(const base::FilePath& path,
const base::FilePath& relative_path,
size_t max_script_length,
int file_not_read_error_id,
std::string* error,
std::vector<InstallWarning>* warnings,
size_t& remaining_length) { … }
std::u16string GetEmptyFieldError(std::string_view static_error,
std::string_view dynamic_error,
const std::string& script_id,
std::optional<int> definition_index) { … }
std::u16string GetInvalidMatchError(std::string_view static_error,
std::string_view dynamic_error,
const std::string& script_id,
std::optional<int> definition_index,
URLPattern::ParseResult parse_result,
int match_index) { … }
std::u16string GetEmptyMatchesError(const std::string& script_id,
std::optional<int> definition_index) { … }
std::u16string GetEmptyFilesError(const std::string& script_id,
std::optional<int> definition_index) { … }
std::u16string GetInvalidExcludeMatchError(const std::string& script_id,
std::optional<int> definition_index,
URLPattern::ParseResult parse_result,
int match_index) { … }
std::u16string GetInvalidMatchError(const std::string& script_id,
std::optional<int> definition_index,
URLPattern::ParseResult parse_result,
int match_index) { … }
}
size_t GetMaxScriptLength() { … }
size_t GetMaxScriptsLengthPerExtension() { … }
ScopedMaxScriptLengthOverride CreateScopedMaxScriptLengthForTesting(
size_t max) { … }
ScopedMaxScriptLengthOverride
CreateScopedMaxScriptsLengthPerExtensionForTesting(size_t max) { … }
bool ParseMatchPatterns(const std::vector<std::string>& matches,
const std::vector<std::string>* exclude_matches,
int creation_flags,
bool can_execute_script_everywhere,
bool all_urls_includes_chrome_urls,
std::optional<int> definition_index,
UserScript* result,
std::u16string* error,
bool* wants_file_access) { … }
bool ParseFileSources(
const Extension* extension,
const std::vector<api::scripts_internal::ScriptSource>* js,
const std::vector<api::scripts_internal::ScriptSource>* css,
std::optional<int> definition_index,
UserScript* result,
std::u16string* error) { … }
void ParseGlobs(const std::vector<std::string>* include_globs,
const std::vector<std::string>* exclude_globs,
UserScript* result) { … }
bool ValidateFileSources(const UserScriptList& scripts,
ExtensionResource::SymlinkPolicy symlink_policy,
std::string* error,
std::vector<InstallWarning>* warnings) { … }
bool ValidateMatchOriginAsFallback(
MatchOriginAsFallbackBehavior match_origin_as_fallback,
const URLPatternSet& url_patterns,
std::u16string* error_out) { … }
ExtensionResource::SymlinkPolicy GetSymlinkPolicy(const Extension* extension) { … }
}
}