diff --git a/lib/webfontloader/demo/server.rb b/lib/webfontloader/demo/server.rb index af4b0213..573b7783 100644 --- a/lib/webfontloader/demo/server.rb +++ b/lib/webfontloader/demo/server.rb @@ -8,8 +8,8 @@ class Server < Sinatra::Base DemoRoot = File.expand_path(File.join(File.dirname(__FILE__))) ProjectRoot = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..")) - GoogleApi = "http://fonts.googleapis.com/css" - GoogleFontApi = "http://themes.googleusercontent.com/font" + GoogleApi = "https://fonts.googleapis.com/css" + GoogleFontApi = "https://themes.googleusercontent.com/font" set :app_file, __FILE__ set :sessions, false @@ -43,7 +43,7 @@ class Server < Sinatra::Base headers 'Cache-Control' => 'max-age=300' response = open(url, 'User-Agent' => env['HTTP_USER_AGENT']) source = response.read - source.gsub!(%r[http://themes.googleusercontent.com/font], '/fonts/font') + source.gsub!(%r[https://themes.googleusercontent.com/font], '/fonts/font') source end diff --git a/spec/core/domhelper_spec.js b/spec/core/domhelper_spec.js index d59da93e..3d80ee68 100644 --- a/spec/core/domhelper_spec.js +++ b/spec/core/domhelper_spec.js @@ -405,100 +405,6 @@ describe('DomHelper', function () { }); }); - describe('#getProtocol', function () { - it('should return http', function () { - var domHelper = new DomHelper({ - location: { - protocol: 'http:' - } - }); - - expect(domHelper.getProtocol()).toEqual('http:'); - }); - - it('should return https', function () { - var domHelper = new DomHelper({ - location: { - protocol: 'https:' - } - }); - - expect(domHelper.getProtocol()).toEqual('https:'); - }); - - it('should return the protocol from an iframe', function () { - var domHelper = new DomHelper({ - location: { - protocol: 'https:' - } - }, { - location: { - protocol: 'http:' - } - }); - - expect(domHelper.getProtocol()).toEqual('http:'); - }); - - it('should return the protocol from the main window if the iframe has no protocol', function () { - var domHelper = new DomHelper({ - location: { - protocol: 'http:' - } - }, { - location: { - protocol: 'about:' - } - }); - - expect(domHelper.getProtocol()).toEqual('http:'); - }); - }); - - describe('#setProtocol', function () { - it('ignores invalid values', function () { - var domHelper = new DomHelper({ - location: 'http:' - }); - - domHelper.setProtocol('huh'); - - expect(domHelper.getProtocol()).toEqual('http:'); - }); - - it('overrides the global value', function () { - var domHelper = new DomHelper({ - location: 'http:' - }); - - domHelper.setProtocol('https:'); - - expect(domHelper.getProtocol()).toEqual('https:'); - }); - }); - - describe('#isHttps', function () { - it('should return true if the protocol is https', function () { - var domHelper = new DomHelper({ - location: { - protocol: 'https:' - } - }); - - expect(domHelper.isHttps()).toBe(true); - }); - - it('should return false if the protocol is not https', function () { - var domHelper = new DomHelper({ - location: { - protocol: 'http:' - } - }); - - expect(domHelper.isHttps()).toBe(false); - }); - }); - describe('#getHostname', function () { it('should return the hostname', function () { var domHelper = new DomHelper({ diff --git a/spec/modules/custom_spec.js b/spec/modules/custom_spec.js index 78f7a630..db76e578 100644 --- a/spec/modules/custom_spec.js +++ b/spec/modules/custom_spec.js @@ -24,7 +24,7 @@ describe('modules.Custom', function () { var defaultModule = new Custom(fakeDomHelper, { families: ['Font1', 'Font2', 'Font3'], - urls: ['http://moo', 'http://meuh'], + urls: ['https://moo', 'https://meuh'], testStrings: { Font3: 'hello world' } @@ -35,8 +35,8 @@ describe('modules.Custom', function () { it('should have inserted the links correctly', function () { expect(fakeDomHelper.loadStylesheet.callCount).toEqual(2); - expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('http://moo', new Any(Function)); - expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('http://meuh', new Any(Function)); + expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('https://moo', new Any(Function)); + expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('https://meuh', new Any(Function)); }); if (webfont.DomHelper.CAN_WAIT_STYLESHEET) { diff --git a/spec/modules/fontdeck_spec.js b/spec/modules/fontdeck_spec.js index 0aebd841..71861685 100644 --- a/spec/modules/fontdeck_spec.js +++ b/spec/modules/fontdeck_spec.js @@ -8,9 +8,9 @@ describe('modules.Fontdeck', function () { var apiResponse = { "domain" : "localhost", - "cssurl" : "http://f.fontdeck.com/s/css/03BmCXiV2AHwX/Rp+OBFTfD2oFs/localhost/2282.css", + "cssurl" : "https://f.fontdeck.com/s/css/03BmCXiV2AHwX/Rp+OBFTfD2oFs/localhost/2282.css", "project" : 2282, - "cssbase" : "http://f.fontdeck.com/s/css/03BmCXiV2AHwX/Rp+OBFTfD2oFs", + "cssbase" : "https://f.fontdeck.com/s/css/03BmCXiV2AHwX/Rp+OBFTfD2oFs", "fonts" : [ { "font_family" : "'Fertigo Pro Regular', Fertigo, Constantia, Palatino, serif", @@ -19,10 +19,10 @@ describe('modules.Fontdeck', function () { "style" : "normal", "weight" : "normal", "font_urls" : { - "eot" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.eot", - "ttf" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.ttf", - "woff" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.woff", - "svg" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.svg#104" + "eot" : "https://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.eot", + "ttf" : "https://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.ttf", + "woff" : "https://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.woff", + "svg" : "https://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.svg#104" }, "id" : 104 }, @@ -33,10 +33,10 @@ describe('modules.Fontdeck', function () { "style" : "italic", "weight" : "bold", "font_urls" : { - "eot" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.eot", - "ttf" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.ttf", - "woff" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.woff", - "svg" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.svg#2256" + "eot" : "https://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.eot", + "ttf" : "https://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.ttf", + "woff" : "https://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.woff", + "svg" : "https://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.svg#2256" }, "id" : 2256 } @@ -54,7 +54,6 @@ describe('modules.Fontdeck', function () { fakeDomHelper = { loadScript: jasmine.createSpy('loadScript'), getLoadWindow: jasmine.createSpy('getLoadWindow').andReturn(global), - getProtocol: jasmine.createSpy('getProtocol').andReturn('https:'), getHostName: function () { return 'test-host-name'; } }; }); diff --git a/spec/modules/google/fontapiurlbuilder_spec.js b/spec/modules/google/fontapiurlbuilder_spec.js index ac715eee..0ffecb72 100644 --- a/spec/modules/google/fontapiurlbuilder_spec.js +++ b/spec/modules/google/fontapiurlbuilder_spec.js @@ -2,37 +2,37 @@ describe('modules.google.FontApiUrlBuilder', function () { var FontApiUrlBuilder = webfont.modules.google.FontApiUrlBuilder; it('should throw an exception if there are no font families', function () { - var builder = new FontApiUrlBuilder('http://moo', 'http:'); + var builder = new FontApiUrlBuilder('https://moo'); expect(builder.build).toThrow(); }); it('should build a proper url', function () { - var builder = new FontApiUrlBuilder('http://moo', 'http:'); + var builder = new FontApiUrlBuilder('https://moo'); builder.setFontFamilies(['Font1', 'Font2']); - expect(builder.build()).toEqual('http://moo?family=Font1%7CFont2'); + expect(builder.build()).toEqual('https://moo?family=Font1%7CFont2'); }); it('should build a proper url', function () { - var builder = new FontApiUrlBuilder(undefined, 'http:'); + var builder = new FontApiUrlBuilder(undefined); builder.setFontFamilies(['Font1', 'Font2']); - expect(builder.build()).toEqual('http:' + + expect(builder.build()).toEqual( FontApiUrlBuilder.DEFAULT_API_URL + '?family=Font1%7CFont2'); }); it('should build a proper url', function () { - var builder = new FontApiUrlBuilder(undefined, 'http:'); + var builder = new FontApiUrlBuilder(undefined); builder.setFontFamilies(['Font1:bold:greek,cyrillic', 'Font2:italic', 'Font3']); - expect(builder.build()).toEqual('http:' + + expect(builder.build()).toEqual( FontApiUrlBuilder.DEFAULT_API_URL + '?family=Font1:bold%7CFont2:italic%7CFont3' + '&subset=greek,cyrillic'); }); it('should build a proper url', function () { - var builder = new FontApiUrlBuilder(undefined, 'http:'); + var builder = new FontApiUrlBuilder(undefined); builder.setFontFamilies(['Font1:bold,italic:greek,cyrillic', 'Font2:italic', 'Font3::latin']); - expect(builder.build()).toEqual('http:' + + expect(builder.build()).toEqual( FontApiUrlBuilder.DEFAULT_API_URL + '?family=Font1:bold,italic%7CFont2:italic%7CFont3' + '&subset=greek,cyrillic,latin'); diff --git a/spec/modules/google/googlefontapi_spec.js b/spec/modules/google/googlefontapi_spec.js index 14c8854d..28a8f423 100644 --- a/spec/modules/google/googlefontapi_spec.js +++ b/spec/modules/google/googlefontapi_spec.js @@ -12,9 +12,6 @@ describe('modules.google.GoogleFontApi', function () { loadStylesheet: function (cssLink, cb) { link = cssLink; onload = cb; - }, - getProtocol: function () { - return 'http:'; } }; @@ -42,7 +39,7 @@ describe('modules.google.GoogleFontApi', function () { }); it('has inserted the link element correctly', function () { - expect(link).toEqual('http://fonts.googleapis.com/css?family=Font1%7CFont2'); + expect(link).toEqual('https://fonts.googleapis.com/css?family=Font1%7CFont2'); }); it('has the correct families', function () { @@ -61,14 +58,14 @@ describe('modules.google.GoogleFontApi', function () { beforeEach(function () { loaded = false; googleFontApi = new GoogleFontApi(fakeDomHelper, { - api: 'http://moo', + api: 'https://moo', families: ['Font1', 'Font2'] }); googleFontApi.load(function () { loaded = true; }); }); it('has inserted the link element correctly', function () { - expect(link).toEqual('http://moo?family=Font1%7CFont2'); + expect(link).toEqual('https://moo?family=Font1%7CFont2'); }); if (webfont.DomHelper.CAN_WAIT_STYLESHEET) { @@ -91,7 +88,7 @@ describe('modules.google.GoogleFontApi', function () { }); it('has inserted the link element correctly', function () { - expect(link).toEqual('http://fonts.googleapis.com/css?family=Font1+WithSpace%7CFont2+WithSpaceToo'); + expect(link).toEqual('https://fonts.googleapis.com/css?family=Font1+WithSpace%7CFont2+WithSpaceToo'); }); }); @@ -104,7 +101,7 @@ describe('modules.google.GoogleFontApi', function () { }); it('has inserted the link element correctly', function () { - expect(link).toEqual('http://fonts.googleapis.com/css?family=Font1+WithSpace:bi%7CFont2+WithSpaceToo:b,r'); + expect(link).toEqual('https://fonts.googleapis.com/css?family=Font1+WithSpace:bi%7CFont2+WithSpaceToo:b,r'); }); }); }); diff --git a/spec/modules/monotype_spec.js b/spec/modules/monotype_spec.js index 5951ec4d..f664d2ac 100644 --- a/spec/modules/monotype_spec.js +++ b/spec/modules/monotype_spec.js @@ -7,7 +7,7 @@ describe('modules.Monotype', function () { var configuration = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', - api: 'http://fast.fonts.net/jsapidev' + api: 'https://fast.fonts.net/jsapidev' }; var fakeDomHelper = null, @@ -25,8 +25,7 @@ describe('modules.Monotype', function () { script.onload = callback; return script; }), - getLoadWindow: jasmine.createSpy('getLoadWindow').andReturn(global), - getProtocol: jasmine.createSpy('getProtocol').andReturn('http:') + getLoadWindow: jasmine.createSpy('getLoadWindow').andReturn(global) }; support = jasmine.createSpy('support'); load = jasmine.createSpy('load'); @@ -44,7 +43,7 @@ describe('modules.Monotype', function () { it('should create a script element', function () { expect(fakeDomHelper.loadScript).toHaveBeenCalled(); - expect(fakeDomHelper.loadScript.calls[0].args[0]).toEqual('http://fast.fonts.net/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js'); + expect(fakeDomHelper.loadScript.calls[0].args[0]).toEqual('https://fast.fonts.net/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js'); expect(load).toHaveBeenCalledWith([new Font('aachen bold'), new Font('kid print regular')]); }); }); diff --git a/spec/modules/typekit_spec.js b/spec/modules/typekit_spec.js index db11bcec..4a0a0761 100644 --- a/spec/modules/typekit_spec.js +++ b/spec/modules/typekit_spec.js @@ -29,8 +29,7 @@ describe('modules.Typekit', function () { loadScript: jasmine.createSpy('loadScript').andCallFake(function (url, cb) { cb(null); }), - getLoadWindow: jasmine.createSpy('getLoadWindow').andReturn(global), - getProtocol: jasmine.createSpy('getProtocol').andReturn('http:') + getLoadWindow: jasmine.createSpy('getLoadWindow').andReturn(global) }; }); diff --git a/src/core/domhelper.js b/src/core/domhelper.js index f9ee6c6d..19c9e58e 100644 --- a/src/core/domhelper.js +++ b/src/core/domhelper.js @@ -234,41 +234,6 @@ goog.scope(function () { return this.loadWindow_; }; - /** - * @return {string} The protocol (http: or https:) to request resources in. - */ - DomHelper.prototype.getProtocol = function() { - if (typeof this.protocol_ === 'string') { - return this.protocol_; - } else { - var protocol = this.loadWindow_.location.protocol; - // For empty iframes, fallback to main window's protocol. - if (protocol == 'about:') { - protocol = this.mainWindow_.location.protocol; - } - return protocol == 'https:' ? 'https:' : 'http:'; - } - }; - - /** - * Explicitly set the protocol instead of automatic detection. - * - * @param {string} protocol - */ - DomHelper.prototype.setProtocol = function (protocol) { - if (/^http(s)?:$/.test(protocol)) { - this.protocol_ = protocol; - } - }; - - /** - * Returns the secure status of the current document. - * @return {boolean} true if the current document is served securely. - */ - DomHelper.prototype.isHttps = function() { - return this.getProtocol() === 'https:'; - }; - /** * Returns the hostname of the current document. * @return {string} hostname. diff --git a/src/modules/custom.js b/src/modules/custom.js index a722d271..7031eda7 100644 --- a/src/modules/custom.js +++ b/src/modules/custom.js @@ -8,7 +8,7 @@ goog.require('webfont.StyleSheetWaiter'); * WebFont.load({ * custom: { * families: ['Font1', 'Font2'], - * urls: [ 'http://moo', 'http://meuh' ] } + * urls: [ 'https://moo', 'https://meuh' ] } * }); * * @constructor diff --git a/src/modules/fontdeck.js b/src/modules/fontdeck.js index ab7e0758..a195b325 100644 --- a/src/modules/fontdeck.js +++ b/src/modules/fontdeck.js @@ -18,7 +18,7 @@ webfont.modules.Fontdeck = function(domHelper, configuration) { */ webfont.modules.Fontdeck.NAME = 'fontdeck'; webfont.modules.Fontdeck.HOOK = '__webfontfontdeckmodule__'; -webfont.modules.Fontdeck.API = '//f.fontdeck.com/s/css/js/'; +webfont.modules.Fontdeck.API = 'https://f.fontdeck.com/s/css/js/'; goog.scope(function () { var Fontdeck = webfont.modules.Fontdeck, @@ -26,11 +26,10 @@ goog.scope(function () { FontVariationDescription = webfont.FontVariationDescription; Fontdeck.prototype.getScriptSrc = function(projectId) { - var protocol = this.domHelper_.getProtocol(); // For empty iframes, fall back to main window's hostname. var hostname = this.domHelper_.getHostName(); var api = this.configuration_['api'] || webfont.modules.Fontdeck.API; - return protocol + api + hostname + '/' + projectId + '.js'; + return api + hostname + '/' + projectId + '.js'; }; Fontdeck.prototype.load = function(onReady) { diff --git a/src/modules/google/fontapiurlbuilder.js b/src/modules/google/fontapiurlbuilder.js index 563f285e..8d1bec18 100644 --- a/src/modules/google/fontapiurlbuilder.js +++ b/src/modules/google/fontapiurlbuilder.js @@ -3,11 +3,11 @@ goog.provide('webfont.modules.google.FontApiUrlBuilder'); /** * @constructor */ -webfont.modules.google.FontApiUrlBuilder = function(apiUrl, protocol, text) { +webfont.modules.google.FontApiUrlBuilder = function(apiUrl, text) { if (apiUrl) { this.apiUrl_ = apiUrl; } else { - this.apiUrl_ = protocol + webfont.modules.google.FontApiUrlBuilder.DEFAULT_API_URL; + this.apiUrl_ = webfont.modules.google.FontApiUrlBuilder.DEFAULT_API_URL; } this.fontFamilies_ = []; this.subsets_ = []; @@ -15,7 +15,7 @@ webfont.modules.google.FontApiUrlBuilder = function(apiUrl, protocol, text) { }; -webfont.modules.google.FontApiUrlBuilder.DEFAULT_API_URL = '//fonts.googleapis.com/css'; +webfont.modules.google.FontApiUrlBuilder.DEFAULT_API_URL = 'https://fonts.googleapis.com/css'; goog.scope(function () { var FontApiUrlBuilder = webfont.modules.google.FontApiUrlBuilder; diff --git a/src/modules/google/googlefontapi.js b/src/modules/google/googlefontapi.js index 3379f3b3..8f3e5a43 100644 --- a/src/modules/google/googlefontapi.js +++ b/src/modules/google/googlefontapi.js @@ -38,7 +38,6 @@ goog.scope(function () { var domHelper = this.domHelper_; var fontApiUrlBuilder = new FontApiUrlBuilder( this.configuration_['api'], - domHelper.getProtocol(), this.configuration_['text'] ); var fontFamilies = this.configuration_['families']; diff --git a/src/modules/monotype.js b/src/modules/monotype.js index 5c60ce84..3bff98cb 100644 --- a/src/modules/monotype.js +++ b/src/modules/monotype.js @@ -52,9 +52,8 @@ goog.scope(function() { Monotype.prototype.getScriptSrc = function(projectId, version) { - var p = this.domHelper_.getProtocol(); - var api = (this.configuration_['api'] || 'fast.fonts.net/jsapi').replace(/^.*http(s?):(\/\/)?/, ""); - return p + "//" + api + '/' + projectId + '.js' + (version ? '?v=' + version : ''); + var api = (this.configuration_['api'] || 'https://fast.fonts.net/jsapi') + return api + '/' + projectId + '.js' + (version ? '?v=' + version : ''); }; Monotype.prototype.load = function(onReady) {