Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_view_host.h
blob84c7a6f3a86a0159c6037159ac184d1276df6ca1
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 "chrome/browser/extensions/extension_host.h"
10 #include "components/web_modal/web_contents_modal_dialog_host.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
13 #if defined(TOOLKIT_VIEWS)
14 #include "chrome/browser/ui/views/extensions/extension_view_views.h"
15 #elif defined(OS_MACOSX)
16 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
17 #elif defined(TOOLKIT_GTK)
18 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
19 #elif defined(OS_ANDROID)
20 #include "chrome/browser/ui/android/extensions/extension_view_android.h"
21 #endif
23 class Browser;
25 namespace content {
26 class SiteInstance;
27 class WebContents;
30 namespace extensions {
32 // The ExtensionHost for an extension that backs a view in the browser UI. For
33 // example, this could be an extension popup, infobar or dialog, but not a
34 // background page.
35 class ExtensionViewHost
36 : public ExtensionHost,
37 public web_modal::WebContentsModalDialogManagerDelegate,
38 public web_modal::WebContentsModalDialogHost {
39 public:
40 ExtensionViewHost(const Extension* extension,
41 content::SiteInstance* site_instance,
42 const GURL& url,
43 ViewType host_type);
44 virtual ~ExtensionViewHost();
46 // TODO(jamescook): Create platform specific subclasses?
47 #if defined(TOOLKIT_VIEWS)
48 typedef ExtensionViewViews PlatformExtensionView;
49 #elif defined(OS_MACOSX)
50 typedef ExtensionViewMac PlatformExtensionView;
51 #elif defined(TOOLKIT_GTK)
52 typedef ExtensionViewGtk PlatformExtensionView;
53 #elif defined(OS_ANDROID)
54 // Android does not support extensions.
55 typedef ExtensionViewAndroid PlatformExtensionView;
56 #endif
58 PlatformExtensionView* view() { return view_.get(); }
60 // Create an ExtensionView and tie it to this host and |browser|. Note NULL
61 // is a valid argument for |browser|. Extension views may be bound to
62 // tab-contents hosted in ExternalTabContainer objects, which do not
63 // instantiate Browser objects.
64 void CreateView(Browser* browser);
66 void SetAssociatedWebContents(content::WebContents* web_contents);
68 // Handles keyboard events that were not handled by HandleKeyboardEvent().
69 // Platform specific implementation may override this method to handle the
70 // event in platform specific way.
71 virtual void UnhandledKeyboardEvent(
72 content::WebContents* source,
73 const content::NativeWebKeyboardEvent& event);
75 // ExtensionHost
76 virtual void OnDidStopLoading() OVERRIDE;
77 virtual void OnDocumentAvailable() OVERRIDE;
78 virtual void LoadInitialURL() OVERRIDE;
79 virtual bool IsBackgroundPage() const OVERRIDE;
81 // content::WebContentsDelegate
82 virtual content::WebContents* OpenURLFromTab(
83 content::WebContents* source,
84 const content::OpenURLParams& params) OVERRIDE;
85 virtual bool PreHandleKeyboardEvent(
86 content::WebContents* source,
87 const content::NativeWebKeyboardEvent& event,
88 bool* is_keyboard_shortcut) OVERRIDE;
89 virtual void HandleKeyboardEvent(
90 content::WebContents* source,
91 const content::NativeWebKeyboardEvent& event) OVERRIDE;
92 virtual content::ColorChooser* OpenColorChooser(
93 content::WebContents* web_contents,
94 SkColor color,
95 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE;
96 virtual void RunFileChooser(
97 content::WebContents* tab,
98 const content::FileChooserParams& params) OVERRIDE;
99 virtual void ResizeDueToAutoResize(content::WebContents* source,
100 const gfx::Size& new_size) OVERRIDE;
102 // content::WebContentsObserver
103 virtual void RenderViewCreated(
104 content::RenderViewHost* render_view_host) OVERRIDE;
106 // web_modal::WebContentsModalDialogManagerDelegate
107 virtual web_modal::WebContentsModalDialogHost*
108 GetWebContentsModalDialogHost() OVERRIDE;
109 virtual bool IsWebContentsVisible(
110 content::WebContents* web_contents) OVERRIDE;
112 // web_modal::WebContentsModalDialogHost
113 virtual gfx::NativeView GetHostView() const OVERRIDE;
114 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
115 virtual gfx::Size GetMaximumDialogSize() OVERRIDE;
116 virtual void AddObserver(
117 web_modal::ModalDialogHostObserver* observer) OVERRIDE;
118 virtual void RemoveObserver(
119 web_modal::ModalDialogHostObserver* observer) OVERRIDE;
121 // ExtensionFunctionDispatcher::Delegate
122 virtual WindowController* GetExtensionWindowController() const OVERRIDE;
123 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
124 virtual content::WebContents* GetVisibleWebContents() const OVERRIDE;
126 // content::NotificationObserver
127 virtual void Observe(int type,
128 const content::NotificationSource& source,
129 const content::NotificationDetails& details) OVERRIDE;
131 private:
132 // Insert a default style sheet for Extension Infobars.
133 void InsertInfobarCSS();
135 // Optional view that shows the rendered content in the UI.
136 scoped_ptr<PlatformExtensionView> view_;
138 // The relevant WebContents associated with this ExtensionViewHost, if any.
139 content::WebContents* associated_web_contents_;
141 // Observer to detect when the associated web contents is destroyed.
142 class AssociatedWebContentsObserver;
143 scoped_ptr<AssociatedWebContentsObserver> associated_web_contents_observer_;
145 DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost);
148 } // namespace extensions
150 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_