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/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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if (!rvh) { | 100 if (!rvh) { |
103 LOG(WARNING) << "Notification has icon url but no RenderViewHost"; | 101 LOG(WARNING) << "Notification has icon url but no RenderViewHost"; |
104 return; | 102 return; |
105 } | 103 } |
106 content::WebContents* web_contents = | 104 content::WebContents* web_contents = |
107 content::WebContents::FromRenderViewHost(rvh); | 105 content::WebContents::FromRenderViewHost(rvh); |
108 if (!web_contents) { | 106 if (!web_contents) { |
109 LOG(WARNING) << "Notification has icon url but no WebContents"; | 107 LOG(WARNING) << "Notification has icon url but no WebContents"; |
110 return; | 108 return; |
111 } | 109 } |
112 icon_fetcher_.reset(new FaviconDownloadHelper(web_contents, this)); | 110 web_contents->RegisterFaviconDelegate(this); |
113 current_download_id_ = icon_fetcher_->DownloadFavicon( | 111 current_download_id_ = web_contents->DownloadFavicon( |
114 notification.icon_url(), kNotificationIconImageSize); | 112 notification.icon_url(), kNotificationIconImageSize); |
115 cached_notification_id_ = notification.notification_id(); | 113 cached_notification_id_ = notification.notification_id(); |
116 } | 114 } |
117 | 115 |
118 void BalloonViewAsh::OnDidDownloadFavicon( | 116 void BalloonViewAsh::DidDownloadFavicon( |
119 int id, | 117 int id, |
120 const GURL& image_url, | 118 const GURL& image_url, |
121 bool errored, | 119 bool errored, |
122 int requested_size, | 120 int requested_size, |
123 const std::vector<SkBitmap>& bitmaps) { | 121 const std::vector<SkBitmap>& bitmaps) { |
124 if (id != current_download_id_ || bitmaps.empty()) | 122 if (id != current_download_id_ || bitmaps.empty()) |
125 return; | 123 return; |
126 GetMessageCenter()->SetNotificationImage( | 124 GetMessageCenter()->SetNotificationImage( |
127 cached_notification_id_, gfx::ImageSkia(bitmaps[0])); | 125 cached_notification_id_, gfx::ImageSkia(bitmaps[0])); |
128 current_download_id_ = -1; | 126 current_download_id_ = -1; |
129 cached_notification_id_.clear(); | 127 cached_notification_id_.clear(); |
130 } | 128 } |
131 | 129 |
132 std::string BalloonViewAsh::GetExtensionId(Balloon* balloon) { | 130 std::string BalloonViewAsh::GetExtensionId(Balloon* balloon) { |
133 ExtensionService* extension_service = | 131 ExtensionService* extension_service = |
134 balloon_->profile()->GetExtensionService(); | 132 balloon_->profile()->GetExtensionService(); |
135 const GURL& origin = balloon_->notification().origin_url(); | 133 const GURL& origin = balloon_->notification().origin_url(); |
136 const extensions::Extension* extension = | 134 const extensions::Extension* extension = |
137 extension_service->extensions()->GetExtensionOrAppByURL( | 135 extension_service->extensions()->GetExtensionOrAppByURL( |
138 ExtensionURLInfo(origin)); | 136 ExtensionURLInfo(origin)); |
139 if (extension) | 137 if (extension) |
140 return extension->id(); | 138 return extension->id(); |
141 return std::string(); | 139 return std::string(); |
142 } | 140 } |
OLD | NEW |