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