Skip to content

Commit

Permalink
Always use https for fonts.googleapis.com
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Jan 11, 2017
1 parent 30b5d7f commit 2f05dd1
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 180 deletions.
6 changes: 3 additions & 3 deletions lib/webfontloader/demo/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

This comment has been minimized.

Copy link
@fightingkyo

fightingkyo Jul 18, 2023

For Material Symbols variable axes, I suggest updating to Google Fonts API v2
GoogleApi = "http://fonts.googleapis.com/css2"

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
Expand Down Expand Up @@ -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

Expand Down
94 changes: 0 additions & 94 deletions spec/core/domhelper_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions spec/modules/custom_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -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) {
Expand Down
21 changes: 10 additions & 11 deletions spec/modules/fontdeck_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
},
Expand All @@ -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
}
Expand All @@ -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'; }
};
});
Expand Down
18 changes: 9 additions & 9 deletions spec/modules/google/fontapiurlbuilder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 5 additions & 8 deletions spec/modules/google/googlefontapi_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ describe('modules.google.GoogleFontApi', function () {
loadStylesheet: function (cssLink, cb) {
link = cssLink;
onload = cb;
},
getProtocol: function () {
return 'http:';
}
};

Expand Down Expand Up @@ -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 () {
Expand All @@ -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) {
Expand All @@ -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');
});
});

Expand All @@ -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');
});
});
});
7 changes: 3 additions & 4 deletions spec/modules/monotype_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
Expand All @@ -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')]);
});
});
3 changes: 1 addition & 2 deletions spec/modules/typekit_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
});

Expand Down
35 changes: 0 additions & 35 deletions src/core/domhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2f05dd1

Please sign in to comment.