Commit 375fa1b1 authored by fsamuel@chromium.org's avatar fsamuel@chromium.org

Browser Plugin: WebContnets should notify when it's restored

Renamed NOTIFICATION_WEB_CONTENTS_HIDDEN to NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED and
updated all appropriate places. We check for the detail false if we meant to check if the
WebContents is hidden. This matches the behavior of RenderWidget's
NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED.

Added a WasRestored method to WebContents public interface.
Call WasRestored from WebContents::ShowContents

BUG=128814
TEST=did not break existing autofill popup browser test

Review URL: https://chromiumcodereview.appspot.com/10411033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138372 0039d316-1c4b-4281-b951-d872f2087c98
parent 666b38db
...@@ -49,7 +49,7 @@ AutofillPopupView::AutofillPopupView( ...@@ -49,7 +49,7 @@ AutofillPopupView::AutofillPopupView(
return; return;
registrar_.Add(this, registrar_.Add(this,
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<content::WebContents>(web_contents)); content::Source<content::WebContents>(web_contents));
registrar_.Add( registrar_.Add(
this, this,
...@@ -196,7 +196,10 @@ bool AutofillPopupView::HasAutofillEntries() { ...@@ -196,7 +196,10 @@ bool AutofillPopupView::HasAutofillEntries() {
void AutofillPopupView::Observe(int type, void AutofillPopupView::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
|| type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) if (!*content::Details<bool>(details).ptr())
Hide();
} else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
Hide(); Hide();
}
} }
...@@ -80,7 +80,7 @@ IN_PROC_BROWSER_TEST_F(AutofillPopupViewBrowserTest, ...@@ -80,7 +80,7 @@ IN_PROC_BROWSER_TEST_F(AutofillPopupViewBrowserTest,
EXPECT_CALL(*autofill_popup_view_, Hide()).Times(AtLeast(1)); EXPECT_CALL(*autofill_popup_view_, Hide()).Times(AtLeast(1));
ui_test_utils::WindowedNotificationObserver observer( ui_test_utils::WindowedNotificationObserver observer(
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<content::WebContents>(web_contents_)); content::Source<content::WebContents>(web_contents_));
browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
content::PAGE_TRANSITION_START_PAGE); content::PAGE_TRANSITION_START_PAGE);
......
...@@ -56,7 +56,7 @@ class DownloadAnimationWebObserver : public content::NotificationObserver { ...@@ -56,7 +56,7 @@ class DownloadAnimationWebObserver : public content::NotificationObserver {
: owner_(owner), : owner_(owner),
web_contents_(web_contents) { web_contents_(web_contents) {
registrar_.Add(this, registrar_.Add(this,
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<WebContents>(web_contents_)); content::Source<WebContents>(web_contents_));
registrar_.Add(this, registrar_.Add(this,
content::NOTIFICATION_WEB_CONTENTS_DESTROYED, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
...@@ -68,6 +68,11 @@ class DownloadAnimationWebObserver : public content::NotificationObserver { ...@@ -68,6 +68,11 @@ class DownloadAnimationWebObserver : public content::NotificationObserver {
void Observe(int type, void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
bool visible = *content::Details<bool>(details).ptr();
if (visible)
return;
}
// This ends up deleting us. // This ends up deleting us.
[owner_ closeAnimation]; [owner_ closeAnimation];
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "base/message_loop.h" #include "base/message_loop.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
...@@ -106,7 +107,7 @@ DownloadStartedAnimationGtk::DownloadStartedAnimationGtk( ...@@ -106,7 +107,7 @@ DownloadStartedAnimationGtk::DownloadStartedAnimationGtk(
registrar_.Add( registrar_.Add(
this, this,
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<WebContents>(web_contents_)); content::Source<WebContents>(web_contents_));
registrar_.Add( registrar_.Add(
this, this,
...@@ -162,7 +163,7 @@ void DownloadStartedAnimationGtk::Close() { ...@@ -162,7 +163,7 @@ void DownloadStartedAnimationGtk::Close() {
registrar_.Remove( registrar_.Remove(
this, this,
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<WebContents>(web_contents_)); content::Source<WebContents>(web_contents_));
registrar_.Remove( registrar_.Remove(
this, this,
...@@ -196,6 +197,11 @@ void DownloadStartedAnimationGtk::Observe( ...@@ -196,6 +197,11 @@ void DownloadStartedAnimationGtk::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
bool visible = *content::Details<bool>(details).ptr();
if (visible)
return;
}
Close(); Close();
} }
......
...@@ -96,7 +96,7 @@ DownloadStartedAnimationWin::DownloadStartedAnimationWin( ...@@ -96,7 +96,7 @@ DownloadStartedAnimationWin::DownloadStartedAnimationWin(
registrar_.Add( registrar_.Add(
this, this,
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<WebContents>(web_contents_)); content::Source<WebContents>(web_contents_));
registrar_.Add( registrar_.Add(
this, this,
...@@ -143,7 +143,7 @@ void DownloadStartedAnimationWin::Close() { ...@@ -143,7 +143,7 @@ void DownloadStartedAnimationWin::Close() {
registrar_.Remove( registrar_.Remove(
this, this,
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<WebContents>(web_contents_)); content::Source<WebContents>(web_contents_));
registrar_.Remove( registrar_.Remove(
this, this,
...@@ -171,6 +171,11 @@ void DownloadStartedAnimationWin::Observe( ...@@ -171,6 +171,11 @@ void DownloadStartedAnimationWin::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
bool visible = *content::Details<bool>(details).ptr();
if (visible)
return;
}
Close(); Close();
} }
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "content/public/browser/load_notification_details.h" #include "content/public/browser/load_notification_details.h"
#include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_details.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/resource_request_details.h" #include "content/public/browser/resource_request_details.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
...@@ -906,10 +907,19 @@ void WebContentsImpl::WasHidden() { ...@@ -906,10 +907,19 @@ void WebContentsImpl::WasHidden() {
rwhv->WasHidden(); rwhv->WasHidden();
} }
bool is_visible = false;
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
content::NOTIFICATION_WEB_CONTENTS_HIDDEN, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<WebContents>(this), content::Source<WebContents>(this),
content::NotificationService::NoDetails()); content::Details<bool>(&is_visible));
}
void WebContentsImpl::WasRestored() {
bool is_visible = true;
content::NotificationService::current()->Notify(
content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<WebContents>(this),
content::Details<bool>(&is_visible));
} }
void WebContentsImpl::ShowContents() { void WebContentsImpl::ShowContents() {
...@@ -917,6 +927,7 @@ void WebContentsImpl::ShowContents() { ...@@ -917,6 +927,7 @@ void WebContentsImpl::ShowContents() {
RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView()); RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
if (rwhv) if (rwhv)
rwhv->DidBecomeSelected(); rwhv->DidBecomeSelected();
WasRestored();
} }
void WebContentsImpl::HideContents() { void WebContentsImpl::HideContents() {
......
...@@ -187,6 +187,7 @@ class CONTENT_EXPORT WebContentsImpl ...@@ -187,6 +187,7 @@ class CONTENT_EXPORT WebContentsImpl
virtual void DidBecomeSelected() OVERRIDE; virtual void DidBecomeSelected() OVERRIDE;
virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE; virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE;
virtual void WasHidden() OVERRIDE; virtual void WasHidden() OVERRIDE;
virtual void WasRestored() OVERRIDE;
virtual void ShowContents() OVERRIDE; virtual void ShowContents() OVERRIDE;
virtual void HideContents() OVERRIDE; virtual void HideContents() OVERRIDE;
virtual bool NeedToFireBeforeUnload() OVERRIDE; virtual bool NeedToFireBeforeUnload() OVERRIDE;
......
...@@ -212,9 +212,10 @@ enum NotificationType { ...@@ -212,9 +212,10 @@ enum NotificationType {
// is a std::pair<NavigationEntry*, bool> that contains more information. // is a std::pair<NavigationEntry*, bool> that contains more information.
NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
// This notification is sent when a WebContents is being hidden, e.g. due // Indicates a WebContents has been hidden or restored. The source is
// to switching away from this tab. The source is a Source<WebContents>. // a Source<WebContents>. The details is a bool set to true if the new
NOTIFICATION_WEB_CONTENTS_HIDDEN, // state is visible.
NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
// This notification is sent when a WebContents is being destroyed. Any // This notification is sent when a WebContents is being destroyed. Any
// object holding a reference to a WebContents can listen to that // object holding a reference to a WebContents can listen to that
......
...@@ -201,9 +201,11 @@ class WebContents : public PageNavigator { ...@@ -201,9 +201,11 @@ class WebContents : public PageNavigator {
virtual base::TimeTicks GetLastSelectedTime() const = 0; virtual base::TimeTicks GetLastSelectedTime() const = 0;
// Invoked when the WebContents becomes hidden. // Invoked when the WebContents becomes hidden.
// NOTE: If you override this, call the superclass version too!
virtual void WasHidden() = 0; virtual void WasHidden() = 0;
// Invoked when the WebContents is restored.
virtual void WasRestored() = 0;
// TODO(brettw) document these. // TODO(brettw) document these.
virtual void ShowContents() = 0; virtual void ShowContents() = 0;
virtual void HideContents() = 0; virtual void HideContents() = 0;
......
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