| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_FRAME_NP_EVENT_LISTENER_H_ | 5 #ifndef CHROME_FRAME_NP_EVENT_LISTENER_H_ |
| 6 #define CHROME_FRAME_NP_EVENT_LISTENER_H_ | 6 #define CHROME_FRAME_NP_EVENT_LISTENER_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 #include "chrome_frame/utils.h" | 10 #include "chrome_frame/utils.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class NpEventListener { | 26 class NpEventListener { |
| 27 public: | 27 public: |
| 28 NS_IMETHOD_(nsrefcnt) AddRef() = 0; | 28 NS_IMETHOD_(nsrefcnt) AddRef() = 0; |
| 29 NS_IMETHOD_(nsrefcnt) Release() = 0; | 29 NS_IMETHOD_(nsrefcnt) Release() = 0; |
| 30 virtual bool Subscribe(NPP instance, | 30 virtual bool Subscribe(NPP instance, |
| 31 const char* event_names[], | 31 const char* event_names[], |
| 32 int event_name_count) = 0; | 32 int event_name_count) = 0; |
| 33 virtual bool Unsubscribe(NPP instance, | 33 virtual bool Unsubscribe(NPP instance, |
| 34 const char* event_names[], | 34 const char* event_names[], |
| 35 int event_name_count) = 0; | 35 int event_name_count) = 0; |
| 36 |
| 37 protected: |
| 38 virtual ~NpEventListener() {} |
| 36 }; | 39 }; |
| 37 | 40 |
| 38 // A little helper class to implement simple ref counting | 41 // A little helper class to implement simple ref counting |
| 39 // and assert on single threadedness. | 42 // and assert on single threadedness. |
| 40 template <class T> | 43 template <class T> |
| 41 class NpEventListenerBase : public NpEventListener { | 44 class NpEventListenerBase : public NpEventListener { |
| 42 public: | 45 public: |
| 43 NpEventListenerBase(NpEventDelegate* delegate) | 46 explicit NpEventListenerBase(NpEventDelegate* delegate) |
| 44 : ref_count_(0), delegate_(delegate) { | 47 : ref_count_(0), delegate_(delegate) { |
| 45 DCHECK(delegate_); | 48 DCHECK(delegate_); |
| 46 thread_id_ = ::GetCurrentThreadId(); | 49 thread_id_ = ::GetCurrentThreadId(); |
| 47 } | 50 } |
| 48 | 51 |
| 49 ~NpEventListenerBase() { | 52 ~NpEventListenerBase() { |
| 50 DCHECK(thread_id_ == ::GetCurrentThreadId()); | 53 DCHECK(thread_id_ == ::GetCurrentThreadId()); |
| 51 } | 54 } |
| 52 | 55 |
| 53 NS_IMETHOD_(nsrefcnt) AddRef() { | 56 NS_IMETHOD_(nsrefcnt) AddRef() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 76 // used to DCHECK on expected single-threaded usage | 79 // used to DCHECK on expected single-threaded usage |
| 77 unsigned long thread_id_; | 80 unsigned long thread_id_; |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 // Implements nsIDOMEventListener in order to receive events from DOM | 83 // Implements nsIDOMEventListener in order to receive events from DOM |
| 81 // elements inside an HTML page. | 84 // elements inside an HTML page. |
| 82 class DomEventListener | 85 class DomEventListener |
| 83 : public nsIDOMEventListener, | 86 : public nsIDOMEventListener, |
| 84 public NpEventListenerBase<DomEventListener> { | 87 public NpEventListenerBase<DomEventListener> { |
| 85 public: | 88 public: |
| 86 DomEventListener(NpEventDelegate* delegate); | 89 explicit DomEventListener(NpEventDelegate* delegate); |
| 87 ~DomEventListener(); | 90 virtual ~DomEventListener(); |
| 88 | 91 |
| 89 // Implementation of NpEventListener | 92 // Implementation of NpEventListener |
| 90 virtual bool Subscribe(NPP instance, | 93 virtual bool Subscribe(NPP instance, |
| 91 const char* event_names[], | 94 const char* event_names[], |
| 92 int event_name_count); | 95 int event_name_count); |
| 93 virtual bool Unsubscribe(NPP instance, | 96 virtual bool Unsubscribe(NPP instance, |
| 94 const char* event_names[], | 97 const char* event_names[], |
| 95 int event_name_count); | 98 int event_name_count); |
| 96 protected: | 99 protected: |
| 97 // We implement QueryInterface etc ourselves in order to avoid | 100 // We implement QueryInterface etc ourselves in order to avoid |
| (...skipping 13 matching lines...) Expand all Loading... |
| 111 private: | 114 private: |
| 112 static bool GetObjectElement(NPP instance, nsIDOMElement** element); | 115 static bool GetObjectElement(NPP instance, nsIDOMElement** element); |
| 113 | 116 |
| 114 private: | 117 private: |
| 115 DISALLOW_COPY_AND_ASSIGN(DomEventListener); | 118 DISALLOW_COPY_AND_ASSIGN(DomEventListener); |
| 116 }; | 119 }; |
| 117 | 120 |
| 118 class NPObjectEventListener | 121 class NPObjectEventListener |
| 119 : public NpEventListenerBase<NPObjectEventListener> { | 122 : public NpEventListenerBase<NPObjectEventListener> { |
| 120 public: | 123 public: |
| 121 NPObjectEventListener(NpEventDelegate* delegate); | 124 explicit NPObjectEventListener(NpEventDelegate* delegate); |
| 122 ~NPObjectEventListener(); | 125 ~NPObjectEventListener(); |
| 123 | 126 |
| 124 // Implementation of NpEventListener | 127 // Implementation of NpEventListener |
| 125 virtual bool Subscribe(NPP instance, | 128 virtual bool Subscribe(NPP instance, |
| 126 const char* event_names[], | 129 const char* event_names[], |
| 127 int event_name_count); | 130 int event_name_count); |
| 128 virtual bool Unsubscribe(NPP instance, | 131 virtual bool Unsubscribe(NPP instance, |
| 129 const char* event_names[], | 132 const char* event_names[], |
| 130 int event_name_count); | 133 int event_name_count); |
| 131 | 134 |
| 132 protected: | 135 protected: |
| 133 // NPObject structure which is exposed by NPObjectEventListener. | 136 // NPObject structure which is exposed by NPObjectEventListener. |
| 134 class Npo : public NPObject { | 137 class Npo : public NPObject { |
| 135 public: | 138 public: |
| 136 Npo(NPP npp) : npp_(npp), listener_(NULL) { | 139 explicit Npo(NPP npp) : npp_(npp), listener_(NULL) { |
| 137 } | 140 } |
| 138 | 141 |
| 139 void Initialize(NPObjectEventListener* listener) { | 142 void Initialize(NPObjectEventListener* listener) { |
| 140 listener_ = listener; | 143 listener_ = listener; |
| 141 } | 144 } |
| 142 | 145 |
| 143 inline NPObjectEventListener* listener() const { | 146 inline NPObjectEventListener* listener() const { |
| 144 return listener_; | 147 return listener_; |
| 145 } | 148 } |
| 146 | 149 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 static NPObject* GetObjectElement(NPP instance); | 181 static NPObject* GetObjectElement(NPP instance); |
| 179 | 182 |
| 180 private: | 183 private: |
| 181 // Our NPObject. | 184 // Our NPObject. |
| 182 ScopedNpObject<Npo> npo_; | 185 ScopedNpObject<Npo> npo_; |
| 183 | 186 |
| 184 DISALLOW_COPY_AND_ASSIGN(NPObjectEventListener); | 187 DISALLOW_COPY_AND_ASSIGN(NPObjectEventListener); |
| 185 }; | 188 }; |
| 186 | 189 |
| 187 #endif // CHROME_FRAME_NP_EVENT_LISTENER_H_ | 190 #endif // CHROME_FRAME_NP_EVENT_LISTENER_H_ |
| OLD | NEW |