Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: safari/ext/content.js

Issue 29829615: Issue 6786 - Switch Safari 12+ users to content blocking API (Closed)
Patch Set: Created July 13, 2018, 6:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« options.js ('K') | « safari/contentBlocking.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/ext/content.js
diff --git a/safari/ext/content.js b/safari/ext/content.js
index 25d64b006a20a69e14c8e2f9db5d4686ca8970d8..13992e1f5e4a46574aed4c4c967e9df25fd5fd04 100644
--- a/safari/ext/content.js
+++ b/safari/ext/content.js
@@ -25,23 +25,33 @@
/* Intialization */
- var beforeLoadEvent = document.createEvent("Event");
- beforeLoadEvent.initEvent("beforeload", false, true);
+ var applicatonVersion = navigator.userAgent.match(/Version\/([\d.]+)/)[1];
+ var majorApplicationVersion = parseInt(applicatonVersion.split(".")[0], 10);
- // Decide if we should use the new content blocker API or not. (Note when the
- // API is used Safari breaks the canLoad function, making it either throw an
- // exception or return true when used.)
+ var beforeLoadEvent;
var usingContentBlockerAPI = true;
- try
- {
- if (safari.self.tab.canLoad(beforeLoadEvent,
- {category: "request",
- payload: {type: "prefs.get",
- key: "safariContentBlocker"}}) != true)
- usingContentBlockerAPI = false;
- }
- catch (e)
+
+ // Safari 12 automatically disables extensions which use the old canLoad API,
+ // so avoid using the old APIs on Safari 12!
+ if (majorApplicationVersion < 12)
{
+ beforeLoadEvent = document.createEvent("Event");
+ beforeLoadEvent.initEvent("beforeload", false, true);
+
+ // Decide if we should use the new content blocker API or not. (Note when the
+ // API is used Safari breaks the canLoad function, making it either throw an
+ // exception or return true when used.)
+ try
+ {
+ if (safari.self.tab.canLoad(beforeLoadEvent,
+ {category: "request",
+ payload: {type: "prefs.get",
+ key: "safariContentBlocker"}}) != true)
+ usingContentBlockerAPI = false;
+ }
+ catch (e)
+ {
+ }
}
var isTopLevel;
@@ -63,7 +73,8 @@
isTopLevel: isTopLevel,
isPrerendered: isPrerendered,
documentId: documentId,
- legacyAPISupported: "canLoad" in safari.self.tab &&
+ legacyAPISupported: majorApplicationVersion < 12 &&
+ "canLoad" in safari.self.tab &&
"onbeforeload" in Element.prototype
});
}
@@ -183,14 +194,17 @@
},
sendMessageSync: function(message)
{
- return safari.self.tab.canLoad(
- beforeLoadEvent,
- {
- category: "request",
- documentId: documentId,
- payload: message
- }
- );
+ if (majorApplicationVersion < 12)
+ {
+ return safari.self.tab.canLoad(
+ beforeLoadEvent,
+ {
+ category: "request",
+ documentId: documentId,
+ payload: message
+ }
+ );
+ }
}
};
« options.js ('K') | « safari/contentBlocking.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld