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.
5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_HOST_H_
6 #define CHROME_BROWSER_UI_PANELS_PANEL_HOST_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/extensions/extension_function_dispatcher.h"
11 #include "content/public/browser/web_contents_delegate.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/common/page_zoom.h"
15 class FaviconTabHelper
;
25 namespace extensions
{
26 class WindowController
;
34 // Helper class for Panel, implementing WebContents hosting and Extension
35 // delegates. Owned and used by Panel only.
36 class PanelHost
: public content::WebContentsDelegate
,
37 public content::WebContentsObserver
,
38 public ExtensionFunctionDispatcher::Delegate
{
40 PanelHost(Panel
* panel
, Profile
* profile
);
43 void Init(const GURL
& url
);
44 content::WebContents
* web_contents() { return web_contents_
.get(); }
45 void DestroyWebContents();
47 // Returns the icon for the current page.
48 gfx::Image
GetPageIcon() const;
50 // content::WebContentsDelegate overrides.
51 virtual content::WebContents
* OpenURLFromTab(
52 content::WebContents
* source
,
53 const content::OpenURLParams
& params
) OVERRIDE
;
54 virtual void NavigationStateChanged(const content::WebContents
* source
,
55 unsigned changed_flags
) OVERRIDE
;
56 virtual void AddNewContents(content::WebContents
* source
,
57 content::WebContents
* new_contents
,
58 WindowOpenDisposition disposition
,
59 const gfx::Rect
& initial_pos
,
61 bool* was_blocked
) OVERRIDE
;
62 virtual void ActivateContents(content::WebContents
* contents
) OVERRIDE
;
63 virtual void DeactivateContents(content::WebContents
* contents
) OVERRIDE
;
64 virtual void LoadingStateChanged(content::WebContents
* source
) OVERRIDE
;
65 virtual void CloseContents(content::WebContents
* source
) OVERRIDE
;
66 virtual void MoveContents(content::WebContents
* source
,
67 const gfx::Rect
& pos
) OVERRIDE
;
68 virtual bool IsPopupOrPanel(
69 const content::WebContents
* source
) const OVERRIDE
;
70 virtual void ContentsZoomChange(bool zoom_in
) OVERRIDE
;
71 virtual void HandleKeyboardEvent(
72 content::WebContents
* source
,
73 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
74 virtual void WebContentsFocused(content::WebContents
* contents
) OVERRIDE
;
75 virtual void ResizeDueToAutoResize(content::WebContents
* web_contents
,
76 const gfx::Size
& new_size
) OVERRIDE
;
78 // content::WebContentsObserver overrides.
79 virtual void RenderViewCreated(
80 content::RenderViewHost
* render_view_host
) OVERRIDE
;
81 virtual void RenderProcessGone(base::TerminationStatus status
) OVERRIDE
;
82 virtual void WebContentsDestroyed(
83 content::WebContents
* web_contents
) OVERRIDE
;
84 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
86 // ExtensionFunctionDispatcher::Delegate overrides.
87 virtual extensions::WindowController
* GetExtensionWindowController() const
89 virtual content::WebContents
* GetAssociatedWebContents() const OVERRIDE
;
91 // Actions on web contents.
93 void ReloadIgnoringCache();
95 void Zoom(content::PageZoom zoom
);
98 // Helper to close panel via the message loop.
102 void OnRequest(const ExtensionHostMsg_Request_Params
& params
);
104 Panel
* panel_
; // Weak, owns us.
106 ExtensionFunctionDispatcher extension_function_dispatcher_
;
108 scoped_ptr
<content::WebContents
> web_contents_
;
110 // The following factory is used to close the panel via the message loop.
111 base::WeakPtrFactory
<PanelHost
> weak_factory_
;
113 DISALLOW_COPY_AND_ASSIGN(PanelHost
);
116 #endif // CHROME_BROWSER_UI_PANELS_PANEL_HOST_H_