Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6057)

Unified Diff: chrome/browser/ui/web_applications/hosted_app_tab_helper.h

Issue 64853004: Use high resolution icons where possible for streamlined hosted app icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_experiment_create_app_from_page
Patch Set: rework, add tests Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/web_applications/hosted_app_tab_helper.h
diff --git a/chrome/browser/ui/web_applications/hosted_app_tab_helper.h b/chrome/browser/ui/web_applications/hosted_app_tab_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..242c90b09fbe5694f8bb980c337434499d1fc4d1
--- /dev/null
+++ b/chrome/browser/ui/web_applications/hosted_app_tab_helper.h
@@ -0,0 +1,108 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_
+#define CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_
+
+#include <set>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+#include "ui/gfx/image/image_family.h"
+
+class HostedAppTabHelperDelegate;
+class SkBitmap;
+struct WebApplicationInfo;
+
+namespace content {
+struct FaviconURL;
+}
+
+namespace gfx {
+class Size;
+}
+
+// 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
+class HostedAppTabHelper
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<HostedAppTabHelper> {
+ public:
+ virtual ~HostedAppTabHelper();
+
+ // Creates a hosted app for |web_app_info| using the current tab's icons.
+ void CreateHostedApp(const WebApplicationInfo& web_app_info);
+
+ // Sets a delegate to notify on icon load. |fetch_icons_immediately| decides
+ // whether icons are fetched as soon as a page loads, rather than when
+ // CreateHostedApp() is called.
+ void SetDelegate(HostedAppTabHelperDelegate* delegate,
+ bool fetch_icons_immediately);
+
+ const gfx::ImageFamily& image_family() {
+ return image_family_;
+ }
+
+ 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.
+
+ // Icon download callback.
+ 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
+ int http_status_code,
+ const GURL& image_url,
+ const std::vector<SkBitmap>& bitmaps,
+ const std::vector<gfx::Size>& original_bitmap_sizes);
+
+ // content::WebContentsObserver overrides:
+ virtual void DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) OVERRIDE;
+ virtual void DidUpdateFaviconURL(
+ int32 page_id,
+ const std::vector<content::FaviconURL>& candidates) OVERRIDE;
+
+ protected:
+ // These are used for testing.
+
+ 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
+
+ // Downloads |url| and adds the download id to |in_progress_requests_|.
+ virtual int DownloadImage(const GURL& url);
+
+ private:
+ friend class content::WebContentsUserData<HostedAppTabHelper>;
+
+ // Fetches the icons in |favicon_url_candidates_|. Downloads are handled in
+ // DidDownloadFavicon.
+ void FetchIcons();
+
+ // Fetches icons for creating the hosted app from |favicon_url_candidates| and
+ // |web_app_info_.icons|. FinishCreateHostedApp() is called on completion.
+ void FetchIconsIfNecessaryForCreateHostedApp();
+
+ // Creates and installs the hosted app for |web_app_info_|.
+ void FinishCreateHostedApp();
+
+ // Candidate favicon URLs for the current page. Repopulated each page load.
+ scoped_ptr<std::set<GURL> > favicon_url_candidates_;
+
+ // The current page's icons. Populated by FetchIcons() or CreateHostedApp().
+ gfx::ImageFamily image_family_;
+
+ // Info of a web app to create a hosted app for.
+ scoped_ptr<WebApplicationInfo> web_app_info_;
+
+ // Request ids of in-progress requests.
+ std::set<int> in_progress_requests_;
+
+ // Whether we should fetch icons as soon as the |favicon_url_candidates_| are
+ // updated.
+ bool fetch_icons_immediately_;
+
+ HostedAppTabHelperDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostedAppTabHelper);
+};
+
+#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_HOSTED_APP_TAB_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698