[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 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_AUTOMATION_H_ |
| 6 | #define CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ |
| 7 | |
| 8 | #include <atlbase.h> |
| 9 | #include <atlwin.h> |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 10 | #include <map> |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 11 | #include <string> |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 12 | #include <vector> |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 13 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
| 15 | #include "base/memory/scoped_handle.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 16 | #include "base/stack_container.h" |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 17 | #include "base/synchronization/lock.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 18 | #include "base/threading/thread.h" |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 19 | #include "base/timer.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 20 | #include "chrome/test/automation/automation_proxy.h" |
| 21 | #include "chrome/test/automation/tab_proxy.h" |
| 22 | #include "chrome_frame/chrome_frame_delegate.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 23 | #include "chrome_frame/plugin_url_request.h" |
[email protected] | d0b8e5f | 2010-05-18 04:26:02 | [diff] [blame] | 24 | #include "chrome_frame/sync_msg_reply_dispatcher.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 25 | #include "content/public/common/page_zoom.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 26 | |
[email protected] | b0b85fe9 | 2009-10-21 00:11:23 | [diff] [blame] | 27 | // By a convoluated route, this timeout also winds up being the sync automation |
| 28 | // message timeout. See the ChromeFrameAutomationProxyImpl ctor and the |
| 29 | // AutomationProxy ctor for details. |
| 30 | const unsigned long kCommandExecutionTimeout = 60000; // NOLINT, 60 seconds |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 31 | |
| 32 | class ProxyFactory; |
[email protected] | 354bcba | 2010-12-14 04:34:43 | [diff] [blame] | 33 | class NavigationConstraints; |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 34 | enum AutomationPageFontSize; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 35 | |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 36 | struct DECLSPEC_NOVTABLE ChromeFrameAutomationProxy { // NOLINT |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 37 | virtual bool Send(IPC::Message* msg) = 0; |
| 38 | |
[email protected] | d0b8e5f | 2010-05-18 04:26:02 | [diff] [blame] | 39 | virtual void SendAsAsync( |
| 40 | IPC::SyncMessage* msg, |
| 41 | SyncMessageReplyDispatcher::SyncMessageCallContext* context, |
| 42 | void* key) = 0; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 43 | virtual void CancelAsync(void* key) = 0; |
| 44 | virtual scoped_refptr<TabProxy> CreateTabProxy(int handle) = 0; |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 45 | virtual void ReleaseTabProxy(AutomationHandle handle) = 0; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 46 | virtual std::string server_version() = 0; |
| 47 | |
| 48 | virtual void SendProxyConfig(const std::string&) = 0; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 49 | protected: |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 50 | virtual ~ChromeFrameAutomationProxy() {} |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 51 | }; |
| 52 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 53 | // Forward declarations. |
| 54 | class ProxyFactory; |
| 55 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 56 | // We extend the AutomationProxy class to handle our custom |
| 57 | // IPC messages |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 58 | class ChromeFrameAutomationProxyImpl |
| 59 | : public ChromeFrameAutomationProxy, |
| 60 | // We have to derive from automationproxy since we want access to some |
| 61 | // members (tracker_ & channel_) - simple aggregation wont work; |
| 62 | // .. and non-public inheritance is verboten. |
| 63 | public AutomationProxy { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 64 | public: |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 65 | ~ChromeFrameAutomationProxyImpl(); |
[email protected] | d0b8e5f | 2010-05-18 04:26:02 | [diff] [blame] | 66 | virtual void SendAsAsync( |
| 67 | IPC::SyncMessage* msg, |
| 68 | SyncMessageReplyDispatcher::SyncMessageCallContext* context, |
| 69 | void* key); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 70 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 71 | // Called on the worker thread. |
| 72 | virtual void OnChannelError(); |
| 73 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 74 | virtual void CancelAsync(void* key); |
| 75 | |
| 76 | virtual scoped_refptr<TabProxy> CreateTabProxy(int handle); |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 77 | virtual void ReleaseTabProxy(AutomationHandle handle); |
[email protected] | e67a73f4 | 2010-08-31 15:05:02 | [diff] [blame] | 78 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 79 | virtual std::string server_version() { |
| 80 | return AutomationProxy::server_version(); |
| 81 | } |
| 82 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 83 | virtual bool Send(IPC::Message* msg) { |
| 84 | return AutomationProxy::Send(msg); |
| 85 | } |
| 86 | |
| 87 | virtual void SendProxyConfig(const std::string& p) { |
| 88 | AutomationProxy::SendProxyConfig(p); |
| 89 | } |
| 90 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 91 | protected: |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 92 | friend class AutomationProxyCacheEntry; |
| 93 | ChromeFrameAutomationProxyImpl(AutomationProxyCacheEntry* entry, |
[email protected] | dfe0deb | 2010-12-23 20:40:16 | [diff] [blame] | 94 | std::string channel_id, |
[email protected] | a0b900b | 2012-07-20 19:41:56 | [diff] [blame] | 95 | base::TimeDelta launch_timeout); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 96 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 97 | class CFMsgDispatcher; |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 98 | class TabProxyNotificationMessageFilter; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 99 | |
| 100 | scoped_refptr<CFMsgDispatcher> sync_; |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 101 | scoped_refptr<TabProxyNotificationMessageFilter> message_filter_; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 102 | AutomationProxyCacheEntry* proxy_entry_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 103 | }; |
| 104 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 105 | // This class contains information used for launching chrome. |
| 106 | class ChromeFrameLaunchParams : // NOLINT |
[email protected] | e67a73f4 | 2010-08-31 15:05:02 | [diff] [blame] | 107 | public base::RefCountedThreadSafe<ChromeFrameLaunchParams> { |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 108 | public: |
| 109 | ChromeFrameLaunchParams(const GURL& url, const GURL& referrer, |
| 110 | const FilePath& profile_path, |
| 111 | const std::wstring& profile_name, |
[email protected] | 6ae3d49 | 2010-10-20 14:01:21 | [diff] [blame] | 112 | const std::wstring& language, |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 113 | bool incognito, bool widget_mode, |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 114 | bool route_all_top_level_navigations, |
| 115 | bool send_shutdown_delay_switch) |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 116 | : launch_timeout_(kCommandExecutionTimeout), url_(url), |
| 117 | referrer_(referrer), profile_path_(profile_path), |
[email protected] | 6ae3d49 | 2010-10-20 14:01:21 | [diff] [blame] | 118 | profile_name_(profile_name), language_(language), |
[email protected] | c70e558 | 2011-12-20 21:22:45 | [diff] [blame] | 119 | version_check_(true), incognito_mode_(incognito), |
| 120 | is_widget_mode_(widget_mode), |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 121 | route_all_top_level_navigations_(route_all_top_level_navigations), |
| 122 | send_shutdown_delay_switch_(send_shutdown_delay_switch) { |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | ~ChromeFrameLaunchParams() { |
| 126 | } |
| 127 | |
| 128 | void set_launch_timeout(int timeout) { |
| 129 | launch_timeout_ = timeout; |
| 130 | } |
| 131 | |
| 132 | int launch_timeout() const { |
| 133 | return launch_timeout_; |
| 134 | } |
| 135 | |
| 136 | const GURL& url() const { |
| 137 | return url_; |
| 138 | } |
| 139 | |
| 140 | void set_url(const GURL& url) { |
| 141 | url_ = url; |
| 142 | } |
| 143 | |
| 144 | const GURL& referrer() const { |
| 145 | return referrer_; |
| 146 | } |
| 147 | |
| 148 | void set_referrer(const GURL& referrer) { |
| 149 | referrer_ = referrer; |
| 150 | } |
| 151 | |
| 152 | const FilePath& profile_path() const { |
| 153 | return profile_path_; |
| 154 | } |
| 155 | |
| 156 | const std::wstring& profile_name() const { |
| 157 | return profile_name_; |
| 158 | } |
| 159 | |
[email protected] | 6ae3d49 | 2010-10-20 14:01:21 | [diff] [blame] | 160 | const std::wstring& language() const { |
| 161 | return language_; |
| 162 | } |
| 163 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 164 | bool version_check() const { |
| 165 | return version_check_; |
| 166 | } |
| 167 | |
| 168 | void set_version_check(bool check) { |
| 169 | version_check_ = check; |
| 170 | } |
| 171 | |
| 172 | bool incognito() const { |
| 173 | return incognito_mode_; |
| 174 | } |
| 175 | |
| 176 | bool widget_mode() const { |
| 177 | return is_widget_mode_; |
| 178 | } |
| 179 | |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 180 | void set_route_all_top_level_navigations( |
| 181 | bool route_all_top_level_navigations) { |
| 182 | route_all_top_level_navigations_ = route_all_top_level_navigations; |
| 183 | } |
| 184 | |
| 185 | bool route_all_top_level_navigations() const { |
| 186 | return route_all_top_level_navigations_; |
| 187 | } |
| 188 | |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 189 | bool send_shutdown_delay_switch() const { |
| 190 | return send_shutdown_delay_switch_; |
| 191 | } |
| 192 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 193 | protected: |
| 194 | int launch_timeout_; |
| 195 | GURL url_; |
| 196 | GURL referrer_; |
| 197 | FilePath profile_path_; |
| 198 | std::wstring profile_name_; |
[email protected] | 6ae3d49 | 2010-10-20 14:01:21 | [diff] [blame] | 199 | std::wstring language_; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 200 | bool version_check_; |
| 201 | bool incognito_mode_; |
| 202 | bool is_widget_mode_; |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 203 | bool route_all_top_level_navigations_; |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 204 | bool send_shutdown_delay_switch_; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 205 | |
| 206 | private: |
| 207 | DISALLOW_COPY_AND_ASSIGN(ChromeFrameLaunchParams); |
| 208 | }; |
| 209 | |
| 210 | // Callback when chrome process launch is complete and automation handshake |
[email protected] | 5548186f | 2011-12-17 03:37:55 | [diff] [blame] | 211 | // (Hello message) is established. All methods are invoked on the automation |
| 212 | // proxy's worker thread. |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 213 | struct DECLSPEC_NOVTABLE LaunchDelegate { // NOLINT |
| 214 | virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy, |
| 215 | AutomationLaunchResult result) = 0; |
| 216 | virtual void AutomationServerDied() = 0; |
| 217 | }; // NOLINT |
| 218 | |
| 219 | // Manages a cached ChromeFrameAutomationProxyImpl entry and holds |
| 220 | // reference-less pointers to LaunchDelegate(s) to be notified in case |
| 221 | // of automation server process changes. |
| 222 | class AutomationProxyCacheEntry |
| 223 | : public base::RefCounted<AutomationProxyCacheEntry> { |
| 224 | public: |
| 225 | AutomationProxyCacheEntry(ChromeFrameLaunchParams* params, |
| 226 | LaunchDelegate* delegate); |
| 227 | |
| 228 | ~AutomationProxyCacheEntry(); |
| 229 | |
| 230 | void AddDelegate(LaunchDelegate* delegate); |
| 231 | void RemoveDelegate(LaunchDelegate* delegate, base::WaitableEvent* done, |
| 232 | bool* was_last_delegate); |
| 233 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 234 | DWORD WaitForThread(DWORD timeout) { // NOLINT |
| 235 | DCHECK(thread_.get()); |
| 236 | return ::WaitForSingleObject(thread_->thread_handle(), timeout); |
| 237 | } |
| 238 | |
| 239 | bool IsSameProfile(const std::wstring& name) const { |
| 240 | return lstrcmpiW(name.c_str(), profile_name.c_str()) == 0; |
| 241 | } |
| 242 | |
| 243 | base::Thread* thread() const { |
| 244 | return thread_.get(); |
| 245 | } |
| 246 | |
| 247 | MessageLoop* message_loop() const { |
| 248 | return thread_->message_loop(); |
| 249 | } |
| 250 | |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 251 | bool IsSameThread(base::PlatformThreadId id) const { |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 252 | return thread_->thread_id() == id; |
| 253 | } |
| 254 | |
| 255 | ChromeFrameAutomationProxyImpl* proxy() const { |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 256 | DCHECK(IsSameThread(base::PlatformThread::CurrentId())); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 257 | return proxy_.get(); |
| 258 | } |
| 259 | |
| 260 | // Called by the proxy when the automation server has unexpectedly gone away. |
| 261 | void OnChannelError(); |
| 262 | |
| 263 | protected: |
| 264 | void CreateProxy(ChromeFrameLaunchParams* params, |
| 265 | LaunchDelegate* delegate); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 266 | |
| 267 | protected: |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 268 | std::wstring profile_name; |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 269 | scoped_ptr<base::Thread> thread_; |
| 270 | scoped_ptr<ChromeFrameAutomationProxyImpl> proxy_; |
| 271 | AutomationLaunchResult launch_result_; |
| 272 | typedef std::vector<LaunchDelegate*> LaunchDelegates; |
| 273 | LaunchDelegates launch_delegates_; |
| 274 | // Used for UMA histogram logging to measure the time for the chrome |
| 275 | // automation server to start; |
| 276 | base::TimeTicks automation_server_launch_start_time_; |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 277 | }; |
| 278 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 279 | // We must create and destroy automation proxy in a thread with a message loop. |
| 280 | // Hence thread cannot be a member of the proxy. |
| 281 | class ProxyFactory { |
| 282 | public: |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 283 | ProxyFactory(); |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 284 | virtual ~ProxyFactory(); |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 285 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 286 | // Fetches or creates a new automation server instance. |
| 287 | // delegate may be NULL. If non-null, a pointer to the delegate will |
| 288 | // be stored for the lifetime of the automation process or until |
| 289 | // ReleaseAutomationServer is called. |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 290 | virtual void GetAutomationServer(LaunchDelegate* delegate, |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 291 | ChromeFrameLaunchParams* params, |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 292 | void** automation_server_id); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 293 | virtual bool ReleaseAutomationServer(void* server_id, |
| 294 | LaunchDelegate* delegate); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 295 | |
| 296 | private: |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 297 | typedef StackVector<scoped_refptr<AutomationProxyCacheEntry>, 4> Vector; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 298 | Vector proxies_; |
| 299 | // Lock if we are going to call GetAutomationServer from more than one thread. |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 300 | base::Lock lock_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 301 | }; |
| 302 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 303 | // Handles all automation requests initiated from the chrome frame objects. |
[email protected] | 99d81e5 | 2011-06-29 02:29:53 | [diff] [blame] | 304 | // These include the chrome tab/chrome frame activex plugin objects. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 305 | class ChromeFrameAutomationClient |
| 306 | : public CWindowImpl<ChromeFrameAutomationClient>, |
| 307 | public TaskMarshallerThroughWindowsMessages<ChromeFrameAutomationClient>, |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 308 | public base::RefCountedThreadSafe<ChromeFrameAutomationClient>, |
| 309 | public PluginUrlRequestDelegate, |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 310 | public TabProxy::TabProxyDelegate, |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 311 | public LaunchDelegate { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 312 | public: |
| 313 | ChromeFrameAutomationClient(); |
| 314 | ~ChromeFrameAutomationClient(); |
| 315 | |
| 316 | // Called from UI thread. |
| 317 | virtual bool Initialize(ChromeFrameDelegate* chrome_frame_delegate, |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 318 | ChromeFrameLaunchParams* chrome_launch_params); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 319 | void Uninitialize(); |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 320 | void NotifyAndUninitialize(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 321 | |
[email protected] | 354bcba | 2010-12-14 04:34:43 | [diff] [blame] | 322 | virtual bool InitiateNavigation( |
| 323 | const std::string& url, |
| 324 | const std::string& referrer, |
| 325 | NavigationConstraints* navigation_constraints); |
| 326 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 327 | virtual bool NavigateToIndex(int index); |
| 328 | bool ForwardMessageFromExternalHost(const std::string& message, |
| 329 | const std::string& origin, |
| 330 | const std::string& target); |
| 331 | bool SetProxySettings(const std::string& json_encoded_proxy_settings); |
| 332 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 333 | void FindInPage(const std::wstring& search_string, |
| 334 | FindInPageDirection forward, |
| 335 | FindInPageCase match_case, |
| 336 | bool find_next); |
| 337 | |
[email protected] | 2b19e2fe | 2010-02-16 02:24:18 | [diff] [blame] | 338 | virtual void OnChromeFrameHostMoved(); |
| 339 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 340 | TabProxy* tab() const { return tab_.get(); } |
| 341 | |
| 342 | BEGIN_MSG_MAP(ChromeFrameAutomationClient) |
| 343 | CHAIN_MSG_MAP( |
| 344 | TaskMarshallerThroughWindowsMessages<ChromeFrameAutomationClient>) |
| 345 | END_MSG_MAP() |
| 346 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 347 | // Resizes the hosted chrome window. This is brokered to the chrome |
| 348 | // automation instance as the host browser could be running under low IL, |
| 349 | // which would cause the SetWindowPos call to fail. |
| 350 | void Resize(int width, int height, int flags); |
| 351 | |
| 352 | // Sets the passed in window as the parent of the external tab. |
| 353 | void SetParentWindow(HWND parent_window); |
| 354 | |
| 355 | void SendContextMenuCommandToChromeFrame(int selected_command); |
| 356 | |
| 357 | HWND tab_window() const { |
| 358 | return tab_window_; |
| 359 | } |
| 360 | |
| 361 | void ReleaseAutomationServer(); |
| 362 | |
| 363 | // Returns the version number of plugin dll. |
| 364 | std::wstring GetVersion() const; |
| 365 | |
| 366 | // BitBlts the contents of the chrome window to the print dc. |
| 367 | void Print(HDC print_dc, const RECT& print_bounds); |
| 368 | |
| 369 | // Called in full tab mode and indicates a request to chrome to print |
| 370 | // the whole tab. |
| 371 | void PrintTab(); |
| 372 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 373 | void set_use_chrome_network(bool use_chrome_network) { |
| 374 | use_chrome_network_ = use_chrome_network; |
| 375 | } |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 376 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 377 | bool use_chrome_network() const { |
| 378 | return use_chrome_network_; |
| 379 | } |
| 380 | |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 381 | bool send_shutdown_delay_switch() const { |
| 382 | return send_shutdown_delay_switch_; |
| 383 | } |
| 384 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 385 | #ifdef UNIT_TEST |
| 386 | void set_proxy_factory(ProxyFactory* factory) { |
| 387 | proxy_factory_ = factory; |
| 388 | } |
| 389 | #endif |
| 390 | |
| 391 | void set_handle_top_level_requests(bool handle_top_level_requests) { |
| 392 | handle_top_level_requests_ = handle_top_level_requests; |
| 393 | } |
| 394 | |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 395 | // Url request manager set up. |
| 396 | void SetUrlFetcher(PluginUrlRequestManager* url_fetcher); |
| 397 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 398 | // Attaches an existing external tab to this automation client instance. |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 399 | void AttachExternalTab(uint64 external_tab_cookie); |
| 400 | void BlockExternalTab(uint64 cookie); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 401 | |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 402 | void SetPageFontSize(enum AutomationPageFontSize); |
| 403 | |
[email protected] | bc73b4e5 | 2010-03-26 04:16:20 | [diff] [blame] | 404 | // For IDeleteBrowsingHistorySupport |
| 405 | void RemoveBrowsingData(int remove_mask); |
| 406 | |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 407 | // Sets the current zoom level on the tab. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 408 | void SetZoomLevel(content::PageZoom zoom_level); |
[email protected] | 7f860dd8 | 2010-08-09 23:18:05 | [diff] [blame] | 409 | |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 410 | // Fires before unload and unload handlers on the page if any. Allows the |
| 411 | // the website to put up a confirmation dialog on unload. |
| 412 | void OnUnload(bool* should_unload); |
| 413 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 414 | protected: |
| 415 | // ChromeFrameAutomationProxy::LaunchDelegate implementation. |
| 416 | virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy, |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 417 | AutomationLaunchResult result); |
| 418 | virtual void AutomationServerDied(); |
| 419 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 420 | // TabProxyDelegate implementation |
[email protected] | 6db8d990 | 2010-12-24 08:36:25 | [diff] [blame] | 421 | virtual bool OnMessageReceived(TabProxy* tab, const IPC::Message& msg); |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 422 | virtual void OnChannelError(TabProxy* tab); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 423 | |
| 424 | void CreateExternalTab(); |
[email protected] | ef8561d | 2010-05-19 02:49:18 | [diff] [blame] | 425 | AutomationLaunchResult CreateExternalTabComplete(HWND chrome_window, |
| 426 | HWND tab_window, |
[email protected] | 751bf4b | 2010-11-05 22:06:31 | [diff] [blame] | 427 | int tab_handle, |
| 428 | int session_id); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 429 | // Called in UI thread. Here we fire event to the client notifying for |
| 430 | // the result of Initialize() method call. |
| 431 | void InitializeComplete(AutomationLaunchResult result); |
| 432 | |
[email protected] | 3148c0ae | 2010-03-11 18:06:00 | [diff] [blame] | 433 | virtual void OnFinalMessage(HWND wnd) { |
| 434 | Release(); |
| 435 | } |
| 436 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 437 | scoped_refptr<ChromeFrameLaunchParams> launch_params() { |
| 438 | return chrome_launch_params_; |
| 439 | } |
| 440 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 441 | private: |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 442 | void InitializeFieldTrials(); |
| 443 | |
[email protected] | 2c9847a1 | 2010-12-24 08:16:46 | [diff] [blame] | 444 | void OnMessageReceivedUIThread(const IPC::Message& msg); |
[email protected] | efd4dfc2 | 2010-03-26 20:14:40 | [diff] [blame] | 445 | void OnChannelErrorUIThread(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 446 | |
| 447 | HWND chrome_window() const { return chrome_window_; } |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 448 | void BeginNavigate(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 449 | void BeginNavigateCompleted(AutomationMsg_NavigationResponseValues result); |
| 450 | |
| 451 | // Helpers |
| 452 | void ReportNavigationError(AutomationMsg_NavigationResponseValues error_code, |
| 453 | const std::string& url); |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 454 | |
| 455 | bool ProcessUrlRequestMessage(TabProxy* tab, const IPC::Message& msg, |
| 456 | bool ui_thread); |
| 457 | |
| 458 | // PluginUrlRequestDelegate implementation. Simply adds tab's handle |
| 459 | // as parameter and forwards to Chrome via IPC. |
| 460 | virtual void OnResponseStarted(int request_id, const char* mime_type, |
| 461 | const char* headers, int size, base::Time last_modified, |
[email protected] | 0d282c2e | 2011-02-24 20:42:51 | [diff] [blame] | 462 | const std::string& redirect_url, int redirect_status, |
| 463 | const net::HostPortPair& socket_address); |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 464 | virtual void OnReadComplete(int request_id, const std::string& data); |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 465 | virtual void OnResponseEnd(int request_id, |
| 466 | const net::URLRequestStatus& status); |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 467 | virtual void OnCookiesRetrieved(bool success, const GURL& url, |
| 468 | const std::string& cookie_string, int cookie_id); |
| 469 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 470 | bool is_initialized() const { |
| 471 | return init_state_ == INITIALIZED; |
| 472 | } |
| 473 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 474 | HWND parent_window_; |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 475 | base::PlatformThreadId ui_thread_id_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 476 | |
| 477 | void* automation_server_id_; |
| 478 | ChromeFrameAutomationProxy* automation_server_; |
[email protected] | a5205b6 | 2010-05-19 01:31:31 | [diff] [blame] | 479 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 480 | HWND chrome_window_; |
| 481 | scoped_refptr<TabProxy> tab_; |
| 482 | ChromeFrameDelegate* chrome_frame_delegate_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 483 | |
| 484 | // Handle to the underlying chrome window. This is a child of the external |
| 485 | // tab window. |
| 486 | HWND tab_window_; |
| 487 | |
| 488 | // Keeps track of the version of Chrome we're talking to. |
| 489 | std::string automation_server_version_; |
| 490 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 491 | typedef enum InitializationState { |
| 492 | UNINITIALIZED = 0, |
| 493 | INITIALIZING, |
| 494 | INITIALIZED, |
| 495 | UNINITIALIZING, |
| 496 | }; |
| 497 | |
| 498 | InitializationState init_state_; |
| 499 | bool use_chrome_network_; |
| 500 | bool handle_top_level_requests_; |
| 501 | ProxyFactory* proxy_factory_; |
| 502 | int tab_handle_; |
[email protected] | 751bf4b | 2010-11-05 22:06:31 | [diff] [blame] | 503 | // The SessionId used by Chrome as the id in the Javascript Tab object. |
| 504 | int session_id_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 505 | // Only used if we attach to an existing tab. |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 506 | uint64 external_tab_cookie_; |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 507 | |
| 508 | // Set to true if we received a navigation request prior to the automation |
| 509 | // server being initialized. |
| 510 | bool navigate_after_initialization_; |
| 511 | |
[email protected] | bbfa9a1 | 2010-08-10 14:09:37 | [diff] [blame] | 512 | scoped_refptr<ChromeFrameLaunchParams> chrome_launch_params_; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 513 | |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 514 | // Cache security manager for URL zone checking |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 515 | base::win::ScopedComPtr<IInternetSecurityManager> security_manager_; |
[email protected] | d266ce8 | 2010-08-13 21:33:40 | [diff] [blame] | 516 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 517 | // When host network stack is used, this object is in charge of |
| 518 | // handling network requests. |
| 519 | PluginUrlRequestManager* url_fetcher_; |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 520 | PluginUrlRequestManager::ThreadSafeFlags url_fetcher_flags_; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 521 | |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 522 | // set to true if the host needs to get notified of all top level navigations |
| 523 | // in this page. This typically applies to hosts which would render the new |
| 524 | // page without chrome frame. Defaults to false. |
| 525 | bool route_all_top_level_navigations_; |
| 526 | |
[email protected] | add184df | 2012-03-10 10:08:57 | [diff] [blame] | 527 | // Set to true if Chrome Frame should tell Chrome to delay shutdown after |
| 528 | // we break a connection. Currently used only as part of a field trial. |
| 529 | bool send_shutdown_delay_switch_; |
| 530 | |
[email protected] | d0b8e5f | 2010-05-18 04:26:02 | [diff] [blame] | 531 | friend class BeginNavigateContext; |
| 532 | friend class CreateExternalTabContext; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 533 | }; |
| 534 | |
| 535 | #endif // CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ |