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

Side by Side Diff: content/renderer/favicon_helper.cc

Issue 11411180: move favicon download code from chrome/ into content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix order Created 8 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/favicon_helper.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/renderer/favicon_helper.h" 5 #include "content/renderer/favicon_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "chrome/common/chrome_constants.h" 10 #include "content/common/icon_messages.h"
10 #include "chrome/common/favicon_url.h"
11 #include "chrome/common/icon_messages.h"
12 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
13 #include "net/base/data_url.h" 12 #include "net/base/data_url.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
17 #include "ui/base/ui_base_switches.h"
18 #include "ui/gfx/favicon_size.h" 18 #include "ui/gfx/favicon_size.h"
19 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
20 #include "ui/gfx/skbitmap_operations.h" 20 #include "ui/gfx/skbitmap_operations.h"
21 #include "webkit/glue/image_decoder.h" 21 #include "webkit/glue/image_decoder.h"
22 #include "webkit/glue/multi_resolution_image_resource_fetcher.h" 22 #include "webkit/glue/multi_resolution_image_resource_fetcher.h"
23 #include "webkit/glue/webkit_glue.h" 23 #include "webkit/glue/webkit_glue.h"
24 24
25 using WebKit::WebFrame; 25 using WebKit::WebFrame;
26 using WebKit::WebIconURL; 26 using WebKit::WebIconURL;
27 using WebKit::WebVector; 27 using WebKit::WebVector;
28 using WebKit::WebURL; 28 using WebKit::WebURL;
29 using WebKit::WebURLRequest; 29 using WebKit::WebURLRequest;
30 using webkit_glue::MultiResolutionImageResourceFetcher; 30 using webkit_glue::MultiResolutionImageResourceFetcher;
31 31
32 namespace content {
33
34 namespace {
35 bool TouchEnabled() {
36 // Based on the definition of chrome::kEnableTouchIcon.
37 #if defined(OS_ANDROID)
38 return true;
39 #else
40 return false;
41 #endif
42 }
43
44 } // namespace
45
46
32 static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { 47 static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) {
33 switch (type) { 48 switch (type) {
34 case WebIconURL::TypeFavicon: 49 case WebIconURL::TypeFavicon:
35 return FaviconURL::FAVICON; 50 return FaviconURL::FAVICON;
36 case WebIconURL::TypeTouch: 51 case WebIconURL::TypeTouch:
37 return FaviconURL::TOUCH_ICON; 52 return FaviconURL::TOUCH_ICON;
38 case WebIconURL::TypeTouchPrecomposed: 53 case WebIconURL::TypeTouchPrecomposed:
39 return FaviconURL::TOUCH_PRECOMPOSED_ICON; 54 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
40 case WebIconURL::TypeInvalid: 55 case WebIconURL::TypeInvalid:
41 return FaviconURL::INVALID_ICON; 56 return FaviconURL::INVALID_ICON;
42 } 57 }
43 return FaviconURL::INVALID_ICON; 58 return FaviconURL::INVALID_ICON;
44 } 59 }
45 60
46 FaviconHelper::FaviconHelper(content::RenderView* render_view) 61 FaviconHelper::FaviconHelper(RenderView* render_view)
47 : content::RenderViewObserver(render_view) { 62 : RenderViewObserver(render_view) {
63 }
64
65 void FaviconHelper::DidChangeIcon(WebKit::WebFrame* frame,
66 WebKit::WebIconURL::Type icon_type) {
67 if (frame->parent())
68 return;
69
70 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
71 return;
72
73 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
74 std::vector<FaviconURL> urls;
75 for (size_t i = 0; i < icon_urls.size(); i++) {
76 urls.push_back(FaviconURL(icon_urls[i].iconURL(),
77 ToFaviconType(icon_urls[i].iconType())));
78 }
79 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls);
48 } 80 }
49 81
50 FaviconHelper::~FaviconHelper() { 82 FaviconHelper::~FaviconHelper() {
51 } 83 }
52 84
53 void FaviconHelper::OnDownloadFavicon(int id, 85 void FaviconHelper::OnDownloadFavicon(int id,
54 const GURL& image_url, 86 const GURL& image_url,
55 int image_size) { 87 int image_size) {
56 std::vector<SkBitmap> result_images; 88 std::vector<SkBitmap> result_images;
57 if (image_url.SchemeIs("data")) { 89 if (image_url.SchemeIs("data")) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 IPC_BEGIN_MESSAGE_MAP(FaviconHelper, message) 164 IPC_BEGIN_MESSAGE_MAP(FaviconHelper, message)
133 IPC_MESSAGE_HANDLER(IconMsg_DownloadFavicon, OnDownloadFavicon) 165 IPC_MESSAGE_HANDLER(IconMsg_DownloadFavicon, OnDownloadFavicon)
134 IPC_MESSAGE_UNHANDLED(handled = false) 166 IPC_MESSAGE_UNHANDLED(handled = false)
135 IPC_END_MESSAGE_MAP() 167 IPC_END_MESSAGE_MAP()
136 168
137 return handled; 169 return handled;
138 } 170 }
139 171
140 void FaviconHelper::DidStopLoading() { 172 void FaviconHelper::DidStopLoading() {
141 int icon_types = WebIconURL::TypeFavicon; 173 int icon_types = WebIconURL::TypeFavicon;
142 if (chrome::kEnableTouchIcon) 174 if (TouchEnabled())
143 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; 175 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
144 176
145 WebVector<WebIconURL> icon_urls = 177 WebVector<WebIconURL> icon_urls =
146 render_view()->GetWebView()->mainFrame()->iconURLs(icon_types); 178 render_view()->GetWebView()->mainFrame()->iconURLs(icon_types);
147 std::vector<FaviconURL> urls; 179 std::vector<FaviconURL> urls;
148 for (size_t i = 0; i < icon_urls.size(); i++) { 180 for (size_t i = 0; i < icon_urls.size(); i++) {
149 WebURL url = icon_urls[i].iconURL(); 181 WebURL url = icon_urls[i].iconURL();
150 if (!url.isEmpty()) 182 if (!url.isEmpty())
151 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); 183 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType())));
152 } 184 }
153 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); 185 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls);
154 } 186 }
155 187
156 void FaviconHelper::DidChangeIcon(WebKit::WebFrame* frame, 188 } // namespace content
157 WebKit::WebIconURL::Type icon_type) {
158 if (frame->parent())
159 return;
160
161 if (!chrome::kEnableTouchIcon &&
162 icon_type != WebIconURL::TypeFavicon)
163 return;
164
165 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
166 std::vector<FaviconURL> urls;
167 for (size_t i = 0; i < icon_urls.size(); i++) {
168 urls.push_back(FaviconURL(icon_urls[i].iconURL(),
169 ToFaviconType(icon_urls[i].iconType())));
170 }
171 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls);
172 }
OLDNEW
« no previous file with comments | « content/renderer/favicon_helper.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698