Skip to content

Commit 745e462

Browse files
Add dig:// protocol support with welcome page
1 parent 9ae9b4f commit 745e462

File tree

2 files changed

+232
-0
lines changed

2 files changed

+232
-0
lines changed

patches/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ ungoogled-chromium/windows/windows-fix-licenses-gn-path.patch
2121
ungoogled-chromium/windows/windows-fix-building-with-rust.patch
2222
ungoogled-chromium/windows/windows-fix-remove-unused-preferences-fields.patch
2323
ungoogled-chromium/windows/windows-fix-missing-includes.patch
24+
ungoogled-chromium/windows/windows-add-dig-protocol.patch
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# Add support for dig:// protocol with welcome page
2+
# This patch adds a custom protocol handler for dig:// URLs that displays a welcome page
3+
4+
--- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
5+
+++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc
6+
@@ -72,6 +72,7 @@ ChromeAutocompleteSchemeClassifier::GetI
7+
if (base::IsStringASCII(scheme) &&
8+
(ProfileIOData::IsHandledProtocol(scheme) ||
9+
base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) ||
10+
+ base::EqualsCaseInsensitiveASCII(scheme, url::kDigScheme) ||
11+
base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) ||
12+
base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme))) {
13+
return metrics::OmniboxInputType::URL;
14+
--- a/chrome/browser/history/history_utils.cc
15+
+++ b/chrome/browser/history/history_utils.cc
16+
@@ -22,6 +22,7 @@ bool CanAddURLToHistory(const GURL& url)
17+
url.SchemeIs(content::kChromeUIScheme) ||
18+
url.SchemeIs(content::kChromeUIUntrustedScheme) ||
19+
url.SchemeIs(content::kViewSourceScheme) ||
20+
+ url.SchemeIs(url::kDigScheme) ||
21+
url.SchemeIs(chrome::kChromeNativeScheme) ||
22+
url.SchemeIs(chrome::kChromeSearchScheme) ||
23+
url.SchemeIs(dom_distiller::kDomDistillerScheme))
24+
--- a/chrome/browser/ui/singleton_tabs.cc
25+
+++ b/chrome/browser/ui/singleton_tabs.cc
26+
@@ -132,7 +132,8 @@ int GetIndexOfExistingTab(Browser* brows
27+
// RewriteURLIfNecessary removes the "view-source:" scheme which could lead
28+
// to incorrect matching, so ensure that the target and the candidate are
29+
// either both view-source:, or neither is.
30+
- if (tab_url.SchemeIs(content::kViewSourceScheme) != target_is_view_source) {
31+
+ if (tab_url.SchemeIs(content::kViewSourceScheme) != target_is_view_source ||
32+
+ tab_url.SchemeIs(url::kDigScheme)) {
33+
continue;
34+
}
35+
36+
--- a/components/omnibox/browser/autocomplete_input.cc
37+
+++ b/components/omnibox/browser/autocomplete_input.cc
38+
@@ -578,7 +578,8 @@ void AutocompleteInput::ParseForEmphasiz
39+
// For the view-source and blob schemes, we should emphasize the host of the
40+
// URL qualified by the view-source or blob prefix.
41+
if ((base::EqualsCaseInsensitiveASCII(scheme_str, kViewSourceScheme) ||
42+
- base::EqualsCaseInsensitiveASCII(scheme_str, url::kBlobScheme)) &&
43+
+ base::EqualsCaseInsensitiveASCII(scheme_str, url::kBlobScheme) ||
44+
+ base::EqualsCaseInsensitiveASCII(scheme_str, url::kDigScheme)) &&
45+
(static_cast<int>(text.length()) > after_scheme_and_colon)) {
46+
// Obtain the URL prefixed by view-source or blob and parse it.
47+
std::u16string real_url(text.substr(after_scheme_and_colon));
48+
--- a/components/url_formatter/url_fixer.cc
49+
+++ b/components/url_formatter/url_fixer.cc
50+
@@ -602,6 +602,10 @@ GURL FixupURLInternal(const std::string&
51+
}
52+
}
53+
54+
+ if (scheme == url::kDigScheme) {
55+
+ return GURL(text);
56+
+ }
57+
+
58+
// We handle the file scheme separately.
59+
if (scheme == url::kFileScheme) {
60+
return GURL(parts.scheme.is_valid() ? text : FixupPath(text));
61+
--- a/content/browser/child_process_security_policy_impl.cc
62+
+++ b/content/browser/child_process_security_policy_impl.cc
63+
@@ -938,6 +938,7 @@ ChildProcessSecurityPolicyImpl::ChildPro
64+
RegisterWebSafeScheme(url::kWssScheme);
65+
#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
66+
RegisterWebSafeScheme(url::kDataScheme);
67+
+ RegisterWebSafeScheme(url::kDigScheme);
68+
69+
// TODO(nick): https://crbug.com/651534 blob: and filesystem: schemes embed
70+
// other origins, so we should not treat them as web safe. Remove callers of
71+
--- a/net/BUILD.gn
72+
+++ b/net/BUILD.gn
73+
@@ -1108,6 +1108,8 @@ component("net") {
74+
"url_request/static_http_user_agent_settings.cc",
75+
"url_request/static_http_user_agent_settings.h",
76+
"url_request/storage_access_status_cache.h",
77+
+ "url_request/dig_protocol_handler.cc",
78+
+ "url_request/dig_protocol_handler.h",
79+
"url_request/url_request.cc",
80+
"url_request/url_request.h",
81+
"url_request/url_request_context.cc",
82+
--- /dev/null
83+
+++ b/net/url_request/dig_protocol_handler.cc
84+
@@ -0,0 +1,53 @@
85+
+// Copyright (c) 2024 The ungoogled-chromium Authors. All rights reserved.
86+
+// Use of this source code is governed by a BSD-style license that can be
87+
+// found in the LICENSE file.
88+
+
89+
+#include "net/url_request/dig_protocol_handler.h"
90+
+
91+
+#include "base/logging.h"
92+
+#include "base/strings/string_piece.h"
93+
+#include "net/base/net_errors.h"
94+
+#include "net/url_request/url_request_simple_job.h"
95+
+
96+
+namespace net {
97+
+
98+
+namespace {
99+
+
100+
+class DigProtocolJob : public URLRequestSimpleJob {
101+
+ public:
102+
+ DigProtocolJob(URLRequest* request) : URLRequestSimpleJob(request) {}
103+
+
104+
+ DigProtocolJob(const DigProtocolJob&) = delete;
105+
+ DigProtocolJob& operator=(const DigProtocolJob&) = delete;
106+
+
107+
+ int GetData(std::string* mime_type,
108+
+ std::string* charset,
109+
+ std::string* data,
110+
+ CompletionOnceCallback callback) const override {
111+
+ *mime_type = "text/html";
112+
+ *charset = "utf-8";
113+
+ *data = R"(
114+
+<!DOCTYPE html>
115+
+<html>
116+
+<head>
117+
+ <title>Welcome to the DIG Network</title>
118+
+ <meta charset="utf-8">
119+
+ <style>
120+
+ body { font-family: Arial, sans-serif; text-align: center; margin: 50px; }
121+
+ h1 { color: #2e7d32; font-size: 3em; }
122+
+ p { font-size: 1.2em; color: #555; }
123+
+ </style>
124+
+</head>
125+
+<body>
126+
+ <h1>Welcome to the DIG Network</h1>
127+
+ <p>You have successfully accessed a dig:// URL!</p>
128+
+ <p>This is a custom protocol handler for the DIG Network.</p>
129+
+</body>
130+
+</html>
131+
+)";
132+
+ return OK;
133+
+ }
134+
+};
135+
+
136+
+} // namespace
137+
+
138+
+DigProtocolHandler::DigProtocolHandler() = default;
139+
+
140+
+std::unique_ptr<URLRequestJob> DigProtocolHandler::CreateJob(
141+
+ URLRequest* request) const {
142+
+ return std::make_unique<DigProtocolJob>(request);
143+
+}
144+
+
145+
+bool DigProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
146+
+ return true;
147+
+}
148+
+
149+
+} // namespace net
150+
--- /dev/null
151+
+++ b/net/url_request/dig_protocol_handler.h
152+
@@ -0,0 +1,30 @@
153+
+// Copyright (c) 2024 The ungoogled-chromium Authors. All rights reserved.
154+
+// Use of this source code is governed by a BSD-style license that can be
155+
+// found in the LICENSE file.
156+
+
157+
+#ifndef NET_URL_REQUEST_DIG_PROTOCOL_HANDLER_H_
158+
+#define NET_URL_REQUEST_DIG_PROTOCOL_HANDLER_H_
159+
+
160+
+#include "base/compiler_specific.h"
161+
+#include "net/base/net_export.h"
162+
+#include "net/url_request/url_request_job_factory.h"
163+
+
164+
+namespace net {
165+
+
166+
+class URLRequestJob;
167+
+
168+
+// Implements a ProtocolHandler for DIG Network URLs.
169+
+class NET_EXPORT DigProtocolHandler
170+
+ : public URLRequestJobFactory::ProtocolHandler {
171+
+ public:
172+
+ DigProtocolHandler();
173+
+ DigProtocolHandler(const DigProtocolHandler&) = delete;
174+
+ DigProtocolHandler& operator=(const DigProtocolHandler&) = delete;
175+
+ std::unique_ptr<URLRequestJob> CreateJob(
176+
+ URLRequest* request) const override;
177+
+ bool IsSafeRedirectTarget(const GURL& location) const override;
178+
+};
179+
+
180+
+} // namespace net
181+
+
182+
+#endif // NET_URL_REQUEST_DIG_PROTOCOL_HANDLER_H_
183+
--- a/net/url_request/url_request_context_builder.cc
184+
+++ b/net/url_request/url_request_context_builder.cc
185+
@@ -53,6 +53,7 @@
186+
#include "net/socket/network_binding_client_socket_factory.h"
187+
#include "net/ssl/ssl_config_service_defaults.h"
188+
#include "net/url_request/static_http_user_agent_settings.h"
189+
+#include "net/url_request/dig_protocol_handler.h"
190+
#include "net/url_request/url_request_context.h"
191+
#include "net/url_request/url_request_job_factory.h"
192+
#include "url/url_constants.h"
193+
@@ -612,6 +613,9 @@ std::unique_ptr<URLRequestContext> URLRe
194+
}
195+
protocol_handlers_.clear();
196+
197+
+ job_factory->SetProtocolHandler(url::kDigScheme,
198+
+ std::make_unique<DigProtocolHandler>());
199+
+
200+
context->set_job_factory(std::move(job_factory));
201+
202+
if (cookie_deprecation_label_.has_value()) {
203+
--- a/url/url_constants.h
204+
+++ b/url/url_constants.h
205+
@@ -50,6 +50,8 @@ inline constexpr char kMaterializedViewS
206+
inline constexpr char kSteamScheme[] = "steam";
207+
inline constexpr char kTelScheme[] = "tel";
208+
inline constexpr char16_t kTelScheme16[] = u"tel";
209+
+inline constexpr char kDigScheme[] = "dig";
210+
+inline constexpr char16_t kDigScheme16[] = u"dig";
211+
inline constexpr char kUrnScheme[] = "urn";
212+
inline constexpr char16_t kUrnScheme16[] = u"urn";
213+
inline constexpr char kUuidInPackageScheme[] = "uuid-in-package";
214+
--- a/url/url_util.cc
215+
+++ b/url/url_util.cc
216+
@@ -85,6 +85,7 @@ struct SchemeRegistry {
217+
kWssScheme,
218+
kDataScheme,
219+
kAboutScheme,
220+
+ kDigScheme,
221+
};
222+
223+
// Schemes that normal pages cannot link to or access (i.e., with the same
224+
@@ -99,6 +100,7 @@ struct SchemeRegistry {
225+
kAboutScheme,
226+
kJavaScriptScheme,
227+
kDataScheme,
228+
+ kDigScheme,
229+
};
230+
231+
// Schemes that can be sent CORS requests.

0 commit comments

Comments
 (0)