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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 class NotificationsApiDelegate : public NotificationDelegate { | 74 class NotificationsApiDelegate : public NotificationDelegate { |
75 public: | 75 public: |
76 NotificationsApiDelegate(ChromeAsyncExtensionFunction* api_function, | 76 NotificationsApiDelegate(ChromeAsyncExtensionFunction* api_function, |
77 Profile* profile, | 77 Profile* profile, |
78 const std::string& extension_id, | 78 const std::string& extension_id, |
79 const std::string& id) | 79 const std::string& id) |
80 : api_function_(api_function), | 80 : api_function_(api_function), |
81 profile_(profile), | 81 profile_(profile), |
82 extension_id_(extension_id), | 82 extension_id_(extension_id), |
83 id_(id), | 83 id_(id), |
84 scoped_id_(CreateScopedIdentifier(extension_id, id)), | 84 scoped_id_(CreateScopedIdentifier(extension_id, id)) { |
85 process_id_(-1) { | |
86 DCHECK(api_function_.get()); | 85 DCHECK(api_function_.get()); |
87 if (api_function_->render_view_host()) | |
88 process_id_ = api_function->render_view_host()->GetProcess()->GetID(); | |
89 } | 86 } |
90 | 87 |
91 virtual void Display() OVERRIDE { } | 88 virtual void Display() OVERRIDE { } |
92 | 89 |
93 virtual void Error() OVERRIDE {} | 90 virtual void Error() OVERRIDE {} |
94 | 91 |
95 virtual void Close(bool by_user) OVERRIDE { | 92 virtual void Close(bool by_user) OVERRIDE { |
96 EventRouter::UserGestureState gesture = | 93 EventRouter::UserGestureState gesture = |
97 by_user ? EventRouter::USER_GESTURE_ENABLED | 94 by_user ? EventRouter::USER_GESTURE_ENABLED |
98 : EventRouter::USER_GESTURE_NOT_ENABLED; | 95 : EventRouter::USER_GESTURE_NOT_ENABLED; |
(...skipping 19 matching lines...) Expand all Loading... |
118 args->Append(new base::FundamentalValue(index)); | 115 args->Append(new base::FundamentalValue(index)); |
119 SendEvent(notifications::OnButtonClicked::kEventName, | 116 SendEvent(notifications::OnButtonClicked::kEventName, |
120 EventRouter::USER_GESTURE_ENABLED, | 117 EventRouter::USER_GESTURE_ENABLED, |
121 args.Pass()); | 118 args.Pass()); |
122 } | 119 } |
123 | 120 |
124 virtual std::string id() const OVERRIDE { | 121 virtual std::string id() const OVERRIDE { |
125 return scoped_id_; | 122 return scoped_id_; |
126 } | 123 } |
127 | 124 |
128 virtual int process_id() const OVERRIDE { | |
129 return process_id_; | |
130 } | |
131 | |
132 virtual content::WebContents* GetWebContents() const OVERRIDE { | 125 virtual content::WebContents* GetWebContents() const OVERRIDE { |
133 // We're holding a reference to api_function_, so we know it'll be valid | 126 // We're holding a reference to api_function_, so we know it'll be valid |
134 // until ReleaseRVH is called, and api_function_ (as a | 127 // until ReleaseRVH is called, and api_function_ (as a |
135 // AsyncExtensionFunction) will zero out its copy of render_view_host | 128 // AsyncExtensionFunction) will zero out its copy of render_view_host |
136 // when the RVH goes away. | 129 // when the RVH goes away. |
137 if (!api_function_.get()) | 130 if (!api_function_.get()) |
138 return NULL; | 131 return NULL; |
139 content::RenderViewHost* rvh = api_function_->render_view_host(); | 132 content::RenderViewHost* rvh = api_function_->render_view_host(); |
140 if (!rvh) | 133 if (!rvh) |
141 return NULL; | 134 return NULL; |
(...skipping 20 matching lines...) Expand all Loading... |
162 scoped_ptr<base::ListValue> args(new base::ListValue()); | 155 scoped_ptr<base::ListValue> args(new base::ListValue()); |
163 args->Append(new base::StringValue(id_)); | 156 args->Append(new base::StringValue(id_)); |
164 return args.Pass(); | 157 return args.Pass(); |
165 } | 158 } |
166 | 159 |
167 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; | 160 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; |
168 Profile* profile_; | 161 Profile* profile_; |
169 const std::string extension_id_; | 162 const std::string extension_id_; |
170 const std::string id_; | 163 const std::string id_; |
171 const std::string scoped_id_; | 164 const std::string scoped_id_; |
172 int process_id_; | |
173 | 165 |
174 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate); | 166 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate); |
175 }; | 167 }; |
176 | 168 |
177 } // namespace | 169 } // namespace |
178 | 170 |
179 bool NotificationsApiFunction::IsNotificationsApiAvailable() { | 171 bool NotificationsApiFunction::IsNotificationsApiAvailable() { |
180 // We need to check this explicitly rather than letting | 172 // We need to check this explicitly rather than letting |
181 // _permission_features.json enforce it, because we're sharing the | 173 // _permission_features.json enforce it, because we're sharing the |
182 // chrome.notifications permissions namespace with WebKit notifications. | 174 // chrome.notifications permissions namespace with WebKit notifications. |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 ? api::notifications::PERMISSION_LEVEL_GRANTED | 622 ? api::notifications::PERMISSION_LEVEL_GRANTED |
631 : api::notifications::PERMISSION_LEVEL_DENIED; | 623 : api::notifications::PERMISSION_LEVEL_DENIED; |
632 | 624 |
633 SetResult(new base::StringValue(api::notifications::ToString(result))); | 625 SetResult(new base::StringValue(api::notifications::ToString(result))); |
634 SendResponse(true); | 626 SendResponse(true); |
635 | 627 |
636 return true; | 628 return true; |
637 } | 629 } |
638 | 630 |
639 } // namespace extensions | 631 } // namespace extensions |
OLD | NEW |