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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 356 } |
357 | 357 |
358 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame( | 358 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame( |
359 int64 frame_num, | 359 int64 frame_num, |
360 int64 parent_frame_num, | 360 int64 parent_frame_num, |
361 bool is_main_frame, | 361 bool is_main_frame, |
362 const GURL& validated_url, | 362 const GURL& validated_url, |
363 bool is_error_page, | 363 bool is_error_page, |
364 bool is_iframe_srcdoc, | 364 bool is_iframe_srcdoc, |
365 content::RenderViewHost* render_view_host) { | 365 content::RenderViewHost* render_view_host) { |
| 366 DVLOG(2) << "DidStartProvisionalLoad(" |
| 367 << "render_view_host=" << render_view_host |
| 368 << ", frame_num=" << frame_num |
| 369 << ", url=" << validated_url << ")"; |
366 if (!render_view_host_) | 370 if (!render_view_host_) |
367 render_view_host_ = render_view_host; | 371 render_view_host_ = render_view_host; |
368 if (render_view_host != render_view_host_ && | 372 if (render_view_host != render_view_host_ && |
369 render_view_host != pending_render_view_host_) | 373 render_view_host != pending_render_view_host_) |
370 return; | 374 return; |
371 | 375 |
372 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 376 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
373 FrameNavigationState::FrameID parent_frame_id( | 377 FrameNavigationState::FrameID parent_frame_id( |
374 parent_frame_num, render_view_host); | 378 parent_frame_num, render_view_host); |
375 | 379 |
(...skipping 16 matching lines...) Expand all Loading... |
392 navigation_state_.IsMainFrame(parent_frame_id), | 396 navigation_state_.IsMainFrame(parent_frame_id), |
393 navigation_state_.GetUrl(frame_id)); | 397 navigation_state_.GetUrl(frame_id)); |
394 } | 398 } |
395 | 399 |
396 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( | 400 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( |
397 int64 frame_num, | 401 int64 frame_num, |
398 bool is_main_frame, | 402 bool is_main_frame, |
399 const GURL& url, | 403 const GURL& url, |
400 content::PageTransition transition_type, | 404 content::PageTransition transition_type, |
401 content::RenderViewHost* render_view_host) { | 405 content::RenderViewHost* render_view_host) { |
| 406 DVLOG(2) << "DidCommitProvisionalLoad(" |
| 407 << "render_view_host=" << render_view_host |
| 408 << ", frame_num=" << frame_num |
| 409 << ", url=" << url << ")"; |
402 if (render_view_host != render_view_host_ && | 410 if (render_view_host != render_view_host_ && |
403 render_view_host != pending_render_view_host_) | 411 render_view_host != pending_render_view_host_) |
404 return; | 412 return; |
405 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 413 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
406 | 414 |
407 bool is_reference_fragment_navigation = | 415 bool is_reference_fragment_navigation = |
408 IsReferenceFragmentNavigation(frame_id, url); | 416 IsReferenceFragmentNavigation(frame_id, url); |
409 bool is_history_state_modification = | 417 bool is_history_state_modification = |
410 navigation_state_.GetNavigationCommitted(frame_id); | 418 navigation_state_.GetNavigationCommitted(frame_id); |
411 | 419 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } | 477 } |
470 } | 478 } |
471 | 479 |
472 void WebNavigationTabObserver::DidFailProvisionalLoad( | 480 void WebNavigationTabObserver::DidFailProvisionalLoad( |
473 int64 frame_num, | 481 int64 frame_num, |
474 bool is_main_frame, | 482 bool is_main_frame, |
475 const GURL& validated_url, | 483 const GURL& validated_url, |
476 int error_code, | 484 int error_code, |
477 const string16& error_description, | 485 const string16& error_description, |
478 content::RenderViewHost* render_view_host) { | 486 content::RenderViewHost* render_view_host) { |
| 487 DVLOG(2) << "DidFailProvisionalLoad(" |
| 488 << "render_view_host=" << render_view_host |
| 489 << ", frame_num=" << frame_num |
| 490 << ", url=" << validated_url << ")"; |
479 if (render_view_host != render_view_host_ && | 491 if (render_view_host != render_view_host_ && |
480 render_view_host != pending_render_view_host_) | 492 render_view_host != pending_render_view_host_) |
481 return; | 493 return; |
482 bool stop_tracking_frames = false; | 494 bool stop_tracking_frames = false; |
483 if (render_view_host == pending_render_view_host_) { | 495 if (render_view_host == pending_render_view_host_) { |
484 pending_render_view_host_ = NULL; | 496 pending_render_view_host_ = NULL; |
485 stop_tracking_frames = true; | 497 stop_tracking_frames = true; |
486 } | 498 } |
487 | 499 |
488 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 500 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
489 if (navigation_state_.CanSendEvents(frame_id)) { | 501 if (navigation_state_.CanSendEvents(frame_id)) { |
490 helpers::DispatchOnErrorOccurred( | 502 helpers::DispatchOnErrorOccurred( |
491 web_contents(), | 503 web_contents(), |
492 render_view_host->GetProcess()->GetID(), | 504 render_view_host->GetProcess()->GetID(), |
493 navigation_state_.GetUrl(frame_id), | 505 navigation_state_.GetUrl(frame_id), |
494 frame_num, | 506 frame_num, |
495 is_main_frame, | 507 is_main_frame, |
496 error_code); | 508 error_code); |
497 } | 509 } |
498 navigation_state_.SetErrorOccurredInFrame(frame_id); | 510 navigation_state_.SetErrorOccurredInFrame(frame_id); |
499 if (stop_tracking_frames) { | 511 if (stop_tracking_frames) { |
500 navigation_state_.StopTrackingFramesInRVH(render_view_host, | 512 navigation_state_.StopTrackingFramesInRVH(render_view_host, |
501 FrameNavigationState::FrameID()); | 513 FrameNavigationState::FrameID()); |
502 } | 514 } |
503 } | 515 } |
504 | 516 |
505 void WebNavigationTabObserver::DocumentLoadedInFrame( | 517 void WebNavigationTabObserver::DocumentLoadedInFrame( |
506 int64 frame_num, | 518 int64 frame_num, |
507 content::RenderViewHost* render_view_host) { | 519 content::RenderViewHost* render_view_host) { |
| 520 DVLOG(2) << "DocumentLoadedInFrame(" |
| 521 << "render_view_host=" << render_view_host |
| 522 << ", frame_num=" << frame_num << ")"; |
508 if (render_view_host != render_view_host_) | 523 if (render_view_host != render_view_host_) |
509 return; | 524 return; |
510 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 525 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
511 if (!navigation_state_.CanSendEvents(frame_id)) | 526 if (!navigation_state_.CanSendEvents(frame_id)) |
512 return; | 527 return; |
513 helpers::DispatchOnDOMContentLoaded(web_contents(), | 528 helpers::DispatchOnDOMContentLoaded(web_contents(), |
514 navigation_state_.GetUrl(frame_id), | 529 navigation_state_.GetUrl(frame_id), |
515 navigation_state_.IsMainFrame(frame_id), | 530 navigation_state_.IsMainFrame(frame_id), |
516 frame_num); | 531 frame_num); |
517 } | 532 } |
518 | 533 |
519 void WebNavigationTabObserver::DidFinishLoad( | 534 void WebNavigationTabObserver::DidFinishLoad( |
520 int64 frame_num, | 535 int64 frame_num, |
521 const GURL& validated_url, | 536 const GURL& validated_url, |
522 bool is_main_frame, | 537 bool is_main_frame, |
523 content::RenderViewHost* render_view_host) { | 538 content::RenderViewHost* render_view_host) { |
| 539 DVLOG(2) << "DidFinishLoad(" |
| 540 << "render_view_host=" << render_view_host |
| 541 << ", frame_num=" << frame_num |
| 542 << ", url=" << validated_url << ")"; |
524 if (render_view_host != render_view_host_) | 543 if (render_view_host != render_view_host_) |
525 return; | 544 return; |
526 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 545 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
527 // When showing replacement content, we might get load signals for frames | 546 // When showing replacement content, we might get load signals for frames |
528 // that weren't reguarly loaded. | 547 // that weren't reguarly loaded. |
529 if (!navigation_state_.IsValidFrame(frame_id)) | 548 if (!navigation_state_.IsValidFrame(frame_id)) |
530 return; | 549 return; |
531 navigation_state_.SetNavigationCompleted(frame_id); | 550 navigation_state_.SetNavigationCompleted(frame_id); |
532 if (!navigation_state_.CanSendEvents(frame_id)) | 551 if (!navigation_state_.CanSendEvents(frame_id)) |
533 return; | 552 return; |
534 DCHECK(navigation_state_.GetUrl(frame_id) == validated_url || | 553 DCHECK(navigation_state_.GetUrl(frame_id) == validated_url || |
535 (navigation_state_.GetUrl(frame_id) == GURL(chrome::kAboutSrcDocURL) && | 554 (navigation_state_.GetUrl(frame_id) == GURL(chrome::kAboutSrcDocURL) && |
536 validated_url == GURL(chrome::kAboutBlankURL))); | 555 validated_url == GURL(chrome::kAboutBlankURL))); |
537 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame); | 556 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame); |
538 helpers::DispatchOnCompleted(web_contents(), | 557 helpers::DispatchOnCompleted(web_contents(), |
539 navigation_state_.GetUrl(frame_id), | 558 navigation_state_.GetUrl(frame_id), |
540 is_main_frame, | 559 is_main_frame, |
541 frame_num); | 560 frame_num); |
542 } | 561 } |
543 | 562 |
544 void WebNavigationTabObserver::DidFailLoad( | 563 void WebNavigationTabObserver::DidFailLoad( |
545 int64 frame_num, | 564 int64 frame_num, |
546 const GURL& validated_url, | 565 const GURL& validated_url, |
547 bool is_main_frame, | 566 bool is_main_frame, |
548 int error_code, | 567 int error_code, |
549 const string16& error_description, | 568 const string16& error_description, |
550 content::RenderViewHost* render_view_host) { | 569 content::RenderViewHost* render_view_host) { |
| 570 DVLOG(2) << "DidFailLoad(" |
| 571 << "render_view_host=" << render_view_host |
| 572 << ", frame_num=" << frame_num |
| 573 << ", url=" << validated_url << ")"; |
551 if (render_view_host != render_view_host_) | 574 if (render_view_host != render_view_host_) |
552 return; | 575 return; |
553 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 576 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
554 // When showing replacement content, we might get load signals for frames | 577 // When showing replacement content, we might get load signals for frames |
555 // that weren't reguarly loaded. | 578 // that weren't reguarly loaded. |
556 if (!navigation_state_.IsValidFrame(frame_id)) | 579 if (!navigation_state_.IsValidFrame(frame_id)) |
557 return; | 580 return; |
558 if (navigation_state_.CanSendEvents(frame_id)) { | 581 if (navigation_state_.CanSendEvents(frame_id)) { |
559 helpers::DispatchOnErrorOccurred( | 582 helpers::DispatchOnErrorOccurred( |
560 web_contents(), | 583 web_contents(), |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 return &g_factory.Get(); | 808 return &g_factory.Get(); |
786 } | 809 } |
787 | 810 |
788 void WebNavigationAPI::OnListenerAdded( | 811 void WebNavigationAPI::OnListenerAdded( |
789 const extensions::EventListenerInfo& details) { | 812 const extensions::EventListenerInfo& details) { |
790 web_navigation_event_router_.reset(new WebNavigationEventRouter(profile_)); | 813 web_navigation_event_router_.reset(new WebNavigationEventRouter(profile_)); |
791 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 814 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
792 } | 815 } |
793 | 816 |
794 } // namespace extensions | 817 } // namespace extensions |
OLD | NEW |