summaryrefslogtreecommitdiffstats
path: root/chrome/browser/render_view_host_delegate.h
blob: f0c4b0ef11c50d01c6ff7e987b96901a61129cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_RENDER_VIEW_HOST_DELEGATE_H__
#define CHROME_BROWSER_RENDER_VIEW_HOST_DELEGATE_H__

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "chrome/browser/autofill_manager.h"
#include "chrome/common/render_messages.h"
#include "webkit/glue/webpreferences.h"

class NavigationEntry;
class Profile;
class RenderProcessHost;
class RenderViewHost;
class SkBitmap;
class WebContents;
struct WebDropData;
enum WindowOpenDisposition;

namespace IPC {
class Message;
}

namespace gfx {
class Rect;
}

namespace net {
enum LoadState;
}

//
// RenderViewHostDelegate
//
//  An interface implemented by an object interested in knowing about the state
//  of the RenderViewHost.
//
//  This interface currently encompasses every type of message that was
//  previously being sent by WebContents itself. Some of these notifications
//  may not be relevant to all users of RenderViewHost and we should consider
//  exposing a more generic Send function on RenderViewHost and a response
//  listener here to serve that need.
//
class RenderViewHostDelegate {
 public:
  class View {
   public:
    // The page is trying to open a new page (e.g. a popup window). The
    // window should be created associated with the given route, but it should
    // not be shown yet. That should happen in response to ShowCreatedWindow.
    //
    // Note: this is not called "CreateWindow" because that will clash with
    // the Windows function which is actually a #define.
    virtual void CreateNewWindow(int route_id, HANDLE modal_dialog_event) = 0;

    // The page is trying to open a new widget (e.g. a select popup). The
    // widget should be created associated with the given route, but it should
    // not be shown yet. That should happen in response to ShowCreatedWidget.
    // If |focus_on_show| is true, the focus is given to the widget when shown,
    // otherwise the focus is not changed.
    virtual void CreateNewWidget(int route_id,
                                 bool focus_on_show) = 0;

    // Show a previously created page with the specified disposition and bounds.
    // The window is identified by the route_id passed to CreateNewWindow.
    //
    // Note: this is not called "ShowWindow" because that will clash with
    // the Windows function which is actually a #define.
    virtual void ShowCreatedWindow(int route_id,
                                   WindowOpenDisposition disposition,
                                   const gfx::Rect& initial_pos,
                                   bool user_gesture) = 0;

    // Show the newly created widget with the specified bounds.
    // The widget is identified by the route_id passed to CreateNewWidget.
    virtual void ShowCreatedWidget(int route_id,
                                   const gfx::Rect& initial_pos) = 0;

    // A context menu should be shown, to be built using the context information
    // provided in the supplied params.
    virtual void ShowContextMenu(
        const ViewHostMsg_ContextMenu_Params& params) = 0;

    // The user started dragging content of the specified type within the
    // RenderView. Contextual information about the dragged content is supplied
    // by WebDropData.
    virtual void StartDragging(const WebDropData& drop_data) = 0;

    // The page wants to update the mouse cursor during a drag & drop operation.
    // |is_drop_target| is true if the mouse is over a valid drop target.
    virtual void UpdateDragCursor(bool is_drop_target) = 0;

    // Callback to inform the browser it should take back focus. If reverse is
    // true, it means the focus was retrieved by doing a Shift-Tab.
    virtual void TakeFocus(bool reverse) = 0;

    // Callback to inform the browser that the renderer did not process the
    // specified events. This gives an opportunity to the browser to process the
    // event (used for keyboard shortcuts).
    virtual void HandleKeyboardEvent(const WebKeyboardEvent& event) = 0;

    // A find operation in the current page completed.
    virtual void OnFindReply(int request_id,
                             int number_of_matches,
                             const gfx::Rect& selection_rect,
                             int active_match_ordinal,
                             bool final_update) = 0;
  };

  // Interface for saving web pages.
  class Save {
   public:
    // Notification that we get when we receive all savable links of
    // sub-resources for the current page, their referrers and list of frames
    // (include main frame and sub frames).
    virtual void OnReceivedSavableResourceLinksForCurrentPage(
        const std::vector<GURL>& resources_list,
        const std::vector<GURL>& referrers_list,
        const std::vector<GURL>& frames_list) = 0;

    // Notification that we get when we receive serialized html content data of
    // a specified web page from render process. The parameter frame_url
    // specifies what frame the data belongs. The parameter data contains the
    // available data for sending. The parameter status indicates the
    // serialization status, See
    // webkit_glue::DomSerializerDelegate::PageSavingSerializationStatus for
    // the detail meaning of status.
    virtual void OnReceivedSerializedHtmlData(const GURL& frame_url,
                                              const std::string& data,
                                              int32 status) = 0;
  };

  // Returns the current delegate associated with a feature. May be NULL.
  virtual View* GetViewDelegate() const { return NULL; }
  virtual Save* GetSaveDelegate() const { return NULL; }

  // Retrieves the profile to be used.
  virtual Profile* GetProfile() const = 0;

  // The RenderView is being constructed (message sent to the renderer process
  // to construct a RenderView).  Now is a good time to send other setup events
  // to the RenderView.  This precedes any other commands to the RenderView.
  virtual void RendererCreated(RenderViewHost* render_view_host) { }

  // The RenderView has been constructed.
  virtual void RendererReady(RenderViewHost* render_view_host) { }

  // The RenderView died somehow (crashed or was killed by the user).
  virtual void RendererGone(RenderViewHost* render_view_host) { }

  // The RenderView was navigated to a different page.
  virtual void DidNavigate(RenderViewHost* render_view_host,
                           const ViewHostMsg_FrameNavigate_Params& params) { }

  // The state for the page changed and should be updated.
  virtual void UpdateState(RenderViewHost* render_view_host,
                           int32 page_id,
                           const std::string& state) { }

  // The page's title was changed and should be updated.
  virtual void UpdateTitle(RenderViewHost* render_view_host,
                           int32 page_id,
                           const std::wstring& title) { }

  // The page's encoding was changed and should be updated.
  virtual void UpdateEncoding(RenderViewHost* render_view_host,
                              const std::wstring& encoding) { }

  // The destination URL has changed should be updated
  virtual void UpdateTargetURL(int32 page_id, const GURL& url) { }

  // The thumbnail representation of the page changed and should be updated.
  virtual void UpdateThumbnail(const GURL& url,
                               const SkBitmap& bitmap,
                               const ThumbnailScore& score) { }

  // The page is trying to close the RenderView's representation in the client.
  virtual void Close(RenderViewHost* render_view_host) { }

  // The page is trying to move the RenderView's representation in the client.
  virtual void RequestMove(const gfx::Rect& new_bounds) { }

  // The RenderView began loading a new page.
  virtual void DidStartLoading(RenderViewHost* render_view_host,
                               int32 page_id) { }

  // The RenderView stopped loading a page.
  virtual void DidStopLoading(RenderViewHost* render_view_host,
                              int32 page_id) { }

  // The RenderView is starting a provisional load.
  virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host,
                                               bool is_main_frame,
                                               const GURL& url) { }

  // Sent when a provisional load is redirected.
  virtual void DidRedirectProvisionalLoad(int32 page_id,
                                          const GURL& source_url,
                                          const GURL& target_url) { }

  // The RenderView loaded a resource from an in-memory cache.
  // |security_info| contains the security info if this resource was originally
  // loaded over a secure connection.
  virtual void DidLoadResourceFromMemoryCache(const GURL& url,
      const std::string& security_info) { }

  // The RenderView failed a provisional load with an error.
  virtual void DidFailProvisionalLoadWithError(
      RenderViewHost* render_view_host,
      bool is_main_frame,
      int error_code,
      const GURL& url,
      bool showing_repost_interstitial) { }

  // The URL for the FavIcon of a page has changed.
  virtual void UpdateFavIconURL(RenderViewHost* render_view_host,
                                int32 page_id, const GURL& icon_url) { }

  // An image that was requested to be downloaded by DownloadImage has
  // completed.
  virtual void DidDownloadImage(RenderViewHost* render_view_host,
                                int id,
                                const GURL& image_url,
                                bool errored,
                                const SkBitmap& image) { }

  // The page wants to open a URL with the specified disposition.
  virtual void RequestOpenURL(const GURL& url,
                              const GURL& referrer,
                              WindowOpenDisposition disposition) { }

  // A DOM automation operation completed. The result of the operation is
  // expressed in a json string.
  virtual void DomOperationResponse(const std::string& json_string,
                                    int automation_id) { }

  // A message was sent from HTML-based UI.
  // By default we ignore such messages.
  virtual void ProcessDOMUIMessage(const std::string& message,
                                   const std::string& content) { }

  // A message for external host. By default we ignore such messages.
  // |receiver| can be a receiving script and |message| is any
  // arbitrary string that makes sense to the receiver.
  virtual void ProcessExternalHostMessage(const std::string& receiver,
                                          const std::string& message) { }

  // Navigate to the history entry for the given offset from the current
  // position within the NavigationController.  Makes no change if offset is
  // not valid.
  virtual void GoToEntryAtOffset(int offset) { }

  // The page requests the size of the back and forward lists
  // within the NavigationController.
  virtual void GetHistoryListCount(int* back_list_count,
                                   int* forward_list_count) { }

  // A file chooser should be shown.
  virtual void RunFileChooser(const std::wstring& default_file) { }

  // A javascript message, confirmation or prompt should be shown.
  virtual void RunJavaScriptMessage(const std::wstring& message,
                                    const std::wstring& default_prompt,
                                    const int flags,
                                    IPC::Message* reply_msg,
                                    bool* did_suppress_message) { }

  virtual void RunBeforeUnloadConfirm(const std::wstring& message,
                                      IPC::Message* reply_msg) { }

  // Display this RenderViewHost in a modal fashion.
  virtual void RunModal(IPC::Message* reply_msg) { }

  virtual void ShowModalHTMLDialog(const GURL& url, int width, int height,
                                   const std::string& json_arguments,
                                   IPC::Message* reply_msg) { }

  // Password forms have been detected in the page.
  virtual void PasswordFormsSeen(const std::vector<PasswordForm>& forms) { }

  // Forms fillable by autofill have been detected in the page.
  virtual void AutofillFormSubmitted(const AutofillForm& form) { }

  // Called to retrieve a list of suggestions from the web database given 
  // the name of the field |field_name| and what the user has already typed in
  // the field |user_text|.  Appeals to the database thead to perform the query.
  // When the database thread is finished, the autofill manager retrieves the
  // calling RenderViewHost and then passes the vector of suggestions to
  // RenderViewHost::AutofillSuggestionsReturned.
  virtual void GetAutofillSuggestions(const std::wstring& field_name, 
                                      const std::wstring& user_text,
                                      int64 node_id,
                                      int request_id) { }

  // Notification that the page has an OpenSearch description document.
  virtual void PageHasOSDD(RenderViewHost* render_view_host,
                           int32 page_id, const GURL& doc_url,
                           bool autodetected) { }

  // Notification that the inspect element window has been opened
  virtual void InspectElementReply(int num_resources) { }

  // Notification that the render view has calculated the number of printed
  // pages.
  virtual void DidGetPrintedPagesCount(int cookie, int number_pages) {
    NOTREACHED();
  }

  // Notification that the render view is done rendering one printed page. This
  // call is synchronous, the renderer is waiting on us because of the EMF
  // memory mapped data.
  virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params) {
    NOTREACHED();
  }

  // |url| is assigned to a server that can provide alternate error pages.  If
  // unchanged, just use the error pages built into our webkit.
  virtual GURL GetAlternateErrorPageURL() const {
    return GURL();
  }

  // Returns a WebPreferences object that will be used by the renderer
  // associated with the owning render view host.
  virtual WebPreferences GetWebkitPrefs() {
    NOTREACHED();
    return WebPreferences();
  }

  // Notification when default plugin updates status of the missing plugin.
  virtual void OnMissingPluginStatus(int status) { }

  // Notification from the renderer that a plugin instance has crashed.
  virtual void OnCrashedPlugin(const std::wstring& plugin_path) { }

  // Notification from the renderer that JS runs out of memory.
  virtual void OnJSOutOfMemory() { }

  // Notification whether we should close the page, after an explicit call to
  // AttemptToClosePage.  This is called before a cross-site request or before
  // a tab/window is closed, to allow the appropriate renderer to approve or
  // deny the request.  |proceed| indicates whether the user chose to proceed.
  virtual void ShouldClosePage(bool proceed) { }

  // Called by ResourceDispatcherHost when a response for a pending cross-site
  // request is received.  The ResourceDispatcherHost will pause the response
  // until the onunload handler of the previous renderer is run.
  virtual void OnCrossSiteResponse(int new_render_process_host_id,
                                   int new_request_id) { }

  // Whether this object can be blurred through a javascript
  // obj.blur() call. ConstrainedWindows shouldn't be able to be
  // blurred.
  virtual bool CanBlur() const { return true; }

  // Notification that the renderer has become unresponsive. The
  // delegate can use this notification to show a warning to the user.
  virtual void RendererUnresponsive(RenderViewHost* render_view_host, 
                                    bool is_during_unload) { }

  // Notification that a previously unresponsive renderer has become
  // responsive again. The delegate can use this notification to end the
  // warning shown to the user.
  virtual void RendererResponsive(RenderViewHost* render_view_host) { }

  // Notification that the RenderViewHost's load state changed.
  virtual void LoadStateChanged(const GURL& url, net::LoadState load_state) { }

  // Notification that a request for install info has completed.
  virtual void OnDidGetApplicationInfo(
      int32 page_id,
      const webkit_glue::WebApplicationInfo& app_info) { }

  // Notification the user has pressed enter or space while focus was on the
  // page. This is used to avoid uninitiated user downloads (aka carpet
  // bombing), see DownloadRequestManager for details.
  virtual void OnEnterOrSpace() { }
};

#endif  // CHROME_BROWSER_RENDER_VIEW_HOST_DELEGATE_H__