Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: chrome_frame/chrome_frame_automation.h

Issue 3061036: Handle automation server crashes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/chrome_frame_activex_base.h ('k') | chrome_frame/chrome_frame_automation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ 5 #ifndef CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_
6 #define CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ 6 #define CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_
7 7
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlwin.h> 9 #include <atlwin.h>
10 #include <string> 10 #include <string>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 virtual void CancelAsync(void* key) = 0; 44 virtual void CancelAsync(void* key) = 0;
45 virtual scoped_refptr<TabProxy> CreateTabProxy(int handle) = 0; 45 virtual scoped_refptr<TabProxy> CreateTabProxy(int handle) = 0;
46 virtual void ReleaseTabProxy(AutomationHandle handle) = 0; 46 virtual void ReleaseTabProxy(AutomationHandle handle) = 0;
47 virtual std::string server_version() = 0; 47 virtual std::string server_version() = 0;
48 48
49 virtual void SendProxyConfig(const std::string&) = 0; 49 virtual void SendProxyConfig(const std::string&) = 0;
50 protected: 50 protected:
51 virtual ~ChromeFrameAutomationProxy() {} 51 virtual ~ChromeFrameAutomationProxy() {}
52 }; 52 };
53 53
54 // Forward declarations.
55 class ProxyFactory;
56
54 // We extend the AutomationProxy class to handle our custom 57 // We extend the AutomationProxy class to handle our custom
55 // IPC messages 58 // IPC messages
56 class ChromeFrameAutomationProxyImpl : public ChromeFrameAutomationProxy, 59 class ChromeFrameAutomationProxyImpl
57 // We have to derive from automationproxy since we want access to some members 60 : public ChromeFrameAutomationProxy,
58 // (tracker_ & channel_) - simple aggregation wont work; 61 // We have to derive from automationproxy since we want access to some
59 // .. and non-public inheritance is verboten. 62 // members (tracker_ & channel_) - simple aggregation wont work;
60 public AutomationProxy { 63 // .. and non-public inheritance is verboten.
64 public AutomationProxy {
61 public: 65 public:
66 ~ChromeFrameAutomationProxyImpl();
62 virtual void SendAsAsync( 67 virtual void SendAsAsync(
63 IPC::SyncMessage* msg, 68 IPC::SyncMessage* msg,
64 SyncMessageReplyDispatcher::SyncMessageCallContext* context, 69 SyncMessageReplyDispatcher::SyncMessageCallContext* context,
65 void* key); 70 void* key);
66 71
72 // Called on the worker thread.
73 virtual void OnChannelError();
74
67 virtual void CancelAsync(void* key); 75 virtual void CancelAsync(void* key);
68 76
69 virtual scoped_refptr<TabProxy> CreateTabProxy(int handle); 77 virtual scoped_refptr<TabProxy> CreateTabProxy(int handle);
70 virtual void ReleaseTabProxy(AutomationHandle handle); 78 virtual void ReleaseTabProxy(AutomationHandle handle);
71 virtual std::string server_version() { 79 virtual std::string server_version() {
72 return AutomationProxy::server_version(); 80 return AutomationProxy::server_version();
73 } 81 }
74 82
75 virtual bool Send(IPC::Message* msg) { 83 virtual bool Send(IPC::Message* msg) {
76 return AutomationProxy::Send(msg); 84 return AutomationProxy::Send(msg);
77 } 85 }
78 86
79 virtual void SendProxyConfig(const std::string& p) { 87 virtual void SendProxyConfig(const std::string& p) {
80 AutomationProxy::SendProxyConfig(p); 88 AutomationProxy::SendProxyConfig(p);
81 } 89 }
82 90
83 protected: 91 protected:
84 explicit ChromeFrameAutomationProxyImpl(int launch_timeout); 92 friend class AutomationProxyCacheEntry;
85 ~ChromeFrameAutomationProxyImpl(); 93 ChromeFrameAutomationProxyImpl(AutomationProxyCacheEntry* entry,
94 int launch_timeout);
95
86 class CFMsgDispatcher; 96 class CFMsgDispatcher;
97 class TabProxyNotificationMessageFilter;
98
87 scoped_refptr<CFMsgDispatcher> sync_; 99 scoped_refptr<CFMsgDispatcher> sync_;
88 class TabProxyNotificationMessageFilter;
89 scoped_refptr<TabProxyNotificationMessageFilter> message_filter_; 100 scoped_refptr<TabProxyNotificationMessageFilter> message_filter_;
90 friend class ProxyFactory; 101 AutomationProxyCacheEntry* proxy_entry_;
91 }; 102 };
92 103
93 // This structure contains information used for launching chrome. 104 // This class contains information used for launching chrome.
94 struct ChromeFrameLaunchParams { 105 class ChromeFrameLaunchParams : // NOLINT
95 int automation_server_launch_timeout; 106 public base::RefCounted<ChromeFrameLaunchParams> {
96 GURL url; 107 public:
97 GURL referrer; 108 ChromeFrameLaunchParams(const GURL& url, const GURL& referrer,
98 FilePath profile_path; 109 const FilePath& profile_path,
110 const std::wstring& profile_name,
111 const std::wstring& extra_arguments,
112 bool incognito, bool widget_mode)
113 : launch_timeout_(kCommandExecutionTimeout), url_(url),
114 referrer_(referrer), profile_path_(profile_path),
115 profile_name_(profile_name), extra_arguments_(extra_arguments),
116 version_check_(true), incognito_mode_(incognito),
117 is_widget_mode_(widget_mode) {
118 }
119
120 ~ChromeFrameLaunchParams() {
121 }
122
123 void set_launch_timeout(int timeout) {
124 launch_timeout_ = timeout;
125 }
126
127 int launch_timeout() const {
128 return launch_timeout_;
129 }
130
131 const GURL& url() const {
132 return url_;
133 }
134
135 void set_url(const GURL& url) {
136 url_ = url;
137 }
138
139 const GURL& referrer() const {
140 return referrer_;
141 }
142
143 void set_referrer(const GURL& referrer) {
144 referrer_ = referrer;
145 }
146
147 const FilePath& profile_path() const {
148 return profile_path_;
149 }
150
151 const std::wstring& profile_name() const {
152 return profile_name_;
153 }
154
155 const std::wstring& extra_arguments() const {
156 return extra_arguments_;
157 }
158
159 bool version_check() const {
160 return version_check_;
161 }
162
163 void set_version_check(bool check) {
164 version_check_ = check;
165 }
166
167 bool incognito() const {
168 return incognito_mode_;
169 }
170
171 bool widget_mode() const {
172 return is_widget_mode_;
173 }
174
175 protected:
176 int launch_timeout_;
177 GURL url_;
178 GURL referrer_;
179 FilePath profile_path_;
180 std::wstring profile_name_;
181 std::wstring extra_arguments_;
182 bool version_check_;
183 bool incognito_mode_;
184 bool is_widget_mode_;
185
186 private:
187 DISALLOW_COPY_AND_ASSIGN(ChromeFrameLaunchParams);
188 };
189
190 // Callback when chrome process launch is complete and automation handshake
191 // (Hello message) is established.
192 struct DECLSPEC_NOVTABLE LaunchDelegate { // NOLINT
193 virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy,
194 AutomationLaunchResult result) = 0;
195 virtual void AutomationServerDied() = 0;
196 }; // NOLINT
197
198 // Manages a cached ChromeFrameAutomationProxyImpl entry and holds
199 // reference-less pointers to LaunchDelegate(s) to be notified in case
200 // of automation server process changes.
201 class AutomationProxyCacheEntry
202 : public base::RefCounted<AutomationProxyCacheEntry> {
203 public:
204 AutomationProxyCacheEntry(ChromeFrameLaunchParams* params,
205 LaunchDelegate* delegate);
206
207 ~AutomationProxyCacheEntry();
208
209 void AddDelegate(LaunchDelegate* delegate);
210 void RemoveDelegate(LaunchDelegate* delegate, base::WaitableEvent* done,
211 bool* was_last_delegate);
212
213 void StartSendUmaInterval(ChromeFrameHistogramSnapshots* snapshots,
214 int send_interval);
215
216 DWORD WaitForThread(DWORD timeout) { // NOLINT
217 DCHECK(thread_.get());
218 return ::WaitForSingleObject(thread_->thread_handle(), timeout);
219 }
220
221 bool IsSameProfile(const std::wstring& name) const {
222 return lstrcmpiW(name.c_str(), profile_name.c_str()) == 0;
223 }
224
225 base::Thread* thread() const {
226 return thread_.get();
227 }
228
229 MessageLoop* message_loop() const {
230 return thread_->message_loop();
231 }
232
233 bool IsSameThread(PlatformThreadId id) const {
234 return thread_->thread_id() == id;
235 }
236
237 ChromeFrameAutomationProxyImpl* proxy() const {
238 DCHECK(IsSameThread(PlatformThread::CurrentId()));
239 return proxy_.get();
240 }
241
242 // Called by the proxy when the automation server has unexpectedly gone away.
243 void OnChannelError();
244
245 protected:
246 void CreateProxy(ChromeFrameLaunchParams* params,
247 LaunchDelegate* delegate);
248 void SendUMAData();
249
250 protected:
99 std::wstring profile_name; 251 std::wstring profile_name;
100 std::wstring extra_chrome_arguments; 252 scoped_ptr<base::Thread> thread_;
101 bool perform_version_check; 253 scoped_ptr<ChromeFrameAutomationProxyImpl> proxy_;
102 bool incognito_mode; 254 AutomationLaunchResult launch_result_;
103 bool is_widget_mode; 255 typedef std::vector<LaunchDelegate*> LaunchDelegates;
256 LaunchDelegates launch_delegates_;
257 // Used for UMA histogram logging to measure the time for the chrome
258 // automation server to start;
259 base::TimeTicks automation_server_launch_start_time_;
260 ChromeFrameHistogramSnapshots* snapshots_;
261 int uma_send_interval_;
104 }; 262 };
105 263
106 // We must create and destroy automation proxy in a thread with a message loop. 264 // We must create and destroy automation proxy in a thread with a message loop.
107 // Hence thread cannot be a member of the proxy. 265 // Hence thread cannot be a member of the proxy.
108 class ProxyFactory { 266 class ProxyFactory {
109 public: 267 public:
110 // Callback when chrome process launch is complete and automation handshake
111 // (Hello message) is established.
112 struct DECLSPEC_NOVTABLE LaunchDelegate { // NOLINT
113 virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy,
114 AutomationLaunchResult result) = 0;
115 }; // NOLINT
116
117 ProxyFactory(); 268 ProxyFactory();
118 virtual ~ProxyFactory(); 269 virtual ~ProxyFactory();
119 270
271 // Fetches or creates a new automation server instance.
272 // delegate may be NULL. If non-null, a pointer to the delegate will
273 // be stored for the lifetime of the automation process or until
274 // ReleaseAutomationServer is called.
120 virtual void GetAutomationServer(LaunchDelegate* delegate, 275 virtual void GetAutomationServer(LaunchDelegate* delegate,
121 const ChromeFrameLaunchParams& params, 276 ChromeFrameLaunchParams* params,
122 void** automation_server_id); 277 void** automation_server_id);
123 virtual bool ReleaseAutomationServer(void* server_id); 278 virtual bool ReleaseAutomationServer(void* server_id,
279 LaunchDelegate* delegate);
124 280
125 private: 281 private:
126 struct ProxyCacheEntry { 282 typedef StackVector<scoped_refptr<AutomationProxyCacheEntry>, 4> Vector;
127 std::wstring profile_name;
128 int ref_count;
129 scoped_ptr<base::Thread> thread;
130 ChromeFrameAutomationProxyImpl* proxy;
131 AutomationLaunchResult launch_result;
132 explicit ProxyCacheEntry(const std::wstring& profile);
133 };
134
135 void CreateProxy(ProxyCacheEntry* entry,
136 const ChromeFrameLaunchParams& params,
137 LaunchDelegate* delegate);
138 void ReleaseProxy(ProxyCacheEntry* entry, base::WaitableEvent* done);
139
140 void SendUMAData(ProxyCacheEntry* proxy_entry);
141
142 typedef StackVector<ProxyCacheEntry*, 4> Vector;
143 Vector proxies_; 283 Vector proxies_;
144 // Lock if we are going to call GetAutomationServer from more than one thread. 284 // Lock if we are going to call GetAutomationServer from more than one thread.
145 Lock lock_; 285 Lock lock_;
146 286
147 // Used for UMA histogram logging to measure the time for the chrome
148 // automation server to start;
149 base::TimeTicks automation_server_launch_start_time_;
150
151 // Gathers histograms to be sent to Chrome. 287 // Gathers histograms to be sent to Chrome.
152 ChromeFrameHistogramSnapshots chrome_frame_histograms_; 288 ChromeFrameHistogramSnapshots chrome_frame_histograms_;
153 289
154 // Interval for sending UMA data 290 // Interval for sending UMA data
155 int uma_send_interval_; 291 int uma_send_interval_;
156 }; 292 };
157 293
158 // Handles all automation requests initiated from the chrome frame objects. 294 // Handles all automation requests initiated from the chrome frame objects.
159 // These include the chrome tab/chrome frame activex/chrome frame npapi 295 // These include the chrome tab/chrome frame activex/chrome frame npapi
160 // plugin objects. 296 // plugin objects.
161 class ChromeFrameAutomationClient 297 class ChromeFrameAutomationClient
162 : public CWindowImpl<ChromeFrameAutomationClient>, 298 : public CWindowImpl<ChromeFrameAutomationClient>,
163 public TaskMarshallerThroughWindowsMessages<ChromeFrameAutomationClient>, 299 public TaskMarshallerThroughWindowsMessages<ChromeFrameAutomationClient>,
164 public base::RefCountedThreadSafe<ChromeFrameAutomationClient>, 300 public base::RefCountedThreadSafe<ChromeFrameAutomationClient>,
165 public PluginUrlRequestDelegate, 301 public PluginUrlRequestDelegate,
166 public TabProxy::TabProxyDelegate, 302 public TabProxy::TabProxyDelegate,
167 public ProxyFactory::LaunchDelegate { 303 public LaunchDelegate {
168 public: 304 public:
169 ChromeFrameAutomationClient(); 305 ChromeFrameAutomationClient();
170 ~ChromeFrameAutomationClient(); 306 ~ChromeFrameAutomationClient();
171 307
172 // Called from UI thread. 308 // Called from UI thread.
173 virtual bool Initialize(ChromeFrameDelegate* chrome_frame_delegate, 309 virtual bool Initialize(ChromeFrameDelegate* chrome_frame_delegate,
174 const ChromeFrameLaunchParams& chrome_launch_params); 310 ChromeFrameLaunchParams* chrome_launch_params);
175 void Uninitialize(); 311 void Uninitialize();
312 void NotifyAndUninitialize();
176 313
177 virtual bool InitiateNavigation(const std::string& url, 314 virtual bool InitiateNavigation(const std::string& url,
178 const std::string& referrer, 315 const std::string& referrer,
179 bool is_privileged); 316 bool is_privileged);
180 virtual bool NavigateToIndex(int index); 317 virtual bool NavigateToIndex(int index);
181 bool ForwardMessageFromExternalHost(const std::string& message, 318 bool ForwardMessageFromExternalHost(const std::string& message,
182 const std::string& origin, 319 const std::string& origin,
183 const std::string& target); 320 const std::string& target);
184 bool SetProxySettings(const std::string& json_encoded_proxy_settings); 321 bool SetProxySettings(const std::string& json_encoded_proxy_settings);
185 322
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // Sends an IPC message to the external tab container requesting it to run 414 // Sends an IPC message to the external tab container requesting it to run
278 // unload handlers on the page. 415 // unload handlers on the page.
279 void RunUnloadHandlers(HWND notification_window, int notification_message); 416 void RunUnloadHandlers(HWND notification_window, int notification_message);
280 417
281 // Sets the current zoom level on the tab. 418 // Sets the current zoom level on the tab.
282 void SetZoomLevel(PageZoom::Function zoom_level); 419 void SetZoomLevel(PageZoom::Function zoom_level);
283 420
284 protected: 421 protected:
285 // ChromeFrameAutomationProxy::LaunchDelegate implementation. 422 // ChromeFrameAutomationProxy::LaunchDelegate implementation.
286 virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy, 423 virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy,
287 AutomationLaunchResult result); 424 AutomationLaunchResult result);
425 virtual void AutomationServerDied();
426
288 // TabProxyDelegate implementation 427 // TabProxyDelegate implementation
289 virtual void OnMessageReceived(TabProxy* tab, const IPC::Message& msg); 428 virtual void OnMessageReceived(TabProxy* tab, const IPC::Message& msg);
290 virtual void OnChannelError(TabProxy* tab); 429 virtual void OnChannelError(TabProxy* tab);
291 430
292 void CreateExternalTab(); 431 void CreateExternalTab();
293 AutomationLaunchResult CreateExternalTabComplete(HWND chrome_window, 432 AutomationLaunchResult CreateExternalTabComplete(HWND chrome_window,
294 HWND tab_window, 433 HWND tab_window,
295 int tab_handle); 434 int tab_handle);
296 // Called in UI thread. Here we fire event to the client notifying for 435 // Called in UI thread. Here we fire event to the client notifying for
297 // the result of Initialize() method call. 436 // the result of Initialize() method call.
298 void InitializeComplete(AutomationLaunchResult result); 437 void InitializeComplete(AutomationLaunchResult result);
299 438
300 virtual void OnFinalMessage(HWND wnd) { 439 virtual void OnFinalMessage(HWND wnd) {
301 Release(); 440 Release();
302 } 441 }
303 442
443 scoped_refptr<ChromeFrameLaunchParams> launch_params() {
444 return chrome_launch_params_;
445 }
446
304 private: 447 private:
305 void OnMessageReceivedUIThread(const IPC::Message& msg); 448 void OnMessageReceivedUIThread(const IPC::Message& msg);
306 void OnChannelErrorUIThread(); 449 void OnChannelErrorUIThread();
307 450
308 HWND chrome_window() const { return chrome_window_; } 451 HWND chrome_window() const { return chrome_window_; }
309 void BeginNavigate(const GURL& url, const GURL& referrer); 452 void BeginNavigate();
310 void BeginNavigateCompleted(AutomationMsg_NavigationResponseValues result); 453 void BeginNavigateCompleted(AutomationMsg_NavigationResponseValues result);
311 454
312 // Helpers 455 // Helpers
313 void ReportNavigationError(AutomationMsg_NavigationResponseValues error_code, 456 void ReportNavigationError(AutomationMsg_NavigationResponseValues error_code,
314 const std::string& url); 457 const std::string& url);
315 bool is_initialized() const { 458 bool is_initialized() const {
316 return init_state_ == INITIALIZED; 459 return init_state_ == INITIALIZED;
317 } 460 }
318 461
319 HWND parent_window_; 462 HWND parent_window_;
(...skipping 25 matching lines...) Expand all
345 bool handle_top_level_requests_; 488 bool handle_top_level_requests_;
346 ProxyFactory* proxy_factory_; 489 ProxyFactory* proxy_factory_;
347 int tab_handle_; 490 int tab_handle_;
348 // Only used if we attach to an existing tab. 491 // Only used if we attach to an existing tab.
349 uint64 external_tab_cookie_; 492 uint64 external_tab_cookie_;
350 493
351 // Set to true if we received a navigation request prior to the automation 494 // Set to true if we received a navigation request prior to the automation
352 // server being initialized. 495 // server being initialized.
353 bool navigate_after_initialization_; 496 bool navigate_after_initialization_;
354 497
355 ChromeFrameLaunchParams chrome_launch_params_; 498 scoped_refptr<ChromeFrameLaunchParams> chrome_launch_params_;
356 499
357 // When host network stack is used, this object is in charge of 500 // When host network stack is used, this object is in charge of
358 // handling network requests. 501 // handling network requests.
359 PluginUrlRequestManager* url_fetcher_; 502 PluginUrlRequestManager* url_fetcher_;
360 PluginUrlRequestManager::ThreadSafeFlags url_fetcher_flags_; 503 PluginUrlRequestManager::ThreadSafeFlags url_fetcher_flags_;
361 504
362 bool ProcessUrlRequestMessage(TabProxy* tab, const IPC::Message& msg, 505 bool ProcessUrlRequestMessage(TabProxy* tab, const IPC::Message& msg,
363 bool ui_thread); 506 bool ui_thread);
364 507
365 // PluginUrlRequestDelegate implementation. Simply adds tab's handle 508 // PluginUrlRequestDelegate implementation. Simply adds tab's handle
(...skipping 12 matching lines...) Expand all
378 public: 521 public:
379 void SetUrlFetcher(PluginUrlRequestManager* url_fetcher) { 522 void SetUrlFetcher(PluginUrlRequestManager* url_fetcher) {
380 DCHECK(url_fetcher != NULL); 523 DCHECK(url_fetcher != NULL);
381 url_fetcher_ = url_fetcher; 524 url_fetcher_ = url_fetcher;
382 url_fetcher_flags_ = url_fetcher->GetThreadSafeFlags(); 525 url_fetcher_flags_ = url_fetcher->GetThreadSafeFlags();
383 url_fetcher_->set_delegate(this); 526 url_fetcher_->set_delegate(this);
384 } 527 }
385 }; 528 };
386 529
387 #endif // CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ 530 #endif // CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_
OLDNEW
« no previous file with comments | « chrome_frame/chrome_frame_activex_base.h ('k') | chrome_frame/chrome_frame_automation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698