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/extensions/api/notifications/notifications_api.h" | 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/notifications/desktop_notification_service.h" | 14 #include "chrome/browser/notifications/desktop_notification_service.h" |
15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
17 #include "chrome/browser/notifications/notification_ui_manager.h" | 17 #include "chrome/browser/notifications/notification_ui_manager.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
22 #include "extensions/browser/event_router.h" | 22 #include "extensions/browser/event_router.h" |
23 #include "extensions/browser/extension_system.h" | |
24 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
25 #include "extensions/common/features/feature.h" | 24 #include "extensions/common/features/feature.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
28 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
29 #include "ui/gfx/image/image_skia_rep.h" | 28 #include "ui/gfx/image/image_skia_rep.h" |
30 #include "ui/message_center/message_center_style.h" | 29 #include "ui/message_center/message_center_style.h" |
31 #include "ui/message_center/message_center_util.h" | 30 #include "ui/message_center/message_center_util.h" |
32 #include "ui/message_center/notifier_settings.h" | 31 #include "ui/message_center/notifier_settings.h" |
33 #include "url/gurl.h" | 32 #include "url/gurl.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 args->Append(new base::FundamentalValue(by_user)); | 149 args->Append(new base::FundamentalValue(by_user)); |
151 SendEvent(notifications::OnClosed::kEventName, args.Pass()); | 150 SendEvent(notifications::OnClosed::kEventName, args.Pass()); |
152 } | 151 } |
153 | 152 |
154 virtual void Click() OVERRIDE { | 153 virtual void Click() OVERRIDE { |
155 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); | 154 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); |
156 SendEvent(notifications::OnClicked::kEventName, args.Pass()); | 155 SendEvent(notifications::OnClicked::kEventName, args.Pass()); |
157 } | 156 } |
158 | 157 |
159 virtual bool HasClickedListener() OVERRIDE { | 158 virtual bool HasClickedListener() OVERRIDE { |
160 return ExtensionSystem::Get(profile_)->event_router()->HasEventListener( | 159 return EventRouter::Get(profile_) |
161 notifications::OnClicked::kEventName); | 160 ->HasEventListener(notifications::OnClicked::kEventName); |
162 } | 161 } |
163 | 162 |
164 virtual void ButtonClick(int index) OVERRIDE { | 163 virtual void ButtonClick(int index) OVERRIDE { |
165 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); | 164 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); |
166 args->Append(new base::FundamentalValue(index)); | 165 args->Append(new base::FundamentalValue(index)); |
167 SendEvent(notifications::OnButtonClicked::kEventName, args.Pass()); | 166 SendEvent(notifications::OnButtonClicked::kEventName, args.Pass()); |
168 } | 167 } |
169 | 168 |
170 virtual std::string id() const OVERRIDE { | 169 virtual std::string id() const OVERRIDE { |
171 return scoped_id_; | 170 return scoped_id_; |
(...skipping 15 matching lines...) Expand all Loading... |
187 | 186 |
188 virtual void ReleaseRenderViewHost() OVERRIDE { | 187 virtual void ReleaseRenderViewHost() OVERRIDE { |
189 api_function_ = NULL; | 188 api_function_ = NULL; |
190 } | 189 } |
191 | 190 |
192 private: | 191 private: |
193 virtual ~NotificationsApiDelegate() {} | 192 virtual ~NotificationsApiDelegate() {} |
194 | 193 |
195 void SendEvent(const std::string& name, scoped_ptr<base::ListValue> args) { | 194 void SendEvent(const std::string& name, scoped_ptr<base::ListValue> args) { |
196 scoped_ptr<Event> event(new Event(name, args.Pass())); | 195 scoped_ptr<Event> event(new Event(name, args.Pass())); |
197 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 196 EventRouter::Get(profile_) |
198 extension_id_, event.Pass()); | 197 ->DispatchEventToExtension(extension_id_, event.Pass()); |
199 } | 198 } |
200 | 199 |
201 scoped_ptr<base::ListValue> CreateBaseEventArgs() { | 200 scoped_ptr<base::ListValue> CreateBaseEventArgs() { |
202 scoped_ptr<base::ListValue> args(new base::ListValue()); | 201 scoped_ptr<base::ListValue> args(new base::ListValue()); |
203 args->Append(new base::StringValue(id_)); | 202 args->Append(new base::StringValue(id_)); |
204 return args.Pass(); | 203 return args.Pass(); |
205 } | 204 } |
206 | 205 |
207 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; | 206 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; |
208 Profile* profile_; | 207 Profile* profile_; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 ? api::notifications::PERMISSION_LEVEL_GRANTED | 611 ? api::notifications::PERMISSION_LEVEL_GRANTED |
613 : api::notifications::PERMISSION_LEVEL_DENIED; | 612 : api::notifications::PERMISSION_LEVEL_DENIED; |
614 | 613 |
615 SetResult(new base::StringValue(api::notifications::ToString(result))); | 614 SetResult(new base::StringValue(api::notifications::ToString(result))); |
616 SendResponse(true); | 615 SendResponse(true); |
617 | 616 |
618 return true; | 617 return true; |
619 } | 618 } |
620 | 619 |
621 } // namespace extensions | 620 } // namespace extensions |
OLD | NEW |