Skip to content

Commit

Permalink
Safari: important improvements to request capturing + fix twitch.tv
Browse files Browse the repository at this point in the history
twitch.tv now works out of the box in HTML5 in Safari. Make sure you
disable Flash if you don't get the HTML5 player.
  • Loading branch information
chrisaljoudi committed Feb 12, 2015
1 parent dc36bf5 commit d2cc20e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion assets/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
7edb2a585b445f28aa5ab06306f1a23f assets/ublock/privacy.txt
2818b73e0bcbea13800c9c006b2d521d assets/ublock/filters.txt
f8ef909c16003b6ef79a502998c83dee assets/ublock/filters.txt
dcf3e05bae803343c9d632f0baf8bedd assets/ublock/mirror-candidates.txt
48f4e02826d244a48d140cb5e4b81114 assets/ublock/filter-lists.json
132b3ecc9da8a68c3faf740c00af734b assets/thirdparties/adblock-plus-japanese-filter.googlecode.com/hg/abp_jp.txt
Expand Down
3 changes: 3 additions & 0 deletions assets/ublock/filters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,6 @@ deviantart.com##.dp-ad-chrome.dp-ad-visible
# https://github.com/gorhill/uBlock/issues/774
# To counter `carbonads.net` in Peter Lowe's
@@||carbonads.net^$~third-party

# This enables twitch.tv to work in HTML5
@@||imasdk.googleapis.com$domain=twitch.tv
16 changes: 11 additions & 5 deletions platform/safari/vapi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}
vAPI.vapiClientInjected = true;
vAPI.safari = true;

/******************************************************************************/
var messagingConnector = function(response) {
if(!response) {
Expand Down Expand Up @@ -74,6 +75,9 @@
requestId: 1,
connectorId: uniqueId(),
setup: function() {
if(typeof safari === "undefined") {
return;
}
this.connector = function(msg) {
// messages from the background script are sent to every frame,
// so we need to check the connectorId to accept only
Expand Down Expand Up @@ -107,6 +111,9 @@
channelName: channelName,
listener: typeof callback === 'function' ? callback : null,
send: function(message, callback) {
if(typeof safari === "undefined") {
return;
}
if(!vAPI.messaging.connector) {
vAPI.messaging.setup();
}
Expand Down Expand Up @@ -157,8 +164,7 @@
// Helper event to message background,
// and helper anchor element
var beforeLoadEvent = new Event("beforeload"),
linkHelper = document.createElement("a"),
isHttp_s = /^https?:/;
linkHelper = document.createElement("a");

// Inform that we've navigated
if(frameId === 0) {
Expand Down Expand Up @@ -186,10 +192,10 @@
return !(safari.self.tab.canLoad(beforeLoadEvent, details));
};
var onBeforeLoad = function(e) {
if(e.url.charCodeAt(0) !== 104 && !isHttp_s.test(e.url)) { // h = 104
linkHelper.href = e.url;
if(linkHelper.protocol.charCodeAt(0) !== 104) { // h = 104
return;
}
linkHelper.href = e.url;
var details = {
url: linkHelper.href,
type: nodeTypes[e.target.nodeName.toLowerCase()] || "other",
Expand All @@ -199,7 +205,7 @@
timeStamp: Date.now()
};
var response = safari.self.tab.canLoad(e, details);
if(!response) {
if(response === false) {
e.preventDefault();
}
};
Expand Down

0 comments on commit d2cc20e

Please sign in to comment.