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 Browser; | |
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 create hosted apps from the current web contents. | |
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); | |
benwells
2013/11/25 00:40:16
I think this is all that needs to be public on thi
calamity
2013/11/29 05:45:36
Done.
| |
37 | |
38 const gfx::ImageFamily& image_family() const { | |
39 return image_family_; | |
40 } | |
41 | |
42 size_t pending_requests() const { | |
43 return in_progress_requests_.size(); | |
44 } | |
45 | |
46 // Icon download callback. | |
47 void DidDownloadFavicon(int id, | |
48 int http_status_code, | |
49 const GURL& image_url, | |
50 const std::vector<SkBitmap>& bitmaps, | |
51 const std::vector<gfx::Size>& original_bitmap_sizes); | |
52 | |
53 // content::WebContentsObserver overrides: | |
54 virtual void DidNavigateMainFrame( | |
55 const content::LoadCommittedDetails& details, | |
56 const content::FrameNavigateParams& params) OVERRIDE; | |
57 virtual void DidUpdateFaviconURL( | |
58 int32 page_id, | |
59 const std::vector<content::FaviconURL>& candidates) OVERRIDE; | |
60 | |
61 protected: | |
62 // These are protected to be overriden in testing. | |
63 explicit HostedAppTabHelper(content::WebContents* web_contents); | |
64 | |
65 // Initiates a download of the image at |url| and returns the download id. | |
66 virtual int DownloadImage(const GURL& url); | |
67 | |
68 private: | |
69 friend class content::WebContentsUserData<HostedAppTabHelper>; | |
70 | |
71 // Fetches icons for creating the hosted app from |favicon_url_candidates| and | |
72 // |web_app_info_.icons|. FinishCreateHostedApp() is called on download | |
73 // completion. | |
74 void FetchIcons(); | |
75 | |
76 // Creates and installs the hosted app for |web_app_info_|. | |
77 void FinishCreateHostedApp(); | |
78 | |
79 // Candidate favicon URLs for the current page. Repopulated each page load. | |
80 scoped_ptr<std::set<GURL> > favicon_url_candidates_; | |
81 | |
82 // The current page's icons. Populated by FetchIcons() or CreateHostedApp(). | |
benwells
2013/11/25 00:40:16
Is this comment out of date? Seems like only Fetch
calamity
2013/11/29 05:45:36
Done.
| |
83 gfx::ImageFamily image_family_; | |
84 | |
85 // Info of a web app to create a hosted app for. | |
86 scoped_ptr<WebApplicationInfo> web_app_info_; | |
87 | |
88 // Request ids of in-progress requests. | |
89 std::set<int> in_progress_requests_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(HostedAppTabHelper); | |
92 }; | |
93 | |
94 #endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_ | |
OLD | NEW |