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

Side by Side Diff: chrome/browser/ui/views/ash/balloon_view_ash.cc

Issue 11411180: move favicon download code from chrome/ into content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WebContentsObserver and callback 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
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/browser/ui/views/ash/balloon_view_ash.h" 5 #include "chrome/browser/ui/views/ash/balloon_view_ash.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/web_notification/web_notification_tray.h" 8 #include "ash/system/web_notification/web_notification_tray.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/favicon/favicon_download_helper.h"
13 #include "chrome/browser/favicon/favicon_util.h" 12 #include "chrome/browser/favicon/favicon_util.h"
14 #include "chrome/browser/notifications/balloon_collection.h" 13 #include "chrome/browser/notifications/balloon_collection.h"
15 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
16 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/icon_messages.h"
18 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/site_instance.h" 18 #include "content/public/browser/site_instance.h"
21 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_contents_delegate.h" 20 #include "content/public/browser/web_contents_delegate.h"
23 #include "content/public/browser/web_contents_observer.h" 21 #include "content/public/browser/web_contents_observer.h"
22 #include "googleurl/src/gurl.h"
jam 2012/12/03 21:59:39 this is pretty redundant to include, by definition
Cait (Slow) 2012/12/04 20:57:35 Done.
24 #include "ipc/ipc_message.h" 23 #include "ipc/ipc_message.h"
25 #include "ipc/ipc_message_macros.h" 24 #include "ipc/ipc_message_macros.h"
25 #include "third_party/skia/include/core/SkBitmap.h"
jam 2012/12/03 21:59:39 ditto
Cait (Slow) 2012/12/04 20:57:35 Done.
26 #include "ui/gfx/image/image_skia.h" 26 #include "ui/gfx/image/image_skia.h"
27 #include "ui/message_center/message_center.h" 27 #include "ui/message_center/message_center.h"
28 #include "webkit/glue/image_resource_fetcher.h" 28 #include "webkit/glue/image_resource_fetcher.h"
29 29
30 namespace { 30 namespace {
31 31
32 const int kNotificationIconImageSize = 32; 32 const int kNotificationIconImageSize = 32;
33 33
34 message_center::MessageCenter* GetMessageCenter() { 34 message_center::MessageCenter* GetMessageCenter() {
35 return ash::Shell::GetInstance()->GetWebNotificationTray()->message_center(); 35 return ash::Shell::GetInstance()->GetWebNotificationTray()->message_center();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 gfx::Size BalloonViewAsh::GetSize() const { 85 gfx::Size BalloonViewAsh::GetSize() const {
86 return gfx::Size(); 86 return gfx::Size();
87 } 87 }
88 88
89 BalloonHost* BalloonViewAsh::GetHost() const { 89 BalloonHost* BalloonViewAsh::GetHost() const {
90 return NULL; 90 return NULL;
91 } 91 }
92 92
93 void BalloonViewAsh::DidDownloadFavicon(
94 int id,
95 const GURL& image_url,
96 bool errored,
97 int requested_size,
98 const std::vector<SkBitmap>& bitmaps) {
99 if (id != current_download_id_ || bitmaps.empty())
100 return;
101 GetMessageCenter()->SetNotificationImage(
102 cached_notification_id_, gfx::ImageSkia(bitmaps[0]));
103 current_download_id_ = -1;
104 cached_notification_id_.clear();
105 }
106
93 void BalloonViewAsh::FetchIcon(const Notification& notification) { 107 void BalloonViewAsh::FetchIcon(const Notification& notification) {
94 if (!notification.icon().isNull()) { 108 if (!notification.icon().isNull()) {
95 GetMessageCenter()->SetNotificationImage( 109 GetMessageCenter()->SetNotificationImage(
96 notification.notification_id(), notification.icon()); 110 notification.notification_id(), notification.icon());
97 return; 111 return;
98 } 112 }
99 if (notification.icon_url().is_empty()) 113 if (notification.icon_url().is_empty())
100 return; 114 return;
101 content::RenderViewHost* rvh = notification.GetRenderViewHost(); 115 content::RenderViewHost* rvh = notification.GetRenderViewHost();
102 if (!rvh) { 116 if (!rvh) {
103 LOG(WARNING) << "Notification has icon url but no RenderViewHost"; 117 LOG(WARNING) << "Notification has icon url but no RenderViewHost";
104 return; 118 return;
105 } 119 }
106 content::WebContents* web_contents = 120 content::WebContents* web_contents =
107 content::WebContents::FromRenderViewHost(rvh); 121 content::WebContents::FromRenderViewHost(rvh);
108 if (!web_contents) { 122 if (!web_contents) {
109 LOG(WARNING) << "Notification has icon url but no WebContents"; 123 LOG(WARNING) << "Notification has icon url but no WebContents";
110 return; 124 return;
111 } 125 }
112 icon_fetcher_.reset(new FaviconDownloadHelper(web_contents, this)); 126 current_download_id_ = web_contents->DownloadFavicon(
113 current_download_id_ = icon_fetcher_->DownloadFavicon( 127 notification.icon_url(), kNotificationIconImageSize,
114 notification.icon_url(), kNotificationIconImageSize); 128 base::Bind(&BalloonViewAsh::DidDownloadFavicon,
129 base::Unretained(this)));
jam 2012/12/03 21:59:39 are you sure that this object will outlive web_con
115 cached_notification_id_ = notification.notification_id(); 130 cached_notification_id_ = notification.notification_id();
116 } 131 }
117 132
118 void BalloonViewAsh::OnDidDownloadFavicon(
119 int id,
120 const GURL& image_url,
121 bool errored,
122 int requested_size,
123 const std::vector<SkBitmap>& bitmaps) {
124 if (id != current_download_id_ || bitmaps.empty())
125 return;
126 GetMessageCenter()->SetNotificationImage(
127 cached_notification_id_, gfx::ImageSkia(bitmaps[0]));
128 current_download_id_ = -1;
129 cached_notification_id_.clear();
130 }
131
132 std::string BalloonViewAsh::GetExtensionId(Balloon* balloon) { 133 std::string BalloonViewAsh::GetExtensionId(Balloon* balloon) {
133 ExtensionService* extension_service = 134 ExtensionService* extension_service =
134 balloon_->profile()->GetExtensionService(); 135 balloon_->profile()->GetExtensionService();
135 const GURL& origin = balloon_->notification().origin_url(); 136 const GURL& origin = balloon_->notification().origin_url();
136 const extensions::Extension* extension = 137 const extensions::Extension* extension =
137 extension_service->extensions()->GetExtensionOrAppByURL( 138 extension_service->extensions()->GetExtensionOrAppByURL(
138 ExtensionURLInfo(origin)); 139 ExtensionURLInfo(origin));
139 if (extension) 140 if (extension)
140 return extension->id(); 141 return extension->id();
141 return std::string(); 142 return std::string();
142 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698