blob: cbf40e6a8ce8ec0c268fd5554367410431bfb5eb (
plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright 2019 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 "third_party/blink/renderer/modules/content_index/content_description_type_converter.h"
#include "third_party/blink/public/mojom/content_index/content_index.mojom-blink.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_content_icon_definition.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
namespace mojo {
namespace {
blink::mojom::ContentCategory GetContentCategory(const WTF::String& category) {
if (category == "")
return blink::mojom::ContentCategory::NONE;
if (category == "homepage")
return blink::mojom::ContentCategory::HOME_PAGE;
if (category == "article")
return blink::mojom::ContentCategory::ARTICLE;
if (category == "video")
return blink::mojom::ContentCategory::VIDEO;
if (category == "audio")
return blink::mojom::ContentCategory::AUDIO;
NOTREACHED();
return blink::mojom::ContentCategory::NONE;
}
WTF::String GetContentCategory(blink::mojom::ContentCategory category) {
switch (category) {
case blink::mojom::ContentCategory::NONE:
return "";
case blink::mojom::ContentCategory::HOME_PAGE:
return "homepage";
case blink::mojom::ContentCategory::ARTICLE:
return "article";
case blink::mojom::ContentCategory::VIDEO:
return "video";
case blink::mojom::ContentCategory::AUDIO:
return "audio";
}
}
} // namespace
blink::mojom::blink::ContentDescriptionPtr TypeConverter<
blink::mojom::blink::ContentDescriptionPtr,
const blink::ContentDescription*>::Convert(const blink::ContentDescription*
description) {
auto result = blink::mojom::blink::ContentDescription::New();
result->id = description->id();
result->title = description->title();
result->description = description->description();
result->category = GetContentCategory(description->category());
for (const auto& icon : description->icons()) {
result->icons.push_back(blink::mojom::blink::ContentIconDefinition::New(
icon->src(), icon->sizes(), icon->type()));
}
result->launch_url = description->launchUrl();
return result;
}
blink::ContentDescription*
TypeConverter<blink::ContentDescription*,
blink::mojom::blink::ContentDescriptionPtr>::
Convert(const blink::mojom::blink::ContentDescriptionPtr& description) {
auto* result = blink::MakeGarbageCollected<blink::ContentDescription>();
result->setId(description->id);
result->setTitle(description->title);
result->setDescription(description->description);
result->setCategory(GetContentCategory(description->category));
blink::HeapVector<blink::Member<blink::ContentIconDefinition>> blink_icons;
for (const auto& icon : description->icons) {
auto* blink_icon =
blink::MakeGarbageCollected<blink::ContentIconDefinition>();
blink_icon->setSrc(icon->src);
blink_icon->setSizes(icon->sizes);
blink_icon->setType(icon->type);
blink_icons.push_back(blink_icon);
}
result->setIcons(blink_icons);
result->setLaunchUrl(description->launch_url);
return result;
}
} // namespace mojo
|