Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / panels / panel_host.h
blob1a1a27463766b90a989ffd210a8de0fa52564f93
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"
15 class FaviconTabHelper;
16 class GURL;
17 class Panel;
18 class PrefsTabHelper;
19 class Profile;
21 namespace content {
22 class WebContents;
25 namespace extensions {
26 class WindowController;
29 namespace gfx {
30 class Image;
31 class Rect;
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 extensions::ExtensionFunctionDispatcher::Delegate {
39 public:
40 PanelHost(Panel* panel, Profile* profile);
41 virtual ~PanelHost();
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(
55 const content::WebContents* source,
56 content::InvalidateTypes changed_flags) override;
57 virtual void AddNewContents(content::WebContents* source,
58 content::WebContents* new_contents,
59 WindowOpenDisposition disposition,
60 const gfx::Rect& initial_pos,
61 bool user_gesture,
62 bool* was_blocked) override;
63 virtual void ActivateContents(content::WebContents* contents) override;
64 virtual void DeactivateContents(content::WebContents* contents) override;
65 virtual void LoadingStateChanged(content::WebContents* source,
66 bool to_different_document) override;
67 virtual void CloseContents(content::WebContents* source) override;
68 virtual void MoveContents(content::WebContents* source,
69 const gfx::Rect& pos) override;
70 virtual bool IsPopupOrPanel(
71 const content::WebContents* source) const override;
72 virtual void ContentsZoomChange(bool zoom_in) override;
73 virtual void HandleKeyboardEvent(
74 content::WebContents* source,
75 const content::NativeWebKeyboardEvent& event) override;
76 virtual void WebContentsFocused(content::WebContents* contents) override;
77 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
78 const gfx::Size& new_size) override;
80 // content::WebContentsObserver overrides.
81 virtual void RenderViewCreated(
82 content::RenderViewHost* render_view_host) override;
83 virtual void RenderProcessGone(base::TerminationStatus status) override;
84 virtual void WebContentsDestroyed() override;
85 virtual bool OnMessageReceived(const IPC::Message& message) override;
87 // extensions::ExtensionFunctionDispatcher::Delegate overrides.
88 virtual extensions::WindowController* GetExtensionWindowController() const
89 override;
90 virtual content::WebContents* GetAssociatedWebContents() const override;
92 // Actions on web contents.
93 void Reload();
94 void ReloadIgnoringCache();
95 void StopLoading();
96 void Zoom(content::PageZoom zoom);
98 private:
99 // Helper to close panel via the message loop.
100 void ClosePanel();
102 // Message handlers.
103 void OnRequest(const ExtensionHostMsg_Request_Params& params);
105 Panel* panel_; // Weak, owns us.
106 Profile* profile_;
107 extensions::ExtensionFunctionDispatcher extension_function_dispatcher_;
109 scoped_ptr<content::WebContents> web_contents_;
111 // The following factory is used to close the panel via the message loop.
112 base::WeakPtrFactory<PanelHost> weak_factory_;
114 DISALLOW_COPY_AND_ASSIGN(PanelHost);
117 #endif // CHROME_BROWSER_UI_PANELS_PANEL_HOST_H_