| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_DELEGATE_H_ | |
| 6 #define CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_DELEGATE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/i18n/rtl.h" | |
| 13 #include "base/process_util.h" | |
| 14 #include "base/string16.h" | |
| 15 #include "content/common/content_export.h" | |
| 16 #include "ipc/ipc_channel.h" | |
| 17 #include "net/base/load_states.h" | |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" | |
| 19 #include "ui/base/javascript_message_type.h" | |
| 20 #include "webkit/glue/window_open_disposition.h" | |
| 21 | |
| 22 class GURL; | |
| 23 class SkBitmap; | |
| 24 class WebContentsImpl; | |
| 25 class WebKeyboardEvent; | |
| 26 struct ViewHostMsg_CreateWindow_Params; | |
| 27 struct ViewHostMsg_DidFailProvisionalLoadWithError_Params; | |
| 28 struct ViewHostMsg_FrameNavigate_Params; | |
| 29 struct ViewMsg_PostMessage_Params; | |
| 30 | |
| 31 namespace webkit_glue { | |
| 32 struct WebPreferences; | |
| 33 } | |
| 34 | |
| 35 namespace base { | |
| 36 class ListValue; | |
| 37 class TimeTicks; | |
| 38 } | |
| 39 | |
| 40 namespace gfx { | |
| 41 class Point; | |
| 42 class Rect; | |
| 43 class Size; | |
| 44 } | |
| 45 | |
| 46 namespace content { | |
| 47 | |
| 48 class BrowserContext; | |
| 49 class RenderViewHost; | |
| 50 class RenderViewHostDelegateView; | |
| 51 class WebContents; | |
| 52 struct ContextMenuParams; | |
| 53 struct FileChooserParams; | |
| 54 struct GlobalRequestID; | |
| 55 struct NativeWebKeyboardEvent; | |
| 56 struct Referrer; | |
| 57 struct RendererPreferences; | |
| 58 | |
| 59 // | |
| 60 // RenderViewHostDelegate | |
| 61 // | |
| 62 // An interface implemented by an object interested in knowing about the state | |
| 63 // of the RenderViewHost. | |
| 64 // | |
| 65 // This interface currently encompasses every type of message that was | |
| 66 // previously being sent by WebContents itself. Some of these notifications | |
| 67 // may not be relevant to all users of RenderViewHost and we should consider | |
| 68 // exposing a more generic Send function on RenderViewHost and a response | |
| 69 // listener here to serve that need. | |
| 70 // | |
| 71 // TODO(joi): See if we can hide most or all of this from chrome/. | |
| 72 class CONTENT_EXPORT RenderViewHostDelegate : public IPC::Channel::Listener { | |
| 73 public: | |
| 74 // RendererManagerment ------------------------------------------------------- | |
| 75 // Functions for managing switching of Renderers. For WebContents, this is | |
| 76 // implemented by the RenderViewHostManager. | |
| 77 | |
| 78 class CONTENT_EXPORT RendererManagement { | |
| 79 public: | |
| 80 // Notification whether we should close the page, after an explicit call to | |
| 81 // AttemptToClosePage. This is called before a cross-site request or before | |
| 82 // a tab/window is closed (as indicated by the first parameter) to allow the | |
| 83 // appropriate renderer to approve or deny the request. |proceed| indicates | |
| 84 // whether the user chose to proceed. |proceed_time| is the time when the | |
| 85 // request was allowed to proceed. | |
| 86 virtual void ShouldClosePage( | |
| 87 bool for_cross_site_transition, | |
| 88 bool proceed, | |
| 89 const base::TimeTicks& proceed_time) = 0; | |
| 90 | |
| 91 // Called by ResourceDispatcherHost when a response for a pending cross-site | |
| 92 // request is received. The ResourceDispatcherHost will pause the response | |
| 93 // until the onunload handler of the previous renderer is run. | |
| 94 virtual void OnCrossSiteResponse(int new_render_process_host_id, | |
| 95 int new_request_id) = 0; | |
| 96 | |
| 97 protected: | |
| 98 virtual ~RendererManagement() {} | |
| 99 }; | |
| 100 | |
| 101 // --------------------------------------------------------------------------- | |
| 102 | |
| 103 // Returns the current delegate associated with a feature. May return NULL if | |
| 104 // there is no corresponding delegate. | |
| 105 virtual RenderViewHostDelegateView* GetDelegateView(); | |
| 106 virtual RendererManagement* GetRendererManagementDelegate(); | |
| 107 | |
| 108 // IPC::Channel::Listener implementation. | |
| 109 // This is used to give the delegate a chance to filter IPC messages. | |
| 110 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 111 | |
| 112 // Gets the URL that is currently being displayed, if there is one. | |
| 113 virtual const GURL& GetURL() const; | |
| 114 | |
| 115 // Return this object cast to a WebContents, if it is one. If the object is | |
| 116 // not a WebContents, returns NULL. DEPRECATED: Be sure to include brettw or | |
| 117 // jam as reviewers before you use this method. http://crbug.com/82582 | |
| 118 virtual content::WebContents* GetAsWebContents(); | |
| 119 | |
| 120 // Return the rect where to display the resize corner, if any, otherwise | |
| 121 // an empty rect. | |
| 122 virtual gfx::Rect GetRootWindowResizerRect() const = 0; | |
| 123 | |
| 124 // The RenderView is being constructed (message sent to the renderer process | |
| 125 // to construct a RenderView). Now is a good time to send other setup events | |
| 126 // to the RenderView. This precedes any other commands to the RenderView. | |
| 127 virtual void RenderViewCreated(RenderViewHost* render_view_host) {} | |
| 128 | |
| 129 // The RenderView has been constructed. | |
| 130 virtual void RenderViewReady(RenderViewHost* render_view_host) {} | |
| 131 | |
| 132 // The RenderView died somehow (crashed or was killed by the user). | |
| 133 virtual void RenderViewGone(RenderViewHost* render_view_host, | |
| 134 base::TerminationStatus status, | |
| 135 int error_code) {} | |
| 136 | |
| 137 // The RenderView is going to be deleted. This is called when each | |
| 138 // RenderView is going to be destroyed | |
| 139 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {} | |
| 140 | |
| 141 // The RenderView started a provisional load for a given frame. | |
| 142 virtual void DidStartProvisionalLoadForFrame( | |
| 143 content::RenderViewHost* render_view_host, | |
| 144 int64 frame_id, | |
| 145 bool main_frame, | |
| 146 const GURL& opener_url, | |
| 147 const GURL& url) {} | |
| 148 | |
| 149 // The RenderView processed a redirect during a provisional load. | |
| 150 // | |
| 151 // TODO(creis): Remove this method and have the pre-rendering code listen to | |
| 152 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification | |
| 153 // instead. See http://crbug.com/78512. | |
| 154 virtual void DidRedirectProvisionalLoad( | |
| 155 content::RenderViewHost* render_view_host, | |
| 156 int32 page_id, | |
| 157 const GURL& opener_url, | |
| 158 const GURL& source_url, | |
| 159 const GURL& target_url) {} | |
| 160 | |
| 161 // A provisional load in the RenderView failed. | |
| 162 virtual void DidFailProvisionalLoadWithError( | |
| 163 content::RenderViewHost* render_view_host, | |
| 164 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {} | |
| 165 | |
| 166 // The RenderView was navigated to a different page. | |
| 167 virtual void DidNavigate(RenderViewHost* render_view_host, | |
| 168 const ViewHostMsg_FrameNavigate_Params& params) {} | |
| 169 | |
| 170 // The state for the page changed and should be updated. | |
| 171 virtual void UpdateState(RenderViewHost* render_view_host, | |
| 172 int32 page_id, | |
| 173 const std::string& state) {} | |
| 174 | |
| 175 // The page's title was changed and should be updated. | |
| 176 virtual void UpdateTitle(RenderViewHost* render_view_host, | |
| 177 int32 page_id, | |
| 178 const string16& title, | |
| 179 base::i18n::TextDirection title_direction) {} | |
| 180 | |
| 181 // The page's encoding was changed and should be updated. | |
| 182 virtual void UpdateEncoding(RenderViewHost* render_view_host, | |
| 183 const std::string& encoding) {} | |
| 184 | |
| 185 // The destination URL has changed should be updated | |
| 186 virtual void UpdateTargetURL(int32 page_id, const GURL& url) {} | |
| 187 | |
| 188 // The page is trying to close the RenderView's representation in the client. | |
| 189 virtual void Close(RenderViewHost* render_view_host) {} | |
| 190 | |
| 191 // The RenderViewHost has been swapped out. | |
| 192 virtual void SwappedOut(RenderViewHost* render_view_host) {} | |
| 193 | |
| 194 // The page is trying to move the RenderView's representation in the client. | |
| 195 virtual void RequestMove(const gfx::Rect& new_bounds) {} | |
| 196 | |
| 197 // The RenderView began loading a new page. This corresponds to WebKit's | |
| 198 // notion of the throbber starting. | |
| 199 virtual void DidStartLoading() {} | |
| 200 | |
| 201 // The RenderView stopped loading a page. This corresponds to WebKit's | |
| 202 // notion of the throbber stopping. | |
| 203 virtual void DidStopLoading() {} | |
| 204 | |
| 205 // The pending page load was canceled. | |
| 206 virtual void DidCancelLoading() {} | |
| 207 | |
| 208 // The RenderView made progress loading a page's top frame. | |
| 209 // |progress| is a value between 0 (nothing loaded) to 1.0 (top frame | |
| 210 // entirely loaded). | |
| 211 virtual void DidChangeLoadProgress(double progress) {} | |
| 212 | |
| 213 // The RenderView's main frame document element is ready. This happens when | |
| 214 // the document has finished parsing. | |
| 215 virtual void DocumentAvailableInMainFrame(RenderViewHost* render_view_host) {} | |
| 216 | |
| 217 // The onload handler in the RenderView's main frame has completed. | |
| 218 virtual void DocumentOnLoadCompletedInMainFrame( | |
| 219 RenderViewHost* render_view_host, | |
| 220 int32 page_id) {} | |
| 221 | |
| 222 // The page wants to open a URL with the specified disposition. | |
| 223 virtual void RequestOpenURL(RenderViewHost* rvh, | |
| 224 const GURL& url, | |
| 225 const content::Referrer& referrer, | |
| 226 WindowOpenDisposition disposition, | |
| 227 int64 source_frame_id) {} | |
| 228 | |
| 229 // The page wants to transfer the request to a new renderer. | |
| 230 virtual void RequestTransferURL( | |
| 231 const GURL& url, | |
| 232 const content::Referrer& referrer, | |
| 233 WindowOpenDisposition disposition, | |
| 234 int64 source_frame_id, | |
| 235 const content::GlobalRequestID& old_request_id) {} | |
| 236 | |
| 237 // The page wants to close the active view in this tab. | |
| 238 virtual void RouteCloseEvent(RenderViewHost* rvh) {} | |
| 239 | |
| 240 // The page wants to post a message to the active view in this tab. | |
| 241 virtual void RouteMessageEvent( | |
| 242 RenderViewHost* rvh, | |
| 243 const ViewMsg_PostMessage_Params& params) {} | |
| 244 | |
| 245 // A javascript message, confirmation or prompt should be shown. | |
| 246 virtual void RunJavaScriptMessage(RenderViewHost* rvh, | |
| 247 const string16& message, | |
| 248 const string16& default_prompt, | |
| 249 const GURL& frame_url, | |
| 250 ui::JavascriptMessageType type, | |
| 251 IPC::Message* reply_msg, | |
| 252 bool* did_suppress_message) {} | |
| 253 | |
| 254 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh, | |
| 255 const string16& message, | |
| 256 bool is_reload, | |
| 257 IPC::Message* reply_msg) {} | |
| 258 | |
| 259 // Return a dummy RendererPreferences object that will be used by the renderer | |
| 260 // associated with the owning RenderViewHost. | |
| 261 virtual content::RendererPreferences GetRendererPrefs( | |
| 262 content::BrowserContext* browser_context) const = 0; | |
| 263 | |
| 264 // Returns a WebPreferences object that will be used by the renderer | |
| 265 // associated with the owning render view host. | |
| 266 virtual webkit_glue::WebPreferences GetWebkitPrefs(); | |
| 267 | |
| 268 // Notification the user has made a gesture while focus was on the | |
| 269 // page. This is used to avoid uninitiated user downloads (aka carpet | |
| 270 // bombing), see DownloadRequestLimiter for details. | |
| 271 virtual void OnUserGesture() {} | |
| 272 | |
| 273 // Notification from the renderer host that blocked UI event occurred. | |
| 274 // This happens when there are tab-modal dialogs. In this case, the | |
| 275 // notification is needed to let us draw attention to the dialog (i.e. | |
| 276 // refocus on the modal dialog, flash title etc). | |
| 277 virtual void OnIgnoredUIEvent() {} | |
| 278 | |
| 279 // Notification that the renderer has become unresponsive. The | |
| 280 // delegate can use this notification to show a warning to the user. | |
| 281 virtual void RendererUnresponsive(RenderViewHost* render_view_host, | |
| 282 bool is_during_unload) {} | |
| 283 | |
| 284 // Notification that a previously unresponsive renderer has become | |
| 285 // responsive again. The delegate can use this notification to end the | |
| 286 // warning shown to the user. | |
| 287 virtual void RendererResponsive(RenderViewHost* render_view_host) {} | |
| 288 | |
| 289 // Notification that the RenderViewHost's load state changed. | |
| 290 virtual void LoadStateChanged(const GURL& url, | |
| 291 const net::LoadStateWithParam& load_state, | |
| 292 uint64 upload_position, | |
| 293 uint64 upload_size) {} | |
| 294 | |
| 295 // Notification that a worker process has crashed. | |
| 296 virtual void WorkerCrashed() {} | |
| 297 | |
| 298 // The page wants the hosting window to activate/deactivate itself (it | |
| 299 // called the JavaScript window.focus()/blur() method). | |
| 300 virtual void Activate() {} | |
| 301 virtual void Deactivate() {} | |
| 302 | |
| 303 // Notification that the view has lost capture. | |
| 304 virtual void LostCapture() {} | |
| 305 | |
| 306 // Notifications about mouse events in this view. This is useful for | |
| 307 // implementing global 'on hover' features external to the view. | |
| 308 virtual void HandleMouseMove() {} | |
| 309 virtual void HandleMouseDown() {} | |
| 310 virtual void HandleMouseLeave() {} | |
| 311 virtual void HandleMouseUp() {} | |
| 312 virtual void HandleMouseActivate() {} | |
| 313 | |
| 314 // Called when a file selection is to be done. | |
| 315 virtual void RunFileChooser( | |
| 316 RenderViewHost* render_view_host, | |
| 317 const content::FileChooserParams& params) {} | |
| 318 | |
| 319 // Notification that the page wants to go into or out of fullscreen mode. | |
| 320 virtual void ToggleFullscreenMode(bool enter_fullscreen) {} | |
| 321 virtual bool IsFullscreenForCurrentTab() const; | |
| 322 | |
| 323 // The contents' preferred size changed. | |
| 324 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} | |
| 325 | |
| 326 // The contents auto-resized and the container should match it. | |
| 327 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) {} | |
| 328 | |
| 329 // Requests to lock the mouse. Once the request is approved or rejected, | |
| 330 // GotResponseToLockMouseRequest() will be called on the requesting render | |
| 331 // view host. | |
| 332 virtual void RequestToLockMouse(bool user_gesture) {} | |
| 333 | |
| 334 // Notification that the view has lost the mouse lock. | |
| 335 virtual void LostMouseLock() {} | |
| 336 | |
| 337 // The page is trying to open a new page (e.g. a popup window). The window | |
| 338 // should be created associated with the given route, but it should not be | |
| 339 // shown yet. That should happen in response to ShowCreatedWindow. | |
| 340 // |params.window_container_type| describes the type of RenderViewHost | |
| 341 // container that is requested -- in particular, the window.open call may | |
| 342 // have specified 'background' and 'persistent' in the feature string. | |
| 343 // | |
| 344 // The passed |params.frame_name| parameter is the name parameter that was | |
| 345 // passed to window.open(), and will be empty if none was passed. | |
| 346 // | |
| 347 // Note: this is not called "CreateWindow" because that will clash with | |
| 348 // the Windows function which is actually a #define. | |
| 349 virtual void CreateNewWindow( | |
| 350 int route_id, | |
| 351 const ViewHostMsg_CreateWindow_Params& params) {} | |
| 352 | |
| 353 // The page is trying to open a new widget (e.g. a select popup). The | |
| 354 // widget should be created associated with the given route, but it should | |
| 355 // not be shown yet. That should happen in response to ShowCreatedWidget. | |
| 356 // |popup_type| indicates if the widget is a popup and what kind of popup it | |
| 357 // is (select, autofill...). | |
| 358 virtual void CreateNewWidget(int route_id, | |
| 359 WebKit::WebPopupType popup_type) {} | |
| 360 | |
| 361 // Creates a full screen RenderWidget. Similar to above. | |
| 362 virtual void CreateNewFullscreenWidget(int route_id) {} | |
| 363 | |
| 364 // Show a previously created page with the specified disposition and bounds. | |
| 365 // The window is identified by the route_id passed to CreateNewWindow. | |
| 366 // | |
| 367 // Note: this is not called "ShowWindow" because that will clash with | |
| 368 // the Windows function which is actually a #define. | |
| 369 virtual void ShowCreatedWindow(int route_id, | |
| 370 WindowOpenDisposition disposition, | |
| 371 const gfx::Rect& initial_pos, | |
| 372 bool user_gesture) {} | |
| 373 | |
| 374 // Show the newly created widget with the specified bounds. | |
| 375 // The widget is identified by the route_id passed to CreateNewWidget. | |
| 376 virtual void ShowCreatedWidget(int route_id, | |
| 377 const gfx::Rect& initial_pos) {} | |
| 378 | |
| 379 // Show the newly created full screen widget. Similar to above. | |
| 380 virtual void ShowCreatedFullscreenWidget(int route_id) {} | |
| 381 | |
| 382 // A context menu should be shown, to be built using the context information | |
| 383 // provided in the supplied params. | |
| 384 virtual void ShowContextMenu(const content::ContextMenuParams& params) {} | |
| 385 | |
| 386 protected: | |
| 387 virtual ~RenderViewHostDelegate() {} | |
| 388 }; | |
| 389 | |
| 390 } // namespace content | |
| 391 | |
| 392 #endif // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_DELEGATE_H_ | |
| OLD | NEW |