-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0001-net-add-trk-scheme-and-help-identify-URLs-being-retr.patch
612 lines (576 loc) · 21.7 KB
/
0001-net-add-trk-scheme-and-help-identify-URLs-being-retr.patch
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
From ccb2369f3a53d2a5066e3a1ecec9d5aa42371fc7 Mon Sep 17 00:00:00 2001
From: Jan Engelhardt <[email protected]>
Date: Wed, 20 May 2015 01:34:50 +0200
Subject: [PATCH] net: add "trk:" scheme and help identify URLs being retrieved
The Chromium codebase has left us with a number of suspect URLs, and
we want to know if the browser attempts to contact those sites.
This patch introduces a new scheme, "trk:", which, when attempted to
being processed, will dump a warning onto the screen as the resource
is loaded. All URLs we think are suspect are "blacklisted" by
prepending the new scheme to an existing URL:
trk:1234:https://clients4.google.com/
trk:https://clients4.google.com/ (unnumbered old variant)
trk:0.1234:https://... (stderr only, no UI reporting)
Upon seeing a warning, we then know to investigate further, and either
(a) whitelist the URL, that is, remove the trk: prefix and not show
the warning, and/or (b) disable the particular feature which caused
the loading of the URL in the first place, by default.
Implementation:
We hack up the URLFetcher class which sits in the network stack, and
most of the URL that get loaded pass through here. The trk: prefix is
stripped and processing continues with the inner URL.
---
chrome/BUILD.gn | 2 +
chrome/app/chrome_main.cc | 20 ++++++++
.../chrome_autocomplete_scheme_classifier.cc | 1 +
chrome/browser/history/history_utils.cc | 1 +
chrome/browser/ui/browser_navigator.cc | 8 +++
chrome/browser/ui/singleton_tabs.cc | 3 +-
components/infobars/core/infobar_delegate.h | 1 +
components/omnibox/browser/autocomplete_input.cc | 8 +--
content/browser/browser_url_handler_impl.cc | 20 ++++++++
.../browser/child_process_security_policy_impl.cc | 1 +
iridium/BUILD.gn | 9 ++++
iridium/trkbar.cpp | 45 +++++++++++++++++
iridium/trkbar.h | 33 ++++++++++++
iridium/trknotify.cpp | 59 ++++++++++++++++++++++
iridium/trknotify.h | 20 ++++++++
net/url_request/url_request.cc | 8 ++-
net/url_request/url_request.h | 2 +
tools/metrics/histograms/enums.xml | 1 +
url/gurl.cc | 35 +++++++++++++
url/gurl.h | 5 ++
url/url_constants.cc | 1 +
url/url_constants.h | 1 +
22 files changed, 279 insertions(+), 5 deletions(-)
create mode 100644 iridium/BUILD.gn
create mode 100644 iridium/trkbar.cpp
create mode 100644 iridium/trkbar.h
create mode 100644 iridium/trknotify.cpp
create mode 100644 iridium/trknotify.h
diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn
index 960921acd7eb..b315ffcd32b4 100644
--- a/chrome/BUILD.gn
+++ b/chrome/BUILD.gn
@@ -246,6 +246,7 @@ if (!is_android && !is_mac) {
deps += [
# On Linux, link the dependencies (libraries) that make up actual
# Chromium functionality directly into the executable.
+ "//iridium:trknotify",
":browser_dependencies",
":child_dependencies",
@@ -495,6 +496,7 @@ if (is_win) {
"//content/public/app:child",
"//content/public/common:service_names",
"//headless:headless_shell_child_lib",
+ "//iridium:trknotify",
"//services/service_manager/embedder",
]
diff --git a/chrome/app/chrome_main.cc b/chrome/app/chrome_main.cc
index 5f43d02ae903..87a3522c1287 100644
--- a/chrome/app/chrome_main.cc
+++ b/chrome/app/chrome_main.cc
@@ -17,6 +17,10 @@
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_features.h"
#include "ui/gfx/switches.h"
+#if !defined(CHROME_MULTIPLE_DLL_CHILD)
+# include "net/url_request/url_request.h"
+# include "iridium/trknotify.h"
+#endif
#if BUILDFLAG(ENABLE_MUS)
#include "services/service_manager/runner/common/client_util.h"
@@ -49,6 +53,19 @@ int ChromeMain(int argc, const char** argv);
}
#endif
+#if !defined(CHROME_MULTIPLE_DLL_CHILD)
+static void trace_url_request(const std::string &caller, const GURL &url)
+{
+ iridium::log_url_request(caller, url);
+ if (url.scheme() != url::kTraceScheme)
+ /* Do not show infobar for non-trk URLs */
+ return;
+ if (url.is_trq())
+ return;
+ iridium::trace_url_request(caller, url);
+}
+#endif
+
#if defined(OS_WIN)
DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info,
@@ -126,6 +143,9 @@ int ChromeMain(int argc, const char** argv) {
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(ENABLE_MUS)
+#if !defined(CHROME_MULTIPLE_DLL_CHILD)
+ net::trace_urlreq_cb = &trace_url_request;
+#endif
int rv = content::ContentMain(params);
return rv;
diff --git a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
index e356d0f12753..8c54fbfc64c3 100644
--- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
+++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
@@ -25,6 +25,7 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme(
if (base::IsStringASCII(scheme) &&
(ProfileIOData::IsHandledProtocol(scheme) ||
base::LowerCaseEqualsASCII(scheme, content::kViewSourceScheme) ||
+ base::LowerCaseEqualsASCII(scheme, url::kTraceScheme) ||
base::LowerCaseEqualsASCII(scheme, url::kJavaScriptScheme) ||
base::LowerCaseEqualsASCII(scheme, url::kDataScheme))) {
return metrics::OmniboxInputType::URL;
diff --git a/chrome/browser/history/history_utils.cc b/chrome/browser/history/history_utils.cc
index 8bf6a91e67cd..57dd5e1fb5c0 100644
--- a/chrome/browser/history/history_utils.cc
+++ b/chrome/browser/history/history_utils.cc
@@ -21,6 +21,7 @@ bool CanAddURLToHistory(const GURL& url) {
url.SchemeIs(content::kChromeDevToolsScheme) ||
url.SchemeIs(content::kChromeUIScheme) ||
url.SchemeIs(content::kViewSourceScheme) ||
+ url.SchemeIs(url::kTraceScheme) ||
url.SchemeIs(chrome::kChromeNativeScheme) ||
url.SchemeIs(chrome::kChromeSearchScheme) ||
url.SchemeIs(dom_distiller::kDomDistillerScheme))
diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc
index 4f7de207a485..0f917abb9c72 100644
--- a/chrome/browser/ui/browser_navigator.cc
+++ b/chrome/browser/ui/browser_navigator.cc
@@ -695,6 +695,14 @@ bool IsURLAllowedInIncognito(const GURL& url,
return stripped_url.is_valid() &&
IsURLAllowedInIncognito(stripped_url, browser_context);
}
+
+ if (url.SchemeIs(url::kTraceScheme)) {
+ /* Same as view-source:, strip prefix and re-check. */
+ auto url2 = url.strip_trk();
+ return url2.is_valid() &&
+ IsURLAllowedInIncognito(url2, browser_context);
+ }
+
// Most URLs are allowed in incognito; the following are exceptions.
// chrome://extensions is on the list because it redirects to
// chrome://settings.
diff --git a/chrome/browser/ui/singleton_tabs.cc b/chrome/browser/ui/singleton_tabs.cc
index 6019fb0006a7..1594fcdcb0ec 100644
--- a/chrome/browser/ui/singleton_tabs.cc
+++ b/chrome/browser/ui/singleton_tabs.cc
@@ -101,7 +101,8 @@ int GetIndexOfExistingTab(Browser* browser, const NavigateParams& params) {
// Skip view-source tabs. This is needed because RewriteURLIfNecessary
// removes the "view-source:" scheme which leads to incorrect matching.
- if (tab_url.SchemeIs(content::kViewSourceScheme))
+ if (tab_url.SchemeIs(content::kViewSourceScheme) ||
+ tab_url.SchemeIs(url::kTraceScheme))
continue;
GURL rewritten_tab_url = tab_url;
diff --git a/components/infobars/core/infobar_delegate.h b/components/infobars/core/infobar_delegate.h
index 62860bb62419..a08b4239fc06 100644
--- a/components/infobars/core/infobar_delegate.h
+++ b/components/infobars/core/infobar_delegate.h
@@ -148,6 +148,7 @@ class InfoBarDelegate {
FRAMEBUST_BLOCK_INFOBAR_ANDROID = 77,
SURVEY_INFOBAR_ANDROID = 78,
NEAR_OOM_INFOBAR_ANDROID = 79,
+ TRACKING_ALERT_INFOBAR_DELEGATE = 9001
};
// Describes navigation events, used to decide whether infobars should be
diff --git a/components/omnibox/browser/autocomplete_input.cc b/components/omnibox/browser/autocomplete_input.cc
index 75ab139eb734..790a79cc41b9 100644
--- a/components/omnibox/browser/autocomplete_input.cc
+++ b/components/omnibox/browser/autocomplete_input.cc
@@ -486,7 +486,8 @@ void AutocompleteInput::ParseForEmphasizeComponents(
int after_scheme_and_colon = parts.scheme.end() + 1;
// For the view-source scheme, we should emphasize the scheme and host of the
// URL qualified by the view-source prefix.
- if (base::LowerCaseEqualsASCII(scheme_str, kViewSourceScheme) &&
+ if ((base::LowerCaseEqualsASCII(scheme_str, kViewSourceScheme) ||
+ base::LowerCaseEqualsASCII(scheme_str, url::kTraceScheme)) &&
(static_cast<int>(text.length()) > after_scheme_and_colon)) {
// Obtain the URL prefixed by view-source and parse it.
base::string16 real_url(text.substr(after_scheme_and_colon));
@@ -555,9 +556,10 @@ int AutocompleteInput::NumNonHostComponents(const url::Parsed& parts) {
bool AutocompleteInput::HasHTTPScheme(const base::string16& input) {
std::string utf8_input(base::UTF16ToUTF8(input));
url::Component scheme;
- if (url::FindAndCompareScheme(utf8_input, kViewSourceScheme, &scheme)) {
+ if (url::FindAndCompareScheme(utf8_input, url::kTraceScheme, &scheme))
+ gurl_strip_trk(utf8_input);
+ else if (url::FindAndCompareScheme(utf8_input, kViewSourceScheme, &scheme))
utf8_input.erase(0, scheme.end() + 1);
- }
return url::FindAndCompareScheme(utf8_input, url::kHttpScheme, nullptr);
}
diff --git a/content/browser/browser_url_handler_impl.cc b/content/browser/browser_url_handler_impl.cc
index ef78ddd5e26b..8a1c8c900493 100644
--- a/content/browser/browser_url_handler_impl.cc
+++ b/content/browser/browser_url_handler_impl.cc
@@ -14,9 +14,28 @@
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "url/gurl.h"
+#include "net/url_request/url_request.h"
namespace content {
+static bool handle_trace_scheme(GURL *url, BrowserContext *)
+{
+ if (!url->SchemeIs(url::kTraceScheme))
+ return false;
+ if (net::trace_urlreq_cb != NULL)
+ (*net::trace_urlreq_cb)("handle_trace_scheme", *url);
+ *url = url->strip_trk();
+ return false;
+}
+
+static bool trace_scheme_revlookup(GURL *url, BrowserContext *)
+{
+ if (url->SchemeIs(url::kTraceScheme))
+ return false;
+ *url = GURL(url::kTraceScheme + (":" + url->spec()));
+ return true;
+}
+
// Handles rewriting view-source URLs for what we'll actually load.
static bool HandleViewSource(GURL* url, BrowserContext* browser_context) {
if (url->SchemeIs(kViewSourceScheme)) {
@@ -100,6 +119,7 @@ BrowserURLHandlerImpl::BrowserURLHandlerImpl() :
AddHandlerPair(&HandleViewSource, &ReverseViewSource);
GetContentClient()->browser()->BrowserURLHandlerCreated(this);
+ AddHandlerPair(&handle_trace_scheme, &trace_scheme_revlookup);
}
BrowserURLHandlerImpl::~BrowserURLHandlerImpl() {
diff --git a/content/browser/child_process_security_policy_impl.cc b/content/browser/child_process_security_policy_impl.cc
index 084675ab196b..8604d61ac803 100644
--- a/content/browser/child_process_security_policy_impl.cc
+++ b/content/browser/child_process_security_policy_impl.cc
@@ -350,6 +350,7 @@ ChildProcessSecurityPolicyImpl::ChildProcessSecurityPolicyImpl() {
RegisterPseudoScheme(kViewSourceScheme);
+ RegisterPseudoScheme(url::kTraceScheme);
}
ChildProcessSecurityPolicyImpl::~ChildProcessSecurityPolicyImpl() {
diff --git a/iridium/BUILD.gn b/iridium/BUILD.gn
new file mode 100644
index 000000000000..913b266e04df
--- /dev/null
+++ b/iridium/BUILD.gn
@@ -0,0 +1,9 @@
+config("trknotify_c") {
+ include_dirs = ["..", "../third_party/skia/include/config", "../third_party/skia/include/core"]
+}
+
+component("trknotify") {
+ sources = ["trkbar.cpp", "trkbar.h", "trknotify.cpp", "trknotify.h"]
+ public_configs = [":trknotify_c"]
+ deps = ["//chrome/browser/ui"]
+}
diff --git a/iridium/trkbar.cpp b/iridium/trkbar.cpp
new file mode 100644
index 000000000000..16013abaf19b
--- /dev/null
+++ b/iridium/trkbar.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015 The Iridium Authors
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "base/strings/utf_string_conversions.h"
+#include "components/infobars/core/infobar.h"
+#include "iridium/trkbar.h"
+
+namespace content {
+
+void TrkBar::Create(InfoBarService *s, const GURL &url)
+{
+ s->AddInfoBar(s->CreateConfirmInfoBar(
+ std::unique_ptr<ConfirmInfoBarDelegate>(new TrkBar(url))
+ ));
+}
+
+bool TrkBar::ShouldExpire(const NavigationDetails &) const
+{
+ return false;
+}
+
+TrkBar::TrkBar(const GURL &url) :
+ ConfirmInfoBarDelegate(), m_url(url)
+{
+}
+
+base::string16 TrkBar::GetMessageText(void) const
+{
+ return base::ASCIIToUTF16("Loading traced URL: " + m_url.spec());
+}
+
+int TrkBar::GetButtons(void) const
+{
+ return BUTTON_NONE;
+}
+
+infobars::InfoBarDelegate::InfoBarIdentifier TrkBar::GetIdentifier(void) const
+{
+ return TRACKING_ALERT_INFOBAR_DELEGATE;
+}
+
+}; /* namespace content */
diff --git a/iridium/trkbar.h b/iridium/trkbar.h
new file mode 100644
index 000000000000..b251feca039b
--- /dev/null
+++ b/iridium/trkbar.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2015 The Iridium Authors.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef IRIDIUM_TRKBAR_H
+#define IRIDIUM_TRKBAR_H 1
+
+#include "chrome/browser/infobars/infobar_service.h"
+#include "components/infobars/core/confirm_infobar_delegate.h"
+#include "url/gurl.h"
+
+namespace content {
+
+class TrkBar : public ConfirmInfoBarDelegate {
+ public:
+ static void Create(InfoBarService *, const GURL &);
+ bool ShouldExpire(const NavigationDetails &) const override;
+
+ private:
+ TrkBar(const GURL &);
+ base::string16 GetMessageText(void) const override;
+ int GetButtons(void) const override;
+ infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier(void) const override;
+
+ GURL m_url;
+ DISALLOW_COPY_AND_ASSIGN(TrkBar);
+};
+
+}; /* namespace content */
+
+#endif /* IRIDIUM_TRKBAR_H */
diff --git a/iridium/trknotify.cpp b/iridium/trknotify.cpp
new file mode 100644
index 000000000000..f01fd02b013d
--- /dev/null
+++ b/iridium/trknotify.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2015 The Iridium Authors.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <cstdio>
+#ifdef __linux__
+# include <unistd.h>
+#endif
+#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "content/public/browser/browser_thread.h"
+#include "url/url_constants.h"
+#include "iridium/trkbar.h"
+#include "iridium/trknotify.h"
+
+namespace iridium {
+
+void log_url_request(const std::string &caller, const GURL &url)
+{
+#ifdef __linux__
+ bool tty = isatty(fileno(stderr));
+#else
+ bool tty = false;
+#endif
+ const char *xred = tty ? "\033[1;37;41m" : ""; // ]
+ const char *xfruit = tty ? "\033[33m" : ""; // ]
+ const char *xdark = tty ? "\033[1;30m" : ""; // ]
+ const char *xreset = tty ? "\033[0m" : ""; // ]
+
+ if (url.scheme() == url::kTraceScheme)
+ fprintf(stderr, "%s*** %s(%s)%s\n", xred, caller.c_str(),
+ url.possibly_invalid_spec().c_str(), xreset);
+ else
+ fprintf(stderr, "%s***%s %s(%s)%s\n", xfruit, xdark,
+ caller.c_str(), url.possibly_invalid_spec().c_str(),
+ xreset);
+}
+
+static void __trace_url_request(const std::string &caller, const GURL &url)
+{
+ auto browser = chrome::FindLastActive();
+ if (browser == NULL)
+ return;
+
+ auto service = InfoBarService::FromWebContents(browser->tab_strip_model()->GetActiveWebContents());
+ content::TrkBar::Create(service, url);
+}
+
+void trace_url_request(const std::string &caller, const GURL &url)
+{
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&__trace_url_request, caller, url));
+}
+
+}; /* namespace iridium */
diff --git a/iridium/trknotify.h b/iridium/trknotify.h
new file mode 100644
index 000000000000..3c58d22a4426
--- /dev/null
+++ b/iridium/trknotify.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 The Iridium Authors.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef IRIDIUM_TRKNOTIFY_H
+#define IRIDIUM_TRKNOTIFY_H 1
+
+#include <string>
+#include "url/gurl.h"
+
+namespace iridium {
+
+extern void log_url_request(const std::string &, const GURL &);
+extern void trace_url_request(const std::string &, const GURL &);
+
+}; /* namespace iridium */
+
+#endif /* IRIDIUM_TRKNOTIFY_H */
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 8cef4d5f0d17..8eb15f83b90f 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -53,6 +53,8 @@ using std::string;
namespace net {
+void (*trace_urlreq_cb)(const std::string &, const GURL &);
+
namespace {
// TODO(battre): Delete this, see http://crbug.com/89321:
@@ -581,7 +583,11 @@ URLRequest::URLRequest(const GURL& url,
// Sanity check out environment.
DCHECK(base::ThreadTaskRunnerHandle::IsSet());
- context->url_requests()->insert(this);
+ if (trace_urlreq_cb != NULL)
+ (*trace_urlreq_cb)("URLRequest", url);
+ if (url.scheme() == url::kTraceScheme)
+ url_chain_[0] = url.strip_trk();
+ context->url_requests()->insert(this);
net_log_.BeginEvent(
NetLogEventType::REQUEST_ALIVE,
base::Bind(&NetLogURLRequestConstructorCallback, &url, priority_));
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index 60fbf78c7886..83ac536e5e97 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -913,6 +913,8 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
DISALLOW_COPY_AND_ASSIGN(URLRequest);
};
+extern void NET_EXPORT (*trace_urlreq_cb)(const std::string &, const GURL &);
+
} // namespace net
#endif // NET_URL_REQUEST_URL_REQUEST_H_
diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml
index 3add8215b57f..a69c1f943615 100644
--- a/tools/metrics/histograms/enums.xml
+++ b/tools/metrics/histograms/enums.xml
@@ -22509,6 +22509,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="77" label="FRAMEBUST_BLOCK_INFOBAR_ANDROID"/>
<int value="78" label="SURVEY_INFOBAR_ANDROID"/>
<int value="79" label="NEAR_OOM_INFOBAR_ANDROID"/>
+ <int value="9001" label="TRACKING_ALERT_INFOBAR_DELEGATE"/>
</enum>
<enum name="InfoBarResponse">
diff --git a/url/gurl.cc b/url/gurl.cc
index cec69c7cc494..c100164d7d52 100644
--- a/url/gurl.cc
+++ b/url/gurl.cc
@@ -470,6 +470,41 @@ size_t GURL::EstimateMemoryUsage() const {
(parsed_.inner_parsed() ? sizeof(url::Parsed) : 0);
}
+std::string &gurl_strip_trk(std::string &s)
+{
+ auto slen = strlen(url::kTraceScheme);
+ if (!isdigit(s[slen+1]))
+ /* trk:https://... */
+ return s.erase(0, slen);
+ /* trk:123:https://... (or so we hope) */
+ auto pos = s.find(':', slen + 1);
+ if (pos == std::string::npos)
+ return s.erase(0, slen);
+ return s.erase(0, pos + 1);
+}
+
+bool gurl_is_trq(const std::string &s)
+{
+ auto slen = strlen(url::kTraceScheme);
+ /* trk:0.nnn:http:// makes for a quiet one */
+ return s[slen+1] == '0' && s[slen+2] == '.';
+}
+
+GURL GURL::strip_trk(void) const
+{
+ if (!SchemeIs(url::kTraceScheme))
+ return *this;
+ auto s = spec();
+ return GURL(gurl_strip_trk(s));
+}
+
+bool GURL::is_trq(void) const
+{
+ if (!SchemeIs(url::kTraceScheme))
+ return false;
+ return gurl_is_trq(spec());
+}
+
std::ostream& operator<<(std::ostream& out, const GURL& url) {
return out << url.possibly_invalid_spec();
}
diff --git a/url/gurl.h b/url/gurl.h
index 7a28bb9cce65..7cec8737f159 100644
--- a/url/gurl.h
+++ b/url/gurl.h
@@ -432,6 +432,9 @@ class URL_EXPORT GURL {
// See base/trace_event/memory_usage_estimator.h for more info.
size_t EstimateMemoryUsage() const;
+ GURL strip_trk(void) const;
+ bool is_trq(void) const;
+
private:
// Variant of the string parsing constructor that allows the caller to elect
// retain trailing whitespace, if any, on the passed URL spec, but only if
@@ -476,6 +479,8 @@ 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);
+URL_EXPORT std::string &gurl_strip_trk(std::string &);
+URL_EXPORT bool gurl_is_trq(const std::string &);
URL_EXPORT bool operator==(const GURL& x, const GURL& y);
URL_EXPORT bool operator!=(const GURL& x, const GURL& y);
diff --git a/url/url_constants.cc b/url/url_constants.cc
index 37fc82c1c450..4c02cf465930 100644
--- a/url/url_constants.cc
+++ b/url/url_constants.cc
@@ -24,6 +24,7 @@ const char kHttpScheme[] = "http";
const char kHttpsScheme[] = "https";
const char kJavaScriptScheme[] = "javascript";
const char kMailToScheme[] = "mailto";
+const char kTraceScheme[] = "trk";
const char kWsScheme[] = "ws";
const char kWssScheme[] = "wss";
diff --git a/url/url_constants.h b/url/url_constants.h
index 7e5cb53face9..c5bd1990d014 100644
--- a/url/url_constants.h
+++ b/url/url_constants.h
@@ -30,6 +30,7 @@ URL_EXPORT extern const char kHttpScheme[];
URL_EXPORT extern const char kHttpsScheme[];
URL_EXPORT extern const char kJavaScriptScheme[];
URL_EXPORT extern const char kMailToScheme[];
+URL_EXPORT extern const char kTraceScheme[];
URL_EXPORT extern const char kWsScheme[];
URL_EXPORT extern const char kWssScheme[];
--
2.14.3