Home | History | Annotate | Download | only in blocked_content
      1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_BLOCKED_CONTENT_BLOCKED_CONTENT_TAB_HELPER_H_
      6 #define CHROME_BROWSER_UI_BLOCKED_CONTENT_BLOCKED_CONTENT_TAB_HELPER_H_
      7 
      8 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
      9 #include "chrome/browser/ui/find_bar/find_notification_details.h"
     10 #include "content/public/browser/notification_registrar.h"
     11 #include "content/public/browser/web_contents_observer.h"
     12 #include "content/public/browser/web_contents_user_data.h"
     13 #include "ui/base/window_open_disposition.h"
     14 
     15 class BlockedContentContainer;
     16 class BlockedContentTabHelperDelegate;
     17 
     18 // Per-tab class to manage blocked popups.
     19 class BlockedContentTabHelper
     20     : public content::WebContentsObserver,
     21       public content::WebContentsUserData<BlockedContentTabHelper> {
     22  public:
     23   virtual ~BlockedContentTabHelper();
     24 
     25   BlockedContentTabHelperDelegate* delegate() const { return delegate_; }
     26   void set_delegate(BlockedContentTabHelperDelegate* d) { delegate_ = d; }
     27 
     28   // Sets whether all WebContents added by way of |AddNewContents| should be
     29   // blocked. Transitioning from all blocked to not all blocked results in
     30   // reevaluating any blocked WebContentses, which may result in unblocking some
     31   // of the blocked WebContentses.
     32   void SetAllContentsBlocked(bool value);
     33 
     34   bool all_contents_blocked() const { return all_contents_blocked_; }
     35 
     36   // Adds the incoming |new_contents| to the |blocked_contents_| container.
     37   void AddWebContents(content::WebContents* new_contents,
     38                       WindowOpenDisposition disposition,
     39                       const gfx::Rect& initial_pos,
     40                       bool user_gesture);
     41 
     42   // Adds the incoming |new_contents| to the |blocked_contents_| container.
     43   void AddPopup(content::WebContents* new_contents,
     44                 WindowOpenDisposition disposition,
     45                 const gfx::Rect& initial_pos,
     46                 bool user_gesture);
     47 
     48   // Shows the blocked WebContents |web_contents|.
     49   void LaunchForContents(content::WebContents* web_contents);
     50 
     51   // Returns the number of blocked contents.
     52   size_t GetBlockedContentsCount() const;
     53 
     54   // Returns the blocked WebContentses.  |blocked_contents| must be non-NULL.
     55   void GetBlockedContents(
     56       std::vector<content::WebContents*>* blocked_contents) const;
     57 
     58   // content::WebContentsObserver overrides:
     59   virtual void DidNavigateMainFrame(
     60       const content::LoadCommittedDetails& details,
     61       const content::FrameNavigateParams& params) OVERRIDE;
     62 
     63  private:
     64   explicit BlockedContentTabHelper(content::WebContents* web_contents);
     65   friend class content::WebContentsUserData<BlockedContentTabHelper>;
     66 
     67   // Called when the blocked popup notification is shown or hidden.
     68   void PopupNotificationVisibilityChanged(bool visible);
     69 
     70   // Called to notify any observers that |contents| is entering or leaving
     71   // the blocked state.
     72   void SendNotification(content::WebContents* contents, bool blocked_state);
     73 
     74   // Object that holds any blocked WebContentses spawned from this WebContents.
     75   scoped_ptr<BlockedContentContainer> blocked_contents_;
     76 
     77   // Should we block all child WebContentses this attempts to spawn.
     78   bool all_contents_blocked_;
     79 
     80   // Delegate for notifying our owner (usually Browser) about stuff. Not owned
     81   // by us.
     82   BlockedContentTabHelperDelegate* delegate_;
     83 
     84   DISALLOW_COPY_AND_ASSIGN(BlockedContentTabHelper);
     85 };
     86 
     87 #endif  // CHROME_BROWSER_UI_BLOCKED_CONTENT_BLOCKED_CONTENT_TAB_HELPER_H_
     88