diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-17 19:36:52 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-17 19:36:52 +0000 |
commit | a0729671be0628b5d2c45ef9c19a51c53bfa65b5 (patch) | |
tree | 5e4fadde19f6c5702a799cc3b786fee48fc4c9c0 /chrome/browser/safe_browsing | |
parent | 39ae0a282dc3c1b9e1aea492e11c4d1439ac6921 (diff) | |
download | chromium_src-a0729671be0628b5d2c45ef9c19a51c53bfa65b5.zip chromium_src-a0729671be0628b5d2c45ef9c19a51c53bfa65b5.tar.gz chromium_src-a0729671be0628b5d2c45ef9c19a51c53bfa65b5.tar.bz2 |
Revamp of the interstitial pages.
The interstitial is now a RVH that is displayed on top of the WebContents with no interaction with the WebContents' RenderViewHostManager.
This simplifies the states that the RenderViewHostManager has. The interstitial is responsible for hiding and deleting itself when told to proceed/not proceed or when a navigation occurs or the tab is closed.
The interstitial now uses a data URL (instead of loading some alternate HTML), which allowed me to remove some interstitial flags from NavigationController::LoadCommittedDetails and ProvisionalLoadDetails.
Also changed tab_utils::GetTabContentsByID to return a WebContents since only WebContents have a RVH associated with them.
TEST=Run all ui tests and unit tests.
Review URL: http://codereview.chromium.org/13764
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing')
3 files changed, 42 insertions, 26 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 6c6433a..265e4c7 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -43,7 +43,7 @@ static const wchar_t* const kSbDiagnosticHtml = SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( SafeBrowsingService* sb_service, const SafeBrowsingService::BlockingPageParam& param) - : InterstitialPage(tab_util::GetTabContentsByID( + : InterstitialPage(tab_util::GetWebContentsByID( param.render_process_host_id, param.render_view_id), param.resource_type == ResourceType::MAIN_FRAME, param.url), @@ -55,6 +55,12 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( proceed_(false), did_notify_(false), is_main_frame_(param.resource_type == ResourceType::MAIN_FRAME) { + if (!is_main_frame_) { + navigation_entry_index_to_remove_ = + tab()->controller()->GetLastCommittedEntryIndex(); + } else { + navigation_entry_index_to_remove_ = -1; + } } SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { @@ -138,8 +144,6 @@ std::string SafeBrowsingBlockingPage::GetHTMLContents() { } void SafeBrowsingBlockingPage::CommandReceived(const std::string& command) { - DCHECK(tab()->type() == TAB_CONTENTS_WEB); - WebContents* web = tab()->AsWebContents(); if (command == "2") { // User pressed "Learn more". GURL url; @@ -150,7 +154,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& command) { } else { NOTREACHED(); } - web->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::LINK); + tab()->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::LINK); return; } if (command == "3") { @@ -161,8 +165,8 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& command) { GURL report_url = safe_browsing_util::GeneratePhishingReportUrl(kSbReportPhishingUrl, url().spec()); - web->HideInterstitialPage(false, false); - web->OpenURL(report_url, GURL(), CURRENT_TAB, PageTransition::LINK); + Hide(); + tab()->OpenURL(report_url, GURL(), CURRENT_TAB, PageTransition::LINK); return; } if (command == "4") { @@ -173,33 +177,26 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& command) { GURL diagnostic_url(diagnostic); diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); DCHECK(result_ == SafeBrowsingService::URL_MALWARE); - web->HideInterstitialPage(false, false); - web->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); + tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); return; } proceed_ = command == "1"; - if (proceed_) { - if (is_main_frame_) - web->HideInterstitialPage(true, true); - else - web->HideInterstitialPage(false, false); - } else { - if (is_main_frame_) { - DontProceed(); - } else { - NavigationController* controller = web->controller(); - controller->RemoveEntryAtIndex(controller->GetLastCommittedEntryIndex(), - NewTabUIURL()); - } - } + if (proceed_) + Proceed(); + else + DontProceed(); + NotifyDone(); } -void SafeBrowsingBlockingPage::InterstitialClosed() { - NotifyDone(); - InterstitialPage::InterstitialClosed(); +void SafeBrowsingBlockingPage::DontProceed() { + if (navigation_entry_index_to_remove_ != -1) { + tab()->controller()->RemoveEntryAtIndex(navigation_entry_index_to_remove_, + NewTabUIURL()); + } + InterstitialPage::DontProceed(); // We are now deleted. } diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h index 056d9ae..b0fa2ea 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h @@ -38,7 +38,7 @@ class SafeBrowsingBlockingPage : public InterstitialPage { // InterstitialPage method: virtual std::string GetHTMLContents(); - virtual void InterstitialClosed(); + virtual void DontProceed(); protected: // InterstitialPage method: @@ -77,6 +77,10 @@ class SafeBrowsingBlockingPage : public InterstitialPage { // Whether the flagged resource is the main page (or a sub-resource is false). bool is_main_frame_; + // The index of a navigation entry that should be removed when DontProceed() + // is invoked, -1 if not entry should be removed. + int navigation_entry_index_to_remove_; + DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); }; diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 837c11f..5a7a617 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -17,6 +17,7 @@ #include "chrome/browser/safe_browsing/protocol_manager.h" #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" #include "chrome/browser/safe_browsing/safe_browsing_database.h" +#include "chrome/browser/tab_util.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -281,6 +282,20 @@ void SafeBrowsingService::DisplayBlockingPage(const GURL& url, // Invoked on the UI thread. void SafeBrowsingService::DoDisplayBlockingPage( const BlockingPageParam& param) { + // The tab might have been closed. + if (!tab_util::GetWebContentsByID(param.render_process_host_id, + param.render_view_id)) { + // The tab is gone and we did not have a chance at showing the interstitial. + // Just act as "Don't Proceed" was chosen. + base::Thread* io_thread = g_browser_process->io_thread(); + if (!io_thread) + return; + BlockingPageParam response_param = param; + response_param.proceed = false; + io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( + this, &SafeBrowsingService::OnBlockingPageDone, response_param)); + return; + } SafeBrowsingBlockingPage* blocking_page = new SafeBrowsingBlockingPage(this, param); blocking_page->Show(); |