| 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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 scoped_id_(CreateScopedIdentifier(extension_id, id)), | 128 scoped_id_(CreateScopedIdentifier(extension_id, id)), |
| 129 process_id_(-1) { | 129 process_id_(-1) { |
| 130 DCHECK(api_function_.get()); | 130 DCHECK(api_function_.get()); |
| 131 if (api_function_->render_view_host()) | 131 if (api_function_->render_view_host()) |
| 132 process_id_ = api_function->render_view_host()->GetProcess()->GetID(); | 132 process_id_ = api_function->render_view_host()->GetProcess()->GetID(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 virtual void Display() OVERRIDE { } | 135 virtual void Display() OVERRIDE { } |
| 136 | 136 |
| 137 virtual void Error() OVERRIDE { | 137 virtual void Error() OVERRIDE { |
| 138 scoped_ptr<ListValue> args(CreateBaseEventArgs()); | 138 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); |
| 139 SendEvent(event_names::kOnNotificationError, args.Pass()); | 139 SendEvent(event_names::kOnNotificationError, args.Pass()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 virtual void Close(bool by_user) OVERRIDE { | 142 virtual void Close(bool by_user) OVERRIDE { |
| 143 scoped_ptr<ListValue> args(CreateBaseEventArgs()); | 143 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); |
| 144 args->Append(Value::CreateBooleanValue(by_user)); | 144 args->Append(Value::CreateBooleanValue(by_user)); |
| 145 SendEvent(event_names::kOnNotificationClosed, args.Pass()); | 145 SendEvent(event_names::kOnNotificationClosed, args.Pass()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 virtual void Click() OVERRIDE { | 148 virtual void Click() OVERRIDE { |
| 149 scoped_ptr<ListValue> args(CreateBaseEventArgs()); | 149 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); |
| 150 SendEvent(event_names::kOnNotificationClicked, args.Pass()); | 150 SendEvent(event_names::kOnNotificationClicked, args.Pass()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 virtual bool HasClickedListener() OVERRIDE { | 153 virtual bool HasClickedListener() OVERRIDE { |
| 154 return ExtensionSystem::Get(profile_)->event_router()->HasEventListener( | 154 return ExtensionSystem::Get(profile_)->event_router()->HasEventListener( |
| 155 event_names::kOnNotificationClicked); | 155 event_names::kOnNotificationClicked); |
| 156 } | 156 } |
| 157 | 157 |
| 158 virtual void ButtonClick(int index) OVERRIDE { | 158 virtual void ButtonClick(int index) OVERRIDE { |
| 159 scoped_ptr<ListValue> args(CreateBaseEventArgs()); | 159 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); |
| 160 args->Append(Value::CreateIntegerValue(index)); | 160 args->Append(Value::CreateIntegerValue(index)); |
| 161 SendEvent(event_names::kOnNotificationButtonClicked, args.Pass()); | 161 SendEvent(event_names::kOnNotificationButtonClicked, args.Pass()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 virtual std::string id() const OVERRIDE { | 164 virtual std::string id() const OVERRIDE { |
| 165 return scoped_id_; | 165 return scoped_id_; |
| 166 } | 166 } |
| 167 | 167 |
| 168 virtual int process_id() const OVERRIDE { | 168 virtual int process_id() const OVERRIDE { |
| 169 return process_id_; | 169 return process_id_; |
| 170 } | 170 } |
| 171 | 171 |
| 172 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { | 172 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { |
| 173 // We're holding a reference to api_function_, so we know it'll be valid | 173 // We're holding a reference to api_function_, so we know it'll be valid |
| 174 // until ReleaseRVH is called, and api_function_ (as a | 174 // until ReleaseRVH is called, and api_function_ (as a |
| 175 // UIThreadExtensionFunction) will zero out its copy of render_view_host | 175 // UIThreadExtensionFunction) will zero out its copy of render_view_host |
| 176 // when the RVH goes away. | 176 // when the RVH goes away. |
| 177 if (!api_function_.get()) | 177 if (!api_function_.get()) |
| 178 return NULL; | 178 return NULL; |
| 179 return api_function_->render_view_host(); | 179 return api_function_->render_view_host(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 virtual void ReleaseRenderViewHost() OVERRIDE { | 182 virtual void ReleaseRenderViewHost() OVERRIDE { |
| 183 api_function_ = NULL; | 183 api_function_ = NULL; |
| 184 } | 184 } |
| 185 | 185 |
| 186 private: | 186 private: |
| 187 virtual ~NotificationsApiDelegate() {} | 187 virtual ~NotificationsApiDelegate() {} |
| 188 | 188 |
| 189 void SendEvent(const std::string& name, scoped_ptr<ListValue> args) { | 189 void SendEvent(const std::string& name, scoped_ptr<base::ListValue> args) { |
| 190 scoped_ptr<Event> event(new Event(name, args.Pass())); | 190 scoped_ptr<Event> event(new Event(name, args.Pass())); |
| 191 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 191 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( |
| 192 extension_id_, event.Pass()); | 192 extension_id_, event.Pass()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 scoped_ptr<ListValue> CreateBaseEventArgs() { | 195 scoped_ptr<base::ListValue> CreateBaseEventArgs() { |
| 196 scoped_ptr<ListValue> args(new ListValue()); | 196 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 197 args->Append(Value::CreateStringValue(id_)); | 197 args->Append(Value::CreateStringValue(id_)); |
| 198 return args.Pass(); | 198 return args.Pass(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 scoped_refptr<ApiFunction> api_function_; | 201 scoped_refptr<ApiFunction> api_function_; |
| 202 Profile* profile_; | 202 Profile* profile_; |
| 203 const std::string extension_id_; | 203 const std::string extension_id_; |
| 204 const std::string id_; | 204 const std::string id_; |
| 205 const std::string scoped_id_; | 205 const std::string scoped_id_; |
| 206 int process_id_; | 206 int process_id_; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 435 |
| 436 NotificationsGetAllFunction::~NotificationsGetAllFunction() {} | 436 NotificationsGetAllFunction::~NotificationsGetAllFunction() {} |
| 437 | 437 |
| 438 bool NotificationsGetAllFunction::RunNotificationsApi() { | 438 bool NotificationsGetAllFunction::RunNotificationsApi() { |
| 439 NotificationUIManager* notification_ui_manager = | 439 NotificationUIManager* notification_ui_manager = |
| 440 g_browser_process->notification_ui_manager(); | 440 g_browser_process->notification_ui_manager(); |
| 441 std::set<std::string> notification_ids = | 441 std::set<std::string> notification_ids = |
| 442 notification_ui_manager->GetAllIdsByProfileAndSourceOrigin( | 442 notification_ui_manager->GetAllIdsByProfileAndSourceOrigin( |
| 443 profile_, extension_->url()); | 443 profile_, extension_->url()); |
| 444 | 444 |
| 445 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 445 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 446 | 446 |
| 447 for (std::set<std::string>::iterator iter = notification_ids.begin(); | 447 for (std::set<std::string>::iterator iter = notification_ids.begin(); |
| 448 iter != notification_ids.end(); iter++) { | 448 iter != notification_ids.end(); iter++) { |
| 449 result->SetBooleanWithoutPathExpansion( | 449 result->SetBooleanWithoutPathExpansion( |
| 450 StripScopeFromIdentifier(extension_->id(), *iter), true); | 450 StripScopeFromIdentifier(extension_->id(), *iter), true); |
| 451 } | 451 } |
| 452 | 452 |
| 453 SetResult(result.release()); | 453 SetResult(result.release()); |
| 454 SendResponse(true); | 454 SendResponse(true); |
| 455 | 455 |
| 456 return true; | 456 return true; |
| 457 } | 457 } |
| 458 | 458 |
| 459 } // namespace extensions | 459 } // namespace extensions |
| OLD | NEW |