Browse Source

Latest version of click-tracking-removal patch

csagan5 7 năm trước cách đây
mục cha
commit
11994a352c

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 65
patches/privacy/dont-track-me.patch


+ 59 - 48
patches/privacy/remove-google-click-tracking.patch

@@ -1,57 +1,68 @@
-commit 8d0b67d87462d537af6f7eb0cf445a2f66d5dd5c
+commit 9032b89c5a4c28d43c5a13f8bc151c71acad874b
 Author: csagan5 <32685696+csagan5@users.noreply.github.com>
-Date:   Sun Oct 15 18:01:18 2017 +0200
+Date:   Sat Oct 28 10:09:41 2017 +0200
 
-    Remove click tracking from google search results
+    Do not track google search results clicks
 
-diff --git a/third_party/WebKit/Source/core/dom/ContainerNode.cpp b/third_party/WebKit/Source/core/dom/ContainerNode.cpp
-index 1bada98..fb15e01 100644
---- a/third_party/WebKit/Source/core/dom/ContainerNode.cpp
-+++ b/third_party/WebKit/Source/core/dom/ContainerNode.cpp
-@@ -58,6 +58,8 @@
- #include "platform/bindings/RuntimeCallStats.h"
- #include "platform/bindings/V8PerIsolateData.h"
+diff --git a/third_party/WebKit/Source/core/dom/BUILD.gn b/third_party/WebKit/Source/core/dom/BUILD.gn
+index 93f080f..2df8d30 100644
+--- a/third_party/WebKit/Source/core/dom/BUILD.gn
++++ b/third_party/WebKit/Source/core/dom/BUILD.gn
+@@ -344,6 +344,7 @@ blink_core_sources("dom") {
+     "events/TreeScopeEventContext.h",
+     "events/WindowEventContext.cpp",
+     "events/WindowEventContext.h",
++    "extensions/dont-track-me.h",
+     "trustedtypes/TrustedHTML.cpp",
+     "trustedtypes/TrustedHTML.h",
+     "trustedtypes/TrustedScriptURL.cpp",
+diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
+index b7c5748..4978c84 100644
+--- a/third_party/WebKit/Source/core/dom/Document.cpp
++++ b/third_party/WebKit/Source/core/dom/Document.cpp
+@@ -218,6 +218,7 @@
+ #include "core/xml/parser/XMLDocumentParser.h"
+ #include "core/xml_names.h"
+ #include "core/xmlns_names.h"
++#include "extensions/dont-track-me.h"
+ #include "platform/CrossThreadFunctional.h"
+ #include "platform/DateComponents.h"
+ #include "platform/EventDispatchForbiddenScope.h"
+@@ -5825,8 +5826,24 @@ void Document::FinishedParsing() {
+     fetcher_->ClearResourcesFromPreviousFetcher();
+   }
  
-+#include "base/logging.h"
-+
- namespace blink {
- 
- using namespace HTMLNames;
-@@ -1391,6 +1393,26 @@ StaticElementList* ContainerNode::QuerySelectorAll(
-   return QuerySelectorAll(selectors, ASSERT_NO_EXCEPTION);
- }
- 
-+// this logic here will cleanup click tracking from hyperlink nodes on search results
-+static void applyInsertCustomization(Document *document, Node *c) {
-+  if (c->getNodeType() != Node::kElementNode)
-+	return;
-+  Element *element = ToElement(c);
-+
-+  // filter out non-hyperlink nodes
-+  if (element->tagName() != "A")
-+	return;
+-  if (IsPrefetchOnly())
++  if (IsPrefetchOnly()) {
+     WebPrerenderingSupport::Current()->PrefetchFinished();
++    return;
++  }
 +
 +  // determine whether this is a Google search results page
-+  WTF::String domain = document->GetSecurityOrigin()->Domain();
-+  size_t pos = domain.Find(".google.");
-+  if ((pos != WTF::kNotFound) && (domain.length() - pos - 8 < 4)) {
-+    //LOG(INFO) << "sanitizing Google search results hyperlink, href: " << element->getAttribute("href") << " onmousedown: " << element->getAttribute("onmousedown");
-+    // remove attribute
-+    element->removeAttribute("onmousedown");
++  SecurityOrigin *origin = GetSecurityOrigin();
++  if (origin) {
++    WTF::String domain = origin->Domain();
++    size_t pos = domain.Find(".google.");
++    auto* bodyElement = body();
++    if (bodyElement && (pos != WTF::kNotFound) && (domain.length() - pos - 8 < 4)) {
++      LOG(INFO) << "BRM: injecting dont-track-me Javascript payload";
++      HTMLScriptElement* e = HTMLScriptElement::Create(*this, false);
++      e->setText(DONT_TRACK_ME_JS);
++      bodyElement->AppendChild(e);
++    }
 +  }
-+}
-+
- static void DispatchChildInsertionEvents(Node& child) {
-   if (child.IsInShadowTree())
-     return;
-@@ -1402,6 +1424,10 @@ static void DispatchChildInsertionEvents(Node& child) {
-   Node* c = &child;
-   Document* document = &child.GetDocument();
+ }
  
-+  // csagan5: no extension support in Chrom* for Android? no problem! we add custom code directly here
-+  if (c->parentNode())
-+      applyInsertCustomization(document, c);
+ void Document::ElementDataCacheClearTimerFired(TimerBase*) {
+diff --git a/third_party/WebKit/Source/core/dom/extensions/dont-track-me.h b/third_party/WebKit/Source/core/dom/extensions/dont-track-me.h
+new file mode 100644
+index 0000000..57a7670
+--- /dev/null
++++ b/third_party/WebKit/Source/core/dom/extensions/dont-track-me.h
+@@ -0,0 +1,6 @@
++#ifndef dont_track_me_h
++#define dont_track_me_h
++
++#define DONT_TRACK_ME_JS "/* click-tracking removal - from https://github.com/Rob--W/dont-track-me-google */\n\nfunction sanitizeHyperlink(a) {\n    var inlineMousedown = a.getAttribute('onmousedown');\n    // return rwt(....); // E.g Google search results.\n    // return google.rwt(...); // E.g. sponsored search results\n    // return google.arwt(this); // E.g. sponsored search results (dec 2016).\n    if (inlineMousedown && /\\ba?rwt\\(/.test(inlineMousedown)) {\n        a.removeAttribute('onmousedown');\n    }\n    var realLink = getRealLinkFromGoogleUrl(a);\n    if (realLink) {\n        a.href = realLink;\n    }\n    a.referrerPolicy = 'origin';\n\n    var ping = a.getAttribute('ping');\n    if (ping && /\\/url\\?/.test(ping)) {\n        a.removeAttribute('oncontextmenu');\n        a.removeAttribute('ping');\n    }\n}\n\n/**\n * @returns {String} the real URL if the given link is a Google redirect URL.\n */\nfunction getRealLinkFromGoogleUrl(a) {\n    if ((a.hostname === location.hostname || a.hostname === 'www.google.com') &&\n        /^\\/(local_)?url$/.test(a.pathname)) {\n        // Google Maps / Dito (/local_url?q=<url>)\n        // Mobile (/url?q=<url>)\n        var url = /[?&](?:q|url)=((?:https?|ftp)[%:][^&]+)/.exec(a.search);\n        if (url) {\n            return decodeURIComponent(url[1]);\n        }\n        // Help pages, e.g. safe browsing (/url?...&q=%2Fsupport%2Fanswer...)\n        url = /[?&](?:q|url)=((?:%2[Ff]|\\/)[^&]+)/.exec(a.search);\n        if (url) {\n            return a.origin + decodeURIComponent(url[1]);\n        }\n    }\n}\n\nfunction sanitizeAllHyperlinks() {\n\t// scan all hyperlinks\n\tvar hyperlinks = document.getElementsByTagName('a');\n\tfor(var i = 0; i < hyperlinks.length; i++) {\n\t\tvar a = hyperlinks[i];\n\t\tif (a.href)\n\t\t\tsanitizeHyperlink(a);\n\t}\n}\n\nsanitizeAllHyperlinks();\n"
 +
-   if (c->parentNode() &&
-       document->HasListenerType(Document::kDOMNodeInsertedListener))
-     c->DispatchScopedEvent(MutationEvent::Create(
++#endif  // dont_track_me_h

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác