forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorigin_struct_traits.h
48 lines (39 loc) · 1.44 KB
/
origin_struct_traits.h
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
// Copyright 2016 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 URL_MOJO_ORIGIN_STRUCT_TRAITS_H_
#define URL_MOJO_ORIGIN_STRUCT_TRAITS_H_
#include "base/strings/string_piece.h"
#include "url/mojo/origin.mojom.h"
#include "url/origin.h"
namespace mojo {
template <>
struct StructTraits<url::mojom::OriginDataView, url::Origin> {
static const std::string& scheme(const url::Origin& r) { return r.scheme(); }
static const std::string& host(const url::Origin& r) { return r.host(); }
static uint16_t port(const url::Origin& r) {
return r.port();
}
static bool unique(const url::Origin& r) {
return r.unique();
}
static bool Read(url::mojom::OriginDataView data, url::Origin* out) {
if (data.unique()) {
*out = url::Origin();
} else {
base::StringPiece scheme, host;
if (!data.ReadScheme(&scheme) || !data.ReadHost(&host))
return false;
*out = url::Origin::UnsafelyCreateOriginWithoutNormalization(scheme, host,
data.port());
}
// If a unique origin was created, but the unique flag wasn't set, then
// the values provided to 'UnsafelyCreateOriginWithoutNormalization' were
// invalid.
if (!data.unique() && out->unique())
return false;
return true;
}
};
}
#endif // URL_MOJO_ORIGIN_STRUCT_TRAITS_H_