summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webview_delegate.h
blob: f7aedd5897f843dd1dec1f79816a35449fbd385b (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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//    * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//    * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// WebCore provides hooks for several kinds of functionality, allowing separate
// classes termed "delegates" to receive notifications (in the form of direct
// function calls) when certain events are about to occur or have just occurred.
// In some cases, the delegate implements the needed functionality; in others,
// the delegate has some control over the behavior but doesn't actually
// implement it.  For example, the UI delegate is responsible for showing a
// dialog box or otherwise handling a JavaScript window.alert() call, via the
// RunJavaScriptAlert() method. On the other hand, the editor delegate doesn't
// actually handle editing functionality, although it could (for example)
// override whether a content-editable node accepts editing focus by returning
// false from ShouldBeginEditing(). (It would also possible for a more
// special-purpose editing delegate to act on the edited node in some way, e.g.
// to highlight modified text in the DidChangeContents() method.)

// WebKit divides the delegated tasks into several different classes, but we
// combine them into a single WebViewDelegate. This single delegate encompasses
// the needed functionality of the WebKit UIDelegate, ContextMenuDelegate,
// PolicyDelegate, FrameLoadDelegate, and EditorDelegate; additional portions
// of ChromeClient and FrameLoaderClient not delegated in the WebKit
// implementation; and some WebView additions.

#ifndef WEBKIT_GLUE_WEBVIEW_DELEGATE_H__
#define WEBKIT_GLUE_WEBVIEW_DELEGATE_H__

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "googleurl/src/gurl.h"
#include "webkit/glue/context_node_types.h"
#include "webkit/glue/webwidget_delegate.h"

namespace gfx {
  class Point;
  class Rect;
}

enum WindowOpenDisposition;
struct PasswordForm;
struct WebDropData;
struct WebPreferences;
class SkBitmap;
class WebError;
class WebFrame;
class WebHistoryItem;
class WebPluginDelegate;
class WebRequest;
class WebResponse;
class WebView;
class WebWidget;

enum WebNavigationType {
  WebNavigationTypeLinkClicked,
  WebNavigationTypeFormSubmitted,
  WebNavigationTypeBackForward,
  WebNavigationTypeReload,
  WebNavigationTypeFormResubmitted,
  WebNavigationTypeOther
};

enum NavigationGesture {
  NavigationGestureUser,    // User initiated navigation/load. This is not
                            // currently used due to the untrustworthy nature
                            // of userGestureHint (wasRunByUserGesture). See
                            // bug 1051891.
  NavigationGestureAuto,    // Non-user initiated navigation / load. For example
                            // onload or setTimeout triggered document.location
                            // changes, and form.submits. See bug 1046841 for
                            // some cases that should be treated this way but
                            // aren't yet.
  NavigationGestureUnknown, // What we assign when userGestureHint returns true
                            // because we can't trust it.
};


// Interface passed in to the WebViewDelegate to receive notification of the
// result of an open file dialog.
class WebFileChooserCallback {
 public:
  WebFileChooserCallback() {}
  virtual ~WebFileChooserCallback() {}
  virtual void OnFileChoose(const std::wstring& file_name) { }

 private:
  DISALLOW_EVIL_CONSTRUCTORS(WebFileChooserCallback);
};


// Inheritance here is somewhat weird, but since a WebView is a WebWidget,
// it makes sense that a WebViewDelegate is a WebWidgetDelegate.
class WebViewDelegate : virtual public WebWidgetDelegate {
 public:
  // WebView additions -------------------------------------------------------

  // This method is called to create a new WebView.  The WebView should not be
  // made visible until the new WebView's Delegate has its Show method called.
  // The returned WebView pointer is assumed to be owned by the host window,
  // and the caller of CreateWebView should not release the given WebView.
  // user_gesture is true if a user action initiated this call.
  virtual WebView* CreateWebView(WebView* webview, bool user_gesture) {
    return NULL;
  }

  // This method is called to create a new WebWidget to act as a popup
  // (like a drop-down menu).
  virtual WebWidget* CreatePopupWidget(WebView* webview) {
    return NULL;
  }

  // This method is called to create a WebPluginDelegate implementation when a
  // new plugin is instanced.  See webkit_glue::CreateWebPluginDelegateHelper
  // for a default WebPluginDelegate implementation.
  virtual WebPluginDelegate* CreatePluginDelegate(
      WebView* webview,
      const GURL& url,
      const std::string& mime_type,
      const std::string& clsid,
      std::string* actual_mime_type) {
    return NULL;
  }

  // This method is called when default plugin has been correctly created and
  // initialized, and found that the missing plugin is available to install or
  // user has started installation.
  virtual void OnMissingPluginStatus(WebPluginDelegate* delegate, int status) {
  }

  // This method is called to open a URL in the specified manner.
  virtual void OpenURL(WebView* webview, const GURL& url,
                       WindowOpenDisposition disposition) {
  }

  // Notifies how many matches have been found so far, for a given request_id.
  // |final_update| specifies whether this is the last update (all frames have
  // completed scoping).
  virtual void ReportFindInPageMatchCount(int count, int request_id,
                                          bool final_update) {
  }

  // Notifies the browser what tick-mark rect is currently selected. Parameter
  // |request_id| lets the recipient know which request this message belongs to,
  // so that it can choose to ignore the message if it has moved on to other
  // things. |selection_rect| is expected to have coordinates relative to the
  // top left corner of the web page area and represent where on the screen the
  // selection rect is currently located.
  virtual void ReportFindInPageSelection(int request_id,
                                         int active_match_ordinal,
                                         const gfx::Rect& selection_rect) {
  }

  // This function is called to retrieve a resource bitmap from the
  // renderer that was cached as a result of the renderer receiving a
  // ViewMsg_Preload_Bitmap message from the browser.
  virtual const SkBitmap* GetPreloadedResourceBitmap(int resource_id) {
    return NULL;
  }

  // Returns whether this WebView was opened by a user gesture.
  virtual bool WasOpenedByUserGesture(WebView* webview) const {
    return true;
  }

  // FrameLoaderClient -------------------------------------------------------

  // Notifies the delegate that a load has begun.
  virtual void DidStartLoading(WebView* webview) {
  }

  // Notifies the delegate that all loads are finished.
  virtual void DidStopLoading(WebView* webview) {
  }

  // The original version of this is WindowScriptObjectAvailable, below. This
  // is a Chrome-specific version that serves the same purpose, but has been
  // renamed since we haven't implemented WebScriptObject.  Our embedding
  // implementation binds native objects to the window via the webframe instead.
  // TODO(pamg): If we do implement WebScriptObject, we may wish to switch to
  // using the original version of this function.
  virtual void WindowObjectCleared(WebFrame* webframe) {
  }

  // PolicyDelegate ----------------------------------------------------------

  // This method is called to notify the delegate, and let it modify a
  // proposed navigation. It will be called before loading starts, and
  // on every redirect.
  //
  // disposition specifies what should normally happen for this
  // navigation (open in current tab, start a new tab, start a new
  // window, etc).  This method can return an altered disposition, and
  // take any additional separate action it wants to.
  //
  // is_redirect is true if this is a redirect rather than user action.
  virtual WindowOpenDisposition DispositionForNavigationAction(
      WebView* webview,
      WebFrame* frame,
      const WebRequest* request,
      WebNavigationType type,
      WindowOpenDisposition disposition,
      bool is_redirect) {
    return disposition;
  }

  // FrameLoadDelegate -------------------------------------------------------

  // Notifies the delegate that the provisional load of a specified frame in a
  // given WebView has started. By the time the provisional load for a frame has
  // started, we know whether or not the current load is due to a client
  // redirect or not, so we pass this information through to allow us to set
  // the referrer properly in those cases. The consumed_client_redirect_src is
  // an empty invalid GURL in other cases.
  virtual void DidStartProvisionalLoadForFrame(
      WebView* webview,
      WebFrame* frame,
      NavigationGesture gesture) {
  }

  // Called when a provisional load is redirected (see GetProvisionalDataSource
  // for more info on provisional loads). This happens when the server sends
  // back any type of redirect HTTP response.
  //
  // The redirect information can be retrieved from the provisional data
  // source's redirect chain, which will be updated prior to this callback.
  // The last element in that vector will be the new URL (which will be the
  // same as the provisional data source's current URL), and the next-to-last
  // element will be the referring URL.
  virtual void DidReceiveProvisionalLoadServerRedirect(WebView* webview,
                                                       WebFrame* frame) {
  }

  //  @method webView:didFailProvisionalLoadWithError:forFrame:
  //  @abstract Notifies the delegate that the provisional load has failed
  //  @param webView The WebView sending the message
  //  @param error The error that occurred
  //  @param frame The frame for which the error occurred
  //  @discussion This method is called after the provisional data source has
  //  failed to load.  The frame will continue to display the contents of the
  //  committed data source if there is one.
  virtual void DidFailProvisionalLoadWithError(WebView* webview,
                                               const WebError& error,
                                               WebFrame* frame) {
  }

  // If the provisional load fails, we try to load a an error page describing
  // the user about the load failure.  |html| is the UTF8 text to display.  If
  // |html| is empty, we will fall back on a local error page.
  virtual void LoadNavigationErrorPage(WebFrame* frame,
                                       const WebRequest* failed_request,
                                       const WebError& error,
                                       const std::string& html,
                                       bool replace) {
  }

  // Notifies the delegate that the load has changed from provisional to
  // committed. This method is called after the provisional data source has
  // become the committed data source.
  //
  // In some cases, a single load may be committed more than once. This
  // happens in the case of multipart/x-mixed-replace, also known as "server
  // push". In this case, a single location change leads to multiple documents
  // that are loaded in sequence. When this happens, a new commit will be sent
  // for each document.
  //
  // The "is_new_navigation" flag will be true when a new session history entry
  // was created for the load.  The frame's GetHistoryState method can be used
  // to get the corresponding session history state.
  virtual void DidCommitLoadForFrame(WebView* webview, WebFrame* frame,
                                     bool is_new_navigation) {
  }

  //
  //  @method webView:didReceiveTitle:forFrame:
  //  @abstract Notifies the delegate that the page title for a frame has been received
  //  @param webView The WebView sending the message
  //  @param title The new page title
  //  @param frame The frame for which the title has been received
  //  @discussion The title may update during loading; clients should be prepared for this.
  //  - (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame;
  virtual void DidReceiveTitle(WebView* webview,
                               const std::wstring& title,
                               WebFrame* frame) {
  }

  //
  //  @method webView:didFinishLoadForFrame:
  //  @abstract Notifies the delegate that the committed load of a frame has completed
  //  @param webView The WebView sending the message
  //  @param frame The frame that finished loading
  //  @discussion This method is called after the committed data source of a frame has successfully loaded
  //  and will only be called when all subresources such as images and stylesheets are done loading.
  //  Plug-In content and JavaScript-requested loads may occur after this method is called.
  //  - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;
  virtual void DidFinishLoadForFrame(WebView* webview,
                                     WebFrame* frame) {
  }

  //
  //  @method webView:didFailLoadWithError:forFrame:
  //  @abstract Notifies the delegate that the committed load of a frame has failed
  //  @param webView The WebView sending the message
  //  @param error The error that occurred
  //  @param frame The frame that failed to load
  //  @discussion This method is called after a data source has committed but failed to completely load.
  //  - (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame;
  virtual void DidFailLoadWithError(WebView* webview,
                                    const WebError& error,
                                    WebFrame* forFrame) {
  }

  // Notifies the delegate of a DOMContentLoaded event.
  // This is called when the html resource has been loaded, but
  // not necessarily all subresources (images, stylesheets). So, this is called
  // before DidFinishLoadForFrame.
  virtual void DidFinishDocumentLoadForFrame(WebView* webview, WebFrame* frame) {
  }

  // This method is called when we load a resource from an in-memory cache.
  // A return value of |false| indicates the load should proceed, but WebCore
  // appears to largely ignore the return value.
  virtual bool DidLoadResourceFromMemoryCache(WebView* webview,
                                              const WebRequest& request,
                                              const WebResponse& response,
                                              WebFrame* frame) {
    return false;
  }

  // This is called after javascript onload handlers have been fired.
  virtual void DidHandleOnloadEventsForFrame(WebView* webview, WebFrame* frame) {
  }

  // This method is called when anchors within a page have been clicked.
  // It is very similar to DidCommitLoadForFrame.
  virtual void DidChangeLocationWithinPageForFrame(WebView* webview,
                                                   WebFrame* frame,
                                                   bool is_new_navigation) {
  }

  // This is called when the favicon for a frame has been received.
  virtual void DidReceiveIconForFrame(WebView* webview, WebFrame* frame) {
  }

  // Notifies the delegate that a frame will start a client-side redirect. When
  // this function is called, the redirect has not yet been started (it may
  // not even be scheduled to happen until some point in the future). When the
  // redirect has been cancelled or has succeeded, DidStopClientRedirect will
  // be called.
  //
  // WebKit considers meta refreshes, and setting document.location (regardless
  // of when called) as client redirects (possibly among others).
  //
  // This function is intended to continue progress feedback while a
  // client-side redirect is pending. Watch out: WebKit seems to call us twice
  // for client redirects, resulting in two calls of this function.
  virtual void WillPerformClientRedirect(WebView* webview,
                                         WebFrame* frame,
                                         const GURL& src_url,
                                         const GURL& dest_url,
                                         unsigned int delay_seconds,
                                         unsigned int fire_date) {
  }

  // Notifies the delegate that a pending client-side redirect has been
  // cancelled (for example, if the frame changes before the timeout) or has
  // completed successfully. A client-side redirect is the result of setting
  // document.location, for example, as opposed to a server side redirect
  // which is the result of HTTP headers (see DidReceiveServerRedirect).
  //
  // On success, this will be called when the provisional load that the client
  // side redirect initiated is committed.
  //
  // See the implementation of FrameLoader::clientRedirectCancelledOrFinished.
  virtual void DidCancelClientRedirect(WebView* webview,
                                       WebFrame* frame) {
  }

  // Notifies the delegate that the load about to be committed for the specified
  // webview and frame was due to a client redirect originating from source URL.
  virtual void DidCompleteClientRedirect(WebView* webview,
                                         WebFrame* frame,
                                         const GURL& source) {
  }
  //
  //  @method webView:willCloseFrame:
  //  @abstract Notifies the delegate that a frame will be closed
  //  @param webView The WebView sending the message
  //  @param frame The frame that will be closed
  //  @discussion This method is called right before WebKit is done with the frame
  //  and the objects that it contains.
  //  - (void)webView:(WebView *)sender willCloseFrame:(WebFrame *)frame;
  virtual void WillCloseFrame(WebView* webview, WebFrame* frame) {
  }

  // ResourceLoadDelegate ----------------------------------------------------

  // Associates the given identifier with the initial resource request.
  // Resource load callbacks will use the identifier throughout the life of the
  // request.
  virtual void AssignIdentifierToRequest(WebView* webview,
                                         uint32 identifier,
                                         const WebRequest& request) {
  }

  // Notifies the delegate that a request is about to be sent out, giving the
  // delegate the opportunity to modify the request.  Note that request is
  // writable here, and changes to the URL, for example, will change the request
  // to be made.
  virtual void WillSendRequest(WebView* webview,
                               uint32 identifier,
                               WebRequest* request) {
  }

  // Notifies the delegate that a subresource load has succeeded.
  virtual void DidFinishLoading(WebView* webview, uint32 identifier) {
  }

  // Notifies the delegate that a subresource load has failed, and why.
  virtual void DidFailLoadingWithError(WebView* webview,
                                       uint32 identifier,
                                       const WebError& error) {
  }

  // ChromeClient ------------------------------------------------------------

  // Appends a line to the application's error console.  The message contains
  // an error description or other information, the line_no provides a line
  // number (e.g. for a JavaScript error report), and the source_id contains
  // a URL or other description of the source of the message.
  virtual void AddMessageToConsole(WebView* webview,
                                   const std::wstring& message,
                                   unsigned int line_no,
                                   const std::wstring& source_id) {
  }

  // Notification of possible password forms to be filled/submitted by
  // the password manager
  virtual void OnPasswordFormsSeen(WebView* webview,
                                   const std::vector<PasswordForm>& forms) {
  }

  //
  virtual void OnUnloadListenerChanged(WebView* webview, WebFrame* webframe) {
  }

  // UIDelegate --------------------------------------------------------------

  // Displays a JavaScript alert panel associated with the given view. Clients
  // should visually indicate that this panel comes from JavaScript. The panel
  // should have a single OK button.
  virtual void RunJavaScriptAlert(WebView* webview,
                                  const std::wstring& message) {
  }

  // Displays a JavaScript confirm panel associated with the given view.
  // Clients should visually indicate that this panel comes
  // from JavaScript. The panel should have two buttons, e.g. "OK" and
  // "Cancel". Returns true if the user hit OK, or false if the user hit Cancel.
  virtual bool RunJavaScriptConfirm(WebView* webview,
                                    const std::wstring& message) {
    return false;
  }

  // Displays a JavaScript text input panel associated with the given view.
  // Clients should visually indicate that this panel comes from JavaScript.
  // The panel should have two buttons, e.g. "OK" and "Cancel", and an area to
  // type text. The default_value should appear as the initial text in the
  // panel when it is shown. If the user hit OK, returns true and fills result
  // with the text in the box.  The value of result is undefined if the user
  // hit Cancel.
  virtual bool RunJavaScriptPrompt(WebView* webview,
                                   const std::wstring& message,
                                   const std::wstring& default_value,
                                   std::wstring* result) {
    return false;
  }

  // Displays a "before unload" confirm panel associated with the given view.
  // The panel should have two buttons, e.g. "OK" and "Cancel", where OK means
  // that the navigation should continue, and Cancel means that the navigation
  // should be cancelled, leaving the user on the current page.  Returns true
  // if the user hit OK, or false if the user hit Cancel.
  virtual bool RunBeforeUnloadConfirm(WebView* webview,
                                      const std::wstring& message) {
    return true;  // OK, continue to navigate away
  }

  // Tells the client that we're hovering over a link with a given URL,
  // if the node is not a link, the URL will be an empty GURL.
  virtual void UpdateTargetURL(WebView* webview,
                               const GURL& url) {
  }

  // Called to display a file chooser prompt.  The prompt should be pre-
  // populated with the given initial_filename string.  The WebViewDelegate
  // will own the WebFileChooserCallback object and is responsible for
  // freeing it.
  virtual void RunFileChooser(const std::wstring& initial_filename,
                              WebFileChooserCallback* file_chooser) {
    delete file_chooser;
  }

  // @abstract Shows a context menu with commands relevant to a specific
  //           element on the current page.
  // @param webview The WebView sending the delegate method.
  // @param type The type of node(s) the context menu is being invoked on
  // @param x The x position of the mouse pointer (relative to the webview)
  // @param y The y position of the mouse pointer (relative to the webview)
  // @param link_url The absolute URL of the link that contains the node the
  // mouse right clicked on
  // @param image_url The absolute URL of the image that the mouse right
  // clicked on
  // @param page_url The URL of the page the mouse right clicked on
  // @param frame_url The URL of the subframe the mouse right clicked on
  // @param selection_text The raw text of the selection that the mouse right
  // clicked on
  // @param misspelled_word The editable (possibily) misspelled word
  // in the Editor on which dictionary lookup for suggestions will be done.
  // @param edit_flags Which edit operations the renderer believes are available
  virtual void ShowContextMenu(WebView* webview,
                               ContextNode::Type type,
                               int x,
                               int y,
                               const GURL& link_url,
                               const GURL& image_url,
                               const GURL& page_url,
                               const GURL& frame_url,
                               const std::wstring& selection_text,
                               const std::wstring& misspelled_word,
                               int edit_flags) {
  }

  // Starts a drag session with the supplied contextual information.
  // webview: The WebView sending the delegate method.
  // drop_data: a WebDropData struct which should contain all the necessary
  // information for dragging data out of the webview.
  virtual void StartDragging(WebView* webview, const WebDropData& drop_data) { }

  // Returns the focus to the client.
  // reverse: Whether the focus should go to the previous (if true) or the next
  // focusable element.
  virtual void TakeFocus(WebView* webview, bool reverse) {
  }

  // Displays JS out-of-memory warning in the infobar
  virtual void JSOutOfMemory() {
  }

  // EditorDelegate ----------------------------------------------------------

  // These methods exist primarily to allow a specialized executable to record
  // edit events for testing purposes.  Most embedders are not expected to
  // override them. In fact, by default these editor delegate methods aren't
  // even called by the EditorClient, for performance reasons. To enable them,
  // call WebView::SetUseEditorDelegate(true) for each WebView.

  virtual bool ShouldBeginEditing(WebView* webview, std::wstring range) {
    return true;
  }

  virtual bool ShouldEndEditing(WebView* webview, std::wstring range) {
    return true;
  }

  virtual bool ShouldInsertNode(WebView* webview,
                                std::wstring node,
                                std::wstring range,
                                std::wstring action) {
    return true;
  }

  virtual bool ShouldInsertText(WebView* webview,
                                std::wstring text,
                                std::wstring range,
                                std::wstring action) {
    return true;
  }

  virtual bool ShouldChangeSelectedRange(WebView* webview,
                                         std::wstring fromRange,
                                         std::wstring toRange,
                                         std::wstring affinity,
                                         bool stillSelecting) {
    return true;
  }

  virtual bool ShouldDeleteRange(WebView* webview, std::wstring range) {
    return true;
  }

  virtual bool ShouldApplyStyle(WebView* webview,
                                std::wstring style,
                                std::wstring range) {
    return true;
  }

  virtual bool SmartInsertDeleteEnabled() {
    return false;
  }
  virtual void DidBeginEditing() { }
  virtual void DidChangeSelection() { }
  virtual void DidChangeContents() { }
  virtual void DidEndEditing() { }

  // Notification that a user metric has occurred.
  virtual void UserMetricsRecordAction(const std::wstring& action) { }
  virtual void UserMetricsRecordComputedAction(const std::wstring& action) {
    UserMetricsRecordAction(action);
  }

  // -------------------------------------------------------------------------

  // Notification that a request to download an image has completed. |errored|
  // indicates if there was a network error. The image is empty if there was
  // a network error, the contents of the page couldn't by converted to an
  // image, or the response from the host was not 200.
  // NOTE: image is empty if the response didn't contain image data.
  virtual void DidDownloadImage(int id,
                                const GURL& image_url,
                                bool errored,
                                const SkBitmap& image) {
  }

  enum ErrorPageType {
    DNS_ERROR,
    HTTP_404
  };
  // If providing an alternate error page (like link doctor), returns the URL
  // to fetch instead.  If an invalid url is returned, just fall back on local
  // error pages. |error_name| tells the delegate what type of error page we
  // want (e.g., 404 vs dns errors).
  virtual GURL GetAlternateErrorPageURL(const GURL& failedURL,
                                        ErrorPageType error_type) {
    return GURL();
  }

  // History Related ---------------------------------------------------------

  // Returns the session history entry at a distance |offset| relative to the
  // current entry.  Returns NULL on failure.
  virtual WebHistoryItem* GetHistoryEntryAtOffset(int offset) {
    return NULL;
  }

  // Asynchronously navigates to the history entry at the given offset.
  virtual void GoToEntryAtOffsetAsync(int offset) {
  }

  // Returns how many entries are in the back and forward lists, respectively.
  virtual int GetHistoryBackListCount() {
    return 0;
  }
  virtual int GetHistoryForwardListCount() {
    return 0;
  }

  // Notification that the form state of an element in the document, scroll
  // position, or possibly something else has changed that affects session
  // history (HistoryItem). This function will be called frequently, so the
  // implementor should not perform intensive operations in this notification.
  virtual void OnNavStateChanged(WebView* webview) { }

  // -------------------------------------------------------------------------

  // Tell the delegate the tooltip text for the current mouse position.
  virtual void SetTooltipText(WebView* webview,
                              const std::wstring& tooltip_text) { }

  // Downloading -------------------------------------------------------------

  virtual void DownloadUrl(const GURL& url, const GURL& referrer) { }

  // Editor Client -----------------------------------------------------------

  // Returns true if the word is spelled correctly. The word may begin or end
  // with whitespace or punctuation, so the implementor should be sure to handle
  // these cases.
  //
  // If the word is misspelled (returns false), the given first and last
  // indices (inclusive) will be filled with the offsets of the boundary of the
  // word within the given buffer. The out pointers must be specified. If the
  // word is correctly spelled (returns true), they will be set to (0,0).
  virtual void SpellCheck(const std::wstring& word, int& misspell_location,
                          int& misspell_length) {
    misspell_location = misspell_length = 0;
  }

  // Changes the state of the input method editor.
  virtual void SetInputMethodState(bool enabled) { }

  // Asks the user to print the page or a specific frame. Called in response to
  // a window.print() call.
  virtual void ScriptedPrint(WebFrame* frame) { }

  virtual void WebInspectorOpened(int num_resources) { }

  WebViewDelegate() { }
  virtual ~WebViewDelegate() { }

 private:
  DISALLOW_EVIL_CONSTRUCTORS(WebViewDelegate);
};

#endif  // WEBKIT_GLUE_WEBVIEW_DELEGATE_H__