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.
5 #ifndef CHROME_FRAME_CHROME_FRAME_DELEGATE_H_
6 #define CHROME_FRAME_CHROME_FRAME_DELEGATE_H_
11 #include "chrome/test/automation/automation_messages.h"
12 #include "ipc/ipc_message.h"
14 // A common interface supported by all the browser specific ChromeFrame
16 class ChromeFrameDelegate
{
18 typedef HWND WindowType
;
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;
26 virtual void OnExtensionInstalled(
29 AutomationMsg_ExtensionResponseValues response
) = 0;
30 virtual void OnMessageReceived(const IPC::Message
& msg
) = 0;
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;
36 // Returns true if this instance is alive and well for processing automation
38 virtual bool IsValid() const = 0;
40 // To be called when the top-most window of an application hosting
41 // ChromeFrame is moved.
42 virtual void OnHostMoved() = 0;
45 ~ChromeFrameDelegate() {}
48 // Template specialization
49 template <> struct RunnableMethodTraits
<ChromeFrameDelegate
> {
50 void RetainCallee(ChromeFrameDelegate
* obj
) {}
51 void ReleaseCallee(ChromeFrameDelegate
* obj
) {}
54 extern UINT kAutomationServerReady
;
55 extern UINT kMessageFromChromeFrame
;
57 class ChromeFrameDelegateImpl
: public ChromeFrameDelegate
{
59 virtual WindowType
GetWindow() { return NULL
; }
60 virtual void GetBounds(RECT
* bounds
) {}
61 virtual std::string
GetDocumentUrl() { return std::string(); }
62 virtual void OnAutomationServerReady() {}
63 virtual void OnAutomationServerLaunchFailed(
64 AutomationLaunchResult reason
, const std::string
& server_version
) {}
65 virtual void OnExtensionInstalled(
68 AutomationMsg_ExtensionResponseValues response
) {}
69 virtual void OnLoadFailed(int error_code
, const std::string
& url
) {}
70 virtual void OnMessageReceived(const IPC::Message
& msg
);
72 static bool IsTabMessage(const IPC::Message
& message
, int* tab_handle
);
74 virtual bool IsValid() const {
78 virtual void OnHostMoved() {}
81 // Protected methods to be overriden.
82 virtual void OnNavigationStateChanged(int tab_handle
, int flags
,
83 const IPC::NavigationInfo
& nav_info
) {}
84 virtual void OnUpdateTargetUrl(int tab_handle
,
85 const std::wstring
& new_target_url
) {}
86 virtual void OnAcceleratorPressed(int tab_handle
, const MSG
& accel_message
) {}
87 virtual void OnTabbedOut(int tab_handle
, bool reverse
) {}
88 virtual void OnOpenURL(int tab_handle
, const GURL
& url
,
89 const GURL
& referrer
, int open_disposition
) {}
90 virtual void OnDidNavigate(int tab_handle
,
91 const IPC::NavigationInfo
& navigation_info
) {}
92 virtual void OnNavigationFailed(int tab_handle
, int error_code
,
94 virtual void OnLoad(int tab_handle
, const GURL
& url
) {}
95 virtual void OnMessageFromChromeFrame(int tab_handle
,
96 const std::string
& message
,
97 const std::string
& origin
,
98 const std::string
& target
) {}
99 virtual void OnHandleContextMenu(int tab_handle
, HANDLE menu_handle
,
101 const IPC::ContextMenuParams
& params
) {}
102 virtual void OnRequestStart(int tab_handle
, int request_id
,
103 const IPC::AutomationURLRequest
& request
) {}
104 virtual void OnRequestRead(int tab_handle
, int request_id
,
105 int bytes_to_read
) {}
106 virtual void OnRequestEnd(int tab_handle
, int request_id
,
107 const URLRequestStatus
& status
) {}
108 virtual void OnDownloadRequestInHost(int tab_handle
, int request_id
) {}
109 virtual void OnSetCookieAsync(int tab_handle
, const GURL
& url
,
110 const std::string
& cookie
) {}
111 virtual void OnAttachExternalTab(int tab_handle
, intptr_t cookie
,
113 virtual void OnGoToHistoryEntryOffset(int tab_handle
, int offset
) {}
116 // This interface enables tasks to be marshalled to desired threads.
117 class TaskMarshaller
{
119 virtual void PostTask(const tracked_objects::Location
& from_here
,
123 // T is expected to be something CWindowImpl derived, or at least to have
124 // PostMessage(UINT, WPARAM) method. Do not forget to CHAIN_MSG_MAP
125 template <class T
> class TaskMarshallerThroughWindowsMessages
126 : public TaskMarshaller
{
128 virtual void PostTask(const tracked_objects::Location
& from_here
,
130 task
->SetBirthPlace(from_here
);
131 T
* this_ptr
= static_cast<T
*>(this);
132 if (this_ptr
->IsWindow()) {
134 this_ptr
->PostMessage(MSG_EXECUTE_TASK
, reinterpret_cast<WPARAM
>(task
));
136 DLOG(INFO
) << "Dropping MSG_EXECUTE_TASK message for destroyed window.";
140 BEGIN_MSG_MAP(PostMessageMarshaller
)
141 MESSAGE_HANDLER(MSG_EXECUTE_TASK
, ExecuteTask
)
145 enum { MSG_EXECUTE_TASK
= WM_APP
+ 6 };
146 inline LRESULT
ExecuteTask(UINT
, WPARAM wparam
, LPARAM
,
147 BOOL
& handled
) { // NOLINT
148 Task
* task
= reinterpret_cast<Task
*>(wparam
);
151 T
* this_ptr
= static_cast<T
*>(this);
157 #endif // CHROME_FRAME_CHROME_FRAME_DELEGATE_H_