| 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" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 args->Append(new base::FundamentalValue(index)); | 115 args->Append(new base::FundamentalValue(index)); |
| 116 SendEvent(notifications::OnButtonClicked::kEventName, | 116 SendEvent(notifications::OnButtonClicked::kEventName, |
| 117 EventRouter::USER_GESTURE_ENABLED, | 117 EventRouter::USER_GESTURE_ENABLED, |
| 118 args.Pass()); | 118 args.Pass()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 virtual std::string id() const OVERRIDE { | 121 virtual std::string id() const OVERRIDE { |
| 122 return scoped_id_; | 122 return scoped_id_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 virtual content::WebContents* GetWebContents() const OVERRIDE { | |
| 126 // We're holding a reference to api_function_, so we know it'll be valid | |
| 127 // until ReleaseRVH is called, and api_function_ (as a | |
| 128 // AsyncExtensionFunction) will zero out its copy of render_view_host | |
| 129 // when the RVH goes away. | |
| 130 if (!api_function_.get()) | |
| 131 return NULL; | |
| 132 content::RenderViewHost* rvh = api_function_->render_view_host(); | |
| 133 if (!rvh) | |
| 134 return NULL; | |
| 135 return content::WebContents::FromRenderViewHost(rvh); | |
| 136 } | |
| 137 | |
| 138 virtual void ReleaseRenderViewHost() OVERRIDE { | |
| 139 api_function_ = NULL; | |
| 140 } | |
| 141 | |
| 142 private: | 125 private: |
| 143 virtual ~NotificationsApiDelegate() {} | 126 virtual ~NotificationsApiDelegate() {} |
| 144 | 127 |
| 145 void SendEvent(const std::string& name, | 128 void SendEvent(const std::string& name, |
| 146 EventRouter::UserGestureState user_gesture, | 129 EventRouter::UserGestureState user_gesture, |
| 147 scoped_ptr<base::ListValue> args) { | 130 scoped_ptr<base::ListValue> args) { |
| 148 scoped_ptr<Event> event(new Event(name, args.Pass())); | 131 scoped_ptr<Event> event(new Event(name, args.Pass())); |
| 149 event->user_gesture = user_gesture; | 132 event->user_gesture = user_gesture; |
| 150 EventRouter::Get(profile_)->DispatchEventToExtension(extension_id_, | 133 EventRouter::Get(profile_)->DispatchEventToExtension(extension_id_, |
| 151 event.Pass()); | 134 event.Pass()); |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 ? api::notifications::PERMISSION_LEVEL_GRANTED | 605 ? api::notifications::PERMISSION_LEVEL_GRANTED |
| 623 : api::notifications::PERMISSION_LEVEL_DENIED; | 606 : api::notifications::PERMISSION_LEVEL_DENIED; |
| 624 | 607 |
| 625 SetResult(new base::StringValue(api::notifications::ToString(result))); | 608 SetResult(new base::StringValue(api::notifications::ToString(result))); |
| 626 SendResponse(true); | 609 SendResponse(true); |
| 627 | 610 |
| 628 return true; | 611 return true; |
| 629 } | 612 } |
| 630 | 613 |
| 631 } // namespace extensions | 614 } // namespace extensions |
| OLD | NEW |