OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_ |
7 | 7 |
8 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | 9 |
| 10 #include "base/scoped_ptr.h" |
| 11 #include "chrome/browser/extensions/extension_host.h" |
| 12 #include "googleurl/src/gurl.h" |
10 #include "skia/include/SkBitmap.h" | 13 #include "skia/include/SkBitmap.h" |
11 | 14 |
12 // TODO(port): Port these files. | 15 // TODO(port): Port these files. |
13 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
14 #include "chrome/browser/views/hwnd_html_view.h" | 17 #include "chrome/views/controls/hwnd_view.h" |
15 #else | 18 #else |
| 19 #include "chrome/views/view.h" |
16 #include "chrome/common/temp_scaffolding_stubs.h" | 20 #include "chrome/common/temp_scaffolding_stubs.h" |
17 #endif | 21 #endif |
18 | 22 |
19 class Browser; | 23 class Browser; |
20 class Extension; | 24 class Extension; |
21 class ExtensionFunctionDispatcher; | |
22 class RenderWidgetHost; | |
23 class RenderWidgetHostView; | |
24 class WebContents; | |
25 struct WebPreferences; | |
26 | 25 |
27 // This class is the browser component of an extension component's RenderView. | 26 // This handles the display portion of an ExtensionHost. |
28 // It handles setting up the renderer process, if needed, with special | 27 class ExtensionView : public views::HWNDView { |
29 // priviliges available to extensions. The view may be drawn to the screen or | |
30 // hidden. | |
31 class ExtensionView : public HWNDHtmlView, | |
32 public RenderViewHostDelegate, | |
33 public RenderViewHostDelegate::View { | |
34 public: | 28 public: |
35 // ExtensionView | 29 ExtensionView(ExtensionHost* host, Browser* browser, const GURL& content_url); |
36 ExtensionView(Extension* extension, | 30 ~ExtensionView(); |
37 const GURL& url, | |
38 SiteInstance* instance, | |
39 Browser* browser); | |
40 | 31 |
41 Extension* extension() { return extension_; } | 32 ExtensionHost* host() const { return host_.get(); } |
| 33 Browser* browser() const { return browser_; } |
| 34 Extension* extension() { return host_->extension(); } |
| 35 RenderViewHost* render_view_host() { return host_->render_view_host(); } |
42 | 36 |
43 // HWNDHtmlView | 37 // Notification from ExtensionHost. |
44 virtual void CreatingRenderer(); | 38 void DidContentsPreferredWidthChange(const int pref_width); |
45 | 39 |
46 virtual void SetBackground(const SkBitmap& background); | 40 // Set a custom background for the view. The background will be tiled. |
| 41 void SetBackground(const SkBitmap& background); |
47 | 42 |
48 // RenderViewHostDelegate | 43 // views::HWNDView |
49 // TODO(mpcomplete): GetProfile is unused. | 44 virtual void SetVisible(bool is_visible); |
50 virtual Profile* GetProfile() const { return NULL; } | 45 virtual void DidChangeBounds(const gfx::Rect& previous, |
51 virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher( | 46 const gfx::Rect& current); |
52 RenderViewHost *render_view_host, | 47 virtual void ViewHierarchyChanged(bool is_add, |
53 const std::string& extension_id); | 48 views::View *parent, views::View *child); |
54 virtual void RenderViewCreated(RenderViewHost* render_view_host); | 49 private: |
55 virtual void DidContentsPreferredWidthChange(const int pref_width); | 50 friend class ExtensionHost; |
56 virtual void DidStopLoading(RenderViewHost* render_view_host); | |
57 virtual WebPreferences GetWebkitPrefs(); | |
58 virtual void RunJavaScriptMessage( | |
59 const std::wstring& message, | |
60 const std::wstring& default_prompt, | |
61 const GURL& frame_url, | |
62 const int flags, | |
63 IPC::Message* reply_msg, | |
64 bool* did_suppress_message); | |
65 virtual void DidStartLoading(RenderViewHost* render_view_host); | |
66 virtual RenderViewHostDelegate::View* GetViewDelegate() const; | |
67 | 51 |
68 // RenderViewHostDelegate::View | |
69 virtual void CreateNewWindow(int route_id, | |
70 base::WaitableEvent* modal_dialog_event); | |
71 virtual void CreateNewWidget(int route_id, bool activatable); | |
72 virtual void ShowCreatedWindow(int route_id, | |
73 WindowOpenDisposition disposition, | |
74 const gfx::Rect& initial_pos, | |
75 bool user_gesture); | |
76 virtual void ShowCreatedWidget(int route_id, | |
77 const gfx::Rect& initial_pos); | |
78 virtual void ShowContextMenu(const ContextMenuParams& params); | |
79 virtual void StartDragging(const WebDropData& drop_data); | |
80 virtual void UpdateDragCursor(bool is_drop_target); | |
81 virtual void TakeFocus(bool reverse); | |
82 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); | |
83 | |
84 private: | |
85 // We wait to show the ExtensionView until several things have loaded. | 52 // We wait to show the ExtensionView until several things have loaded. |
86 void ShowIfCompletelyLoaded(); | 53 void ShowIfCompletelyLoaded(); |
87 | 54 |
88 // The extension that we're hosting in this view. | 55 // The running extension instance that we're displaying. |
89 Extension* extension_; | 56 scoped_ptr<ExtensionHost> host_; |
90 | 57 |
91 // The browser window that this view is in. | 58 // The browser window that this view is in. |
92 Browser* browser_; | 59 Browser* browser_; |
93 | 60 |
94 // Common implementations of some RenderViewHostDelegate::View methods. | 61 // The URL to navigate the host to upon initialization. |
95 RenderViewHostDelegateViewHelper delegate_view_helper_; | 62 GURL content_url_; |
96 | 63 |
97 // Whether the RenderWidget has reported that it has stopped loading. | 64 // True if we've been initialized. |
98 bool did_stop_loading_; | 65 bool initialized_; |
| 66 |
| 67 // The background the view should have once it is initialized. This is set |
| 68 // when the view has a custom background, but hasn't been initialized yet. |
| 69 SkBitmap pending_background_; |
99 | 70 |
100 // What we should set the preferred width to once the ExtensionView has | 71 // What we should set the preferred width to once the ExtensionView has |
101 // loaded. | 72 // loaded. |
102 int pending_preferred_width_; | 73 int pending_preferred_width_; |
103 | 74 |
104 DISALLOW_COPY_AND_ASSIGN(ExtensionView); | 75 DISALLOW_COPY_AND_ASSIGN(ExtensionView); |
105 }; | 76 }; |
106 | 77 |
107 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_ | 78 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_ |
OLD | NEW |