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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// Copyright 2015 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 "ios/chrome/browser/ui/webui/about_ui.h"
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include "base/format_macros.h"
#include "base/i18n/number_formatting.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/string_number_conversions.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "grit/components_resources.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/web/public/url_data_source_ios.h"
#include "net/base/escape.h"
#include "ui/base/device_form_factor.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/gurl.h"
namespace {
const char kCreditsJsPath[] = "credits.js";
const char kStringsJsPath[] = "strings.js";
class AboutUIHTMLSource : public web::URLDataSourceIOS {
public:
// Construct a data source for the specified |source_name|.
AboutUIHTMLSource(const std::string& source_name);
// web::URLDataSourceIOS implementation.
std::string GetSource() const override;
void StartDataRequest(
const std::string& path,
const web::URLDataSourceIOS::GotDataCallback& callback) override;
std::string GetMimeType(const std::string& path) const override;
bool ShouldDenyXFrameOptions() const override;
// Send the response data.
void FinishDataRequest(
const std::string& html,
const web::URLDataSourceIOS::GotDataCallback& callback);
private:
~AboutUIHTMLSource() override;
std::string source_name_;
DISALLOW_COPY_AND_ASSIGN(AboutUIHTMLSource);
};
void AppendHeader(std::string* output,
int refresh,
const std::string& unescaped_title) {
output->append("<!DOCTYPE HTML>\n<html>\n<head>\n");
if (!unescaped_title.empty()) {
output->append("<title>");
output->append(net::EscapeForHTML(unescaped_title));
output->append("</title>\n");
}
output->append("<meta charset='utf-8'>\n");
if (refresh > 0) {
output->append("<meta http-equiv='refresh' content='");
output->append(base::IntToString(refresh));
output->append("'/>\n");
}
}
void AppendBody(std::string* output) {
output->append("</head>\n<body>\n");
}
void AppendFooter(std::string* output) {
output->append("</body>\n</html>\n");
}
std::string ChromeURLs() {
std::string html;
AppendHeader(&html, 0, "Chrome URLs");
AppendBody(&html);
html += "<h2>List of Chrome URLs</h2>\n<ul>\n";
std::vector<std::string> hosts(kChromeHostURLs,
kChromeHostURLs + kNumberOfChromeHostURLs);
// Remove chrome://bookmarks from list of hosts for iPhone because it is not
// possible to open bookmarks via URL on the iPhone form factor.
if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE) {
hosts.erase(
std::remove(hosts.begin(), hosts.end(), kChromeUIBookmarksHost));
}
std::sort(hosts.begin(), hosts.end());
for (std::vector<std::string>::const_iterator i = hosts.begin();
i != hosts.end(); ++i)
html += "<li><a href='chrome://" + *i + "/'>chrome://" + *i + "</a></li>\n";
html += "</ul>\n";
AppendFooter(&html);
return html;
}
} // namespace
// AboutUIHTMLSource ----------------------------------------------------------
AboutUIHTMLSource::AboutUIHTMLSource(const std::string& source_name)
: source_name_(source_name) {}
AboutUIHTMLSource::~AboutUIHTMLSource() {}
std::string AboutUIHTMLSource::GetSource() const {
return source_name_;
}
void AboutUIHTMLSource::StartDataRequest(
const std::string& path,
const web::URLDataSourceIOS::GotDataCallback& callback) {
std::string response;
// Add your data source here, in alphabetical order.
if (source_name_ == kChromeUIChromeURLsHost) {
response = ChromeURLs();
} else if (source_name_ == kChromeUICreditsHost) {
int idr = IDR_ABOUT_UI_CREDITS_HTML;
if (path == kCreditsJsPath)
idr = IDR_ABOUT_UI_CREDITS_JS;
response =
ResourceBundle::GetSharedInstance().GetRawDataResource(idr).as_string();
} else if (source_name_ == kChromeUIHistogramHost) {
// Note: On other platforms, this is implemented in //content. If there is
// ever a need for embedders other than //ios/chrome to use
// chrome://histograms, this code could likely be moved to //io/web.
base::StatisticsRecorder::WriteHTMLGraph("", &response);
}
FinishDataRequest(response, callback);
}
void AboutUIHTMLSource::FinishDataRequest(
const std::string& html,
const web::URLDataSourceIOS::GotDataCallback& callback) {
std::string html_copy(html);
callback.Run(base::RefCountedString::TakeString(&html_copy));
}
std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const {
if (path == kCreditsJsPath || path == kStringsJsPath) {
return "application/javascript";
}
return "text/html";
}
bool AboutUIHTMLSource::ShouldDenyXFrameOptions() const {
return web::URLDataSourceIOS::ShouldDenyXFrameOptions();
}
AboutUI::AboutUI(web::WebUIIOS* web_ui, const std::string& name)
: web::WebUIIOSController(web_ui) {
web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
new AboutUIHTMLSource(name));
}
AboutUI::~AboutUI() {}
|