forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nsGlobalWindow.cpp
11159 lines (9101 loc) · 329 KB
/
nsGlobalWindow.cpp
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
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=2 et tw=78: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Brendan Eich <brendan@mozilla.org>
* David Hyatt (hyatt@netscape.com)
* Dan Rosen <dr@netscape.com>
* Vidur Apparao <vidur@netscape.com>
* Johnny Stenback <jst@netscape.com>
* Mark Hammond <mhammond@skippinet.com.au>
* Ryan Jones <sciguyryan@gmail.com>
* Jeff Walden <jwalden+code@mit.edu>
* Ben Bucksch <ben.bucksch beonex.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "base/basictypes.h"
// Local Includes
#include "nsGlobalWindow.h"
#include "nsScreen.h"
#include "nsHistory.h"
#include "nsBarProps.h"
#include "nsDOMStorage.h"
#include "nsDOMOfflineResourceList.h"
#include "nsDOMError.h"
// Helper Classes
#include "nsXPIDLString.h"
#include "nsJSUtils.h"
#include "prmem.h"
#include "jsapi.h" // for JSAutoRequest
#include "jsdbgapi.h" // for JS_ClearWatchPointsForObject
#include "jsfriendapi.h" // for JS_GetFrameScopeChainRaw
#include "nsReadableUtils.h"
#include "nsDOMClassInfo.h"
#include "nsJSEnvironment.h"
#include "nsCharSeparatedTokenizer.h" // for Accept-Language parsing
#include "nsUnicharUtils.h"
// Other Classes
#include "nsIEventListenerManager.h"
#include "nsEscape.h"
#include "nsStyleCoord.h"
#include "nsMimeTypeArray.h"
#include "nsNetUtil.h"
#include "nsICachingChannel.h"
#include "nsPluginArray.h"
#include "nsIPluginHost.h"
#include "nsPluginHost.h"
#include "nsIPluginInstanceOwner.h"
#include "nsGeolocation.h"
#include "nsDesktopNotification.h"
#include "nsContentCID.h"
#include "nsLayoutStatics.h"
#include "nsCycleCollector.h"
#include "nsCCUncollectableMarker.h"
#include "nsDOMThreadService.h"
#include "nsAutoJSValHolder.h"
#include "nsDOMMediaQueryList.h"
// Interfaces Needed
#include "nsIFrame.h"
#include "nsCanvasFrame.h"
#include "nsIWidget.h"
#include "nsIBaseWindow.h"
#include "nsDeviceMotion.h"
#include "nsIContent.h"
#include "nsIContentViewerEdit.h"
#include "nsIDocShell.h"
#include "nsIDocShellLoadInfo.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeNode.h"
#include "nsIEditorDocShell.h"
#include "nsIDocCharset.h"
#include "nsIDocument.h"
#include "nsIHTMLDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#ifndef MOZ_DISABLE_DOMCRYPTO
#include "nsIDOMCrypto.h"
#endif
#include "nsIDOMDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMessageEvent.h"
#include "nsIDOMPopupBlockedEvent.h"
#include "nsIDOMPopStateEvent.h"
#include "nsIDOMHashChangeEvent.h"
#include "nsIDOMOfflineResourceList.h"
#include "nsIDOMGeoGeolocation.h"
#include "nsIDOMDesktopNotification.h"
#include "nsPIDOMStorage.h"
#include "nsDOMString.h"
#include "nsIEmbeddingSiteWindow2.h"
#include "nsThreadUtils.h"
#include "nsEventStateManager.h"
#include "nsIHttpProtocolHandler.h"
#include "nsIJSContextStack.h"
#include "nsIJSRuntimeService.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIPrefBranch.h"
#include "nsIPresShell.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIProgrammingLanguage.h"
#include "nsIServiceManager.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptSecurityManager.h"
#include "nsIScrollableFrame.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsISelectionController.h"
#include "nsISelection.h"
#include "nsIPrompt.h"
#include "nsIPromptService.h"
#include "nsIPromptFactory.h"
#include "nsIWritablePropertyBag2.h"
#include "nsIWebNavigation.h"
#include "nsIWebBrowser.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWebBrowserFind.h" // For window.find()
#include "nsIWebContentHandlerRegistrar.h"
#include "nsIWindowMediator.h" // For window.find()
#include "nsComputedDOMStyle.h"
#include "nsIEntropyCollector.h"
#include "nsDOMCID.h"
#include "nsDOMError.h"
#include "nsDOMWindowUtils.h"
#include "nsIWindowWatcher.h"
#include "nsPIWindowWatcher.h"
#include "nsIContentViewer.h"
#include "nsDOMClassInfo.h"
#include "nsIJSNativeInitializer.h"
#include "nsIScriptError.h"
#include "nsIScriptEventManager.h" // For GetInterface()
#include "nsIConsoleService.h"
#include "nsIControllers.h"
#include "nsIControllerContext.h"
#include "nsGlobalWindowCommands.h"
#include "nsAutoPtr.h"
#include "nsContentUtils.h"
#include "nsCSSProps.h"
#include "nsFileDataProtocolHandler.h"
#include "nsIDOMFile.h"
#include "nsIURIFixup.h"
#include "mozilla/FunctionTimer.h"
#include "nsCDefaultURIFixup.h"
#include "nsEventDispatcher.h"
#include "nsIObserverService.h"
#include "nsIXULAppInfo.h"
#include "nsNetUtil.h"
#include "nsFocusManager.h"
#include "nsIXULWindow.h"
#include "nsEventStateManager.h"
#ifdef MOZ_XUL
#include "nsXULPopupManager.h"
#include "nsIDOMXULControlElement.h"
#include "nsIFrame.h"
#endif
#include "xpcprivate.h"
#ifdef NS_PRINTING
#include "nsIPrintSettings.h"
#include "nsIPrintSettingsService.h"
#include "nsIWebBrowserPrint.h"
#endif
#include "nsWindowRoot.h"
#include "nsNetCID.h"
#include "nsIArray.h"
#include "nsIScriptRuntime.h"
// XXX An unfortunate dependency exists here (two XUL files).
#include "nsIDOMXULDocument.h"
#include "nsIDOMXULCommandDispatcher.h"
#include "nsBindingManager.h"
#include "nsIXBLService.h"
// used for popup blocking, needs to be converted to something
// belonging to the back-end like nsIContentPolicy
#include "nsIPopupWindowManager.h"
#include "nsIDragService.h"
#include "mozilla/dom/Element.h"
#include "nsFrameLoader.h"
#include "nsISupportsPrimitives.h"
#include "nsXPCOMCID.h"
#include "mozilla/FunctionTimer.h"
#include "mozIThirdPartyUtil.h"
#ifdef MOZ_LOGGING
// so we can get logging even in release builds
#define FORCE_PR_LOG 1
#endif
#include "prlog.h"
#include "mozilla/dom/indexedDB/IDBFactory.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "nsRefreshDriver.h"
#include "mozAutoDocUpdate.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gDOMLeakPRLog;
#endif
static const char kStorageEnabled[] = "dom.storage.enabled";
using namespace mozilla::dom;
using mozilla::TimeStamp;
using mozilla::TimeDuration;
nsIDOMStorageList *nsGlobalWindow::sGlobalStorageList = nsnull;
nsGlobalWindow::WindowByIdTable *nsGlobalWindow::sOuterWindowsById = nsnull;
static nsIEntropyCollector *gEntropyCollector = nsnull;
static PRInt32 gRefCnt = 0;
static PRInt32 gOpenPopupSpamCount = 0;
static PopupControlState gPopupControlState = openAbused;
static PRInt32 gRunningTimeoutDepth = 0;
static PRPackedBool gMouseDown = PR_FALSE;
static PRPackedBool gDragServiceDisabled = PR_FALSE;
static FILE *gDumpFile = nsnull;
static PRUint64 gNextWindowID = 0;
static PRUint32 gSerialCounter = 0;
#ifdef DEBUG_jst
PRInt32 gTimeoutCnt = 0;
#endif
#if !(defined(NS_DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
static PRBool gDOMWindowDumpEnabled = PR_FALSE;
#endif
#if defined(DEBUG_bryner) || defined(DEBUG_chb)
#define DEBUG_PAGE_CACHE
#endif
// The default shortest interval/timeout we permit
#define DEFAULT_MIN_TIMEOUT_VALUE 4 // 4ms
#define DEFAULT_MIN_BACKGROUND_TIMEOUT_VALUE 1000 // 1000ms
static PRInt32 gMinTimeoutValue;
static PRInt32 gMinBackgroundTimeoutValue;
inline PRInt32
nsGlobalWindow::DOMMinTimeoutValue() const {
PRBool isBackground = !mOuterWindow || mOuterWindow->IsBackground();
return
NS_MAX(isBackground ? gMinBackgroundTimeoutValue : gMinTimeoutValue, 0);
}
// The number of nested timeouts before we start clamping. HTML5 says 1, WebKit
// uses 5.
#define DOM_CLAMP_TIMEOUT_NESTING_LEVEL 5
// The longest interval (as PRIntervalTime) we permit, or that our
// timer code can handle, really. See DELAY_INTERVAL_LIMIT in
// nsTimerImpl.h for details.
#define DOM_MAX_TIMEOUT_VALUE DELAY_INTERVAL_LIMIT
#define FORWARD_TO_OUTER(method, args, err_rval) \
PR_BEGIN_MACRO \
if (IsInnerWindow()) { \
nsGlobalWindow *outer = GetOuterWindowInternal(); \
if (!outer) { \
NS_WARNING("No outer window available!"); \
return err_rval; \
} \
return outer->method args; \
} \
PR_END_MACRO
#define FORWARD_TO_OUTER_VOID(method, args) \
PR_BEGIN_MACRO \
if (IsInnerWindow()) { \
nsGlobalWindow *outer = GetOuterWindowInternal(); \
if (!outer) { \
NS_WARNING("No outer window available!"); \
return; \
} \
outer->method args; \
return; \
} \
PR_END_MACRO
#define FORWARD_TO_OUTER_CHROME(method, args, err_rval) \
PR_BEGIN_MACRO \
if (IsInnerWindow()) { \
nsGlobalWindow *outer = GetOuterWindowInternal(); \
if (!outer) { \
NS_WARNING("No outer window available!"); \
return err_rval; \
} \
return ((nsGlobalChromeWindow *)outer)->method args; \
} \
PR_END_MACRO
#define FORWARD_TO_INNER_CHROME(method, args, err_rval) \
PR_BEGIN_MACRO \
if (IsOuterWindow()) { \
if (!mInnerWindow) { \
NS_WARNING("No inner window available!"); \
return err_rval; \
} \
return ((nsGlobalChromeWindow *)mInnerWindow)->method args; \
} \
PR_END_MACRO
#define FORWARD_TO_OUTER_MODAL_CONTENT_WINDOW(method, args, err_rval) \
PR_BEGIN_MACRO \
if (IsInnerWindow()) { \
nsGlobalWindow *outer = GetOuterWindowInternal(); \
if (!outer) { \
NS_WARNING("No outer window available!"); \
return err_rval; \
} \
return ((nsGlobalModalWindow *)outer)->method args; \
} \
PR_END_MACRO
#define FORWARD_TO_INNER(method, args, err_rval) \
PR_BEGIN_MACRO \
if (IsOuterWindow()) { \
if (!mInnerWindow) { \
NS_WARNING("No inner window available!"); \
return err_rval; \
} \
return GetCurrentInnerWindowInternal()->method args; \
} \
PR_END_MACRO
#define FORWARD_TO_INNER_MODAL_CONTENT_WINDOW(method, args, err_rval) \
PR_BEGIN_MACRO \
if (IsOuterWindow()) { \
if (!mInnerWindow) { \
NS_WARNING("No inner window available!"); \
return err_rval; \
} \
return ((nsGlobalModalWindow*)GetCurrentInnerWindowInternal())->method args; \
} \
PR_END_MACRO
#define FORWARD_TO_INNER_VOID(method, args) \
PR_BEGIN_MACRO \
if (IsOuterWindow()) { \
if (!mInnerWindow) { \
NS_WARNING("No inner window available!"); \
return; \
} \
GetCurrentInnerWindowInternal()->method args; \
return; \
} \
PR_END_MACRO
// Same as FORWARD_TO_INNER, but this will create a fresh inner if an
// inner doesn't already exists.
#define FORWARD_TO_INNER_CREATE(method, args, err_rval) \
PR_BEGIN_MACRO \
if (IsOuterWindow()) { \
if (!mInnerWindow) { \
if (mIsClosed) { \
return err_rval; \
} \
nsCOMPtr<nsIDOMDocument> doc; \
nsresult fwdic_nr = GetDocument(getter_AddRefs(doc)); \
NS_ENSURE_SUCCESS(fwdic_nr, err_rval); \
if (!mInnerWindow) { \
return err_rval; \
} \
} \
return GetCurrentInnerWindowInternal()->method args; \
} \
PR_END_MACRO
// CIDs
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
static const char sJSStackContractID[] = "@mozilla.org/js/xpc/ContextStack;1";
#ifndef MOZ_DISABLE_DOMCRYPTO
static const char kCryptoContractID[] = NS_CRYPTO_CONTRACTID;
static const char kPkcs11ContractID[] = NS_PKCS11_CONTRACTID;
#endif
static const char sPopStatePrefStr[] = "browser.history.allowPopState";
static PRBool
IsAboutBlank(nsIURI* aURI)
{
NS_PRECONDITION(aURI, "Must have URI");
// GetSpec can be expensive for some URIs, so check the scheme first.
PRBool isAbout = PR_FALSE;
if (NS_FAILED(aURI->SchemeIs("about", &isAbout)) || !isAbout) {
return PR_FALSE;
}
nsCAutoString str;
aURI->GetSpec(str);
return str.EqualsLiteral("about:blank");
}
class nsDummyJavaPluginOwner : public nsIPluginInstanceOwner
{
public:
nsDummyJavaPluginOwner(nsIDocument *aDocument)
: mDocument(aDocument)
{
}
void Destroy();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIPLUGININSTANCEOWNER
NS_IMETHOD GetURL(const char *aURL, const char *aTarget,
nsIInputStream *aPostStream,
void *aHeadersData, PRUint32 aHeadersDataLen);
NS_IMETHOD ShowStatus(const PRUnichar *aStatusMsg);
NPError ShowNativeContextMenu(NPMenu* menu, void* event);
NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace);
void SendIdleEvent();
NS_DECL_CYCLE_COLLECTION_CLASS(nsDummyJavaPluginOwner)
private:
nsRefPtr<nsNPAPIPluginInstance> mInstance;
nsCOMPtr<nsIDocument> mDocument;
};
NS_IMPL_CYCLE_COLLECTION_2(nsDummyJavaPluginOwner, mDocument, mInstance)
// QueryInterface implementation for nsDummyJavaPluginOwner
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDummyJavaPluginOwner)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIPluginInstanceOwner)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDummyJavaPluginOwner)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDummyJavaPluginOwner)
void
nsDummyJavaPluginOwner::Destroy()
{
// If we have a plugin instance, stop it and destroy it now.
if (mInstance) {
mInstance->Stop();
mInstance->InvalidateOwner();
mInstance = nsnull;
}
mDocument = nsnull;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::SetInstance(nsNPAPIPluginInstance *aInstance)
{
// If we're going to null out mInstance after use, be sure to call
// mInstance->InvalidateOwner() here, since it now won't be called
// from nsDummyJavaPluginOwner::Destroy().
if (mInstance && !aInstance)
mInstance->InvalidateOwner();
mInstance = aInstance;
return NS_OK;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::GetInstance(nsNPAPIPluginInstance **aInstance)
{
NS_IF_ADDREF(mInstance);
*aInstance = mInstance;
return NS_OK;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::GetWindow(NPWindow *&aWindow)
{
aWindow = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::SetWindow()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::GetMode(PRInt32 *aMode)
{
// This is wrong, but there's no better alternative.
*aMode = NP_EMBED;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::CreateWidget(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::GetURL(const char *aURL, const char *aTarget,
nsIInputStream *aPostStream,
void *aHeadersData, PRUint32 aHeadersDataLen)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::ShowStatus(const char *aStatusMsg)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::ShowStatus(const PRUnichar *aStatusMsg)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NPError
nsDummyJavaPluginOwner::ShowNativeContextMenu(NPMenu* menu, void* event)
{
return NPERR_GENERIC_ERROR;
}
NPBool
nsDummyJavaPluginOwner::ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace)
{
return PR_FALSE;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::GetDocument(nsIDocument **aDocument)
{
NS_IF_ADDREF(*aDocument = mDocument);
return NS_OK;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::InvalidateRect(NPRect *invalidRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::InvalidateRegion(NPRegion invalidRegion)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::ForceRedraw()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::GetNetscapeWindow(void *value)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDummyJavaPluginOwner::SetEventModel(PRInt32 eventModel)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
nsDummyJavaPluginOwner::SendIdleEvent()
{
}
/**
* An object implementing the window.URL property.
*/
class nsDOMMozURLProperty : public nsIDOMMozURLProperty
{
public:
nsDOMMozURLProperty(nsGlobalWindow* aWindow)
: mWindow(aWindow)
{
}
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMOZURLPROPERTY
void ClearWindowReference() {
mWindow = nsnull;
}
private:
nsGlobalWindow* mWindow;
};
DOMCI_DATA(MozURLProperty, nsDOMMozURLProperty)
NS_IMPL_ADDREF(nsDOMMozURLProperty)
NS_IMPL_RELEASE(nsDOMMozURLProperty)
NS_INTERFACE_MAP_BEGIN(nsDOMMozURLProperty)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozURLProperty)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMozURLProperty)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozURLProperty)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsDOMMozURLProperty::CreateObjectURL(nsIDOMBlob* aBlob, nsAString& aURL)
{
NS_PRECONDITION(!mWindow || mWindow->IsInnerWindow(),
"Should be inner window");
NS_ENSURE_STATE(mWindow && mWindow->mDoc);
NS_ENSURE_ARG_POINTER(aBlob);
nsIDocument* doc = mWindow->mDoc;
nsresult rv = aBlob->GetInternalUrl(doc->NodePrincipal(), aURL);
NS_ENSURE_SUCCESS(rv, rv);
doc->RegisterFileDataUri(NS_LossyConvertUTF16toASCII(aURL));
return NS_OK;
}
NS_IMETHODIMP
nsDOMMozURLProperty::RevokeObjectURL(const nsAString& aURL)
{
NS_PRECONDITION(!mWindow || mWindow->IsInnerWindow(),
"Should be inner window");
NS_ENSURE_STATE(mWindow);
NS_LossyConvertUTF16toASCII asciiurl(aURL);
nsIPrincipal* winPrincipal = mWindow->GetPrincipal();
if (!winPrincipal) {
return NS_OK;
}
nsIPrincipal* principal =
nsFileDataProtocolHandler::GetFileDataEntryPrincipal(asciiurl);
PRBool subsumes;
if (principal && winPrincipal &&
NS_SUCCEEDED(winPrincipal->Subsumes(principal, &subsumes)) &&
subsumes) {
if (mWindow->mDoc) {
mWindow->mDoc->UnregisterFileDataUri(asciiurl);
}
nsFileDataProtocolHandler::RemoveFileDataEntry(asciiurl);
}
return NS_OK;
}
/**
* An indirect observer object that means we don't have to implement nsIObserver
* on nsGlobalWindow, where any script could see it.
*/
class nsGlobalWindowObserver : public nsIObserver {
public:
nsGlobalWindowObserver(nsGlobalWindow* aWindow) : mWindow(aWindow) {}
NS_DECL_ISUPPORTS
NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData)
{
if (!mWindow)
return NS_OK;
return mWindow->Observe(aSubject, aTopic, aData);
}
void Forget() { mWindow = nsnull; }
private:
nsGlobalWindow* mWindow;
};
NS_IMPL_ISUPPORTS1(nsGlobalWindowObserver, nsIObserver)
nsTimeout::nsTimeout()
{
#ifdef DEBUG_jst
{
extern int gTimeoutCnt;
++gTimeoutCnt;
}
#endif
memset(this, 0, sizeof(*this));
MOZ_COUNT_CTOR(nsTimeout);
}
nsTimeout::~nsTimeout()
{
#ifdef DEBUG_jst
{
extern int gTimeoutCnt;
--gTimeoutCnt;
}
#endif
MOZ_COUNT_DTOR(nsTimeout);
}
NS_IMPL_CYCLE_COLLECTION_CLASS(nsTimeout)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(nsTimeout)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsTimeout)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mWindow,
nsIScriptGlobalObject)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptHandler)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTimeout, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTimeout, Release)
nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindow *aOuterWindow)
: mFrameElement(nsnull), mDocShell(nsnull), mModalStateDepth(0),
mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE),
mIsHandlingResizeEvent(PR_FALSE), mIsInnerWindow(aOuterWindow != nsnull),
mMayHavePaintEventListener(PR_FALSE), mMayHaveTouchEventListener(PR_FALSE),
mMayHaveAudioAvailableEventListener(PR_FALSE), mIsModalContentWindow(PR_FALSE),
mIsActive(PR_FALSE), mIsBackground(PR_FALSE),
mInnerWindow(nsnull), mOuterWindow(aOuterWindow),
// Make sure no actual window ends up with mWindowID == 0
mWindowID(++gNextWindowID), mHasNotifiedGlobalCreated(PR_FALSE)
{}
nsPIDOMWindow::~nsPIDOMWindow() {}
//*****************************************************************************
// nsOuterWindowProxy: Outer Window Proxy
//*****************************************************************************
JSString *
nsOuterWindowProxy::obj_toString(JSContext *cx, JSObject *proxy)
{
JS_ASSERT(proxy->isProxy());
return JS_NewStringCopyZ(cx, "[object Window]");
}
nsOuterWindowProxy
nsOuterWindowProxy::singleton;
JSObject *
NS_NewOuterWindowProxy(JSContext *cx, JSObject *parent)
{
JSAutoEnterCompartment ac;
if (!ac.enter(cx, parent)) {
return nsnull;
}
JSObject *obj = JSWrapper::New(cx, parent, parent->getProto(), parent,
&nsOuterWindowProxy::singleton);
NS_ASSERTION(obj->getClass()->ext.innerObject, "bad class");
return obj;
}
//*****************************************************************************
//*** nsGlobalWindow: Object Management
//*****************************************************************************
nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
: nsPIDOMWindow(aOuterWindow),
mIsFrozen(PR_FALSE),
mDidInitJavaProperties(PR_FALSE),
mFullScreen(PR_FALSE),
mIsClosed(PR_FALSE),
mInClose(PR_FALSE),
mHavePendingClose(PR_FALSE),
mHadOriginalOpener(PR_FALSE),
mIsPopupSpam(PR_FALSE),
mBlockScriptedClosingFlag(PR_FALSE),
mFireOfflineStatusChangeEventOnThaw(PR_FALSE),
mCreatingInnerWindow(PR_FALSE),
mIsChrome(PR_FALSE),
mCleanMessageManager(PR_FALSE),
mNeedsFocus(PR_TRUE),
mHasFocus(PR_FALSE),
#if defined(XP_MACOSX)
mShowAccelerators(PR_FALSE),
mShowFocusRings(PR_FALSE),
#else
mShowAccelerators(PR_TRUE),
mShowFocusRings(PR_TRUE),
#endif
mShowFocusRingForContent(PR_FALSE),
mFocusByKeyOccurred(PR_FALSE),
mHasDeviceMotion(PR_FALSE),
mNotifiedIDDestroyed(PR_FALSE),
mTimeoutInsertionPoint(nsnull),
mTimeoutPublicIdCounter(1),
mTimeoutFiringDepth(0),
mJSObject(nsnull),
mPendingStorageEventsObsolete(nsnull),
mTimeoutsSuspendDepth(0),
mFocusMethod(0),
mSerial(0),
#ifdef DEBUG
mSetOpenerWindowCalled(PR_FALSE),
#endif
mCleanedUp(PR_FALSE),
mCallCleanUpAfterModalDialogCloses(PR_FALSE),
mDialogAbuseCount(0),
mDialogDisabled(PR_FALSE)
{
nsLayoutStatics::AddRef();
// Initialize the PRCList (this).
PR_INIT_CLIST(this);
// Initialize timeout storage
PR_INIT_CLIST(&mTimeouts);
if (aOuterWindow) {
// |this| is an inner window, add this inner window to the outer
// window list of inners.
PR_INSERT_AFTER(this, aOuterWindow);
mObserver = new nsGlobalWindowObserver(this);
if (mObserver) {
NS_ADDREF(mObserver);
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
// Watch for online/offline status changes so we can fire events. Use
// a strong reference.
os->AddObserver(mObserver, NS_IOSERVICE_OFFLINE_STATUS_TOPIC,
PR_FALSE);
// Watch for dom-storage-changed so we can fire storage
// events. Use a strong reference.
os->AddObserver(mObserver, "dom-storage2-changed", PR_FALSE);
os->AddObserver(mObserver, "dom-storage-changed", PR_FALSE);
}
}
} else {
// |this| is an outer window. Outer windows start out frozen and
// remain frozen until they get an inner window, so freeze this
// outer window here.
Freeze();
mObserver = nsnull;
SetIsProxy();
if (!sOuterWindowsById) {
sOuterWindowsById = new WindowByIdTable();
if (!sOuterWindowsById->Init()) {
delete sOuterWindowsById;
sOuterWindowsById = nsnull;
}
}
if (sOuterWindowsById) {
sOuterWindowsById->Put(mWindowID, this);
}
}
// We could have failed the first time through trying
// to create the entropy collector, so we should
// try to get one until we succeed.
gRefCnt++;
if (gRefCnt == 1) {
#if !(defined(NS_DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
nsContentUtils::AddBoolPrefVarCache("browser.dom.window.dump.enabled",
&gDOMWindowDumpEnabled);
#endif
nsContentUtils::AddIntPrefVarCache("dom.min_timeout_value",
&gMinTimeoutValue,
DEFAULT_MIN_TIMEOUT_VALUE);
nsContentUtils::AddIntPrefVarCache("dom.min_background_timeout_value",
&gMinBackgroundTimeoutValue,
DEFAULT_MIN_BACKGROUND_TIMEOUT_VALUE);
}
if (gDumpFile == nsnull) {
const nsAdoptingCString& fname =
nsContentUtils::GetCharPref("browser.dom.window.dump.file");
if (!fname.IsEmpty()) {
// if this fails to open, Dump() knows to just go to stdout
// on null.
gDumpFile = fopen(fname, "wb+");
} else {
gDumpFile = stdout;
}
}
if (!gEntropyCollector) {
CallGetService(NS_ENTROPYCOLLECTOR_CONTRACTID, &gEntropyCollector);
}
mSerial = ++gSerialCounter;
#ifdef DEBUG
printf("++DOMWINDOW == %d (%p) [serial = %d] [outer = %p]\n", gRefCnt,
static_cast<void*>(static_cast<nsIScriptGlobalObject*>(this)),
gSerialCounter, static_cast<void*>(aOuterWindow));
#endif
#ifdef PR_LOGGING
if (!gDOMLeakPRLog)
gDOMLeakPRLog = PR_NewLogModule("DOMLeak");
if (gDOMLeakPRLog)
PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG,
("DOMWINDOW %p created outer=%p", this, aOuterWindow));
#endif
}
nsGlobalWindow::~nsGlobalWindow()
{
if (sOuterWindowsById) {
sOuterWindowsById->Remove(mWindowID);
}
if (!--gRefCnt) {
NS_IF_RELEASE(gEntropyCollector);
delete sOuterWindowsById;
sOuterWindowsById = nsnull;
}
#ifdef DEBUG
nsCAutoString url;
if (mLastOpenedURI) {
mLastOpenedURI->GetSpec(url);
}
printf("--DOMWINDOW == %d (%p) [serial = %d] [outer = %p] [url = %s]\n",
gRefCnt, static_cast<void*>(static_cast<nsIScriptGlobalObject*>(this)),
mSerial, static_cast<void*>(mOuterWindow.get()), url.get());
#endif
#ifdef PR_LOGGING
if (gDOMLeakPRLog)
PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG,
("DOMWINDOW %p destroyed", this));
#endif
if (IsOuterWindow()) {
// An outer window is destroyed with inner windows still possibly
// alive, iterate through the inner windows and null out their
// back pointer to this outer, and pull them out of the list of
// inner windows.
nsGlobalWindow *w;
while ((w = (nsGlobalWindow *)PR_LIST_HEAD(this)) != this) {
PR_REMOVE_AND_INIT_LINK(w);
}
} else {
if (mListenerManager) {
mListenerManager->Disconnect();
mListenerManager = nsnull;
}
// An inner window is destroyed, pull it out of the outer window's
// list if inner windows.
PR_REMOVE_LINK(this);