Skip to content

Commit

Permalink
use parent URL as referrer in documents that are loaded from blob: URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Aug 9, 2019
1 parent f5ed9dd commit 770a5dc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
54 changes: 54 additions & 0 deletions debug/iframe-blob.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
</head>

<body>

<iframe width="800" height="600"></iframe>
<script>let mapboxgl = {};</script>
<script src='access_token_generated.js'></script>
<script>
let js = document.createElement("a");
js.href = "../dist/mapbox-gl-dev.js";
let css = document.createElement("a");
css.href = "../dist/mapbox-gl.css";
document.querySelector('iframe').src = URL.createObjectURL(new Blob([ `
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel='stylesheet' href='${css.href}' />
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id='map'></div>
<script src='${js.href}'><\/script>
<script>
mapboxgl.accessToken = '${mapboxgl.accessToken}';
var map = window.map = new mapboxgl.Map({
container: 'map',
zoom: 12.5,
center: [-77.01866, 38.888],
style: 'mapbox://styles/mapbox/streets-v10',
hash: true
});
<\/script>
</body>
</html>
` ], {type: 'text/html'}));
</script>

</body>
</html>
14 changes: 14 additions & 0 deletions debug/iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
</head>

<body>

<iframe width="800" height="600" src="index.html"></iframe>

</body>
</html>
7 changes: 1 addition & 6 deletions src/util/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ function isWorker() {
/* global self, WorkerGlobalScope */
export const getReferrer = isWorker() ?
() => self.worker && self.worker.referrer :
() => {
const origin = window.location.origin;
if (origin && origin !== 'null' && origin !== 'file://') {
return origin + window.location.pathname;
}
};
() => (location.protocol === 'blob:' ? parent : window).location.href;

function makeFetchRequest(requestParameters: RequestParameters, callback: ResponseCallback<any>): Cancelable {
const controller = new window.AbortController();
Expand Down

0 comments on commit 770a5dc

Please sign in to comment.