| 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/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 error_code); | 488 error_code); |
| 489 } | 489 } |
| 490 navigation_state_.SetErrorOccurredInFrame(frame_id); | 490 navigation_state_.SetErrorOccurredInFrame(frame_id); |
| 491 if (stop_tracking_frames) { | 491 if (stop_tracking_frames) { |
| 492 navigation_state_.StopTrackingFramesInRVH(render_view_host, | 492 navigation_state_.StopTrackingFramesInRVH(render_view_host, |
| 493 FrameNavigationState::FrameID()); | 493 FrameNavigationState::FrameID()); |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 void WebNavigationTabObserver::DocumentLoadedInFrame( | 497 void WebNavigationTabObserver::DocumentLoadedInFrame( |
| 498 int64 frame_num, | 498 content::RenderFrameHost* render_frame_host) { |
| 499 content::RenderViewHost* render_view_host) { | 499 content::RenderViewHost* render_view_host = |
| 500 render_frame_host->GetRenderViewHost(); |
| 500 DVLOG(2) << "DocumentLoadedInFrame(" | 501 DVLOG(2) << "DocumentLoadedInFrame(" |
| 501 << "render_view_host=" << render_view_host | 502 << "render_view_host=" << render_view_host |
| 502 << ", frame_num=" << frame_num << ")"; | 503 << ", frame_num=" << render_frame_host->GetRoutingID() << ")"; |
| 503 if (render_view_host != render_view_host_) | 504 if (render_view_host != render_view_host_) |
| 504 return; | 505 return; |
| 505 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 506 FrameNavigationState::FrameID frame_id(render_frame_host->GetRoutingID(), |
| 507 render_view_host); |
| 506 if (!navigation_state_.CanSendEvents(frame_id)) | 508 if (!navigation_state_.CanSendEvents(frame_id)) |
| 507 return; | 509 return; |
| 508 navigation_state_.SetParsingFinished(frame_id); | 510 navigation_state_.SetParsingFinished(frame_id); |
| 509 helpers::DispatchOnDOMContentLoaded(web_contents(), | 511 helpers::DispatchOnDOMContentLoaded(web_contents(), |
| 510 navigation_state_.GetUrl(frame_id), | 512 navigation_state_.GetUrl(frame_id), |
| 511 navigation_state_.IsMainFrame(frame_id), | 513 navigation_state_.IsMainFrame(frame_id), |
| 512 frame_num); | 514 frame_id.frame_num); |
| 513 | 515 |
| 514 if (!navigation_state_.GetNavigationCompleted(frame_id)) | 516 if (!navigation_state_.GetNavigationCompleted(frame_id)) |
| 515 return; | 517 return; |
| 516 | 518 |
| 517 // The load might already have finished by the time we finished parsing. For | 519 // The load might already have finished by the time we finished parsing. For |
| 518 // compatibility reasons, we artifically delay the load completed signal until | 520 // compatibility reasons, we artifically delay the load completed signal until |
| 519 // after parsing was completed. | 521 // after parsing was completed. |
| 520 helpers::DispatchOnCompleted(web_contents(), | 522 helpers::DispatchOnCompleted(web_contents(), |
| 521 navigation_state_.GetUrl(frame_id), | 523 navigation_state_.GetUrl(frame_id), |
| 522 navigation_state_.IsMainFrame(frame_id), | 524 navigation_state_.IsMainFrame(frame_id), |
| 523 frame_num); | 525 frame_id.frame_num); |
| 524 } | 526 } |
| 525 | 527 |
| 526 void WebNavigationTabObserver::DidFinishLoad( | 528 void WebNavigationTabObserver::DidFinishLoad( |
| 527 int64 frame_num, | 529 content::RenderFrameHost* render_frame_host, |
| 528 const GURL& validated_url, | 530 const GURL& validated_url) { |
| 529 bool is_main_frame, | 531 content::RenderViewHost* render_view_host = |
| 530 content::RenderViewHost* render_view_host) { | 532 render_frame_host->GetRenderViewHost(); |
| 531 DVLOG(2) << "DidFinishLoad(" | 533 DVLOG(2) << "DidFinishLoad(" |
| 532 << "render_view_host=" << render_view_host | 534 << "render_view_host=" << render_view_host |
| 533 << ", frame_num=" << frame_num | 535 << ", frame_num=" << render_frame_host->GetRoutingID() |
| 534 << ", url=" << validated_url << ")"; | 536 << ", url=" << validated_url << ")"; |
| 535 if (render_view_host != render_view_host_) | 537 if (render_view_host != render_view_host_) |
| 536 return; | 538 return; |
| 537 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 539 FrameNavigationState::FrameID frame_id(render_frame_host->GetRoutingID(), |
| 540 render_view_host); |
| 538 // When showing replacement content, we might get load signals for frames | 541 // When showing replacement content, we might get load signals for frames |
| 539 // that weren't reguarly loaded. | 542 // that weren't reguarly loaded. |
| 540 if (!navigation_state_.IsValidFrame(frame_id)) | 543 if (!navigation_state_.IsValidFrame(frame_id)) |
| 541 return; | 544 return; |
| 542 navigation_state_.SetNavigationCompleted(frame_id); | 545 navigation_state_.SetNavigationCompleted(frame_id); |
| 543 if (!navigation_state_.CanSendEvents(frame_id)) | 546 if (!navigation_state_.CanSendEvents(frame_id)) |
| 544 return; | 547 return; |
| 545 DCHECK( | 548 DCHECK( |
| 546 navigation_state_.GetUrl(frame_id) == validated_url || | 549 navigation_state_.GetUrl(frame_id) == validated_url || |
| 547 (navigation_state_.GetUrl(frame_id) == GURL(content::kAboutSrcDocURL) && | 550 (navigation_state_.GetUrl(frame_id) == GURL(content::kAboutSrcDocURL) && |
| 548 validated_url == GURL(url::kAboutBlankURL))) | 551 validated_url == GURL(url::kAboutBlankURL))) |
| 549 << "validated URL is " << validated_url << " but we expected " | 552 << "validated URL is " << validated_url << " but we expected " |
| 550 << navigation_state_.GetUrl(frame_id); | 553 << navigation_state_.GetUrl(frame_id); |
| 551 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame); | 554 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), |
| 555 !render_frame_host->GetParent()); |
| 552 | 556 |
| 553 // The load might already have finished by the time we finished parsing. For | 557 // The load might already have finished by the time we finished parsing. For |
| 554 // compatibility reasons, we artifically delay the load completed signal until | 558 // compatibility reasons, we artifically delay the load completed signal until |
| 555 // after parsing was completed. | 559 // after parsing was completed. |
| 556 if (!navigation_state_.GetParsingFinished(frame_id)) | 560 if (!navigation_state_.GetParsingFinished(frame_id)) |
| 557 return; | 561 return; |
| 558 helpers::DispatchOnCompleted(web_contents(), | 562 helpers::DispatchOnCompleted(web_contents(), |
| 559 navigation_state_.GetUrl(frame_id), | 563 navigation_state_.GetUrl(frame_id), |
| 560 is_main_frame, | 564 !render_frame_host->GetParent(), |
| 561 frame_num); | 565 frame_id.frame_num); |
| 562 } | 566 } |
| 563 | 567 |
| 564 void WebNavigationTabObserver::DidFailLoad( | 568 void WebNavigationTabObserver::DidFailLoad( |
| 565 int64 frame_num, | 569 content::RenderFrameHost* render_frame_host, |
| 566 const GURL& validated_url, | 570 const GURL& validated_url, |
| 567 bool is_main_frame, | |
| 568 int error_code, | 571 int error_code, |
| 569 const base::string16& error_description, | 572 const base::string16& error_description) { |
| 570 content::RenderViewHost* render_view_host) { | 573 content::RenderViewHost* render_view_host = |
| 574 render_frame_host->GetRenderViewHost(); |
| 571 DVLOG(2) << "DidFailLoad(" | 575 DVLOG(2) << "DidFailLoad(" |
| 572 << "render_view_host=" << render_view_host | 576 << "render_view_host=" << render_view_host |
| 573 << ", frame_num=" << frame_num | 577 << ", frame_num=" << render_frame_host->GetRoutingID() |
| 574 << ", url=" << validated_url << ")"; | 578 << ", url=" << validated_url << ")"; |
| 575 if (render_view_host != render_view_host_) | 579 if (render_view_host != render_view_host_) |
| 576 return; | 580 return; |
| 577 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 581 FrameNavigationState::FrameID frame_id(render_frame_host->GetRoutingID(), |
| 582 render_view_host); |
| 578 // When showing replacement content, we might get load signals for frames | 583 // When showing replacement content, we might get load signals for frames |
| 579 // that weren't reguarly loaded. | 584 // that weren't reguarly loaded. |
| 580 if (!navigation_state_.IsValidFrame(frame_id)) | 585 if (!navigation_state_.IsValidFrame(frame_id)) |
| 581 return; | 586 return; |
| 582 if (navigation_state_.CanSendEvents(frame_id)) { | 587 if (navigation_state_.CanSendEvents(frame_id)) { |
| 583 helpers::DispatchOnErrorOccurred( | 588 helpers::DispatchOnErrorOccurred(web_contents(), |
| 584 web_contents(), | 589 render_view_host->GetProcess()->GetID(), |
| 585 render_view_host->GetProcess()->GetID(), | 590 navigation_state_.GetUrl(frame_id), |
| 586 navigation_state_.GetUrl(frame_id), | 591 frame_id.frame_num, |
| 587 frame_num, | 592 !render_frame_host->GetParent(), |
| 588 is_main_frame, | 593 error_code); |
| 589 error_code); | |
| 590 } | 594 } |
| 591 navigation_state_.SetErrorOccurredInFrame(frame_id); | 595 navigation_state_.SetErrorOccurredInFrame(frame_id); |
| 592 } | 596 } |
| 593 | 597 |
| 594 void WebNavigationTabObserver::DidGetRedirectForResourceRequest( | 598 void WebNavigationTabObserver::DidGetRedirectForResourceRequest( |
| 595 content::RenderViewHost* render_view_host, | 599 content::RenderViewHost* render_view_host, |
| 596 const content::ResourceRedirectDetails& details) { | 600 const content::ResourceRedirectDetails& details) { |
| 597 if (details.resource_type != ResourceType::MAIN_FRAME && | 601 if (details.resource_type != ResourceType::MAIN_FRAME && |
| 598 details.resource_type != ResourceType::SUB_FRAME) { | 602 details.resource_type != ResourceType::SUB_FRAME) { |
| 599 return; | 603 return; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 return g_factory.Pointer(); | 848 return g_factory.Pointer(); |
| 845 } | 849 } |
| 846 | 850 |
| 847 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { | 851 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 848 web_navigation_event_router_.reset(new WebNavigationEventRouter( | 852 web_navigation_event_router_.reset(new WebNavigationEventRouter( |
| 849 Profile::FromBrowserContext(browser_context_))); | 853 Profile::FromBrowserContext(browser_context_))); |
| 850 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 854 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 851 } | 855 } |
| 852 | 856 |
| 853 } // namespace extensions | 857 } // namespace extensions |
| OLD | NEW |