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 "components/enhanced_bookmarks/bookmark_image_service.h" |
| 9 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 10 |
| 11 namespace chrome { |
| 12 class BitmapFetcher; |
| 13 } |
| 14 |
| 15 namespace content { |
| 16 class BrowserContext; |
| 17 class RenderFrameHost; |
| 18 class WebContents; |
| 19 } |
| 20 |
| 21 namespace enhanced_bookmarks { |
| 22 |
| 23 class BookmarkImageServiceAndroid : public BookmarkImageService { |
| 24 public: |
| 25 explicit BookmarkImageServiceAndroid(content::BrowserContext* browserContext); |
| 26 |
| 27 void RetrieveSalientImage(const GURL& page_url, |
| 28 const GURL& image_url, |
| 29 const std::string& referrer, |
| 30 net::URLRequest::ReferrerPolicy referrer_policy, |
| 31 bool update_bookmark) override; |
| 32 |
| 33 // Searches the current page for a salient image, if a url is found the image |
| 34 // is fetched and stored. |
| 35 void RetrieveSalientImageFromContext( |
| 36 content::RenderFrameHost* render_frame_host, |
| 37 const GURL& page_url, |
| 38 bool update_bookmark); |
| 39 |
| 40 // Investigates if the tab points to a bookmarked url in needs of an updated |
| 41 // image. If it is, invokes RetrieveSalientImageFromContext() for the relevant |
| 42 // urls. |
| 43 void FinishSuccessfulPageLoadForTab(content::WebContents* web_contents, |
| 44 bool update_bookmark); |
| 45 |
| 46 private: |
| 47 void RetrieveSalientImageFromContextCallback(const GURL& page_url, |
| 48 bool update_bookmark, |
| 49 const base::Value* result); |
| 50 |
| 51 content::BrowserContext* browser_context_; |
| 52 // The script injected in a page to extract image urls. |
| 53 base::string16 script_; |
| 54 |
| 55 class BitmapFetcherHandler : private chrome::BitmapFetcherDelegate { |
| 56 public: |
| 57 explicit BitmapFetcherHandler(BookmarkImageServiceAndroid* service, |
| 58 const GURL& image_url) |
| 59 : service_(service), bitmap_fetcher_(image_url, this) {} |
| 60 void Start(content::BrowserContext* browser_context, |
| 61 const std::string& referrer, |
| 62 net::URLRequest::ReferrerPolicy referrer_policy, |
| 63 int load_flags, |
| 64 bool update_bookmark, |
| 65 const GURL& page_url); |
| 66 void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; |
| 67 |
| 68 protected: |
| 69 ~BitmapFetcherHandler() override {} |
| 70 |
| 71 private: |
| 72 BookmarkImageServiceAndroid* service_; |
| 73 chrome::BitmapFetcher bitmap_fetcher_; |
| 74 bool update_bookmark_; |
| 75 GURL page_url_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherHandler); |
| 78 }; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(BookmarkImageServiceAndroid); |
| 81 }; |
| 82 |
| 83 } // namespace enhanced_bookmarks |
| 84 |
| 85 #endif // CHROME_BROWSER_ENHANCED_BOOKMARKS_ANDROID_BOOKMARK_IMAGE_SERVICE_ANDR
OID_H_ |
OLD | NEW |