| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_WIN_H_ | 5 #ifndef CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_WIN_H_ |
| 6 #define CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_WIN_H_ | 6 #define CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_WIN_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/browser/favicon/favicon_download_helper.h" | |
| 11 #include "chrome/browser/favicon/favicon_download_helper_delegate.h" | |
| 12 #include "chrome/common/favicon_url.h" | |
| 13 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "content/public/browser/web_contents_user_data.h" | 11 #include "content/public/browser/web_contents_user_data.h" |
| 12 #include "content/public/common/favicon_url.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
| 17 | 15 |
| 18 // Per-tab class to help manage metro pinning. | 16 // Per-tab class to help manage metro pinning. |
| 19 class MetroPinTabHelper | 17 class MetroPinTabHelper |
| 20 : public content::WebContentsObserver, | 18 : public content::WebContentsObserver, |
| 21 public content::WebContentsUserData<MetroPinTabHelper>, | 19 public content::WebContentsUserData<MetroPinTabHelper> { |
| 22 public FaviconDownloadHelperDelegate { | |
| 23 public: | 20 public: |
| 24 virtual ~MetroPinTabHelper(); | 21 virtual ~MetroPinTabHelper(); |
| 25 | 22 |
| 26 bool IsPinned() const; | 23 bool IsPinned() const; |
| 27 | 24 |
| 28 void TogglePinnedToStartScreen(); | 25 void TogglePinnedToStartScreen(); |
| 29 | 26 |
| 30 // content::WebContentsObserver overrides: | 27 // content::WebContentsObserver overrides: |
| 31 virtual void DidNavigateMainFrame( | 28 virtual void DidNavigateMainFrame( |
| 32 const content::LoadCommittedDetails& details, | 29 const content::LoadCommittedDetails& details, |
| 33 const content::FrameNavigateParams& params) OVERRIDE; | 30 const content::FrameNavigateParams& params) OVERRIDE; |
| 31 virtual void DidUpdateFaviconURL( |
| 32 int32 page_id, |
| 33 const std::vector<content::FaviconURL>& candidates) OVERRIDE; |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // The FaviconDownloader class handles downloading the favicons when a page | 36 // The FaviconDownloader class handles downloading the favicons when a page |
| 37 // is being pinned. After it has downloaded any available favicons it will | 37 // is being pinned. After it has downloaded any available favicons it will |
| 38 // continue on with the page pinning action. | 38 // continue on with the page pinning action. |
| 39 class FaviconChooser; | 39 class FaviconChooser; |
| 40 | 40 |
| 41 explicit MetroPinTabHelper(content::WebContents* tab_contents); | 41 explicit MetroPinTabHelper(content::WebContents* tab_contents); |
| 42 friend class content::WebContentsUserData<MetroPinTabHelper>; | 42 friend class content::WebContentsUserData<MetroPinTabHelper>; |
| 43 | 43 |
| 44 // FaviconDownloadHelperDelegate overrides. | 44 // Favicon download callback. |
| 45 void OnUpdateFaviconURL(int32 page_id, | 45 void DidDownloadFavicon(int id, |
| 46 const std::vector<FaviconURL>& candidates) OVERRIDE; | 46 const GURL& image_url, |
| 47 | 47 bool errored, |
| 48 void OnDidDownloadFavicon(int id, | 48 int requested_size, |
| 49 const GURL& image_url, | 49 const std::vector<SkBitmap>& bitmaps); |
| 50 bool errored, | |
| 51 int requested_size, | |
| 52 const std::vector<SkBitmap>& bitmaps) OVERRIDE; | |
| 53 | 50 |
| 54 void UnPinPageFromStartScreen(); | 51 void UnPinPageFromStartScreen(); |
| 55 | 52 |
| 56 // Called by the |favicon_downloader_| when it has finished. | 53 // Called by the |favicon_chooser_| when it has finished. |
| 57 void FaviconDownloaderFinished(); | 54 void FaviconDownloaderFinished(); |
| 58 | 55 |
| 59 // Candidate Favicon URLs for the current page. | 56 // Candidate Favicon URLs for the current page. |
| 60 std::vector<FaviconURL> favicon_url_candidates_; | 57 std::vector<content::FaviconURL> favicon_url_candidates_; |
| 61 | 58 |
| 62 // The currently active FaviconChooser, if there is one. | 59 // The currently active FaviconChooser, if there is one. |
| 63 scoped_ptr<FaviconChooser> favicon_chooser_; | 60 scoped_ptr<FaviconChooser> favicon_chooser_; |
| 64 | 61 |
| 65 // FaviconDownloadHelper handles the sending and listening for IPC messages. | |
| 66 FaviconDownloadHelper favicon_download_helper_; | |
| 67 | 62 |
| 68 DISALLOW_COPY_AND_ASSIGN(MetroPinTabHelper); | 63 DISALLOW_COPY_AND_ASSIGN(MetroPinTabHelper); |
| 69 }; | 64 }; |
| 70 | 65 |
| 71 #endif // CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_WIN_H_ | 66 #endif // CHROME_BROWSER_UI_METRO_PIN_TAB_HELPER_WIN_H_ |
| OLD | NEW |