Commit 4bdad24e authored by sky's avatar sky Committed by Commit bot

Makes InfoBarService not close infobars on a reload from browser instant

BrowserInstantController calls Reload() if the google url
changes. This triggers closing the session crashed info bar
prematurely. Seems like we want this for all InfoBars, so I've
centralized the ignore.

BUG=401024
TEST=none
R=pkasting@chromium.org

Review URL: https://codereview.chromium.org/553333006

Cr-Commit-Position: refs/heads/master@{#295546}
parent 317e48ff
......@@ -20,6 +20,16 @@ using infobars::InfoBar;
using infobars::InfoBarDelegate;
using infobars::InfoBarManager;
namespace {
bool IsReload(const content::LoadCommittedDetails& details) {
return content::PageTransitionStripQualifier(
details.entry->GetTransitionType()) == content::PAGE_TRANSITION_RELOAD;
}
} // namespace
// static
InfoBarDelegate::NavigationDetails
InfoBarService::NavigationDetailsFromLoadCommittedDetails(
......@@ -32,9 +42,7 @@ InfoBarDelegate::NavigationDetails
navigation_details.is_main_frame = details.is_main_frame;
const content::PageTransition transition = details.entry->GetTransitionType();
navigation_details.is_reload =
content::PageTransitionStripQualifier(transition) ==
content::PAGE_TRANSITION_RELOAD;
navigation_details.is_reload = IsReload(details);
navigation_details.is_redirect =
(transition & content::PAGE_TRANSITION_IS_REDIRECT_MASK) != 0;
......@@ -51,7 +59,8 @@ content::WebContents* InfoBarService::WebContentsFromInfoBar(InfoBar* infobar) {
}
InfoBarService::InfoBarService(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {
: content::WebContentsObserver(web_contents),
ignore_next_reload_(false) {
DCHECK(web_contents);
}
......@@ -90,9 +99,18 @@ void InfoBarService::RenderProcessGone(base::TerminationStatus status) {
RemoveAllInfoBars(true);
}
void InfoBarService::DidStartNavigationToPendingEntry(
const GURL& url,
content::NavigationController::ReloadType reload_type) {
ignore_next_reload_ = false;
}
void InfoBarService::NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) {
OnNavigation(NavigationDetailsFromLoadCommittedDetails(load_details));
const bool ignore = ignore_next_reload_ && IsReload(load_details);
ignore_next_reload_ = false;
if (!ignore)
OnNavigation(NavigationDetailsFromLoadCommittedDetails(load_details));
}
void InfoBarService::WebContentsDestroyed() {
......
......@@ -37,6 +37,14 @@ class InfoBarService : public infobars::InfoBarManager,
static content::WebContents* WebContentsFromInfoBar(
infobars::InfoBar* infobar);
// Makes it so the next reload is ignored. That is, if the next commit is a
// reload then it is treated as if nothing happened and no infobars are
// attempted to be closed.
// This is useful for non-user triggered reloads that should not dismiss
// infobars. For example, instant may trigger a reload when the google URL
// changes.
void set_ignore_next_reload() { ignore_next_reload_ = true; }
private:
friend class content::WebContentsUserData<InfoBarService>;
......@@ -53,6 +61,9 @@ class InfoBarService : public infobars::InfoBarManager,
// content::WebContentsObserver:
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
virtual void DidStartNavigationToPendingEntry(
const GURL& url,
content::NavigationController::ReloadType reload_type) OVERRIDE;
virtual void NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) OVERRIDE;
virtual void WebContentsDestroyed() OVERRIDE;
......@@ -62,6 +73,8 @@ class InfoBarService : public infobars::InfoBarManager,
void OnDidBlockDisplayingInsecureContent();
void OnDidBlockRunningInsecureContent();
// See description in set_ignore_next_reload().
bool ignore_next_reload_;
DISALLOW_COPY_AND_ASSIGN(InfoBarService);
};
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/browser_instant_controller.h"
#include "base/bind.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h"
......@@ -160,6 +161,13 @@ void BrowserInstantController::DefaultSearchProviderChanged() {
// renderer.
if (!instant_service->IsInstantProcess(rph->GetID()))
continue;
contents->GetController().Reload(false);
// As the reload was not triggered by the user we don't want to close any
// infobars. We have to tell the InfoBarService after the reload, otherwise
// it would ignore this call when
// WebContentsObserver::DidStartNavigationToPendingEntry is invoked.
InfoBarService::FromWebContents(contents)->set_ignore_next_reload();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment