Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: chrome/browser/renderer_host/render_view_host_delegate.h

Issue 6532073: Move core pieces of browser\renderer_host to src\content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_ 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_
6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_ 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 // TODO(jam): remove this file when all files have been converted.
10 #include <vector> 10 #include "content/browser/renderer_host/render_view_host_delegate.h"
11
12 #include "base/basictypes.h"
13 #include "base/process_util.h"
14 #include "base/ref_counted.h"
15 #include "base/string16.h"
16 #include "chrome/common/content_settings_types.h"
17 #include "chrome/common/dom_storage_common.h"
18 #include "chrome/common/translate_errors.h"
19 #include "chrome/common/view_types.h"
20 #include "chrome/common/window_container_type.h"
21 #include "ipc/ipc_channel.h"
22 #include "net/base/load_states.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h"
25 #include "webkit/glue/window_open_disposition.h"
26
27
28 class AutomationResourceRoutingDelegate;
29 class BackgroundContents;
30 struct BookmarkNodeData;
31 class BookmarkNode;
32 struct ContextMenuParams;
33 class FilePath;
34 class GURL;
35 class ListValue;
36 struct NativeWebKeyboardEvent;
37 class NavigationEntry;
38 class Profile;
39 struct RendererPreferences;
40 class RenderProcessHost;
41 class RenderViewHost;
42 class ResourceRedirectDetails;
43 class ResourceRequestDetails;
44 class SkBitmap;
45 class SSLClientAuthHandler;
46 class SSLAddCertHandler;
47 class TabContents;
48 struct ThumbnailScore;
49 struct ViewHostMsg_CreateWindow_Params;
50 struct ViewHostMsg_DomMessage_Params;
51 struct ViewHostMsg_FrameNavigate_Params;
52 struct WebApplicationInfo;
53 struct WebDropData;
54 struct WebMenuItem;
55 class WebKeyboardEvent;
56 struct WebPreferences;
57
58 namespace base {
59 class WaitableEvent;
60 }
61
62 namespace gfx {
63 class Point;
64 class Rect;
65 class Size;
66 }
67
68 namespace IPC {
69 class Message;
70 }
71
72 namespace net {
73 class CookieList;
74 class CookieOptions;
75 }
76
77 namespace webkit_glue {
78 struct FormData;
79 class FormField;
80 struct PasswordForm;
81 }
82
83 //
84 // RenderViewHostDelegate
85 //
86 // An interface implemented by an object interested in knowing about the state
87 // of the RenderViewHost.
88 //
89 // This interface currently encompasses every type of message that was
90 // previously being sent by TabContents itself. Some of these notifications
91 // may not be relevant to all users of RenderViewHost and we should consider
92 // exposing a more generic Send function on RenderViewHost and a response
93 // listener here to serve that need.
94 //
95 class RenderViewHostDelegate : public IPC::Channel::Listener {
96 public:
97 // View ----------------------------------------------------------------------
98 // Functions that can be routed directly to a view-specific class.
99
100 class View {
101 public:
102 // The page is trying to open a new page (e.g. a popup window). The window
103 // should be created associated with the given route, but it should not be
104 // shown yet. That should happen in response to ShowCreatedWindow.
105 // |params.window_container_type| describes the type of RenderViewHost
106 // container that is requested -- in particular, the window.open call may
107 // have specified 'background' and 'persistent' in the feature string.
108 //
109 // The passed |params.frame_name| parameter is the name parameter that was
110 // passed to window.open(), and will be empty if none was passed.
111 //
112 // Note: this is not called "CreateWindow" because that will clash with
113 // the Windows function which is actually a #define.
114 //
115 // NOTE: this takes ownership of @modal_dialog_event
116 virtual void CreateNewWindow(
117 int route_id,
118 const ViewHostMsg_CreateWindow_Params& params) = 0;
119
120 // The page is trying to open a new widget (e.g. a select popup). The
121 // widget should be created associated with the given route, but it should
122 // not be shown yet. That should happen in response to ShowCreatedWidget.
123 // |popup_type| indicates if the widget is a popup and what kind of popup it
124 // is (select, autofill...).
125 virtual void CreateNewWidget(int route_id,
126 WebKit::WebPopupType popup_type) = 0;
127
128 // Creates a full screen RenderWidget. Similar to above.
129 virtual void CreateNewFullscreenWidget(int route_id) = 0;
130
131 // Show a previously created page with the specified disposition and bounds.
132 // The window is identified by the route_id passed to CreateNewWindow.
133 //
134 // Note: this is not called "ShowWindow" because that will clash with
135 // the Windows function which is actually a #define.
136 virtual void ShowCreatedWindow(int route_id,
137 WindowOpenDisposition disposition,
138 const gfx::Rect& initial_pos,
139 bool user_gesture) = 0;
140
141 // Show the newly created widget with the specified bounds.
142 // The widget is identified by the route_id passed to CreateNewWidget.
143 virtual void ShowCreatedWidget(int route_id,
144 const gfx::Rect& initial_pos) = 0;
145
146 // Show the newly created full screen widget. Similar to above.
147 virtual void ShowCreatedFullscreenWidget(int route_id) = 0;
148
149 // A context menu should be shown, to be built using the context information
150 // provided in the supplied params.
151 virtual void ShowContextMenu(const ContextMenuParams& params) = 0;
152
153 // Shows a popup menu with the specified items.
154 // This method should call RenderViewHost::DidSelectPopupMenuItemAt() or
155 // RenderViewHost::DidCancelPopupMenu() ased on the user action.
156 virtual void ShowPopupMenu(const gfx::Rect& bounds,
157 int item_height,
158 double item_font_size,
159 int selected_item,
160 const std::vector<WebMenuItem>& items,
161 bool right_aligned) = 0;
162
163 // The user started dragging content of the specified type within the
164 // RenderView. Contextual information about the dragged content is supplied
165 // by WebDropData.
166 virtual void StartDragging(const WebDropData& drop_data,
167 WebKit::WebDragOperationsMask allowed_ops,
168 const SkBitmap& image,
169 const gfx::Point& image_offset) = 0;
170
171 // The page wants to update the mouse cursor during a drag & drop operation.
172 // |operation| describes the current operation (none, move, copy, link.)
173 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) = 0;
174
175 // Notification that view for this delegate got the focus.
176 virtual void GotFocus() = 0;
177
178 // Callback to inform the browser that the page is returning the focus to
179 // the browser's chrome. If reverse is true, it means the focus was
180 // retrieved by doing a Shift-Tab.
181 virtual void TakeFocus(bool reverse) = 0;
182
183 // Notification that the view has lost capture.
184 virtual void LostCapture() = 0;
185
186 // The page wants the hosting window to activate/deactivate itself (it
187 // called the JavaScript window.focus()/blur() method).
188 virtual void Activate() = 0;
189 virtual void Deactivate() = 0;
190
191 // Callback to give the browser a chance to handle the specified keyboard
192 // event before sending it to the renderer.
193 // Returns true if the |event| was handled. Otherwise, if the |event| would
194 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
195 // |*is_keyboard_shortcut| should be set to true.
196 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
197 bool* is_keyboard_shortcut) = 0;
198
199 // Callback to inform the browser that the renderer did not process the
200 // specified events. This gives an opportunity to the browser to process the
201 // event (used for keyboard shortcuts).
202 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) = 0;
203
204 // Notifications about mouse events in this view. This is useful for
205 // implementing global 'on hover' features external to the view.
206 virtual void HandleMouseMove() = 0;
207 virtual void HandleMouseDown() = 0;
208 virtual void HandleMouseLeave() = 0;
209 virtual void HandleMouseUp() = 0;
210 virtual void HandleMouseActivate() = 0;
211
212 // The contents' preferred size changed.
213 virtual void UpdatePreferredSize(const gfx::Size& pref_size) = 0;
214
215 protected:
216 virtual ~View() {}
217 };
218
219 // RendererManagerment -------------------------------------------------------
220 // Functions for managing switching of Renderers. For TabContents, this is
221 // implemented by the RenderViewHostManager
222
223 class RendererManagement {
224 public:
225 // Notification whether we should close the page, after an explicit call to
226 // AttemptToClosePage. This is called before a cross-site request or before
227 // a tab/window is closed (as indicated by the first parameter) to allow the
228 // appropriate renderer to approve or deny the request. |proceed| indicates
229 // whether the user chose to proceed.
230 virtual void ShouldClosePage(bool for_cross_site_transition,
231 bool proceed) = 0;
232
233 // Called by ResourceDispatcherHost when a response for a pending cross-site
234 // request is received. The ResourceDispatcherHost will pause the response
235 // until the onunload handler of the previous renderer is run.
236 virtual void OnCrossSiteResponse(int new_render_process_host_id,
237 int new_request_id) = 0;
238
239 // Called the ResourceDispatcherHost's associate CrossSiteRequestHandler
240 // when a cross-site navigation has been canceled.
241 virtual void OnCrossSiteNavigationCanceled() = 0;
242
243 protected:
244 virtual ~RendererManagement() {}
245 };
246
247 // ContentSettings------------------------------------------------------------
248 // Interface for content settings related events.
249
250 class ContentSettings {
251 public:
252 // Called when content in the current page was blocked due to the user's
253 // content settings.
254 virtual void OnContentBlocked(ContentSettingsType type,
255 const std::string& resource_identifier) = 0;
256
257 // Called when cookies for the given URL were read either from within the
258 // current page or while loading it. |blocked_by_policy| should be true, if
259 // reading cookies was blocked due to the user's content settings. In that
260 // case, this function should invoke OnContentBlocked.
261 virtual void OnCookiesRead(
262 const GURL& url,
263 const net::CookieList& cookie_list,
264 bool blocked_by_policy) = 0;
265
266 // Called when a specific cookie in the current page was changed.
267 // |blocked_by_policy| should be true, if the cookie was blocked due to the
268 // user's content settings. In that case, this function should invoke
269 // OnContentBlocked.
270 virtual void OnCookieChanged(const GURL& url,
271 const std::string& cookie_line,
272 const net::CookieOptions& options,
273 bool blocked_by_policy) = 0;
274
275 // Called when a specific indexed db factory in the current page was
276 // accessed. If access was blocked due to the user's content settings,
277 // |blocked_by_policy| should be true, and this function should invoke
278 // OnContentBlocked.
279 virtual void OnIndexedDBAccessed(const GURL& url,
280 const string16& description,
281 bool blocked_by_policy) = 0;
282
283 // Called when a specific local storage area in the current page was
284 // accessed. If access was blocked due to the user's content settings,
285 // |blocked_by_policy| should be true, and this function should invoke
286 // OnContentBlocked.
287 virtual void OnLocalStorageAccessed(const GURL& url,
288 DOMStorageType storage_type,
289 bool blocked_by_policy) = 0;
290
291 // Called when a specific Web database in the current page was accessed. If
292 // access was blocked due to the user's content settings,
293 // |blocked_by_policy| should eb true, and this function should invoke
294 // OnContentBlocked.
295 virtual void OnWebDatabaseAccessed(const GURL& url,
296 const string16& name,
297 const string16& display_name,
298 unsigned long estimated_size,
299 bool blocked_by_policy) = 0;
300
301 // Called when a specific appcache in the current page was accessed. If
302 // access was blocked due to the user's content settings,
303 // |blocked_by_policy| should eb true, and this function should invoke
304 // OnContentBlocked.
305 virtual void OnAppCacheAccessed(const GURL& manifest_url,
306 bool blocked_by_policy) = 0;
307
308 // Called when geolocation permission was set in a frame on the current
309 // page.
310 virtual void OnGeolocationPermissionSet(const GURL& requesting_frame,
311 bool allowed) = 0;
312
313 protected:
314 virtual ~ContentSettings() {}
315 };
316
317 // BookmarkDrag --------------------------------------------------------------
318 // Interface for forwarding bookmark drag and drop to extenstions.
319
320 class BookmarkDrag {
321 public:
322 virtual void OnDragEnter(const BookmarkNodeData& data) = 0;
323 virtual void OnDragOver(const BookmarkNodeData& data) = 0;
324 virtual void OnDragLeave(const BookmarkNodeData& data) = 0;
325 virtual void OnDrop(const BookmarkNodeData& data) = 0;
326
327 protected:
328 virtual ~BookmarkDrag() {}
329 };
330
331 // SSL -----------------------------------------------------------------------
332 // Interface for UI and other RenderViewHost-specific interactions with SSL.
333
334 class SSL {
335 public:
336 // Displays a dialog to select client certificates from |request_info|,
337 // returning them to |handler|.
338 virtual void ShowClientCertificateRequestDialog(
339 scoped_refptr<SSLClientAuthHandler> handler) = 0;
340
341 // Called when |handler| encounters an error in verifying a
342 // received client certificate. Note that, because CAs often will
343 // not send us intermediate certificates, the verification we can
344 // do is minimal: we verify the certificate is parseable, that we
345 // have the corresponding private key, and that the certificate
346 // has not expired.
347 virtual void OnVerifyClientCertificateError(
348 scoped_refptr<SSLAddCertHandler> handler, int error_code) = 0;
349
350 // Called when |handler| requests the user's confirmation in adding a
351 // client certificate.
352 virtual void AskToAddClientCertificate(
353 scoped_refptr<SSLAddCertHandler> handler) = 0;
354
355 // Called when |handler| successfully adds a client certificate.
356 virtual void OnAddClientCertificateSuccess(
357 scoped_refptr<SSLAddCertHandler> handler) = 0;
358
359 // Called when |handler| encounters an error adding a client certificate.
360 virtual void OnAddClientCertificateError(
361 scoped_refptr<SSLAddCertHandler> handler, int error_code) = 0;
362
363 // Called when |handler| has completed, so the delegate may release any
364 // state accumulated.
365 virtual void OnAddClientCertificateFinished(
366 scoped_refptr<SSLAddCertHandler> handler) = 0;
367
368 protected:
369 virtual ~SSL() {}
370 };
371
372 // ---------------------------------------------------------------------------
373
374 // Returns the current delegate associated with a feature. May return NULL if
375 // there is no corresponding delegate.
376 virtual View* GetViewDelegate();
377 virtual RendererManagement* GetRendererManagementDelegate();
378 virtual ContentSettings* GetContentSettingsDelegate();
379
380 virtual BookmarkDrag* GetBookmarkDragDelegate();
381 virtual SSL* GetSSLDelegate();
382
383 // Return the delegate for registering RenderViewHosts for automation resource
384 // routing.
385 virtual AutomationResourceRoutingDelegate*
386 GetAutomationResourceRoutingDelegate();
387
388 // IPC::Channel::Listener implementation.
389 // This is used to give the delegate a chance to filter IPC messages.
390 virtual bool OnMessageReceived(const IPC::Message& message);
391
392 // Gets the URL that is currently being displayed, if there is one.
393 virtual const GURL& GetURL() const;
394
395 // Return this object cast to a TabContents, if it is one. If the object is
396 // not a TabContents, returns NULL. DEPRECATED: Be sure to include brettw and
397 // jam as reviewers before you use this method.
398 virtual TabContents* GetAsTabContents();
399
400 // Return this object cast to a BackgroundContents, if it is one. If the
401 // object is not a BackgroundContents, returns NULL.
402 virtual BackgroundContents* GetAsBackgroundContents();
403
404 // Return id number of browser window which this object is attached to. If no
405 // browser window is attached to, just return -1.
406 virtual int GetBrowserWindowID() const = 0;
407
408 // Return type of RenderView which is attached with this object.
409 virtual ViewType::Type GetRenderViewType() const = 0;
410
411 // The RenderView is being constructed (message sent to the renderer process
412 // to construct a RenderView). Now is a good time to send other setup events
413 // to the RenderView. This precedes any other commands to the RenderView.
414 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
415
416 // The RenderView has been constructed.
417 virtual void RenderViewReady(RenderViewHost* render_view_host) {}
418
419 // The RenderView died somehow (crashed or was killed by the user).
420 virtual void RenderViewGone(RenderViewHost* render_view_host,
421 base::TerminationStatus status,
422 int error_code) {}
423
424 // The RenderView is going to be deleted. This is called when each
425 // RenderView is going to be destroyed
426 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
427
428 // The RenderView was navigated to a different page.
429 virtual void DidNavigate(RenderViewHost* render_view_host,
430 const ViewHostMsg_FrameNavigate_Params& params) {}
431
432 // The state for the page changed and should be updated.
433 virtual void UpdateState(RenderViewHost* render_view_host,
434 int32 page_id,
435 const std::string& state) {}
436
437 // The page's title was changed and should be updated.
438 virtual void UpdateTitle(RenderViewHost* render_view_host,
439 int32 page_id,
440 const std::wstring& title) {}
441
442 // The page's encoding was changed and should be updated.
443 virtual void UpdateEncoding(RenderViewHost* render_view_host,
444 const std::string& encoding) {}
445
446 // The destination URL has changed should be updated
447 virtual void UpdateTargetURL(int32 page_id, const GURL& url) {}
448
449 // The thumbnail representation of the page changed and should be updated.
450 virtual void UpdateThumbnail(const GURL& url,
451 const SkBitmap& bitmap,
452 const ThumbnailScore& score) {}
453
454 // Inspector setting was changed and should be persisted.
455 virtual void UpdateInspectorSetting(const std::string& key,
456 const std::string& value) = 0;
457
458 virtual void ClearInspectorSettings() = 0;
459
460 // The page is trying to close the RenderView's representation in the client.
461 virtual void Close(RenderViewHost* render_view_host) {}
462
463 // The page is trying to move the RenderView's representation in the client.
464 virtual void RequestMove(const gfx::Rect& new_bounds) {}
465
466 // The RenderView began loading a new page. This corresponds to WebKit's
467 // notion of the throbber starting.
468 virtual void DidStartLoading() {}
469
470 // The RenderView stopped loading a page. This corresponds to WebKit's
471 // notion of the throbber stopping.
472 virtual void DidStopLoading() {}
473
474 // The RenderView made progress loading a page's top frame.
475 // |progress| is a value between 0 (nothing loaded) to 1.0 (top frame
476 // entirely loaded).
477 virtual void DidChangeLoadProgress(double progress) {}
478
479 // The RenderView's main frame document element is ready. This happens when
480 // the document has finished parsing.
481 virtual void DocumentAvailableInMainFrame(RenderViewHost* render_view_host) {}
482
483 // The onload handler in the RenderView's main frame has completed.
484 virtual void DocumentOnLoadCompletedInMainFrame(
485 RenderViewHost* render_view_host,
486 int32 page_id) {}
487
488 // The page wants to open a URL with the specified disposition.
489 virtual void RequestOpenURL(const GURL& url,
490 const GURL& referrer,
491 WindowOpenDisposition disposition) {}
492
493 // A DOM automation operation completed. The result of the operation is
494 // expressed in a json string.
495 virtual void DomOperationResponse(const std::string& json_string,
496 int automation_id) {}
497
498 // A message was sent from HTML-based UI.
499 // By default we ignore such messages.
500 virtual void ProcessWebUIMessage(
501 const ViewHostMsg_DomMessage_Params& params) {}
502
503 // A message for external host. By default we ignore such messages.
504 // |receiver| can be a receiving script and |message| is any
505 // arbitrary string that makes sense to the receiver.
506 virtual void ProcessExternalHostMessage(const std::string& message,
507 const std::string& origin,
508 const std::string& target) {}
509
510 // A javascript message, confirmation or prompt should be shown.
511 virtual void RunJavaScriptMessage(const std::wstring& message,
512 const std::wstring& default_prompt,
513 const GURL& frame_url,
514 const int flags,
515 IPC::Message* reply_msg,
516 bool* did_suppress_message) {}
517
518 virtual void RunBeforeUnloadConfirm(const std::wstring& message,
519 IPC::Message* reply_msg) {}
520
521 virtual void ShowModalHTMLDialog(const GURL& url, int width, int height,
522 const std::string& json_arguments,
523 IPC::Message* reply_msg) {}
524
525 // |url| is assigned to a server that can provide alternate error pages. If
526 // the returned URL is empty, the default error page built into WebKit will
527 // be used.
528 virtual GURL GetAlternateErrorPageURL() const;
529
530 // Return a dummy RendererPreferences object that will be used by the renderer
531 // associated with the owning RenderViewHost.
532 virtual RendererPreferences GetRendererPrefs(Profile* profile) const = 0;
533
534 // Returns a WebPreferences object that will be used by the renderer
535 // associated with the owning render view host.
536 virtual WebPreferences GetWebkitPrefs();
537
538 // Notification the user has made a gesture while focus was on the
539 // page. This is used to avoid uninitiated user downloads (aka carpet
540 // bombing), see DownloadRequestLimiter for details.
541 virtual void OnUserGesture() {}
542
543 // Notification from the renderer host that blocked UI event occurred.
544 // This happens when there are tab-modal dialogs. In this case, the
545 // notification is needed to let us draw attention to the dialog (i.e.
546 // refocus on the modal dialog, flash title etc).
547 virtual void OnIgnoredUIEvent() {}
548
549 // Notification that the renderer has become unresponsive. The
550 // delegate can use this notification to show a warning to the user.
551 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
552 bool is_during_unload) {}
553
554 // Notification that a previously unresponsive renderer has become
555 // responsive again. The delegate can use this notification to end the
556 // warning shown to the user.
557 virtual void RendererResponsive(RenderViewHost* render_view_host) {}
558
559 // Notification that the RenderViewHost's load state changed.
560 virtual void LoadStateChanged(const GURL& url, net::LoadState load_state,
561 uint64 upload_position, uint64 upload_size) {}
562
563 // Returns true if this view is used to host an external tab container.
564 virtual bool IsExternalTabContainer() const;
565
566 // The RenderView has inserted one css file into page.
567 virtual void DidInsertCSS() {}
568
569 // A different node in the page got focused.
570 virtual void FocusedNodeChanged(bool is_editable_node) {}
571
572 // Updates the minimum and maximum zoom percentages.
573 virtual void UpdateZoomLimits(int minimum_percent,
574 int maximum_percent,
575 bool remember) {}
576
577 // Notification that a worker process has crashed.
578 void WorkerCrashed() {}
579
580 protected:
581 virtual ~RenderViewHostDelegate() {}
582 };
583 11
584 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_ 12 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698