OLD | NEW |
(Empty) | |
| 1 // Copyright 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 CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "content/public/browser/web_contents_user_data.h" |
| 14 #include "ui/gfx/image/image_family.h" |
| 15 |
| 16 class HostedAppTabHelperDelegate; |
| 17 class SkBitmap; |
| 18 struct WebApplicationInfo; |
| 19 |
| 20 namespace content { |
| 21 struct FaviconURL; |
| 22 } |
| 23 |
| 24 namespace gfx { |
| 25 class Size; |
| 26 } |
| 27 |
| 28 // Per-tab class to help manage hosted app taskbar icons and create hosted apps |
| 29 // from the current web contents. |
| 30 class HostedAppTabHelper |
| 31 : public content::WebContentsObserver, |
| 32 public content::WebContentsUserData<HostedAppTabHelper> { |
| 33 public: |
| 34 virtual ~HostedAppTabHelper(); |
| 35 |
| 36 // Creates a hosted app for |web_app_info| using the current tab's icons. |
| 37 void CreateHostedApp(const WebApplicationInfo& web_app_info); |
| 38 |
| 39 // Sets a delegate to notify on icon load. On Windows, this will cause icons |
| 40 // to be fetched immediately once favicon URLs are available. |
| 41 void SetDelegate(HostedAppTabHelperDelegate* delegate); |
| 42 |
| 43 const gfx::ImageFamily& image_family() const { |
| 44 return image_family_; |
| 45 } |
| 46 |
| 47 size_t pending_requests() const { |
| 48 return in_progress_requests_.size(); |
| 49 } |
| 50 |
| 51 // Icon download callback. |
| 52 void DidDownloadFavicon(int id, |
| 53 int http_status_code, |
| 54 const GURL& image_url, |
| 55 const std::vector<SkBitmap>& bitmaps, |
| 56 const std::vector<gfx::Size>& original_bitmap_sizes); |
| 57 |
| 58 // content::WebContentsObserver overrides: |
| 59 virtual void DidNavigateMainFrame( |
| 60 const content::LoadCommittedDetails& details, |
| 61 const content::FrameNavigateParams& params) OVERRIDE; |
| 62 virtual void DidUpdateFaviconURL( |
| 63 int32 page_id, |
| 64 const std::vector<content::FaviconURL>& candidates) OVERRIDE; |
| 65 |
| 66 protected: |
| 67 // These are protected to be overriden in testing. |
| 68 explicit HostedAppTabHelper(content::WebContents* web_contents); |
| 69 |
| 70 // Initiates a download of the image at |url| and returns the download id. |
| 71 virtual int DownloadImage(const GURL& url); |
| 72 |
| 73 private: |
| 74 friend class content::WebContentsUserData<HostedAppTabHelper>; |
| 75 |
| 76 // Fetches the icons in |favicon_url_candidates_|. Downloads are handled in |
| 77 // DidDownloadFavicon(). |
| 78 void FetchIcons(); |
| 79 |
| 80 // Fetches icons for creating the hosted app from |favicon_url_candidates| and |
| 81 // |web_app_info_.icons|. FinishCreateHostedApp() is called on download |
| 82 // completion. |
| 83 void FetchIconsIfNecessaryForCreateHostedApp(); |
| 84 |
| 85 // Creates and installs the hosted app for |web_app_info_|. |
| 86 void FinishCreateHostedApp(); |
| 87 |
| 88 // Candidate favicon URLs for the current page. Repopulated each page load. |
| 89 scoped_ptr<std::set<GURL> > favicon_url_candidates_; |
| 90 |
| 91 // The current page's icons. Populated by FetchIcons() or CreateHostedApp(). |
| 92 gfx::ImageFamily image_family_; |
| 93 |
| 94 // Info of a web app to create a hosted app for. |
| 95 scoped_ptr<WebApplicationInfo> web_app_info_; |
| 96 |
| 97 // Request ids of in-progress requests. |
| 98 std::set<int> in_progress_requests_; |
| 99 |
| 100 // Whether we should fetch icons as soon as the |favicon_url_candidates_| are |
| 101 // updated. |
| 102 bool fetch_icons_immediately_; |
| 103 |
| 104 HostedAppTabHelperDelegate* delegate_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(HostedAppTabHelper); |
| 107 }; |
| 108 |
| 109 #endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_ |
OLD | NEW |