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

Unified Diff: chrome/browser/extensions/api/notification/notification_api.cc

Issue 11116016: Hook up API to notification_ui_manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asargent review suggestion Created 8 years, 2 months 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 side-by-side diff with in-line comments
Download patch
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 = &params_->options;
+ scoped_ptr<DictionaryValue> options_dict(options->ToValue());
+ src_id_ = ExtractSrcId(options_dict.get());
+ 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);
+
+ return true;
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698