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

Side by Side Diff: ios/chrome/browser/ui/webui/history/favicon_source.h

Issue 2494853003: Remove some unused history resources on iOS (Closed)
Patch Set: add back URL constants Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 IOS_CHROME_BROWSER_UI_WEBUI_HISTORY_FAVICON_SOURCE_H_
6 #define IOS_CHROME_BROWSER_UI_WEBUI_HISTORY_FAVICON_SOURCE_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/task/cancelable_task_tracker.h"
14 #include "components/favicon/core/favicon_service.h"
15 #include "ios/web/public/url_data_source_ios.h"
16 #include "ui/gfx/favicon_size.h"
17
18 namespace favicon {
19 class FaviconService;
20 }
21
22 namespace history {
23 class TopSites;
24 }
25
26 namespace syncer {
27 class SyncService;
28 }
29
30 // FaviconSource is the gateway between network-level chrome:
31 // requests for favicons and the history backend that serves these.
32 //
33 // Format:
34 // chrome://favicon/size&scalefactor/urlmodifier/url
35 // Some parameters are optional as described below. However, the order of the
36 // parameters is not interchangeable.
37 //
38 // Parameter:
39 // 'url' Required
40 // Specifies the page URL of the requested favicon. If the 'urlmodifier'
41 // parameter is 'iconurl', the URL refers to the URL of the favicon image
42 // instead.
43 // 'size&scalefactor' Optional
44 // Values: ['largest', size/aa@bx/]
45 // 'largest': Specifies that the largest available favicon is requested.
46 // Example: chrome://favicon/largest/http://www.google.com/
47 // 'size/aa@bx/':
48 // Specifies the requested favicon's size in DIP (aa) and the requested
49 // favicon's scale factor. (b).
50 // The supported requested DIP sizes are: 16x16, 32x32 and 64x64.
51 // If the parameter is unspecified, the requested favicon's size defaults
52 // to 16 and the requested scale factor defaults to 1x.
53 // Example: chrome://favicon/size/16@2x/http://www.google.com/
54 // 'urlmodifier' Optional
55 // Values: ['iconurl', 'origin']
56 // 'iconurl': Specifies that the url parameter refers to the URL of
57 // the favicon image as opposed to the URL of the page that the favicon is
58 // on.
59 // Example: chrome://favicon/iconurl/http://www.google.com/favicon.ico
60 // 'origin': Specifies that the URL should be converted to a form with
61 // an empty path and a valid scheme. The converted URL will be used to
62 // request the favicon from the favicon service.
63 // Examples:
64 // chrome://favicon/origin/http://example.com/a
65 // chrome://favicon/origin/example.com
66 // Both URLs request the favicon for http://example.com from the
67 // favicon service.
68 class FaviconSource : public web::URLDataSourceIOS {
69 public:
70 // |favicon_service|, |top_sites| and |sync_service| can be null.
71 FaviconSource(favicon::FaviconService* favicon_service,
72 const scoped_refptr<history::TopSites>& top_sites,
73 syncer::SyncService* sync_service);
74
75 ~FaviconSource() override;
76
77 // web::URLDataSourceIOS implementation.
78 std::string GetSource() const override;
79 void StartDataRequest(
80 const std::string& path,
81 const web::URLDataSourceIOS::GotDataCallback& callback) override;
82 std::string GetMimeType(const std::string&) const override;
83 bool ShouldReplaceExistingSource() const override;
84
85 protected:
86 struct IconRequest {
87 IconRequest();
88 IconRequest(const web::URLDataSourceIOS::GotDataCallback& cb,
89 const GURL& path,
90 int size,
91 float scale);
92 IconRequest(const IconRequest& other);
93 ~IconRequest();
94
95 web::URLDataSourceIOS::GotDataCallback callback;
96 GURL request_path;
97 int size_in_dip;
98 float device_scale_factor;
99 };
100
101 // Called when the favicon data is missing to perform additional checks to
102 // locate the resource.
103 // |request| contains information for the failed request.
104 // Returns true if the missing resource is found.
105 virtual bool HandleMissingResource(const IconRequest& request);
106
107 private:
108 // Defines the allowed pixel sizes for requested favicons.
109 enum IconSize { SIZE_16, SIZE_32, SIZE_64, NUM_SIZES };
110
111 // Called when favicon data is available from the history backend.
112 void OnFaviconDataAvailable(
113 const IconRequest& request,
114 const favicon_base::FaviconRawBitmapResult& bitmap_result);
115
116 // Sends the 16x16 DIP 1x default favicon.
117 void SendDefaultResponse(
118 const web::URLDataSourceIOS::GotDataCallback& callback);
119
120 // Sends the default favicon.
121 void SendDefaultResponse(const IconRequest& request);
122
123 favicon::FaviconService* favicon_service_;
124 scoped_refptr<history::TopSites> top_sites_;
125 syncer::SyncService* sync_service_;
126
127 base::CancelableTaskTracker cancelable_task_tracker_;
128
129 // Raw PNG representations of favicons of each size to show when the favicon
130 // database doesn't have a favicon for a webpage. Indexed by IconSize values.
131 scoped_refptr<base::RefCountedMemory> default_favicons_[NUM_SIZES];
132
133 DISALLOW_COPY_AND_ASSIGN(FaviconSource);
134 };
135
136 #endif // IOS_CHROME_BROWSER_UI_WEBUI_HISTORY_FAVICON_SOURCE_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/history/browsing_history_handler.cc ('k') | ios/chrome/browser/ui/webui/history/favicon_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698