From dc7bbd9b76b1e113bec8409d4f448af7e1b05e5a Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Tue, 30 Jun 2015 17:00:39 +0200 Subject: [PATCH 01/12] Create sandbox iframes on demand rather than always by template code. --- static/js/directives/odfcanvas.js | 10 ++++--- static/js/directives/pdfcanvas.js | 10 ++++--- static/js/directives/youtubevideo.js | 3 +- static/js/services/sandbox.js | 42 ++++++++++++++++++++++++---- static/partials/youtubevideo.html | 4 +-- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/static/js/directives/odfcanvas.js b/static/js/directives/odfcanvas.js index ba96d944..449d5e41 100644 --- a/static/js/directives/odfcanvas.js +++ b/static/js/directives/odfcanvas.js @@ -31,14 +31,16 @@ define(['require', 'underscore', 'jquery', 'text!partials/odfcanvas_sandbox.html var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { var container = $($element); - var odfCanvas; - var template = sandboxTemplate; template = template.replace(/__PARENT_ORIGIN__/g, $window.location.protocol + "//" + $window.location.host); template = template.replace(/__WEBODF_SANDBOX_JS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('sandboxes/webodf') + ".js")); template = template.replace(/__WEBODF_URL__/g, restURL.createAbsoluteUrl(require.toUrl('webodf') + ".js")); - var sandboxApi = sandbox.createSandbox($("iframe", container)[0], template); + var sandboxApi = sandbox.createSandbox(container, template, "allow-scripts", null, { + allowfullscreen: true, + mozallowfullscreen: true, + webkitallowfullscreen: true + }); sandboxApi.e.on("message", function(event, message) { var msg = message.data; @@ -231,7 +233,7 @@ define(['require', 'underscore', 'jquery', 'text!partials/odfcanvas_sandbox.html return { restrict: 'E', replace: true, - template: '
', + template: '
', controller: controller }; diff --git a/static/js/directives/pdfcanvas.js b/static/js/directives/pdfcanvas.js index e4327664..fd6c8e86 100644 --- a/static/js/directives/pdfcanvas.js +++ b/static/js/directives/pdfcanvas.js @@ -29,16 +29,18 @@ define(['require', 'underscore', 'jquery', 'text!partials/pdfcanvas_sandbox.html var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { var container = $($element); - var pdfCanvas; - var template = sandboxTemplate; template = template.replace(/__PARENT_ORIGIN__/g, $window.location.protocol + "//" + $window.location.host); template = template.replace(/__PDFJS_SANDBOX_JS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('sandboxes/pdf') + ".js")); template = template.replace(/__PDFJS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('pdf') + ".js")); template = template.replace(/__PDFJS_WORKER_URL__/g, restURL.createAbsoluteUrl(require.toUrl('pdf.worker') + ".js")); template = template.replace(/__PDFJS_COMPATIBILITY_URL__/g, restURL.createAbsoluteUrl(require.toUrl('libs/pdf/compatibility') + ".js")); - var sandboxApi = sandbox.createSandbox($("iframe", container)[0], template); + var sandboxApi = sandbox.createSandbox(container, template, "allow-scripts", null, { + allowfullscreen: true, + mozallowfullscreen: true, + webkitallowfullscreen: true + }); sandboxApi.e.on("message", function(event, message) { var msg = message.data; @@ -289,7 +291,7 @@ define(['require', 'underscore', 'jquery', 'text!partials/pdfcanvas_sandbox.html return { restrict: 'E', replace: true, - template: '
', + template: '
', controller: controller }; diff --git a/static/js/directives/youtubevideo.js b/static/js/directives/youtubevideo.js index 98806f1a..46e85758 100644 --- a/static/js/directives/youtubevideo.js +++ b/static/js/directives/youtubevideo.js @@ -112,12 +112,11 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo sandboxApi = null; } if (!sandboxApi) { - var sandboxFrame = $(".youtubeplayer", $element)[0]; var template = sandboxTemplate; template = template.replace(/__PARENT_ORIGIN__/g, $window.location.protocol + "//" + $window.location.host); template = template.replace(/__YOUTUBE_SANDBOX_JS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('sandboxes/youtube') + ".js")); - sandboxApi = sandbox.createSandbox(sandboxFrame, template); + sandboxApi = sandbox.createSandbox($(".youtubeplayercontainer", $element)[0], template, "allow-scripts allow-same-origin", "youtubeplayer"); sandboxApi.e.on("message", function(event, message) { var msg = message.data; diff --git a/static/js/services/sandbox.js b/static/js/services/sandbox.js index f3046c93..774efffc 100644 --- a/static/js/services/sandbox.js +++ b/static/js/services/sandbox.js @@ -24,11 +24,37 @@ define(["jquery", "underscore"], function($, _) { return ["$window", function($window) { - var Sandbox = function(iframe, template) { - this.iframe = iframe; + var Sandbox = function(container, template, sandbox, className, attrs) { var blob = new $window.Blob([template], {type: "text/html;charset=utf-8"}); this.url = $window.URL.createObjectURL(blob); - this.iframe.src = this.url; + var iframe; + var $container = $(container); + if ($container.is("iframe")) { + // Container is iframe. + if (className) { + $container.addClass(className); + } + if (attrs) { + $container.attr(attrs); + } + iframe = $container[0]; + iframe.src = this.url; + this.created = false; + } else { + // Create iframe. + iframe = $window.document.createElement("iframe"); + iframe.sandbox = sandbox; + if (className) { + iframe.className = className; + } + if (attrs) { + $(iframe).attr(attrs); + } + iframe.src = this.url; + $container.append(iframe); + this.created = true; + } + this.iframe = iframe; this.target = this.iframe.contentWindow; this.e = $({}); this.handler = _.bind(this.onPostMessageReceived, this); @@ -47,6 +73,9 @@ define(["jquery", "underscore"], function($, _) { $window.URL.revokeObjectURL(this.url); this.url = null; } + if (this.created) { + $(this.iframe).remove(); + } }; Sandbox.prototype.onPostMessageReceived = function(event) { @@ -83,8 +112,11 @@ define(["jquery", "underscore"], function($, _) { }; return { - createSandbox: function(iframe, template) { - return new Sandbox(iframe, template); + createSandbox: function(iframe, template, sandbox, className, attrs) { + if (!sandbox) { + sandbox = ""; + } + return new Sandbox(iframe, template, sandbox, className, attrs); } }; diff --git a/static/partials/youtubevideo.html b/static/partials/youtubevideo.html index 0cd01e76..0542f3bb 100644 --- a/static/partials/youtubevideo.html +++ b/static/partials/youtubevideo.html @@ -30,9 +30,7 @@
-
- -
+
{{_('Currently playing')}}
{{ currentVideoUrl }}
From 5be1eda4eef5f07632b552e1930fdd90b62dbcd7 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Tue, 30 Jun 2015 23:34:13 +0200 Subject: [PATCH 02/12] Don't return users twice in "Welcome" from global room. --- src/app/spreed-webrtc-server/roomworker.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/spreed-webrtc-server/roomworker.go b/src/app/spreed-webrtc-server/roomworker.go index 95355309..9302638d 100644 --- a/src/app/spreed-webrtc-server/roomworker.go +++ b/src/app/spreed-webrtc-server/roomworker.go @@ -207,10 +207,12 @@ func (r *roomWorker) GetUsers() []*DataSession { } } r.mutex.RUnlock() - // Include connections to global room. - for _, ec := range r.manager.GlobalUsers() { - if !appender(ec) { - break + if r.id != r.manager.globalRoomID { + // Include connections to global room. + for _, ec := range r.manager.GlobalUsers() { + if !appender(ec) { + break + } } } From 7df88de38c1c7cb50700b8a02f782ee13856cd30 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Thu, 2 Jul 2015 10:37:20 +0200 Subject: [PATCH 03/12] Removed vim settings to avoid file beeing detected as Java by GitHub. --- static/js/libs/pdf/pdf.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/static/js/libs/pdf/pdf.js b/static/js/libs/pdf/pdf.js index 3627683f..05fc4861 100644 --- a/static/js/libs/pdf/pdf.js +++ b/static/js/libs/pdf/pdf.js @@ -27,8 +27,6 @@ PDFJS.build = '997096f'; // Use strict in our context only - users might not want it 'use strict'; -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ /* Copyright 2012 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -1735,7 +1733,7 @@ PDFJS.verbosity = (PDFJS.verbosity === undefined ? PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity); /** - * The maximum supported canvas size in total pixels e.g. width * height. + * The maximum supported canvas size in total pixels e.g. width * height. * The default value is 4096 * 4096. Use -1 for no limit. * @var {number} */ @@ -2018,7 +2016,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { * rendering call the function that is the first argument * to the callback. */ - + /** * PDF page operator list. * @@ -6850,7 +6848,7 @@ var SVGExtraState = (function SVGExtraStateClosure() { this.lineJoin = ''; this.lineCap = ''; this.miterLimit = 0; - + this.dashArray = []; this.dashPhase = 0; @@ -7077,7 +7075,7 @@ var SVGGraphics = (function SVGGraphicsClosure() { } return opListToTree(opList); }, - + executeOpTree: function SVGGraphics_executeOpTree(opTree) { var opTreeLen = opTree.length; for(var x = 0; x < opTreeLen; x++) { From a523d6b783273035acd223ab742704e04c69df63 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Thu, 2 Jul 2015 12:19:56 +0200 Subject: [PATCH 04/12] Improved comments. --- src/app/spreed-webrtc-server/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/spreed-webrtc-server/main.go b/src/app/spreed-webrtc-server/main.go index 13fd051a..d2821a05 100644 --- a/src/app/spreed-webrtc-server/main.go +++ b/src/app/spreed-webrtc-server/main.go @@ -335,7 +335,7 @@ func runner(runtime phoenix.Runtime) error { runtime.DefaultHTTPSHandler(r) } - // Add handlers. + // Prepare services. buddyImages := NewImageCache() codec := NewCodec(incomingCodecLimit) roomManager := NewRoomManager(config, codec) @@ -344,6 +344,8 @@ func runner(runtime phoenix.Runtime) error { sessionManager := NewSessionManager(config, tickets, hub, roomManager, roomManager, buddyImages, sessionSecret) statsManager := NewStatsManager(hub, roomManager, sessionManager) channellingAPI := NewChannellingAPI(config, roomManager, tickets, sessionManager, statsManager, hub, hub, hub) + + // Add handlers. r.HandleFunc("/", httputils.MakeGzipHandler(mainHandler)) r.Handle("/static/img/buddy/{flags}/{imageid}/{idx:.*}", http.StripPrefix(config.B, makeImageHandler(buddyImages, time.Duration(24)*time.Hour))) r.Handle("/static/{path:.*}", http.StripPrefix(config.B, httputils.FileStaticServer(http.Dir(rootFolder)))) From e35dd0f8a333955bec6982b5e1662aa88e647e98 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Thu, 2 Jul 2015 13:57:54 +0200 Subject: [PATCH 05/12] Added URL support to sandbox service. --- static/js/directives/odfcanvas.js | 2 +- static/js/directives/pdfcanvas.js | 2 +- static/js/directives/youtubevideo.js | 2 +- static/js/services/sandbox.js | 52 +++++++++++++++++++--------- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/static/js/directives/odfcanvas.js b/static/js/directives/odfcanvas.js index 449d5e41..9ce853cb 100644 --- a/static/js/directives/odfcanvas.js +++ b/static/js/directives/odfcanvas.js @@ -36,7 +36,7 @@ define(['require', 'underscore', 'jquery', 'text!partials/odfcanvas_sandbox.html template = template.replace(/__PARENT_ORIGIN__/g, $window.location.protocol + "//" + $window.location.host); template = template.replace(/__WEBODF_SANDBOX_JS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('sandboxes/webodf') + ".js")); template = template.replace(/__WEBODF_URL__/g, restURL.createAbsoluteUrl(require.toUrl('webodf') + ".js")); - var sandboxApi = sandbox.createSandbox(container, template, "allow-scripts", null, { + var sandboxApi = sandbox.createSandbox(container, template, null, "allow-scripts", null, { allowfullscreen: true, mozallowfullscreen: true, webkitallowfullscreen: true diff --git a/static/js/directives/pdfcanvas.js b/static/js/directives/pdfcanvas.js index fd6c8e86..a89f50bc 100644 --- a/static/js/directives/pdfcanvas.js +++ b/static/js/directives/pdfcanvas.js @@ -36,7 +36,7 @@ define(['require', 'underscore', 'jquery', 'text!partials/pdfcanvas_sandbox.html template = template.replace(/__PDFJS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('pdf') + ".js")); template = template.replace(/__PDFJS_WORKER_URL__/g, restURL.createAbsoluteUrl(require.toUrl('pdf.worker') + ".js")); template = template.replace(/__PDFJS_COMPATIBILITY_URL__/g, restURL.createAbsoluteUrl(require.toUrl('libs/pdf/compatibility') + ".js")); - var sandboxApi = sandbox.createSandbox(container, template, "allow-scripts", null, { + var sandboxApi = sandbox.createSandbox(container, template, null, "allow-scripts", null, { allowfullscreen: true, mozallowfullscreen: true, webkitallowfullscreen: true diff --git a/static/js/directives/youtubevideo.js b/static/js/directives/youtubevideo.js index 46e85758..93a484dc 100644 --- a/static/js/directives/youtubevideo.js +++ b/static/js/directives/youtubevideo.js @@ -116,7 +116,7 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo var template = sandboxTemplate; template = template.replace(/__PARENT_ORIGIN__/g, $window.location.protocol + "//" + $window.location.host); template = template.replace(/__YOUTUBE_SANDBOX_JS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('sandboxes/youtube') + ".js")); - sandboxApi = sandbox.createSandbox($(".youtubeplayercontainer", $element)[0], template, "allow-scripts allow-same-origin", "youtubeplayer"); + sandboxApi = sandbox.createSandbox($(".youtubeplayercontainer", $element)[0], template, null, "allow-scripts allow-same-origin", "youtubeplayer"); sandboxApi.e.on("message", function(event, message) { var msg = message.data; diff --git a/static/js/services/sandbox.js b/static/js/services/sandbox.js index 774efffc..f351e9ad 100644 --- a/static/js/services/sandbox.js +++ b/static/js/services/sandbox.js @@ -24,18 +24,35 @@ define(["jquery", "underscore"], function($, _) { return ["$window", function($window) { - var Sandbox = function(container, template, sandbox, className, attrs) { - var blob = new $window.Blob([template], {type: "text/html;charset=utf-8"}); - this.url = $window.URL.createObjectURL(blob); + var Sandbox = function(container, template, url, sandbox, className, attrs) { + this.container = container; + this.sandbox = sandbox ? sandbox : ""; + this.className = className; + this.attrs = attrs; + if (template) { + var blob = new $window.Blob([template], {type: "text/html;charset=utf-8"}); + this.url = this.blobUrl = $window.URL.createObjectURL(blob); + } else if (url) { + this.url = url; + } + if (this.url) { + this.create(); + } + }; + + Sandbox.prototype.create = function() { + if (!this.url) { + return; + } var iframe; - var $container = $(container); + var $container = $(this.container); if ($container.is("iframe")) { // Container is iframe. - if (className) { - $container.addClass(className); + if (this.className) { + $container.addClass(this.className); } - if (attrs) { - $container.attr(attrs); + if (this.attrs) { + $container.attr(this.attrs); } iframe = $container[0]; iframe.src = this.url; @@ -43,12 +60,12 @@ define(["jquery", "underscore"], function($, _) { } else { // Create iframe. iframe = $window.document.createElement("iframe"); - iframe.sandbox = sandbox; - if (className) { - iframe.className = className; + iframe.sandbox = this.sandbox; + if (this.className) { + iframe.className = this.className; } - if (attrs) { - $(iframe).attr(attrs); + if (this.attrs) { + $(iframe).attr(this.attrs); } iframe.src = this.url; $container.append(iframe); @@ -69,10 +86,13 @@ define(["jquery", "underscore"], function($, _) { $window.removeEventListener("message", this.handler, false); this.handler = null; } - if (this.url) { - $window.URL.revokeObjectURL(this.url); - this.url = null; + if (this.blobUrl) { + $window.URL.revokeObjectURL(this.blobUrl); + this.blobUrl = null; } + this.url = null; + this.container = null; + this.attrs = null; if (this.created) { $(this.iframe).remove(); } From b3d03b819c4b69f19cb740584895b473c8398b50 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Thu, 2 Jul 2015 17:54:45 +0200 Subject: [PATCH 06/12] Serve odf and pdf sandbox from the server to prepare CSP http header for Firefox compatibility as Firefox does not support CSP in meta tag (see https://bugzilla.mozilla.org/show_bug.cgi?id=663570). --- .../sandboxes}/odfcanvas_sandbox.html | 7 +- .../sandboxes}/pdfcanvas_sandbox.html | 7 +- src/app/spreed-webrtc-server/context.go | 1 + src/app/spreed-webrtc-server/main.go | 64 +++++++++++++++++-- static/js/directives/odfcanvas.js | 9 +-- static/js/directives/pdfcanvas.js | 11 +--- static/js/main.js | 18 ------ static/js/services/resturl.js | 3 + 8 files changed, 78 insertions(+), 42 deletions(-) rename {static/partials => html/sandboxes}/odfcanvas_sandbox.html (71%) rename {static/partials => html/sandboxes}/pdfcanvas_sandbox.html (56%) diff --git a/static/partials/odfcanvas_sandbox.html b/html/sandboxes/odfcanvas_sandbox.html similarity index 71% rename from static/partials/odfcanvas_sandbox.html rename to html/sandboxes/odfcanvas_sandbox.html index abe06482..40ee1e35 100644 --- a/static/partials/odfcanvas_sandbox.html +++ b/html/sandboxes/odfcanvas_sandbox.html @@ -1,8 +1,9 @@ - + WebODF Sandbox - + +