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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/automation/automation_event_observers.h" | 9 #include "chrome/browser/automation/automation_event_observers.h" |
10 #include "chrome/browser/automation/automation_event_queue.h" | 10 #include "chrome/browser/automation/automation_event_queue.h" |
11 #include "chrome/browser/automation/automation_provider.h" | 11 #include "chrome/browser/automation/automation_provider.h" |
12 #include "chrome/browser/automation/automation_provider_json.h" | 12 #include "chrome/browser/automation/automation_provider_json.h" |
13 #include "content/public/browser/dom_operation_notification_details.h" | 13 #include "content/public/browser/dom_operation_notification_details.h" |
14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
16 | 16 |
17 const char* DomEventObserver::kSubstringReplaceWithObserverId = "$(id)"; | 17 const char* DomEventObserver::kSubstringReplaceWithObserverId = "$(id)"; |
18 | 18 |
19 AutomationEventObserver::AutomationEventObserver( | 19 AutomationEventObserver::AutomationEventObserver( |
20 AutomationEventQueue* event_queue, bool recurring) | 20 AutomationEventQueue* event_queue, bool recurring) |
21 : event_queue_(event_queue), | 21 : event_queue_(event_queue), |
22 recurring_(recurring), | 22 recurring_(recurring), |
23 observer_id_(-1), | 23 observer_id_(-1), |
24 event_count_(0) { | 24 event_count_(0) { |
25 DCHECK(event_queue_ != NULL); | 25 DCHECK(event_queue_ != NULL); |
26 } | 26 } |
27 | 27 |
28 AutomationEventObserver::~AutomationEventObserver() {} | 28 AutomationEventObserver::~AutomationEventObserver() {} |
29 | 29 |
30 void AutomationEventObserver::NotifyEvent(DictionaryValue* value) { | 30 void AutomationEventObserver::NotifyEvent(base::DictionaryValue* value) { |
31 if (event_queue_) { | 31 if (event_queue_) { |
32 if (!value) | 32 if (!value) |
33 value = new DictionaryValue; | 33 value = new base::DictionaryValue; |
34 value->SetInteger("observer_id", GetId()); | 34 value->SetInteger("observer_id", GetId()); |
35 event_queue_->NotifyEvent( | 35 event_queue_->NotifyEvent( |
36 new AutomationEventQueue::AutomationEvent( | 36 new AutomationEventQueue::AutomationEvent( |
37 GetId(), value)); | 37 GetId(), value)); |
38 event_count_++; | 38 event_count_++; |
39 } else if (value) { | 39 } else if (value) { |
40 delete value; | 40 delete value; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 int type, | 87 int type, |
88 const content::NotificationSource& source, | 88 const content::NotificationSource& source, |
89 const content::NotificationDetails& details) { | 89 const content::NotificationDetails& details) { |
90 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { | 90 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { |
91 content::Details<content::DomOperationNotificationDetails> dom_op_details( | 91 content::Details<content::DomOperationNotificationDetails> dom_op_details( |
92 details); | 92 details); |
93 if ((dom_op_details->automation_id == automation_id_ || | 93 if ((dom_op_details->automation_id == automation_id_ || |
94 automation_id_ == -1) && | 94 automation_id_ == -1) && |
95 (event_name_.length() == 0 || | 95 (event_name_.length() == 0 || |
96 event_name_.compare(dom_op_details->json) == 0)) { | 96 event_name_.compare(dom_op_details->json) == 0)) { |
97 DictionaryValue* dict = new DictionaryValue; | 97 base::DictionaryValue* dict = new base::DictionaryValue; |
98 dict->SetString("type", "raised_event"); | 98 dict->SetString("type", "raised_event"); |
99 dict->SetString("name", dom_op_details->json); | 99 dict->SetString("name", dom_op_details->json); |
100 NotifyEvent(dict); | 100 NotifyEvent(dict); |
101 } | 101 } |
102 } | 102 } |
103 // Nothing should happen after RemoveIfDone() as it may delete the object. | 103 // Nothing should happen after RemoveIfDone() as it may delete the object. |
104 RemoveIfDone(); | 104 RemoveIfDone(); |
105 } | 105 } |
OLD | NEW |