build: remove //extensions source copies (#14949)

* build: remove //extensions source copies

* chore: gn format
This commit is contained in:
Robo 2018-10-03 22:14:51 +05:30 коммит произвёл Charles Kerr
Родитель 4c4d8c5bfa
Коммит 91a965e24d
6 изменённых файлов: 11 добавлений и 1039 удалений

Просмотреть файл

@ -264,7 +264,15 @@ static_library("electron_lib") {
sources = filenames.lib_sources
set_sources_assignment_filter(sources_assignment_filter)
sources += [ "$target_gen_dir/atom_natives.h" ]
sources += [
"$target_gen_dir/atom_natives.h",
"//extensions/browser/app_window/size_constraints.cc",
"//extensions/browser/app_window/size_constraints.h",
"//extensions/common/constants.cc",
"//extensions/common/constants.h",
"//extensions/common/url_pattern.cc",
"//extensions/common/url_pattern.h",
]
if (is_component_build) {
defines += [ "NODE_SHARED_MODE" ]
@ -849,10 +857,10 @@ group("licenses") {
copy("electron_version") {
sources = [
"VERSION"
"VERSION",
]
outputs = [
"$root_build_dir/version"
"$root_build_dir/version",
]
}

Просмотреть файл

@ -1,82 +0,0 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/browser/app_window/size_constraints.h"
#include <algorithm>
#include "ui/gfx/geometry/insets.h"
namespace extensions {
SizeConstraints::SizeConstraints()
: maximum_size_(kUnboundedSize, kUnboundedSize) {}
SizeConstraints::SizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size)
: minimum_size_(min_size), maximum_size_(max_size) {}
SizeConstraints::~SizeConstraints() {}
// static
gfx::Size SizeConstraints::AddFrameToConstraints(
const gfx::Size& size_constraints,
const gfx::Insets& frame_insets) {
return gfx::Size(size_constraints.width() == kUnboundedSize
? kUnboundedSize
: size_constraints.width() + frame_insets.width(),
size_constraints.height() == kUnboundedSize
? kUnboundedSize
: size_constraints.height() + frame_insets.height());
}
gfx::Size SizeConstraints::ClampSize(gfx::Size size) const {
const gfx::Size max_size = GetMaximumSize();
if (max_size.width() != kUnboundedSize)
size.set_width(std::min(size.width(), max_size.width()));
if (max_size.height() != kUnboundedSize)
size.set_height(std::min(size.height(), max_size.height()));
size.SetToMax(GetMinimumSize());
return size;
}
bool SizeConstraints::HasMinimumSize() const {
const gfx::Size min_size = GetMinimumSize();
return min_size.width() != kUnboundedSize ||
min_size.height() != kUnboundedSize;
}
bool SizeConstraints::HasMaximumSize() const {
const gfx::Size max_size = GetMaximumSize();
return max_size.width() != kUnboundedSize ||
max_size.height() != kUnboundedSize;
}
bool SizeConstraints::HasFixedSize() const {
return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize();
}
gfx::Size SizeConstraints::GetMinimumSize() const {
return minimum_size_;
}
gfx::Size SizeConstraints::GetMaximumSize() const {
return gfx::Size(
maximum_size_.width() == kUnboundedSize
? kUnboundedSize
: std::max(maximum_size_.width(), minimum_size_.width()),
maximum_size_.height() == kUnboundedSize
? kUnboundedSize
: std::max(maximum_size_.height(), minimum_size_.height()));
}
void SizeConstraints::set_minimum_size(const gfx::Size& min_size) {
minimum_size_ = min_size;
}
void SizeConstraints::set_maximum_size(const gfx::Size& max_size) {
maximum_size_ = max_size;
}
} // namespace extensions

Просмотреть файл

@ -1,57 +0,0 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_APP_WINDOW_SIZE_CONSTRAINTS_H_
#define EXTENSIONS_BROWSER_APP_WINDOW_SIZE_CONSTRAINTS_H_
#include "ui/gfx/geometry/size.h"
namespace gfx {
class Insets;
}
namespace extensions {
class SizeConstraints {
public:
// The value SizeConstraints uses to represent an unbounded width or height.
// This is an enum so that it can be declared inline here.
enum { kUnboundedSize = 0 };
SizeConstraints();
SizeConstraints(const gfx::Size& min_size, const gfx::Size& max_size);
~SizeConstraints();
// Adds frame insets to a size constraint.
static gfx::Size AddFrameToConstraints(const gfx::Size& size_constraints,
const gfx::Insets& frame_insets);
// Returns the bounds with its size clamped to the min/max size.
gfx::Size ClampSize(gfx::Size size) const;
// When gfx::Size is used as a min/max size, a zero represents an unbounded
// component. This method checks whether either component is specified.
// Note we can't use gfx::Size::IsEmpty as it returns true if either width
// or height is zero.
bool HasMinimumSize() const;
bool HasMaximumSize() const;
// This returns true if all components are specified, and min and max are
// equal.
bool HasFixedSize() const;
gfx::Size GetMaximumSize() const;
gfx::Size GetMinimumSize() const;
void set_minimum_size(const gfx::Size& min_size);
void set_maximum_size(const gfx::Size& max_size);
private:
gfx::Size minimum_size_;
gfx::Size maximum_size_;
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_APP_WINDOW_SIZE_CONSTRAINTS_H_

Просмотреть файл

@ -1,629 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/common/url_pattern.h"
#include <stddef.h>
#include <ostream>
#include "base/macros.h"
#include "base/strings/pattern.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "content/public/common/url_constants.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
#include "url/url_util.h"
const char URLPattern::kAllUrlsPattern[] = "<all_urls>";
const char kExtensionScheme[] = "chrome-extension";
namespace {
// TODO(aa): What about more obscure schemes like data: and javascript: ?
// Note: keep this array in sync with kValidSchemeMasks.
const char* const kValidSchemes[] = {
url::kHttpScheme, url::kHttpsScheme, url::kFileScheme,
url::kFtpScheme, content::kChromeUIScheme, kExtensionScheme,
url::kFileSystemScheme,
};
const int kValidSchemeMasks[] = {
URLPattern::SCHEME_HTTP, URLPattern::SCHEME_HTTPS,
URLPattern::SCHEME_FILE, URLPattern::SCHEME_FTP,
URLPattern::SCHEME_CHROMEUI, URLPattern::SCHEME_EXTENSION,
URLPattern::SCHEME_FILESYSTEM,
};
static_assert(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks),
"must keep these arrays in sync");
const char kParseSuccess[] = "Success.";
const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator.";
const char kParseErrorInvalidScheme[] = "Invalid scheme.";
const char kParseErrorWrongSchemeType[] = "Wrong scheme type.";
const char kParseErrorEmptyHost[] = "Host can not be empty.";
const char kParseErrorInvalidHostWildcard[] = "Invalid host wildcard.";
const char kParseErrorEmptyPath[] = "Empty path.";
const char kParseErrorInvalidPort[] = "Invalid port.";
const char kParseErrorInvalidHost[] = "Invalid host.";
// Message explaining each URLPattern::ParseResult.
const char* const kParseResultMessages[] = {
kParseSuccess,
kParseErrorMissingSchemeSeparator,
kParseErrorInvalidScheme,
kParseErrorWrongSchemeType,
kParseErrorEmptyHost,
kParseErrorInvalidHostWildcard,
kParseErrorEmptyPath,
kParseErrorInvalidPort,
kParseErrorInvalidHost,
};
static_assert(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages),
"must add message for each parse result");
const char kPathSeparator[] = "/";
bool IsStandardScheme(base::StringPiece scheme) {
// "*" gets the same treatment as a standard scheme.
if (scheme == "*")
return true;
return url::IsStandard(scheme.data(),
url::Component(0, static_cast<int>(scheme.length())));
}
bool IsValidPortForScheme(base::StringPiece scheme, base::StringPiece port) {
if (port == "*")
return true;
// Only accept non-wildcard ports if the scheme uses ports.
if (url::DefaultPortForScheme(scheme.data(), scheme.length()) ==
url::PORT_UNSPECIFIED) {
return false;
}
int parsed_port = url::PORT_UNSPECIFIED;
if (!base::StringToInt(port, &parsed_port))
return false;
return (parsed_port >= 0) && (parsed_port < 65536);
}
// Returns |path| with the trailing wildcard stripped if one existed.
//
// The functions that rely on this (OverlapsWith and Contains) are only
// called for the patterns inside URLPatternSet. In those cases, we know that
// the path will have only a single wildcard at the end. This makes figuring
// out overlap much easier. It seems like there is probably a computer-sciency
// way to solve the general case, but we don't need that yet.
base::StringPiece StripTrailingWildcard(base::StringPiece path) {
if (path.ends_with("*"))
path.remove_suffix(1);
return path;
}
// Removes trailing dot from |host_piece| if any.
base::StringPiece CanonicalizeHostForMatching(base::StringPiece host_piece) {
if (host_piece.ends_with("."))
host_piece.remove_suffix(1);
return host_piece;
}
} // namespace
// static
bool URLPattern::IsValidSchemeForExtensions(base::StringPiece scheme) {
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
if (scheme == kValidSchemes[i])
return true;
}
return false;
}
URLPattern::URLPattern()
: valid_schemes_(SCHEME_NONE),
match_all_urls_(false),
match_subdomains_(false),
port_("*") {}
URLPattern::URLPattern(int valid_schemes)
: valid_schemes_(valid_schemes),
match_all_urls_(false),
match_subdomains_(false),
port_("*") {}
URLPattern::URLPattern(int valid_schemes, base::StringPiece pattern)
// Strict error checking is used, because this constructor is only
// appropriate when we know |pattern| is valid.
: valid_schemes_(valid_schemes),
match_all_urls_(false),
match_subdomains_(false),
port_("*") {
ParseResult result = Parse(pattern);
if (PARSE_SUCCESS != result)
NOTREACHED() << "URLPattern invalid: " << pattern << " result " << result;
}
URLPattern::URLPattern(const URLPattern& other) = default;
URLPattern::~URLPattern() {}
bool URLPattern::operator<(const URLPattern& other) const {
return GetAsString() < other.GetAsString();
}
bool URLPattern::operator>(const URLPattern& other) const {
return GetAsString() > other.GetAsString();
}
bool URLPattern::operator==(const URLPattern& other) const {
return GetAsString() == other.GetAsString();
}
std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern) {
return out << '"' << url_pattern.GetAsString() << '"';
}
URLPattern::ParseResult URLPattern::Parse(base::StringPiece pattern) {
spec_.clear();
SetMatchAllURLs(false);
SetMatchSubdomains(false);
SetPort("*");
// Special case pattern to match every valid URL.
if (pattern == kAllUrlsPattern) {
SetMatchAllURLs(true);
return PARSE_SUCCESS;
}
// Parse out the scheme.
size_t scheme_end_pos = pattern.find(url::kStandardSchemeSeparator);
bool has_standard_scheme_separator = true;
// Some urls also use ':' alone as the scheme separator.
if (scheme_end_pos == base::StringPiece::npos) {
scheme_end_pos = pattern.find(':');
has_standard_scheme_separator = false;
}
if (scheme_end_pos == base::StringPiece::npos)
return PARSE_ERROR_MISSING_SCHEME_SEPARATOR;
if (!SetScheme(pattern.substr(0, scheme_end_pos)))
return PARSE_ERROR_INVALID_SCHEME;
bool standard_scheme = IsStandardScheme(scheme_);
if (standard_scheme != has_standard_scheme_separator)
return PARSE_ERROR_WRONG_SCHEME_SEPARATOR;
// Advance past the scheme separator.
scheme_end_pos +=
(standard_scheme ? strlen(url::kStandardSchemeSeparator) : 1);
if (scheme_end_pos >= pattern.size())
return PARSE_ERROR_EMPTY_HOST;
// Parse out the host and path.
size_t host_start_pos = scheme_end_pos;
size_t path_start_pos = 0;
if (!standard_scheme) {
path_start_pos = host_start_pos;
} else if (scheme_ == url::kFileScheme) {
size_t host_end_pos = pattern.find(kPathSeparator, host_start_pos);
if (host_end_pos == base::StringPiece::npos) {
// Allow hostname omission.
// e.g. file://* is interpreted as file:///*,
// file://foo* is interpreted as file:///foo*.
path_start_pos = host_start_pos - 1;
} else {
// Ignore hostname if scheme is file://.
// e.g. file://localhost/foo is equal to file:///foo.
path_start_pos = host_end_pos;
}
} else {
size_t host_end_pos = pattern.find(kPathSeparator, host_start_pos);
// Host is required.
if (host_start_pos == host_end_pos)
return PARSE_ERROR_EMPTY_HOST;
if (host_end_pos == base::StringPiece::npos)
return PARSE_ERROR_EMPTY_PATH;
// TODO(devlin): This whole series is expensive. Luckily we don't do it
// *too* often, but it could be optimized.
pattern.substr(host_start_pos, host_end_pos - host_start_pos)
.CopyToString(&host_);
// The first component can optionally be '*' to match all subdomains.
std::vector<std::string> host_components = base::SplitString(
host_, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
// Could be empty if the host only consists of whitespace characters.
if (host_components.empty() ||
(host_components.size() == 1 && host_components[0].empty()))
return PARSE_ERROR_EMPTY_HOST;
if (host_components[0] == "*") {
match_subdomains_ = true;
host_components.erase(host_components.begin(),
host_components.begin() + 1);
}
host_ = base::JoinString(host_components, ".");
path_start_pos = host_end_pos;
}
SetPath(pattern.substr(path_start_pos));
size_t port_pos = host_.find(':');
if (port_pos != std::string::npos) {
if (!SetPort(host_.substr(port_pos + 1)))
return PARSE_ERROR_INVALID_PORT;
host_ = host_.substr(0, port_pos);
}
// No other '*' can occur in the host, though. This isn't necessary, but is
// done as a convenience to developers who might otherwise be confused and
// think '*' works as a glob in the host.
if (host_.find('*') != std::string::npos)
return PARSE_ERROR_INVALID_HOST_WILDCARD;
// Null characters are not allowed in hosts.
if (host_.find('\0') != std::string::npos)
return PARSE_ERROR_INVALID_HOST;
return PARSE_SUCCESS;
}
void URLPattern::SetValidSchemes(int valid_schemes) {
spec_.clear();
valid_schemes_ = valid_schemes;
}
void URLPattern::SetHost(base::StringPiece host) {
spec_.clear();
host.CopyToString(&host_);
}
void URLPattern::SetMatchAllURLs(bool val) {
spec_.clear();
match_all_urls_ = val;
if (val) {
match_subdomains_ = true;
scheme_ = "*";
host_.clear();
SetPath("/*");
}
}
void URLPattern::SetMatchSubdomains(bool val) {
spec_.clear();
match_subdomains_ = val;
}
bool URLPattern::SetScheme(base::StringPiece scheme) {
spec_.clear();
scheme.CopyToString(&scheme_);
if (scheme_ == "*") {
valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS);
} else if (!IsValidScheme(scheme_)) {
return false;
}
return true;
}
bool URLPattern::IsValidScheme(base::StringPiece scheme) const {
if (valid_schemes_ == SCHEME_ALL)
return true;
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
if (scheme == kValidSchemes[i] && (valid_schemes_ & kValidSchemeMasks[i]))
return true;
}
return false;
}
void URLPattern::SetPath(base::StringPiece path) {
spec_.clear();
path.CopyToString(&path_);
path_escaped_ = path_;
base::ReplaceSubstringsAfterOffset(&path_escaped_, 0, "\\", "\\\\");
base::ReplaceSubstringsAfterOffset(&path_escaped_, 0, "?", "\\?");
}
bool URLPattern::SetPort(base::StringPiece port) {
spec_.clear();
if (IsValidPortForScheme(scheme_, port)) {
port.CopyToString(&port_);
return true;
}
return false;
}
bool URLPattern::MatchesURL(const GURL& test) const {
const GURL* test_url = &test;
bool has_inner_url = test.inner_url() != NULL;
if (has_inner_url) {
if (!test.SchemeIsFileSystem())
return false; // The only nested URLs we handle are filesystem URLs.
test_url = test.inner_url();
}
if (!MatchesScheme(test_url->scheme_piece()))
return false;
if (match_all_urls_)
return true;
std::string path_for_request = test.PathForRequest();
if (has_inner_url) {
path_for_request = base::StringPrintf("%s%s", test_url->path_piece().data(),
path_for_request.c_str());
}
return MatchesSecurityOriginHelper(*test_url) &&
MatchesPath(path_for_request);
}
bool URLPattern::MatchesSecurityOrigin(const GURL& test) const {
const GURL* test_url = &test;
bool has_inner_url = test.inner_url() != NULL;
if (has_inner_url) {
if (!test.SchemeIsFileSystem())
return false; // The only nested URLs we handle are filesystem URLs.
test_url = test.inner_url();
}
if (!MatchesScheme(test_url->scheme()))
return false;
if (match_all_urls_)
return true;
return MatchesSecurityOriginHelper(*test_url);
}
bool URLPattern::MatchesScheme(base::StringPiece test) const {
if (!IsValidScheme(test))
return false;
return scheme_ == "*" || test == scheme_;
}
bool URLPattern::MatchesHost(base::StringPiece host) const {
// TODO(devlin): This is a bit sad. Parsing urls is expensive.
return MatchesHost(
GURL(base::StringPrintf("%s%s%s/", url::kHttpScheme,
url::kStandardSchemeSeparator, host.data())));
}
bool URLPattern::MatchesHost(const GURL& test) const {
const base::StringPiece test_host(
CanonicalizeHostForMatching(test.host_piece()));
const base::StringPiece pattern_host(CanonicalizeHostForMatching(host_));
// If the hosts are exactly equal, we have a match.
if (test_host == pattern_host)
return true;
// If we're matching subdomains, and we have no host in the match pattern,
// that means that we're matching all hosts, which means we have a match no
// matter what the test host is.
if (match_subdomains_ && pattern_host.empty())
return true;
// Otherwise, we can only match if our match pattern matches subdomains.
if (!match_subdomains_)
return false;
// We don't do subdomain matching against IP addresses, so we can give up now
// if the test host is an IP address.
if (test.HostIsIPAddress())
return false;
// Check if the test host is a subdomain of our host.
if (test_host.length() <= (pattern_host.length() + 1))
return false;
if (!test_host.ends_with(pattern_host))
return false;
return test_host[test_host.length() - pattern_host.length() - 1] == '.';
}
bool URLPattern::ImpliesAllHosts() const {
// Check if it matches all urls or is a pattern like http://*/*.
if (match_all_urls_ ||
(match_subdomains_ && host_.empty() && port_ == "*" && path_ == "/*")) {
return true;
}
// If this doesn't even match subdomains, it can't possibly imply all hosts.
if (!match_subdomains_)
return false;
// If there was more than just a TLD in the host (e.g., *.foobar.com), it
// doesn't imply all hosts. We don't include private TLDs, so that, e.g.,
// *.appspot.com does not imply all hosts.
if (net::registry_controlled_domains::HostHasRegistryControlledDomain(
host_, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES))
return false;
// At this point the host could either be just a TLD ("com") or some unknown
// TLD-like string ("notatld"). To disambiguate between them construct a
// fake URL, and check the registry.
//
// If we recognized this TLD, then this is a pattern like *.com, and it
// should imply all hosts.
return net::registry_controlled_domains::HostHasRegistryControlledDomain(
"notatld." + host_,
net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
}
bool URLPattern::MatchesSingleOrigin() const {
// Strictly speaking, the port is part of the origin, but in URLPattern it
// defaults to *. It's not very interesting anyway, so leave it out.
return !ImpliesAllHosts() && scheme_ != "*" && !match_subdomains_;
}
bool URLPattern::MatchesPath(base::StringPiece test) const {
// Make the behaviour of OverlapsWith consistent with MatchesURL, which is
// need to match hosted apps on e.g. 'google.com' also run on 'google.com/'.
// The below if is a no-copy way of doing (test + "/*" == path_escaped_).
if (path_escaped_.length() == test.length() + 2 &&
base::StartsWith(path_escaped_.c_str(), test,
base::CompareCase::SENSITIVE) &&
base::EndsWith(path_escaped_, "/*", base::CompareCase::SENSITIVE)) {
return true;
}
return base::MatchPattern(test, path_escaped_);
}
const std::string& URLPattern::GetAsString() const {
if (!spec_.empty())
return spec_;
if (match_all_urls_) {
spec_ = kAllUrlsPattern;
return spec_;
}
bool standard_scheme = IsStandardScheme(scheme_);
std::string spec =
scheme_ + (standard_scheme ? url::kStandardSchemeSeparator : ":");
if (scheme_ != url::kFileScheme && standard_scheme) {
if (match_subdomains_) {
spec += "*";
if (!host_.empty())
spec += ".";
}
if (!host_.empty())
spec += host_;
if (port_ != "*") {
spec += ":";
spec += port_;
}
}
if (!path_.empty())
spec += path_;
spec_ = std::move(spec);
return spec_;
}
bool URLPattern::OverlapsWith(const URLPattern& other) const {
if (match_all_urls() || other.match_all_urls())
return true;
return (MatchesAnyScheme(other.GetExplicitSchemes()) ||
other.MatchesAnyScheme(GetExplicitSchemes())) &&
(MatchesHost(other.host()) || other.MatchesHost(host())) &&
(MatchesPortPattern(other.port()) ||
other.MatchesPortPattern(port())) &&
(MatchesPath(StripTrailingWildcard(other.path())) ||
other.MatchesPath(StripTrailingWildcard(path())));
}
bool URLPattern::Contains(const URLPattern& other) const {
if (match_all_urls())
return true;
return MatchesAllSchemes(other.GetExplicitSchemes()) &&
MatchesHost(other.host()) &&
(!other.match_subdomains_ || match_subdomains_) &&
MatchesPortPattern(other.port()) &&
MatchesPath(StripTrailingWildcard(other.path()));
}
bool URLPattern::MatchesAnyScheme(
const std::vector<std::string>& schemes) const {
for (std::vector<std::string>::const_iterator i = schemes.begin();
i != schemes.end(); ++i) {
if (MatchesScheme(*i))
return true;
}
return false;
}
bool URLPattern::MatchesAllSchemes(
const std::vector<std::string>& schemes) const {
for (std::vector<std::string>::const_iterator i = schemes.begin();
i != schemes.end(); ++i) {
if (!MatchesScheme(*i))
return false;
}
return true;
}
bool URLPattern::MatchesSecurityOriginHelper(const GURL& test) const {
// Ignore hostname if scheme is file://.
if (scheme_ != url::kFileScheme && !MatchesHost(test))
return false;
if (!MatchesPortPattern(base::IntToString(test.EffectiveIntPort())))
return false;
return true;
}
bool URLPattern::MatchesPortPattern(base::StringPiece port) const {
return port_ == "*" || port_ == port;
}
std::vector<std::string> URLPattern::GetExplicitSchemes() const {
std::vector<std::string> result;
if (scheme_ != "*" && !match_all_urls_ && IsValidScheme(scheme_)) {
result.push_back(scheme_);
return result;
}
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
if (MatchesScheme(kValidSchemes[i])) {
result.push_back(kValidSchemes[i]);
}
}
return result;
}
std::vector<URLPattern> URLPattern::ConvertToExplicitSchemes() const {
std::vector<std::string> explicit_schemes = GetExplicitSchemes();
std::vector<URLPattern> result;
for (std::vector<std::string>::const_iterator i = explicit_schemes.begin();
i != explicit_schemes.end(); ++i) {
URLPattern temp = *this;
temp.SetScheme(*i);
temp.SetMatchAllURLs(false);
result.push_back(temp);
}
return result;
}
// static
const char* URLPattern::GetParseResultString(
URLPattern::ParseResult parse_result) {
return kParseResultMessages[parse_result];
}

Просмотреть файл

@ -1,264 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_COMMON_URL_PATTERN_H_
#define EXTENSIONS_COMMON_URL_PATTERN_H_
#include <functional>
#include <iosfwd>
#include <string>
#include <vector>
#include "base/strings/string_piece.h"
class GURL;
// A pattern that can be used to match URLs. A URLPattern is a very restricted
// subset of URL syntax:
//
// <url-pattern> := <scheme>://<host><port><path> | '<all_urls>'
// <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' |
// 'chrome-extension' | 'filesystem'
// <host> := '*' | '*.' <anychar except '/' and '*'>+
// <port> := [':' ('*' | <port number between 0 and 65535>)]
// <path> := '/' <any chars>
//
// * Host is not used when the scheme is 'file'.
// * The path can have embedded '*' characters which act as glob wildcards.
// * '<all_urls>' is a special pattern that matches any URL that contains a
// valid scheme (as specified by valid_schemes_).
// * The '*' scheme pattern excludes file URLs.
//
// Examples of valid patterns:
// - http://*/*
// - http://*/foo*
// - https://*.google.com/foo*bar
// - file://monkey*
// - http://127.0.0.1/*
//
// Examples of invalid patterns:
// - http://* -- path not specified
// - http://*foo/bar -- * not allowed as substring of host component
// - http://foo.*.bar/baz -- * must be first component
// - http:/bar -- scheme separator not found
// - foo://* -- invalid scheme
// - chrome:// -- we don't support chrome internal URLs
class URLPattern {
public:
// A collection of scheme bitmasks for use with valid_schemes.
enum SchemeMasks {
SCHEME_NONE = 0,
SCHEME_HTTP = 1 << 0,
SCHEME_HTTPS = 1 << 1,
SCHEME_FILE = 1 << 2,
SCHEME_FTP = 1 << 3,
SCHEME_CHROMEUI = 1 << 4,
SCHEME_EXTENSION = 1 << 5,
SCHEME_FILESYSTEM = 1 << 6,
// IMPORTANT!
// SCHEME_ALL will match every scheme, including chrome://, chrome-
// extension://, about:, etc. Because this has lots of security
// implications, third-party extensions should usually not be able to get
// access to URL patterns initialized this way. If there is a reason
// for violating this general rule, document why this it safe.
SCHEME_ALL = -1,
};
// Error codes returned from Parse().
enum ParseResult {
PARSE_SUCCESS = 0,
PARSE_ERROR_MISSING_SCHEME_SEPARATOR,
PARSE_ERROR_INVALID_SCHEME,
PARSE_ERROR_WRONG_SCHEME_SEPARATOR,
PARSE_ERROR_EMPTY_HOST,
PARSE_ERROR_INVALID_HOST_WILDCARD,
PARSE_ERROR_EMPTY_PATH,
PARSE_ERROR_INVALID_PORT,
PARSE_ERROR_INVALID_HOST,
NUM_PARSE_RESULTS
};
// The <all_urls> string pattern.
static const char kAllUrlsPattern[];
// Returns true if the given |scheme| is considered valid for extensions.
static bool IsValidSchemeForExtensions(base::StringPiece scheme);
explicit URLPattern(int valid_schemes);
// Convenience to construct a URLPattern from a string. If the string is not
// known ahead of time, use Parse() instead, which returns success or failure.
URLPattern(int valid_schemes, base::StringPiece pattern);
URLPattern();
URLPattern(const URLPattern& other);
~URLPattern();
bool operator<(const URLPattern& other) const;
bool operator>(const URLPattern& other) const;
bool operator==(const URLPattern& other) const;
// Initializes this instance by parsing the provided string. Returns
// URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On
// failure, this instance will have some intermediate values and is in an
// invalid state.
ParseResult Parse(base::StringPiece pattern_str);
// Gets the bitmask of valid schemes.
int valid_schemes() const { return valid_schemes_; }
void SetValidSchemes(int valid_schemes);
// Gets the host the pattern matches. This can be an empty string if the
// pattern matches all hosts (the input was <scheme>://*/<whatever>).
const std::string& host() const { return host_; }
void SetHost(base::StringPiece host);
// Gets whether to match subdomains of host().
bool match_subdomains() const { return match_subdomains_; }
void SetMatchSubdomains(bool val);
// Gets the path the pattern matches with the leading slash. This can have
// embedded asterisks which are interpreted using glob rules.
const std::string& path() const { return path_; }
void SetPath(base::StringPiece path);
// Returns true if this pattern matches all urls.
bool match_all_urls() const { return match_all_urls_; }
void SetMatchAllURLs(bool val);
// Sets the scheme for pattern matches. This can be a single '*' if the
// pattern matches all valid schemes (as defined by the valid_schemes_
// property). Returns false on failure (if the scheme is not valid).
bool SetScheme(base::StringPiece scheme);
// Note: You should use MatchesScheme() instead of this getter unless you
// absolutely need the exact scheme. This is exposed for testing.
const std::string& scheme() const { return scheme_; }
// Returns true if the specified scheme can be used in this URL pattern, and
// false otherwise. Uses valid_schemes_ to determine validity.
bool IsValidScheme(base::StringPiece scheme) const;
// Returns true if this instance matches the specified URL.
bool MatchesURL(const GURL& test) const;
// Returns true if this instance matches the specified security origin.
bool MatchesSecurityOrigin(const GURL& test) const;
// Returns true if |test| matches our scheme.
// Note that if test is "filesystem", this may fail whereas MatchesURL
// may succeed. MatchesURL is smart enough to look at the inner_url instead
// of the outer "filesystem:" part.
bool MatchesScheme(base::StringPiece test) const;
// Returns true if |test| matches our host.
bool MatchesHost(base::StringPiece test) const;
bool MatchesHost(const GURL& test) const;
// Returns true if |test| matches our path.
bool MatchesPath(base::StringPiece test) const;
// Returns true if the pattern is vague enough that it implies all hosts,
// such as *://*/*.
// This is an expensive method, and should be used sparingly!
// You should probably use URLPatternSet::ShouldWarnAllHosts(), which is
// cached.
bool ImpliesAllHosts() const;
// Returns true if the pattern only matches a single origin. The pattern may
// include a path.
bool MatchesSingleOrigin() const;
// Sets the port. Returns false if the port is invalid.
bool SetPort(base::StringPiece port);
const std::string& port() const { return port_; }
// Returns a string representing this instance.
const std::string& GetAsString() const;
// Determines whether there is a URL that would match this instance and
// another instance. This method is symmetrical: Calling
// other.OverlapsWith(this) would result in the same answer.
bool OverlapsWith(const URLPattern& other) const;
// Returns true if this pattern matches all possible URLs that |other| can
// match. For example, http://*.google.com encompasses http://www.google.com.
bool Contains(const URLPattern& other) const;
// Converts this URLPattern into an equivalent set of URLPatterns that don't
// use a wildcard in the scheme component. If this URLPattern doesn't use a
// wildcard scheme, then the returned set will contain one element that is
// equivalent to this instance.
std::vector<URLPattern> ConvertToExplicitSchemes() const;
static bool EffectiveHostCompare(const URLPattern& a, const URLPattern& b) {
if (a.match_all_urls_ && b.match_all_urls_)
return false;
return a.host_.compare(b.host_) < 0;
}
// Used for origin comparisons in a std::set.
class EffectiveHostCompareFunctor {
public:
bool operator()(const URLPattern& a, const URLPattern& b) const {
return EffectiveHostCompare(a, b);
}
};
// Get an error string for a ParseResult.
static const char* GetParseResultString(URLPattern::ParseResult parse_result);
private:
// Returns true if any of the |schemes| items matches our scheme.
bool MatchesAnyScheme(const std::vector<std::string>& schemes) const;
// Returns true if all of the |schemes| items matches our scheme.
bool MatchesAllSchemes(const std::vector<std::string>& schemes) const;
bool MatchesSecurityOriginHelper(const GURL& test) const;
// Returns true if our port matches the |port| pattern (it may be "*").
bool MatchesPortPattern(base::StringPiece port) const;
// If the URLPattern contains a wildcard scheme, returns a list of
// equivalent literal schemes, otherwise returns the current scheme.
std::vector<std::string> GetExplicitSchemes() const;
// A bitmask containing the schemes which are considered valid for this
// pattern. Parse() uses this to decide whether a pattern contains a valid
// scheme.
int valid_schemes_;
// True if this is a special-case "<all_urls>" pattern.
bool match_all_urls_;
// The scheme for the pattern.
std::string scheme_;
// The host without any leading "*" components.
std::string host_;
// Whether we should match subdomains of the host. This is true if the first
// component of the pattern's host was "*".
bool match_subdomains_;
// The port.
std::string port_;
// The path to match. This is everything after the host of the URL, or
// everything after the scheme in the case of file:// URLs.
std::string path_;
// The path with "?" and "\" characters escaped for use with the
// MatchPattern() function.
std::string path_escaped_;
// A string representing this URLPattern.
mutable std::string spec_;
};
std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern);
typedef std::vector<URLPattern> URLPatternList;
#endif // EXTENSIONS_COMMON_URL_PATTERN_H_

Просмотреть файл

@ -650,10 +650,6 @@ filenames = {
"chromium_src/chrome/renderer/tts_dispatcher.cc",
"chromium_src/chrome/renderer/tts_dispatcher.h",
"chromium_src/chrome/utility/utility_message_handler.h",
"chromium_src/extensions/browser/app_window/size_constraints.cc",
"chromium_src/extensions/browser/app_window/size_constraints.h",
"chromium_src/extensions/common/url_pattern.cc",
"chromium_src/extensions/common/url_pattern.h",
"chromium_src/library_loaders/libspeechd_loader.cc",
"chromium_src/library_loaders/libspeechd.h",
]