Home | History | Annotate | Download | only in tab_contents
      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 #ifndef CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_
      6 #define CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "content/public/browser/notification_observer.h"
     12 #include "content/public/browser/notification_registrar.h"
     13 #include "content/public/browser/web_contents_delegate.h"
     14 #include "content/public/browser/web_contents_observer.h"
     15 #include "ui/base/window_open_disposition.h"
     16 
     17 class Profile;
     18 
     19 namespace content {
     20 class SiteInstance;
     21 };
     22 
     23 // This class consumes WebContents. It can host a renderer, but does not
     24 // have any visible display.
     25 class BackgroundContents : public content::WebContentsDelegate,
     26                            public content::WebContentsObserver,
     27                            public content::NotificationObserver {
     28  public:
     29   class Delegate {
     30    public:
     31     // Called by AddNewContents(). Asks the delegate to attach the opened
     32     // WebContents to a suitable container (e.g. browser) or to show it if it's
     33     // a popup window. If |was_blocked| is non-NULL, then |*was_blocked| will be
     34     // set to true if the popup gets blocked, and left unchanged otherwise.
     35     virtual void AddWebContents(content::WebContents* new_contents,
     36                                 WindowOpenDisposition disposition,
     37                                 const gfx::Rect& initial_pos,
     38                                 bool user_gesture,
     39                                 bool* was_blocked) = 0;
     40 
     41    protected:
     42     virtual ~Delegate() {}
     43   };
     44 
     45   BackgroundContents(content::SiteInstance* site_instance,
     46                      int routing_id,
     47                      Delegate* delegate);
     48   virtual ~BackgroundContents();
     49 
     50   content::WebContents* web_contents() const { return web_contents_.get(); }
     51   virtual const GURL& GetURL() const;
     52 
     53   // content::WebContentsDelegate implementation:
     54   virtual void CloseContents(content::WebContents* source) OVERRIDE;
     55   virtual bool ShouldSuppressDialogs() OVERRIDE;
     56   virtual void DidNavigateMainFramePostCommit(
     57       content::WebContents* tab) OVERRIDE;
     58   virtual void AddNewContents(content::WebContents* source,
     59                               content::WebContents* new_contents,
     60                               WindowOpenDisposition disposition,
     61                               const gfx::Rect& initial_pos,
     62                               bool user_gesture,
     63                               bool* was_blocked) OVERRIDE;
     64 
     65   // content::WebContentsObserver implementation:
     66   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
     67 
     68   // content::NotificationObserver
     69   virtual void Observe(int type,
     70                        const content::NotificationSource& source,
     71                        const content::NotificationDetails& details) OVERRIDE;
     72 
     73  protected:
     74   // Exposed for testing.
     75   BackgroundContents();
     76 
     77  private:
     78   // The delegate for this BackgroundContents.
     79   Delegate* delegate_;
     80 
     81   Profile* profile_;
     82   scoped_ptr<content::WebContents> web_contents_;
     83   content::NotificationRegistrar registrar_;
     84 
     85   DISALLOW_COPY_AND_ASSIGN(BackgroundContents);
     86 };
     87 
     88 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED.
     89 struct BackgroundContentsOpenedDetails {
     90   // The BackgroundContents object that has just been opened.
     91   BackgroundContents* contents;
     92 
     93   // The name of the parent frame for these contents.
     94   const string16& frame_name;
     95 
     96   // The ID of the parent application (if any).
     97   const string16& application_id;
     98 };
     99 
    100 #endif  // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_
    101