summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/blocked_content/blocked_content_container.h
blob: f6eb7d8b7e6d76da6ba0751ddc8035d0d5f5727e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Defines the public interface for the blocked content (including popup)
// notifications. This interface should only be used by the
// BlockedContentTabHelper. Users and subclasses of WebContents/TabContents
// should use the appropriate methods on BlockedContentTabHelper to access
// information about blocked content.

#ifndef CHROME_BROWSER_UI_BLOCKED_CONTENT_BLOCKED_CONTENT_CONTAINER_H_
#define CHROME_BROWSER_UI_BLOCKED_CONTENT_BLOCKED_CONTENT_CONTAINER_H_

#include <vector>

#include "base/compiler_specific.h"
#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.h"
#include "content/public/browser/web_contents_delegate.h"

class TabContents;

// Takes ownership of TabContentses that are unrequested popup windows.
class BlockedContentContainer : public BlockedContentTabHelperDelegate,
                                public content::WebContentsDelegate {
 public:
  // Creates a container for a certain TabContents:
  explicit BlockedContentContainer(TabContents* owner);
  virtual ~BlockedContentContainer();

  // Adds a TabContents to this container. |bounds| are the window bounds
  // requested for the TabContents.
  void AddTabContents(TabContents* tab_contents,
                      WindowOpenDisposition disposition,
                      const gfx::Rect& bounds,
                      bool user_gesture);

  // Shows the blocked TabContents |tab_contents|.
  void LaunchForContents(TabContents* tab_contents);

  // Returns the number of blocked contents.
  size_t GetBlockedContentsCount() const;

  // Returns the contained TabContents pointers.  |blocked_contents| must
  // be non-NULL.
  void GetBlockedContents(std::vector<TabContents*>* blocked_contents) const;

  // Removes all blocked contents.
  void Clear();

  // Overridden from BlockedContentTabHelperDelegate:
  virtual TabContents* GetConstrainingTabContents(TabContents* source) OVERRIDE;

  // Overridden from content::WebContentsDelegate:

  // Forwards OpenURLFromTab to our |owner_|.
  virtual content::WebContents* OpenURLFromTab(
      content::WebContents* source,
      const content::OpenURLParams& params) OVERRIDE;

  // Forwards AddNewContents to our |owner_|.
  virtual void AddNewContents(content::WebContents* source,
                              content::WebContents* new_contents,
                              WindowOpenDisposition disposition,
                              const gfx::Rect& initial_position,
                              bool user_gesture) OVERRIDE;

  // Removes |source| from our internal list of blocked contents.
  virtual void CloseContents(content::WebContents* source) OVERRIDE;

  // Changes the opening rectangle associated with |source|.
  virtual void MoveContents(content::WebContents* source,
                            const gfx::Rect& new_bounds) OVERRIDE;

  virtual bool IsPopupOrPanel(
      const content::WebContents* source) const OVERRIDE;

  // Always returns true.
  virtual bool ShouldSuppressDialogs() OVERRIDE;

  // Maximum number of blocked contents we allow. No page should really need
  // this many anyway. If reached it typically means there is a compromised
  // renderer.
  static const size_t kImpossibleNumberOfPopups;

 private:
  struct BlockedContent;

  typedef std::vector<BlockedContent> BlockedContents;

  // The TabContents that owns and constrains this BlockedContentContainer.
  TabContents* owner_;

  // Information about all blocked contents.
  BlockedContents blocked_contents_;

  DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedContentContainer);
};

#endif  // CHROME_BROWSER_UI_BLOCKED_CONTENT_BLOCKED_CONTENT_CONTAINER_H_