- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / balloon_host.h
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_NOTIFICATIONS_BALLOON_HOST_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/extensions/extension_function_dispatcher.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/browser/web_contents_observer.h"
17
18 class Balloon;
19 class Browser;
20
21 namespace content {
22 class SiteInstance;
23 };
24
25 class BalloonHost : public content::WebContentsDelegate,
26                     public content::WebContentsObserver,
27                     public ExtensionFunctionDispatcher::Delegate {
28  public:
29   explicit BalloonHost(Balloon* balloon);
30
31   // Initialize the view.
32   void Init();
33
34   // Stops showing the balloon.
35   void Shutdown();
36
37   // ExtensionFunctionDispatcher::Delegate overrides.
38   virtual extensions::WindowController* GetExtensionWindowController()
39       const OVERRIDE;
40   virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
41
42   const string16& GetSource() const;
43
44   content::WebContents* web_contents() const { return web_contents_.get(); }
45
46   // Enable Web UI. This has to be called before renderer is created.
47   void EnableWebUI();
48
49   // Returns whether the associated render view is ready. Used only for testing.
50   bool IsRenderViewReady() const;
51
52   // content::WebContentsDelegate implementation:
53   virtual bool CanLoadDataURLsInWebUI() const OVERRIDE;
54
55  protected:
56   virtual ~BalloonHost();
57
58   scoped_ptr<content::WebContents> web_contents_;
59
60  private:
61   // content::WebContentsDelegate implementation:
62   virtual void CloseContents(content::WebContents* source) OVERRIDE;
63   virtual void HandleMouseDown() OVERRIDE;
64   virtual void ResizeDueToAutoResize(content::WebContents* source,
65                                      const gfx::Size& pref_size) OVERRIDE;
66   virtual void AddNewContents(content::WebContents* source,
67                               content::WebContents* new_contents,
68                               WindowOpenDisposition disposition,
69                               const gfx::Rect& initial_pos,
70                               bool user_gesture,
71                               bool* was_blocked) OVERRIDE;
72
73   // content::WebContentsObserver implementation:
74   virtual void RenderViewCreated(
75       content::RenderViewHost* render_view_host) OVERRIDE;
76   virtual void RenderViewReady() OVERRIDE;
77   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
78   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
79
80   // Message handlers
81   void OnRequest(const ExtensionHostMsg_Request_Params& params);
82
83   // Called to send an event that the balloon has been disconnected from
84   // a renderer (if should_notify_on_disconnect_ is true).
85   void NotifyDisconnect();
86
87   // Non-owned pointer to the associated balloon.
88   Balloon* balloon_;
89
90   // True after Init() has completed.
91   bool initialized_;
92
93   // Indicates whether we should notify about disconnection of this balloon.
94   // This is used to ensure disconnection notifications only happen if
95   // a connection notification has happened and that they happen only once.
96   bool should_notify_on_disconnect_;
97
98   // Site instance for the balloon/profile, to be used for opening new links.
99   scoped_refptr<content::SiteInstance> site_instance_;
100
101   // A flag to enable Web UI.
102   bool enable_web_ui_;
103
104   ExtensionFunctionDispatcher extension_function_dispatcher_;
105 };
106
107 #endif  // CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_