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

Unified Diff: content/browser/tab_contents/interstitial_page.cc

Issue 9323071: Use InterstitialPage through a delegate interface instead of deriving from it. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix tests Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/tab_contents/interstitial_page.cc
===================================================================
--- content/browser/tab_contents/interstitial_page.cc (revision 120576)
+++ content/browser/tab_contents/interstitial_page.cc (working copy)
@@ -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 @@
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 @@
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() {
- 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() {
@@ -199,8 +206,8 @@
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 +217,7 @@
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 +267,10 @@
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 +313,14 @@
// 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 +426,7 @@
content::RendererPreferences InterstitialPage::GetRendererPrefs(
content::BrowserContext* browser_context) const {
+ delegate_->OverrideRendererPrefs(&renderer_preferences_);
return renderer_preferences_;
}
@@ -446,6 +457,8 @@
}
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 +499,12 @@
// 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 +535,8 @@
tab_->GetController().Reload(true);
Hide();
- // WARNING: we are now deleted!
+ delegate_->OnDontProceed();
+ delete this;
}
void InterstitialPage::CancelForNavigation() {
@@ -560,6 +574,14 @@
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;
}

Powered by Google App Engine
This is Rietveld 408576698