blocked_content_container.h revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Defines the public interface for the blocked content (including popup) 6// notifications. This interface should only be used by TabContents. Users and 7// subclasses of TabContents should use the appropriate methods on TabContents 8// to access information about blocked content. 9 10#ifndef CHROME_BROWSER_BLOCKED_CONTENT_CONTAINER_H_ 11#define CHROME_BROWSER_BLOCKED_CONTENT_CONTAINER_H_ 12#pragma once 13 14#include <vector> 15 16#include "chrome/browser/tab_contents/tab_contents_delegate.h" 17 18// Takes ownership of TabContents that are unrequested popup windows. 19class BlockedContentContainer : public TabContentsDelegate { 20 public: 21 // Creates a container for a certain TabContents: 22 explicit BlockedContentContainer(TabContents* owner); 23 virtual ~BlockedContentContainer(); 24 25 // Adds a TabContents to this container. |bounds| are the window bounds 26 // requested for the TabContents. 27 void AddTabContents(TabContents* tab_contents, 28 WindowOpenDisposition disposition, 29 const gfx::Rect& bounds, 30 bool user_gesture); 31 32 // Shows the blocked TabContents |tab_contents|. 33 void LaunchForContents(TabContents* tab_contents); 34 35 // Returns the number of blocked contents. 36 size_t GetBlockedContentsCount() const; 37 38 // Returns the contained TabContents pointers. |blocked_contents| must be 39 // non-NULL. 40 void GetBlockedContents(std::vector<TabContents*>* blocked_contents) const; 41 42 // Sets this object up to delete itself. 43 void Destroy(); 44 45 // Overridden from TabContentsDelegate: 46 47 // Forwards OpenURLFromTab to our |owner_|. 48 virtual void OpenURLFromTab(TabContents* source, 49 const GURL& url, const GURL& referrer, 50 WindowOpenDisposition disposition, 51 PageTransition::Type transition); 52 53 // Ignored; BlockedContentContainer doesn't display a throbber. 54 virtual void NavigationStateChanged(const TabContents* source, 55 unsigned changed_flags) {} 56 57 // Forwards AddNewContents to our |owner_|. 58 virtual void AddNewContents(TabContents* source, 59 TabContents* new_contents, 60 WindowOpenDisposition disposition, 61 const gfx::Rect& initial_position, 62 bool user_gesture); 63 64 // Ignore activation/deactivation requests from the TabContents we're 65 // blocking. 66 virtual void ActivateContents(TabContents* contents) {} 67 virtual void DeactivateContents(TabContents* contents) {} 68 69 // Ignored; BlockedContentContainer doesn't display a throbber. 70 virtual void LoadingStateChanged(TabContents* source) {} 71 72 // Removes |source| from our internal list of blocked contents. 73 virtual void CloseContents(TabContents* source); 74 75 // Changes the opening rectangle associated with |source|. 76 virtual void MoveContents(TabContents* source, const gfx::Rect& new_bounds); 77 78 // Always returns true. 79 virtual bool IsPopup(const TabContents* source) const; 80 81 // Returns our |owner_|. 82 virtual TabContents* GetConstrainingContents(TabContents* source); 83 84 // Ignored; BlockedContentContainer doesn't display a toolbar. 85 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} 86 87 // Ignored; BlockedContentContainer doesn't display a URL bar. 88 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} 89 90 // Maximum number of blocked contents we allow. No page should really need 91 // this many anyway. If reached it typically means there is a compromised 92 // renderer. 93 static const size_t kImpossibleNumberOfPopups; 94 95 private: 96 struct BlockedContent; 97 98 typedef std::vector<BlockedContent> BlockedContents; 99 100 // The TabContents that owns and constrains this BlockedContentContainer. 101 TabContents* owner_; 102 103 // Information about all blocked contents. 104 BlockedContents blocked_contents_; 105 106 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedContentContainer); 107}; 108 109#endif // CHROME_BROWSER_BLOCKED_CONTENT_CONTAINER_H_ 110