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 "content/public/browser/web_contents_delegate.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/common/page_zoom.h"
13 #include "extensions/browser/extension_function_dispatcher.h"
24 namespace extensions
{
25 class WindowController
;
33 // Helper class for Panel, implementing WebContents hosting and Extension
34 // delegates. Owned and used by Panel only.
35 class PanelHost
: public content::WebContentsDelegate
,
36 public content::WebContentsObserver
,
37 public extensions::ExtensionFunctionDispatcher::Delegate
{
39 PanelHost(Panel
* panel
, Profile
* profile
);
40 ~PanelHost() override
;
42 void Init(const GURL
& url
);
43 content::WebContents
* web_contents() { return web_contents_
.get(); }
44 void DestroyWebContents();
46 // Returns the icon for the current page.
47 gfx::Image
GetPageIcon() const;
49 // content::WebContentsDelegate overrides.
50 content::WebContents
* OpenURLFromTab(
51 content::WebContents
* source
,
52 const content::OpenURLParams
& params
) override
;
53 void NavigationStateChanged(content::WebContents
* source
,
54 content::InvalidateTypes changed_flags
) override
;
55 void AddNewContents(content::WebContents
* source
,
56 content::WebContents
* new_contents
,
57 WindowOpenDisposition disposition
,
58 const gfx::Rect
& initial_rect
,
60 bool* was_blocked
) override
;
61 void ActivateContents(content::WebContents
* contents
) override
;
62 void DeactivateContents(content::WebContents
* contents
) override
;
63 void LoadingStateChanged(content::WebContents
* source
,
64 bool to_different_document
) override
;
65 void CloseContents(content::WebContents
* source
) override
;
66 void MoveContents(content::WebContents
* source
,
67 const gfx::Rect
& pos
) override
;
68 bool IsPopupOrPanel(const content::WebContents
* source
) const override
;
69 void ContentsZoomChange(bool zoom_in
) override
;
70 void HandleKeyboardEvent(
71 content::WebContents
* source
,
72 const content::NativeWebKeyboardEvent
& event
) override
;
73 void ResizeDueToAutoResize(content::WebContents
* web_contents
,
74 const gfx::Size
& new_size
) override
;
76 // content::WebContentsObserver overrides.
77 void RenderProcessGone(base::TerminationStatus status
) override
;
78 void WebContentsDestroyed() override
;
80 // extensions::ExtensionFunctionDispatcher::Delegate overrides.
81 extensions::WindowController
* GetExtensionWindowController() const override
;
82 content::WebContents
* GetAssociatedWebContents() const override
;
84 // Actions on web contents.
86 void ReloadIgnoringCache();
88 void Zoom(content::PageZoom zoom
);
91 // Helper to close panel via the message loop.
94 Panel
* panel_
; // Weak, owns us.
97 scoped_ptr
<content::WebContents
> web_contents_
;
99 // The following factory is used to close the panel via the message loop.
100 base::WeakPtrFactory
<PanelHost
> weak_factory_
;
102 DISALLOW_COPY_AND_ASSIGN(PanelHost
);
105 #endif // CHROME_BROWSER_UI_PANELS_PANEL_HOST_H_