| OLD | NEW |
| (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 #ifndef CHROME_BROWSER_ENHANCED_BOOKMARKS_ANDROID_BOOKMARK_IMAGE_SERVICE_ANDROID
_H_ | |
| 6 #define CHROME_BROWSER_ENHANCED_BOOKMARKS_ANDROID_BOOKMARK_IMAGE_SERVICE_ANDROID
_H_ | |
| 7 | |
| 8 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | |
| 9 #include "components/enhanced_bookmarks/bookmark_image_service.h" | |
| 10 #include "content/public/common/referrer.h" | |
| 11 | |
| 12 namespace chrome { | |
| 13 class BitmapFetcher; | |
| 14 } | |
| 15 | |
| 16 namespace content { | |
| 17 class BrowserContext; | |
| 18 class RenderFrameHost; | |
| 19 class WebContents; | |
| 20 } | |
| 21 | |
| 22 namespace enhanced_bookmarks { | |
| 23 | |
| 24 class BookmarkImageServiceAndroid : public BookmarkImageService { | |
| 25 public: | |
| 26 explicit BookmarkImageServiceAndroid(content::BrowserContext* browserContext); | |
| 27 | |
| 28 ~BookmarkImageServiceAndroid() override; | |
| 29 | |
| 30 void RetrieveSalientImage(const GURL& page_url, | |
| 31 const GURL& image_url, | |
| 32 const std::string& referrer, | |
| 33 net::URLRequest::ReferrerPolicy referrer_policy, | |
| 34 bool update_bookmark) override; | |
| 35 | |
| 36 // Searches the current page for a salient image, if a url is found the image | |
| 37 // is fetched and stored. | |
| 38 void RetrieveSalientImageFromContext( | |
| 39 content::WebContents* web_contents, | |
| 40 const GURL& page_url, | |
| 41 bool update_bookmark); | |
| 42 | |
| 43 // Investigates if the tab points to a bookmarked url in needs of an updated | |
| 44 // image. If it is, invokes RetrieveSalientImageFromContext() for the relevant | |
| 45 // urls. | |
| 46 void FinishSuccessfulPageLoadForTab(content::WebContents* web_contents, | |
| 47 bool update_bookmark); | |
| 48 | |
| 49 private: | |
| 50 // The callback for dom_initializer_script_. Once the DOM is initialized, | |
| 51 // this method starts execution of get_salient_image_url_script_. | |
| 52 void InitializeDomCallback(blink::WebReferrerPolicy policy, | |
| 53 content::RenderFrameHost* render_frame_host, | |
| 54 const GURL& page_url, | |
| 55 bool update_bookmark, | |
| 56 const base::Value* result); | |
| 57 | |
| 58 // The callback for get_salient_image_url_srcipt. Parses the JSON from | |
| 59 // execution of get_salient_image_url_script_ to determine the URL for the | |
| 60 // salient image and invokes RetrieveSalientImage. | |
| 61 void RetrieveSalientImageFromContextCallback(blink::WebReferrerPolicy policy, | |
| 62 const GURL& page_url, | |
| 63 bool update_bookmark, | |
| 64 const base::Value* result); | |
| 65 | |
| 66 scoped_ptr<gfx::Image> ResizeImage(const gfx::Image& image) override; | |
| 67 | |
| 68 content::BrowserContext* browser_context_; | |
| 69 | |
| 70 // The script injected in a page to initialize the DOM before extracting image | |
| 71 // urls. | |
| 72 base::string16 dom_initializer_script_; | |
| 73 | |
| 74 // The script injected in a page to extract image urls. | |
| 75 base::string16 get_salient_image_url_script_; | |
| 76 | |
| 77 // Maximum size for retrieved salient images in pixels. This is used when | |
| 78 // resizing an image. | |
| 79 gfx::Size max_size_; | |
| 80 | |
| 81 class BitmapFetcherHandler : private chrome::BitmapFetcherDelegate { | |
| 82 public: | |
| 83 explicit BitmapFetcherHandler(BookmarkImageServiceAndroid* service, | |
| 84 const GURL& image_url) | |
| 85 : service_(service), bitmap_fetcher_(image_url, this) {} | |
| 86 void Start(content::BrowserContext* browser_context, | |
| 87 const std::string& referrer, | |
| 88 net::URLRequest::ReferrerPolicy referrer_policy, | |
| 89 int load_flags, | |
| 90 bool update_bookmark, | |
| 91 const GURL& page_url); | |
| 92 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override; | |
| 93 | |
| 94 protected: | |
| 95 ~BitmapFetcherHandler() override {} | |
| 96 | |
| 97 private: | |
| 98 BookmarkImageServiceAndroid* service_; | |
| 99 chrome::BitmapFetcher bitmap_fetcher_; | |
| 100 bool update_bookmark_; | |
| 101 GURL page_url_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherHandler); | |
| 104 }; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(BookmarkImageServiceAndroid); | |
| 107 }; | |
| 108 | |
| 109 } // namespace enhanced_bookmarks | |
| 110 | |
| 111 #endif // CHROME_BROWSER_ENHANCED_BOOKMARKS_ANDROID_BOOKMARK_IMAGE_SERVICE_ANDR
OID_H_ | |
| OLD | NEW |