Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: ios/chrome/browser/enhanced_bookmarks/bookmark_image_service_ios.js

Issue 1219713002: Removed bookmark_image_service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed accidental BookmarkImageServiceFactory mention Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 /*
5 * Looks on the page to find the image that could be the most representative
6 * one.
7 */
8 (function() {
9 // Extract the referrer policy from the page.
10 var referrerPolicy = "";
11 if (window.__gCrWeb && __gCrWeb['getPageReferrerPolicy']) {
12 referrerPolicy = __gCrWeb['getPageReferrerPolicy'];
13 }
14
15 // See what to use for JSON. Some pages uses a library that overrides JSON.
16 var jsonEncoder = JSON.stringify;
17 if (!jsonEncoder)
18 jsonEncoder = JSON.encode;
19
20 // First look if there is an Open Graph Image property available.
21 var ogImage = document.querySelector('meta[property=\"og:image\"]');
22 if (ogImage) {
23 // Checks that the url in ogImage has a path that conatians more than just a
24 // simple '/'.
25 var url = ogImage.content;
26 var location = document.createElement("a");
27 location.href = url;
28 if (location.pathname.length > 1) {
29 return jsonEncoder({
30 'imageUrl': url,
31 'referrerPolicy': referrerPolicy
32 });
33 }
34 }
35
36 // Iterates through the images on the page, find the largest one that doesn't
37 // look like a banner.
38 var maxPointSize = 0;
39 var maxImage = null;
40
41 var images = document.getElementsByTagName('img');
42 for (var ii = 0; ii < images.length; ii++) {
43 var currentImage = images[ii];
44 var aspectRatio = currentImage.width / currentImage.height;
45 if (aspectRatio >= 2.4 || aspectRatio <= 0.5) {
46 continue; // Skip weirdly shaped images. Those are ads or headers.
47 }
48 var pointSize = currentImage.width * currentImage.height;
49 if (pointSize > maxPointSize) {
50 maxPointSize = pointSize;
51 maxImage = currentImage;
52 }
53 }
54
55 // Only keep images larger than 320*160.
56 if (maxPointSize <= 51200.0 || maxImage === null)
57 return "";
58
59 return jsonEncoder({
60 'imageUrl': maxImage.src,
61 'referrerPolicy': referrerPolicy
62 });
63 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698