OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/automation/automation_resource_message_filter.h" | 5 #include "chrome/browser/automation/automation_resource_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 int tab_handle, AutomationResourceMessageFilter* filter, | 256 int tab_handle, AutomationResourceMessageFilter* filter, |
257 bool pending_view) { | 257 bool pending_view) { |
258 RendererId renderer_key(renderer_pid, renderer_id); | 258 RendererId renderer_key(renderer_pid, renderer_id); |
259 | 259 |
260 RenderViewMap::iterator automation_details_iter( | 260 RenderViewMap::iterator automation_details_iter( |
261 filtered_render_views_.Get().find(renderer_key)); | 261 filtered_render_views_.Get().find(renderer_key)); |
262 // We need to match the renderer key and the AutomationResourceMessageFilter | 262 // We need to match the renderer key and the AutomationResourceMessageFilter |
263 // instances. If the filter instances are different it means that a new | 263 // instances. If the filter instances are different it means that a new |
264 // automation channel (External host process) was created for this tab. | 264 // automation channel (External host process) was created for this tab. |
265 if (automation_details_iter != filtered_render_views_.Get().end() && | 265 if (automation_details_iter != filtered_render_views_.Get().end() && |
266 automation_details_iter->second.filter == filter) { | 266 automation_details_iter->second.filter.get() == filter) { |
267 DCHECK_GT(automation_details_iter->second.ref_count, 0); | 267 DCHECK_GT(automation_details_iter->second.ref_count, 0); |
268 automation_details_iter->second.ref_count++; | 268 automation_details_iter->second.ref_count++; |
269 // The tab handle and the pending status may have changed:- | 269 // The tab handle and the pending status may have changed:- |
270 // 1.A external tab container is being destroyed and a new one is being | 270 // 1.A external tab container is being destroyed and a new one is being |
271 // created. | 271 // created. |
272 // 2.The external tab container being destroyed receives a RVH created | 272 // 2.The external tab container being destroyed receives a RVH created |
273 // notification for the new RVH created to host the newly created tab. | 273 // notification for the new RVH created to host the newly created tab. |
274 // In this case the tab handle in the AutomationDetails structure would | 274 // In this case the tab handle in the AutomationDetails structure would |
275 // be invalid as it points to a destroyed tab. | 275 // be invalid as it points to a destroyed tab. |
276 // We need to replace the handle of the external tab being destroyed with | 276 // We need to replace the handle of the external tab being destroyed with |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 RenderViewMap::iterator automation_details_iter( | 314 RenderViewMap::iterator automation_details_iter( |
315 filtered_render_views_.Get().find(renderer_key)); | 315 filtered_render_views_.Get().find(renderer_key)); |
316 | 316 |
317 DCHECK(automation_details_iter != filtered_render_views_.Get().end()) | 317 DCHECK(automation_details_iter != filtered_render_views_.Get().end()) |
318 << "Failed to find pending view for renderer pid:" | 318 << "Failed to find pending view for renderer pid:" |
319 << renderer_pid << ", render view id:" << renderer_id; | 319 << renderer_pid << ", render view id:" << renderer_id; |
320 | 320 |
321 DCHECK(automation_details_iter->second.is_pending_render_view); | 321 DCHECK(automation_details_iter->second.is_pending_render_view); |
322 | 322 |
323 AutomationResourceMessageFilter* old_filter = | 323 AutomationResourceMessageFilter* old_filter = |
324 automation_details_iter->second.filter; | 324 automation_details_iter->second.filter.get(); |
325 DCHECK(old_filter != NULL); | 325 DCHECK(old_filter != NULL); |
326 | 326 |
327 filtered_render_views_.Get()[renderer_key] = | 327 filtered_render_views_.Get()[renderer_key] = |
328 AutomationDetails(tab_handle, filter, false); | 328 AutomationDetails(tab_handle, filter, false); |
329 | 329 |
330 ResumeJobsForPendingView(tab_handle, old_filter, filter); | 330 ResumeJobsForPendingView(tab_handle, old_filter, filter); |
331 } | 331 } |
332 | 332 |
333 bool AutomationResourceMessageFilter::LookupRegisteredRenderView( | 333 bool AutomationResourceMessageFilter::LookupRegisteredRenderView( |
334 int renderer_pid, int renderer_id, AutomationDetails* details) { | 334 int renderer_pid, int renderer_id, AutomationDetails* details) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 void AutomationResourceMessageFilter::GetCookiesForUrl( | 387 void AutomationResourceMessageFilter::GetCookiesForUrl( |
388 BrowserMessageFilter* filter, net::URLRequestContext* context, | 388 BrowserMessageFilter* filter, net::URLRequestContext* context, |
389 int render_process_id, IPC::Message* reply_msg, const GURL& url) { | 389 int render_process_id, IPC::Message* reply_msg, const GURL& url) { |
390 | 390 |
391 RendererId renderer_key(render_process_id, reply_msg->routing_id()); | 391 RendererId renderer_key(render_process_id, reply_msg->routing_id()); |
392 | 392 |
393 RenderViewMap::iterator automation_details_iter( | 393 RenderViewMap::iterator automation_details_iter( |
394 filtered_render_views_.Get().find(renderer_key)); | 394 filtered_render_views_.Get().find(renderer_key)); |
395 | 395 |
396 DCHECK(automation_details_iter != filtered_render_views_.Get().end()); | 396 DCHECK(automation_details_iter != filtered_render_views_.Get().end()); |
397 DCHECK(automation_details_iter->second.filter != NULL); | 397 DCHECK(automation_details_iter->second.filter.get() != NULL); |
398 | 398 |
399 int completion_callback_id = GetNextCompletionCallbackId(); | 399 int completion_callback_id = GetNextCompletionCallbackId(); |
400 DCHECK(!ContainsKey(completion_callback_map_.Get(), completion_callback_id)); | 400 DCHECK(!ContainsKey(completion_callback_map_.Get(), completion_callback_id)); |
401 | 401 |
402 CookieCompletionInfo cookie_info; | 402 CookieCompletionInfo cookie_info; |
403 cookie_info.filter = filter; | 403 cookie_info.filter = filter; |
404 cookie_info.context = context; | 404 cookie_info.context = context; |
405 cookie_info.render_process_id = render_process_id; | 405 cookie_info.render_process_id = render_process_id; |
406 cookie_info.reply_msg = reply_msg; | 406 cookie_info.reply_msg = reply_msg; |
407 cookie_info.automation_message_filter = | 407 cookie_info.automation_message_filter = |
408 automation_details_iter->second.filter; | 408 automation_details_iter->second.filter; |
409 | 409 |
410 completion_callback_map_.Get()[completion_callback_id] = cookie_info; | 410 completion_callback_map_.Get()[completion_callback_id] = cookie_info; |
411 | 411 |
412 DCHECK(automation_details_iter->second.filter != NULL); | 412 DCHECK(automation_details_iter->second.filter.get() != NULL); |
413 | 413 |
414 if (automation_details_iter->second.filter) { | 414 if (automation_details_iter->second.filter.get()) { |
415 automation_details_iter->second.filter->Send( | 415 automation_details_iter->second.filter |
416 new AutomationMsg_GetCookiesFromHost( | 416 ->Send(new AutomationMsg_GetCookiesFromHost( |
417 automation_details_iter->second.tab_handle, url, | 417 automation_details_iter->second.tab_handle, |
418 completion_callback_id)); | 418 url, |
| 419 completion_callback_id)); |
419 } | 420 } |
420 } | 421 } |
421 | 422 |
422 void AutomationResourceMessageFilter::OnGetCookiesHostResponse( | 423 void AutomationResourceMessageFilter::OnGetCookiesHostResponse( |
423 int tab_handle, bool success, const GURL& url, const std::string& cookies, | 424 int tab_handle, bool success, const GURL& url, const std::string& cookies, |
424 int cookie_id) { | 425 int cookie_id) { |
425 CompletionCallbackMap::iterator index = | 426 CompletionCallbackMap::iterator index = |
426 completion_callback_map_.Get().find(cookie_id); | 427 completion_callback_map_.Get().find(cookie_id); |
427 if (index == completion_callback_map_.Get().end()) { | 428 if (index == completion_callback_map_.Get().end()) { |
428 NOTREACHED() << "Received invalid completion callback id:" | 429 NOTREACHED() << "Received invalid completion callback id:" |
(...skipping 10 matching lines...) Expand all Loading... |
439 | 440 |
440 void AutomationResourceMessageFilter::SetCookiesForUrl( | 441 void AutomationResourceMessageFilter::SetCookiesForUrl( |
441 int render_process_id, | 442 int render_process_id, |
442 int render_view_id, | 443 int render_view_id, |
443 const GURL& url, | 444 const GURL& url, |
444 const std::string& cookie_line) { | 445 const std::string& cookie_line) { |
445 RenderViewMap::iterator automation_details_iter( | 446 RenderViewMap::iterator automation_details_iter( |
446 filtered_render_views_.Get().find(RendererId( | 447 filtered_render_views_.Get().find(RendererId( |
447 render_process_id, render_view_id))); | 448 render_process_id, render_view_id))); |
448 DCHECK(automation_details_iter != filtered_render_views_.Get().end()); | 449 DCHECK(automation_details_iter != filtered_render_views_.Get().end()); |
449 DCHECK(automation_details_iter->second.filter != NULL); | 450 DCHECK(automation_details_iter->second.filter.get() != NULL); |
450 | 451 |
451 if (automation_details_iter->second.filter) { | 452 if (automation_details_iter->second.filter.get()) { |
452 automation_details_iter->second.filter->Send( | 453 automation_details_iter->second.filter |
453 new AutomationMsg_SetCookieAsync( | 454 ->Send(new AutomationMsg_SetCookieAsync( |
454 automation_details_iter->second.tab_handle, url, cookie_line)); | 455 automation_details_iter->second.tab_handle, url, cookie_line)); |
455 } | 456 } |
456 } | 457 } |
457 | 458 |
458 // static | 459 // static |
459 void AutomationResourceMessageFilter::ResumeJobsForPendingView( | 460 void AutomationResourceMessageFilter::ResumeJobsForPendingView( |
460 int tab_handle, | 461 int tab_handle, |
461 AutomationResourceMessageFilter* old_filter, | 462 AutomationResourceMessageFilter* old_filter, |
462 AutomationResourceMessageFilter* new_filter) { | 463 AutomationResourceMessageFilter* new_filter) { |
463 DCHECK(old_filter != NULL); | 464 DCHECK(old_filter != NULL); |
464 DCHECK(new_filter != NULL); | 465 DCHECK(new_filter != NULL); |
465 | 466 |
466 RequestMap pending_requests = old_filter->pending_request_map_; | 467 RequestMap pending_requests = old_filter->pending_request_map_; |
467 old_filter->pending_request_map_.clear(); | 468 old_filter->pending_request_map_.clear(); |
468 | 469 |
469 for (RequestMap::iterator index = pending_requests.begin(); | 470 for (RequestMap::iterator index = pending_requests.begin(); |
470 index != pending_requests.end(); index++) { | 471 index != pending_requests.end(); index++) { |
471 URLRequestAutomationJob* job = (*index).second; | 472 URLRequestAutomationJob* job = (*index).second; |
472 DCHECK_EQ(job->message_filter(), old_filter); | 473 DCHECK_EQ(job->message_filter(), old_filter); |
473 DCHECK(job->is_pending()); | 474 DCHECK(job->is_pending()); |
474 // StartPendingJob will register the job with the new filter. | 475 // StartPendingJob will register the job with the new filter. |
475 job->StartPendingJob(tab_handle, new_filter); | 476 job->StartPendingJob(tab_handle, new_filter); |
476 } | 477 } |
477 } | 478 } |
OLD | NEW |