Skip to content

Commit

Permalink
url: Clean up export macros.
Browse files Browse the repository at this point in the history
Migrates the bindings library to COMPONENT_EXPORT macro.

Change-Id: I09bff19f47cc5df47797c5a517055afe5cd15046
Reviewed-on: https://chromium-review.googlesource.com/c/1359868
Commit-Queue: Staphany Park <staphany@chromium.org>
Reviewed-by: Chris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613694}
  • Loading branch information
Staphany Park authored and Commit Bot committed Dec 4, 2018
1 parent d3698ba commit 6fd74a2
Show file tree
Hide file tree
Showing 14 changed files with 602 additions and 547 deletions.
5 changes: 2 additions & 3 deletions url/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# found in the LICENSE file.

import("//build/buildflag_header.gni")
import("//testing/test.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("features.gni")

if (is_android) {
Expand Down Expand Up @@ -47,7 +47,6 @@ component("url") {
"url_canon_stdurl.cc",
"url_constants.cc",
"url_constants.h",
"url_export.h",
"url_file.h",
"url_parse_file.cc",
"url_parse_internal.h",
Expand All @@ -56,7 +55,7 @@ component("url") {
"url_util_internal.h",
]

defines = [ "URL_IMPLEMENTATION" ]
defines = [ "IS_URL_IMPL" ]

configs += [
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
Expand Down
23 changes: 14 additions & 9 deletions url/gurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#include <memory>
#include <string>

#include "base/component_export.h"
#include "base/debug/alias.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_canon.h"
#include "url/url_canon_stdstring.h"
#include "url/url_constants.h"
#include "url/url_export.h"

// Represents a URL. GURL is Google's URL parsing library.
//
Expand All @@ -43,7 +43,7 @@
// path that contains a literal '#'. Using string concatenation will generate a
// URL with a truncated path and a reference fragment, while ReplaceComponents
// will know to escape this and produce the desired result.
class URL_EXPORT GURL {
class COMPONENT_EXPORT(URL) GURL {
public:
typedef url::StringPieceReplacements<std::string> Replacements;
typedef url::StringPieceReplacements<base::string16> ReplacementsW;
Expand Down Expand Up @@ -472,18 +472,23 @@ class URL_EXPORT GURL {
};

// Stream operator so GURL can be used in assertion statements.
URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url);
COMPONENT_EXPORT(URL)
std::ostream& operator<<(std::ostream& out, const GURL& url);

URL_EXPORT bool operator==(const GURL& x, const GURL& y);
URL_EXPORT bool operator!=(const GURL& x, const GURL& y);
COMPONENT_EXPORT(URL) bool operator==(const GURL& x, const GURL& y);
COMPONENT_EXPORT(URL) bool operator!=(const GURL& x, const GURL& y);

// Equality operator for comparing raw spec_. This should be used in place of
// url == GURL(spec) where |spec| is known (i.e. constants). This is to prevent
// needlessly re-parsing |spec| into a temporary GURL.
URL_EXPORT bool operator==(const GURL& x, const base::StringPiece& spec);
URL_EXPORT bool operator==(const base::StringPiece& spec, const GURL& x);
URL_EXPORT bool operator!=(const GURL& x, const base::StringPiece& spec);
URL_EXPORT bool operator!=(const base::StringPiece& spec, const GURL& x);
COMPONENT_EXPORT(URL)
bool operator==(const GURL& x, const base::StringPiece& spec);
COMPONENT_EXPORT(URL)
bool operator==(const base::StringPiece& spec, const GURL& x);
COMPONENT_EXPORT(URL)
bool operator!=(const GURL& x, const base::StringPiece& spec);
COMPONENT_EXPORT(URL)
bool operator!=(const base::StringPiece& spec, const GURL& x);

// DEBUG_ALIAS_FOR_GURL(var_name, url) copies |url| into a new stack-allocated
// variable named |<var_name>|. This helps ensure that the value of |url| gets
Expand Down
23 changes: 12 additions & 11 deletions url/origin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <string>

#include "base/component_export.h"
#include "base/debug/alias.h"
#include "base/optional.h"
#include "base/strings/string16.h"
Expand All @@ -20,7 +21,6 @@
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_canon.h"
#include "url/url_constants.h"
#include "url/url_export.h"

class GURL;

Expand Down Expand Up @@ -117,7 +117,7 @@ class OriginDataView;
// if (this.IsSameOriginWith(that)) {
// // Amazingness goes here.
// }
class URL_EXPORT Origin {
class COMPONENT_EXPORT(URL) Origin {
public:
// Creates an opaque Origin with a nonce that is different from all previously
// existing origins.
Expand Down Expand Up @@ -264,8 +264,8 @@ class URL_EXPORT Origin {
friend struct ipc_fuzzer::FuzzTraits<Origin>;
friend struct mojo::StructTraits<url::mojom::OriginDataView, url::Origin>;
friend IPC::ParamTraits<url::Origin>;
friend URL_EXPORT std::ostream& operator<<(std::ostream& out,
const Origin& origin);
friend COMPONENT_EXPORT(URL) std::ostream& operator<<(std::ostream& out,
const Origin& origin);

// Origin::Nonce is a wrapper around base::UnguessableToken that generates
// the random value only when the value is first accessed. The lazy generation
Expand All @@ -274,7 +274,7 @@ class URL_EXPORT Origin {
//
// TODO(nick): Should this optimization move into UnguessableToken, once it no
// longer treats the Null case specially?
class URL_EXPORT Nonce {
class COMPONENT_EXPORT(URL) Nonce {
public:
// Creates a nonce to hold a newly-generated UnguessableToken. The actual
// token value will be generated lazily.
Expand Down Expand Up @@ -315,8 +315,8 @@ class URL_EXPORT Origin {

// This needs to be friended within Origin as well, since Nonce is a private
// nested class of Origin.
friend URL_EXPORT std::ostream& operator<<(std::ostream& out,
const Nonce& nonce);
friend COMPONENT_EXPORT(URL) std::ostream& operator<<(std::ostream& out,
const Nonce& nonce);

// Creates an origin without sanity checking that the host is canonicalized.
// This should only be used when converting between already normalized types,
Expand Down Expand Up @@ -366,11 +366,12 @@ class URL_EXPORT Origin {
};

// Pretty-printers for logging. These expose the internal state of the nonce.
URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin);
URL_EXPORT std::ostream& operator<<(std::ostream& out,
const Origin::Nonce& origin);
COMPONENT_EXPORT(URL)
std::ostream& operator<<(std::ostream& out, const Origin& origin);
COMPONENT_EXPORT(URL)
std::ostream& operator<<(std::ostream& out, const Origin::Nonce& origin);

URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b);
COMPONENT_EXPORT(URL) bool IsSameOriginWith(const GURL& a, const GURL& b);

// DEBUG_ALIAS_FOR_ORIGIN(var_name, origin) copies |origin| into a new
// stack-allocated variable named |<var_name>|. This helps ensure that the
Expand Down
9 changes: 5 additions & 4 deletions url/scheme_host_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <string>

#include "base/component_export.h"
#include "base/strings/string_piece.h"
#include "url/url_export.h"

class GURL;

Expand Down Expand Up @@ -72,7 +72,7 @@ struct Parsed;
//
// GURL url("https://example.com/");
// tuple == url::SchemeHostPort(url); // true
class URL_EXPORT SchemeHostPort {
class COMPONENT_EXPORT(URL) SchemeHostPort {
public:
// Creates an invalid (scheme, host, port) tuple, which represents an invalid
// or non-standard URL.
Expand Down Expand Up @@ -161,8 +161,9 @@ class URL_EXPORT SchemeHostPort {
uint16_t port_;
};

URL_EXPORT std::ostream& operator<<(std::ostream& out,
const SchemeHostPort& scheme_host_port);
COMPONENT_EXPORT(URL)
std::ostream& operator<<(std::ostream& out,
const SchemeHostPort& scheme_host_port);

} // namespace url

Expand Down
133 changes: 68 additions & 65 deletions url/third_party/mozilla/url_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef URL_THIRD_PARTY_MOZILLA_URL_PARSE_H_
#define URL_THIRD_PARTY_MOZILLA_URL_PARSE_H_

#include "base/component_export.h"
#include "base/strings/string16.h"
#include "url/url_export.h"

namespace url {

Expand Down Expand Up @@ -74,7 +74,7 @@ inline Component MakeRange(int begin, int end) {
// else
// ParsePathURL(url, url_len, &parsed);
//
struct URL_EXPORT Parsed {
struct COMPONENT_EXPORT(URL) Parsed {
// Identifies different components.
enum ComponentType {
SCHEME,
Expand Down Expand Up @@ -227,46 +227,44 @@ struct URL_EXPORT Parsed {
// StandardURL is for when the scheme is known to be one that has an
// authority (host) like "http". This function will not handle weird ones
// like "about:" and "javascript:", or do the right thing for "file:" URLs.
URL_EXPORT void ParseStandardURL(const char* url,
int url_len,
Parsed* parsed);
URL_EXPORT void ParseStandardURL(const base::char16* url,
int url_len,
Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseStandardURL(const char* url, int url_len, Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed);

// PathURL is for when the scheme is known not to have an authority (host)
// section but that aren't file URLs either. The scheme is parsed, and
// everything after the scheme is considered as the path. This is used for
// things like "about:" and "javascript:"
URL_EXPORT void ParsePathURL(const char* url,
int url_len,
bool trim_path_end,
Parsed* parsed);
URL_EXPORT void ParsePathURL(const base::char16* url,
int url_len,
bool trim_path_end,
Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParsePathURL(const char* url,
int url_len,
bool trim_path_end,
Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParsePathURL(const base::char16* url,
int url_len,
bool trim_path_end,
Parsed* parsed);

// FileURL is for file URLs. There are some special rules for interpreting
// these.
URL_EXPORT void ParseFileURL(const char* url, int url_len, Parsed* parsed);
URL_EXPORT void ParseFileURL(const base::char16* url,
int url_len,
Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseFileURL(const char* url, int url_len, Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseFileURL(const base::char16* url, int url_len, Parsed* parsed);

// Filesystem URLs are structured differently than other URLs.
URL_EXPORT void ParseFileSystemURL(const char* url,
int url_len,
Parsed* parsed);
URL_EXPORT void ParseFileSystemURL(const base::char16* url,
int url_len,
Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed);

// MailtoURL is for mailto: urls. They are made up scheme,path,query
URL_EXPORT void ParseMailtoURL(const char* url, int url_len, Parsed* parsed);
URL_EXPORT void ParseMailtoURL(const base::char16* url,
int url_len,
Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseMailtoURL(const char* url, int url_len, Parsed* parsed);
COMPONENT_EXPORT(URL)
void ParseMailtoURL(const base::char16* url, int url_len, Parsed* parsed);

// Helper functions -----------------------------------------------------------

Expand All @@ -290,31 +288,31 @@ URL_EXPORT void ParseMailtoURL(const base::char16* url,
// end of the string).
//
// The 8-bit version requires UTF-8 encoding.
URL_EXPORT bool ExtractScheme(const char* url,
int url_len,
Component* scheme);
URL_EXPORT bool ExtractScheme(const base::char16* url,
int url_len,
Component* scheme);
COMPONENT_EXPORT(URL)
bool ExtractScheme(const char* url, int url_len, Component* scheme);
COMPONENT_EXPORT(URL)
bool ExtractScheme(const base::char16* url, int url_len, Component* scheme);

// Returns true if ch is a character that terminates the authority segment
// of a URL.
URL_EXPORT bool IsAuthorityTerminator(base::char16 ch);
COMPONENT_EXPORT(URL) bool IsAuthorityTerminator(base::char16 ch);

// Does a best effort parse of input |spec|, in range |auth|. If a particular
// component is not found, it will be set to invalid.
URL_EXPORT void ParseAuthority(const char* spec,
const Component& auth,
Component* username,
Component* password,
Component* hostname,
Component* port_num);
URL_EXPORT void ParseAuthority(const base::char16* spec,
const Component& auth,
Component* username,
Component* password,
Component* hostname,
Component* port_num);
COMPONENT_EXPORT(URL)
void ParseAuthority(const char* spec,
const Component& auth,
Component* username,
Component* password,
Component* hostname,
Component* port_num);
COMPONENT_EXPORT(URL)
void ParseAuthority(const base::char16* spec,
const Component& auth,
Component* username,
Component* password,
Component* hostname,
Component* port_num);

// Computes the integer port value from the given port component. The port
// component should have been identified by one of the init functions on
Expand All @@ -323,8 +321,9 @@ URL_EXPORT void ParseAuthority(const base::char16* spec,
// The return value will be a positive integer between 0 and 64K, or one of
// the two special values below.
enum SpecialPort { PORT_UNSPECIFIED = -1, PORT_INVALID = -2 };
URL_EXPORT int ParsePort(const char* url, const Component& port);
URL_EXPORT int ParsePort(const base::char16* url, const Component& port);
COMPONENT_EXPORT(URL) int ParsePort(const char* url, const Component& port);
COMPONENT_EXPORT(URL)
int ParsePort(const base::char16* url, const Component& port);

// Extracts the range of the file name in the given url. The path must
// already have been computed by the parse function, and the matching URL
Expand All @@ -336,12 +335,14 @@ URL_EXPORT int ParsePort(const base::char16* url, const Component& port);
// following the last slash.
//
// The 8-bit version requires UTF-8 encoding.
URL_EXPORT void ExtractFileName(const char* url,
const Component& path,
Component* file_name);
URL_EXPORT void ExtractFileName(const base::char16* url,
const Component& path,
Component* file_name);
COMPONENT_EXPORT(URL)
void ExtractFileName(const char* url,
const Component& path,
Component* file_name);
COMPONENT_EXPORT(URL)
void ExtractFileName(const base::char16* url,
const Component& path,
Component* file_name);

// Extract the first key/value from the range defined by |*query|. Updates
// |*query| to start at the end of the extracted key/value pair. This is
Expand All @@ -358,14 +359,16 @@ URL_EXPORT void ExtractFileName(const base::char16* url,
//
// If no key/value are found |*key| and |*value| will be unchanged and it will
// return false.
URL_EXPORT bool ExtractQueryKeyValue(const char* url,
Component* query,
Component* key,
Component* value);
URL_EXPORT bool ExtractQueryKeyValue(const base::char16* url,
Component* query,
Component* key,
Component* value);
COMPONENT_EXPORT(URL)
bool ExtractQueryKeyValue(const char* url,
Component* query,
Component* key,
Component* value);
COMPONENT_EXPORT(URL)
bool ExtractQueryKeyValue(const base::char16* url,
Component* query,
Component* key,
Component* value);

} // namespace url

Expand Down
Loading

0 comments on commit 6fd74a2

Please sign in to comment.