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