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: Simplify Safari version parsing logic Created July 13, 2018, 6:57 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
« no previous file with comments | « 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..4f34456004e75edea40b67ccc53434dc978c325f 100644
--- a/safari/ext/content.js
+++ b/safari/ext/content.js
@@ -25,23 +25,32 @@
/* Intialization */
- var beforeLoadEvent = document.createEvent("Event");
- beforeLoadEvent.initEvent("beforeload", false, true);
+ var majorApplicationVersion = parseInt(navigator.userAgent.match(/Version\/([\d]+)/)[1]);
- // 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 +72,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 +193,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
+ }
+ );
+ }
}
};
« no previous file with comments | « safari/contentBlocking.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld