[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ |
| 6 | #define CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ |
| 7 | |
[email protected] | 5778de6e | 2009-10-24 01:29:20 | [diff] [blame^] | 8 | #include <atlbase.h> |
| 9 | #include <atlwin.h> |
| 10 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 11 | #include "chrome/test/automation/automation_messages.h" |
| 12 | #include "ipc/ipc_message.h" |
| 13 | |
| 14 | // A common interface supported by all the browser specific ChromeFrame |
| 15 | // implementations. |
| 16 | class ChromeFrameDelegate { |
| 17 | public: |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 18 | typedef HWND WindowType; |
| 19 | |
| 20 | virtual WindowType GetWindow() const = 0; |
| 21 | virtual void GetBounds(RECT* bounds) = 0; |
| 22 | virtual std::string GetDocumentUrl() = 0; |
| 23 | virtual void OnAutomationServerReady() = 0; |
| 24 | virtual void OnAutomationServerLaunchFailed( |
| 25 | AutomationLaunchResult reason, const std::string& server_version) = 0; |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [diff] [blame] | 26 | virtual void OnExtensionInstalled( |
| 27 | const FilePath& path, |
| 28 | void* user_data, |
| 29 | AutomationMsg_ExtensionResponseValues response) = 0; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 30 | virtual void OnMessageReceived(const IPC::Message& msg) = 0; |
| 31 | |
| 32 | // This remains in interface since we call it if Navigate() |
| 33 | // returns immediate error. |
| 34 | virtual void OnLoadFailed(int error_code, const std::string& url) = 0; |
| 35 | |
| 36 | // Returns true if this instance is alive and well for processing automation |
| 37 | // messages. |
| 38 | virtual bool IsValid() const = 0; |
| 39 | |
| 40 | protected: |
| 41 | ~ChromeFrameDelegate() {} |
| 42 | }; |
| 43 | |
| 44 | // Template specialization |
| 45 | template <> struct RunnableMethodTraits<ChromeFrameDelegate> { |
[email protected] | 39fe32a | 2009-09-30 04:29:20 | [diff] [blame] | 46 | void RetainCallee(ChromeFrameDelegate* obj) {} |
| 47 | void ReleaseCallee(ChromeFrameDelegate* obj) {} |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | extern UINT kAutomationServerReady; |
| 51 | extern UINT kMessageFromChromeFrame; |
| 52 | |
| 53 | class ChromeFrameDelegateImpl : public ChromeFrameDelegate { |
| 54 | public: |
| 55 | virtual WindowType GetWindow() { return NULL; } |
| 56 | virtual void GetBounds(RECT* bounds) {} |
| 57 | virtual std::string GetDocumentUrl() { return std::string(); } |
| 58 | virtual void OnAutomationServerReady() {} |
| 59 | virtual void OnAutomationServerLaunchFailed( |
| 60 | AutomationLaunchResult reason, const std::string& server_version) {} |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [diff] [blame] | 61 | virtual void OnExtensionInstalled( |
| 62 | const FilePath& path, |
| 63 | void* user_data, |
| 64 | AutomationMsg_ExtensionResponseValues response) {} |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 65 | virtual void OnLoadFailed(int error_code, const std::string& url) {} |
| 66 | virtual void OnMessageReceived(const IPC::Message& msg); |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [diff] [blame] | 67 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 68 | static bool IsTabMessage(const IPC::Message& message, int* tab_handle); |
| 69 | |
| 70 | virtual bool IsValid() const { |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | protected: |
| 75 | // Protected methods to be overriden. |
| 76 | virtual void OnNavigationStateChanged(int tab_handle, int flags, |
| 77 | const IPC::NavigationInfo& nav_info) {} |
| 78 | virtual void OnUpdateTargetUrl(int tab_handle, |
| 79 | const std::wstring& new_target_url) {} |
| 80 | virtual void OnAcceleratorPressed(int tab_handle, const MSG& accel_message) {} |
| 81 | virtual void OnTabbedOut(int tab_handle, bool reverse) {} |
| 82 | virtual void OnOpenURL(int tab_handle, const GURL& url, |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 83 | const GURL& referrer, int open_disposition) {} |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 84 | virtual void OnDidNavigate(int tab_handle, |
| 85 | const IPC::NavigationInfo& navigation_info) {} |
| 86 | virtual void OnNavigationFailed(int tab_handle, int error_code, |
| 87 | const GURL& gurl) {} |
| 88 | virtual void OnLoad(int tab_handle, const GURL& url) {} |
| 89 | virtual void OnMessageFromChromeFrame(int tab_handle, |
| 90 | const std::string& message, |
| 91 | const std::string& origin, |
| 92 | const std::string& target) {} |
| 93 | virtual void OnHandleContextMenu(int tab_handle, HANDLE menu_handle, |
| 94 | int x_pos, int y_pos, int align_flags) {} |
| 95 | virtual void OnRequestStart(int tab_handle, int request_id, |
| 96 | const IPC::AutomationURLRequest& request) {} |
| 97 | virtual void OnRequestRead(int tab_handle, int request_id, |
| 98 | int bytes_to_read) {} |
| 99 | virtual void OnRequestEnd(int tab_handle, int request_id, |
| 100 | const URLRequestStatus& status) {} |
| 101 | virtual void OnSetCookieAsync(int tab_handle, const GURL& url, |
| 102 | const std::string& cookie) {} |
| 103 | virtual void OnAttachExternalTab(int tab_handle, intptr_t cookie, |
| 104 | int disposition) {} |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 105 | virtual void OnGoToHistoryEntryOffset(int tab_handle, int offset) {} |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 106 | }; |
| 107 | |
[email protected] | 5778de6e | 2009-10-24 01:29:20 | [diff] [blame^] | 108 | // This interface enables tasks to be marshalled to desired threads. |
| 109 | class TaskMarshaller { |
| 110 | public: |
| 111 | virtual void PostTask(const tracked_objects::Location& from_here, |
| 112 | Task* task) = 0; |
| 113 | }; |
| 114 | |
| 115 | // T is expected to be something CWindowImpl derived, or at least to have |
| 116 | // PostMessage(UINT, WPARAM) method. Do not forget to CHAIN_MSG_MAP |
| 117 | template <class T> class TaskMarshallerThroughWindowsMessages |
| 118 | : public TaskMarshaller { |
| 119 | public: |
| 120 | virtual void PostTask(const tracked_objects::Location& from_here, |
| 121 | Task* task) { |
| 122 | task->SetBirthPlace(from_here); |
| 123 | T* this_ptr = static_cast<T*>(this); |
| 124 | if (this_ptr->IsWindow()) { |
| 125 | this_ptr->AddRef(); |
| 126 | this_ptr->PostMessage(MSG_EXECUTE_TASK, reinterpret_cast<WPARAM>(task)); |
| 127 | } else { |
| 128 | DLOG(INFO) << "Dropping MSG_EXECUTE_TASK message for destroyed window."; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | BEGIN_MSG_MAP(PostMessageMarshaller) |
| 133 | MESSAGE_HANDLER(MSG_EXECUTE_TASK, ExecuteTask) |
| 134 | END_MSG_MAP() |
| 135 | |
| 136 | private: |
| 137 | enum { MSG_EXECUTE_TASK = WM_APP + 6 }; |
| 138 | inline LRESULT ExecuteTask(UINT, WPARAM wparam, LPARAM, |
| 139 | BOOL& handled) { // NOLINT |
| 140 | Task* task = reinterpret_cast<Task*>(wparam); |
| 141 | task->Run(); |
| 142 | delete task; |
| 143 | T* this_ptr = static_cast<T*>(this); |
| 144 | this_ptr->Release(); |
| 145 | return 0; |
| 146 | } |
| 147 | }; |
| 148 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 149 | #endif // CHROME_FRAME_CHROME_FRAME_DELEGATE_H_ |