OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ |
6 #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // it needs to do. | 76 // it needs to do. |
77 virtual void CloseContents(TabContents* source) = 0; | 77 virtual void CloseContents(TabContents* source) = 0; |
78 | 78 |
79 // Request the delegate to move this tab contents to the specified position | 79 // Request the delegate to move this tab contents to the specified position |
80 // in screen coordinates. | 80 // in screen coordinates. |
81 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) = 0; | 81 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) = 0; |
82 | 82 |
83 // Causes the delegate to detach |source| and clean up any internal data | 83 // Causes the delegate to detach |source| and clean up any internal data |
84 // pointing to it. After this call ownership of |source| passes to the | 84 // pointing to it. After this call ownership of |source| passes to the |
85 // caller, and it is safe to call "source->set_delegate(someone_else);". | 85 // caller, and it is safe to call "source->set_delegate(someone_else);". |
86 virtual void DetachContents(TabContents* source) { } | 86 virtual void DetachContents(TabContents* source); |
87 | 87 |
88 // Called to determine if the TabContents is contained in a popup window. | 88 // Called to determine if the TabContents is contained in a popup window. |
89 virtual bool IsPopup(TabContents* source) = 0; | 89 virtual bool IsPopup(TabContents* source) = 0; |
90 | 90 |
91 // If |source| is constrained, returns the tab containing it. Otherwise | 91 // If |source| is constrained, returns the tab containing it. Otherwise |
92 // returns |source|. | 92 // returns |source|. |
93 virtual TabContents* GetConstrainingContents(TabContents* source) { | 93 virtual TabContents* GetConstrainingContents(TabContents* source); |
94 return source; | |
95 } | |
96 | 94 |
97 // Notification that some of our content has changed size as | 95 // Notification that some of our content has changed size as |
98 // part of an animation. | 96 // part of an animation. |
99 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) = 0; | 97 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) = 0; |
100 | 98 |
101 // Notification that the starredness of the current URL changed. | 99 // Notification that the starredness of the current URL changed. |
102 virtual void URLStarredChanged(TabContents* source, bool starred) = 0; | 100 virtual void URLStarredChanged(TabContents* source, bool starred) = 0; |
103 | 101 |
104 // Notification that the target URL has changed. | 102 // Notification that the target URL has changed. |
105 virtual void UpdateTargetURL(TabContents* source, const GURL& url) = 0; | 103 virtual void UpdateTargetURL(TabContents* source, const GURL& url) = 0; |
106 | 104 |
107 // Notification that there was a mouse event, along with the absolute | 105 // Notification that there was a mouse event, along with the absolute |
108 // coordinates of the mouse pointer and whether it was a normal motion event | 106 // coordinates of the mouse pointer and whether it was a normal motion event |
109 // (otherwise, the pointer left the contents area). | 107 // (otherwise, the pointer left the contents area). |
110 virtual void ContentsMouseEvent( | 108 virtual void ContentsMouseEvent( |
111 TabContents* source, const gfx::Point& location, bool motion) { } | 109 TabContents* source, const gfx::Point& location, bool motion); |
112 | 110 |
113 // Request the delegate to change the zoom level of the current tab. | 111 // Request the delegate to change the zoom level of the current tab. |
114 virtual void ContentsZoomChange(bool zoom_in) { } | 112 virtual void ContentsZoomChange(bool zoom_in); |
115 | 113 |
116 // Notifies the delegate that something has changed about what content the | 114 // Notifies the delegate that something has changed about what content the |
117 // TabContents is blocking. Interested parties should call | 115 // TabContents is blocking. Interested parties should call |
118 // TabContents::IsContentBlocked() to see if something they care about has | 116 // TabContents::IsContentBlocked() to see if something they care about has |
119 // changed. | 117 // changed. |
120 virtual void OnContentSettingsChange(TabContents* source) { } | 118 virtual void OnContentSettingsChange(TabContents* source); |
121 | 119 |
122 // Check whether this contents is inside a window dedicated to running a web | 120 // Check whether this contents is inside a window dedicated to running a web |
123 // application. | 121 // application. |
124 virtual bool IsApplication() const { return false; } | 122 virtual bool IsApplication() const; |
125 | 123 |
126 // Detach the given tab and convert it to a "webapp" view. The tab must be | 124 // Detach the given tab and convert it to a "webapp" view. The tab must be |
127 // a TabContents with a valid WebApp set. | 125 // a TabContents with a valid WebApp set. |
128 virtual void ConvertContentsToApplication(TabContents* source) { } | 126 virtual void ConvertContentsToApplication(TabContents* source); |
129 | 127 |
130 // Whether this tab can be blurred through a javascript obj.blur() | 128 // Whether this tab can be blurred through a javascript obj.blur() |
131 // call. ConstrainedWindows shouldn't be able to be blurred. | 129 // call. ConstrainedWindows shouldn't be able to be blurred. |
132 virtual bool CanBlur() const { return true; } | 130 virtual bool CanBlur() const; |
133 | 131 |
134 // Whether the specified tab can be reloaded. | 132 // Whether the specified tab can be reloaded. |
135 // Reloading can be disabled e. g. for the DevTools window. | 133 // Reloading can be disabled e. g. for the DevTools window. |
136 virtual bool CanReloadContents(TabContents* source) const { return true; } | 134 virtual bool CanReloadContents(TabContents* source) const; |
137 | 135 |
138 // Return the rect where to display the resize corner, if any, otherwise | 136 // Return the rect where to display the resize corner, if any, otherwise |
139 // an empty rect. | 137 // an empty rect. |
140 virtual gfx::Rect GetRootWindowResizerRect() const { return gfx::Rect(); } | 138 virtual gfx::Rect GetRootWindowResizerRect() const; |
141 | 139 |
142 // Show a dialog with HTML content. |delegate| contains a pointer to the | 140 // Show a dialog with HTML content. |delegate| contains a pointer to the |
143 // delegate who knows how to display the dialog (which file URL and JSON | 141 // delegate who knows how to display the dialog (which file URL and JSON |
144 // string input to use during initialization). |parent_window| is the window | 142 // string input to use during initialization). |parent_window| is the window |
145 // that should be parent of the dialog, or NULL for the default. | 143 // that should be parent of the dialog, or NULL for the default. |
146 virtual void ShowHtmlDialog(HtmlDialogUIDelegate* delegate, | 144 virtual void ShowHtmlDialog(HtmlDialogUIDelegate* delegate, |
147 gfx::NativeWindow parent_window) { } | 145 gfx::NativeWindow parent_window); |
148 | 146 |
149 // Tells us that we've finished firing this tab's beforeunload event. | 147 // Tells us that we've finished firing this tab's beforeunload event. |
150 // The proceed bool tells us whether the user chose to proceed closing the | 148 // The proceed bool tells us whether the user chose to proceed closing the |
151 // tab. Returns true if the tab can continue on firing it's unload event. | 149 // tab. Returns true if the tab can continue on firing it's unload event. |
152 // If we're closing the entire browser, then we'll want to delay firing | 150 // If we're closing the entire browser, then we'll want to delay firing |
153 // unload events until all the beforeunload events have fired. | 151 // unload events until all the beforeunload events have fired. |
154 virtual void BeforeUnloadFired(TabContents* tab, | 152 virtual void BeforeUnloadFired(TabContents* tab, |
155 bool proceed, | 153 bool proceed, |
156 bool* proceed_to_fire_unload) { | 154 bool* proceed_to_fire_unload); |
157 *proceed_to_fire_unload = true; | |
158 } | |
159 | 155 |
160 // Send IPC to external host. Default implementation is do nothing. | 156 // Send IPC to external host. Default implementation is do nothing. |
161 virtual void ForwardMessageToExternalHost(const std::string& message, | 157 virtual void ForwardMessageToExternalHost(const std::string& message, |
162 const std::string& origin, | 158 const std::string& origin, |
163 const std::string& target) { | 159 const std::string& target); |
164 } | |
165 | 160 |
166 // If the delegate is hosting tabs externally. | 161 // If the delegate is hosting tabs externally. |
167 virtual bool IsExternalTabContainer() const { return false; } | 162 virtual bool IsExternalTabContainer() const; |
168 | 163 |
169 // Sets focus to the location bar or some other place that is appropriate. | 164 // Sets focus to the location bar or some other place that is appropriate. |
170 // This is called when the tab wants to encourage user input, like for the | 165 // This is called when the tab wants to encourage user input, like for the |
171 // new tab page. | 166 // new tab page. |
172 virtual void SetFocusToLocationBar(bool select_all) {} | 167 virtual void SetFocusToLocationBar(bool select_all); |
173 | 168 |
174 // Called when a popup select is about to be displayed. The delegate can use | 169 // Called when a popup select is about to be displayed. The delegate can use |
175 // this to disable inactive rendering for the frame in the window the select | 170 // this to disable inactive rendering for the frame in the window the select |
176 // is opened within if necessary. | 171 // is opened within if necessary. |
177 virtual void RenderWidgetShowing() {} | 172 virtual void RenderWidgetShowing(); |
178 | 173 |
179 // This is used when the contents is an extension that needs to route | 174 // This is used when the contents is an extension that needs to route |
180 // api calls through to the Browser process. | 175 // api calls through to the Browser process. |
181 virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher( | 176 virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher( |
182 RenderViewHost* render_view_host, | 177 RenderViewHost* render_view_host, |
183 const std::string& extension_id) { | 178 const std::string& extension_id); |
184 return NULL; | |
185 } | |
186 | 179 |
187 // This is called when webkit tells us that it is done tabbing through | 180 // This is called when webkit tells us that it is done tabbing through |
188 // controls on the page. Provides a way for TabContentsDelegates to handle | 181 // controls on the page. Provides a way for TabContentsDelegates to handle |
189 // this. Returns true if the delegate successfully handled it. | 182 // this. Returns true if the delegate successfully handled it. |
190 virtual bool TakeFocus(bool reverse) { | 183 virtual bool TakeFocus(bool reverse); |
191 return false; | |
192 } | |
193 | 184 |
194 // Changes the blocked state of the tab at |index|. TabContents are | 185 // Changes the blocked state of the tab at |index|. TabContents are |
195 // considered blocked while displaying a tab modal dialog. During that time | 186 // considered blocked while displaying a tab modal dialog. During that time |
196 // renderer host will ignore any UI interaction within TabContent outside of | 187 // renderer host will ignore any UI interaction within TabContent outside of |
197 // the currently displaying dialog. | 188 // the currently displaying dialog. |
198 virtual void SetTabContentBlocked(TabContents* contents, bool blocked) { } | 189 virtual void SetTabContentBlocked(TabContents* contents, bool blocked); |
199 | 190 |
200 // Notification that |tab_contents| has gained focus. | 191 // Notification that |tab_contents| has gained focus. |
201 virtual void TabContentsFocused(TabContents* tab_content) { } | 192 virtual void TabContentsFocused(TabContents* tab_content); |
202 | 193 |
203 // Return much extra vertical space should be allotted to the | 194 // Return much extra vertical space should be allotted to the |
204 // render view widget during various animations (e.g. infobar closing). | 195 // render view widget during various animations (e.g. infobar closing). |
205 // This is used to make painting look smoother. | 196 // This is used to make painting look smoother. |
206 virtual int GetExtraRenderViewHeight() const { | 197 virtual int GetExtraRenderViewHeight() const; |
207 return 0; | |
208 } | |
209 | 198 |
210 virtual bool CanDownload(int request_id) { | 199 virtual bool CanDownload(int request_id); |
211 return true; | |
212 } | |
213 | 200 |
214 virtual void OnStartDownload(DownloadItem* download) { | 201 virtual void OnStartDownload(DownloadItem* download); |
215 } | |
216 | 202 |
217 // Returns true if the context menu operation was handled by the delegate. | 203 // Returns true if the context menu operation was handled by the delegate. |
218 virtual bool HandleContextMenu(const ContextMenuParams& params) { | 204 virtual bool HandleContextMenu(const ContextMenuParams& params); |
219 return false; | |
220 } | |
221 | 205 |
222 // Returns true if the context menu command was handled | 206 // Returns true if the context menu command was handled |
223 virtual bool ExecuteContextMenuCommand(int command) { | 207 virtual bool ExecuteContextMenuCommand(int command); |
224 return false; | |
225 } | |
226 | 208 |
227 // Shows a confirmation UI that the specified |template_url| is to be added as | 209 // Shows a confirmation UI that the specified |template_url| is to be added as |
228 // a search engine. | 210 // a search engine. |
229 virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, | 211 virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, |
230 Profile* profile) { | 212 Profile* profile); |
231 } | |
232 | 213 |
233 // Shows the page info using the specified information. | 214 // Shows the page info using the specified information. |
234 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL | 215 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL |
235 // information for that page/frame. If |show_history| is true, a section | 216 // information for that page/frame. If |show_history| is true, a section |
236 // showing how many times that URL has been visited is added to the page info. | 217 // showing how many times that URL has been visited is added to the page info. |
237 virtual void ShowPageInfo(Profile* profile, | 218 virtual void ShowPageInfo(Profile* profile, |
238 const GURL& url, | 219 const GURL& url, |
239 const NavigationEntry::SSLStatus& ssl, | 220 const NavigationEntry::SSLStatus& ssl, |
240 bool show_history) { | 221 bool show_history); |
241 } | |
242 | 222 |
243 // Allows delegates to handle keyboard events before sending to the renderer. | 223 // Allows delegates to handle keyboard events before sending to the renderer. |
244 // Returns true if the |event| was handled. Otherwise, if the |event| would be | 224 // Returns true if the |event| was handled. Otherwise, if the |event| would be |
245 // handled in HandleKeyboardEvent() method as a normal keyboard shortcut, | 225 // handled in HandleKeyboardEvent() method as a normal keyboard shortcut, |
246 // |*is_keyboard_shortcut| should be set to true. | 226 // |*is_keyboard_shortcut| should be set to true. |
247 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 227 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
248 bool* is_keyboard_shortcut) { | 228 bool* is_keyboard_shortcut); |
249 return false; | |
250 } | |
251 | 229 |
252 // Allows delegates to handle unhandled keyboard messages coming back from | 230 // Allows delegates to handle unhandled keyboard messages coming back from |
253 // the renderer. | 231 // the renderer. |
254 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} | 232 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); |
255 | 233 |
256 // Shows the repost form confirmation dialog box. | 234 // Shows the repost form confirmation dialog box. |
257 virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) {} | 235 virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); |
258 | 236 |
259 // Shows the Content Settings dialog for a given content type. | 237 // Shows the Content Settings dialog for a given content type. |
260 virtual void ShowContentSettingsWindow(ContentSettingsType content_type) {} | 238 virtual void ShowContentSettingsWindow(ContentSettingsType content_type); |
261 | 239 |
262 // Allows delegate to override navigation to the history entries. | 240 // Allows delegate to override navigation to the history entries. |
263 // Returns true to allow TabContents to continue with the default processing. | 241 // Returns true to allow TabContents to continue with the default processing. |
264 virtual bool OnGoToEntryOffset(int offset) { | 242 virtual bool OnGoToEntryOffset(int offset); |
265 return true; | |
266 } | |
267 | 243 |
268 // Returns whether this tab contents should add navigations to history. | 244 // Returns whether this tab contents should add navigations to history. |
269 virtual bool ShouldAddNavigationsToHistory() const { return true; } | 245 virtual bool ShouldAddNavigationsToHistory() const; |
270 | 246 |
271 // Notification when web app info data is available | 247 // Notification when web app info data is available |
272 virtual void OnDidGetApplicationInfo(TabContents* tab_contents, | 248 virtual void OnDidGetApplicationInfo(TabContents* tab_contents, |
273 int32 page_id) { | 249 int32 page_id); |
274 } | |
275 | 250 |
276 // Returns the browser in which the tab contents is being displayed. | 251 // Returns the browser in which the tab contents is being displayed. |
277 virtual Browser* GetBrowser() { return NULL; } | 252 virtual Browser* GetBrowser(); |
278 | 253 |
279 // Returns the native window framing the view containing the tab contents. | 254 // Returns the native window framing the view containing the tab contents. |
280 virtual gfx::NativeWindow GetFrameNativeWindow() { return NULL; } | 255 virtual gfx::NativeWindow GetFrameNativeWindow(); |
281 | 256 |
282 // Notifies the delegate about the creation of a new TabContents. This | 257 // Notifies the delegate about the creation of a new TabContents. This |
283 // typically happens when popups are created. | 258 // typically happens when popups are created. |
284 virtual void TabContentsCreated(TabContents* new_contents) {} | 259 virtual void TabContentsCreated(TabContents* new_contents); |
285 | 260 |
286 // Returns whether infobars are enabled. Overrideable by child classes. | 261 // Returns whether infobars are enabled. Overrideable by child classes. |
287 virtual bool infobars_enabled() { return true; } | 262 virtual bool infobars_enabled(); |
288 | 263 |
289 // Whether the renderer should report its preferred size when it changes by | 264 // Whether the renderer should report its preferred size when it changes by |
290 // calling UpdatePreferredSize(). | 265 // calling UpdatePreferredSize(). |
291 // Note that this is set when the RenderViewHost is created and cannot be | 266 // Note that this is set when the RenderViewHost is created and cannot be |
292 // changed after that. | 267 // changed after that. |
293 virtual bool ShouldEnablePreferredSizeNotifications() { return false; } | 268 virtual bool ShouldEnablePreferredSizeNotifications(); |
294 | 269 |
295 // Notification that the preferred size of the contents has changed. | 270 // Notification that the preferred size of the contents has changed. |
296 // Only called if ShouldEnablePreferredSizeNotifications() returns true. | 271 // Only called if ShouldEnablePreferredSizeNotifications() returns true. |
297 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} | 272 virtual void UpdatePreferredSize(const gfx::Size& pref_size); |
298 | 273 |
299 protected: | 274 protected: |
300 ~TabContentsDelegate() {} | 275 ~TabContentsDelegate(); |
301 }; | 276 }; |
302 | 277 |
303 #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ | 278 #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ |
OLD | NEW |