summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortwellington <twellington@chromium.org>2015-05-28 10:30:17 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-28 17:30:51 +0000
commit9bacad65abe3631048c1e5d0467e1cea414e5700 (patch)
treeeb10e27c3b9fa257339120c1ce67bb3d2eced574
parent06ef7cacb458935497396f8e3810a29d62d97878 (diff)
downloadchromium_src-9bacad65abe3631048c1e5d0467e1cea414e5700.zip
chromium_src-9bacad65abe3631048c1e5d0467e1cea414e5700.tar.gz
chromium_src-9bacad65abe3631048c1e5d0467e1cea414e5700.tar.bz2
Refactor get_salient_image_url.js to use DocumentImageExtractor
Refactor get_salient_image_url.js to use the DocumentImageExtractor. Move get_salient_image_url.js into components so it accessible for iOS as well. BUG=454623 Review URL: https://codereview.chromium.org/1036113002 Cr-Commit-Position: refs/heads/master@{#331807}
-rw-r--r--chrome/browser/browser_resources.grd3
-rw-r--r--chrome/browser/enhanced_bookmarks/android/DEPS1
-rw-r--r--chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.cc61
-rw-r--r--chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.h27
-rw-r--r--chrome/browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc2
-rw-r--r--chrome/browser/resources/get_salient_image_url.js67
-rw-r--r--chrome/chrome_browser.gypi21
-rw-r--r--chrome/chrome_repack_resources.gypi5
-rw-r--r--components/resources/enhanced_bookmarks/OWNERS3
-rw-r--r--components/resources/enhanced_bookmarks/dom_initializer.js11
-rw-r--r--components/resources/enhanced_bookmarks/enhanced_bookmarks.gypi89
-rw-r--r--components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.grd15
-rw-r--r--components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.gyp31
-rw-r--r--components/resources/enhanced_bookmarks/get_salient_image_url.js59
-rw-r--r--tools/gritsettings/resource_ids3
15 files changed, 296 insertions, 102 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index b30eae2..3987476 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -146,9 +146,6 @@
<include name="IDR_FEEDBACK_MANIFEST" file="resources\feedback\manifest.json" type="BINDATA" />
<include name="IDR_FLAGS_HTML" file="resources\flags.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_FLAGS_JS" file="resources\flags.js" type="BINDATA" />
- <if expr="is_android">
- <include name="IDR_GET_SALIENT_IMAGE_URL_JS" file="resources\get_salient_image_url.js" type="BINDATA" />
- </if>
<if expr="_google_chrome or enable_hangout_services_extension">
<!-- Hangout Services extension, included in Google Chrome builds only. -->
<include name="IDR_HANGOUT_SERVICES_MANIFEST" file="resources\hangout_services\manifest.json" type="BINDATA" />
diff --git a/chrome/browser/enhanced_bookmarks/android/DEPS b/chrome/browser/enhanced_bookmarks/android/DEPS
index 5d93983..c3e3c3d 100644
--- a/chrome/browser/enhanced_bookmarks/android/DEPS
+++ b/chrome/browser/enhanced_bookmarks/android/DEPS
@@ -1,3 +1,4 @@
include_rules = [
"+chrome/renderer/chrome_isolated_world_ids.h",
+ "+grit/enhanced_bookmarks_resources.h",
]
diff --git a/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.cc b/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.cc
index 61e5b3b..5f8bd9c 100644
--- a/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.cc
+++ b/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.cc
@@ -17,7 +17,7 @@
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/common/referrer.h"
+#include "grit/enhanced_bookmarks_resources.h"
#include "net/base/load_flags.h"
#include "skia/ext/image_operations.h"
#include "ui/base/device_form_factor.h"
@@ -87,7 +87,7 @@ void BookmarkImageServiceAndroid::RetrieveSalientImage(
}
void BookmarkImageServiceAndroid::RetrieveSalientImageFromContext(
- content::RenderFrameHost* render_frame_host,
+ content::WebContents* web_contents,
const GURL& page_url,
bool update_bookmark) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
@@ -109,18 +109,25 @@ void BookmarkImageServiceAndroid::RetrieveSalientImageFromContext(
return;
}
- if (script_.empty()) {
- script_ =
- base::UTF8ToUTF16(ResourceBundle::GetSharedInstance()
- .GetRawDataResource(IDR_GET_SALIENT_IMAGE_URL_JS)
- .as_string());
+ if (dom_initializer_script_.empty()) {
+ dom_initializer_script_ =
+ base::UTF8ToUTF16(
+ ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_DOM_INITIALIZER_GEN_JS)
+ .as_string());
}
+ blink::WebReferrerPolicy policy =
+ web_contents->GetController().GetVisibleEntry()->GetReferrer().policy;
+
+ content::RenderFrameHost* render_frame_host = web_contents->GetMainFrame();
+
render_frame_host->ExecuteJavaScriptInIsolatedWorld(
- script_,
+ dom_initializer_script_,
base::Bind(
- &BookmarkImageServiceAndroid::RetrieveSalientImageFromContextCallback,
- base::Unretained(this), page_url, update_bookmark),
+ &BookmarkImageServiceAndroid::InitializeDomCallback,
+ base::Unretained(this), policy, render_frame_host, page_url,
+ update_bookmark),
chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL);
}
@@ -141,13 +148,36 @@ void BookmarkImageServiceAndroid::FinishSuccessfulPageLoadForTab(
urls.push_back(entry_original_url);
for (GURL url : urls) {
if (enhanced_bookmark_model_->bookmark_model()->IsBookmarked(url)) {
- RetrieveSalientImageFromContext(web_contents->GetMainFrame(), url,
+ RetrieveSalientImageFromContext(web_contents, url,
update_bookmark);
}
}
}
+void BookmarkImageServiceAndroid::InitializeDomCallback(
+ blink::WebReferrerPolicy policy,
+ content::RenderFrameHost* render_frame_host,
+ const GURL& page_url,
+ bool update_bookmark,
+ const base::Value* result) {
+ if (get_salient_image_url_script_.empty()) {
+ get_salient_image_url_script_ =
+ base::UTF8ToUTF16(
+ ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_GET_SALIENT_IMAGE_URL_GEN_JS)
+ .as_string());
+ }
+
+ render_frame_host->ExecuteJavaScriptInIsolatedWorld(
+ get_salient_image_url_script_,
+ base::Bind(
+ &BookmarkImageServiceAndroid::RetrieveSalientImageFromContextCallback,
+ base::Unretained(this), policy, page_url, update_bookmark),
+ chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL);
+}
+
void BookmarkImageServiceAndroid::RetrieveSalientImageFromContextCallback(
+ blink::WebReferrerPolicy policy,
const GURL& page_url,
bool update_bookmark,
const base::Value* result) {
@@ -181,15 +211,6 @@ void BookmarkImageServiceAndroid::RetrieveSalientImageFromContextCallback(
dict->GetString("referrerPolicy", &referrerPolicy);
dict->GetString("imageUrl", &image_url);
- // The policy strings are guaranteed to be in lower-case.
- blink::WebReferrerPolicy policy = blink::WebReferrerPolicyDefault;
- if (referrerPolicy == "never")
- policy = blink::WebReferrerPolicyNever;
- if (referrerPolicy == "always")
- policy = blink::WebReferrerPolicyAlways;
- if (referrerPolicy == "origin")
- policy = blink::WebReferrerPolicyOrigin;
-
in_progress_page_urls_.insert(page_url);
Referrer referrer =
diff --git a/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.h b/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.h
index d44c579..ca47f92 100644
--- a/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.h
+++ b/chrome/browser/enhanced_bookmarks/android/bookmark_image_service_android.h
@@ -5,8 +5,9 @@
#ifndef CHROME_BROWSER_ENHANCED_BOOKMARKS_ANDROID_BOOKMARK_IMAGE_SERVICE_ANDROID_H_
#define CHROME_BROWSER_ENHANCED_BOOKMARKS_ANDROID_BOOKMARK_IMAGE_SERVICE_ANDROID_H_
-#include "components/enhanced_bookmarks/bookmark_image_service.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
+#include "components/enhanced_bookmarks/bookmark_image_service.h"
+#include "content/public/common/referrer.h"
namespace chrome {
class BitmapFetcher;
@@ -35,7 +36,7 @@ class BookmarkImageServiceAndroid : public BookmarkImageService {
// Searches the current page for a salient image, if a url is found the image
// is fetched and stored.
void RetrieveSalientImageFromContext(
- content::RenderFrameHost* render_frame_host,
+ content::WebContents* web_contents,
const GURL& page_url,
bool update_bookmark);
@@ -46,15 +47,33 @@ class BookmarkImageServiceAndroid : public BookmarkImageService {
bool update_bookmark);
private:
- void RetrieveSalientImageFromContextCallback(const GURL& page_url,
+ // The callback for dom_initializer_script_. Once the DOM is initialized,
+ // this method starts execution of get_salient_image_url_script_.
+ void InitializeDomCallback(blink::WebReferrerPolicy policy,
+ content::RenderFrameHost* render_frame_host,
+ const GURL& page_url,
+ bool update_bookmark,
+ const base::Value* result);
+
+ // The callback for get_salient_image_url_srcipt. Parses the JSON from
+ // execution of get_salient_image_url_script_ to determine the URL for the
+ // salient image and invokes RetrieveSalientImage.
+ void RetrieveSalientImageFromContextCallback(blink::WebReferrerPolicy policy,
+ const GURL& page_url,
bool update_bookmark,
const base::Value* result);
scoped_ptr<gfx::Image> ResizeImage(const gfx::Image& image) override;
content::BrowserContext* browser_context_;
+
+ // The script injected in a page to initialize the DOM before extracting image
+ // urls.
+ base::string16 dom_initializer_script_;
+
// The script injected in a page to extract image urls.
- base::string16 script_;
+ base::string16 get_salient_image_url_script_;
+
// Maximum size for retrieved salient images in pixels. This is used when
// resizing an image.
gfx::Size max_size_;
diff --git a/chrome/browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc b/chrome/browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc
index 96c2f5b..94a1de1 100644
--- a/chrome/browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc
+++ b/chrome/browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc
@@ -115,7 +115,7 @@ void EnhancedBookmarksBridge::FetchImageForTab(JNIEnv* env,
jobject j_web_contents) {
WebContents* web_contents = WebContents::FromJavaWebContents(j_web_contents);
bookmark_image_service_->RetrieveSalientImageFromContext(
- web_contents->GetMainFrame(), web_contents->GetURL(), true);
+ web_contents, web_contents->GetURL(), true);
}
ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription(
diff --git a/chrome/browser/resources/get_salient_image_url.js b/chrome/browser/resources/get_salient_image_url.js
deleted file mode 100644
index cb3020e..0000000
--- a/chrome/browser/resources/get_salient_image_url.js
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-/*
- * Looks on the page to find the image that could be the most representative
- * one.
- */
-(function() {
- // Extract the referrer policy from the page.
- var referrerPolicy = 'default';
- var metaTags = document.getElementsByTagName('meta');
- for (var i = 0; i < metaTags.length; ++i) {
- if (metaTags[i].name.toLowerCase() == 'referrer') {
- referrerPolicy = metaTags[i].content.toLowerCase();
- break;
- }
- }
-
- // See what to use for JSON. Some pages use a library that overrides JSON.
- var jsonEncoder = JSON.stringify;
- if (!jsonEncoder)
- jsonEncoder = JSON.encode;
-
- // First look if there is an Open Graph Image property available.
- var ogImage = document.querySelector('meta[property=\"og:image\"]');
- if (ogImage) {
- // Checks that the url in ogImage has a path that contains more than just a
- // simple '/'.
- var url = ogImage.content;
- var location = document.createElement('a');
- location.href = url;
- if (location.pathname.length > 1) {
- return jsonEncoder({
- 'imageUrl': url,
- 'referrerPolicy': referrerPolicy
- });
- }
- }
-
- // Iterates through the images on the page, find the largest one that doesn't
- // look like a banner.
- var maxPointSize = 0;
- var maxImage = null;
-
- var images = document.getElementsByTagName('img');
- for (var i = 0; i < images.length; i++) {
- var currentImage = images[i];
- var aspectRatio = currentImage.width / currentImage.height;
- if (aspectRatio >= 2.4 || aspectRatio <= 0.5)
- continue; // Skip weirdly shaped images. Those are ads or headers.
- var pointSize = currentImage.width * currentImage.height;
- if (pointSize > maxPointSize) {
- maxPointSize = pointSize;
- maxImage = currentImage;
- }
- }
-
- // Only keep images larger than 320*160.
- if (maxPointSize <= 51200.0 || maxImage === null)
- return '';
-
- return jsonEncoder({
- 'imageUrl': maxImage.src,
- 'referrerPolicy': referrerPolicy
- });
-})();
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index ad5b486..c4bac94 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1318,6 +1318,14 @@
'browser/bookmarks/chrome_bookmark_client_factory.h',
'browser/bookmarks/enhanced_bookmarks_features.cc',
'browser/bookmarks/enhanced_bookmarks_features.h',
+ 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service.cc',
+ 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service.h',
+ 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service_factory.cc',
+ 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service_factory.h',
+ 'browser/enhanced_bookmarks/enhanced_bookmark_model_factory.cc',
+ 'browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h',
+ ],
+ 'chrome_browser_bookmark_android_sources': [
'browser/enhanced_bookmarks/android/bookmark_image_service_android.cc',
'browser/enhanced_bookmarks/android/bookmark_image_service_android.h',
'browser/enhanced_bookmarks/android/bookmark_image_service_factory.cc',
@@ -1326,12 +1334,6 @@
'browser/enhanced_bookmarks/android/enhanced_bookmark_tab_helper.h',
'browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc',
'browser/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h',
- 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service.cc',
- 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service.h',
- 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service_factory.cc',
- 'browser/enhanced_bookmarks/chrome_bookmark_server_cluster_service_factory.h',
- 'browser/enhanced_bookmarks/enhanced_bookmark_model_factory.cc',
- 'browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h',
],
'chrome_browser_browser_process_sources': [
'browser/browser_process.cc',
@@ -3584,6 +3586,8 @@
'../components/components.gyp:service_tab_launcher',
'../components/components.gyp:web_contents_delegate_android',
'../components/components_resources.gyp:components_resources',
+ '../components/resources/enhanced_bookmarks/enhanced_bookmarks.gypi:*',
+ '../components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.gyp:*',
'../third_party/android_opengl/etc1/etc1.gyp:etc1',
'../third_party/libaddressinput/libaddressinput.gyp:libaddressinput_util',
'chrome_browser_jni_headers',
@@ -3595,7 +3599,10 @@
'../components/components.gyp:web_modal',
'../third_party/libaddressinput/libaddressinput.gyp:libaddressinput',
],
- 'sources': [ '<@(chrome_browser_android_sources)' ],
+ 'sources': [
+ '<@(chrome_browser_android_sources)',
+ '<@(chrome_browser_bookmark_android_sources)',
+ ],
'defines': [ 'ENABLE_DATA_REDUCTION_PROXY_DEBUGGING' ],
'conditions': [
['use_seccomp_bpf==1', {
diff --git a/chrome/chrome_repack_resources.gypi b/chrome/chrome_repack_resources.gypi
index 8c0c7e7..9b06ec6 100644
--- a/chrome/chrome_repack_resources.gypi
+++ b/chrome/chrome_repack_resources.gypi
@@ -28,6 +28,11 @@
'<(SHARED_INTERMEDIATE_DIR)/ui/oobe/oobe_resources.pak',
],
}],
+ ['OS == "android"', {
+ 'pak_inputs': [
+ '<(SHARED_INTERMEDIATE_DIR)/components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.pak',
+ ]
+ }],
['OS != "ios"', {
'pak_inputs': [
'<(SHARED_INTERMEDIATE_DIR)/blink/public/resources/blink_resources.pak',
diff --git a/components/resources/enhanced_bookmarks/OWNERS b/components/resources/enhanced_bookmarks/OWNERS
new file mode 100644
index 0000000..ffa7f07
--- /dev/null
+++ b/components/resources/enhanced_bookmarks/OWNERS
@@ -0,0 +1,3 @@
+kkimlabs@chromium.org
+noyau@chromium.org
+twellington@chromium.org
diff --git a/components/resources/enhanced_bookmarks/dom_initializer.js b/components/resources/enhanced_bookmarks/dom_initializer.js
new file mode 100644
index 0000000..8f8d4e8
--- /dev/null
+++ b/components/resources/enhanced_bookmarks/dom_initializer.js
@@ -0,0 +1,11 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+goog.provide('DomInitializer');
+
+goog.require('image.collections.extension.domextractor.DomController');
+
+var domController =
+ new image.collections.extension.domextractor.DomController();
+domController.initialize();
diff --git a/components/resources/enhanced_bookmarks/enhanced_bookmarks.gypi b/components/resources/enhanced_bookmarks/enhanced_bookmarks.gypi
new file mode 100644
index 0000000..f9dcb67
--- /dev/null
+++ b/components/resources/enhanced_bookmarks/enhanced_bookmarks.gypi
@@ -0,0 +1,89 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+{
+ 'targets' :[
+ {
+ 'target_name': 'document_image_extractor',
+ 'type': 'none',
+ 'variables': { 'CLOSURE_DIR': '<(DEPTH)/third_party/closure_compiler', },
+ 'actions': [
+ {
+ # This action optionally takes these arguments:
+ # - depends: scripts that the source file depends on being included already
+ # - externs: files that describe globals used by |source|
+ 'action_name': 'Compile enhanced bookmarks image extractor JavaScript',
+ 'variables': {
+ 'source_file': 'get_salient_image_url.js',
+ 'out_file': '<(SHARED_INTERMEDIATE_DIR)/closure/<!(python <(CLOSURE_DIR)/build/outputs.py <@(source_file))',
+ },
+ 'inputs': [
+ '<(CLOSURE_DIR)/compile.py',
+ '<(CLOSURE_DIR)/processor.py',
+ '<(CLOSURE_DIR)/build/inputs.py',
+ '<(CLOSURE_DIR)/build/outputs.py',
+ '<(CLOSURE_DIR)/compiler/compiler.jar',
+ '<(CLOSURE_DIR)/runner/runner.jar',
+ '<!@(python <(CLOSURE_DIR)/build/inputs.py <(source_file))',
+ ],
+ 'outputs': [
+ '<(out_file)',
+ ],
+ 'action': [
+ 'python',
+ '<(CLOSURE_DIR)/compile.py',
+ '<@(document_image_extractor_js_files)',
+ '<(source_file)',
+ '--out_file', '<(out_file)',
+ '--no-single-file',
+ '--output_wrapper', '(function(){%output% return GetSalientImageUrl();})();',
+ ],
+ }
+ ],
+ 'includes': [
+ '../../../third_party/document_image_extractor/document_image_extractor_files.gypi'
+ ],
+ },
+ {
+ 'target_name': 'dom_initializer',
+ 'type': 'none',
+ 'variables': { 'CLOSURE_DIR': '<(DEPTH)/third_party/closure_compiler', },
+ 'actions': [
+ {
+ # This action optionally takes these arguments:
+ # - depends: scripts that the source file depends on being included already
+ # - externs: files that describe globals used by |source|
+ 'action_name': 'Compile enhanced bookmarks dom initializer JavaScript',
+ 'variables': {
+ 'source_file': 'dom_initializer.js',
+ 'out_file': '<(SHARED_INTERMEDIATE_DIR)/closure/<!(python <(CLOSURE_DIR)/build/outputs.py <@(source_file))',
+ },
+ 'inputs': [
+ '<(CLOSURE_DIR)/compile.py',
+ '<(CLOSURE_DIR)/processor.py',
+ '<(CLOSURE_DIR)/build/inputs.py',
+ '<(CLOSURE_DIR)/build/outputs.py',
+ '<(CLOSURE_DIR)/compiler/compiler.jar',
+ '<(CLOSURE_DIR)/runner/runner.jar',
+ '<!@(python <(CLOSURE_DIR)/build/inputs.py <(source_file))',
+ ],
+ 'outputs': [
+ '<(out_file)',
+ ],
+ 'action': [
+ 'python',
+ '<(CLOSURE_DIR)/compile.py',
+ '<@(dom_controller_js_files)',
+ '<(source_file)',
+ '--out_file', '<(out_file)',
+ '--no-single-file',
+ '--output_wrapper', '(function(){%output%})();',
+ ]
+ }
+ ],
+ 'includes': [
+ '../../../third_party/document_image_extractor/dom_controller_files.gypi'
+ ],
+ },
+ ],
+}
diff --git a/components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.grd b/components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.grd
new file mode 100644
index 0000000..6fa24e6
--- /dev/null
+++ b/components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.grd
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grit latest_public_release="0" current_release="1">
+ <outputs>
+ <output filename="grit/enhanced_bookmarks_resources.h" type="rc_header">
+ <emit emit_type='prepend'></emit>
+ </output>
+ <output filename="enhanced_bookmarks_resources.pak" type="data_package" />
+ </outputs>
+ <release seq="1">
+ <includes>
+ <include name="IDR_GET_SALIENT_IMAGE_URL_GEN_JS" file="${get_salient_image_url_gen_js}" use_base_dir="false" type="BINDATA" />
+ <include name="IDR_DOM_INITIALIZER_GEN_JS" file="${dom_initializer_gen_js}" use_base_dir="false" type="BINDATA" />
+ </includes>
+ </release>
+</grit>
diff --git a/components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.gyp b/components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.gyp
new file mode 100644
index 0000000..c0c817d
--- /dev/null
+++ b/components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.gyp
@@ -0,0 +1,31 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'enhanced_bookmarks_resources',
+ 'type': 'none',
+ 'variables': {
+ 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/components/resources/enhanced_bookmarks',
+ 'get_salient_image_url_gen_js': '<(SHARED_INTERMEDIATE_DIR)/closure/components/resources/enhanced_bookmarks/get_salient_image_url.js',
+ 'dom_initializer_gen_js': '<(SHARED_INTERMEDIATE_DIR)/closure/components/resources/enhanced_bookmarks/dom_initializer.js',
+ },
+ 'actions': [
+ {
+ 'action_name': 'generate_enhanced_bookmarks_resources',
+ 'variables': {
+ 'grit_grd_file': 'enhanced_bookmarks_resources.grd',
+ 'grit_additional_defines': [
+ '-E', 'get_salient_image_url_gen_js=<(get_salient_image_url_gen_js)',
+ '-E', 'dom_initializer_gen_js=<(dom_initializer_gen_js)',
+ ],
+ },
+ 'includes': [ '../../../build/grit_action.gypi' ],
+ },
+ ],
+ 'includes': [ '../../../build/grit_target.gypi' ],
+ },
+ ],
+}
diff --git a/components/resources/enhanced_bookmarks/get_salient_image_url.js b/components/resources/enhanced_bookmarks/get_salient_image_url.js
new file mode 100644
index 0000000..c7a32b6
--- /dev/null
+++ b/components/resources/enhanced_bookmarks/get_salient_image_url.js
@@ -0,0 +1,59 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+goog.require('image.collections.extension.domextractor.DocumentImageExtractor');
+
+/*
+ * Examines the DOM to find the image that is the most representative of the
+ * webpage.
+ */
+var GetSalientImageUrl = function() {
+ // Extract the referrer policy from the page.
+ var referrerPolicy = 'default';
+ var metaTags = document.getElementsByTagName('meta');
+ for (var i = 0; i < metaTags.length; i++) {
+ if (metaTags[i].name.toLowerCase() == 'referrer') {
+ referrerPolicy = metaTags[i].content.toLowerCase();
+ break;
+ }
+ }
+
+ // Determine which JSON method (stringify or encode) to use for encoding.
+ // Some pages use a library that overrides JSON, so JSON['stringify'] is not
+ // always available.
+ var jsonEncoder = JSON['stringify'];
+ if (!jsonEncoder)
+ jsonEncoder = JSON['encode'];
+
+ var context = new
+ image.collections.extension.domextractor.DocumentImageExtractor.Context();
+ var documentImageExtractor =
+ new image.collections.extension.domextractor.DocumentImageExtractor();
+ var images = documentImageExtractor.extractFromNodeList(
+ document.querySelectorAll('img,link,meta'), context);
+
+ var maxImage = null;
+ var maxRelevance = 0;
+ for (var i = 0; i < images.length; i++) {
+ var currentImage = images[i];
+ var imageSize = currentImage.getSize();
+ if (!imageSize)
+ continue;
+
+ if (currentImage.getRelevance() > maxRelevance) {
+ maxImage = currentImage;
+ maxRelevance = currentImage.getRelevance();
+ }
+ }
+
+ if (maxImage === null)
+ return '';
+
+ var result = jsonEncoder({
+ 'imageUrl': maxImage.getUrl(),
+ 'referrerPolicy': referrerPolicy
+ });
+
+ return result;
+};
diff --git a/tools/gritsettings/resource_ids b/tools/gritsettings/resource_ids
index 6562e14..7cd7d64 100644
--- a/tools/gritsettings/resource_ids
+++ b/tools/gritsettings/resource_ids
@@ -248,6 +248,9 @@
"components/resources/components_scaled_resources.grd": {
"structures": [30280],
},
+ "components/resources/enhanced_bookmarks/enhanced_bookmarks_resources.grd": {
+ "includes": [30330],
+ },
"third_party/WebKit/public/blink_resources.grd": {
"includes": [30350],
"structures": [30650],