Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_view_host.h
1 // Copyright 2013 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_EXTENSIONS_EXTENSION_VIEW_HOST_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "components/web_modal/popup_manager.h"
10 #include "components/web_modal/web_contents_modal_dialog_host.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
12 #include "extensions/browser/extension_host.h"
13
14 class Browser;
15
16 namespace content {
17 class SiteInstance;
18 class WebContents;
19 }
20
21 namespace extensions {
22
23 class ExtensionView;
24
25 // The ExtensionHost for an extension that backs a view in the browser UI. For
26 // example, this could be an extension popup, infobar or dialog, but not a
27 // background page.
28 // TODO(gbillock): See if we can remove WebContentsModalDialogManager here.
29 class ExtensionViewHost
30     : public ExtensionHost,
31       public web_modal::WebContentsModalDialogManagerDelegate,
32       public web_modal::WebContentsModalDialogHost {
33  public:
34   ExtensionViewHost(const Extension* extension,
35                     content::SiteInstance* site_instance,
36                     const GURL& url,
37                     ViewType host_type);
38   ~ExtensionViewHost() override;
39
40   ExtensionView* view() { return view_.get(); }
41   const ExtensionView* view() const { return view_.get(); }
42
43   // Create an ExtensionView and tie it to this host and |browser|.  Note NULL
44   // is a valid argument for |browser|.  Extension views may be bound to
45   // tab-contents hosted in ExternalTabContainer objects, which do not
46   // instantiate Browser objects.
47   void CreateView(Browser* browser);
48
49   void SetAssociatedWebContents(content::WebContents* web_contents);
50
51   // Handles keyboard events that were not handled by HandleKeyboardEvent().
52   // Platform specific implementation may override this method to handle the
53   // event in platform specific way.
54   virtual void UnhandledKeyboardEvent(
55       content::WebContents* source,
56       const content::NativeWebKeyboardEvent& event);
57
58   // ExtensionHost
59   void OnDidStopLoading() override;
60   void OnDocumentAvailable() override;
61   void LoadInitialURL() override;
62   bool IsBackgroundPage() const override;
63
64   // content::WebContentsDelegate
65   content::WebContents* OpenURLFromTab(
66       content::WebContents* source,
67       const content::OpenURLParams& params) override;
68   bool PreHandleKeyboardEvent(content::WebContents* source,
69                               const content::NativeWebKeyboardEvent& event,
70                               bool* is_keyboard_shortcut) override;
71   void HandleKeyboardEvent(
72       content::WebContents* source,
73       const content::NativeWebKeyboardEvent& event) override;
74   bool PreHandleGestureEvent(content::WebContents* source,
75                              const blink::WebGestureEvent& event) override;
76   content::ColorChooser* OpenColorChooser(
77       content::WebContents* web_contents,
78       SkColor color,
79       const std::vector<content::ColorSuggestion>& suggestions) override;
80   void RunFileChooser(content::WebContents* tab,
81                       const content::FileChooserParams& params) override;
82   void ResizeDueToAutoResize(content::WebContents* source,
83                              const gfx::Size& new_size) override;
84
85   // content::WebContentsObserver
86   void RenderViewCreated(content::RenderViewHost* render_view_host) override;
87
88   // web_modal::WebContentsModalDialogManagerDelegate
89   web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
90       override;
91   bool IsWebContentsVisible(content::WebContents* web_contents) override;
92
93   // web_modal::WebContentsModalDialogHost
94   gfx::NativeView GetHostView() const override;
95   gfx::Point GetDialogPosition(const gfx::Size& size) override;
96   gfx::Size GetMaximumDialogSize() override;
97   void AddObserver(web_modal::ModalDialogHostObserver* observer) override;
98   void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override;
99
100   // extensions::ExtensionFunctionDispatcher::Delegate
101   WindowController* GetExtensionWindowController() const override;
102   content::WebContents* GetAssociatedWebContents() const override;
103   content::WebContents* GetVisibleWebContents() const override;
104
105   // content::NotificationObserver
106   void Observe(int type,
107                const content::NotificationSource& source,
108                const content::NotificationDetails& details) override;
109
110  private:
111   // Implemented per-platform. Create the platform-specific ExtensionView.
112   static scoped_ptr<ExtensionView> CreateExtensionView(ExtensionViewHost* host,
113                                                        Browser* browser);
114
115   // Insert a default style sheet for Extension Infobars.
116   void InsertInfobarCSS();
117
118   // Optional view that shows the rendered content in the UI.
119   scoped_ptr<ExtensionView> view_;
120
121   // The relevant WebContents associated with this ExtensionViewHost, if any.
122   content::WebContents* associated_web_contents_;
123
124   // Observer to detect when the associated web contents is destroyed.
125   class AssociatedWebContentsObserver;
126   scoped_ptr<AssociatedWebContentsObserver> associated_web_contents_observer_;
127
128   // Manage popups overlaying the WebContents in this EVH.
129   // TODO(gbillock): should usually not be used -- instead use the parent
130   // window's popup manager. Should only be used when the EVH is created without
131   // a parent window.
132   scoped_ptr<web_modal::PopupManager> popup_manager_;
133
134   DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost);
135 };
136
137 }  // namespace extensions
138
139 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_