Make the ChromeOS chromecast system tray integration use a private API.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_view_host.h
bloba8c47a8882b96b3b401f52190f44c4c1eb384ab0
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "components/web_modal/web_contents_modal_dialog_host.h"
10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "extensions/browser/extension_host.h"
15 class Browser;
17 namespace content {
18 class SiteInstance;
19 class WebContents;
22 namespace extensions {
24 class ExtensionView;
26 // The ExtensionHost for an extension that backs a view in the browser UI. For
27 // example, this could be an extension popup or dialog, but not a background
28 // page.
29 class ExtensionViewHost
30 : public ExtensionHost,
31 public web_modal::WebContentsModalDialogManagerDelegate,
32 public web_modal::WebContentsModalDialogHost,
33 public content::NotificationObserver {
34 public:
35 ExtensionViewHost(const Extension* extension,
36 content::SiteInstance* site_instance,
37 const GURL& url,
38 ViewType host_type);
39 ~ExtensionViewHost() override;
41 ExtensionView* view() { return view_.get(); }
42 const ExtensionView* view() const { return view_.get(); }
44 // Create an ExtensionView and tie it to this host and |browser|. Note NULL
45 // is a valid argument for |browser|. Extension views may be bound to
46 // tab-contents hosted in ExternalTabContainer objects, which do not
47 // instantiate Browser objects.
48 void CreateView(Browser* browser);
50 void SetAssociatedWebContents(content::WebContents* web_contents);
52 // Handles keyboard events that were not handled by HandleKeyboardEvent().
53 // Platform specific implementation may override this method to handle the
54 // event in platform specific way.
55 virtual void UnhandledKeyboardEvent(
56 content::WebContents* source,
57 const content::NativeWebKeyboardEvent& event);
59 // ExtensionHost
60 void OnDidStopFirstLoad() override;
61 void LoadInitialURL() override;
62 bool IsBackgroundPage() const override;
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;
85 // content::WebContentsObserver
86 void RenderViewCreated(content::RenderViewHost* render_view_host) override;
88 // web_modal::WebContentsModalDialogManagerDelegate
89 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
90 override;
91 bool IsWebContentsVisible(content::WebContents* web_contents) override;
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;
100 // extensions::ExtensionFunctionDispatcher::Delegate
101 WindowController* GetExtensionWindowController() const override;
102 content::WebContents* GetAssociatedWebContents() const override;
103 content::WebContents* GetVisibleWebContents() const override;
105 // content::NotificationObserver
106 void Observe(int type,
107 const content::NotificationSource& source,
108 const content::NotificationDetails& details) override;
110 private:
111 // Implemented per-platform. Create the platform-specific ExtensionView.
112 static scoped_ptr<ExtensionView> CreateExtensionView(ExtensionViewHost* host,
113 Browser* browser);
115 // Optional view that shows the rendered content in the UI.
116 scoped_ptr<ExtensionView> view_;
118 // The relevant WebContents associated with this ExtensionViewHost, if any.
119 content::WebContents* associated_web_contents_;
121 // Observer to detect when the associated web contents is destroyed.
122 class AssociatedWebContentsObserver;
123 scoped_ptr<AssociatedWebContentsObserver> associated_web_contents_observer_;
125 content::NotificationRegistrar registrar_;
127 DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost);
130 } // namespace extensions
132 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_