blob: 26abf8f5e525673b0d4029e327cd59508e5360a4 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]5a8db802010-10-06 17:34:432// 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_EXTERNAL_TAB_H_
6#define CHROME_FRAME_EXTERNAL_TAB_H_
7#pragma once
8
9#include <windows.h>
10#include <atlbase.h>
11#include <atlwin.h>
[email protected]8ee65ba2011-04-12 20:53:2312
[email protected]5a8db802010-10-06 17:34:4313#include <string>
[email protected]8ee65ba2011-04-12 20:53:2314#include <vector>
15
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_ptr.h"
[email protected]5a8db802010-10-06 17:34:4317#include "base/time.h"
[email protected]8ee65ba2011-04-12 20:53:2318#include "base/win/scoped_comptr.h"
[email protected]a8ba6362010-11-10 20:02:2519#include "chrome/common/automation_constants.h"
[email protected]5a8db802010-10-06 17:34:4320#include "chrome_frame/cfproxy.h"
21#include "chrome_frame/task_marshaller.h"
[email protected]4dd57932011-03-17 06:06:1222#include "content/common/page_zoom.h"
[email protected]5a8db802010-10-06 17:34:4323#include "googleurl/src/gurl.h"
24
25class Task;
26class CancelableTask;
[email protected]27a112c2011-01-06 04:19:3027
[email protected]5a8db802010-10-06 17:34:4328namespace base {
[email protected]27a112c2011-01-06 04:19:3029class TimeDelta;
30class WaitableEvent;
[email protected]5a8db802010-10-06 17:34:4331}
32
33namespace IPC {
[email protected]27a112c2011-01-06 04:19:3034struct NavigationInfo;
[email protected]5a8db802010-10-06 17:34:4335}
36
[email protected]326d3b72011-03-29 20:38:2437namespace gfx {
38class Rect;
39}
40
41
[email protected]5a8db802010-10-06 17:34:4342// This is the delegate/callback interface that has to be implemented
43// by the customers of ExternalTabProxy class.
44class UIDelegate {
45 public:
[email protected]f5494d42010-12-23 22:15:3446 virtual void OnNavigationStateChanged(
47 int flags, const NavigationInfo& nav_info) = 0;
[email protected]5a8db802010-10-06 17:34:4348 virtual void OnUpdateTargetUrl(const std::wstring& new_target_url) = 0;
[email protected]5a8db802010-10-06 17:34:4349 virtual void OnLoad(const GURL& url) = 0;
[email protected]326d3b72011-03-29 20:38:2450 virtual void OnMoveWindow(const gfx::Rect& pos) = 0;
51
[email protected]f5494d42010-12-23 22:15:3452 virtual void OnMessageFromChromeFrame(
53 const std::string& message, const std::string& origin,
54 const std::string& target) = 0;
55 virtual void OnHandleContextMenu(
[email protected]b516e2d2011-07-12 16:54:1256 const ContextMenuModel& context_menu_model, int align_flags,
[email protected]f5494d42010-12-23 22:15:3457 const MiniContextMenuParams& params) = 0;
[email protected]11b6e602010-10-13 16:02:2658 virtual void OnHandleAccelerator(const MSG& accel_message) = 0;
59 virtual void OnTabbedOut(bool reverse) = 0;
60 virtual void OnGoToHistoryOffset(int offset) = 0;
[email protected]f5494d42010-12-23 22:15:3461 virtual void OnOpenURL(
62 const GURL& url_to_open, const GURL& referrer, int open_disposition) = 0;
[email protected]5a8db802010-10-06 17:34:4363 protected:
64 ~UIDelegate() {}
65};
66
67struct CreateTabParams {
[email protected]11b6e602010-10-13 16:02:2668 struct ProxyParams proxy_params;
[email protected]5a8db802010-10-06 17:34:4369 bool is_incognito;
70 bool is_widget_mode;
71 GURL url;
72 GURL referrer;
[email protected]5a8db802010-10-06 17:34:4373};
74
[email protected]354bcba2010-12-14 04:34:4375class NavigationConstraints;
76
[email protected]5a8db802010-10-06 17:34:4377/////////////////////////////////////////////////////////////////////////
[email protected]99d81e5b2011-06-29 02:29:5378// ExternalTabProxy is a mediator between ChromeProxy (which runs mostly in the
79// background IPC-channel thread) and the UI object (ActiveX, ActiveDocument).
[email protected]5a8db802010-10-06 17:34:4380// The lifetime of ExternalTabProxy is determined by the UI object.
81//
82// When ExternalTabProxy dies:
83// 1. Remove itself as a ChromeProxyDelegate. This blocks until _Disconnected()
84// is received.
85// 2. Kills all posted tasks to the UI thread.
86// 3. Stop all network requests
87// => It does not have to (and should not) be a refcount-ed object.
88
89// Non-public inheritance is not allowed by the style-guide.
90class ExternalTabProxy : public CWindowImpl<ExternalTabProxy>,
91 public ChromeProxyDelegate {
92 public:
93 ExternalTabProxy();
94 ~ExternalTabProxy();
95
96#ifdef UNIT_TEST
97 void set_proxy_factory(ChromeProxyFactory* factory) {
98 proxy_factory_ = factory;
99 }
100#endif
[email protected]f5494d42010-12-23 22:15:34101
102 // IPC::Channel::Listener implementation.
[email protected]a95986a82010-12-24 06:19:28103 bool OnMessageReceived(const IPC::Message& message);
[email protected]f5494d42010-12-23 22:15:34104
[email protected]5a8db802010-10-06 17:34:43105 //
106 virtual void CreateTab(const CreateTabParams& create_params,
107 UIDelegate* delegate);
108 virtual void Navigate(const std::string& url, const std::string& referrer,
[email protected]354bcba2010-12-14 04:34:43109 NavigationConstraints* navigation_constraints);
[email protected]11b6e602010-10-13 16:02:26110 virtual void NavigateToIndex(int index);
[email protected]5a8db802010-10-06 17:34:43111 virtual void ForwardMessageFromExternalHost(const std::string& message,
[email protected]11b6e602010-10-13 16:02:26112 const std::string& origin, const std::string& target);
113 virtual void ChromeFrameHostMoved();
[email protected]5a8db802010-10-06 17:34:43114
[email protected]5a8db802010-10-06 17:34:43115 // Attaches an existing external tab to this automation client instance.
[email protected]11b6e602010-10-13 16:02:26116 virtual void ConnectToExternalTab(uint64 external_tab_cookie);
[email protected]5a8db802010-10-06 17:34:43117 virtual void BlockExternalTab(uint64 cookie);
118
[email protected]11b6e602010-10-13 16:02:26119 void SetZoomLevel(PageZoom::Function zoom_level);
[email protected]5a8db802010-10-06 17:34:43120
121 private:
[email protected]11b6e602010-10-13 16:02:26122 BEGIN_MSG_MAP(ExternalTabProxy)
123 CHAIN_MSG_MAP_MEMBER(ui_);
124 END_MSG_MAP()
125
[email protected]5a8db802010-10-06 17:34:43126 //////////////////////////////////////////////////////////////////////////
127 // ChromeProxyDelegate implementation
128 virtual int tab_handle() {
129 return tab_;
130 }
131 virtual void Connected(ChromeProxy* proxy);
132 virtual void PeerLost(ChromeProxy* proxy, DisconnectReason reason);
133 virtual void Disconnected();
134
[email protected]5a8db802010-10-06 17:34:43135 // Sync message responses.
136 virtual void Completed_CreateTab(bool success, HWND chrome_wnd,
[email protected]751bf4b2010-11-05 22:06:31137 HWND tab_window, int tab_handle, int session_id);
[email protected]5a8db802010-10-06 17:34:43138 virtual void Completed_ConnectToTab(bool success, HWND chrome_window,
[email protected]751bf4b2010-11-05 22:06:31139 HWND tab_window, int tab_handle, int session_id);
[email protected]5a8db802010-10-06 17:34:43140 virtual void Completed_Navigate(bool success,
141 enum AutomationMsg_NavigationResponseValues res);
[email protected]5a8db802010-10-06 17:34:43142
143 // Network requests from Chrome.
[email protected]f5494d42010-12-23 22:15:34144 virtual void OnNetwork_Start(
145 int request_id, const AutomationURLRequest& request_info);
146 virtual void OnNetwork_Read(int request_id, int bytes_to_read);
[email protected]27a112c2011-01-06 04:19:30147 virtual void OnNetwork_End(int request_id, const net::URLRequestStatus& s);
[email protected]f5494d42010-12-23 22:15:34148 virtual void OnNetwork_DownloadInHost(int request_id);
149 virtual void OnGetCookies(const GURL& url, int cookie_id);
150 virtual void OnSetCookie(const GURL& url, const std::string& cookie);
[email protected]5a8db802010-10-06 17:34:43151
152 // Navigation progress notifications.
[email protected]f5494d42010-12-23 22:15:34153 virtual void OnNavigationStateChanged(
154 int flags, const NavigationInfo& nav_info);
155 virtual void OnUpdateTargetUrl(const std::wstring& url);
156 virtual void OnNavigationFailed(int error_code, const GURL& gurl);
157 virtual void OnDidNavigate(const NavigationInfo& navigation_info);
158 virtual void OnTabLoaded(const GURL& url);
[email protected]326d3b72011-03-29 20:38:24159 virtual void OnMoveWindow(const gfx::Rect& pos);
[email protected]5a8db802010-10-06 17:34:43160
[email protected]f5494d42010-12-23 22:15:34161 virtual void OnOpenURL(const GURL& url_to_open, const GURL& referrer,
162 int open_disposition);
163 virtual void OnGoToHistoryOffset(int offset);
164 virtual void OnMessageToHost(
165 const std::string& message, const std::string& origin,
166 const std::string& target);
[email protected]5a8db802010-10-06 17:34:43167
168 // Misc. UI.
[email protected]f5494d42010-12-23 22:15:34169 virtual void OnHandleAccelerator(const MSG& accel_message);
[email protected]b516e2d2011-07-12 16:54:12170 virtual void OnHandleContextMenu(const ContextMenuModel& context_menu_model,
171 int align_flags,
[email protected]f5494d42010-12-23 22:15:34172 const MiniContextMenuParams& params);
173 virtual void OnTabbedOut(bool reverse);
[email protected]5a8db802010-10-06 17:34:43174
175 // Other
[email protected]f5494d42010-12-23 22:15:34176 virtual void OnTabClosed();
177 virtual void OnAttachTab(const AttachExternalTabParams& attach_params);
[email protected]5a8db802010-10-06 17:34:43178
179 // end of ChromeProxyDelegate methods
180 //////////////////////////////////////////////////////////////////////////
[email protected]11b6e602010-10-13 16:02:26181 void Init();
[email protected]5a8db802010-10-06 17:34:43182 void Destroy();
183
184 // The UiXXXX are the ChromeProxyDelegate methods but on UI thread.
185 void UiConnected(ChromeProxy* proxy);
186 void UiPeerLost(ChromeProxy* proxy, DisconnectReason reason);
[email protected]314a06962010-10-20 21:32:32187 void UiCompleted_CreateTab(bool success, HWND chrome_window,
[email protected]751bf4b2010-11-05 22:06:31188 HWND tab_window, int tab_handle, int session_id);
[email protected]5a8db802010-10-06 17:34:43189
190 // With the present state of affairs the only response we can possibly handle
191 // in the background IPC thread is Completed_CreateTab() where we can
192 // initiate a navigation (if there is a pending one).
193 // To simplify - will handle Completed_CreateTab in UI thread and avoid
194 // the need of lock when accessing members.
195 enum {
196 NONE,
197 INIT_IN_PROGRESS,
198 CREATE_TAB_IN_PROGRESS,
199 READY,
200 RELEASE_CF_PROXY_IN_PROGRESS
201 } state_;
202 int tab_;
[email protected]314a06962010-10-20 21:32:32203 HWND tab_wnd_;
204 HWND chrome_wnd_;
[email protected]5a8db802010-10-06 17:34:43205 ChromeProxyFactory* proxy_factory_;
[email protected]11b6e602010-10-13 16:02:26206 // Accessed only in the UI thread for simplicity.
[email protected]5a8db802010-10-06 17:34:43207 ChromeProxy* proxy_;
[email protected]11b6e602010-10-13 16:02:26208 // Accessed from ipc thread as well. It's safe if the object goes away
209 // because this should be preceded by destruction of the window and
210 // therefore all queued tasks should be destroyed.
[email protected]5a8db802010-10-06 17:34:43211 UIDelegate* ui_delegate_;
212 TaskMarshallerThroughMessageQueue ui_;
213
214 scoped_ptr<base::WaitableEvent> done_;
215
216 CreateTabParams tab_params_;
217 struct PendingNavigation {
218 GURL url;
219 GURL referrer;
220 void Set(const GURL& gurl, const GURL& ref) {
221 url = gurl;
222 referrer = ref;
223 }
224 } pending_navigation_;
[email protected]5a8db802010-10-06 17:34:43225};
226
227#endif // CHROME_FRAME_EXTERNAL_TAB_H_