Chromium Code Reviews| Index: chrome/browser/extensions/api/notification/notification_api.cc |
| diff --git a/chrome/browser/extensions/api/notification/notification_api.cc b/chrome/browser/extensions/api/notification/notification_api.cc |
| index 6c48ce182d0ffb71e4e97750f58aa5252865f3c0..b7eee809c0a584495d85511ea96b1b4346651025 100644 |
| --- a/chrome/browser/extensions/api/notification/notification_api.cc |
| +++ b/chrome/browser/extensions/api/notification/notification_api.cc |
| @@ -4,9 +4,62 @@ |
| #include "chrome/browser/extensions/api/notification/notification_api.h" |
| -#include "base/bind.h" |
| -#include "chrome/common/extensions/extension.h" |
| +#include "base/callback.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/extensions/api/api_resource_event_notifier.h" |
| #include "chrome/browser/extensions/extension_system.h" |
| +#include "chrome/browser/notifications/notification.h" |
| +#include "chrome/browser/notifications/notification_ui_manager.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "googleurl/src/gurl.h" |
| + |
| +const char kResultKey[] = "result"; |
| + |
| +namespace { |
| + |
| +class NotificationApiDelegate : public NotificationDelegate { |
| + public: |
| + explicit NotificationApiDelegate( |
| + extensions::ApiResourceEventNotifier* event_notifier) |
| + : event_notifier_(event_notifier) { |
| + } |
| + |
| + virtual void Display() OVERRIDE { |
| + // TODO(miket): propagate to JS |
| + } |
| + |
| + virtual void Error() OVERRIDE { |
| + // TODO(miket): propagate to JS |
| + } |
| + |
| + virtual void Close(bool by_user) OVERRIDE { |
| + // TODO(miket): propagate to JS |
| + } |
| + |
| + virtual void Click() OVERRIDE { |
| + // TODO(miket): propagate to JS |
| + } |
| + |
| + virtual std::string id() const OVERRIDE { |
| + // TODO(miket): implement |
| + return std::string(); |
| + } |
| + |
| + virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { |
| + // TODO(miket): required to handle icon |
| + return NULL; |
| + } |
| + |
| + private: |
| + virtual ~NotificationApiDelegate() {} |
| + |
| + extensions::ApiResourceEventNotifier* event_notifier_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NotificationApiDelegate); |
| +}; |
| + |
| +} // namespace |
| namespace extensions { |
| @@ -16,18 +69,33 @@ NotificationShowFunction::NotificationShowFunction() { |
| NotificationShowFunction::~NotificationShowFunction() { |
| } |
| -bool NotificationShowFunction::Prepare() { |
| +bool NotificationShowFunction::RunImpl() { |
| params_ = api::experimental_notification::Show::Params::Create(*args_); |
| EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| - return true; |
| -} |
| -void NotificationShowFunction::Work() { |
| - SetResult(Value::CreateBooleanValue(true)); |
| -} |
| + api::experimental_notification::ShowOptions* options = ¶ms_->options; |
| + scoped_ptr<DictionaryValue> options_dict(options->ToValue()); |
| + src_id_ = ExtractSrcId(options_dict.get()); |
|
dharcourt
2012/10/12 22:38:50
Presumably src_id will be used by the Notification
miket_OOO
2012/10/15 17:13:11
That's right. When an ApiResource is created, the
|
| + event_notifier_ = CreateEventNotifier(src_id_); |
| + |
| + GURL icon_url(UTF8ToUTF16(options->icon_url)); |
| + string16 title(UTF8ToUTF16(options->title)); |
| + string16 message(UTF8ToUTF16(options->message)); |
| + string16 replace_id(UTF8ToUTF16(options->replace_id)); |
| + |
| + Notification notification( |
| + GURL(), icon_url, title, message, WebKit::WebTextDirectionDefault, |
| + string16(), replace_id, |
| + new NotificationApiDelegate(event_notifier_)); |
| + g_browser_process->notification_ui_manager()->Add(notification, profile()); |
| -bool NotificationShowFunction::Respond() { |
| - return error_.empty(); |
| + // TODO(miket): why return a result if it's always true? |
| + DictionaryValue* result = new DictionaryValue(); |
| + result->SetBoolean(kResultKey, true); |
| + SetResult(result); |
| + SendResponse(true); |
|
asargent_no_longer_on_chrome
2012/10/15 19:26:25
nit: Since you always call SendResponse here, can'
|
| + |
| + return true; |
| } |
| } // namespace extensions |