OLD | NEW |
---|---|
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 "content/public/common/favicon_url.h" |
jam
2012/12/03 21:59:39
nit: redundant since by definition icon_messages.h
Cait (Slow)
2012/12/04 20:57:35
Done.
| |
11 #include "chrome/common/icon_messages.h" | |
12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
13 #include "net/base/data_url.h" | 13 #include "net/base/data_url.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" | 18 #include "ui/base/ui_base_switches.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | |
18 #include "ui/gfx/favicon_size.h" | 19 #include "ui/gfx/favicon_size.h" |
19 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
20 #include "ui/gfx/skbitmap_operations.h" | 21 #include "ui/gfx/skbitmap_operations.h" |
21 #include "webkit/glue/image_decoder.h" | 22 #include "webkit/glue/image_decoder.h" |
22 #include "webkit/glue/multi_resolution_image_resource_fetcher.h" | 23 #include "webkit/glue/multi_resolution_image_resource_fetcher.h" |
23 #include "webkit/glue/webkit_glue.h" | 24 #include "webkit/glue/webkit_glue.h" |
24 | 25 |
25 using WebKit::WebFrame; | 26 using WebKit::WebFrame; |
26 using WebKit::WebIconURL; | 27 using WebKit::WebIconURL; |
27 using WebKit::WebVector; | 28 using WebKit::WebVector; |
28 using WebKit::WebURL; | 29 using WebKit::WebURL; |
29 using WebKit::WebURLRequest; | 30 using WebKit::WebURLRequest; |
30 using webkit_glue::MultiResolutionImageResourceFetcher; | 31 using webkit_glue::MultiResolutionImageResourceFetcher; |
31 | 32 |
33 namespace content { | |
34 | |
35 namespace { | |
36 bool TouchEnabled() { | |
37 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
38 return (cmdline->HasSwitch(switches::kTouchEvents) && | |
39 cmdline->GetSwitchValueASCII(switches::kTouchEvents) == | |
40 switches::kTouchEventsEnabled); | |
41 } | |
42 } // namespace | |
43 | |
44 | |
32 static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { | 45 static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { |
33 switch (type) { | 46 switch (type) { |
34 case WebIconURL::TypeFavicon: | 47 case WebIconURL::TypeFavicon: |
35 return FaviconURL::FAVICON; | 48 return FaviconURL::FAVICON; |
36 case WebIconURL::TypeTouch: | 49 case WebIconURL::TypeTouch: |
37 return FaviconURL::TOUCH_ICON; | 50 return FaviconURL::TOUCH_ICON; |
38 case WebIconURL::TypeTouchPrecomposed: | 51 case WebIconURL::TypeTouchPrecomposed: |
39 return FaviconURL::TOUCH_PRECOMPOSED_ICON; | 52 return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
40 case WebIconURL::TypeInvalid: | 53 case WebIconURL::TypeInvalid: |
41 return FaviconURL::INVALID_ICON; | 54 return FaviconURL::INVALID_ICON; |
42 } | 55 } |
43 return FaviconURL::INVALID_ICON; | 56 return FaviconURL::INVALID_ICON; |
44 } | 57 } |
45 | 58 |
46 FaviconHelper::FaviconHelper(content::RenderView* render_view) | 59 FaviconHelper::FaviconHelper(RenderView* render_view) |
47 : content::RenderViewObserver(render_view) { | 60 : RenderViewObserver(render_view) { |
48 } | 61 } |
49 | 62 |
50 FaviconHelper::~FaviconHelper() { | 63 FaviconHelper::~FaviconHelper() { |
51 } | 64 } |
52 | 65 |
53 void FaviconHelper::OnDownloadFavicon(int id, | 66 void FaviconHelper::OnDownloadFavicon(int id, |
54 const GURL& image_url, | 67 const GURL& image_url, |
55 int image_size) { | 68 int image_size) { |
56 std::vector<SkBitmap> result_images; | 69 std::vector<SkBitmap> result_images; |
57 if (image_url.SchemeIs("data")) { | 70 if (image_url.SchemeIs("data")) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 IPC_BEGIN_MESSAGE_MAP(FaviconHelper, message) | 145 IPC_BEGIN_MESSAGE_MAP(FaviconHelper, message) |
133 IPC_MESSAGE_HANDLER(IconMsg_DownloadFavicon, OnDownloadFavicon) | 146 IPC_MESSAGE_HANDLER(IconMsg_DownloadFavicon, OnDownloadFavicon) |
134 IPC_MESSAGE_UNHANDLED(handled = false) | 147 IPC_MESSAGE_UNHANDLED(handled = false) |
135 IPC_END_MESSAGE_MAP() | 148 IPC_END_MESSAGE_MAP() |
136 | 149 |
137 return handled; | 150 return handled; |
138 } | 151 } |
139 | 152 |
140 void FaviconHelper::DidStopLoading() { | 153 void FaviconHelper::DidStopLoading() { |
141 int icon_types = WebIconURL::TypeFavicon; | 154 int icon_types = WebIconURL::TypeFavicon; |
142 if (chrome::kEnableTouchIcon) | 155 if (TouchEnabled()) |
143 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; | 156 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
144 | 157 |
145 WebVector<WebIconURL> icon_urls = | 158 WebVector<WebIconURL> icon_urls = |
146 render_view()->GetWebView()->mainFrame()->iconURLs(icon_types); | 159 render_view()->GetWebView()->mainFrame()->iconURLs(icon_types); |
147 std::vector<FaviconURL> urls; | 160 std::vector<FaviconURL> urls; |
148 for (size_t i = 0; i < icon_urls.size(); i++) { | 161 for (size_t i = 0; i < icon_urls.size(); i++) { |
149 WebURL url = icon_urls[i].iconURL(); | 162 WebURL url = icon_urls[i].iconURL(); |
150 if (!url.isEmpty()) | 163 if (!url.isEmpty()) |
151 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); | 164 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); |
152 } | 165 } |
153 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); | 166 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); |
154 } | 167 } |
155 | 168 |
156 void FaviconHelper::DidChangeIcon(WebKit::WebFrame* frame, | 169 void FaviconHelper::DidChangeIcon(WebKit::WebFrame* frame, |
157 WebKit::WebIconURL::Type icon_type) { | 170 WebKit::WebIconURL::Type icon_type) { |
158 if (frame->parent()) | 171 if (frame->parent()) |
159 return; | 172 return; |
160 | 173 |
161 if (!chrome::kEnableTouchIcon && | 174 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon) |
162 icon_type != WebIconURL::TypeFavicon) | |
163 return; | 175 return; |
164 | 176 |
165 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); | 177 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
166 std::vector<FaviconURL> urls; | 178 std::vector<FaviconURL> urls; |
167 for (size_t i = 0; i < icon_urls.size(); i++) { | 179 for (size_t i = 0; i < icon_urls.size(); i++) { |
168 urls.push_back(FaviconURL(icon_urls[i].iconURL(), | 180 urls.push_back(FaviconURL(icon_urls[i].iconURL(), |
169 ToFaviconType(icon_urls[i].iconType()))); | 181 ToFaviconType(icon_urls[i].iconType()))); |
170 } | 182 } |
171 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); | 183 SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls); |
172 } | 184 } |
185 | |
186 } // namespace content | |
OLD | NEW |