| 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/api_resource_event_notifier.h" | 5 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/extension_event_router.h" | 10 #include "chrome/browser/extensions/extension_event_router.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DictionaryValue* event) { | 119 DictionaryValue* event) { |
| 120 BrowserThread::PostTask( | 120 BrowserThread::PostTask( |
| 121 BrowserThread::UI, FROM_HERE, | 121 BrowserThread::UI, FROM_HERE, |
| 122 base::Bind( | 122 base::Bind( |
| 123 &APIResourceEventNotifier::DispatchEventOnUIThread, this, extension, | 123 &APIResourceEventNotifier::DispatchEventOnUIThread, this, extension, |
| 124 event)); | 124 event)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void APIResourceEventNotifier::DispatchEventOnUIThread( | 127 void APIResourceEventNotifier::DispatchEventOnUIThread( |
| 128 const std::string &extension, DictionaryValue* event) { | 128 const std::string &extension, DictionaryValue* event) { |
| 129 ListValue args; | |
| 130 | |
| 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 132 | 130 |
| 131 ListValue args; |
| 133 args.Set(0, event); | 132 args.Set(0, event); |
| 134 std::string json_args; | 133 router_->DispatchEventToExtension(src_extension_id_, extension, args, |
| 135 base::JSONWriter::Write(&args, &json_args); | |
| 136 router_->DispatchEventToExtension(src_extension_id_, extension, json_args, | |
| 137 profile_, src_url_); | 134 profile_, src_url_); |
| 138 } | 135 } |
| 139 | 136 |
| 140 DictionaryValue* APIResourceEventNotifier::CreateAPIResourceEvent( | 137 DictionaryValue* APIResourceEventNotifier::CreateAPIResourceEvent( |
| 141 APIResourceEventType event_type) { | 138 APIResourceEventType event_type) { |
| 142 DictionaryValue* event = new DictionaryValue(); | 139 DictionaryValue* event = new DictionaryValue(); |
| 143 event->SetString(kEventTypeKey, APIResourceEventTypeToString(event_type)); | 140 event->SetString(kEventTypeKey, APIResourceEventTypeToString(event_type)); |
| 144 event->SetInteger(kSrcIdKey, src_id_); | 141 event->SetInteger(kSrcIdKey, src_id_); |
| 145 | 142 |
| 146 // TODO(miket): Signal that it's OK to clean up onEvent listeners. This is | 143 // TODO(miket): Signal that it's OK to clean up onEvent listeners. This is |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 int result_code) { | 155 int result_code) { |
| 159 if (src_id_ < 0) | 156 if (src_id_ < 0) |
| 160 return; | 157 return; |
| 161 | 158 |
| 162 DictionaryValue* event = CreateAPIResourceEvent(event_type); | 159 DictionaryValue* event = CreateAPIResourceEvent(event_type); |
| 163 event->SetInteger(kResultCodeKey, result_code); | 160 event->SetInteger(kResultCodeKey, result_code); |
| 164 DispatchEvent(extension, event); | 161 DispatchEvent(extension, event); |
| 165 } | 162 } |
| 166 | 163 |
| 167 } // namespace extensions | 164 } // namespace extensions |
| OLD | NEW |