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

Side by Side 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: 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 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/extensions/api/notification/notification_api.h" 5 #include "chrome/browser/extensions/api/notification/notification_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/callback.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/api/api_resource_event_notifier.h"
11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h"
8 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
9 #include "chrome/browser/extensions/extension_system.h" 15 #include "googleurl/src/gurl.h"
16
17 const char kResultKey[] = "result";
18
19 namespace {
20
21 class NotificationApiDelegate : public NotificationDelegate {
22 public:
23 explicit NotificationApiDelegate(
24 extensions::ApiResourceEventNotifier* event_notifier)
25 : event_notifier_(event_notifier) {
26 }
27
28 virtual void Display() OVERRIDE {
29 // TODO(miket): propagate to JS
30 }
31
32 virtual void Error() OVERRIDE {
33 // TODO(miket): propagate to JS
34 }
35
36 virtual void Close(bool by_user) OVERRIDE {
37 // TODO(miket): propagate to JS
38 }
39
40 virtual void Click() OVERRIDE {
41 // TODO(miket): propagate to JS
42 }
43
44 virtual std::string id() const OVERRIDE {
45 // TODO(miket): implement
46 return std::string();
47 }
48
49 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE {
50 // TODO(miket): required to handle icon
51 return NULL;
52 }
53
54 private:
55 virtual ~NotificationApiDelegate() {}
56
57 extensions::ApiResourceEventNotifier* event_notifier_;
58
59 DISALLOW_COPY_AND_ASSIGN(NotificationApiDelegate);
60 };
61
62 } // namespace
10 63
11 namespace extensions { 64 namespace extensions {
12 65
13 NotificationShowFunction::NotificationShowFunction() { 66 NotificationShowFunction::NotificationShowFunction() {
14 } 67 }
15 68
16 NotificationShowFunction::~NotificationShowFunction() { 69 NotificationShowFunction::~NotificationShowFunction() {
17 } 70 }
18 71
19 bool NotificationShowFunction::Prepare() { 72 bool NotificationShowFunction::RunImpl() {
20 params_ = api::experimental_notification::Show::Params::Create(*args_); 73 params_ = api::experimental_notification::Show::Params::Create(*args_);
21 EXTENSION_FUNCTION_VALIDATE(params_.get()); 74 EXTENSION_FUNCTION_VALIDATE(params_.get());
75
76 api::experimental_notification::ShowOptions* options = &params_->options;
77 scoped_ptr<DictionaryValue> options_dict(options->ToValue());
78 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
79 event_notifier_ = CreateEventNotifier(src_id_);
80
81 GURL icon_url(UTF8ToUTF16(options->icon_url));
82 string16 title(UTF8ToUTF16(options->title));
83 string16 message(UTF8ToUTF16(options->message));
84 string16 replace_id(UTF8ToUTF16(options->replace_id));
85
86 Notification notification(
87 GURL(), icon_url, title, message, WebKit::WebTextDirectionDefault,
88 string16(), replace_id,
89 new NotificationApiDelegate(event_notifier_));
90 g_browser_process->notification_ui_manager()->Add(notification, profile());
91
92 // TODO(miket): why return a result if it's always true?
93 DictionaryValue* result = new DictionaryValue();
94 result->SetBoolean(kResultKey, true);
95 SetResult(result);
96 SendResponse(true);
asargent_no_longer_on_chrome 2012/10/15 19:26:25 nit: Since you always call SendResponse here, can'
97
22 return true; 98 return true;
23 } 99 }
24 100
25 void NotificationShowFunction::Work() {
26 SetResult(Value::CreateBooleanValue(true));
27 }
28
29 bool NotificationShowFunction::Respond() {
30 return error_.empty();
31 }
32
33 } // namespace extensions 101 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698