summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-24 22:36:33 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-24 22:36:33 +0000
commitdb5c20877a4159a01019d183e135e1d713421c09 (patch)
tree968fb9f83527f2de2f7168fcca5b4821a09a7331 /chrome/browser
parent26d7ca2a3b70f96e0571295b0919be152598beaa (diff)
downloadchromium_src-db5c20877a4159a01019d183e135e1d713421c09.zip
chromium_src-db5c20877a4159a01019d183e135e1d713421c09.tar.gz
chromium_src-db5c20877a4159a01019d183e135e1d713421c09.tar.bz2
Stop opening _all_ notification location changes in a new tab. That was allowing unwanted popups from a notification with script that sets window.location=foo.
Instead override some RVHDelegate::View methods to allow popups to be blocked, and new-tab links to open in new tabs; now regular links will navigate the toast. The view methods are implemented using the standard helper. BUG=28015 TEST=none Review URL: http://codereview.chromium.org/434041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/views/notifications/balloon_view_host.cc40
-rw-r--r--chrome/browser/views/notifications/balloon_view_host.h40
2 files changed, 60 insertions, 20 deletions
diff --git a/chrome/browser/views/notifications/balloon_view_host.cc b/chrome/browser/views/notifications/balloon_view_host.cc
index 9bef667..1c467e0 100644
--- a/chrome/browser/views/notifications/balloon_view_host.cc
+++ b/chrome/browser/views/notifications/balloon_view_host.cc
@@ -43,22 +43,6 @@ WebPreferences BalloonViewHost::GetWebkitPrefs() {
return prefs;
}
-RendererPreferences BalloonViewHost::GetRendererPrefs() const {
- // We want links (a.k.a. top_level_requests) to be forwarded to the browser so
- // that we can open them in a new tab rather than in the balloon.
- RendererPreferences prefs = RendererPreferences();
- prefs.browser_handles_top_level_requests = true;
- return prefs;
-}
-
-void BalloonViewHost::RequestOpenURL(const GURL& url,
- const GURL& referrer,
- WindowOpenDisposition disposition) {
- // Always open a link triggered within the notification balloon in a new tab.
- BrowserList::GetLastActive()->AddTabWithURL(url, referrer,
- PageTransition::LINK, true, 0, 0, GetSiteInstance());
-}
-
void BalloonViewHost::Close(RenderViewHost* render_view_host) {
balloon_->CloseByScript();
}
@@ -80,6 +64,30 @@ void BalloonViewHost::RendererGone(RenderViewHost* /* render_view_host */) {
Source<Balloon>(balloon_), NotificationService::NoDetails());
}
+// RenderViewHostDelegate::View methods implemented to allow links to
+// open pages in new tabs.
+void BalloonViewHost::CreateNewWindow(int route_id) {
+ delegate_view_helper_.CreateNewWindow(
+ route_id, balloon_->profile(), site_instance_.get(),
+ DOMUIFactory::GetDOMUIType(balloon_->notification().content_url()), NULL);
+}
+
+void BalloonViewHost::ShowCreatedWindow(int route_id,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ const GURL& creator_url) {
+ // Don't allow pop-ups from notifications.
+ if (disposition == NEW_POPUP)
+ return;
+
+ TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
+ if (contents) {
+ Browser* browser = BrowserList::GetLastActive();
+ browser->AddTabContents(contents, disposition, initial_pos, user_gesture);
+ }
+}
+
void BalloonViewHost::Init(gfx::NativeView parent_hwnd) {
DCHECK(!render_view_host_) << "BalloonViewHost already initialized.";
RenderViewHost* rvh = new RenderViewHost(site_instance_.get(),
diff --git a/chrome/browser/views/notifications/balloon_view_host.h b/chrome/browser/views/notifications/balloon_view_host.h
index 491ba2b..fb9e2e1 100644
--- a/chrome/browser/views/notifications/balloon_view_host.h
+++ b/chrome/browser/views/notifications/balloon_view_host.h
@@ -8,6 +8,7 @@
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/site_instance.h"
+#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
#include "views/controls/native/native_view_host.h"
#include "webkit/glue/webpreferences.h"
@@ -19,7 +20,8 @@ class RenderViewHost;
// the contents of the toast into it. It also handles links within the toast,
// loading them into a new tab.
class BalloonViewHost : public views::NativeViewHost,
- public RenderViewHostDelegate {
+ public RenderViewHostDelegate,
+ public RenderViewHostDelegate::View {
public:
explicit BalloonViewHost(Balloon* balloon);
@@ -32,7 +34,6 @@ class BalloonViewHost : public views::NativeViewHost,
// RenderViewHostDelegate overrides.
virtual WebPreferences GetWebkitPrefs();
- virtual RendererPreferences GetRendererPrefs() const;
virtual SiteInstance* GetSiteInstance() const {
return site_instance_.get();
}
@@ -40,8 +41,6 @@ class BalloonViewHost : public views::NativeViewHost,
virtual const GURL& GetURL() const {
return balloon_->notification().content_url();
}
- virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
- WindowOpenDisposition disposition);
virtual void Close(RenderViewHost* render_view_host);
virtual void RendererReady(RenderViewHost* render_view_host);
virtual void RendererGone(RenderViewHost* render_view_host);
@@ -53,6 +52,36 @@ class BalloonViewHost : public views::NativeViewHost,
virtual ViewType::Type GetRenderViewType() const {
return ViewType::TAB_CONTENTS;
}
+ virtual RenderViewHostDelegate::View* GetViewDelegate() {
+ return this;
+ }
+
+ // RenderViewHostDelegate::View methods. Only the ones for opening new
+ // windows are currently implemented.
+ virtual void CreateNewWindow(int route_id);
+ virtual void CreateNewWidget(int route_id, bool activatable) {}
+ virtual void ShowCreatedWindow(int route_id,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ const GURL& creator_url);
+ virtual void ShowCreatedWidget(int route_id,
+ const gfx::Rect& initial_pos) {}
+ virtual void ShowContextMenu(const ContextMenuParams& params) {}
+ virtual void StartDragging(const WebDropData& drop_data,
+ WebKit::WebDragOperationsMask allowed_ops) {}
+ virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {}
+ virtual void GotFocus() {}
+ virtual void TakeFocus(bool reverse) {}
+ virtual bool IsReservedAccelerator(const NativeWebKeyboardEvent& event) {
+ return false;
+ }
+ virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
+ return false;
+ }
+ virtual void HandleMouseEvent() {}
+ virtual void HandleMouseLeave() {}
+ virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
// Accessors.
RenderViewHost* render_view_host() const { return render_view_host_; }
@@ -87,6 +116,9 @@ class BalloonViewHost : public views::NativeViewHost,
// The title of the balloon page.
std::wstring title_;
+ // Common implementations of some RenderViewHostDelegate::View methods.
+ RenderViewHostDelegateViewHelper delegate_view_helper_;
+
DISALLOW_COPY_AND_ASSIGN(BalloonViewHost);
};