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. | |
benwells
2013/11/13 21:55:17
Nit: this does more than manage hosted app icons,
calamity
2013/11/15 04:25:50
Fixed comment. This will also be where we update t
| |
29 class HostedAppTabHelper | |
30 : public content::WebContentsObserver, | |
31 public content::WebContentsUserData<HostedAppTabHelper> { | |
32 public: | |
33 virtual ~HostedAppTabHelper(); | |
34 | |
35 // Creates a hosted app for |web_app_info| using the current tab's icons. | |
36 void CreateHostedApp(const WebApplicationInfo& web_app_info); | |
37 | |
38 // Sets a delegate to notify on icon load. |fetch_icons_immediately| decides | |
39 // whether icons are fetched as soon as a page loads, rather than when | |
40 // CreateHostedApp() is called. | |
41 void SetDelegate(HostedAppTabHelperDelegate* delegate, | |
42 bool fetch_icons_immediately); | |
43 | |
44 const gfx::ImageFamily& image_family() { | |
45 return image_family_; | |
46 } | |
47 | |
48 size_t pending_requests() { return in_progress_requests_.size(); } | |
tapted
2013/11/13 07:44:53
nit: can probably declare this function const
calamity
2013/11/15 04:25:50
Done.
| |
49 | |
50 // Icon download callback. | |
51 void DidDownloadFavicon(int id, | |
tapted
2013/11/13 07:44:53
nit: should this and the overrides be in private?
calamity
2013/11/15 04:25:50
They need to be public so the tests can use them t
| |
52 int http_status_code, | |
53 const GURL& image_url, | |
54 const std::vector<SkBitmap>& bitmaps, | |
55 const std::vector<gfx::Size>& original_bitmap_sizes); | |
56 | |
57 // content::WebContentsObserver overrides: | |
58 virtual void DidNavigateMainFrame( | |
59 const content::LoadCommittedDetails& details, | |
60 const content::FrameNavigateParams& params) OVERRIDE; | |
61 virtual void DidUpdateFaviconURL( | |
62 int32 page_id, | |
63 const std::vector<content::FaviconURL>& candidates) OVERRIDE; | |
64 | |
65 protected: | |
66 // These are used for testing. | |
67 | |
68 explicit HostedAppTabHelper(content::WebContents* web_contents); | |
benwells
2013/11/13 21:55:17
Nit - remove blank line above.
Nit - is 'they' all
calamity
2013/11/15 04:25:50
The tests switch out the definition of DownloadIma
| |
69 | |
70 // Downloads |url| and adds the download id to |in_progress_requests_|. | |
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 completion. | |
82 void FetchIconsIfNecessaryForCreateHostedApp(); | |
83 | |
84 // Creates and installs the hosted app for |web_app_info_|. | |
85 void FinishCreateHostedApp(); | |
86 | |
87 // Candidate favicon URLs for the current page. Repopulated each page load. | |
88 scoped_ptr<std::set<GURL> > favicon_url_candidates_; | |
89 | |
90 // The current page's icons. Populated by FetchIcons() or CreateHostedApp(). | |
91 gfx::ImageFamily image_family_; | |
92 | |
93 // Info of a web app to create a hosted app for. | |
94 scoped_ptr<WebApplicationInfo> web_app_info_; | |
95 | |
96 // Request ids of in-progress requests. | |
97 std::set<int> in_progress_requests_; | |
98 | |
99 // Whether we should fetch icons as soon as the |favicon_url_candidates_| are | |
100 // updated. | |
101 bool fetch_icons_immediately_; | |
102 | |
103 HostedAppTabHelperDelegate* delegate_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(HostedAppTabHelper); | |
106 }; | |
107 | |
108 #endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_ | |
OLD | NEW |