OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CHROME_FRAME_DELEGATE_H_ | 5 #ifndef CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ |
6 #define CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ | 6 #define CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <atlbase.h> | 9 #include <atlbase.h> |
10 #include <atlwin.h> | 10 #include <atlwin.h> |
11 #include <queue> | 11 #include <queue> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
| 15 #include "base/callback.h" |
15 #include "base/file_path.h" | 16 #include "base/file_path.h" |
16 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/pending_task.h" |
17 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
18 #include "base/task.h" | 20 #include "base/task.h" |
19 #include "chrome/common/automation_constants.h" | 21 #include "chrome/common/automation_constants.h" |
20 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
21 | 23 |
22 class GURL; | 24 class GURL; |
23 struct AttachExternalTabParams; | 25 struct AttachExternalTabParams; |
24 struct AutomationURLRequest; | 26 struct AutomationURLRequest; |
25 struct ContextMenuModel; | 27 struct ContextMenuModel; |
26 struct MiniContextMenuParams; | 28 struct MiniContextMenuParams; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 virtual bool IsValid() const = 0; | 60 virtual bool IsValid() const = 0; |
59 | 61 |
60 // To be called when the top-most window of an application hosting | 62 // To be called when the top-most window of an application hosting |
61 // ChromeFrame is moved. | 63 // ChromeFrame is moved. |
62 virtual void OnHostMoved() = 0; | 64 virtual void OnHostMoved() = 0; |
63 | 65 |
64 protected: | 66 protected: |
65 virtual ~ChromeFrameDelegate() {} | 67 virtual ~ChromeFrameDelegate() {} |
66 }; | 68 }; |
67 | 69 |
68 // Disable refcounting of ChromeFrameDelegate. | |
69 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeFrameDelegate); | |
70 | |
71 extern UINT kAutomationServerReady; | 70 extern UINT kAutomationServerReady; |
72 extern UINT kMessageFromChromeFrame; | 71 extern UINT kMessageFromChromeFrame; |
73 | 72 |
74 class ChromeFrameDelegateImpl : public ChromeFrameDelegate { | 73 class ChromeFrameDelegateImpl : public ChromeFrameDelegate { |
75 public: | 74 public: |
76 virtual WindowType GetWindow() { return NULL; } | 75 virtual WindowType GetWindow() { return NULL; } |
77 virtual void GetBounds(RECT* bounds) {} | 76 virtual void GetBounds(RECT* bounds) {} |
78 virtual std::string GetDocumentUrl() { return std::string(); } | 77 virtual std::string GetDocumentUrl() { return std::string(); } |
79 virtual void OnAutomationServerReady() {} | 78 virtual void OnAutomationServerReady() {} |
80 virtual void OnAutomationServerLaunchFailed( | 79 virtual void OnAutomationServerLaunchFailed( |
81 AutomationLaunchResult reason, const std::string& server_version) {} | 80 AutomationLaunchResult reason, const std::string& server_version) {} |
82 virtual void OnLoadFailed(int error_code, const std::string& url) {} | 81 virtual void OnLoadFailed(int error_code, const std::string& url) {} |
83 virtual bool OnMessageReceived(const IPC::Message& msg); | 82 virtual bool OnMessageReceived(const IPC::Message& msg); |
84 virtual void OnChannelError() {} | 83 virtual void OnChannelError() {} |
85 | 84 |
86 static bool IsTabMessage(const IPC::Message& message); | 85 static bool IsTabMessage(const IPC::Message& message); |
87 | 86 |
88 virtual bool IsValid() const { | 87 virtual bool IsValid() const { |
89 return true; | 88 return true; |
90 } | 89 } |
91 | 90 |
92 virtual void OnHostMoved() {} | 91 virtual void OnHostMoved() {} |
93 | 92 |
94 protected: | 93 protected: |
95 // Protected methods to be overriden. | 94 // Protected methods to be overridden. |
96 virtual void OnNavigationStateChanged( | 95 virtual void OnNavigationStateChanged( |
97 int flags, const NavigationInfo& nav_info) {} | 96 int flags, const NavigationInfo& nav_info) {} |
98 virtual void OnUpdateTargetUrl(const std::wstring& new_target_url) {} | 97 virtual void OnUpdateTargetUrl(const std::wstring& new_target_url) {} |
99 virtual void OnAcceleratorPressed(const MSG& accel_message) {} | 98 virtual void OnAcceleratorPressed(const MSG& accel_message) {} |
100 virtual void OnTabbedOut(bool reverse) {} | 99 virtual void OnTabbedOut(bool reverse) {} |
101 virtual void OnOpenURL( | 100 virtual void OnOpenURL( |
102 const GURL& url, const GURL& referrer, int open_disposition) {} | 101 const GURL& url, const GURL& referrer, int open_disposition) {} |
103 virtual void OnDidNavigate(const NavigationInfo& navigation_info) {} | 102 virtual void OnDidNavigate(const NavigationInfo& navigation_info) {} |
104 virtual void OnNavigationFailed(int error_code, const GURL& gurl) {} | 103 virtual void OnNavigationFailed(int error_code, const GURL& gurl) {} |
105 virtual void OnLoad(const GURL& url) {} | 104 virtual void OnLoad(const GURL& url) {} |
(...skipping 16 matching lines...) Expand all Loading... |
122 virtual void OnGoToHistoryEntryOffset(int offset) {} | 121 virtual void OnGoToHistoryEntryOffset(int offset) {} |
123 | 122 |
124 virtual void OnGetCookiesFromHost(const GURL& url, int cookie_id) {} | 123 virtual void OnGetCookiesFromHost(const GURL& url, int cookie_id) {} |
125 virtual void OnCloseTab() {} | 124 virtual void OnCloseTab() {} |
126 }; | 125 }; |
127 | 126 |
128 // This interface enables tasks to be marshaled to desired threads. | 127 // This interface enables tasks to be marshaled to desired threads. |
129 class TaskMarshaller { // NOLINT | 128 class TaskMarshaller { // NOLINT |
130 public: | 129 public: |
131 virtual void PostTask(const tracked_objects::Location& from_here, | 130 virtual void PostTask(const tracked_objects::Location& from_here, |
132 Task* task) = 0; | 131 const base::Closure& task) = 0; |
133 }; | 132 }; |
134 | 133 |
135 // T is expected to be something CWindowImpl derived, or at least to have | 134 // T is expected to be something CWindowImpl derived, or at least to have |
136 // PostMessage(UINT, WPARAM) method. Do not forget to CHAIN_MSG_MAP | 135 // PostMessage(UINT, WPARAM) method. Do not forget to CHAIN_MSG_MAP |
137 template <class T> class TaskMarshallerThroughWindowsMessages | 136 template <class T> class TaskMarshallerThroughWindowsMessages |
138 : public TaskMarshaller { | 137 : public TaskMarshaller { |
139 public: | 138 public: |
140 TaskMarshallerThroughWindowsMessages() {} | 139 TaskMarshallerThroughWindowsMessages() {} |
141 virtual void PostTask(const tracked_objects::Location& from_here, | 140 virtual void PostTask(const tracked_objects::Location& posted_from, |
142 Task* task) { | 141 const base::Closure& task) OVERRIDE { |
143 T* this_ptr = static_cast<T*>(this); | 142 T* this_ptr = static_cast<T*>(this); |
144 if (this_ptr->IsWindow()) { | 143 if (this_ptr->IsWindow()) { |
145 this_ptr->AddRef(); | 144 this_ptr->AddRef(); |
146 PushTask(task); | 145 base::PendingTask* pending_task = |
147 this_ptr->PostMessage(MSG_EXECUTE_TASK, reinterpret_cast<WPARAM>(task)); | 146 new base::PendingTask(posted_from, task); |
| 147 PushTask(pending_task); |
| 148 this_ptr->PostMessage(MSG_EXECUTE_TASK, |
| 149 reinterpret_cast<WPARAM>(pending_task)); |
148 } else { | 150 } else { |
149 DVLOG(1) << "Dropping MSG_EXECUTE_TASK message for destroyed window."; | 151 DVLOG(1) << "Dropping MSG_EXECUTE_TASK message for destroyed window."; |
150 delete task; | |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 protected: | 155 protected: |
155 ~TaskMarshallerThroughWindowsMessages() { | 156 ~TaskMarshallerThroughWindowsMessages() { |
156 DeleteAllPendingTasks(); | 157 DeleteAllPendingTasks(); |
157 } | 158 } |
158 | 159 |
159 void DeleteAllPendingTasks() { | 160 void DeleteAllPendingTasks() { |
160 base::AutoLock lock(lock_); | 161 base::AutoLock lock(lock_); |
161 DVLOG_IF(1, !pending_tasks_.empty()) << "Destroying " | 162 DVLOG_IF(1, !pending_tasks_.empty()) << "Destroying " |
162 << pending_tasks_.size() | 163 << pending_tasks_.size() |
163 << " pending tasks"; | 164 << " pending tasks"; |
164 while (!pending_tasks_.empty()) { | 165 while (!pending_tasks_.empty()) { |
165 Task* task = pending_tasks_.front(); | 166 base::PendingTask* task = pending_tasks_.front(); |
166 pending_tasks_.pop(); | 167 pending_tasks_.pop(); |
167 delete task; | 168 delete task; |
168 } | 169 } |
169 } | 170 } |
170 | 171 |
171 BEGIN_MSG_MAP(PostMessageMarshaller) | 172 BEGIN_MSG_MAP(PostMessageMarshaller) |
172 MESSAGE_HANDLER(MSG_EXECUTE_TASK, ExecuteTask) | 173 MESSAGE_HANDLER(MSG_EXECUTE_TASK, ExecuteTask) |
173 END_MSG_MAP() | 174 END_MSG_MAP() |
174 | 175 |
175 private: | 176 private: |
176 enum { MSG_EXECUTE_TASK = WM_APP + 6 }; | 177 enum { MSG_EXECUTE_TASK = WM_APP + 6 }; |
177 inline LRESULT ExecuteTask(UINT, WPARAM wparam, LPARAM, | 178 inline LRESULT ExecuteTask(UINT, WPARAM wparam, LPARAM, |
178 BOOL& handled) { // NOLINT | 179 BOOL& handled) { // NOLINT |
179 Task* task = reinterpret_cast<Task*>(wparam); | 180 base::PendingTask* pending_task = |
180 if (task && PopTask(task)) { | 181 reinterpret_cast<base::PendingTask*>(wparam); |
181 task->Run(); | 182 if (pending_task && PopTask(pending_task)) { |
182 delete task; | 183 pending_task->task.Run(); |
| 184 delete pending_task; |
183 } | 185 } |
184 | 186 |
185 T* this_ptr = static_cast<T*>(this); | 187 T* this_ptr = static_cast<T*>(this); |
186 this_ptr->Release(); | 188 this_ptr->Release(); |
187 return 0; | 189 return 0; |
188 } | 190 } |
189 | 191 |
190 inline void PushTask(Task* task) { | 192 inline void PushTask(base::PendingTask* pending_task) { |
191 base::AutoLock lock(lock_); | 193 base::AutoLock lock(lock_); |
192 pending_tasks_.push(task); | 194 pending_tasks_.push(pending_task); |
193 } | 195 } |
194 | 196 |
195 // If the given task is front of the queue, removes the task and returns true, | 197 // If |pending_task| is front of the queue, removes the task and returns true, |
196 // otherwise we assume this is an already destroyed task (but Window message | 198 // otherwise we assume this is an already destroyed task (but Window message |
197 // had remained in the thread queue). | 199 // had remained in the thread queue). |
198 inline bool PopTask(Task* task) { | 200 inline bool PopTask(base::PendingTask* pending_task) { |
199 base::AutoLock lock(lock_); | 201 base::AutoLock lock(lock_); |
200 if (!pending_tasks_.empty() && task == pending_tasks_.front()) { | 202 if (!pending_tasks_.empty() && pending_task == pending_tasks_.front()) { |
201 pending_tasks_.pop(); | 203 pending_tasks_.pop(); |
202 return true; | 204 return true; |
203 } | 205 } |
204 | 206 |
205 return false; | 207 return false; |
206 } | 208 } |
207 | 209 |
208 base::Lock lock_; | 210 base::Lock lock_; |
209 std::queue<Task*> pending_tasks_; | 211 std::queue<base::PendingTask*> pending_tasks_; |
210 }; | 212 }; |
211 | 213 |
212 #endif // CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ | 214 #endif // CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ |
OLD | NEW |