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

Side by Side Diff: safari/ext/content.js

Issue 29339714: Issue 3924 - Notice pages loaded from Safari's page cache (Closed)
Patch Set: Created April 14, 2016, 8:57 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 10 matching lines...) Expand all
21 // So we have to fallback to the safari object from the parent frame. 21 // So we have to fallback to the safari object from the parent frame.
22 if (!("safari" in window)) 22 if (!("safari" in window))
23 window.safari = window.parent.safari; 23 window.safari = window.parent.safari;
24 24
25 25
26 /* Intialization */ 26 /* Intialization */
27 27
28 var beforeLoadEvent = document.createEvent("Event"); 28 var beforeLoadEvent = document.createEvent("Event");
29 beforeLoadEvent.initEvent("beforeload"); 29 beforeLoadEvent.initEvent("beforeload");
30 30
31 var isTopLevel = window == window.top; 31 var isTopLevel;
32 var isPrerendered = document.visibilityState == "prerender"; 32 var isPrerendered;
33 var documentId;
34 function notifyFrameLoading()
35 {
36 isTopLevel = window == window.top;
37 isPrerendered = document.visibilityState == "prerender";
38 documentId = Math.random().toString().substr(2);
33 39
34 // Notify the background page that this frame is loading, generating ourselves 40 // Notify the background page that this frame is loading, generating
35 // a random documentId while we're at it. That way the background page can 41 // ourselves a random documentId while we're at it. That way the background
36 // communicate with us reliably, despite limitations in Safari's extension 42 // page can communicate with us reliably, despite limitations in Safari's
37 // API. 43 // extension API.
38 var documentId = Math.random().toString().substr(2); 44 safari.self.tab.dispatchMessage("loading", {
39 safari.self.tab.dispatchMessage("loading", { 45 url: window.location.href,
40 url: window.location.href, 46 referrer: document.referrer,
41 referrer: document.referrer, 47 isTopLevel: isTopLevel,
42 isTopLevel: isTopLevel, 48 isPrerendered: isPrerendered,
43 isPrerendered: isPrerendered, 49 documentId: documentId
44 documentId: documentId 50 });
51 }
52
53 // We must notify the background page when this page is first loadeding (now)
54 // but also when it is re-shown (if the user uses the back button to return to
55 // this page in the future).
56 notifyFrameLoading();
57 window.addEventListener("pageshow", function (event)
Sebastian Noack 2016/04/14 10:58:56 Nit: Redundant space after function statement.
58 {
59 if (event.persisted)
60 notifyFrameLoading();
45 }); 61 });
46 62
63 // Notify the background page when a prerendered page is displayed. That way
64 // the existing page of the tab can be replaced with this new one.
47 if (isTopLevel && isPrerendered) 65 if (isTopLevel && isPrerendered)
48 { 66 {
49 var onVisibilitychange = function() 67 var onVisibilitychange = function()
50 { 68 {
51 safari.self.tab.dispatchMessage("replaced", {documentId: documentId}); 69 safari.self.tab.dispatchMessage("replaced", {documentId: documentId});
52 document.removeEventListener("visibilitychange", onVisibilitychange); 70 document.removeEventListener("visibilitychange", onVisibilitychange);
53 }; 71 };
54 document.addEventListener("visibilitychange", onVisibilitychange); 72 document.addEventListener("visibilitychange", onVisibilitychange);
55 } 73 }
56 74
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 }); 201 });
184 202
185 203
186 /* Detecting extension reload/disable/uninstall (not supported on Safari) */ 204 /* Detecting extension reload/disable/uninstall (not supported on Safari) */
187 205
188 ext.onExtensionUnloaded = { 206 ext.onExtensionUnloaded = {
189 addListener: function() {}, 207 addListener: function() {},
190 removeListener: function() {} 208 removeListener: function() {}
191 }; 209 };
192 })(); 210 })();
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