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
3 // found in the LICENSE file.
5 #ifndef CHROME_FRAME_EXTERNAL_TAB_H_
6 #define CHROME_FRAME_EXTERNAL_TAB_H_
16 #include "base/memory/scoped_ptr.h"
17 #include "base/time.h"
18 #include "base/win/scoped_comptr.h"
19 #include "chrome/common/automation_constants.h"
20 #include "chrome_frame/cfproxy.h"
21 #include "chrome_frame/task_marshaller.h"
22 #include "content/public/common/page_zoom.h"
23 #include "googleurl/src/gurl.h"
25 struct AttachExternalTabParams
;
26 struct AutomationURLRequest
;
27 struct ContextMenuModel
;
28 struct MiniContextMenuParams
;
29 struct NavigationInfo
;
41 class URLRequestStatus
;
44 // This is the delegate/callback interface that has to be implemented
45 // by the customers of ExternalTabProxy class.
48 virtual void OnNavigationStateChanged(
49 int flags
, const NavigationInfo
& nav_info
) = 0;
50 virtual void OnUpdateTargetUrl(const std::wstring
& new_target_url
) = 0;
51 virtual void OnLoad(const GURL
& url
) = 0;
52 virtual void OnMoveWindow(const gfx::Rect
& pos
) = 0;
54 virtual void OnMessageFromChromeFrame(
55 const std::string
& message
, const std::string
& origin
,
56 const std::string
& target
) = 0;
57 virtual void OnHandleContextMenu(
58 const ContextMenuModel
& context_menu_model
, int align_flags
,
59 const MiniContextMenuParams
& params
) = 0;
60 virtual void OnHandleAccelerator(const MSG
& accel_message
) = 0;
61 virtual void OnTabbedOut(bool reverse
) = 0;
62 virtual void OnGoToHistoryOffset(int offset
) = 0;
63 virtual void OnOpenURL(
64 const GURL
& url_to_open
, const GURL
& referrer
, int open_disposition
) = 0;
69 struct CreateTabParams
{
70 struct ProxyParams proxy_params
;
77 class NavigationConstraints
;
79 /////////////////////////////////////////////////////////////////////////
80 // ExternalTabProxy is a mediator between ChromeProxy (which runs mostly in the
81 // background IPC-channel thread) and the UI object (ActiveX, ActiveDocument).
82 // The lifetime of ExternalTabProxy is determined by the UI object.
84 // When ExternalTabProxy dies:
85 // 1. Remove itself as a ChromeProxyDelegate. This blocks until _Disconnected()
87 // 2. Kills all posted tasks to the UI thread.
88 // 3. Stop all network requests
89 // => It does not have to (and should not) be a refcount-ed object.
91 // Non-public inheritance is not allowed by the style-guide.
92 class ExternalTabProxy
: public CWindowImpl
<ExternalTabProxy
>,
93 public ChromeProxyDelegate
{
99 void set_proxy_factory(ChromeProxyFactory
* factory
) {
100 proxy_factory_
= factory
;
104 // IPC::Channel::Listener implementation.
105 bool OnMessageReceived(const IPC::Message
& message
);
108 virtual void CreateTab(const CreateTabParams
& create_params
,
109 UIDelegate
* delegate
);
110 virtual void Navigate(const std::string
& url
, const std::string
& referrer
,
111 NavigationConstraints
* navigation_constraints
);
112 virtual void NavigateToIndex(int index
);
113 virtual void ForwardMessageFromExternalHost(const std::string
& message
,
114 const std::string
& origin
, const std::string
& target
);
115 virtual void ChromeFrameHostMoved();
117 // Attaches an existing external tab to this automation client instance.
118 virtual void ConnectToExternalTab(uint64 external_tab_cookie
);
119 virtual void BlockExternalTab(uint64 cookie
);
121 void SetZoomLevel(content::PageZoom zoom_level
);
124 BEGIN_MSG_MAP(ExternalTabProxy
)
125 CHAIN_MSG_MAP_MEMBER(ui_
);
128 //////////////////////////////////////////////////////////////////////////
129 // ChromeProxyDelegate implementation
130 virtual int tab_handle() {
133 virtual void Connected(ChromeProxy
* proxy
);
134 virtual void PeerLost(ChromeProxy
* proxy
, DisconnectReason reason
);
135 virtual void Disconnected();
137 // Sync message responses.
138 virtual void Completed_CreateTab(bool success
, HWND chrome_wnd
,
139 HWND tab_window
, int tab_handle
, int session_id
);
140 virtual void Completed_ConnectToTab(bool success
, HWND chrome_window
,
141 HWND tab_window
, int tab_handle
, int session_id
);
142 virtual void Completed_Navigate(bool success
,
143 enum AutomationMsg_NavigationResponseValues res
);
145 // Network requests from Chrome.
146 virtual void OnNetwork_Start(
147 int request_id
, const AutomationURLRequest
& request_info
);
148 virtual void OnNetwork_Read(int request_id
, int bytes_to_read
);
149 virtual void OnNetwork_End(int request_id
, const net::URLRequestStatus
& s
);
150 virtual void OnNetwork_DownloadInHost(int request_id
);
151 virtual void OnGetCookies(const GURL
& url
, int cookie_id
);
152 virtual void OnSetCookie(const GURL
& url
, const std::string
& cookie
);
154 // Navigation progress notifications.
155 virtual void OnNavigationStateChanged(
156 int flags
, const NavigationInfo
& nav_info
);
157 virtual void OnUpdateTargetUrl(const std::wstring
& url
);
158 virtual void OnNavigationFailed(int error_code
, const GURL
& gurl
);
159 virtual void OnDidNavigate(const NavigationInfo
& navigation_info
);
160 virtual void OnTabLoaded(const GURL
& url
);
161 virtual void OnMoveWindow(const gfx::Rect
& pos
);
163 virtual void OnOpenURL(const GURL
& url_to_open
, const GURL
& referrer
,
164 int open_disposition
);
165 virtual void OnGoToHistoryOffset(int offset
);
166 virtual void OnMessageToHost(
167 const std::string
& message
, const std::string
& origin
,
168 const std::string
& target
);
171 virtual void OnHandleAccelerator(const MSG
& accel_message
);
172 virtual void OnHandleContextMenu(const ContextMenuModel
& context_menu_model
,
174 const MiniContextMenuParams
& params
);
175 virtual void OnTabbedOut(bool reverse
);
178 virtual void OnTabClosed();
179 virtual void OnAttachTab(const AttachExternalTabParams
& attach_params
);
181 // end of ChromeProxyDelegate methods
182 //////////////////////////////////////////////////////////////////////////
186 // The UiXXXX are the ChromeProxyDelegate methods but on UI thread.
187 void UiConnected(ChromeProxy
* proxy
);
188 void UiPeerLost(ChromeProxy
* proxy
, DisconnectReason reason
);
189 void UiCompleted_CreateTab(bool success
, HWND chrome_window
,
190 HWND tab_window
, int tab_handle
, int session_id
);
192 // With the present state of affairs the only response we can possibly handle
193 // in the background IPC thread is Completed_CreateTab() where we can
194 // initiate a navigation (if there is a pending one).
195 // To simplify - will handle Completed_CreateTab in UI thread and avoid
196 // the need of lock when accessing members.
200 CREATE_TAB_IN_PROGRESS
,
202 RELEASE_CF_PROXY_IN_PROGRESS
207 ChromeProxyFactory
* proxy_factory_
;
208 // Accessed only in the UI thread for simplicity.
210 // Accessed from ipc thread as well. It's safe if the object goes away
211 // because this should be preceded by destruction of the window and
212 // therefore all queued tasks should be destroyed.
213 UIDelegate
* ui_delegate_
;
214 TaskMarshallerThroughMessageQueue ui_
;
216 scoped_ptr
<base::WaitableEvent
> done_
;
218 CreateTabParams tab_params_
;
219 struct PendingNavigation
{
222 void Set(const GURL
& gurl
, const GURL
& ref
) {
226 } pending_navigation_
;
229 #endif // CHROME_FRAME_EXTERNAL_TAB_H_