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

Side by Side Diff: safari/include.youtube.js

Issue 5091158183116800: Issue 438 - Disable history API in Safari before YouTube's JavaScript runs (Closed)
Patch Set: Created May 7, 2014, 9 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (value != newValue) 54 if (value != newValue)
55 { 55 {
56 param.setAttribute("value", newValue); 56 param.setAttribute("value", newValue);
57 flashvarsChanged = true; 57 flashvarsChanged = true;
58 } 58 }
59 } 59 }
60 } 60 }
61 61
62 if (flashvarsChanged) 62 if (flashvarsChanged)
63 player.parentNode.replaceChild(newPlayer, player); 63 player.parentNode.replaceChild(newPlayer, player);
64
65 // if history.pushState is available, YouTube uses the history API
66 // when navigation from one video to another, and tells the flash
67 // player with JavaScript which video and which ads to show next,
68 // bypassing our flashvars rewrite code. So we disable
69 // history.pushState on pages with YouTube's flash player.
70 var script = document.createElement("script");
71 script.type = "application/javascript";
72 script.async = false;
73 script.textContent = "history.pushState = undefined;";
74 document.documentElement.appendChild(script);
75 document.documentElement.removeChild(script);
76 } 64 }
77 65
78 var deferred = []; 66 var deferred = [];
79 function patchPlayerDeferred(player) 67 function patchPlayerDeferred(player)
80 { 68 {
81 deferred.push(player); 69 deferred.push(player);
82 } 70 }
83 71
84 var onBeforeLoadYoutubeVideo = patchPlayerDeferred; 72 var onBeforeLoadYoutubeVideo = patchPlayerDeferred;
85 function onBeforeLoad(event) 73 function onBeforeLoad(event)
86 { 74 {
87 if ((event.target.localName == "object" || event.target.localName == "embed" ) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url)) 75 if ((event.target.localName == "object" || event.target.localName == "embed" ) && /:\/\/[^\/]*\.ytimg\.com\//.test(event.url))
88 onBeforeLoadYoutubeVideo(event.target); 76 onBeforeLoadYoutubeVideo(event.target);
89 } 77 }
90 78
91 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re sponse) 79 ext.backgroundPage.sendMessage({type: "get-domain-enabled-state"}, function(re sponse)
92 { 80 {
93 if (response.enabled) 81 if (response.enabled)
94 { 82 {
95 deferred.forEach(patchPlayer); 83 deferred.forEach(patchPlayer);
96 onBeforeLoadYoutubeVideo = patchPlayer; 84 onBeforeLoadYoutubeVideo = patchPlayer;
97 } 85 }
98 else 86 else
99 document.removeEventListener("beforeload", onBeforeLoad, true); 87 document.removeEventListener("beforeload", onBeforeLoad, true);
100 }); 88 });
101 89
102 document.addEventListener("beforeload", onBeforeLoad, true); 90 document.addEventListener("beforeload", onBeforeLoad, true);
91
92 // if history.pushState is available, YouTube uses the history API
93 // when navigation from one video to another, and tells the flash
94 // player with JavaScript which video and which ads to show next,
95 // bypassing our flashvars rewrite code. So we disable
96 // history.pushState before YouTube's JavaScript runs.
97 var script = document.createElement("script");
98 script.type = "application/javascript";
99 script.async = false;
100 script.textContent = "history.pushState = undefined;";
101 document.documentElement.appendChild(script);
102 document.documentElement.removeChild(script);
103 })(); 103 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld