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

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

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

Powered by Google App Engine
This is Rietveld 408576698