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 // Implements the Chrome Extensions WebNavigation API. | 5 // Implements the Chrome Extensions WebNavigation API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" | 10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 310 |
311 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { | 311 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { |
312 content::RenderViewHost* render_view_host = | 312 content::RenderViewHost* render_view_host = |
313 content::Source<content::RenderViewHost>(source).ptr(); | 313 content::Source<content::RenderViewHost>(source).ptr(); |
314 if (render_view_host == render_view_host_) | 314 if (render_view_host == render_view_host_) |
315 render_view_host_ = NULL; | 315 render_view_host_ = NULL; |
316 else if (render_view_host == pending_render_view_host_) | 316 else if (render_view_host == pending_render_view_host_) |
317 pending_render_view_host_ = NULL; | 317 pending_render_view_host_ = NULL; |
318 else | 318 else |
319 return; | 319 return; |
320 SendErrorEvents(web_contents(), render_view_host); | 320 SendErrorEvents( |
321 web_contents(), render_view_host, FrameNavigationState::FrameID()); | |
321 break; | 322 break; |
322 } | 323 } |
323 | 324 |
324 default: | 325 default: |
325 NOTREACHED(); | 326 NOTREACHED(); |
326 } | 327 } |
327 } | 328 } |
328 | 329 |
329 void WebNavigationTabObserver::AboutToNavigateRenderView( | 330 void WebNavigationTabObserver::AboutToNavigateRenderView( |
330 content::RenderViewHost* render_view_host) { | 331 content::RenderViewHost* render_view_host) { |
331 if (!render_view_host_) { | 332 if (!render_view_host_) { |
332 render_view_host_ = render_view_host; | 333 render_view_host_ = render_view_host; |
333 } else if (render_view_host != render_view_host_) { | 334 } else if (render_view_host != render_view_host_) { |
334 if (pending_render_view_host_) | 335 if (pending_render_view_host_) { |
335 SendErrorEvents(web_contents(), pending_render_view_host_); | 336 SendErrorEvents(web_contents(), |
337 pending_render_view_host_, | |
338 FrameNavigationState::FrameID()); | |
339 } | |
336 pending_render_view_host_ = render_view_host; | 340 pending_render_view_host_ = render_view_host; |
337 } | 341 } |
338 } | 342 } |
339 | 343 |
340 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame( | 344 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame( |
341 int64 frame_num, | 345 int64 frame_num, |
342 bool is_main_frame, | 346 bool is_main_frame, |
343 const GURL& validated_url, | 347 const GURL& validated_url, |
344 bool is_error_page, | 348 bool is_error_page, |
345 content::RenderViewHost* render_view_host) { | 349 content::RenderViewHost* render_view_host) { |
(...skipping 19 matching lines...) Expand all Loading... | |
365 | 369 |
366 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( | 370 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( |
367 int64 frame_num, | 371 int64 frame_num, |
368 bool is_main_frame, | 372 bool is_main_frame, |
369 const GURL& url, | 373 const GURL& url, |
370 content::PageTransition transition_type, | 374 content::PageTransition transition_type, |
371 content::RenderViewHost* render_view_host) { | 375 content::RenderViewHost* render_view_host) { |
372 if (render_view_host != render_view_host_ && | 376 if (render_view_host != render_view_host_ && |
373 render_view_host != pending_render_view_host_) | 377 render_view_host != pending_render_view_host_) |
374 return; | 378 return; |
375 if (render_view_host != render_view_host_) | 379 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
376 SendErrorEvents(web_contents(), render_view_host_); | 380 FrameNavigationState::FrameID id_to_skip; |
381 if (render_view_host == render_view_host_) | |
382 id_to_skip = frame_id; | |
383 if (is_main_frame) | |
Matt Perry
2012/08/02 12:59:31
Did you mean to add this check for is_main_frame?
jochen (gone - plz use gerrit)
2012/08/02 14:09:49
The old check said "the pending RVH' commits, and
| |
384 SendErrorEvents(web_contents(), render_view_host_, id_to_skip); | |
377 render_view_host_ = render_view_host; | 385 render_view_host_ = render_view_host; |
378 pending_render_view_host_ = NULL; | 386 pending_render_view_host_ = NULL; |
379 | 387 |
380 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | |
381 if (!navigation_state_.CanSendEvents(frame_id)) | 388 if (!navigation_state_.CanSendEvents(frame_id)) |
382 return; | 389 return; |
383 | 390 |
384 bool is_reference_fragment_navigation = | 391 bool is_reference_fragment_navigation = |
385 IsReferenceFragmentNavigation(frame_id, url); | 392 IsReferenceFragmentNavigation(frame_id, url); |
386 bool is_history_navigation = | 393 bool is_history_navigation = |
387 navigation_state_.GetNavigationCommitted(frame_id); | 394 navigation_state_.GetNavigationCommitted(frame_id); |
388 | 395 |
389 // Update the URL as it might have changed. | 396 // Update the URL as it might have changed. |
390 navigation_state_.UpdateFrame(frame_id, url); | 397 navigation_state_.UpdateFrame(frame_id, url); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 stop_tracking_frames = true; | 449 stop_tracking_frames = true; |
443 } | 450 } |
444 | 451 |
445 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 452 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
446 if (navigation_state_.CanSendEvents(frame_id)) { | 453 if (navigation_state_.CanSendEvents(frame_id)) { |
447 navigation_state_.SetErrorOccurredInFrame(frame_id); | 454 navigation_state_.SetErrorOccurredInFrame(frame_id); |
448 helpers::DispatchOnErrorOccurred( | 455 helpers::DispatchOnErrorOccurred( |
449 web_contents(), render_view_host->GetProcess()->GetID(), validated_url, | 456 web_contents(), render_view_host->GetProcess()->GetID(), validated_url, |
450 frame_num, is_main_frame, error_code); | 457 frame_num, is_main_frame, error_code); |
451 } | 458 } |
452 if (stop_tracking_frames) | 459 if (stop_tracking_frames) { |
453 navigation_state_.StopTrackingFramesInRVH(render_view_host); | 460 navigation_state_.StopTrackingFramesInRVH(render_view_host, |
461 FrameNavigationState::FrameID()); | |
462 } | |
454 } | 463 } |
455 | 464 |
456 void WebNavigationTabObserver::DocumentLoadedInFrame( | 465 void WebNavigationTabObserver::DocumentLoadedInFrame( |
457 int64 frame_num, | 466 int64 frame_num, |
458 content::RenderViewHost* render_view_host) { | 467 content::RenderViewHost* render_view_host) { |
459 if (render_view_host != render_view_host_) | 468 if (render_view_host != render_view_host_) |
460 return; | 469 return; |
461 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 470 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
462 if (!navigation_state_.CanSendEvents(frame_id)) | 471 if (!navigation_state_.CanSendEvents(frame_id)) |
463 return; | 472 return; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 new_contents->GetBrowserContext(), | 539 new_contents->GetBrowserContext(), |
531 source_frame_num, | 540 source_frame_num, |
532 navigation_state_.IsMainFrame(frame_id), | 541 navigation_state_.IsMainFrame(frame_id), |
533 new_contents, | 542 new_contents, |
534 url); | 543 url); |
535 } | 544 } |
536 | 545 |
537 void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) { | 546 void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) { |
538 g_tab_observer.Get().erase(tab); | 547 g_tab_observer.Get().erase(tab); |
539 registrar_.RemoveAll(); | 548 registrar_.RemoveAll(); |
540 SendErrorEvents(tab, NULL); | 549 SendErrorEvents(tab, NULL, FrameNavigationState::FrameID()); |
541 } | 550 } |
542 | 551 |
543 void WebNavigationTabObserver::SendErrorEvents( | 552 void WebNavigationTabObserver::SendErrorEvents( |
544 content::WebContents* web_contents, | 553 content::WebContents* web_contents, |
545 content::RenderViewHost* render_view_host) { | 554 content::RenderViewHost* render_view_host, |
555 FrameNavigationState::FrameID id_to_skip) { | |
546 for (FrameNavigationState::const_iterator frame = navigation_state_.begin(); | 556 for (FrameNavigationState::const_iterator frame = navigation_state_.begin(); |
547 frame != navigation_state_.end(); ++frame) { | 557 frame != navigation_state_.end(); ++frame) { |
548 if (!navigation_state_.GetNavigationCompleted(*frame) && | 558 if (!navigation_state_.GetNavigationCompleted(*frame) && |
549 navigation_state_.CanSendEvents(*frame) && | 559 navigation_state_.CanSendEvents(*frame) && |
560 *frame != id_to_skip && | |
550 (!render_view_host || frame->render_view_host == render_view_host)) { | 561 (!render_view_host || frame->render_view_host == render_view_host)) { |
562 navigation_state_.SetErrorOccurredInFrame(*frame); | |
551 helpers::DispatchOnErrorOccurred( | 563 helpers::DispatchOnErrorOccurred( |
552 web_contents, | 564 web_contents, |
Matt Perry
2012/08/02 12:59:31
nit: indent + 2
jochen (gone - plz use gerrit)
2012/08/02 14:09:49
Done.
| |
553 frame->render_view_host->GetProcess()->GetID(), | 565 frame->render_view_host->GetProcess()->GetID(), |
554 navigation_state_.GetUrl(*frame), | 566 navigation_state_.GetUrl(*frame), |
555 frame->frame_num, | 567 frame->frame_num, |
556 navigation_state_.IsMainFrame(*frame), | 568 navigation_state_.IsMainFrame(*frame), |
557 net::ERR_ABORTED); | 569 net::ERR_ABORTED); |
558 } | 570 } |
559 } | 571 } |
560 if (render_view_host) | 572 if (render_view_host) |
561 navigation_state_.StopTrackingFramesInRVH(render_view_host); | 573 navigation_state_.StopTrackingFramesInRVH(render_view_host, id_to_skip); |
562 } | 574 } |
563 | 575 |
564 // See also NavigationController::IsURLInPageNavigation. | 576 // See also NavigationController::IsURLInPageNavigation. |
565 bool WebNavigationTabObserver::IsReferenceFragmentNavigation( | 577 bool WebNavigationTabObserver::IsReferenceFragmentNavigation( |
566 FrameNavigationState::FrameID frame_id, | 578 FrameNavigationState::FrameID frame_id, |
567 const GURL& url) { | 579 const GURL& url) { |
568 GURL existing_url = navigation_state_.GetUrl(frame_id); | 580 GURL existing_url = navigation_state_.GetUrl(frame_id); |
569 if (existing_url == url) | 581 if (existing_url == url) |
570 return false; | 582 return false; |
571 | 583 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 navigation_state.IsMainFrame(frame_id), frame_id.frame_num); | 679 navigation_state.IsMainFrame(frame_id), frame_id.frame_num); |
668 frame->process_id = frame_id.render_view_host->GetProcess()->GetID(); | 680 frame->process_id = frame_id.render_view_host->GetProcess()->GetID(); |
669 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); | 681 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); |
670 result_list.push_back(frame); | 682 result_list.push_back(frame); |
671 } | 683 } |
672 results_ = GetAllFrames::Results::Create(result_list); | 684 results_ = GetAllFrames::Results::Create(result_list); |
673 return true; | 685 return true; |
674 } | 686 } |
675 | 687 |
676 } // namespace extensions | 688 } // namespace extensions |
OLD | NEW |