OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_EXTERNAL_TAB_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_EXTERNAL_TAB_CONTAINER_H_ |
6 #define CHROME_BROWSER_EXTERNAL_TAB_CONTAINER_H_ | 6 #define CHROME_BROWSER_EXTERNAL_TAB_CONTAINER_H_ |
7 | 7 |
8 #include <atlbase.h> | |
9 #include <atlapp.h> | |
10 #include <atlcrack.h> | |
11 #include <atlmisc.h> | |
12 #include <string> | |
13 | |
14 #include "base/basictypes.h" | |
15 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 8 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
16 #include "chrome/common/chrome_constants.h" | |
17 #include "chrome/common/notification_observer.h" | 9 #include "chrome/common/notification_observer.h" |
18 #include "chrome/common/notification_registrar.h" | 10 #include "chrome/common/notification_registrar.h" |
19 #include "views/focus/focus_manager.h" | 11 #include "views/widget/widget_win.h" |
20 #include "views/widget/root_view.h" | |
21 #include "views/widget/widget.h" | |
22 | 12 |
23 class AutomationProvider; | 13 class AutomationProvider; |
24 class TabContents; | |
25 class Profile; | 14 class Profile; |
26 class TabContentsContainer; | 15 class TabContentsContainer; |
| 16 |
27 // This class serves as the container window for an external tab. | 17 // This class serves as the container window for an external tab. |
28 // An external tab is a Chrome tab that is meant to displayed in an | 18 // An external tab is a Chrome tab that is meant to displayed in an |
29 // external process. This class provides the FocusManger needed by the | 19 // external process. This class provides the FocusManger needed by the |
30 // TabContents as well as an implementation of TabContentsDelagate. | 20 // TabContents as well as an implementation of TabContentsDelagate. |
31 // TODO(beng): Should override WidgetWin instead of Widget. | 21 // TODO(beng): Should override WidgetWin instead of Widget. |
32 class ExternalTabContainer : public TabContentsDelegate, | 22 class ExternalTabContainer : public TabContentsDelegate, |
33 public NotificationObserver, | 23 public NotificationObserver, |
34 public views::Widget, | 24 public views::WidgetWin, |
35 public views::KeystrokeListener, | 25 public views::KeystrokeListener { |
36 public CWindowImpl<ExternalTabContainer, | |
37 CWindow, | |
38 CWinTraits<WS_POPUP | | |
39 WS_CLIPCHILDREN>> { | |
40 public: | 26 public: |
41 BEGIN_MSG_MAP(ExternalTabContainer) | 27 explicit ExternalTabContainer(AutomationProvider* automation); |
42 MESSAGE_HANDLER(WM_SIZE, OnSize) | |
43 MESSAGE_HANDLER(WM_DESTROY, OnDestroy) | |
44 END_MSG_MAP() | |
45 | |
46 DECLARE_WND_CLASS(chrome::kExternalTabWindowClass) | |
47 | |
48 ExternalTabContainer(AutomationProvider* automation); | |
49 ~ExternalTabContainer(); | 28 ~ExternalTabContainer(); |
50 | 29 |
51 TabContents* tab_contents() const { | 30 TabContents* tab_contents() const { return tab_contents_; } |
52 return tab_contents_; | |
53 } | |
54 | 31 |
55 // Temporary hack so we can send notifications back | 32 // Temporary hack so we can send notifications back |
56 void set_tab_handle(int handle) { | 33 void set_tab_handle(int handle) { tab_handle_ = handle; } |
57 tab_handle_ = handle; | |
58 } | |
59 | 34 |
60 bool Init(Profile* profile, HWND parent, const gfx::Rect& dimensions, | 35 bool Init(Profile* profile, |
61 unsigned int style); | 36 HWND parent, |
| 37 const gfx::Rect& bounds, |
| 38 DWORD style); |
62 | 39 |
63 // This function gets called from two places, which is fine. | 40 // Sets the keyboard accelerators needed by the external host |
64 // 1. OnFinalMessage | 41 void SetAccelerators(HACCEL accel_table, int accel_table_entry_count); |
65 // 2. In the destructor. | 42 |
66 bool Uninitialize(HWND window); | 43 // This is invoked when the external host reflects back to us a keyboard |
| 44 // message it did not process |
| 45 void ProcessUnhandledAccelerator(const MSG& msg); |
| 46 |
| 47 // See TabContents::SetInitialFocus. Called from AutomationProvider. |
| 48 void SetInitialFocus(bool reverse); |
| 49 |
| 50 // A helper method that tests whether the given window is an |
| 51 // ExternalTabContainer window |
| 52 static bool IsExternalTabContainer(HWND window); |
| 53 |
| 54 // A helper method that retrieves the ExternalTabContainer object that |
| 55 // hosts the given tab window. |
| 56 static ExternalTabContainer* GetContainerForTab(HWND tab_window); |
67 | 57 |
68 // Overridden from TabContentsDelegate: | 58 // Overridden from TabContentsDelegate: |
69 virtual void OpenURLFromTab(TabContents* source, | 59 virtual void OpenURLFromTab(TabContents* source, |
70 const GURL& url, | 60 const GURL& url, |
71 const GURL& referrer, | 61 const GURL& referrer, |
72 WindowOpenDisposition disposition, | 62 WindowOpenDisposition disposition, |
73 PageTransition::Type transition); | 63 PageTransition::Type transition); |
74 virtual void NavigationStateChanged(const TabContents* source, | 64 virtual void NavigationStateChanged(const TabContents* source, |
75 unsigned changed_flags); | 65 unsigned changed_flags); |
76 virtual void AddNewContents(TabContents* source, | 66 virtual void AddNewContents(TabContents* source, |
77 TabContents* new_contents, | 67 TabContents* new_contents, |
78 WindowOpenDisposition disposition, | 68 WindowOpenDisposition disposition, |
79 const gfx::Rect& initial_pos, | 69 const gfx::Rect& initial_pos, |
80 bool user_gesture); | 70 bool user_gesture); |
81 virtual void ActivateContents(TabContents* contents); | 71 virtual void ActivateContents(TabContents* contents); |
82 virtual void LoadingStateChanged(TabContents* source); | 72 virtual void LoadingStateChanged(TabContents* source); |
83 virtual void CloseContents(TabContents* source); | 73 virtual void CloseContents(TabContents* source); |
84 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); | 74 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); |
85 virtual bool IsPopup(TabContents* source); | 75 virtual bool IsPopup(TabContents* source); |
86 virtual void URLStarredChanged(TabContents* source, bool starred); | 76 virtual void URLStarredChanged(TabContents* source, bool starred); |
87 virtual void UpdateTargetURL(TabContents* source, const GURL& url); | 77 virtual void UpdateTargetURL(TabContents* source, const GURL& url); |
88 virtual void ContentsZoomChange(bool zoom_in); | 78 virtual void ContentsZoomChange(bool zoom_in); |
89 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); | 79 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); |
90 virtual void ForwardMessageToExternalHost(const std::string& message, | 80 virtual void ForwardMessageToExternalHost(const std::string& message, |
91 const std::string& origin, | 81 const std::string& origin, |
92 const std::string& target); | 82 const std::string& target); |
93 virtual bool IsExternalTabContainer() const { | 83 virtual bool IsExternalTabContainer() const { |
94 return true; | 84 return true; |
95 }; | 85 }; |
96 | |
97 // Creates an ExtensionFunctionDispatcher that has no browser | |
98 virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher( | 86 virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher( |
99 RenderViewHost* render_view_host, | 87 RenderViewHost* render_view_host, |
100 const std::string& extension_id); | 88 const std::string& extension_id); |
101 | |
102 virtual bool TakeFocus(bool reverse); | 89 virtual bool TakeFocus(bool reverse); |
103 | 90 |
104 // Notification service callback. | 91 // Overridden from NotificationObserver: |
105 virtual void Observe(NotificationType type, | 92 virtual void Observe(NotificationType type, |
106 const NotificationSource& source, | 93 const NotificationSource& source, |
107 const NotificationDetails& details); | 94 const NotificationDetails& details); |
108 | 95 |
109 ///////////////////////////////////////////////////////////////////////////// | 96 // Overridden from views::KeystrokeListener: |
110 // views::Widget | |
111 ///////////////////////////////////////////////////////////////////////////// | |
112 virtual void GetBounds(gfx::Rect* out, bool including_frame) const; | |
113 virtual void SetBounds(const gfx::Rect& bounds); | |
114 virtual void SetBounds(const gfx::Rect& bounds, | |
115 gfx::NativeWindow other_window); | |
116 virtual void Close(); | |
117 virtual void CloseNow(); | |
118 virtual void Show(); | |
119 virtual void Hide(); | |
120 virtual gfx::NativeView GetNativeView() const; | |
121 virtual void PaintNow(const gfx::Rect& update_rect); | |
122 virtual void SetOpacity(unsigned char opacity); | |
123 virtual views::RootView* GetRootView(); | |
124 virtual Widget* GetRootWidget() const { return NULL; } | |
125 virtual bool IsVisible() const; | |
126 virtual bool IsActive() const; | |
127 virtual bool GetAccelerator(int cmd_id, | |
128 views::Accelerator* accelerator) { | |
129 return false; | |
130 } | |
131 | |
132 // views::KeystrokeListener implementation | |
133 // This method checks whether this key[down|up] message is needed by the | |
134 // external host. If so, it sends it over to the external host | |
135 virtual bool ProcessKeyStroke(HWND window, UINT message, WPARAM wparam, | 97 virtual bool ProcessKeyStroke(HWND window, UINT message, WPARAM wparam, |
136 LPARAM lparam); | 98 LPARAM lparam); |
137 | 99 |
138 // Sets the keyboard accelerators needed by the external host | 100 protected: |
139 void SetAccelerators(HACCEL accel_table, int accel_table_entry_count); | 101 // Overridden from views::WidgetWin: |
| 102 virtual void OnDestroy(); |
140 | 103 |
141 // This is invoked when the external host reflects back to us a keyboard | 104 private: |
142 // message it did not process | 105 // Unhook the keystroke listener and notify about the closing TabContents. |
143 void ProcessUnhandledAccelerator(const MSG& msg); | 106 // This function gets called from two places, which is fine. |
| 107 // 1. OnFinalMessage |
| 108 // 2. In the destructor. |
| 109 void Uninitialize(HWND window); |
144 | 110 |
145 // See TabContents::SetInitialFocus | |
146 void SetInitialFocus(bool reverse); | |
147 | |
148 // A helper method that tests whether the given window is an | |
149 // ExternalTabContainer window | |
150 static bool IsExternalTabContainer(HWND window); | |
151 | |
152 // A helper method that retrieves the ExternalTabContainer object that | |
153 // hosts the given tab window. | |
154 static ExternalTabContainer* GetContainerForTab(HWND tab_window); | |
155 | |
156 protected: | |
157 LRESULT OnSize(UINT, WPARAM, LPARAM, BOOL& handled); | |
158 LRESULT OnDestroy(UINT, WPARAM, LPARAM, BOOL& handled); | |
159 void OnFinalMessage(HWND window); | |
160 | |
161 protected: | |
162 TabContents* tab_contents_; | 111 TabContents* tab_contents_; |
163 scoped_refptr<AutomationProvider> automation_; | 112 scoped_refptr<AutomationProvider> automation_; |
164 | 113 |
165 NotificationRegistrar registrar_; | 114 NotificationRegistrar registrar_; |
166 | 115 |
167 // Root view | |
168 views::RootView root_view_; | |
169 // The accelerator table of the external host. | 116 // The accelerator table of the external host. |
170 HACCEL external_accel_table_; | 117 HACCEL external_accel_table_; |
171 unsigned int external_accel_entry_count_; | 118 unsigned int external_accel_entry_count_; |
172 // A view to handle focus cycling | 119 // A view to handle focus cycling |
173 TabContentsContainer* tab_contents_container_; | 120 TabContentsContainer* tab_contents_container_; |
174 | 121 |
175 private: | |
176 int tab_handle_; | 122 int tab_handle_; |
177 // A failed navigation like a 404 is followed in chrome with a success | 123 // A failed navigation like a 404 is followed in chrome with a success |
178 // navigation for the 404 page. We need to ignore the next navigation | 124 // navigation for the 404 page. We need to ignore the next navigation |
179 // to avoid confusing the clients of the external tab. This member variable | 125 // to avoid confusing the clients of the external tab. This member variable |
180 // is set when we need to ignore the next load notification. | 126 // is set when we need to ignore the next load notification. |
181 bool ignore_next_load_notification_; | 127 bool ignore_next_load_notification_; |
182 | 128 |
183 DISALLOW_COPY_AND_ASSIGN(ExternalTabContainer); | 129 DISALLOW_COPY_AND_ASSIGN(ExternalTabContainer); |
184 }; | 130 }; |
185 | 131 |
186 #endif // CHROME_BROWSER_EXTERNAL_TAB_CONTAINER_H_ | 132 #endif // CHROME_BROWSER_EXTERNAL_TAB_CONTAINER_H_ |
OLD | NEW |