OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 * Looks on the page to find the image that could be the most representative | 6 * Looks on the page to find the image that could be the most representative |
7 * one. | 7 * one. |
8 */ | 8 */ |
9 (function() { | 9 (function() { |
10 // Extract the referrer policy from the page. | 10 // Extract the referrer policy from the page. |
11 var referrerPolicy = 'default'; | 11 var referrerPolicy = 'default'; |
12 var metaTags = document.getElementsByTagName('meta'); | 12 var metaTags = document.getElementsByTagName('meta'); |
13 for (var i = 0; i < metaTags.length; ++i) { | 13 for (var i = 0; i < metaTags.length; ++i) { |
14 if (metaTags[i].name.toLowerCase() == 'referrer') { | 14 if (metaTags[i].name.toLowerCase() == 'referrer') { |
15 referrerPolicy = metaTags[i].content.toLowerCase(); | 15 referrerPolicy = metaTags[i].content.toLowerCase(); |
16 break; | 16 break; |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 // See what to use for JSON. Some pages use a library that overrides JSON. | 20 // See what to use for JSON. Some pages use a library that overrides JSON. |
21 var jsonEncoder = JSON.stringify; | 21 var jsonEncoder = JSON['stringify']; |
Dan Beam
2015/03/06 02:57:28
why is this necessary? shouldn't externs preserve
Theresa
2015/03/06 03:07:19
The compiler was complaining about not being able
| |
22 if (!jsonEncoder) | 22 if (!jsonEncoder) |
23 jsonEncoder = JSON.encode; | 23 jsonEncoder = JSON['encode']; |
24 | 24 |
25 // First look if there is an Open Graph Image property available. | 25 // First look if there is an Open Graph Image property available. |
26 var ogImage = document.querySelector('meta[property=\"og:image\"]'); | 26 var ogImage = document.querySelector('meta[property=\"og:image\"]'); |
27 if (ogImage) { | 27 if (ogImage) { |
28 // Checks that the url in ogImage has a path that contains more than just a | 28 // Checks that the url in ogImage has a path that contains more than just a |
29 // simple '/'. | 29 // simple '/'. |
30 var url = ogImage.content; | 30 var url = ogImage.content; |
31 var location = document.createElement('a'); | 31 var location = document.createElement('a'); |
32 location.href = url; | 32 location.href = url; |
33 if (location.pathname.length > 1) { | 33 if (location.pathname.length > 1) { |
(...skipping 24 matching lines...) Expand all Loading... | |
58 | 58 |
59 // Only keep images larger than 320*160. | 59 // Only keep images larger than 320*160. |
60 if (maxPointSize <= 51200.0 || maxImage === null) | 60 if (maxPointSize <= 51200.0 || maxImage === null) |
61 return ''; | 61 return ''; |
62 | 62 |
63 return jsonEncoder({ | 63 return jsonEncoder({ |
64 'imageUrl': maxImage.src, | 64 'imageUrl': maxImage.src, |
65 'referrerPolicy': referrerPolicy | 65 'referrerPolicy': referrerPolicy |
66 }); | 66 }); |
67 })(); | 67 })(); |
OLD | NEW |