1 // Copyright (c) 2013 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 ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ 7 8 #include <string> 9 #include "content/public/browser/web_contents_observer.h" 10 #include "url/gurl.h" 11 12 class SkBitmap; 13 14 namespace content { 15 struct FaviconURL; 16 } 17 18 namespace gfx { 19 class Size; 20 } 21 22 namespace android_webview { 23 24 // A helper that observes favicon changes for Webview. 25 class IconHelper : public content::WebContentsObserver { 26 public: 27 class Listener { 28 public: 29 virtual bool ShouldDownloadFavicon(const GURL& icon_url) = 0; 30 virtual void OnReceivedIcon(const GURL& icon_url, 31 const SkBitmap& bitmap) = 0; 32 virtual void OnReceivedTouchIconUrl(const std::string& url, 33 const bool precomposed) = 0; 34 protected: 35 virtual ~Listener() {} 36 }; 37 38 explicit IconHelper(content::WebContents* web_contents); 39 virtual ~IconHelper(); 40 41 void SetListener(Listener* listener); 42 43 // From WebContentsObserver 44 virtual void DidUpdateFaviconURL(int32 page_id, 45 const std::vector<content::FaviconURL>& candidates) OVERRIDE; 46 47 void DownloadFaviconCallback( 48 int id, 49 int http_status_code, 50 const GURL& image_url, 51 const std::vector<SkBitmap>& bitmaps, 52 const std::vector<gfx::Size>& original_bitmap_sizes); 53 54 private: 55 Listener* listener_; 56 57 DISALLOW_COPY_AND_ASSIGN(IconHelper); 58 }; 59 60 } // namespace android_webview 61 62 #endif // ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ 63