Skip to content
Navigation Menu
{{ message }}
forked from webkitdotnet/webkitdotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebKitBrowser.cs
More file actions
634 lines (557 loc) · 22.2 KB
/
Copy pathWebKitBrowser.cs
File metadata and controls
634 lines (557 loc) · 22.2 KB
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
/*
* Copyright (c) 2009, Peter Nelson (charn.opcode@gmail.com)
* 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.
*
* 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 HOLDER 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.
*/
// TODO: dispose / finalize stuff
// design time support for properties etc..
using System;
using System.ComponentModel;
using System.Drawing;
using System.Security.Cryptography.X509Certificates;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace WebKit
{
/// <summary>
/// WebKit Browser Control.
/// </summary>
public partial class WebKitBrowser : UserControl, IWebKitBrowserHost, IWebKitBrowser
{
private readonly WebKitBrowserCore _core;
/// <summary>
/// Processes a command key. Overridden in WebKitBrowser to forward key events to the WebKit window.
/// </summary>
/// <param name="Msg">The window message to process.</param>
/// <param name="KeyData">The key to process.</param>
/// <returns>Success value.</returns>
protected override bool ProcessCmdKey(ref Message Msg, Keys KeyData)
{
var key = (Keys) Msg.WParam.ToInt32();
if (key == Keys.Left || key == Keys.Right || key == Keys.Up ||
key == Keys.Down || key == Keys.Tab)
{
NativeMethods.SendMessage(Msg.HWnd, (uint) Msg.Msg, Msg.WParam, Msg.LParam);
return true;
}
return base.ProcessCmdKey(ref Msg, KeyData);
}
#region WebKitBrowser events
// public events, roughly the same as in WebBrowser class
// using the null object pattern to avoid null tests
/// <summary>
/// Occurs when the DocumentTitle property value changes.
/// </summary>
public event EventHandler DocumentTitleChanged
{
add { _core.DocumentTitleChanged += value; }
remove { _core.DocumentTitleChanged -= value; }
}
/// <summary>
/// Occurs when the WebKitBrowser control finishes loading a document.
/// </summary>
public event WebBrowserDocumentCompletedEventHandler DocumentCompleted
{
add { _core.DocumentCompleted += value; }
remove { _core.DocumentCompleted -= value; }
}
/// <summary>
/// Occurs when the WebKitBrowser control has navigated to a new document and has begun loading it.
/// </summary>
public event WebBrowserNavigatedEventHandler Navigated
{
add { _core.Navigated += value; }
remove { _core.Navigated -= value; }
}
/// <summary>
/// Occurs before the WebKitBrowser control navigates to a new document.
/// </summary>
public event WebBrowserNavigatingEventHandler Navigating
{
add { _core.Navigating += value; }
remove { _core.Navigating -= value; }
}
/// <summary>
/// Occurs when an error occurs on the current document, or when navigating to a new document.
/// </summary>
public event WebKitBrowserErrorEventHandler Error
{
add { _core.Error += value; }
remove { _core.Error -= value; }
}
/// <summary>
/// Occurs when the WebKitBrowser control begins a file download, before any data has been transferred.
/// </summary>
public event FileDownloadBeginEventHandler DownloadBegin
{
add { _core.DownloadBegin += value; }
remove { _core.DownloadBegin -= value; }
}
/// <summary>
/// Occurs when the WebKitBrowser control attempts to open a link in a new window.
/// </summary>
public event NewWindowRequestEventHandler NewWindowRequest
{
add { _core.NewWindowRequest += value; }
remove { _core.NewWindowRequest -= value; }
}
/// <summary>
/// Occurs when the WebKitBrowser control creates a new window.
/// </summary>
public event NewWindowCreatedEventHandler NewWindowCreated
{
add { _core.NewWindowCreated += value; }
remove { _core.NewWindowCreated -= value; }
}
/// <summary>
/// Occurs when JavaScript requests an alert panel to be displayed via the alert() function.
/// </summary>
public event ShowJavaScriptAlertPanelEventHandler ShowJavaScriptAlertPanel
{
add { _core.ShowJavaScriptAlertPanel += value; }
remove { _core.ShowJavaScriptAlertPanel -= value; }
}
/// <summary>
/// Occurs when JavaScript requests a confirm panel to be displayed via the confirm() function.
/// </summary>
public event ShowJavaScriptConfirmPanelEventHandler ShowJavaScriptConfirmPanel
{
add { _core.ShowJavaScriptConfirmPanel += value; }
remove { _core.ShowJavaScriptConfirmPanel -= value; }
}
/// <summary>
/// Occurs when JavaScript requests a prompt panel to be displayed via the prompt() function.
/// </summary>
public event ShowJavaScriptPromptPanelEventHandler ShowJavaScriptPromptPanel
{
add { _core.ShowJavaScriptPromptPanel += value; }
remove { _core.ShowJavaScriptPromptPanel -= value; }
}
#endregion
#region Public properties
/// <summary>
/// The current print page settings.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public PageSettings PageSettings
{
get { return _core.PageSettings; }
set { _core.PageSettings = value; }
}
/// <summary>
/// Gets the title of the current document.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string DocumentTitle
{
get { return _core.DocumentTitle; }
}
/// <summary>
/// Gets or sets the current Url.
/// </summary>
[Browsable(true), Category("Behavior"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Description("Specifies the Url to navigate to.")]
public Uri Url
{
get { return _core.Url; }
set { _core.Url = value; }
}
/// <summary>
/// Gets a value indicating whether a web page is currently being loaded.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsBusy
{
get { return _core.IsBusy; }
}
/// <summary>
/// Gets or sets the HTML content of the current document.
/// </summary>
[Browsable(true), DefaultValue(""), Category("Appearance")]
[Description("The HTML content to be displayed if no Url is specified.")]
public string DocumentText
{
get { return _core.DocumentText; }
set { _core.DocumentText = value; }
}
/// <summary>
/// Gets the currently selected text.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string SelectedText
{
get { return _core.SelectedText; }
}
/// <summary>
/// Gets or sets the application name for the user agent.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string ApplicationName
{
get { return _core.ApplicationName; }
set { _core.ApplicationName = value; }
}
/// <summary>
/// Gets or sets the user agent string.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string UserAgent
{
get { return _core.UserAgent; }
set { _core.UserAgent = value; }
}
/// <summary>
/// Gets or sets the text size multiplier (1.0 is normal size).
/// </summary>
[Browsable(true), DefaultValue(1.0f), Category("Appearance")]
[Description("Specifies the text size multiplier.")]
public float TextSize
{
get { return _core.TextSize; }
set { _core.TextSize = value; }
}
/// <summary>
/// Gets or sets whether the control can navigate to another page
/// once it's initial page has loaded.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Specifies whether the control can navigate" +
" to another page once it's initial page has loaded.")]
public bool AllowNavigation
{
get { return _core.AllowNavigation; }
set { _core.AllowNavigation = value; }
}
/// <summary>
/// Gets or sets whether to allow file downloads.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Specifies whether to allow file downloads.")]
public bool AllowDownloads
{
get { return _core.AllowDownloads; }
set { _core.AllowDownloads = value; }
}
/// <summary>
/// Gets or sets whether to allow links to be opened in a new window.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Specifies whether to allow links to be" +
" opened in a new window.")]
public bool AllowNewWindows
{
get { return _core.AllowNewWindows; }
set { _core.AllowNewWindows = value; }
}
/// <summary>
/// Gets a value indicating whether a previous page in the navigation history is available.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool CanGoBack
{
get { return _core.CanGoBack; }
}
/// <summary>
/// Gets a value indicating whether a subsequent page in the navigation history is available.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool CanGoForward
{
get { return _core.CanGoForward; }
}
/// <summary>
/// Gets a Document representing the currently displayed page.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DOM.Document Document
{
get { return _core.Document; }
}
/// <summary>
/// Gets the current version.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Version Version
{
get { return _core.Version; }
}
/// <summary>
/// Gets or sets the scroll offset of the current page, in pixels from the origin.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Point ScrollOffset
{
get { return _core.ScrollOffset; }
set { _core.ScrollOffset = value; }
}
/// <summary>
/// Gets the visible content rectangle of the current view, in pixels.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Rectangle VisibleContent
{
get { return _core.VisibleContent; }
}
/// <summary>
/// Gets or sets a value indicating whether the context menu of the WebKitBrowser is enabled.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Specifies whether the default browser context menu is enabled")]
public bool WebBrowserContextMenuEnabled
{
get { return _core.WebBrowserContextMenuEnabled; }
set { _core.WebBrowserContextMenuEnabled = value; }
}
[Browsable(false)]
[Obsolete("Deprecated: use WebBrowserContextMenuEnabled instead")]
public bool IsWebBrowserContextMenuEnabled
{
get { return WebBrowserContextMenuEnabled; }
set { WebBrowserContextMenuEnabled = value; }
}
/// <summary>
/// Gets or sets a value indicating whether JavaScript is enabled.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Specifies whether JavaScript is enabled in the WebKitBrowser")]
public bool ScriptingEnabled
{
get { return _core.ScriptingEnabled; }
set { _core.ScriptingEnabled = value; }
}
[Browsable(false)]
[Obsolete("Deprecated: use ScriptingEnabled instead")]
public bool IsScriptingEnabled
{
get { return ScriptingEnabled; }
set { ScriptingEnabled = value; }
}
/// <summary>
/// Gets or sets a value indicating whether LocalStorage is enabled.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Specifies whether LocalStorage is enabled in the WebKitBrowser")]
public bool LocalStorageEnabled {
get { return _core.LocalStorageEnabled; }
set { _core.LocalStorageEnabled = value; }
}
[Browsable(false)]
[Obsolete("Deprecated: use LocalStorageEnabled instead")]
public bool IsLocalStorageEnabled
{
get { return LocalStorageEnabled; }
set { LocalStorageEnabled = value; }
}
/// <summary>
/// Gets or sets the fully qualified path to the directory where
/// local storage database files will be stored.
/// </summary>
/// <remarks>Value must be a fully qualified directory path.</remarks>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string LocalStorageDatabaseDirectory {
get { return _core.LocalStorageDatabaseDirectory; }
set { _core.LocalStorageDatabaseDirectory = value; }
}
/// <summary>
/// Gets or sets a value indicating whether cross origin requests
/// from file:// URIs to other file:// URIs are allowed.
/// </summary>
public bool AllowFileAccessFromFileURLs
{
get { return _core.AllowFileAccessFromFileURLs; }
set { _core.AllowFileAccessFromFileURLs = value; }
}
/// <summary>
/// Gets or sets a value indicating how cookies are handled.
/// </summary>
public CookieAcceptPolicy CookieAcceptPolicy
{
get { return _core.CookieAcceptPolicy; }
set { _core.CookieAcceptPolicy = value; }
}
public bool AllowAnimatedImages
{
get { return _core.AllowAnimatedImages; }
set { _core.AllowAnimatedImages = value; }
}
public X509Certificate ClientCertificate
{
get { return _core.ClientCertificate; }
set { _core.ClientCertificate = value; }
}
/// <summary>
/// Gets or sets an object that can be accessed by JavaScript contained within the WebKitBrowser control.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object ObjectForScripting
{
get { return _core.ObjectForScripting; }
set { _core.ObjectForScripting = value; }
}
#endregion
#region Constructors / initialization functions
public WebKitBrowser()
: this(new WebKitBrowserCore())
{
}
/// <summary>
/// Initializes a new instance of the WebKitBrowser control.
/// </summary>
public WebKitBrowser(WebKitBrowserCore BrowserCore)
{
_core = BrowserCore;
NewWindowCreated += delegate { };
NewWindowRequest += delegate { };
DownloadBegin += delegate { };
Error += delegate { };
Navigating += delegate { };
Navigated += delegate { };
DocumentCompleted += delegate { };
DocumentTitleChanged += delegate { };
ShowJavaScriptAlertPanel += delegate { };
ShowJavaScriptConfirmPanel += delegate { };
ShowJavaScriptPromptPanel += delegate { };
InitializeComponent();
_core.Initialize(this);
}
#endregion
#region Public Methods
/// <summary>
/// Navigates to the specified Url.
/// </summary>
/// <param name="Url">Url to navigate to.</param>
public void Navigate(string Url)
{
_core.Navigate(Url);
}
/// <summary>
/// Show the web inspector.
/// </summary>
public void ShowInspector()
{
_core.ShowInspector();
}
/// <summary>
/// Navigates to the previous page in the page history, if available.
/// </summary>
/// <returns>Success value.</returns>
public bool GoBack()
{
return _core.GoBack();
}
/// <summary>
/// Navigates to the next page in the page history, if available.
/// </summary>
/// <returns>Success value.</returns>
public bool GoForward()
{
return _core.GoForward();
}
/// <summary>
/// Reloads the current web page.
/// </summary>
public void Reload()
{
_core.Reload();
}
/// <summary>
/// Reloads the current web page.
/// </summary>
/// <param name="Option">Options for reloading the page.</param>
public void Reload(WebBrowserRefreshOption Option)
{
_core.Reload(Option);
}
/// <summary>
/// Stops loading the current web page and any resources associated
/// with it.
/// </summary>
public void Stop()
{
_core.Stop();
}
/// <summary>
/// Returns the result of running a script.
/// </summary>
/// <param name="Script">The script to run.</param>
/// <returns></returns>
public string StringByEvaluatingJavaScriptFromString(string Script)
{
return _core.StringByEvaluatingJavaScriptFromString(Script);
}
/// <summary>
/// Gets the underlying WebKit WebView object used by this instance of WebKitBrowser.
/// </summary>
/// <returns>The WebView object.</returns>
public object GetWebView()
{
return _core.GetWebView();
}
/// <summary>
/// Gets the script context for the WebView.
/// </summary>
/// <returns>A JSCore.JSContext object representing the script context.</returns>
public object GetGlobalScriptContext()
{
return _core.GetGlobalScriptContext();
}
// printing methods
/// <summary>
/// Prints the document using the current print and page settings.
/// </summary>
public void Print()
{
_core.Print();
}
/// <summary>
/// Displays a Page Setup dialog box with the current page and print settings.
/// </summary>
public void ShowPageSetupDialog()
{
_core.ShowPageSetupDialog();
}
/// <summary>
/// Displays a Print dialog box.
/// </summary>
public void ShowPrintDialog()
{
_core.ShowPrintDialog();
}
/// <summary>
/// Displays a Print Preview dialog box.
/// </summary>
public void ShowPrintPreviewDialog()
{
_core.ShowPrintPreviewDialog();
}
#endregion Public Methods
IWebKitBrowserHost IWebKitBrowser.Host
{
get { return this; }
}
bool IWebKitBrowserHost.InDesignMode
{
get { return LicenseManager.UsageMode == LicenseUsageMode.Designtime; }
}
}
}
You can’t perform that action at this time.
