diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-07 22:20:13 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-07 22:20:13 +0000 |
commit | 85f0a572e9b004dff92572be073ea3d85d957b8a (patch) | |
tree | 9f66089703dda8acc33feb35cbf2b5187c4a2392 | |
parent | 05a980d7adcbde16a13f196ef7a9653bee4696f5 (diff) | |
download | chromium_src-85f0a572e9b004dff92572be073ea3d85d957b8a.zip chromium_src-85f0a572e9b004dff92572be073ea3d85d957b8a.tar.gz chromium_src-85f0a572e9b004dff92572be073ea3d85d957b8a.tar.bz2 |
Use InterstitialPage through a delegate interface instead of deriving from it.
In a followup change I'll create an API around InterstitialPage.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9323071
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120840 0039d316-1c4b-4281-b951-d872f2087c98
27 files changed, 422 insertions, 312 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 1dd73e5..e2ec753 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -125,6 +125,7 @@ #include "content/public/browser/browser_child_process_host_iterator.h" #include "content/public/browser/child_process_data.h" #include "content/public/browser/favicon_status.h" +#include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/plugin_service.h" @@ -195,19 +196,21 @@ void SendMouseClick(int flags) { ui_controls::SendMouseClick(button); } -class AutomationInterstitialPage : public InterstitialPage { +class AutomationInterstitialPage : public content::InterstitialPageDelegate { public: AutomationInterstitialPage(WebContents* tab, const GURL& url, const std::string& contents) - : InterstitialPage(tab, true, url), - contents_(contents) { + : contents_(contents) { + interstitial_page_ = InterstitialPage::Create(tab, true, url, this); + interstitial_page_->Show(); } - virtual std::string GetHTMLContents() { return contents_; } + virtual std::string GetHTMLContents() OVERRIDE { return contents_; } private: const std::string contents_; + InterstitialPage* interstitial_page_; // Owns us. DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); }; @@ -1586,11 +1589,8 @@ void TestingAutomationProvider::ShowInterstitialPage( new NavigationNotificationObserver(controller, this, reply_message, 1, false, false); - AutomationInterstitialPage* interstitial = - new AutomationInterstitialPage(web_contents, - GURL("about:interstitial"), - html_text); - interstitial->Show(); + new AutomationInterstitialPage( + web_contents, GURL("about:interstitial"), html_text); return; } diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index f6c30ab..ff2c489 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -25,6 +25,7 @@ #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_widget_host_view.h" #include "content/browser/tab_contents/interstitial_page.h" +#include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" @@ -182,10 +183,9 @@ class BrowserFocusTest : public InProcessBrowserTest { ViewID location_bar_focus_view_id_; }; -class TestInterstitialPage : public InterstitialPage { +class TestInterstitialPage : public content::InterstitialPageDelegate { public: - TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) - : InterstitialPage(tab, new_navigation, url) { + TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { FilePath file_path; bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path); EXPECT_TRUE(r); @@ -193,20 +193,21 @@ class TestInterstitialPage : public InterstitialPage { file_path = file_path.AppendASCII(kTypicalPageName); r = file_util::ReadFileToString(file_path, &html_contents_); EXPECT_TRUE(r); + interstitial_page_ = InterstitialPage::Create( + tab, new_navigation, url , this); + interstitial_page_->Show(); } virtual std::string GetHTMLContents() { return html_contents_; } - // Exposing render_view_host() and tab() to be public; they are declared as - // protected in the superclass. - virtual RenderViewHost* render_view_host() { - return InterstitialPage::render_view_host(); + RenderViewHost* render_view_host() { + return interstitial_page_->render_view_host(); } - virtual WebContents* tab() { - return InterstitialPage::tab(); + void DontProceed() { + interstitial_page_->DontProceed(); } bool HasFocus() { @@ -215,6 +216,7 @@ class TestInterstitialPage : public InterstitialPage { private: std::string html_contents_; + InterstitialPage* interstitial_page_; // Owns us. }; IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { @@ -621,7 +623,6 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { TestInterstitialPage* interstitial_page = new TestInterstitialPage(browser()->GetSelectedWebContents(), true, GURL("http://interstitial.com")); - interstitial_page->Show(); // Give some time for the interstitial to show. MessageLoop::current()->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), @@ -747,7 +748,6 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { TestInterstitialPage* interstitial_page = new TestInterstitialPage(browser()->GetSelectedWebContents(), true, GURL("http://interstitial.com")); - interstitial_page->Show(); // Give some time for the interstitial to show. MessageLoop::current()->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 2bcfe8e..4eb533d 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -329,6 +329,12 @@ void ChromeContentBrowserClient::RenderViewHostCreated( new ChromeRenderViewHostObserver(render_view_host, profile->GetNetworkPredictor()); new ExtensionMessageHandler(render_view_host); + + if (render_view_host->delegate()->GetRenderViewType() == + content::VIEW_TYPE_INTERSTITIAL_PAGE) { + render_view_host->Send(new ChromeViewMsg_SetAsInterstitial( + render_view_host->routing_id())); + } } void ChromeContentBrowserClient::RenderProcessHostCreated( @@ -878,9 +884,7 @@ void ChromeContentBrowserClient::AllowCertificateError( } // Otherwise, display an SSL blocking page. - SSLBlockingPage* blocking_page = new SSLBlockingPage( - handler, overridable, callback); - blocking_page->Show(); + new SSLBlockingPage(handler, overridable, callback); } void ChromeContentBrowserClient::SelectClientCertificate( diff --git a/chrome/browser/chromeos/offline/offline_load_page.cc b/chrome/browser/chromeos/offline/offline_load_page.cc index 61dce60..6476666 100644 --- a/chrome/browser/chromeos/offline/offline_load_page.cc +++ b/chrome/browser/chromeos/offline/offline_load_page.cc @@ -14,6 +14,7 @@ #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" @@ -21,6 +22,7 @@ #include "chrome/common/extensions/extension.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/url_constants.h" +#include "content/browser/tab_contents/interstitial_page.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/web_contents.h" @@ -49,10 +51,13 @@ namespace chromeos { OfflineLoadPage::OfflineLoadPage(WebContents* web_contents, const GURL& url, const CompletionCallback& callback) - : ChromeInterstitialPage(web_contents, true, url), - callback_(callback), - proceeded_(false) { + : callback_(callback), + proceeded_(false), + web_contents_(web_contents), + url_(url) { net::NetworkChangeNotifier::AddOnlineStateObserver(this); + interstitial_page_ = InterstitialPage::Create(web_contents, true, url, this); + interstitial_page_->Show(); } OfflineLoadPage::~OfflineLoadPage() { @@ -76,20 +81,21 @@ std::string OfflineLoadPage::GetHTMLContents() { bool rtl = base::i18n::IsRTL(); strings.SetString("textdirection", rtl ? "rtl" : "ltr"); - string16 failed_url(ASCIIToUTF16(url().spec())); + string16 failed_url(ASCIIToUTF16(url_.spec())); if (rtl) base::i18n::WrapStringWithLTRFormatting(&failed_url); strings.SetString("url", failed_url); // The offline page for app has icons and slightly different message. - Profile* profile = Profile::FromBrowserContext(tab()->GetBrowserContext()); + Profile* profile = Profile::FromBrowserContext( + web_contents_->GetBrowserContext()); DCHECK(profile); const Extension* extension = NULL; ExtensionService* extensions_service = profile->GetExtensionService(); // Extension service does not exist in test. if (extensions_service) extension = extensions_service->extensions()->GetHostedAppByURL( - ExtensionURLInfo(url())); + ExtensionURLInfo(url_)); if (extension) GetAppOfflineStrings(extension, failed_url, &strings); @@ -102,6 +108,27 @@ std::string OfflineLoadPage::GetHTMLContents() { return jstemplate_builder::GetI18nTemplateHtml(html, &strings); } + void OfflineLoadPage::OverrideRendererPrefs( + content::RendererPreferences* prefs) { + Profile* profile = Profile::FromBrowserContext( + web_contents_->GetBrowserContext()); + renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); + } + +void OfflineLoadPage::OnProceed() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + proceeded_ = true; + NotifyBlockingPageComplete(true); +} + +void OfflineLoadPage::OnDontProceed() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + // Ignore if it's already proceeded. + if (proceeded_) + return; + NotifyBlockingPageComplete(false); +} + void OfflineLoadPage::GetAppOfflineStrings( const Extension* app, const string16& failed_url, @@ -128,7 +155,7 @@ void OfflineLoadPage::GetAppOfflineStrings( void OfflineLoadPage::GetNormalOfflineStrings( const string16& failed_url, DictionaryValue* strings) const { - strings->SetString("title", tab()->GetTitle()); + strings->SetString("title", web_contents_->GetTitle()); // No icon for normal web site. strings->SetString("display_icon", "none"); @@ -148,9 +175,9 @@ void OfflineLoadPage::CommandReceived(const std::string& cmd) { } // TODO(oshima): record action for metrics. if (command == "proceed") { - Proceed(); + interstitial_page_->Proceed(); } else if (command == "dontproceed") { - DontProceed(); + interstitial_page_->DontProceed(); } else if (command == "open_network_settings") { Browser* browser = BrowserList::GetLastActive(); DCHECK(browser); @@ -169,29 +196,13 @@ void OfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { BrowserThread::IO, FROM_HERE, base::Bind(callback_, proceed)); } -void OfflineLoadPage::Proceed() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - proceeded_ = true; - NotifyBlockingPageComplete(true); - InterstitialPage::Proceed(); -} - -void OfflineLoadPage::DontProceed() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - // Ignore if it's already proceeded. - if (proceeded_) - return; - NotifyBlockingPageComplete(false); - InterstitialPage::DontProceed(); -} - void OfflineLoadPage::OnOnlineStateChanged(bool online) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DVLOG(1) << "OnlineStateObserver notification received: state=" << (online ? "online" : "offline"); if (online) { net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); - Proceed(); + interstitial_page_->Proceed(); } } diff --git a/chrome/browser/chromeos/offline/offline_load_page.h b/chrome/browser/chromeos/offline/offline_load_page.h index 75bf367..5b45a2c 100644 --- a/chrome/browser/chromeos/offline/offline_load_page.h +++ b/chrome/browser/chromeos/offline/offline_load_page.h @@ -10,22 +10,28 @@ #include "base/callback.h" #include "base/compiler_specific.h" -#include "chrome/browser/tab_contents/chrome_interstitial_page.h" +#include "content/public/browser/interstitial_page_delegate.h" +#include "googleurl/src/gurl.h" #include "net/base/network_change_notifier.h" class Extension; +class InterstitialPage; namespace base { class DictionaryValue; } +namespace content { +class WebContents; +} + namespace chromeos { // OfflineLoadPage class shows the interstitial page that is shown // when no network is available and hides when some network (either // one of wifi, 3g or ethernet) becomes available. // It deletes itself when the interstitial page is closed. -class OfflineLoadPage : public ChromeInterstitialPage, +class OfflineLoadPage : public content::InterstitialPageDelegate, public net::NetworkChangeNotifier::OnlineStateObserver { public: // Passed a boolean indicating whether or not it is OK to proceed with the @@ -44,11 +50,13 @@ class OfflineLoadPage : public ChromeInterstitialPage, virtual void NotifyBlockingPageComplete(bool proceed); private: - // ChromeInterstitialPage implementation. + // InterstitialPageDelegate implementation. virtual std::string GetHTMLContents() OVERRIDE; virtual void CommandReceived(const std::string& command) OVERRIDE; - virtual void Proceed() OVERRIDE; - virtual void DontProceed() OVERRIDE; + virtual void OverrideRendererPrefs( + content::RendererPreferences* prefs) OVERRIDE; + virtual void OnProceed() OVERRIDE; + virtual void OnDontProceed() OVERRIDE; // net::NetworkChangeNotifier::OnlineStateObserver overrides. virtual void OnOnlineStateChanged(bool online) OVERRIDE; @@ -70,7 +78,9 @@ class OfflineLoadPage : public ChromeInterstitialPage, // True if the proceed is chosen. bool proceeded_; - bool in_test_; + content::WebContents* web_contents_; + GURL url_; + InterstitialPage* interstitial_page_; // Owns us. DISALLOW_COPY_AND_ASSIGN(OfflineLoadPage); }; diff --git a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc index 1bf9ea7..fa8b2f7 100644 --- a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc +++ b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/offline/offline_load_page.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" +#include "content/browser/tab_contents/interstitial_page.h" #include "content/browser/tab_contents/test_tab_contents.h" #include "content/test/test_browser_thread.h" @@ -78,7 +79,7 @@ class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness { } void ShowInterstitial(const char* url) { - (new TestOfflineLoadPage(contents(), GURL(url), this))->Show(); + new TestOfflineLoadPage(contents(), GURL(url), this); } // Returns the OfflineLoadPage currently showing or NULL if none is diff --git a/chrome/browser/renderer_host/offline_resource_throttle.cc b/chrome/browser/renderer_host/offline_resource_throttle.cc index 57ca848..0df0312 100644 --- a/chrome/browser/renderer_host/offline_resource_throttle.cc +++ b/chrome/browser/renderer_host/offline_resource_throttle.cc @@ -19,6 +19,7 @@ #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_view_host_delegate.h" #include "content/public/browser/resource_throttle_controller.h" #include "net/base/net_errors.h" #include "net/base/network_change_notifier.h" @@ -50,7 +51,7 @@ void ShowOfflinePage( // the offline page on the IO thread and before we actually show the // offline page here on the UI thread. if (web_contents) - (new chromeos::OfflineLoadPage(web_contents, url, callback))->Show(); + new chromeos::OfflineLoadPage(web_contents, url, callback); } } diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index ea1c2ee..cb125f3 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -20,6 +20,7 @@ #include "chrome/browser/google/google_util.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/safe_browsing/malware_details.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/tab_contents/tab_util.h" @@ -27,6 +28,7 @@ #include "chrome/common/jstemplate_builder.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" +#include "content/browser/tab_contents/interstitial_page.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/user_metrics.h" @@ -136,19 +138,19 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( SafeBrowsingService* sb_service, WebContents* web_contents, const UnsafeResourceList& unsafe_resources) - : ChromeInterstitialPage(web_contents, - IsMainPageLoadBlocked(unsafe_resources), - unsafe_resources[0].url), - malware_details_proceed_delay_ms_( + : malware_details_proceed_delay_ms_( kMalwareDetailsProceedDelayMilliSeconds), sb_service_(sb_service), report_loop_(NULL), is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), - unsafe_resources_(unsafe_resources) { + unsafe_resources_(unsafe_resources), + proceeded_(false), + web_contents_(web_contents), + url_(unsafe_resources[0].url) { RecordUserAction(SHOW); if (!is_main_frame_load_blocked_) { navigation_entry_index_to_remove_ = - tab()->GetController().GetLastCommittedEntryIndex(); + web_contents->GetController().GetLastCommittedEntryIndex(); } else { navigation_entry_index_to_remove_ = -1; } @@ -163,13 +165,16 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( malware_details_ == NULL && CanShowMalwareDetailsOption()) { malware_details_ = MalwareDetails::NewMalwareDetails( - sb_service_, tab(), unsafe_resources[0]); + sb_service_, web_contents, unsafe_resources[0]); } + + interstitial_page_ = InterstitialPage::Create( + web_contents, IsMainPageLoadBlocked(unsafe_resources), url_, this); } bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { - return (!tab()->GetBrowserContext()->IsOffTheRecord() && - tab()->GetURL().SchemeIs(chrome::kHttpScheme)); + return (!web_contents_->GetBrowserContext()->IsOffTheRecord() && + web_contents_->GetURL().SchemeIs(chrome::kHttpScheme)); } SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { @@ -269,7 +274,7 @@ void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE), l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1, - UTF8ToUTF16(tab()->GetURL().host())), + UTF8ToUTF16(web_contents_->GetURL().host())), l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION2), string16()); } else if (malware) { @@ -279,7 +284,7 @@ void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE), l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION1, - UTF8ToUTF16(tab()->GetURL().host())), + UTF8ToUTF16(web_contents_->GetURL().host())), l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION2), l10n_util::GetStringUTF16( IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION3)); @@ -291,7 +296,7 @@ void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), l10n_util::GetStringFUTF16( IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1, - UTF8ToUTF16(tab()->GetURL().host())), + UTF8ToUTF16(web_contents_->GetURL().host())), string16(), string16()); } @@ -313,18 +318,18 @@ void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( l10n_util::GetStringUTF8( IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str()); - strings->SetString("badURL", url().host()); + strings->SetString("badURL", url_.host()); // Check to see if we're blocking the main page, or a sub-resource on the // main page. string16 description1, description3, description5; if (is_main_frame_load_blocked_) { description1 = l10n_util::GetStringFUTF16( - IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, UTF8ToUTF16(url().host())); + IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, UTF8ToUTF16(url_.host())); } else { description1 = l10n_util::GetStringFUTF16( IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4, - UTF8ToUTF16(tab()->GetURL().host()), - UTF8ToUTF16(url().host())); + UTF8ToUTF16(web_contents_->GetURL().host()), + UTF8ToUTF16(url_.host())); } std::string proceed_link = base::StringPrintf(kPLinkHtml, @@ -343,8 +348,8 @@ void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( description5 = l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5, - UTF8ToUTF16(url().host()), - UTF8ToUTF16(url().host()), + UTF8ToUTF16(url_.host()), + UTF8ToUTF16(url_.host()), UTF8ToUTF16(diagnostic_link)); strings->SetString("description5", description5); @@ -371,7 +376,8 @@ void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, UTF8ToUTF16(privacy_link))); - Profile* profile = Profile::FromBrowserContext(tab()->GetBrowserContext()); + Profile* profile = Profile::FromBrowserContext( + web_contents_->GetBrowserContext()); const PrefService::Preference* pref = profile->GetPrefs()->FindPreference( prefs::kSafeBrowsingReportingEnabled); @@ -400,7 +406,7 @@ void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE), l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, - UTF8ToUTF16(url().host())), + UTF8ToUTF16(url_.host())), l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2), description3); @@ -444,7 +450,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { OpenURLParams params( url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); - tab()->OpenURL(params); + web_contents_->OpenURL(params); return; } @@ -453,12 +459,12 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { GURL url(kSbPrivacyPolicyUrl); OpenURLParams params( url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); - tab()->OpenURL(params); + web_contents_->OpenURL(params); return; } if (command == kProceedCommand) { - Proceed(); + interstitial_page_->Proceed(); // We are deleted after this. return; } @@ -467,20 +473,21 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { if (is_main_frame_load_blocked_) { // If the load is blocked, we want to close the interstitial and discard // the pending entry. - DontProceed(); + interstitial_page_->DontProceed(); // We are deleted after this. return; } // Otherwise the offending entry has committed, and we need to go back or // to a safe page. We will close the interstitial when that page commits. - if (tab()->GetController().CanGoBack()) { - tab()->GetController().GoBack(); + if (web_contents_->GetController().CanGoBack()) { + web_contents_->GetController().GoBack(); } else { - tab()->GetController().LoadURL(GURL(chrome::kChromeUINewTabURL), - content::Referrer(), - content::PAGE_TRANSITION_START_PAGE, - std::string()); + web_contents_->GetController().LoadURL( + GURL(chrome::kChromeUINewTabURL), + content::Referrer(), + content::PAGE_TRANSITION_START_PAGE, + std::string()); } return; } @@ -521,7 +528,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { OpenURLParams params( report_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); - tab()->OpenURL(params); + web_contents_->OpenURL(params); return; } @@ -537,20 +544,29 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { OpenURLParams params( diagnostic_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); - tab()->OpenURL(params); + web_contents_->OpenURL(params); return; } NOTREACHED() << "Unexpected command: " << command; } +void SafeBrowsingBlockingPage::OverrideRendererPrefs( + content::RendererPreferences* prefs) { + Profile* profile = Profile::FromBrowserContext( + web_contents_->GetBrowserContext()); + renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); + } + void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { - Profile* profile = Profile::FromBrowserContext(tab()->GetBrowserContext()); + Profile* profile = Profile::FromBrowserContext( + web_contents_->GetBrowserContext()); PrefService* pref = profile->GetPrefs(); pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); } -void SafeBrowsingBlockingPage::Proceed() { +void SafeBrowsingBlockingPage::OnProceed() { + proceeded_ = true; RecordUserAction(PROCEED); // Send the malware details, if we opted to. FinishMalwareDetails(malware_details_proceed_delay_ms_); @@ -560,35 +576,27 @@ void SafeBrowsingBlockingPage::Proceed() { // Check to see if some new notifications of unsafe resources have been // received while we were showing the interstitial. UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); - UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); + UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); SafeBrowsingBlockingPage* blocking_page = NULL; if (iter != unsafe_resource_map->end() && !iter->second.empty()) { // Build an interstitial for all the unsafe resources notifications. // Don't show it now as showing an interstitial while an interstitial is // already showing would cause DontProceed() to be invoked. - blocking_page = factory_->CreateSafeBrowsingPage(sb_service_, tab(), + blocking_page = factory_->CreateSafeBrowsingPage(sb_service_, web_contents_, iter->second); unsafe_resource_map->erase(iter); } - InterstitialPage::Proceed(); - // We are now deleted. - // Now that this interstitial is gone, we can show the new one. if (blocking_page) - blocking_page->Show(); + blocking_page->interstitial_page_->Show(); } -void SafeBrowsingBlockingPage::DontProceed() { - DCHECK(action_taken() != DONT_PROCEED_ACTION); +void SafeBrowsingBlockingPage::OnDontProceed() { // We could have already called Proceed(), in which case we must not notify // the SafeBrowsingService again, as the client has been deleted. - if (action_taken() == PROCEED_ACTION) { - // We still want to hide the interstitial page. - InterstitialPage::DontProceed(); - // We are now deleted. + if (proceeded_) return; - } RecordUserAction(DONT_PROCEED); // Send the malware details, if we opted to. @@ -599,7 +607,7 @@ void SafeBrowsingBlockingPage::DontProceed() { // The user does not want to proceed, clear the queued unsafe resources // notifications we received while the interstitial was showing. UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); - UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); + UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); if (iter != unsafe_resource_map->end() && !iter->second.empty()) { NotifySafeBrowsingService(sb_service_, iter->second, false); unsafe_resource_map->erase(iter); @@ -611,16 +619,14 @@ void SafeBrowsingBlockingPage::DontProceed() { // current entry if it has been committed again, which is possible on a page // that had a subresource warning. int last_committed_index = - tab()->GetController().GetLastCommittedEntryIndex(); + web_contents_->GetController().GetLastCommittedEntryIndex(); if (navigation_entry_index_to_remove_ != -1 && navigation_entry_index_to_remove_ != last_committed_index && - !tab()->IsBeingDestroyed()) { - tab()->GetController().RemoveEntryAtIndex( + !web_contents_->IsBeingDestroyed()) { + web_contents_->GetController().RemoveEntryAtIndex( navigation_entry_index_to_remove_); navigation_entry_index_to_remove_ = -1; } - InterstitialPage::DontProceed(); - // We are now deleted. } void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { @@ -669,7 +675,8 @@ void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { if (malware_details_ == NULL) return; // Not all interstitials have malware details (eg phishing). - Profile* profile = Profile::FromBrowserContext(tab()->GetBrowserContext()); + Profile* profile = Profile::FromBrowserContext( + web_contents_->GetBrowserContext()); const PrefService::Preference* pref = profile->GetPrefs()->FindPreference(prefs::kSafeBrowsingReportingEnabled); @@ -728,7 +735,7 @@ void SafeBrowsingBlockingPage::ShowBlockingPage( factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); SafeBrowsingBlockingPage* blocking_page = factory_->CreateSafeBrowsingPage(sb_service, web_contents, resources); - blocking_page->Show(); + blocking_page->interstitial_page_->Show(); return; } diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h index 767c726..93defc0 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h @@ -33,19 +33,23 @@ #include <vector> #include "chrome/browser/safe_browsing/safe_browsing_service.h" -#include "chrome/browser/tab_contents/chrome_interstitial_page.h" +#include "content/public/browser/interstitial_page_delegate.h" #include "googleurl/src/gurl.h" +class InterstitialPage; +class MalwareDetails; class MessageLoop; class SafeBrowsingBlockingPageFactory; -class MalwareDetails; -class TabContents; namespace base { class DictionaryValue; } -class SafeBrowsingBlockingPage : public ChromeInterstitialPage { +namespace content { +class WebContents; +} + +class SafeBrowsingBlockingPage : public content::InterstitialPageDelegate { public: typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList; typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; @@ -67,16 +71,19 @@ class SafeBrowsingBlockingPage : public ChromeInterstitialPage { factory_ = factory; } - // ChromeInterstitialPage method: + // InterstitialPageDelegate method: virtual std::string GetHTMLContents() OVERRIDE; - virtual void Proceed() OVERRIDE; - virtual void DontProceed() OVERRIDE; + virtual void CommandReceived(const std::string& command) OVERRIDE; + virtual void OverrideRendererPrefs( + content::RendererPreferences* prefs) OVERRIDE; + virtual void OnProceed() OVERRIDE; + virtual void OnDontProceed() OVERRIDE; protected: friend class SafeBrowsingBlockingPageTest; - - // ChromeInterstitialPage method: - virtual void CommandReceived(const std::string& command) OVERRIDE; + friend class TestSafeBrowsingBlockingPage; + FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, + ProceedThenDontProceed); void SetReportingPreference(bool report); @@ -169,6 +176,12 @@ class SafeBrowsingBlockingPage : public ChromeInterstitialPage { // is gone (if the user enables the feature). scoped_refptr<MalwareDetails> malware_details_; + bool proceeded_; + + content::WebContents* web_contents_; + GURL url_; + InterstitialPage* interstitial_page_; // Owns us + // The factory used to instanciate SafeBrowsingBlockingPage objects. // Usefull for tests, so they can provide their own implementation of // SafeBrowsingBlockingPage. diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc index f1b0155..9c52fe1 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc @@ -21,6 +21,7 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" +#include "content/browser/tab_contents/interstitial_page.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" @@ -274,7 +275,8 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest, // NavigateToURL returns. SafeBrowsingBlockingPage* interstitial_page = static_cast<SafeBrowsingBlockingPage*>( - InterstitialPage::GetInterstitialPage(contents)); + InterstitialPage::GetInterstitialPage(contents)-> + GetDelegateForTesting()); ASSERT_TRUE(interstitial_page); interstitial_page->CommandReceived(command); } @@ -304,7 +306,8 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest, if (contents->ShowingInterstitialPage() && wait_for_delete) { // We'll get notified when the interstitial is deleted. static_cast<TestSafeBrowsingBlockingPage*>( - contents->GetInterstitialPage())->set_wait_for_delete(); + contents->GetInterstitialPage()->GetDelegateForTesting())-> + set_wait_for_delete(); ui_test_utils::RunMessageLoop(); } diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc index fac745d..eba926a 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc @@ -8,6 +8,7 @@ #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" +#include "content/browser/tab_contents/interstitial_page.h" #include "content/browser/tab_contents/test_tab_contents.h" #include "content/public/browser/navigation_entry.h" #include "content/test/test_browser_thread.h" @@ -32,12 +33,11 @@ class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { : SafeBrowsingBlockingPage(service, web_contents, unsafe_resources) { // Don't delay details at all for the unittest. malware_details_proceed_delay_ms_ = 0; - } - // Overriden from InterstitialPage. Don't create a view. - virtual WebContentsView* CreateWebContentsView() { - return NULL; + // Don't create a view. + interstitial_page_->DontCreateViewForTesting(); } + }; class TestSafeBrowsingService: public SafeBrowsingService { @@ -138,7 +138,8 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { InterstitialPage::GetInterstitialPage(contents()); if (!interstitial) return NULL; - return static_cast<SafeBrowsingBlockingPage*>(interstitial); + return static_cast<SafeBrowsingBlockingPage*>( + interstitial->GetDelegateForTesting()); } UserResponse user_response() const { return user_response_; } @@ -146,14 +147,14 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { static void ProceedThroughInterstitial( SafeBrowsingBlockingPage* sb_interstitial) { - sb_interstitial->Proceed(); + sb_interstitial->interstitial_page_->Proceed(); // Proceed() posts a task to update the SafeBrowsingService::Client. MessageLoop::current()->RunAllPending(); } static void DontProceedThroughInterstitial( SafeBrowsingBlockingPage* sb_interstitial) { - sb_interstitial->DontProceed(); + sb_interstitial->interstitial_page_->DontProceed(); // DontProceed() posts a task to update the SafeBrowsingService::Client. MessageLoop::current()->RunAllPending(); } @@ -540,8 +541,8 @@ TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { // Simulate the user clicking "proceed" then "don't proceed" (before the // interstitial is shown). - sb_interstitial->Proceed(); - sb_interstitial->DontProceed(); + sb_interstitial->interstitial_page_->Proceed(); + sb_interstitial->interstitial_page_->DontProceed(); // Proceed() and DontProceed() post a task to update the // SafeBrowsingService::Client. MessageLoop::current()->RunAllPending(); diff --git a/chrome/browser/ssl/ssl_blocking_page.cc b/chrome/browser/ssl/ssl_blocking_page.cc index 3d96c05..b32b27b 100644 --- a/chrome/browser/ssl/ssl_blocking_page.cc +++ b/chrome/browser/ssl/ssl_blocking_page.cc @@ -9,12 +9,15 @@ #include "base/string_piece.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/ssl/ssl_error_info.h" #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/common/jstemplate_builder.h" #include "content/browser/cert_store.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/ssl/ssl_cert_error_handler.h" +#include "content/browser/tab_contents/interstitial_page.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" @@ -51,15 +54,15 @@ SSLBlockingPage::SSLBlockingPage( SSLCertErrorHandler* handler, bool overridable, const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) - : ChromeInterstitialPage( - tab_util::GetWebContentsByID( - handler->render_process_host_id(), handler->tab_contents_id()), - true, - handler->request_url()), - handler_(handler), + : handler_(handler), callback_(callback), overridable_(overridable) { RecordSSLBlockingPageStats(SHOW); + web_contents_ = tab_util::GetWebContentsByID( + handler->render_process_host_id(), handler->tab_contents_id()); + interstitial_page_ = InterstitialPage::Create( + web_contents_, true, handler->request_url(), this); + interstitial_page_->Show(); } SSLBlockingPage::~SSLBlockingPage() { @@ -115,10 +118,10 @@ std::string SSLBlockingPage::GetHTMLContents() { return jstemplate_builder::GetI18nTemplateHtml(html, &strings); } -void SSLBlockingPage::UpdateEntry(NavigationEntry* entry) { +void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { const net::SSLInfo& ssl_info = handler_->ssl_info(); int cert_id = CertStore::GetInstance()->StoreCert( - ssl_info.cert, tab()->GetRenderProcessHost()->GetID()); + ssl_info.cert, web_contents_->GetRenderProcessHost()->GetID()); entry->GetSSL().security_style = content::SECURITY_STYLE_AUTHENTICATION_BROKEN; @@ -127,33 +130,36 @@ void SSLBlockingPage::UpdateEntry(NavigationEntry* entry) { entry->GetSSL().security_bits = ssl_info.security_bits; content::NotificationService::current()->Notify( content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, - content::Source<NavigationController>(&tab()->GetController()), + content::Source<NavigationController>(&web_contents_->GetController()), content::NotificationService::NoDetails()); } void SSLBlockingPage::CommandReceived(const std::string& command) { if (command == "1") { - Proceed(); + interstitial_page_->Proceed(); } else { - DontProceed(); + interstitial_page_->DontProceed(); } } -void SSLBlockingPage::Proceed() { +void SSLBlockingPage::OverrideRendererPrefs( + content::RendererPreferences* prefs) { + Profile* profile = Profile::FromBrowserContext( + web_contents_->GetBrowserContext()); + renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); + } + +void SSLBlockingPage::OnProceed() { RecordSSLBlockingPageStats(PROCEED); // Accepting the certificate resumes the loading of the page. NotifyAllowCertificate(); - - // This call hides and deletes the interstitial. - InterstitialPage::Proceed(); } -void SSLBlockingPage::DontProceed() { +void SSLBlockingPage::OnDontProceed() { RecordSSLBlockingPageStats(DONT_PROCEED); NotifyDenyCertificate(); - InterstitialPage::DontProceed(); } void SSLBlockingPage::NotifyDenyCertificate() { diff --git a/chrome/browser/ssl/ssl_blocking_page.h b/chrome/browser/ssl/ssl_blocking_page.h index 5481e51..e4106f7 100644 --- a/chrome/browser/ssl/ssl_blocking_page.h +++ b/chrome/browser/ssl/ssl_blocking_page.h @@ -11,18 +11,24 @@ #include "base/callback.h" #include "base/string16.h" -#include "chrome/browser/tab_contents/chrome_interstitial_page.h" +#include "content/public/browser/interstitial_page_delegate.h" +class GURL; +class InterstitialPage; class SSLCertErrorHandler; namespace base { class DictionaryValue; } +namespace content { +class WebContents; +} + // This class is responsible for showing/hiding the interstitial page that is // shown when a certificate error happens. // It deletes itself when the interstitial page is closed. -class SSLBlockingPage : public ChromeInterstitialPage { +class SSLBlockingPage : public content::InterstitialPageDelegate { public: SSLBlockingPage( SSLCertErrorHandler* handler, @@ -38,12 +44,14 @@ class SSLBlockingPage : public ChromeInterstitialPage { const std::vector<string16>& extra_info); protected: - // ChromeInterstitialPage implementation. + // InterstitialPageDelegate implementation. virtual std::string GetHTMLContents() OVERRIDE; virtual void CommandReceived(const std::string& command) OVERRIDE; - virtual void UpdateEntry(content::NavigationEntry* entry) OVERRIDE; - virtual void Proceed() OVERRIDE; - virtual void DontProceed() OVERRIDE; + virtual void OverrideEntry(content::NavigationEntry* entry) OVERRIDE; + virtual void OverrideRendererPrefs( + content::RendererPreferences* prefs) OVERRIDE; + virtual void OnProceed() OVERRIDE; + virtual void OnDontProceed() OVERRIDE; private: void NotifyDenyCertificate(); @@ -58,6 +66,9 @@ class SSLBlockingPage : public ChromeInterstitialPage { // Is the certificate error overridable or fatal? bool overridable_; + content::WebContents* web_contents_; + InterstitialPage* interstitial_page_; // Owns us. + DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage); }; diff --git a/chrome/browser/tab_contents/chrome_interstitial_page.cc b/chrome/browser/tab_contents/chrome_interstitial_page.cc deleted file mode 100644 index 8b5f1b7..0000000 --- a/chrome/browser/tab_contents/chrome_interstitial_page.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/tab_contents/chrome_interstitial_page.h" - -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/renderer_preferences_util.h" -#include "chrome/common/render_messages.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/public/browser/web_contents.h" - -using content::WebContents; - -ChromeInterstitialPage::ChromeInterstitialPage(WebContents* tab, - bool new_navigation, - const GURL& url) - : InterstitialPage(tab, new_navigation, url) { - Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); - content::RendererPreferences prefs; - renderer_preferences_util::UpdateFromSystemSettings(&prefs, profile); - set_renderer_preferences(prefs); -} - -ChromeInterstitialPage::~ChromeInterstitialPage() { -} - -void ChromeInterstitialPage::Show() { - InterstitialPage::Show(); - - render_view_host()->Send( - new ChromeViewMsg_SetAsInterstitial(render_view_host()->routing_id())); -} diff --git a/chrome/browser/tab_contents/chrome_interstitial_page.h b/chrome/browser/tab_contents/chrome_interstitial_page.h deleted file mode 100644 index 0692e56..0000000 --- a/chrome/browser/tab_contents/chrome_interstitial_page.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_CHROME_INTERSTITIAL_PAGE_H_ -#define CHROME_BROWSER_TAB_CONTENTS_CHROME_INTERSTITIAL_PAGE_H_ -#pragma once - -#include <map> -#include <string> - -#include "content/browser/tab_contents/interstitial_page.h" -#include "content/public/browser/notification_observer.h" -#include "googleurl/src/gurl.h" - -// This class adds the possibility to react to DOMResponse-messages sent by -// the RenderViewHost via ChromeRenderViewHostObserver to the InterstitialPage. -class ChromeInterstitialPage : public InterstitialPage { - public: - ChromeInterstitialPage(content::WebContents* tab, - bool new_navigation, - const GURL& url); - virtual ~ChromeInterstitialPage(); - - // Shows the interstitial page in the tab. - virtual void Show() OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(ChromeInterstitialPage); -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_CHROME_INTERSTITIAL_PAGE_H_ diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index ebb7a88..60cb6cf 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -44,6 +44,7 @@ #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/interstitial_page.h" #include "content/public/browser/favicon_status.h" +#include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" @@ -153,15 +154,24 @@ void RunCloseWithAppMenuCallback(Browser* browser) { // Displays "INTERSTITIAL" while the interstitial is attached. // (InterstitialPage can be used in a test directly, but there would be no way // to visually tell if it is showing or not.) -class TestInterstitialPage : public InterstitialPage { +class TestInterstitialPage : public content::InterstitialPageDelegate { public: - TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) - : InterstitialPage(tab, new_navigation, url) { } + TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { + interstitial_page_ = InterstitialPage::Create( + tab, new_navigation, url , this); + interstitial_page_->Show(); + } virtual ~TestInterstitialPage() { } + void Proceed() { + interstitial_page_->Proceed(); + } virtual std::string GetHTMLContents() OVERRIDE { return "<h1>INTERSTITIAL</h1>"; } + + private: + InterstitialPage* interstitial_page_; // Owns us. }; } // namespace @@ -1358,7 +1368,6 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCommandDisable) { ui_test_utils::WindowedNotificationObserver interstitial_observer( content::NOTIFICATION_INTERSTITIAL_ATTACHED, content::Source<WebContents>(contents)); - interstitial->Show(); interstitial_observer.Wait(); EXPECT_TRUE(contents->ShowingInterstitialPage()); diff --git a/chrome/browser/ui/pdf/pdf_unsupported_feature.cc b/chrome/browser/ui/pdf/pdf_unsupported_feature.cc index 5bce9e2..be6776d 100644 --- a/chrome/browser/ui/pdf/pdf_unsupported_feature.cc +++ b/chrome/browser/ui/pdf/pdf_unsupported_feature.cc @@ -13,7 +13,7 @@ #include "chrome/browser/plugin_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/tab_contents/chrome_interstitial_page.h" +#include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -21,6 +21,8 @@ #include "chrome/common/jstemplate_builder.h" #include "chrome/common/pref_names.h" #include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/tab_contents/interstitial_page.h" +#include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/plugin_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/user_metrics.h" @@ -162,21 +164,23 @@ void OpenUsingReader(TabContentsWrapper* tab, // An interstitial to be used when the user chooses to open a PDF using Adobe // Reader, but it is out of date. -class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { +class PDFUnsupportedFeatureInterstitial + : public content::InterstitialPageDelegate { public: PDFUnsupportedFeatureInterstitial( TabContentsWrapper* tab, const WebPluginInfo& reader_webplugininfo) - : ChromeInterstitialPage( - tab->web_contents(), false, tab->web_contents()->GetURL()), - tab_contents_(tab), + : tab_contents_(tab), reader_webplugininfo_(reader_webplugininfo) { content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); + interstitial_page_ = InterstitialPage::Create( + tab->web_contents(), false, tab->web_contents()->GetURL(), this); + interstitial_page_->Show(); } protected: - // ChromeInterstitialPage implementation. - virtual std::string GetHTMLContents() { + // InterstitialPageDelegate implementation. + virtual std::string GetHTMLContents() OVERRIDE { DictionaryValue strings; strings.SetString( "title", @@ -204,18 +208,18 @@ class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { return jstemplate_builder::GetI18nTemplateHtml(html, &strings); } - virtual void CommandReceived(const std::string& command) { + virtual void CommandReceived(const std::string& command) OVERRIDE { if (command == "0") { content::RecordAction( UserMetricsAction("PDF_ReaderInterstitialCancel")); - DontProceed(); + interstitial_page_->DontProceed(); return; } if (command == "1") { content::RecordAction( UserMetricsAction("PDF_ReaderInterstitialUpdate")); - OpenReaderUpdateURL(tab()); + OpenReaderUpdateURL(tab_contents_->web_contents()); } else if (command == "2") { content::RecordAction( UserMetricsAction("PDF_ReaderInterstitialIgnore")); @@ -223,12 +227,19 @@ class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage { } else { NOTREACHED(); } - Proceed(); + interstitial_page_->Proceed(); + } + + virtual void OverrideRendererPrefs( + content::RendererPreferences* prefs) OVERRIDE { + renderer_preferences_util::UpdateFromSystemSettings( + prefs, tab_contents_->profile()); } private: TabContentsWrapper* tab_contents_; WebPluginInfo reader_webplugininfo_; + InterstitialPage* interstitial_page_; // Owns us. DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); }; @@ -341,10 +352,7 @@ bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() { content::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK")); if (reader_vulnerable_) { - PDFUnsupportedFeatureInterstitial* interstitial = - new PDFUnsupportedFeatureInterstitial(tab_contents_, - reader_webplugininfo_); - interstitial->Show(); + new PDFUnsupportedFeatureInterstitial(tab_contents_, reader_webplugininfo_); return true; } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 4e76b3e..4f6e1be 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2392,8 +2392,6 @@ 'browser/tab_first_render_watcher.h', 'browser/tab_contents/background_contents.cc', 'browser/tab_contents/background_contents.h', - 'browser/tab_contents/chrome_interstitial_page.cc', - 'browser/tab_contents/chrome_interstitial_page.h', 'browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.cc', 'browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h', 'browser/tab_contents/chrome_web_contents_view_mac_delegate.h', diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index 9db1c9c..bac2301 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -263,7 +263,6 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS) IPC_MESSAGE_HANDLER(ChromeViewMsg_AddStrictSecurityHost, OnAddStrictSecurityHost) - IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -361,10 +360,6 @@ void ChromeRenderViewObserver::OnAddStrictSecurityHost( strict_security_hosts_.insert(host); } -void ChromeRenderViewObserver::OnSetAsInterstitial() { - content_settings_->SetAsInterstitial(); -} - void ChromeRenderViewObserver::Navigate(const GURL& url) { // Execute cache clear operations that were postponed until a navigation // event (including tab reload). diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h index 877ac1b..8f9bba1 100644 --- a/chrome/renderer/chrome_render_view_observer.h +++ b/chrome/renderer/chrome_render_view_observer.h @@ -136,7 +136,6 @@ class ChromeRenderViewObserver : public content::RenderViewObserver, void OnStartFrameSniffer(const string16& frame_name); void OnGetFPS(); void OnAddStrictSecurityHost(const std::string& host); - void OnSetAsInterstitial(); // Captures the thumbnail and text contents for indexing for the given load // ID. If the view's load ID is different than the parameter, this call is diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc index d11910d..b311751 100644 --- a/chrome/renderer/content_settings_observer.cc +++ b/chrome/renderer/content_settings_observer.cc @@ -102,6 +102,7 @@ bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { // blocked plugin. IPC_MESSAGE_HANDLER_GENERIC(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins(); handled = false) + IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -280,14 +281,14 @@ void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); } -void ContentSettingsObserver::SetAsInterstitial() { - is_interstitial_page_ = true; -} - void ContentSettingsObserver::OnLoadBlockedPlugins() { plugins_temporarily_allowed_ = true; } +void ContentSettingsObserver::OnSetAsInterstitial() { + is_interstitial_page_ = true; +} + void ContentSettingsObserver::ClearBlockedContentSettings() { for (size_t i = 0; i < arraysize(content_blocked_); ++i) content_blocked_[i] = false; diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h index 689a77d..62b52a9 100644 --- a/chrome/renderer/content_settings_observer.h +++ b/chrome/renderer/content_settings_observer.h @@ -65,12 +65,10 @@ class ContentSettingsObserver void DidNotAllowPlugins(WebKit::WebFrame* frame); void DidNotAllowScript(WebKit::WebFrame* frame); - // Used for allowing scripts and images on views displaying interstitial - // pages. - void SetAsInterstitial(); - private: FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes); + FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, + ContentSettingsInterstitialPages); // RenderViewObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; @@ -79,6 +77,7 @@ class ContentSettingsObserver // Message handlers. void OnLoadBlockedPlugins(); + void OnSetAsInterstitial(); // Resets the |content_blocked_| array. void ClearBlockedContentSettings(); diff --git a/chrome/renderer/content_settings_observer_browsertest.cc b/chrome/renderer/content_settings_observer_browsertest.cc index db720f5..cd9c016 100644 --- a/chrome/renderer/content_settings_observer_browsertest.cc +++ b/chrome/renderer/content_settings_observer_browsertest.cc @@ -345,7 +345,7 @@ TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) { ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); observer->SetContentSettingRules(&content_setting_rules); - observer->SetAsInterstitial(); + observer->OnSetAsInterstitial(); // Load a page which contains a script. std::string html = "<html>" diff --git a/content/browser/tab_contents/interstitial_page.cc b/content/browser/tab_contents/interstitial_page.cc index d42d0cd..9ce0be1 100644 --- a/content/browser/tab_contents/interstitial_page.cc +++ b/content/browser/tab_contents/interstitial_page.cc @@ -24,6 +24,7 @@ #include "content/common/view_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/dom_operation_notification_details.h" +#include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/invalidate_type.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" @@ -36,6 +37,7 @@ using content::BrowserThread; using content::DomOperationNotificationDetails; +using content::InterstitialPageDelegate; using content::NavigationController; using content::NavigationEntry; using content::NavigationEntryImpl; @@ -117,13 +119,21 @@ class InterstitialPage::InterstitialPageRVHViewDelegate DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHViewDelegate); }; +InterstitialPage* InterstitialPage::Create(WebContents* tab, + bool new_navigation, + const GURL& url, + InterstitialPageDelegate* delegate) { + return new InterstitialPage(tab, new_navigation, url, delegate); +} + // static InterstitialPage::InterstitialPageMap* InterstitialPage::tab_to_interstitial_page_ = NULL; InterstitialPage::InterstitialPage(WebContents* tab, bool new_navigation, - const GURL& url) + const GURL& url, + InterstitialPageDelegate* delegate) : tab_(static_cast<TabContents*>(tab)), url_(url), new_navigation_(new_navigation), @@ -138,7 +148,9 @@ InterstitialPage::InterstitialPage(WebContents* tab, tab_was_loading_(false), resource_dispatcher_host_notified_(false), ALLOW_THIS_IN_INITIALIZER_LIST(rvh_view_delegate_( - new InterstitialPageRVHViewDelegate(this))) { + new InterstitialPageRVHViewDelegate(this))), + create_view_(true), + delegate_(delegate) { InitInterstitialPageMap(); // It would be inconsistent to create an interstitial with no new navigation // (which is the case when the interstitial was triggered by a sub-resource on @@ -148,11 +160,6 @@ InterstitialPage::InterstitialPage(WebContents* tab, } InterstitialPage::~InterstitialPage() { - InterstitialPageMap::iterator iter = tab_to_interstitial_page_->find(tab_); - DCHECK(iter != tab_to_interstitial_page_->end()); - if (iter != tab_to_interstitial_page_->end()) - tab_to_interstitial_page_->erase(iter); - DCHECK(!render_view_host_); } void InterstitialPage::Show() { @@ -165,6 +172,7 @@ void InterstitialPage::Show() { InterstitialPage* interstitial = iter->second; if (interstitial->action_taken_ != NO_ACTION) { interstitial->Hide(); + delete interstitial; } else { // If we are currently showing an interstitial page for which we created // a transient entry and a new interstitial is shown as the result of a @@ -199,8 +207,8 @@ void InterstitialPage::Show() { entry->SetVirtualURL(url_); entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); - // Give sub-classes a chance to set some states on the navigation entry. - UpdateEntry(entry); + // Give delegates a chance to set some states on the navigation entry. + delegate_->OverrideEntry(entry); tab_->GetControllerImpl().AddTransientEntry(entry); } @@ -210,7 +218,7 @@ void InterstitialPage::Show() { CreateWebContentsView(); std::string data_url = "data:text/html;charset=utf-8," + - net::EscapePath(GetHTMLContents()); + net::EscapePath(delegate_->GetHTMLContents()); render_view_host_->NavigateToURL(GURL(data_url)); notification_registrar_.Add(this, @@ -260,7 +268,10 @@ void InterstitialPage::Hide() { content::Source<WebContents>(tab_), content::NotificationService::NoDetails()); - delete this; + InterstitialPageMap::iterator iter = tab_to_interstitial_page_->find(tab_); + DCHECK(iter != tab_to_interstitial_page_->end()); + if (iter != tab_to_interstitial_page_->end()) + tab_to_interstitial_page_->erase(iter); } void InterstitialPage::Observe(int type, @@ -303,14 +314,14 @@ void InterstitialPage::Observe(int type, // User decided to proceed and either the navigation was committed or // the tab was closed before that. Hide(); - // WARNING: we are now deleted! + delete this; } break; case content::NOTIFICATION_DOM_OPERATION_RESPONSE: if (enabled()) { content::Details<DomOperationNotificationDetails> dom_op_details( details); - CommandReceived(dom_op_details->json); + delegate_->CommandReceived(dom_op_details->json); } break; default: @@ -416,6 +427,7 @@ void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host, content::RendererPreferences InterstitialPage::GetRendererPrefs( content::BrowserContext* browser_context) const { + delegate_->OverrideRendererPrefs(&renderer_preferences_); return renderer_preferences_; } @@ -446,6 +458,8 @@ RenderViewHost* InterstitialPage::CreateRenderViewHost() { } WebContentsView* InterstitialPage::CreateWebContentsView() { + if (!create_view_) + return NULL; WebContentsView* web_contents_view = tab()->GetView(); RenderWidgetHostView* view = web_contents_view->CreateViewForWidget(render_view_host_); @@ -486,12 +500,12 @@ void InterstitialPage::Proceed() { // navigation is committed. if (!new_navigation_) { Hide(); - // WARNING: we are now deleted! + delegate_->OnProceed(); + delete this; + return; } -} -std::string InterstitialPage::GetHTMLContents() { - return std::string(); + delegate_->OnProceed(); } void InterstitialPage::DontProceed() { @@ -522,7 +536,8 @@ void InterstitialPage::DontProceed() { tab_->GetController().Reload(true); Hide(); - // WARNING: we are now deleted! + delegate_->OnDontProceed(); + delete this; } void InterstitialPage::CancelForNavigation() { @@ -560,6 +575,14 @@ void InterstitialPage::FocusThroughTabTraversal(bool reverse) { render_view_host_->SetInitialFocus(reverse); } +content::InterstitialPageDelegate* InterstitialPage::GetDelegateForTesting() { + return delegate_.get(); +} + +void InterstitialPage::DontCreateViewForTesting() { + create_view_ = false; +} + content::ViewType InterstitialPage::GetRenderViewType() const { return content::VIEW_TYPE_INTERSTITIAL_PAGE; } diff --git a/content/browser/tab_contents/interstitial_page.h b/content/browser/tab_contents/interstitial_page.h index fcbc6f2..0b29713 100644 --- a/content/browser/tab_contents/interstitial_page.h +++ b/content/browser/tab_contents/interstitial_page.h @@ -22,6 +22,7 @@ class TabContents; namespace content { +class InterstitialPageDelegate; class NavigationEntry; class WebContents; class WebContentsView; @@ -61,15 +62,22 @@ class CONTENT_EXPORT InterstitialPage : public content::NotificationObserver, // added to the navigation controller (so the interstitial page appears as a // new navigation entry). |new_navigation| should be false when the // interstitial was triggered by a loading a sub-resource in a page. + // Takes ownership of |delegate|. + static InterstitialPage* Create(content::WebContents* tab, + bool new_navigation, + const GURL& url, + content::InterstitialPageDelegate* delegate); + InterstitialPage(content::WebContents* tab, bool new_navigation, - const GURL& url); + const GURL& url, + content::InterstitialPageDelegate* delegate); virtual ~InterstitialPage(); // Shows the interstitial page in the tab. - virtual void Show(); + void Show(); - // Hides the interstitial page. Warning: this deletes the InterstitialPage. + // Hides the interstitial page. void Hide(); // Retrieves the InterstitialPage if any associated with the specified @@ -77,12 +85,6 @@ class CONTENT_EXPORT InterstitialPage : public content::NotificationObserver, static InterstitialPage* GetInterstitialPage( content::WebContents* web_contents); - // Sub-classes should return the HTML that should be displayed in the page. - virtual std::string GetHTMLContents(); - - // Invoked when the page sent a command through DOMAutomation. - virtual void CommandReceived(const std::string& command) {} - // Reverts to the page showing before the interstitial. // Sub-classes should call this method when the user has chosen NOT to proceed // to the target URL. @@ -112,16 +114,17 @@ class CONTENT_EXPORT InterstitialPage : public content::NotificationObserver, // Called when tab traversing. void FocusThroughTabTraversal(bool reverse); - virtual content::ViewType GetRenderViewType() const OVERRIDE; - - virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; - // See description above field. void set_reload_on_dont_proceed(bool value) { reload_on_dont_proceed_ = value; } bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; } + RenderViewHost* render_view_host() const { return render_view_host_; } + + content::InterstitialPageDelegate* GetDelegateForTesting(); + void DontCreateViewForTesting(); + protected: // content::NotificationObserver method: virtual void Observe(int type, @@ -148,21 +151,12 @@ class CONTENT_EXPORT InterstitialPage : public content::NotificationObserver, bool* is_keyboard_shortcut) OVERRIDE; virtual void HandleKeyboardEvent( const NativeWebKeyboardEvent& event) OVERRIDE; - - // Invoked with the NavigationEntry that is going to be added to the - // navigation controller. - // Gives an opportunity to sub-classes to set states on the |entry|. - // Note that this is only called if the InterstitialPage was constructed with - // |create_navigation_entry| set to true. - virtual void UpdateEntry(content::NavigationEntry* entry) {} + virtual content::ViewType GetRenderViewType() const OVERRIDE; + virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; bool enabled() const { return enabled_; } content::WebContents* tab() const; const GURL& url() const { return url_; } - RenderViewHost* render_view_host() const { return render_view_host_; } - void set_renderer_preferences(const content::RendererPreferences& prefs) { - renderer_preferences_ = prefs; - } // Creates the RenderViewHost containing the interstitial content. // Overriden in unit tests. @@ -256,7 +250,11 @@ class CONTENT_EXPORT InterstitialPage : public content::NotificationObserver, static InterstitialPageMap* tab_to_interstitial_page_; // Settings passed to the renderer. - content::RendererPreferences renderer_preferences_; + mutable content::RendererPreferences renderer_preferences_; + + bool create_view_; + + scoped_ptr<content::InterstitialPageDelegate> delegate_; DISALLOW_COPY_AND_ASSIGN(InterstitialPage); }; diff --git a/content/browser/tab_contents/tab_contents_unittest.cc b/content/browser/tab_contents/tab_contents_unittest.cc index 7f3cca7..f5c5b59 100644 --- a/content/browser/tab_contents/tab_contents_unittest.cc +++ b/content/browser/tab_contents/tab_contents_unittest.cc @@ -13,6 +13,7 @@ #include "content/browser/tab_contents/navigation_entry_impl.h" #include "content/browser/tab_contents/test_tab_contents.h" #include "content/common/view_messages.h" +#include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" @@ -88,6 +89,20 @@ class TabContentsTestBrowserClient : public content::MockContentBrowserClient { TabContentsTestWebUIControllerFactory factory_; }; +class TestInterstitialPage; + +class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { + public: + TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) + : interstitial_page_(interstitial_page) {} + virtual void CommandReceived(const std::string& command) OVERRIDE; + virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } + virtual void OnDontProceed() OVERRIDE; + virtual void OnProceed() OVERRIDE; + private: + TestInterstitialPage* interstitial_page_; +}; + class TestInterstitialPage : public InterstitialPage { public: enum InterstitialState { @@ -119,7 +134,9 @@ class TestInterstitialPage : public InterstitialPage { const GURL& url, InterstitialState* state, bool* deleted) - : InterstitialPage(tab, new_navigation, url), + : InterstitialPage( + tab, new_navigation, url, + new TestInterstitialPageDelegate(this)), state_(state), deleted_(deleted), command_received_count_(0), @@ -135,15 +152,13 @@ class TestInterstitialPage : public InterstitialPage { delegate_->TestInterstitialPageDeleted(this); } - virtual void DontProceed() { + void OnDontProceed() { if (state_) *state_ = CANCELED; - InterstitialPage::DontProceed(); } - virtual void Proceed() { + void OnProceed() { if (state_) *state_ = OKED; - InterstitialPage::Proceed(); } int command_received_count() const { @@ -152,7 +167,7 @@ class TestInterstitialPage : public InterstitialPage { void TestDomOperationResponse(const std::string& json_string) { if (enabled()) - CommandReceived(json_string); + CommandReceived(); } void TestDidNavigate(int page_id, const GURL& url) { @@ -176,22 +191,23 @@ class TestInterstitialPage : public InterstitialPage { delegate_ = NULL; } + void CommandReceived() { + command_received_count_++; + } + void set_delegate(Delegate* delegate) { delegate_ = delegate; } protected: - virtual RenderViewHost* CreateRenderViewHost() { + virtual RenderViewHost* CreateRenderViewHost() OVERRIDE { return new TestRenderViewHost( SiteInstance::Create(tab()->GetBrowserContext()), this, MSG_ROUTING_NONE); } - virtual content::WebContentsView* CreateWebContentsView() { return NULL; } - - - virtual void CommandReceived(const std::string& command) { - command_received_count_++; + virtual content::WebContentsView* CreateWebContentsView() OVERRIDE { + return NULL; } private: @@ -201,6 +217,18 @@ class TestInterstitialPage : public InterstitialPage { Delegate* delegate_; }; +void TestInterstitialPageDelegate::CommandReceived(const std::string& command) { + interstitial_page_->CommandReceived(); +} + +void TestInterstitialPageDelegate::OnDontProceed() { + interstitial_page_->OnDontProceed(); +} + +void TestInterstitialPageDelegate::OnProceed() { + interstitial_page_->OnProceed(); +} + class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate { public: explicit TestInterstitialPageStateGuard( diff --git a/content/public/browser/interstitial_page_delegate.h b/content/public/browser/interstitial_page_delegate.h new file mode 100644 index 0000000..74e4c4c --- /dev/null +++ b/content/public/browser/interstitial_page_delegate.h @@ -0,0 +1,49 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_DELEGATE_H_ +#define CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_DELEGATE_H_ + +#include <string> + +#include "content/common/content_export.h" + +namespace content { + +class NavigationEntry; +struct RendererPreferences; + +// Controls and provides the html for an interstitial page. The delegate is +// owned by the InterstitialPage. +class InterstitialPageDelegate { + public: + virtual ~InterstitialPageDelegate() {} + + // Return the HTML that should be displayed in the page. + virtual std::string GetHTMLContents() = 0; + + // Called when the interstitial is proceeded or cancelled. Note that this may + // be called by content directly even if the embedder didn't call Proceed or + // DontProceed on InterstitialPage, since navigations etc may cancel them. + virtual void OnProceed() {} + virtual void OnDontProceed() {} + + // Invoked when the page sent a command through DOMAutomation. + virtual void CommandReceived(const std::string& command) {} + + // Invoked with the NavigationEntry that is going to be added to the + // navigation controller. + // Gives an opportunity to delegates to set states on the |entry|. + // Note that this is only called if the InterstitialPage was constructed with + // |new_navigation| set to true. + virtual void OverrideEntry(content::NavigationEntry* entry) {} + + // Allows the delegate to override the renderer preferences structure that's + // sent to the new RenderViewHost. + virtual void OverrideRendererPrefs(content::RendererPreferences* prefs) {} +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_DELEGATE_H_ |