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

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: 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
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"
24 #include "ipc/ipc_message.h" 22 #include "ipc/ipc_message.h"
25 #include "ipc/ipc_message_macros.h" 23 #include "ipc/ipc_message_macros.h"
26 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
27 #include "ui/message_center/message_center.h" 25 #include "ui/message_center/message_center.h"
28 #include "webkit/glue/image_resource_fetcher.h" 26 #include "webkit/glue/image_resource_fetcher.h"
29 27
30 namespace { 28 namespace {
31 29
32 const int kNotificationIconImageSize = 32; 30 const int kNotificationIconImageSize = 32;
33 31
34 message_center::MessageCenter* GetMessageCenter() { 32 message_center::MessageCenter* GetMessageCenter() {
35 return ash::Shell::GetInstance()->GetWebNotificationTray()->message_center(); 33 return ash::Shell::GetInstance()->GetWebNotificationTray()->message_center();
36 } 34 }
37 35
38 } // namespace 36 } // namespace
39 37
40 BalloonViewAsh::BalloonViewAsh(BalloonCollection* collection) 38 BalloonViewAsh::BalloonViewAsh(BalloonCollection* collection)
41 : collection_(collection), 39 : collection_(collection),
42 balloon_(NULL) { 40 balloon_(NULL),
41 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
43 } 42 }
44 43
45 BalloonViewAsh::~BalloonViewAsh() { 44 BalloonViewAsh::~BalloonViewAsh() {
46 } 45 }
47 46
48 // BalloonView interface. 47 // BalloonView interface.
49 void BalloonViewAsh::Show(Balloon* balloon) { 48 void BalloonViewAsh::Show(Balloon* balloon) {
50 balloon_ = balloon; 49 balloon_ = balloon;
51 const Notification& notification = balloon_->notification(); 50 const Notification& notification = balloon_->notification();
52 current_notification_id_ = notification.notification_id(); 51 current_notification_id_ = notification.notification_id();
(...skipping 30 matching lines...) Expand all
83 } 82 }
84 83
85 gfx::Size BalloonViewAsh::GetSize() const { 84 gfx::Size BalloonViewAsh::GetSize() const {
86 return gfx::Size(); 85 return gfx::Size();
87 } 86 }
88 87
89 BalloonHost* BalloonViewAsh::GetHost() const { 88 BalloonHost* BalloonViewAsh::GetHost() const {
90 return NULL; 89 return NULL;
91 } 90 }
92 91
92 void BalloonViewAsh::DidDownloadFavicon(
93 int id,
94 const GURL& image_url,
95 bool errored,
96 int requested_size,
97 const std::vector<SkBitmap>& bitmaps) {
98 if (id != current_download_id_ || bitmaps.empty())
99 return;
100 GetMessageCenter()->SetNotificationImage(
101 cached_notification_id_, gfx::ImageSkia(bitmaps[0]));
102 current_download_id_ = -1;
103 cached_notification_id_.clear();
104 }
105
93 void BalloonViewAsh::FetchIcon(const Notification& notification) { 106 void BalloonViewAsh::FetchIcon(const Notification& notification) {
94 if (!notification.icon().isNull()) { 107 if (!notification.icon().isNull()) {
95 GetMessageCenter()->SetNotificationImage( 108 GetMessageCenter()->SetNotificationImage(
96 notification.notification_id(), notification.icon()); 109 notification.notification_id(), notification.icon());
97 return; 110 return;
98 } 111 }
99 if (notification.icon_url().is_empty()) 112 if (notification.icon_url().is_empty())
100 return; 113 return;
101 content::RenderViewHost* rvh = notification.GetRenderViewHost(); 114 content::RenderViewHost* rvh = notification.GetRenderViewHost();
102 if (!rvh) { 115 if (!rvh) {
103 LOG(WARNING) << "Notification has icon url but no RenderViewHost"; 116 LOG(WARNING) << "Notification has icon url but no RenderViewHost";
104 return; 117 return;
105 } 118 }
106 content::WebContents* web_contents = 119 content::WebContents* web_contents =
107 content::WebContents::FromRenderViewHost(rvh); 120 content::WebContents::FromRenderViewHost(rvh);
108 if (!web_contents) { 121 if (!web_contents) {
109 LOG(WARNING) << "Notification has icon url but no WebContents"; 122 LOG(WARNING) << "Notification has icon url but no WebContents";
110 return; 123 return;
111 } 124 }
112 icon_fetcher_.reset(new FaviconDownloadHelper(web_contents, this)); 125 current_download_id_ = web_contents->DownloadFavicon(
113 current_download_id_ = icon_fetcher_->DownloadFavicon( 126 notification.icon_url(), kNotificationIconImageSize,
114 notification.icon_url(), kNotificationIconImageSize); 127 base::Bind(&BalloonViewAsh::DidDownloadFavicon,
128 weak_ptr_factory_.GetWeakPtr()));
115 cached_notification_id_ = notification.notification_id(); 129 cached_notification_id_ = notification.notification_id();
116 } 130 }
117 131
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) { 132 std::string BalloonViewAsh::GetExtensionId(Balloon* balloon) {
133 ExtensionService* extension_service = 133 ExtensionService* extension_service =
134 balloon_->profile()->GetExtensionService(); 134 balloon_->profile()->GetExtensionService();
135 const GURL& origin = balloon_->notification().origin_url(); 135 const GURL& origin = balloon_->notification().origin_url();
136 const extensions::Extension* extension = 136 const extensions::Extension* extension =
137 extension_service->extensions()->GetExtensionOrAppByURL( 137 extension_service->extensions()->GetExtensionOrAppByURL(
138 ExtensionURLInfo(origin)); 138 ExtensionURLInfo(origin));
139 if (extension) 139 if (extension)
140 return extension->id(); 140 return extension->id();
141 return std::string(); 141 return std::string();
142 } 142 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/balloon_view_ash.h ('k') | chrome/browser/ui/views/create_application_shortcut_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698