OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "chrome/browser/automation/automation_event_observer.h" |
| 7 #include "chrome/browser/automation/automation_event_queue.h" |
| 8 #include "chrome/browser/automation/automation_provider.h" |
| 9 #include "chrome/browser/automation/automation_provider_json.h" |
| 10 #include "content/public/browser/notification_service.h" |
| 11 #include "content/public/browser/notification_types.h" |
| 12 |
| 13 AutomationEventObserver::AutomationEventObserver( |
| 14 AutomationEventQueue* event_queue) |
| 15 : event_queue_(event_queue), observer_id_(-1) { |
| 16 DCHECK(event_queue_ != NULL); |
| 17 } |
| 18 |
| 19 AutomationEventObserver::~AutomationEventObserver() {} |
| 20 |
| 21 void AutomationEventObserver::NotifyEvent(DictionaryValue* value) { |
| 22 if (event_queue_) { |
| 23 event_queue_->NotifyEvent( |
| 24 new AutomationEventQueue::AutomationEvent( |
| 25 GetId(), value)); |
| 26 } |
| 27 } |
| 28 |
| 29 void AutomationEventObserver::Init(int observer_id) { |
| 30 if (observer_id_ < 0) { |
| 31 observer_id_ = observer_id; |
| 32 } |
| 33 } |
| 34 |
| 35 int AutomationEventObserver::GetId() const { |
| 36 return observer_id_; |
| 37 } |
| 38 |
| 39 DomRaisedEventObserver::DomRaisedEventObserver( |
| 40 AutomationEventQueue* event_queue, const std::string& event_name) |
| 41 : AutomationEventObserver(event_queue), event_name_(event_name) {} |
| 42 |
| 43 DomRaisedEventObserver::~DomRaisedEventObserver() {} |
| 44 |
| 45 void DomRaisedEventObserver::OnDomOperationCompleted(const std::string& json) { |
| 46 DictionaryValue* dict = new DictionaryValue; |
| 47 dict->SetString("type", "raised"); |
| 48 dict->SetString("name", json); |
| 49 dict->SetInteger("observer_id", GetId()); |
| 50 NotifyEvent(dict); |
| 51 } |
| 52 |
| 53 void DomRaisedEventObserver::OnModalDialogShown() { |
| 54 DictionaryValue* dict = new DictionaryValue; |
| 55 dict->SetString("error", "Blocked by modal dialogue"); |
| 56 NotifyEvent(dict); |
| 57 } |
| 58 |
| 59 void DomRaisedEventObserver::OnJavascriptBlocked() { |
| 60 DictionaryValue* dict = new DictionaryValue; |
| 61 dict->SetString("error", "Javascript execution was blocked"); |
| 62 NotifyEvent(dict); |
| 63 } |
OLD | NEW |