Attachment #182197: pref'd off patch, with some review comments addressed for bug #274784

View | Details | Raw Unified | Return to bug 274784
Collapse All | Expand All

(-)accessible/src/base/nsAccessNode.cpp (-1 / +3 lines)
Line     Link Here 
 Lines 498-504   nsAccessNode::GetDocShellTreeItemFor(nsI Link Here 
498
  NS_ASSERTION(doc, "No document for node passed in");
498
  NS_ASSERTION(doc, "No document for node passed in");
499
  nsCOMPtr<nsISupports> container = doc->GetContainer();
499
  nsCOMPtr<nsISupports> container = doc->GetContainer();
500
  nsIDocShellTreeItem *docShellTreeItem = nsnull;
500
  nsIDocShellTreeItem *docShellTreeItem = nsnull;
501
  CallQueryInterface(container, &docShellTreeItem);
501
  if (container) {
502
    CallQueryInterface(container, &docShellTreeItem);
503
  }
502
504
503
  return docShellTreeItem;
505
  return docShellTreeItem;
504
}
506
}
(-)content/base/public/nsIDocument.h (-3 / +30 lines)
Line     Link Here 
 Lines 88-97   class nsHTMLStyleSheet; Link Here 
88
class nsIHTMLCSSStyleSheet;
88
class nsIHTMLCSSStyleSheet;
89
89
90
// IID for the nsIDocument interface
90
// IID for the nsIDocument interface
91
// f01b47c6-6271-4c0d-b786-eb5eee222b45
92
#define NS_IDOCUMENT_IID      \
91
#define NS_IDOCUMENT_IID      \
93
{ 0xf01b47c6, 0x6271, 0x4c0d, \
92
{ 0x8bc6ae5f, 0xb396, 0x11d9, \
94
  { 0xb7, 0x86, 0xeb, 0x5e, 0xee, 0x22, 0x2b, 0x45 } }
93
  { 0xb1, 0x4f, 0x00, 0x11, 0x24, 0x78, 0xd6, 0x26 } }
95
94
96
// The base value for the content ID counter.
95
// The base value for the content ID counter.
97
// This counter is used by the document to 
96
// This counter is used by the document to 
 Lines 665-670   public: Link Here 
665
    return mPartID;
664
    return mPartID;
666
  }
665
  }
667
666
667
  /**
668
   * Sanitize the document by resetting all input elements and forms that have
669
   * autocomplete=off to their default values.
670
   */
671
  virtual nsresult Sanitize() = 0;
672
673
  /**
674
   * Enumerate all subdocuments.
675
   * The enumerator callback should return PR_TRUE to continue enumerating, or
676
   * PR_FALSE to stop.
677
   */
678
  typedef PRBool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
679
  virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
680
                                     void *aData) = 0;
681
682
  /**
683
   * Check whether there are any requests in our loadgroup or the loadgroups
684
   * of any child documents, recursively.  aIgnoreRequest may be set to a
685
   * specific request to ignore (it can be null).
686
   */
687
  virtual PRBool HasRequests(nsIRequest *aIgnoreRequest) = 0;
688
689
  /**
690
   * Notify the document that its associated ContentViewer is being destroyed.
691
   * This releases circular references so that the document can go away.
692
   */
693
  virtual void Destroy() = 0;
694
668
protected:
695
protected:
669
  ~nsIDocument()
696
  ~nsIDocument()
670
  {
697
  {
(-)content/base/src/nsDocument.cpp (-31 / +202 lines)
Line     Link Here 
 Lines 126-131   static NS_DEFINE_CID(kDOMEventGroupCID, Link Here 
126
126
127
#include "nsIScriptContext.h"
127
#include "nsIScriptContext.h"
128
#include "nsBindingManager.h"
128
#include "nsBindingManager.h"
129
#include "nsIDOMHTMLFormElement.h"
130
#include "nsIRequest.h"
129
131
130
#include "nsICharsetAlias.h"
132
#include "nsICharsetAlias.h"
131
static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
133
static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
 Lines 1851-1887   nsDocument::GetScriptGlobalObject() cons Link Here 
1851
void
1853
void
1852
nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
1854
nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
1853
{
1855
{
1854
  // XXX HACK ALERT! If the script context owner is null, the document
1855
  // will soon be going away. So tell our content that to lose its
1856
  // reference to the document. This has to be done before we actually
1857
  // set the script context owner to null so that the content elements
1858
  // can remove references to their script objects.
1859
  if (!aScriptGlobalObject) {
1860
    PRInt32 count, indx;
1861
1862
    count = mChildren.Count();
1863
1864
    mIsGoingAway = PR_TRUE;
1865
1866
    for (indx = 0; indx < count; ++indx) {
1867
      mChildren[indx]->UnbindFromTree();
1868
    }
1869
1870
    // Propagate the out-of-band notification to each PresShell's
1871
    // anonymous content as well. This ensures that there aren't any
1872
    // accidental script references left in anonymous content keeping
1873
    // the document alive. (While not strictly necessary -- the
1874
    // PresShell owns us -- it's tidy.)
1875
    for (count = mPresShells.Count() - 1; count >= 0; --count) {
1876
      nsCOMPtr<nsIPresShell> shell =
1877
        NS_STATIC_CAST(nsIPresShell*, mPresShells[count]);
1878
      if (!shell)
1879
        continue;
1880
1881
      shell->ReleaseAnonymousContent();
1882
    }
1883
  }
1884
1885
  mScriptGlobalObject = aScriptGlobalObject;
1856
  mScriptGlobalObject = aScriptGlobalObject;
1886
}
1857
}
1887
1858
 Lines 4602-4604   nsDocument::UnsetProperty(nsIAtom *aProp Link Here 
4602
{
4573
{
4603
  return mPropertyTable.UnsetProperty(this, aPropertyName, aStatus);
4574
  return mPropertyTable.UnsetProperty(this, aPropertyName, aStatus);
4604
}
4575
}
4576
4577
nsresult
4578
nsDocument::Sanitize()
4579
{
4580
  // Sanitize the document by resetting all password fields and any form
4581
  // fields with autocomplete=off to their default values.  We do this now,
4582
  // instead of when the presentation is restored, to offer some protection
4583
  // in case there is ever an exploit that allows a cached document to be
4584
  // accessed from a different document.
4585
4586
  // First locate all input elements, regardless of whether they are
4587
  // in a form, and reset the password and autocomplete=off elements.
4588
4589
  nsCOMPtr<nsIDOMNodeList> nodes;
4590
  nsresult rv = GetElementsByTagName(NS_LITERAL_STRING("input"),
4591
                                     getter_AddRefs(nodes));
4592
  NS_ENSURE_SUCCESS(rv, rv);
4593
4594
  PRUint32 length = 0;
4595
  if (nodes)
4596
    nodes->GetLength(&length);
4597
4598
  nsCOMPtr<nsIDOMNode> item;
4599
  nsAutoString value;
4600
  PRUint32 i;
4601
4602
  for (i = 0; i < length; ++i) {
4603
    nodes->Item(i, getter_AddRefs(item));
4604
    NS_ASSERTION(item, "null item in node list!");
4605
4606
    nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(item);
4607
    if (!input)
4608
      continue;
4609
4610
    PRBool resetValue = PR_FALSE;
4611
4612
    input->GetAttribute(NS_LITERAL_STRING("autocomplete"), value);
4613
    if (value.LowerCaseEqualsLiteral("off")) {
4614
      resetValue = PR_TRUE;
4615
    } else {
4616
      input->GetType(value);
4617
      if (value.LowerCaseEqualsLiteral("password"))
4618
        resetValue = PR_TRUE;
4619
    }
4620
4621
    if (resetValue) {
4622
      nsCOMPtr<nsIFormControl> fc = do_QueryInterface(input);
4623
      fc->Reset();
4624
    }
4625
  }
4626
4627
  // Now locate all _form_ elements that have autocomplete=off and reset them
4628
  rv = GetElementsByTagName(NS_LITERAL_STRING("form"), getter_AddRefs(nodes));
4629
  NS_ENSURE_SUCCESS(rv, rv);
4630
4631
  length = 0;
4632
  if (nodes)
4633
    nodes->GetLength(&length);
4634
4635
  for (i = 0; i < length; ++i) {
4636
    nodes->Item(i, getter_AddRefs(item));
4637
    NS_ASSERTION(item, "null item in nodelist");
4638
4639
    nsCOMPtr<nsIDOMHTMLFormElement> form = do_QueryInterface(item);
4640
    if (!form)
4641
      continue;
4642
4643
    form->GetAttribute(NS_LITERAL_STRING("autocomplete"), value);
4644
    if (value.LowerCaseEqualsLiteral("off"))
4645
      form->Reset();
4646
  }
4647
4648
  return NS_OK;
4649
}
4650
4651
struct SubDocEnumArgs
4652
{
4653
  nsIDocument::nsSubDocEnumFunc callback;
4654
  void *data;
4655
};
4656
4657
PR_STATIC_CALLBACK(PLDHashOperator)
4658
SubDocHashEnum(PLDHashTable *table, PLDHashEntryHdr *hdr,
4659
               PRUint32 number, void *arg)
4660
{
4661
  SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr);
4662
  SubDocEnumArgs *args = NS_STATIC_CAST(SubDocEnumArgs*, arg);
4663
4664
  nsIDocument *subdoc = entry->mSubDocument;
4665
  PRBool next = PR_TRUE;
4666
4667
  if (subdoc)
4668
    next = args->callback(subdoc, args->data);
4669
4670
  return next ? PL_DHASH_NEXT : PL_DHASH_STOP;
4671
}
4672
4673
void
4674
nsDocument::EnumerateSubDocuments(nsSubDocEnumFunc aCallback, void *aData)
4675
{
4676
  if (mSubDocuments) {
4677
    SubDocEnumArgs args = { aCallback, aData };
4678
    PL_DHashTableEnumerate(mSubDocuments, SubDocHashEnum, &args);
4679
  }
4680
}
4681
4682
PR_STATIC_CALLBACK(PLDHashOperator)
4683
SubDocHasRequests(PLDHashTable *table, PLDHashEntryHdr *hdr,
4684
                  PRUint32 number, void *arg)
4685
{
4686
  SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr);
4687
  PRBool *hasRequests = NS_STATIC_CAST(PRBool*, arg);
4688
4689
  nsIDocument *subdoc = entry->mSubDocument;
4690
4691
  // The aIgnoreRequest we were passed is only for us, so don't pass it on.
4692
  PRBool hasRequest = subdoc ? subdoc->HasRequests(nsnull) : PR_FALSE;
4693
  if (hasRequest) {
4694
    *hasRequests = PR_TRUE;
4695
    return PL_DHASH_STOP;
4696
  }
4697
4698
  return PL_DHASH_NEXT;
4699
}
4700
4701
#ifdef DEBUG_bryner
4702
#define DEBUG_PAGE_CACHE
4703
#endif
4704
4705
PRBool
4706
nsDocument::HasRequests(nsIRequest *aIgnoreRequest)
4707
{
4708
  nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
4709
  if (loadGroup) {
4710
    nsCOMPtr<nsISimpleEnumerator> requests;
4711
    loadGroup->GetRequests(getter_AddRefs(requests));
4712
4713
    PRBool hasMore = PR_FALSE;
4714
    nsCOMPtr<nsISupports> elem;
4715
    nsCOMPtr<nsIRequest> request;
4716
4717
    while (NS_SUCCEEDED(requests->HasMoreElements(&hasMore)) && hasMore) {
4718
      requests->GetNext(getter_AddRefs(elem));
4719
      request = do_QueryInterface(elem);
4720
      if (request && request != aIgnoreRequest) {
4721
#ifdef DEBUG_PAGE_CACHE
4722
        nsCAutoString requestName, docSpec;
4723
        request->GetName(requestName);
4724
        if (mDocumentURI)
4725
          mDocumentURI->GetSpec(docSpec);
4726
4727
        printf("document %s has request %s\n",
4728
               docSpec.get(), requestName.get());
4729
#endif
4730
        return PR_TRUE;
4731
      }
4732
    }
4733
  }
4734
4735
  PRBool subDocsHaveRequests = PR_FALSE;
4736
  if (mSubDocuments) {
4737
    PL_DHashTableEnumerate(mSubDocuments, SubDocHasRequests,
4738
                           &subDocsHaveRequests);
4739
  }
4740
4741
  return subDocsHaveRequests;
4742
}
4743
4744
void
4745
nsDocument::Destroy()
4746
{
4747
  // XXX HACK ALERT! If the script context owner is null, the document
4748
  // will soon be going away. So tell our content that to lose its
4749
  // reference to the document. This has to be done before we actually
4750
  // set the script context owner to null so that the content elements
4751
  // can remove references to their script objects.
4752
  PRInt32 count, indx;
4753
4754
  count = mChildren.Count();
4755
4756
  mIsGoingAway = PR_TRUE;
4757
4758
  for (indx = 0; indx < count; ++indx) {
4759
    mChildren[indx]->UnbindFromTree();
4760
  }
4761
4762
  // Propagate the out-of-band notification to each PresShell's
4763
  // anonymous content as well. This ensures that there aren't any
4764
  // accidental script references left in anonymous content keeping
4765
  // the document alive. (While not strictly necessary -- the
4766
  // PresShell owns us -- it's tidy.)
4767
  for (count = mPresShells.Count() - 1; count >= 0; --count) {
4768
    nsCOMPtr<nsIPresShell> shell =
4769
      NS_STATIC_CAST(nsIPresShell*, mPresShells[count]);
4770
    if (!shell)
4771
      continue;
4772
4773
    shell->ReleaseAnonymousContent();
4774
  }
4775
}
(-)content/base/src/nsDocument.h (-1 / +10 lines)
Line     Link Here 
 Lines 530-535   public: Link Here 
530
  virtual NS_HIDDEN_(void*) UnsetProperty(nsIAtom  *aPropertyName,
530
  virtual NS_HIDDEN_(void*) UnsetProperty(nsIAtom  *aPropertyName,
531
                                          nsresult *aStatus = nsnull);
531
                                          nsresult *aStatus = nsnull);
532
532
533
  virtual NS_HIDDEN_(nsresult) Sanitize();
534
535
  virtual NS_HIDDEN_(void) EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
536
                                                 void *aData);
537
538
  virtual NS_HIDDEN_(PRBool) HasRequests(nsIRequest *aIgnoreRequest);
539
540
  virtual NS_HIDDEN_(void) Destroy();
541
533
protected:
542
protected:
534
543
535
  void RetrieveRelevantHeaders(nsIChannel *aChannel);
544
  void RetrieveRelevantHeaders(nsIChannel *aChannel);
 Lines 592-598   protected: Link Here 
592
601
593
  nsHashtable mRadioGroups;
602
  nsHashtable mRadioGroups;
594
603
595
  // True if the document is being destroyed.
604
  // True if the document has been detached from its content viewer.
596
  PRPackedBool mIsGoingAway;
605
  PRPackedBool mIsGoingAway;
597
606
598
  // True if the document is being destroyed.
607
  // True if the document is being destroyed.
(-)content/base/src/nsSyncLoadService.cpp (+20 lines)
Line     Link Here 
 Lines 120-125   public: Link Here 
120
    NS_IMETHOD Unload(nsIDOMEvent* aEvent);
120
    NS_IMETHOD Unload(nsIDOMEvent* aEvent);
121
    NS_IMETHOD Abort(nsIDOMEvent* aEvent);
121
    NS_IMETHOD Abort(nsIDOMEvent* aEvent);
122
    NS_IMETHOD Error(nsIDOMEvent* aEvent);
122
    NS_IMETHOD Error(nsIDOMEvent* aEvent);
123
    NS_IMETHOD PageRestore(nsIDOMEvent* aEvent);
123
124
124
    NS_DECL_NSICHANNELEVENTSINK
125
    NS_DECL_NSICHANNELEVENTSINK
125
126
 Lines 161-166   public: Link Here 
161
    NS_IMETHOD Unload(nsIDOMEvent* aEvent);
162
    NS_IMETHOD Unload(nsIDOMEvent* aEvent);
162
    NS_IMETHOD Abort(nsIDOMEvent* aEvent);
163
    NS_IMETHOD Abort(nsIDOMEvent* aEvent);
163
    NS_IMETHOD Error(nsIDOMEvent* aEvent);
164
    NS_IMETHOD Error(nsIDOMEvent* aEvent);
165
    NS_IMETHOD PageRestore(nsIDOMEvent* aEvent);
164
166
165
protected:
167
protected:
166
    nsWeakPtr  mParent;
168
    nsWeakPtr  mParent;
 Lines 249-254   txLoadListenerProxy::Error(nsIDOMEvent* Link Here 
249
    return NS_OK;
251
    return NS_OK;
250
}
252
}
251
253
254
NS_IMETHODIMP
255
txLoadListenerProxy::PageRestore(nsIDOMEvent* aEvent)
256
{
257
    nsCOMPtr<nsIDOMLoadListener> listener = do_QueryReferent(mParent);
258
259
    if (listener) {
260
        return listener->PageRestore(aEvent);
261
    }
262
263
    return NS_OK;
264
}
265
252
class nsForceXMLListener : public nsIStreamListener
266
class nsForceXMLListener : public nsIStreamListener
253
{
267
{
254
public:
268
public:
 Lines 513-518   nsSyncLoader::Error(nsIDOMEvent* aEvent) Link Here 
513
}
527
}
514
528
515
NS_IMETHODIMP
529
NS_IMETHODIMP
530
nsSyncLoader::PageRestore(nsIDOMEvent* aEvent)
531
{
532
    return NS_OK;
533
}
534
535
NS_IMETHODIMP
516
nsSyncLoader::OnChannelRedirect(nsIChannel *aOldChannel,
536
nsSyncLoader::OnChannelRedirect(nsIChannel *aOldChannel,
517
                                nsIChannel *aNewChannel,
537
                                nsIChannel *aNewChannel,
518
                                PRUint32    aFlags)
538
                                PRUint32    aFlags)
(-)content/events/public/nsIEventListenerManager.h (-4 / +10 lines)
Line     Link Here 
 Lines 53-61   class nsIAtom; Link Here 
53
 * Event listener manager interface.
53
 * Event listener manager interface.
54
 */
54
 */
55
#define NS_IEVENTLISTENERMANAGER_IID \
55
#define NS_IEVENTLISTENERMANAGER_IID \
56
{ /* cd91bcf0-ded9-11d1-bd85-00805f8ae3f4 */ \
56
{0xc23b877c, 0xb396, 0x11d9, \
57
0xcd91bcf0, 0xded9, 0x11d1, \
57
{0x86, 0xbd, 0x00, 0x11, 0x24, 0x78, 0xd6, 0x26} }
58
{0xbd, 0x85, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
59
58
60
class nsIEventListenerManager : public nsISupports {
59
class nsIEventListenerManager : public nsISupports {
61
60
 Lines 175-181   public: Link Here 
175
  NS_IMETHOD SetListenerTarget(nsISupports* aTarget) = 0;
174
  NS_IMETHOD SetListenerTarget(nsISupports* aTarget) = 0;
176
175
177
  /**
176
  /**
178
  * Allows us to quickly determine if we have mutation listeners registered.
177
  * Allows us to quickly determine whether we have mutation listeners
178
  * registered.
179
  */
179
  */
180
  NS_IMETHOD HasMutationListeners(PRBool* aListener) = 0;
180
  NS_IMETHOD HasMutationListeners(PRBool* aListener) = 0;
181
181
 Lines 185-190   public: Link Here 
185
  * Loop pass for evaluation of system event listeners.
185
  * Loop pass for evaluation of system event listeners.
186
  */
186
  */
187
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup) = 0;
187
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup) = 0;
188
189
  /**
190
   * Allows us to quickly determine whether we have unload or beforeunload
191
   * listeners registered.
192
   */
193
  virtual PRBool HasUnloadListeners() = 0;
188
};
194
};
189
195
190
nsresult
196
nsresult
(-)content/events/src/nsDOMEvent.cpp (-2 / +6 lines)
Line     Link Here 
 Lines 58-65   static const char* const sEventNames[] = Link Here 
58
  "mousedown", "mouseup", "click", "dblclick", "mouseover",
58
  "mousedown", "mouseup", "click", "dblclick", "mouseover",
59
  "mouseout", "mousemove", "contextmenu", "keydown", "keyup", "keypress",
59
  "mouseout", "mousemove", "contextmenu", "keydown", "keyup", "keypress",
60
  "focus", "blur", "load", "beforeunload", "unload", "abort", "error",
60
  "focus", "blur", "load", "beforeunload", "unload", "abort", "error",
61
  "submit", "reset", "change", "select", "input", "paint" ,"text",
61
  "DOMPageRestore", "submit", "reset", "change", "select", "input", "paint",
62
  "compositionstart", "compositionend", "popupshowing", "popupshown",
62
  "text", "compositionstart", "compositionend", "popupshowing", "popupshown",
63
  "popuphiding", "popuphidden", "close", "command", "broadcast", "commandupdate",
63
  "popuphiding", "popuphidden", "close", "command", "broadcast", "commandupdate",
64
  "dragenter", "dragover", "dragexit", "dragdrop", "draggesture", "resize",
64
  "dragenter", "dragover", "dragexit", "dragdrop", "draggesture", "resize",
65
  "scroll","overflow", "underflow", "overflowchanged",
65
  "scroll","overflow", "underflow", "overflowchanged",
 Lines 434-439   nsDOMEvent::SetEventType(const nsAString Link Here 
434
      mEvent->message = NS_IMAGE_ABORT;
434
      mEvent->message = NS_IMAGE_ABORT;
435
    else if (atom == nsLayoutAtoms::onerror)
435
    else if (atom == nsLayoutAtoms::onerror)
436
      mEvent->message = NS_IMAGE_ERROR;
436
      mEvent->message = NS_IMAGE_ERROR;
437
    else if (atom == nsLayoutAtoms::onDOMPageRestore)
438
      mEvent->message = NS_PAGE_RESTORE;
437
  } else if (mEvent->eventStructType == NS_MUTATION_EVENT) {
439
  } else if (mEvent->eventStructType == NS_MUTATION_EVENT) {
438
    if (atom == nsLayoutAtoms::onDOMAttrModified)
440
    if (atom == nsLayoutAtoms::onDOMAttrModified)
439
      mEvent->message = NS_MUTATION_ATTRMODIFIED;
441
      mEvent->message = NS_MUTATION_ATTRMODIFIED;
 Lines 794-799   const char* nsDOMEvent::GetEventName(PRU Link Here 
794
  case NS_IMAGE_ERROR:
796
  case NS_IMAGE_ERROR:
795
  case NS_SCRIPT_ERROR:
797
  case NS_SCRIPT_ERROR:
796
    return sEventNames[eDOMEvents_error];
798
    return sEventNames[eDOMEvents_error];
799
  case NS_PAGE_RESTORE:
800
    return sEventNames[eDOMEvents_DOMPageRestore];
797
  case NS_FORM_SUBMIT:
801
  case NS_FORM_SUBMIT:
798
    return sEventNames[eDOMEvents_submit];
802
    return sEventNames[eDOMEvents_submit];
799
  case NS_FORM_RESET:
803
  case NS_FORM_RESET:
(-)content/events/src/nsDOMEvent.h (+1 lines)
Line     Link Here 
 Lines 85-90   public: Link Here 
85
    eDOMEvents_unload,
85
    eDOMEvents_unload,
86
    eDOMEvents_abort,
86
    eDOMEvents_abort,
87
    eDOMEvents_error,
87
    eDOMEvents_error,
88
    eDOMEvents_DOMPageRestore,
88
    eDOMEvents_submit,
89
    eDOMEvents_submit,
89
    eDOMEvents_reset,
90
    eDOMEvents_reset,
90
    eDOMEvents_change,
91
    eDOMEvents_change,
(-)content/events/src/nsEventListenerManager.cpp (-1 / +26 lines)
Line     Link Here 
 Lines 241-247   static const EventDispatchData sLoadEven Link Here 
241
  {NS_PAGE_UNLOAD, HANDLER(&nsIDOMLoadListener::Unload),NS_EVENT_BITS_LOAD_UNLOAD},
241
  {NS_PAGE_UNLOAD, HANDLER(&nsIDOMLoadListener::Unload),NS_EVENT_BITS_LOAD_UNLOAD},
242
  {NS_IMAGE_ERROR, HANDLER(&nsIDOMLoadListener::Error), NS_EVENT_BITS_LOAD_ERROR},
242
  {NS_IMAGE_ERROR, HANDLER(&nsIDOMLoadListener::Error), NS_EVENT_BITS_LOAD_ERROR},
243
  {NS_SCRIPT_ERROR,HANDLER(&nsIDOMLoadListener::Error), NS_EVENT_BITS_LOAD_ERROR},
243
  {NS_SCRIPT_ERROR,HANDLER(&nsIDOMLoadListener::Error), NS_EVENT_BITS_LOAD_ERROR},
244
  {NS_BEFORE_PAGE_UNLOAD,HANDLER(&nsIDOMLoadListener::BeforeUnload), NS_EVENT_BITS_LOAD_BEFORE_UNLOAD}
244
  {NS_BEFORE_PAGE_UNLOAD,HANDLER(&nsIDOMLoadListener::BeforeUnload), NS_EVENT_BITS_LOAD_BEFORE_UNLOAD},
245
  {NS_PAGE_RESTORE,HANDLER(&nsIDOMLoadListener::PageRestore), NS_EVENT_BITS_LOAD_PAGE_RESTORE}
245
};
246
};
246
247
247
static const EventDispatchData sPaintEvents[] = {
248
static const EventDispatchData sPaintEvents[] = {
 Lines 890-895   nsEventListenerManager::GetIdentifiersFo Link Here 
890
    *aArrayType = eEventArrayType_Load;
891
    *aArrayType = eEventArrayType_Load;
891
    *aFlags = NS_EVENT_BITS_LOAD_ERROR;
892
    *aFlags = NS_EVENT_BITS_LOAD_ERROR;
892
  }
893
  }
894
  else if (aType == nsLayoutAtoms::onDOMPageRestore) {
895
    *aArrayType = eEventArrayType_Load;
896
    *aFlags = NS_EVENT_BITS_LOAD_PAGE_RESTORE;
897
  }
893
  else if (aType == nsLayoutAtoms::onpaint) {
898
  else if (aType == nsLayoutAtoms::onpaint) {
894
    *aArrayType = eEventArrayType_Paint;
899
    *aArrayType = eEventArrayType_Paint;
895
    *aFlags = NS_EVENT_BITS_PAINT_PAINT;
900
    *aFlags = NS_EVENT_BITS_PAINT_PAINT;
 Lines 2231-2236   nsEventListenerManager::GetCoordinatesFo Link Here 
2231
  }
2236
  }
2232
}
2237
}
2233
2238
2239
PRBool
2240
nsEventListenerManager::HasUnloadListeners()
2241
{
2242
  nsVoidArray *listeners = GetListenersByType(eEventArrayType_Load, nsnull,
2243
                                              PR_FALSE);
2244
  if (listeners) {
2245
    PRInt32 count = listeners->Count();
2246
    for (PRInt32 i = 0; i < count; ++i) {
2247
      PRUint32 subtype = NS_STATIC_CAST(nsListenerStruct*,
2248
                                        listeners->FastElementAt(i))->mSubType;
2249
      if (subtype == NS_EVENT_BITS_NONE ||
2250
          subtype & (NS_EVENT_BITS_LOAD_UNLOAD |
2251
                     NS_EVENT_BITS_LOAD_BEFORE_UNLOAD))
2252
        return PR_TRUE;
2253
    }
2254
  }
2255
2256
  return PR_FALSE;
2257
}
2258
2234
nsresult
2259
nsresult
2235
NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) 
2260
NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) 
2236
{
2261
{
(-)content/events/src/nsEventListenerManager.h (+3 lines)
Line     Link Here 
 Lines 164-169   public: Link Here 
164
164
165
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
165
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
166
166
167
  virtual PRBool HasUnloadListeners();
168
167
  static nsresult GetIdentifiersForType(nsIAtom* aType,
169
  static nsresult GetIdentifiersForType(nsIAtom* aType,
168
                                        EventArrayType* aArrayType,
170
                                        EventArrayType* aArrayType,
169
                                        PRInt32* aSubType);
171
                                        PRInt32* aSubType);
 Lines 301-306   protected: Link Here 
301
#define NS_EVENT_BITS_LOAD_ABORT             0x04
303
#define NS_EVENT_BITS_LOAD_ABORT             0x04
302
#define NS_EVENT_BITS_LOAD_ERROR             0x08
304
#define NS_EVENT_BITS_LOAD_ERROR             0x08
303
#define NS_EVENT_BITS_LOAD_BEFORE_UNLOAD     0x10
305
#define NS_EVENT_BITS_LOAD_BEFORE_UNLOAD     0x10
306
#define NS_EVENT_BITS_LOAD_PAGE_RESTORE      0x20
304
307
305
//nsIDOMXULListener
308
//nsIDOMXULListener
306
#define NS_EVENT_BITS_XUL_NONE               0x00
309
#define NS_EVENT_BITS_XUL_NONE               0x00
(-)content/html/content/src/nsGenericHTMLElement.cpp (-9 / +11 lines)
Line     Link Here 
 Lines 1515-1529   nsGenericHTMLElement::HandleDOMEventForA Link Here 
1515
            // nothing else.
1515
            // nothing else.
1516
            nsCOMPtr<nsPIDOMWindow> win =
1516
            nsCOMPtr<nsPIDOMWindow> win =
1517
              do_QueryInterface(document->GetScriptGlobalObject());
1517
              do_QueryInterface(document->GetScriptGlobalObject());
1518
            nsIFocusController *focusController =
1518
            if (win) {
1519
              win->GetRootFocusController();
1519
              nsIFocusController *focusController =
1520
            PRBool isActive = PR_FALSE;
1520
                win->GetRootFocusController();
1521
            focusController->GetActive(&isActive);
1521
              PRBool isActive = PR_FALSE;
1522
            if (!isActive) {
1522
              focusController->GetActive(&isActive);
1523
              nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
1523
              if (!isActive) {
1524
              if(domElement)
1524
                nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
1525
                focusController->SetFocusedElement(domElement);
1525
                if(domElement)
1526
              break;
1526
                  focusController->SetFocusedElement(domElement);
1527
                break;
1528
              }
1527
            }
1529
            }
1528
  
1530
  
1529
            aPresContext->EventStateManager()->
1531
            aPresContext->EventStateManager()->
(-)content/html/content/src/nsHTMLInputElement.cpp (-15 / +19 lines)
Line     Link Here 
 Lines 1070-1083   nsHTMLInputElement::SetFocus(nsPresConte Link Here 
1070
  // nothing else.
1070
  // nothing else.
1071
  nsCOMPtr<nsPIDOMWindow> win =
1071
  nsCOMPtr<nsPIDOMWindow> win =
1072
    do_QueryInterface(doc->GetScriptGlobalObject());
1072
    do_QueryInterface(doc->GetScriptGlobalObject());
1073
  nsIFocusController *focusController = win->GetRootFocusController();
1073
  if (win) {
1074
  PRBool isActive = PR_FALSE;
1074
    nsIFocusController *focusController = win->GetRootFocusController();
1075
  focusController->GetActive(&isActive);
1075
    PRBool isActive = PR_FALSE;
1076
  if (!isActive) {
1076
    focusController->GetActive(&isActive);
1077
    focusController->SetFocusedWindow(win);
1077
    if (!isActive) {
1078
    focusController->SetFocusedElement(this);
1078
      focusController->SetFocusedWindow(win);
1079
      focusController->SetFocusedElement(this);
1079
1080
1080
    return;
1081
      return;
1082
    }
1081
  }
1083
  }
1082
1084
1083
  aPresContext->EventStateManager()->SetContentState(this,
1085
  aPresContext->EventStateManager()->SetContentState(this,
 Lines 1120-1133   nsHTMLInputElement::Select() Link Here 
1120
    // nothing else.
1122
    // nothing else.
1121
    nsCOMPtr<nsPIDOMWindow> win =
1123
    nsCOMPtr<nsPIDOMWindow> win =
1122
      do_QueryInterface(doc->GetScriptGlobalObject());
1124
      do_QueryInterface(doc->GetScriptGlobalObject());
1123
    nsIFocusController *focusController = win->GetRootFocusController();
1125
    if (win) {
1124
    PRBool isActive = PR_FALSE;
1126
      nsIFocusController *focusController = win->GetRootFocusController();
1125
    focusController->GetActive(&isActive);
1127
      PRBool isActive = PR_FALSE;
1126
    if (!isActive) {
1128
      focusController->GetActive(&isActive);
1127
      focusController->SetFocusedWindow(win);
1129
      if (!isActive) {
1128
      focusController->SetFocusedElement(this);
1130
        focusController->SetFocusedWindow(win);
1129
      SelectAll(presContext);
1131
        focusController->SetFocusedElement(this);
1130
      return NS_OK;
1132
        SelectAll(presContext);
1133
        return NS_OK;
1134
      }
1131
    }
1135
    }
1132
1136
1133
    // Just like SetFocus() but without the ScrollIntoView()!
1137
    // Just like SetFocus() but without the ScrollIntoView()!
(-)content/xbl/src/nsXBLPrototypeHandler.cpp (-1 / +2 lines)
Line     Link Here 
 Lines 291-297   nsXBLPrototypeHandler::ExecuteHandler(ns Link Here 
291
        privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
291
        privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
292
      }
292
      }
293
293
294
      focusController = privateWindow->GetRootFocusController();
294
      if (privateWindow)
295
        focusController = privateWindow->GetRootFocusController();
295
    }
296
    }
296
297
297
    NS_LossyConvertUCS2toASCII command(mHandlerText);
298
    NS_LossyConvertUCS2toASCII command(mHandlerText);
(-)content/xbl/src/nsXBLService.cpp (-5 / +6 lines)
Line     Link Here 
 Lines 229-239   public: Link Here 
229
  NS_DECL_NSIREQUESTOBSERVER
229
  NS_DECL_NSIREQUESTOBSERVER
230
230
231
  NS_IMETHOD Load(nsIDOMEvent* aEvent);
231
  NS_IMETHOD Load(nsIDOMEvent* aEvent);
232
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent) { return NS_OK; };
232
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent) { return NS_OK; }
233
  NS_IMETHOD Unload(nsIDOMEvent* aEvent) { return NS_OK; };
233
  NS_IMETHOD Unload(nsIDOMEvent* aEvent) { return NS_OK; }
234
  NS_IMETHOD Abort(nsIDOMEvent* aEvent) { return NS_OK; };
234
  NS_IMETHOD Abort(nsIDOMEvent* aEvent) { return NS_OK; }
235
  NS_IMETHOD Error(nsIDOMEvent* aEvent) { return NS_OK; };
235
  NS_IMETHOD Error(nsIDOMEvent* aEvent) { return NS_OK; }
236
  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; };
236
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent) { return NS_OK; }
237
  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
237
238
238
#ifdef MOZ_XUL
239
#ifdef MOZ_XUL
239
  static nsIXULPrototypeCache* gXULCache;
240
  static nsIXULPrototypeCache* gXULCache;
(-)docshell/base/nsDocShell.cpp (-24 / +505 lines)
Line     Link Here 
 Lines 166-174   static NS_DEFINE_CID(kDOMScriptObjectFac Link Here 
166
166
167
#if defined(DEBUG_bryner)
167
#if defined(DEBUG_bryner)
168
//#define DEBUG_DOCSHELL_FOCUS
168
//#define DEBUG_DOCSHELL_FOCUS
169
#define DEBUG_PAGE_CACHE
169
#endif
170
#endif
170
171
171
#include "plevent.h"
172
#include "plevent.h"
173
#include "nsGUIEvent.h"
174
#include "nsIPrivateDOMEvent.h"
175
#include "nsIDOMEventReceiver.h"
176
#include "nsIEventListenerManager.h"
177
#include "nsIPluginDocument.h"
172
178
173
// Number of documents currently loading
179
// Number of documents currently loading
174
static PRInt32 gNumberOfDocumentsLoading = 0;
180
static PRInt32 gNumberOfDocumentsLoading = 0;
 Lines 246-251   nsDocShell::nsDocShell(): Link Here 
246
    mIsBeingDestroyed(PR_FALSE),
252
    mIsBeingDestroyed(PR_FALSE),
247
    mIsExecutingOnLoadHandler(PR_FALSE),
253
    mIsExecutingOnLoadHandler(PR_FALSE),
248
    mIsPrintingOrPP(PR_FALSE),
254
    mIsPrintingOrPP(PR_FALSE),
255
    mSavingOldViewer(PR_FALSE),
249
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
256
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
250
    mChildOffset(0),
257
    mChildOffset(0),
251
    mBusyFlags(BUSY_FLAGS_NONE),
258
    mBusyFlags(BUSY_FLAGS_NONE),
 Lines 1355-1366   nsDocShell::SetCurrentURI(nsIURI *aURI, Link Here 
1355
        isRoot = PR_TRUE;
1362
        isRoot = PR_TRUE;
1356
    }
1363
    }
1357
    if (mLSHE) {
1364
    if (mLSHE) {
1358
      nsCOMPtr<nsIHistoryEntry> historyEntry(do_QueryInterface(mLSHE));
1365
        mLSHE->GetIsSubFrame(&isSubFrame);
1359
      
1360
      // Check if this is a subframe navigation
1361
      if (historyEntry) {
1362
        historyEntry->GetIsSubFrame(&isSubFrame);
1363
      }
1364
    }
1366
    }
1365
1367
1366
    if (!isSubFrame && !isRoot) {
1368
    if (!isSubFrame && !isRoot) {
 Lines 1675-1680   nsDocShell::TabToTreeOwner(PRBool aForwa Link Here 
1675
    return NS_OK;
1677
    return NS_OK;
1676
}
1678
}
1677
1679
1680
NS_IMETHODIMP
1681
nsDocShell::GetSecurityUI(nsISecureBrowserUI **aSecurityUI)
1682
{
1683
    NS_IF_ADDREF(*aSecurityUI = mSecurityUI);
1684
    return NS_OK;
1685
}
1686
1687
NS_IMETHODIMP
1688
nsDocShell::SetSecurityUI(nsISecureBrowserUI *aSecurityUI)
1689
{
1690
    mSecurityUI = aSecurityUI;
1691
    return NS_OK;
1692
}
1693
1678
//*****************************************************************************
1694
//*****************************************************************************
1679
// nsDocShell::nsIDocShellTreeItem
1695
// nsDocShell::nsIDocShellTreeItem
1680
//*****************************************************************************   
1696
//*****************************************************************************   
 Lines 3257-3268   nsDocShell::LoadPage(nsISupports *aPageD Link Here 
3257
    // load the page as view-source
3273
    // load the page as view-source
3258
    //
3274
    //
3259
    if (nsIWebPageDescriptor::DISPLAY_AS_SOURCE == aDisplayType) {
3275
    if (nsIWebPageDescriptor::DISPLAY_AS_SOURCE == aDisplayType) {
3260
        nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(shEntry));
3261
        nsCOMPtr<nsIURI> oldUri, newUri;
3276
        nsCOMPtr<nsIURI> oldUri, newUri;
3262
        nsCString spec, newSpec;
3277
        nsCString spec, newSpec;
3263
3278
3264
        // Create a new view-source URI and replace the original.
3279
        // Create a new view-source URI and replace the original.
3265
        rv = srcHE->GetURI(getter_AddRefs(oldUri));
3280
        rv = shEntry->GetURI(getter_AddRefs(oldUri));
3266
        if (NS_FAILED(rv))
3281
        if (NS_FAILED(rv))
3267
              return rv;
3282
              return rv;
3268
3283
 Lines 3716-3722   nsDocShell::SetTitle(const PRUnichar * a Link Here 
3716
    // would suffice. 
3731
    // would suffice. 
3717
    if (mOSHE && (mLoadType != LOAD_BYPASS_HISTORY) &&
3732
    if (mOSHE && (mLoadType != LOAD_BYPASS_HISTORY) &&
3718
        (mLoadType != LOAD_HISTORY) && (mLoadType != LOAD_ERROR_PAGE)) {
3733
        (mLoadType != LOAD_HISTORY) && (mLoadType != LOAD_ERROR_PAGE)) {
3719
        mOSHE->SetTitle(mTitle.get());    
3734
        mOSHE->SetTitle(mTitle);    
3720
    }
3735
    }
3721
3736
3722
3737
 Lines 4311-4317   nsDocShell::CancelRefreshURITimers() Link Here 
4311
    return NS_OK;
4326
    return NS_OK;
4312
}
4327
}
4313
4328
4314
NS_IMETHODIMP
4329
void
4330
nsDocShell::SuspendRefreshURIs()
4331
{
4332
    if (!mRefreshURIList)
4333
        return;
4334
    PRUint32 n = 0;
4335
    mRefreshURIList->Count(&n);
4336
4337
    nsCOMPtr<nsITimer> timer;
4338
    nsCOMPtr<nsITimerCallback> callback;
4339
    nsCOMPtr<nsRefreshTimer> rt;
4340
4341
    for (PRUint32 i = 0;  i < n; ++i) {
4342
        timer = do_QueryElementAt(mRefreshURIList, i);
4343
        if (!timer)
4344
            continue;  // this must be a nsRefreshURI already
4345
4346
        // Replace this timer object with a nsRefreshTimer object.
4347
        nsCOMPtr<nsITimerCallback> callback;
4348
        timer->GetCallback(getter_AddRefs(callback));
4349
4350
        timer->Cancel();
4351
4352
        nsCOMPtr<nsRefreshTimer> rt = do_QueryInterface(callback);
4353
        NS_ASSERTION(rt, "RefreshURIList timer callbacks should only be RefreshTimer objects");
4354
4355
        mRefreshURIList->ReplaceElementAt(rt, i);
4356
    }
4357
}
4358
4359
nsresult
4315
nsDocShell::RefreshURIFromQueue()
4360
nsDocShell::RefreshURIFromQueue()
4316
{
4361
{
4317
    if (!mRefreshURIList)
4362
    if (!mRefreshURIList)
 Lines 4697-4702   nsDocShell::CreateAboutBlankContentViewe Link Here 
4697
  return rv;
4742
  return rv;
4698
}
4743
}
4699
4744
4745
PRBool
4746
nsDocShell::CanSavePresentation(nsIRequest *aNewRequest)
4747
{
4748
    // If max_viewers is set to 0, don't ever try to save the presentation.
4749
    // This check should be removed once we've established that the
4750
    // immediate-evict case works correctly (see bug 274784).
4751
    PRInt32 maxViewers = 0;
4752
    mPrefs->GetIntPref("browser.sessionhistory.max_viewers", &maxViewers);
4753
    if (maxViewers == 0)
4754
        return PR_FALSE;
4755
4756
    // If the document is not done loading, don't cache it.
4757
    nsCOMPtr<nsPIDOMWindow> pWin = do_QueryInterface(mScriptGlobal);
4758
    if (!pWin || pWin->IsLoading())
4759
        return PR_FALSE;
4760
4761
    // If there are any active requests in the document load group, don't cache
4762
    // the document.  Ideally we would instead suspend these requests and
4763
    // resume them when restoring the presentation, but that is potentially
4764
    // difficult (e.g. XMLHttpRequest).
4765
4766
    nsCOMPtr<nsIDocument> doc = do_QueryInterface(pWin->GetExtantDocument());
4767
    if (doc && doc->HasRequests(aNewRequest))
4768
        return PR_FALSE;
4769
4770
    // Don't save plugin documents; we have no easy way of retrieving the
4771
    // plugin data after it is loaded.
4772
    nsCOMPtr<nsIPluginDocument> pluginDoc = do_QueryInterface(doc);
4773
    if (pluginDoc)
4774
        return PR_FALSE;
4775
4776
    // Only save presentation for "normal" loads and link loads.  Anything else
4777
    // probably wants to refetch the page, so caching the old presentation
4778
    // would be incorrect.
4779
    if (mLoadType != LOAD_NORMAL &&
4780
        mLoadType != LOAD_HISTORY &&
4781
        mLoadType != LOAD_LINK)
4782
        return PR_FALSE;
4783
4784
    // If there is an unload or beforeunload listener on the window, then we do
4785
    // not save the presentation into the session history cache.
4786
    nsCOMPtr<nsIDOMEventReceiver> er = do_QueryInterface(mScriptGlobal);
4787
    if (er) {
4788
        nsCOMPtr<nsIEventListenerManager> eventManager;
4789
        er->GetListenerManager(getter_AddRefs(eventManager));
4790
4791
        if (eventManager && eventManager->HasUnloadListeners())
4792
            return PR_FALSE;
4793
    }
4794
4795
    // If the session history entry has the saveLayoutState flag set to false,
4796
    // then we should not cache the presentation.
4797
4798
    if (!mOSHE)
4799
        return PR_FALSE; // no entry to save into
4800
4801
    PRBool canSaveState;
4802
    mOSHE->GetSaveLayoutStateFlag(&canSaveState);
4803
    return canSaveState;
4804
}
4805
4806
nsresult
4807
nsDocShell::CaptureState()
4808
{
4809
    nsCOMPtr<nsPIDOMWindow> privWin = do_QueryInterface(mScriptGlobal);
4810
    if (!privWin || !mOSHE)
4811
        return NS_ERROR_FAILURE;
4812
4813
    nsCOMPtr<nsISupports> windowState;
4814
    nsresult rv = privWin->SaveWindowState(getter_AddRefs(windowState));
4815
    NS_ENSURE_SUCCESS(rv, rv);
4816
4817
#ifdef DEBUG_PAGE_CACHE
4818
    nsCOMPtr<nsIURI> uri;
4819
    mOSHE->GetURI(getter_AddRefs(uri));
4820
    nsCAutoString spec;
4821
    if (uri)
4822
        uri->GetSpec(spec);
4823
    printf("Saving presentation into session history\n");
4824
    printf("  SH URI: %s\n", spec.get());
4825
#endif
4826
4827
    rv = mOSHE->SetWindowState(windowState);
4828
    NS_ENSURE_SUCCESS(rv, rv);
4829
4830
    // Suspend refresh URIs and save off the timer queue
4831
    SuspendRefreshURIs();
4832
    rv = mOSHE->SetRefreshURIList(mRefreshURIList);
4833
    NS_ENSURE_SUCCESS(rv, rv);
4834
4835
    mRefreshURIList = nsnull;
4836
4837
    // Capture the current content viewer bounds.
4838
    nsCOMPtr<nsIPresShell> shell;
4839
    nsDocShell::GetPresShell(getter_AddRefs(shell));
4840
    if (shell) {
4841
        nsIViewManager *vm = shell->GetViewManager();
4842
        if (vm) {
4843
            nsIView *rootView = nsnull;
4844
            vm->GetRootView(rootView);
4845
            if (rootView) {
4846
                nsIWidget *widget = rootView->GetWidget();
4847
                if (widget) {
4848
                    nsRect bounds(0, 0, 0, 0);
4849
                    widget->GetBounds(bounds);
4850
                    rv = mOSHE->SetViewerBounds(bounds);
4851
                }
4852
            }
4853
        }
4854
    }
4855
4856
    // Capture the docshell hierarchy.
4857
4858
    PRInt32 childCount = mChildList.Count();
4859
    nsCOMPtr<nsIDocShellTreeItem> childShell;
4860
4861
    mOSHE->ClearChildShells();
4862
4863
    for (PRInt32 i = 0; i < childCount; ++i) {
4864
        childShell = do_QueryInterface(ChildAt(i));
4865
        NS_ASSERTION(childShell, "null child shell");
4866
4867
        mOSHE->AddChildShell(childShell);
4868
    }
4869
4870
    // Capture the security state.
4871
    nsCOMPtr<nsISecureBrowserUIState> securityState;
4872
    if (mSecurityUI)
4873
        mSecurityUI->CaptureState(getter_AddRefs(securityState));
4874
4875
    return mOSHE->SetSecurityState(securityState);
4876
}
4877
4878
nsresult
4879
nsDocShell::RestorePresentation(nsISHEntry *aSHEntry, PRBool aSavePresentation)
4880
{
4881
    NS_ASSERTION(mLoadType & LOAD_CMD_HISTORY,
4882
                 "RestorePresentation should only be called for history loads");
4883
4884
    nsCOMPtr<nsIURI> uri;
4885
    aSHEntry->GetURI(getter_AddRefs(uri));
4886
4887
    nsCOMPtr<nsIContentViewer> viewer;
4888
    aSHEntry->GetContentViewer(getter_AddRefs(viewer));
4889
4890
#ifdef DEBUG_PAGE_CACHE
4891
    nsCAutoString spec;
4892
    if (uri)
4893
        uri->GetSpec(spec);
4894
#endif
4895
4896
    if (!viewer) {
4897
#ifdef DEBUG_PAGE_CACHE
4898
        printf("no saved presentation for uri: %s\n", spec.get());
4899
#endif
4900
        return NS_ERROR_NOT_AVAILABLE;
4901
    }
4902
4903
    NS_ASSERTION(mContentViewer != viewer, "Restoring existing presentation");
4904
4905
#ifdef DEBUG_PAGE_CACHE
4906
    printf("restoring presentation from session history: %s\n", spec.get());
4907
#endif
4908
4909
    // Save off the root view's parent and sibling so that we can insert the
4910
    // new content viewer's root view at the same position.  Also save the
4911
    // bounds of the root view's widget.
4912
4913
    nsIView *rootViewSibling = nsnull, *rootViewParent = nsnull;
4914
    nsRect newBounds(0, 0, 0, 0);
4915
4916
    nsCOMPtr<nsIPresShell> oldPresShell;
4917
    nsDocShell::GetPresShell(getter_AddRefs(oldPresShell));
4918
    if (oldPresShell) {
4919
        nsIViewManager *vm = oldPresShell->GetViewManager();
4920
        if (vm) {
4921
            nsIView *oldRootView = nsnull;
4922
            vm->GetRootView(oldRootView);
4923
4924
            if (oldRootView) {
4925
                rootViewSibling = oldRootView->GetNextSibling();
4926
                rootViewParent = oldRootView->GetParent();
4927
4928
                nsIWidget *widget = oldRootView->GetWidget();
4929
                if (widget) {
4930
                    widget->GetBounds(newBounds);
4931
                }
4932
            }
4933
        }
4934
    }
4935
4936
    // Transfer ownership to mContentViewer.  By ensuring that either the
4937
    // docshell or the session history, but not both, have references to the
4938
    // content viewer, we prevent the viewer from being torn down after
4939
    // Destroy() is called.
4940
4941
    if (!aSavePresentation)
4942
        FireUnloadNotification();
4943
4944
    mFiredUnloadEvent = PR_FALSE;
4945
4946
    if (mContentViewer) {
4947
        mContentViewer->Close();
4948
4949
        if (aSavePresentation)
4950
            mContentViewer->SetHistoryEntry(mOSHE);
4951
4952
        mContentViewer->Destroy();
4953
    }
4954
4955
    mContentViewer.swap(viewer);
4956
    viewer = nsnull; // force a release to complete ownership transfer
4957
4958
    // Reattach to the window object.
4959
    nsresult rv = mContentViewer->Open();
4960
4961
    // Now remove it from the cached presentation.
4962
    aSHEntry->SetContentViewer(nsnull);
4963
4964
    // Restore our child docshell hierarchy.
4965
    DestroyChildren();
4966
    NS_ENSURE_SUCCESS(rv, rv);
4967
4968
    PRInt32 i = 0;
4969
    nsCOMPtr<nsIDocShellTreeItem> childShell;
4970
    while (NS_SUCCEEDED(aSHEntry->ChildShellAt(i++,
4971
                                               getter_AddRefs(childShell))) &&
4972
           childShell) {
4973
        AddChild(childShell);
4974
    }
4975
4976
    // And release the references in the history entry.
4977
    aSHEntry->ClearChildShells();
4978
4979
    // Restore the sticky state of the viewer.  The viewer automatically
4980
    // sets itself as sticky in Destroy() to avoid teardown.
4981
    PRBool sticky;
4982
    aSHEntry->GetSticky(&sticky);
4983
    mContentViewer->SetSticky(sticky);
4984
4985
    // save the previous content viewer size
4986
    nsRect oldBounds(0, 0, 0, 0);
4987
    aSHEntry->GetViewerBounds(oldBounds);
4988
4989
    nsCOMPtr<nsIPresShell> shell;
4990
    nsDocShell::GetPresShell(getter_AddRefs(shell));
4991
4992
    nsIViewManager *newVM = shell ? shell->GetViewManager() : nsnull;
4993
    nsIView *newRootView = nsnull;
4994
    if (newVM)
4995
        newVM->GetRootView(newRootView);
4996
4997
    // Insert the new root view at the correct location in the view tree.
4998
    if (rootViewParent) {
4999
        nsIViewManager *parentVM = rootViewParent->GetViewManager();
5000
5001
        if (parentVM && newRootView) {
5002
            parentVM->InsertChild(rootViewParent, newRootView,
5003
                                  rootViewSibling, PR_TRUE);
5004
5005
            NS_ASSERTION(newRootView->GetNextSibling() == rootViewSibling,
5006
                         "error in InsertChild");
5007
5008
            shell->InvalidateViewManagers();
5009
        }
5010
    }
5011
5012
    // restore the state of the window object
5013
    nsCOMPtr<nsPIDOMWindow> privWin =
5014
        do_GetInterface(NS_STATIC_CAST(nsIInterfaceRequestor*, this));
5015
    NS_ASSERTION(privWin, "could not get nsPIDOMWindow interface");
5016
5017
    nsCOMPtr<nsISupports> windowState;
5018
    aSHEntry->GetWindowState(getter_AddRefs(windowState));
5019
5020
    rv = privWin->RestoreWindowState(windowState);
5021
    NS_ENSURE_SUCCESS(rv, rv);
5022
5023
    aSHEntry->SetWindowState(nsnull);
5024
5025
    // Restore the refresh URI list.
5026
    aSHEntry->GetRefreshURIList(getter_AddRefs(mRefreshURIList));
5027
    aSHEntry->SetRefreshURIList(nsnull);
5028
5029
    mOSHE = aSHEntry;
5030
5031
    // mEODForCurrentDocument is true here, so EndPageLoad will not fire
5032
    // onload (we fire that below, in a special way so that the content window
5033
    // does not see it).
5034
    EndPageLoad(nsnull, nsnull, NS_OK);
5035
5036
    nsCOMPtr<nsISHistory> rootSH;
5037
    GetRootSessionHistory(getter_AddRefs(rootSH));
5038
    if (rootSH) {
5039
        nsCOMPtr<nsISHistoryInternal> hist = do_QueryInterface(rootSH);
5040
        hist->UpdateIndex();
5041
    }
5042
5043
    // Make sure this presentation is the same size as the previous
5044
    // presentation.  If this is not the same size we showed it at last time,
5045
    // then we need to resize the widget.
5046
5047
    // XXXbryner   This interacts poorly with Firefox's infobar.  If the old
5048
    // presentation had the infobar visible, then we will resize the new
5049
    // presentation to that smaller size.  However, firing the locationchanged
5050
    // event will hide the infobar, which will immediately resize the window
5051
    // back to the larger size.  A future optimization might be to restore
5052
    // the presentation at the "wrong" size, then fire the locationchanged
5053
    // event and check whether the docshell's new size is the same as the
5054
    // cached viewer size (skipping the resize if they are equal).
5055
5056
    if (newRootView) {
5057
        nsIWidget *widget = newRootView->GetWidget();
5058
        if (widget && !newBounds.IsEmpty() && newBounds != oldBounds) {
5059
#ifdef DEBUG_PAGE_CACHE
5060
            printf("resize widget(%d, %d, %d, %d)\n", newBounds.x,
5061
                   newBounds.y, newBounds.width, newBounds.height);
5062
#endif
5063
5064
            widget->Resize(newBounds.x, newBounds.y, newBounds.width,
5065
                           newBounds.height, PR_FALSE);
5066
        }
5067
    }
5068
5069
    // Reset the security state
5070
    if (mSecurityUI) {
5071
        nsCOMPtr<nsISecureBrowserUIState> securityState;
5072
        aSHEntry->GetSecurityState(getter_AddRefs(securityState));
5073
        if (securityState)
5074
            mSecurityUI->TransitionToState(securityState);
5075
    }
5076
5077
    SetCurrentURI(uri);
5078
5079
    // Dispatch events.  This is a little messy.  We need to avoid firing
5080
    // onload so that it is visible from the content DOM window, but we _do_
5081
    // want the chrome to see it for chrome/extensions that look for page load.
5082
    // In addition, we need to fire DOMPageRestore on the content window.
5083
5084
    if (shell) {
5085
        nsEvent event(PR_TRUE, NS_PAGE_LOAD);
5086
        nsEventStatus status = nsEventStatus_eIgnore;
5087
5088
        nsCOMPtr<nsIChromeEventHandler> handler =
5089
            privWin->GetChromeEventHandler();
5090
5091
        PRUint32 flags = NS_EVENT_FLAG_INIT;
5092
        event.flags |= flags;
5093
        flags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
5094
        flags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
5095
5096
        nsIDOMEvent *domEvt = nsnull;
5097
        nsPresContext *pc = shell->GetPresContext();
5098
5099
        rv = handler->HandleChromeEvent(pc, &event, &domEvt,
5100
                                        flags & NS_EVENT_CAPTURE_MASK,
5101
                                        &status);
5102
        NS_ENSURE_SUCCESS(rv, rv);
5103
5104
        if (domEvt) {
5105
            nsrefcnt rc;
5106
            NS_RELEASE2(domEvt, rc);
5107
            if (0 != rc) {
5108
                // Okay, so someone in the DOM loop (a listener, JS object)
5109
                // still has a ref to the DOM Event but the internal data
5110
                // hasn't been malloc'd.  Force a copy of the data here so the
5111
                // DOM Event is still valid.
5112
5113
                nsCOMPtr<nsIPrivateDOMEvent> privateEvent =
5114
                    do_QueryInterface(domEvt);
5115
5116
                if (privateEvent) {
5117
                    privateEvent->DuplicatePrivateData();
5118
                }
5119
            }
5120
        }
5121
5122
        status = nsEventStatus_eIgnore;
5123
        nsEvent restoreEvent(PR_TRUE, NS_PAGE_RESTORE);
5124
5125
        mScriptGlobal->HandleDOMEvent(pc, &restoreEvent, nsnull,
5126
                                      NS_EVENT_FLAG_INIT, &status);
5127
    }
5128
5129
    rv = mContentViewer->Show();
5130
    NS_ENSURE_SUCCESS(rv, rv);
5131
5132
    // Restart plugins
5133
    if (shell)
5134
        shell->Thaw();
5135
5136
    // XXXbryner  Making this invalidate synchronous causes unpainted areas
5137
    // (on Mac, at least) if the above locationchanged event hides Firefox's
5138
    // infobar.  Doing it asynchronously seems to work around the problem, but
5139
    // shouldn't the style change that hides the infobar handle all necessary
5140
    // invalidation, including the newly-exposed area?
5141
5142
    return mParentWidget->Invalidate(PR_FALSE);
5143
}
5144
4700
NS_IMETHODIMP
5145
NS_IMETHODIMP
4701
nsDocShell::CreateContentViewer(const char *aContentType,
5146
nsDocShell::CreateContentViewer(const char *aContentType,
4702
                                nsIRequest * request,
5147
                                nsIRequest * request,
 Lines 4723-4729   nsDocShell::CreateContentViewer(const ch Link Here 
4723
    // is changed within the DocShell - otherwise, javascript will get the
5168
    // is changed within the DocShell - otherwise, javascript will get the
4724
    // wrong information :-(
5169
    // wrong information :-(
4725
    //
5170
    //
4726
    (void) FireUnloadNotification();
5171
5172
    PRBool savePresentation = CanSavePresentation(request);
5173
    if (!savePresentation)
5174
        FireUnloadNotification();
4727
5175
4728
    // Set mFiredUnloadEvent = PR_FALSE so that the unload handler for the
5176
    // Set mFiredUnloadEvent = PR_FALSE so that the unload handler for the
4729
    // *new* document will fire.
5177
    // *new* document will fire.
 Lines 4738-4743   nsDocShell::CreateContentViewer(const ch Link Here 
4738
5186
4739
    PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE);
5187
    PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE);
4740
5188
5189
    if (savePresentation) {
5190
        // The old content viewer will be saved during the call to Embed().
5191
        rv = CaptureState();
5192
        if (NS_SUCCEEDED(rv))
5193
            mSavingOldViewer = PR_TRUE;
5194
        // XXX this isn't really fatal, necessarily...
5195
        // should we try to fire unload if NS_FAILED(rv) ?
5196
    }
5197
4741
    // let's try resetting the load group if we need to...
5198
    // let's try resetting the load group if we need to...
4742
    nsCOMPtr<nsILoadGroup> currentLoadGroup;
5199
    nsCOMPtr<nsILoadGroup> currentLoadGroup;
4743
    NS_ENSURE_SUCCESS(aOpenedChannel->
5200
    NS_ENSURE_SUCCESS(aOpenedChannel->
 Lines 4779-4784   nsDocShell::CreateContentViewer(const ch Link Here 
4779
    NS_ENSURE_SUCCESS(Embed(viewer, "", (nsISupports *) nsnull),
5236
    NS_ENSURE_SUCCESS(Embed(viewer, "", (nsISupports *) nsnull),
4780
                      NS_ERROR_FAILURE);
5237
                      NS_ERROR_FAILURE);
4781
5238
5239
    mSavingOldViewer = PR_FALSE;
4782
    mEODForCurrentDocument = PR_FALSE;
5240
    mEODForCurrentDocument = PR_FALSE;
4783
5241
4784
    // if this document is part of a multipart document,
5242
    // if this document is part of a multipart document,
 Lines 5028-5033   nsDocShell::SetupNewViewer(nsIContentVie Link Here 
5028
5486
5029
        mContentViewer->Close();
5487
        mContentViewer->Close();
5030
        aNewViewer->SetPreviousViewer(mContentViewer);
5488
        aNewViewer->SetPreviousViewer(mContentViewer);
5489
5490
        if (mSavingOldViewer) {
5491
            // Tell the old content viewer to hibernate in session history when
5492
            // it is destroyed.
5493
            mContentViewer->SetHistoryEntry(mOSHE);
5494
        }
5495
5031
        mContentViewer = nsnull;
5496
        mContentViewer = nsnull;
5032
    }
5497
    }
5033
5498
 Lines 5568-5574   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5568
                NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
6033
                NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
5569
                nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
6034
                nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
5570
                if (shEntry)
6035
                if (shEntry)
5571
                    shEntry->SetTitle(mTitle.get());
6036
                    shEntry->SetTitle(mTitle);
5572
            }
6037
            }
5573
6038
5574
            return NS_OK;
6039
            return NS_OK;
 Lines 5588-5593   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5588
        }
6053
        }
5589
    }
6054
    }
5590
6055
6056
    // Check for saving the presentation here, before calling Stop().
6057
    // This is necessary so that we can catch any pending requests.
6058
    PRBool savePresentation =
6059
        aSHEntry ? CanSavePresentation(nsnull) : PR_FALSE;
6060
5591
    // Don't stop current network activity for javascript: URL's since
6061
    // Don't stop current network activity for javascript: URL's since
5592
    // they might not result in any data, and thus nothing should be
6062
    // they might not result in any data, and thus nothing should be
5593
    // stopped in those cases. In the case where they do result in
6063
    // stopped in those cases. In the case where they do result in
 Lines 5623-5628   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5623
    // been called.
6093
    // been called.
5624
    mLSHE = aSHEntry;
6094
    mLSHE = aSHEntry;
5625
6095
6096
    // If we have a saved content viewer in history, restore and show it now.
6097
    if (aSHEntry) {
6098
        if (!savePresentation)
6099
            FireUnloadNotification();
6100
6101
        mFiredUnloadEvent = PR_FALSE;
6102
6103
        if (savePresentation)
6104
            rv = CaptureState();
6105
6106
        rv = RestorePresentation(aSHEntry, savePresentation &&
6107
                                 NS_SUCCEEDED(rv));
6108
        if (NS_SUCCEEDED(rv))
6109
            return rv;
6110
    }
6111
5626
    nsCOMPtr<nsIRequest> req;
6112
    nsCOMPtr<nsIRequest> req;
5627
    rv = DoURILoad(aURI, aReferrer,
6113
    rv = DoURILoad(aURI, aReferrer,
5628
                   !(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER),
6114
                   !(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER),
 Lines 6520-6531   nsDocShell::AddToSessionHistory(nsIURI * Link Here 
6520
    }
7006
    }
6521
7007
6522
    //Title is set in nsDocShell::SetTitle()
7008
    //Title is set in nsDocShell::SetTitle()
6523
    entry->Create(aURI,         // uri
7009
    entry->Create(aURI,              // uri
6524
                  nsnull,       // Title
7010
                  EmptyString(),     // Title
6525
                  nsnull,       // DOMDocument
7011
                  inputStream,       // Post data stream
6526
                  inputStream,  // Post data stream
7012
                  nsnull,            // LayoutHistory state
6527
                  nsnull,       // LayoutHistory state
7013
                  cacheKey,          // CacheKey
6528
                  cacheKey,     // CacheKey
6529
                  mContentTypeHint); // Content-type
7014
                  mContentTypeHint); // Content-type
6530
    entry->SetReferrerURI(referrerURI);
7015
    entry->SetReferrerURI(referrerURI);
6531
    /* If cache got a 'no-store', ask SH not to store
7016
    /* If cache got a 'no-store', ask SH not to store
 Lines 6556-6562   nsDocShell::AddToSessionHistory(nsIURI * Link Here 
6556
        if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {            
7041
        if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {            
6557
            // Replace current entry in session history.
7042
            // Replace current entry in session history.
6558
            PRInt32  index = 0;   
7043
            PRInt32  index = 0;   
6559
            nsCOMPtr<nsIHistoryEntry> hEntry;
6560
            mSessionHistory->GetIndex(&index);
7044
            mSessionHistory->GetIndex(&index);
6561
            nsCOMPtr<nsISHistoryInternal>   shPrivate(do_QueryInterface(mSessionHistory));
7045
            nsCOMPtr<nsISHistoryInternal>   shPrivate(do_QueryInterface(mSessionHistory));
6562
            // Replace the current entry with the new entry
7046
            // Replace the current entry with the new entry
 Lines 6601-6610   nsDocShell::LoadHistoryEntry(nsISHEntry Link Here 
6601
    nsCAutoString contentType;
7085
    nsCAutoString contentType;
6602
7086
6603
    NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
7087
    NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
6604
    nsCOMPtr<nsIHistoryEntry> hEntry(do_QueryInterface(aEntry));
6605
    NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
6606
7088
6607
    NS_ENSURE_SUCCESS(hEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
7089
    NS_ENSURE_SUCCESS(aEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
6608
    NS_ENSURE_SUCCESS(aEntry->GetReferrerURI(getter_AddRefs(referrerURI)),
7090
    NS_ENSURE_SUCCESS(aEntry->GetReferrerURI(getter_AddRefs(referrerURI)),
6609
                      NS_ERROR_FAILURE);
7091
                      NS_ERROR_FAILURE);
6610
    NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
7092
    NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
 Lines 6699-6707   nsDocShell::CloneAndReplace(nsISHEntry * Link Here 
6699
    nsISHEntry *dest = (nsISHEntry *) nsnull;
7181
    nsISHEntry *dest = (nsISHEntry *) nsnull;
6700
    PRUint32 srcID;
7182
    PRUint32 srcID;
6701
    src->GetID(&srcID);
7183
    src->GetID(&srcID);
6702
    nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(src));
6703
7184
6704
    if (!src || !replaceEntry || !srcHE)
7185
    if (!src || !replaceEntry)
6705
        return NS_ERROR_FAILURE;
7186
        return NS_ERROR_FAILURE;
6706
7187
6707
    if (srcID == aCloneID) {
7188
    if (srcID == aCloneID) {
(-)docshell/base/nsDocShell.h (-1 / +55 lines)
Line     Link Here 
 Lines 100-105    Link Here 
100
#include "nsIHttpChannel.h"
100
#include "nsIHttpChannel.h"
101
#include "nsDocShellTransferableHooks.h"
101
#include "nsDocShellTransferableHooks.h"
102
#include "nsIAuthPromptProvider.h"
102
#include "nsIAuthPromptProvider.h"
103
#include "nsISecureBrowserUI.h"
103
104
104
/**
105
/**
105
 * Load flag for error pages. This should be bigger than all flags on
106
 * Load flag for error pages. This should be bigger than all flags on
 Lines 340-346   protected: Link Here 
340
    NS_IMETHOD EnsureEditorData();
341
    NS_IMETHOD EnsureEditorData();
341
    nsresult   EnsureTransferableHookData();
342
    nsresult   EnsureTransferableHookData();
342
    NS_IMETHOD EnsureFind();
343
    NS_IMETHOD EnsureFind();
343
    NS_IMETHOD RefreshURIFromQueue();
344
    nsresult   RefreshURIFromQueue();
345
    void       SuspendRefreshURIs();
344
    NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI,
346
    NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI,
345
                                const PRUnichar *aURL,
347
                                const PRUnichar *aURL,
346
                                nsIChannel* aFailedChannel = nsnull);
348
                                nsIChannel* aFailedChannel = nsnull);
 Lines 395-400   protected: Link Here 
395
    PRBool SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
397
    PRBool SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
396
                         PRBool aFireOnLocationChange);
398
                         PRBool aFireOnLocationChange);
397
399
400
    // The following methods deal with saving and restoring content viewers
401
    // in session history.
402
403
    // mContentViewer points to the current content viewer associated with
404
    // this docshell.  When loading a new document, the content viewer is
405
    // either destroyed or stored into a session history entry.  To make sure
406
    // that destruction happens in a controlled fashion, a given content viewer
407
    // is always owned in exactly one of these ways:
408
    //   1) The content viewer is active and owned by a docshell's
409
    //      mContentViewer.
410
    //   2) The content viewer is still being displayed while we begin loading
411
    //      a new document.  The content viewer is owned by the _new_
412
    //      content viewer's mPreviousViewer, and has a pointer to the
413
    //      nsISHEntry where it will eventually be stored.  The content viewer
414
    //      has been close()d by the docshell, which detaches the document from
415
    //      the window object.
416
    //   3) The content viewer is cached in session history.  The nsISHEntry
417
    //      has the only owning reference to the content viewer.  The viewer
418
    //      has released its nsISHEntry pointer to prevent circular ownership.
419
    //
420
    // When restoring a content viewer from session history, open() is called
421
    // to reattach the document to the window object.  The content viewer is
422
    // then placed into mContentViewer and removed from the history entry.
423
    // (mContentViewer is put into session history as described above, if
424
    // applicable).
425
426
    // Determines whether we can safely cache the current mContentViewer in
427
    // session history.  This checks a number of factors such as cache policy,
428
    // pending requests, and unload handlers.  |aNewRequest| should be the
429
    // request for the document to be loaded in place of the current document.
430
    PRBool CanSavePresentation(nsIRequest *aNewRequest);
431
432
    // Captures the state of the supporting elements of the presentation
433
    // (the "window" object, docshell tree, meta-refresh loads, and security
434
    // state) and stores them on |mOSHE|.
435
    nsresult CaptureState();
436
437
    // Restores the presentation stored in |aSHEntry|.  The old presentation
438
    // is saved in session history if |aSavePresentation| is true.
439
    nsresult RestorePresentation(nsISHEntry *aSHEntry,
440
                                 PRBool aSavePresentation);
441
442
    // Disable the caret in |aRoot| and all children.
443
    static void DisableCaret(nsIDocShellTreeItem *aRoot);
444
398
protected:
445
protected:
399
    // Override the parent setter from nsDocLoader
446
    // Override the parent setter from nsDocLoader
400
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
447
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
 Lines 426-431   protected: Link Here 
426
    // Indicates that a DocShell in this "docshell tree" is printing
473
    // Indicates that a DocShell in this "docshell tree" is printing
427
    PRPackedBool               mIsPrintingOrPP;
474
    PRPackedBool               mIsPrintingOrPP;
428
475
476
    // Indicates to SetupNewViewer() that we are in the process of saving the
477
    // presentation for mContentViewer.
478
    PRPackedBool               mSavingOldViewer;
479
429
    PRUint32                   mAppType;
480
    PRUint32                   mAppType;
430
481
431
    // Offset in the parent's child list.
482
    // Offset in the parent's child list.
 Lines 474-479   protected: Link Here 
474
    // Transferable hooks/callbacks
525
    // Transferable hooks/callbacks
475
    nsCOMPtr<nsIClipboardDragDropHookList>  mTransferableHookData;
526
    nsCOMPtr<nsIClipboardDragDropHookList>  mTransferableHookData;
476
527
528
    // Secure browser UI object
529
    nsCOMPtr<nsISecureBrowserUI> mSecurityUI;
530
477
    // WEAK REFERENCES BELOW HERE.
531
    // WEAK REFERENCES BELOW HERE.
478
    // Note these are intentionally not addrefd.  Doing so will create a cycle.
532
    // Note these are intentionally not addrefd.  Doing so will create a cycle.
479
    // For that reasons don't use nsCOMPtr.
533
    // For that reasons don't use nsCOMPtr.
(-)docshell/base/nsIContentViewer.idl (-1 / +20 lines)
Line     Link Here 
 Lines 1-6    Link Here 
1
#include "nsISupports.idl"
1
#include "nsISupports.idl"
2
2
3
interface nsIDOMDocument;
3
interface nsIDOMDocument;
4
interface nsISHEntry;
4
5
5
6
6
%{ C++
7
%{ C++
 Lines 13-19   struct nsRect; Link Here 
13
[ptr] native nsIDeviceContextPtr(nsIDeviceContext);
14
[ptr] native nsIDeviceContextPtr(nsIDeviceContext);
14
[ref] native nsRectRef(nsRect);
15
[ref] native nsRectRef(nsRect);
15
16
16
[scriptable, uuid(70b8f22d-135c-4c94-8044-1bd3238d0990)]
17
[scriptable, uuid(e2c68a4d-b396-11d9-a3d1-00112478d626)]
17
interface nsIContentViewer : nsISupports
18
interface nsIContentViewer : nsISupports
18
{
19
{
19
20
 Lines 68-71   interface nsIContentViewer : nsISupports Link Here 
68
   */
69
   */
69
70
70
  boolean requestWindowClose();
71
  boolean requestWindowClose();
72
73
  /**
74
   * Attach the content viewer to its DOM window and docshell.
75
   */
76
  void open();
77
78
  /**
79
   * Set the  session history entry for the content viewer.  If this is set,
80
   * then the following actions will happen when destroy() is called (*):
81
   *  - Sanitize() will be called on the viewer's document
82
   *  - The content viewer will set the contentViewer property on the
83
   *    history entry, and release its reference (ownership reversal).
84
   *  - hide() will be called, and no further destruction will happen.
85
   *
86
   *  (*) unless the document is currently being printed, in which case
87
   *      it will never be saved in session history.
88
   */
89
  void setHistoryEntry(in nsISHEntry entry);
71
};
90
};
(-)docshell/base/nsIDocShell.idl (+7 lines)
Line     Link Here 
 Lines 64-69   interface nsIInputStream; Link Here 
64
interface nsIRequest;
64
interface nsIRequest;
65
interface nsISHEntry;
65
interface nsISHEntry;
66
interface nsILayoutHistoryState;
66
interface nsILayoutHistoryState;
67
interface nsISecureBrowserUI;
67
68
68
[scriptable, uuid(BBFDF99E-D675-42FD-B3EA-EA341C2331A6)]
69
[scriptable, uuid(BBFDF99E-D675-42FD-B3EA-EA341C2331A6)]
69
interface nsIDocShell : nsISupports
70
interface nsIDocShell : nsISupports
 Lines 340-344   interface nsIDocShell : nsISupports Link Here 
340
  attribute nsILayoutHistoryState layoutHistoryState;
341
  attribute nsILayoutHistoryState layoutHistoryState;
341
342
342
  readonly attribute boolean shouldSaveLayoutState;
343
  readonly attribute boolean shouldSaveLayoutState;
344
345
  /**
346
   * The SecureBrowserUI object for this docshell.  This is set by XUL
347
   * <browser> or nsWebBrowser for their root docshell.
348
   */
349
  attribute nsISecureBrowserUI securityUI;
343
};
350
};
344
351
(-)dom/public/base/nsPIDOMWindow.h (+13 lines)
Line     Link Here 
 Lines 124-129   public: Link Here 
124
    return !mIsDocumentLoaded || mRunningTimeout;
124
    return !mIsDocumentLoaded || mRunningTimeout;
125
  }
125
  }
126
126
127
  // Check whether a document is currently loading
128
  PRBool IsLoading() const
129
  {
130
    return !mIsDocumentLoaded;
131
  }
132
127
  PRBool IsHandlingResizeEvent() const
133
  PRBool IsHandlingResizeEvent() const
128
  {
134
  {
129
    return mIsHandlingResizeEvent;
135
    return mIsHandlingResizeEvent;
 Lines 139-144   public: Link Here 
139
  // Clear all pending timeouts and intervals.
145
  // Clear all pending timeouts and intervals.
140
  virtual void ClearAllTimeouts() = 0;
146
  virtual void ClearAllTimeouts() = 0;
141
  
147
  
148
  // Returns an object containing the window's state.  This also suspends
149
  // all running timeouts in the window.
150
  virtual nsresult SaveWindowState(nsISupports **aState) = 0;
151
152
  // Restore the window state from aState.
153
  virtual nsresult RestoreWindowState(nsISupports *aState) = 0;
154
142
protected:
155
protected:
143
  nsPIDOMWindow()
156
  nsPIDOMWindow()
144
    : mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE),
157
    : mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE),
(-)dom/public/coreEvents/nsIDOMLoadListener.h (-3 / +9 lines)
Line     Link Here 
 Lines 47-55    Link Here 
47
 *
47
 *
48
 */
48
 */
49
#define NS_IDOMLOADLISTENER_IID \
49
#define NS_IDOMLOADLISTENER_IID \
50
{ /* d1810238-14f8-4cab-9b96-96bedb9de7be */ \
50
{0x0f7fa587, 0xaac5, 0x11d9, \
51
0xd1810238, 0x14f8, 0x4cab, \
51
{0xba, 0x4e, 0x00, 0x11, 0x24, 0x78, 0xd6, 0x26} }
52
{0x9b, 0x96, 0x96, 0xbe, 0xdb, 0x9d, 0xe7, 0xbe} }
53
52
54
class nsIDOMLoadListener : public nsIDOMEventListener {
53
class nsIDOMLoadListener : public nsIDOMEventListener {
55
54
 Lines 91-96   public: Link Here 
91
   */
90
   */
92
  NS_IMETHOD Error(nsIDOMEvent* aEvent) = 0;
91
  NS_IMETHOD Error(nsIDOMEvent* aEvent) = 0;
93
92
93
  /**
94
   * Processes a DOMPageRestore event.  This is dispatched when a page's
95
   * presentation is restored from session history (onload does not fire
96
   * in this case).
97
   * @param aEvent The event object
98
   */
99
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent) = 0;
94
};
100
};
95
101
96
#endif // nsIDOMLoadListener_h__
102
#endif // nsIDOMLoadListener_h__
(-)dom/src/base/nsGlobalWindow.cpp (-4 / +378 lines)
Line     Link Here 
 Lines 153-158    Link Here 
153
153
154
#include "nsIBindingManager.h"
154
#include "nsIBindingManager.h"
155
#include "nsIXBLService.h"
155
#include "nsIXBLService.h"
156
#include "nsIDOMNSHTMLElement.h"
157
#include "nsIDOMXULElement.h"
156
158
157
// used for popup blocking, needs to be converted to something
159
// used for popup blocking, needs to be converted to something
158
// belonging to the back-end like nsIContentPolicy
160
// belonging to the back-end like nsIContentPolicy
 Lines 171-176   static PRInt32 gRunningTime Link Here 
171
PRInt32 gTimeoutCnt                                    = 0;
173
PRInt32 gTimeoutCnt                                    = 0;
172
#endif
174
#endif
173
175
176
#ifdef DEBUG_bryner
177
#define DEBUG_PAGE_CACHE
178
#endif
179
174
#define DOM_MIN_TIMEOUT_VALUE 10 // 10ms
180
#define DOM_MIN_TIMEOUT_VALUE 10 // 10ms
175
181
176
// CIDs
182
// CIDs
 Lines 4292-4301   nsGlobalWindow::GetPrivateRoot() Link Here 
4292
    nsIDocument* doc = chromeElement->GetDocument();
4298
    nsIDocument* doc = chromeElement->GetDocument();
4293
    if (doc) {
4299
    if (doc) {
4294
      parent = do_QueryInterface(doc->GetScriptGlobalObject());
4300
      parent = do_QueryInterface(doc->GetScriptGlobalObject());
4295
      nsCOMPtr<nsIDOMWindow> tempParent;
4301
      if (parent) {
4296
      parent->GetTop(getter_AddRefs(tempParent));
4302
        nsCOMPtr<nsIDOMWindow> tempParent;
4297
      return NS_STATIC_CAST(nsGlobalWindow *,
4303
        parent->GetTop(getter_AddRefs(tempParent));
4298
                            NS_STATIC_CAST(nsIDOMWindow*, tempParent));
4304
        return NS_STATIC_CAST(nsGlobalWindow *,
4305
                              NS_STATIC_CAST(nsIDOMWindow*, tempParent));
4306
      }
4299
    }
4307
    }
4300
  }
4308
  }
4301
4309
 Lines 5788-5793   nsGlobalWindow::EnsureSizeUpToDate() Link Here 
5788
  }
5796
  }
5789
}
5797
}
5790
5798
5799
#define WINDOWSTATEHOLDER_IID \
5800
{0xae1c7401, 0xcdee, 0x404a, {0xbd, 0x63, 0x05, 0xc0, 0x35, 0x0d, 0xa7, 0x72}}
5801
5802
class WindowStateHolder : public nsISupports
5803
{
5804
public:
5805
  NS_DEFINE_STATIC_IID_ACCESSOR(WINDOWSTATEHOLDER_IID)
5806
  NS_DECL_ISUPPORTS
5807
5808
  WindowStateHolder(JSContext *cx,  // The JSContext for the window 
5809
                    JSObject *aObject, // An object to save the properties onto
5810
                    nsGlobalWindow *aWindow); // The window to operate on
5811
5812
  // This is the property store object that holds the window properties.
5813
  JSObject* GetObject() { return mJSObj; }
5814
5815
  // Get the listener manager, which holds all event handlers for the window.
5816
  nsIEventListenerManager* GetListenerManager() { return mListenerManager; }
5817
5818
  // Get the contents of focus memory when the state was saved
5819
  // (if the focus was inside of this window).
5820
  nsIDOMElement* GetFocusedElement() { return mFocusedElement; }
5821
  nsIDOMWindowInternal* GetFocusedWindow() { return mFocusedWindow; }
5822
5823
  // Manage the list of saved timeouts for the window.
5824
  nsTimeout* GetSavedTimeouts() { return mSavedTimeouts; }
5825
  nsTimeout** GetTimeoutInsertionPoint() { return mTimeoutInsertionPoint; }
5826
  void ClearSavedTimeouts() { mSavedTimeouts = nsnull; }
5827
5828
private:
5829
  ~WindowStateHolder();
5830
5831
  JSRuntime *mRuntime;
5832
  JSObject *mJSObj;
5833
  nsCOMPtr<nsIEventListenerManager> mListenerManager;
5834
  nsCOMPtr<nsIDOMElement> mFocusedElement;
5835
  nsCOMPtr<nsIDOMWindowInternal> mFocusedWindow;
5836
  nsTimeout *mSavedTimeouts;
5837
  nsTimeout **mTimeoutInsertionPoint;
5838
};
5839
5840
WindowStateHolder::WindowStateHolder(JSContext *cx, JSObject *aObject,
5841
                                     nsGlobalWindow *aWindow)
5842
  : mRuntime(::JS_GetRuntime(cx)), mJSObj(aObject), mSavedTimeouts(nsnull)
5843
{
5844
  NS_ASSERTION(aWindow, "null window");
5845
5846
  aWindow->GetListenerManager(getter_AddRefs(mListenerManager));
5847
5848
  nsIFocusController *fc = aWindow->GetRootFocusController();
5849
  NS_ASSERTION(fc, "null focus controller");
5850
5851
  // We want to save the focused element/window only if they are inside of
5852
  // this window.
5853
5854
  nsCOMPtr<nsIDOMWindowInternal> focusWinInternal;
5855
  fc->GetFocusedWindow(getter_AddRefs(focusWinInternal));
5856
5857
  nsPIDOMWindow *focusedWindow =
5858
    NS_STATIC_CAST(nsPIDOMWindow*,
5859
                   NS_STATIC_CAST(nsGlobalWindow*,
5860
                                  NS_STATIC_CAST(nsIDOMWindowInternal*,
5861
                                                 focusWinInternal)));
5862
5863
  while (focusedWindow) {
5864
    if (focusedWindow == aWindow) {
5865
      fc->GetFocusedWindow(getter_AddRefs(mFocusedWindow));
5866
      fc->GetFocusedElement(getter_AddRefs(mFocusedElement));
5867
      break;
5868
    }
5869
5870
    focusedWindow =
5871
      NS_STATIC_CAST(nsGlobalWindow*, focusedWindow)->GetPrivateParent();
5872
  }
5873
5874
  aWindow->SuspendTimeouts();
5875
5876
  // Clear the timeout list for aWindow (but we don't need to for children)
5877
  mSavedTimeouts = aWindow->mTimeouts;
5878
  mTimeoutInsertionPoint = aWindow->mTimeoutInsertionPoint;
5879
5880
  aWindow->mTimeouts = nsnull;
5881
  aWindow->mTimeoutInsertionPoint = &aWindow->mTimeouts;
5882
5883
  ::JS_AddNamedRoot(cx, &mJSObj, "WindowStateHolder::mJSObj");
5884
}
5885
5886
WindowStateHolder::~WindowStateHolder()
5887
{
5888
  ::JS_RemoveRootRT(mRuntime, &mJSObj);
5889
}
5890
5891
NS_IMPL_ISUPPORTS1(WindowStateHolder, WindowStateHolder)
5892
5893
static JSClass sWindowStateClass = {
5894
  "window state", 0,
5895
  JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
5896
  JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
5897
  JSCLASS_NO_OPTIONAL_MEMBERS
5898
};
5899
5900
static nsresult
5901
CopyJSPropertyArray(JSContext *cx, JSObject *aSource, JSObject *aDest,
5902
                    JSIdArray *props)
5903
{
5904
  jsint length = props->length;
5905
  jsint i;
5906
  for (i = 0; i < length; ++i) {
5907
    jsval propname_value;
5908
5909
    if (!::JS_IdToValue(cx, props->vector[i], &propname_value) ||
5910
        !JSVAL_IS_STRING(propname_value)) {
5911
      NS_WARNING("Failed to copy non-string-named window property\n");
5912
      return NS_ERROR_FAILURE;
5913
    }
5914
5915
    JSString *propname = JSVAL_TO_STRING(propname_value);
5916
    jschar *propname_str = ::JS_GetStringChars(propname);
5917
    NS_ENSURE_TRUE(propname_str, NS_ERROR_FAILURE);
5918
5919
    size_t propname_len = ::JS_GetStringLength(propname);
5920
5921
    JSPropertyOp getter, setter;
5922
    uintN attrs;
5923
    JSBool found;
5924
    if (!::JS_GetUCPropertyAttrsGetterAndSetter(cx, aSource, propname_str,
5925
                                                propname_len, &attrs, &found,
5926
                                                &getter, &setter))
5927
      return NS_ERROR_FAILURE;
5928
5929
    NS_ENSURE_TRUE(found, NS_ERROR_UNEXPECTED);
5930
5931
    // We may hit an exception trying to retrieve the property value, so
5932
    // save off the exception state and ignore any exceptions we hit.
5933
5934
    JSExceptionState *state = ::JS_SaveExceptionState(cx);
5935
    NS_ENSURE_TRUE(state, NS_ERROR_FAILURE);
5936
5937
    jsval propvalue;
5938
    if (!::JS_GetUCProperty(cx, aSource, propname_str,
5939
                            propname_len, &propvalue)) {
5940
      // An exception was hit, so just define this value with a void value.
5941
      // This can happen if there was a native getter.
5942
      propvalue = JSVAL_VOID;
5943
    }
5944
    
5945
    ::JS_RestoreExceptionState(cx, state);
5946
5947
    PRBool res = ::JS_DefineUCProperty(cx, aDest, propname_str, propname_len,
5948
                                       propvalue, getter, setter, attrs);
5949
#ifdef DEBUG_PAGE_CACHE
5950
    if (res)
5951
      printf("Copied window property: %s\n",
5952
             NS_ConvertUTF16toUTF8(NS_STATIC_CAST(PRUnichar*,
5953
                                                  propname_str)).get());
5954
#endif
5955
5956
    if (!res) {
5957
#ifdef DEBUG
5958
      printf("failed to copy property: %s\n",
5959
             NS_ConvertUTF16toUTF8(NS_STATIC_CAST(PRUnichar*,
5960
                                                  propname_str)).get());
5961
#endif
5962
      return NS_ERROR_FAILURE;
5963
    }
5964
  }
5965
5966
  return NS_OK;
5967
}
5968
5969
static nsresult
5970
CopyJSProperties(JSContext *cx, JSObject *aSource, JSObject *aDest)
5971
{
5972
  // Enumerate all of the properties on aSource and install them on aDest.
5973
5974
  JSIdArray *props = ::JS_Enumerate(cx, aSource);
5975
  if (!props) {
5976
#ifdef DEBUG_PAGE_CACHE
5977
    printf("[no properties]\n");
5978
#endif
5979
    return NS_OK;
5980
  }
5981
5982
#ifdef DEBUG_PAGE_CACHE
5983
  printf("props length = %d\n", props->length);
5984
#endif
5985
5986
  nsresult rv = CopyJSPropertyArray(cx, aSource, aDest, props);
5987
  ::JS_DestroyIdArray(cx, props);
5988
  return rv;
5989
}
5990
5991
nsresult
5992
nsGlobalWindow::SaveWindowState(nsISupports **aState)
5993
{
5994
  *aState = nsnull;
5995
5996
  if (!mContext || !mJSObject) {
5997
    // The window may be getting torn down; don't bother saving state.
5998
    return NS_OK;
5999
  }
6000
6001
  JSContext *cx = NS_STATIC_CAST(JSContext*, mContext->GetNativeContext());
6002
  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
6003
6004
  JSObject *stateObj = ::JS_NewObject(cx, &sWindowStateClass, NULL, NULL);
6005
  NS_ENSURE_TRUE(stateObj, NS_ERROR_OUT_OF_MEMORY);
6006
6007
  // The window state object will root the JSObject.
6008
  *aState = new WindowStateHolder(cx, stateObj, this);
6009
  NS_ENSURE_TRUE(*aState, NS_ERROR_OUT_OF_MEMORY);
6010
6011
#ifdef DEBUG_PAGE_CACHE
6012
  printf("saving window state, stateObj = %p\n", stateObj);
6013
#endif
6014
  nsresult rv = CopyJSProperties(cx, mJSObject, stateObj);
6015
  NS_ENSURE_SUCCESS(rv, rv);
6016
6017
  NS_ADDREF(*aState);
6018
  return NS_OK;
6019
}
6020
6021
nsresult
6022
nsGlobalWindow::RestoreWindowState(nsISupports *aState)
6023
{
6024
  if (!mContext || !mJSObject) {
6025
    // The window may be getting torn down; don't bother restoring state.
6026
    return NS_OK;
6027
  }
6028
6029
  JSContext *cx = NS_STATIC_CAST(JSContext*, mContext->GetNativeContext());
6030
  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
6031
6032
  // Note that we don't need to call JS_ClearScope here.  The scope is already
6033
  // cleared by SetNewDocument(), and calling it again here will remove the
6034
  // XPConnect properties.
6035
6036
  nsCOMPtr<WindowStateHolder> holder = do_QueryInterface(aState);
6037
  if (holder) {
6038
#ifdef DEBUG_PAGE_CACHE
6039
    printf("restoring window state, stateObj = %p\n", holder->GetObject());
6040
#endif
6041
    nsresult rv = CopyJSProperties(cx, holder->GetObject(), mJSObject);
6042
    NS_ENSURE_SUCCESS(rv, rv);
6043
6044
    mListenerManager = holder->GetListenerManager();
6045
6046
    nsIDOMElement *focusedElement = holder->GetFocusedElement();
6047
    if (focusedElement) {
6048
      nsCOMPtr<nsIDOMNSHTMLElement> htmlElement =
6049
        do_QueryInterface(focusedElement);
6050
      if (htmlElement) {
6051
        htmlElement->Focus();
6052
      } else {
6053
        nsCOMPtr<nsIDOMXULElement> xulElement =
6054
          do_QueryInterface(focusedElement);
6055
        if (xulElement) {
6056
          xulElement->Focus();
6057
        }
6058
      }
6059
    } else {
6060
      nsIDOMWindowInternal *focusedWindow = holder->GetFocusedWindow();
6061
      if (focusedWindow) {
6062
        focusedWindow->Focus();
6063
      }
6064
    }
6065
  }
6066
6067
  mTimeouts = holder->GetSavedTimeouts();
6068
  mTimeoutInsertionPoint = holder->GetTimeoutInsertionPoint();
6069
6070
  holder->ClearSavedTimeouts();
6071
6072
  // If our state is being restored from history, we won't be getting an onload
6073
  // event.  Make sure we're marked as being completely loaded.
6074
  mIsDocumentLoaded = PR_TRUE;
6075
6076
  return ResumeTimeouts();
6077
}
6078
6079
void
6080
nsGlobalWindow::SuspendTimeouts()
6081
{
6082
  PRInt64 now = PR_IntervalNow();
6083
  for (nsTimeout *t = mTimeouts; t; t = t->mNext) {
6084
    // Change mWhen to be the time remaining for this timer.
6085
    t->mWhen = PR_MAX(0, t->mWhen - now);
6086
6087
    // Drop the XPCOM timer; we'll reschedule when restoring the state.
6088
    if (t->mTimer) {
6089
      t->mTimer->Cancel();
6090
      t->mTimer = nsnull;
6091
    }
6092
6093
    // We don't Release() the timeout because we still need it.
6094
  }
6095
6096
  // Suspend our children as well.
6097
  nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(mDocShell);
6098
  if (node) {
6099
    PRInt32 childCount = 0;
6100
    node->GetChildCount(&childCount);
6101
6102
    nsCOMPtr<nsIDocShellTreeItem> childShell;
6103
    for (PRInt32 i = 0; i < childCount; ++i) {
6104
      node->GetChildAt(i, getter_AddRefs(childShell));
6105
      NS_ASSERTION(childShell, "null child shell");
6106
6107
      nsCOMPtr<nsPIDOMWindow> pWin = do_GetInterface(childShell);
6108
      if (pWin) {
6109
        nsGlobalWindow *win =
6110
          NS_STATIC_CAST(nsGlobalWindow*,
6111
                         NS_STATIC_CAST(nsPIDOMWindow*, pWin));
6112
6113
        win->SuspendTimeouts();
6114
      }
6115
    }
6116
  }
6117
}
6118
6119
nsresult
6120
nsGlobalWindow::ResumeTimeouts()
6121
{
6122
  // Restore all of the timeouts, using the stored time remaining.
6123
6124
  PRInt64 now = PR_IntervalNow();
6125
  nsresult rv;
6126
6127
  for (nsTimeout *t = mTimeouts; t; t = t->mNext) {
6128
    PRInt32 interval = PR_MAX(t->mWhen, DOM_MIN_TIMEOUT_VALUE);
6129
    t->mWhen += now;
6130
6131
    t->mTimer = do_CreateInstance("@mozilla.org/timer;1");
6132
    NS_ENSURE_TRUE(t->mTimer, NS_ERROR_OUT_OF_MEMORY);
6133
6134
    rv = t->mTimer->InitWithFuncCallback(TimerCallback, t, interval,
6135
                                         nsITimer::TYPE_ONE_SHOT);
6136
    NS_ENSURE_SUCCESS(rv, rv);
6137
  }
6138
6139
  // Resume our children as well.
6140
  nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(mDocShell);
6141
  if (node) {
6142
    PRInt32 childCount = 0;
6143
    node->GetChildCount(&childCount);
6144
6145
    nsCOMPtr<nsIDocShellTreeItem> childShell;
6146
    for (PRInt32 i = 0; i < childCount; ++i) {
6147
      node->GetChildAt(i, getter_AddRefs(childShell));
6148
      NS_ASSERTION(childShell, "null child shell");
6149
6150
      nsCOMPtr<nsPIDOMWindow> pWin = do_GetInterface(childShell);
6151
      if (pWin) {
6152
        nsGlobalWindow *win =
6153
          NS_STATIC_CAST(nsGlobalWindow*,
6154
                         NS_STATIC_CAST(nsPIDOMWindow*, pWin));
6155
6156
        rv = win->ResumeTimeouts();
6157
        NS_ENSURE_SUCCESS(rv, rv);
6158
      }
6159
    }
6160
  }
6161
6162
  return NS_OK;
6163
}
6164
5791
// QueryInterface implementation for nsGlobalChromeWindow
6165
// QueryInterface implementation for nsGlobalChromeWindow
5792
NS_INTERFACE_MAP_BEGIN(nsGlobalChromeWindow)
6166
NS_INTERFACE_MAP_BEGIN(nsGlobalChromeWindow)
5793
  NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow)
6167
  NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow)
(-)dom/src/base/nsGlobalWindow.h (-1 / +7 lines)
Line     Link Here 
 Lines 204-210   public: Link Here 
204
  virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
204
  virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
205
205
206
  virtual NS_HIDDEN_(void) ClearAllTimeouts();
206
  virtual NS_HIDDEN_(void) ClearAllTimeouts();
207
  
207
  virtual NS_HIDDEN_(nsresult) SaveWindowState(nsISupports **aState);
208
  virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState);
209
  virtual NS_HIDDEN_(void) SuspendTimeouts();
210
  virtual NS_HIDDEN_(nsresult) ResumeTimeouts();
211
208
  // nsIDOMViewCSS
212
  // nsIDOMViewCSS
209
  NS_DECL_NSIDOMVIEWCSS
213
  NS_DECL_NSIDOMVIEWCSS
210
214
 Lines 220-225   public: Link Here 
220
  static void ShutDown();
224
  static void ShutDown();
221
  static PRBool IsCallerChrome();
225
  static PRBool IsCallerChrome();
222
226
227
  friend class WindowStateHolder;
228
223
protected:
229
protected:
224
  // Object Management
230
  // Object Management
225
  virtual ~nsGlobalWindow();
231
  virtual ~nsGlobalWindow();
(-)embedding/browser/cocoa/src/CHClickListener.mm (-16 / +18 lines)
Line     Link Here 
 Lines 203-230   CHClickListener::MouseDown(nsIDOMEvent* Link Here 
203
    nsCOMPtr<nsIScriptGlobalObject> sgo;
203
    nsCOMPtr<nsIScriptGlobalObject> sgo;
204
    doc->GetScriptGlobalObject(getter_AddRefs(sgo));
204
    doc->GetScriptGlobalObject(getter_AddRefs(sgo));
205
    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(sgo);
205
    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(sgo);
206
    PRInt32 scrollX, scrollY;
206
    if (window) {
207
    window->GetScrollX(&scrollX);
207
      PRInt32 scrollX, scrollY;
208
    window->GetScrollY(&scrollY);
208
      window->GetScrollX(&scrollX);
209
    xDelta += scrollX; // Normal direction.
209
      window->GetScrollY(&scrollY);
210
    yDelta -= scrollY; // Remember, y is flipped.
210
      xDelta += scrollX; // Normal direction.
211
      yDelta -= scrollY; // Remember, y is flipped.
211
    
212
    
212
#define XMENUOFFSET 20
213
#define XMENUOFFSET 20
213
#define MENUHEIGHT 20
214
#define MENUHEIGHT 20
214
    
215
    
215
    xDelta += XMENUOFFSET;
216
      xDelta += XMENUOFFSET;
216
    yDelta -= MENUHEIGHT*(selIndex+1);
217
      yDelta -= MENUHEIGHT*(selIndex+1);
217
    
218
    
218
    NSEvent* event = [NSApp currentEvent];
219
      NSEvent* event = [NSApp currentEvent];
219
    NSPoint point = [event locationInWindow];
220
      NSPoint point = [event locationInWindow];
220
    point.x -= xDelta;
221
      point.x -= xDelta;
221
    point.y -= yDelta;
222
      point.y -= yDelta;
222
223
223
    NSEvent* mouseEvent = [NSEvent mouseEventWithType: NSLeftMouseDown location: point
224
      NSEvent* mouseEvent = [NSEvent mouseEventWithType: NSLeftMouseDown location: point
224
                                        modifierFlags: 0 timestamp: [event timestamp]
225
                                          modifierFlags: 0 timestamp: [event timestamp]
225
                                         windowNumber: [event windowNumber] context: [event context]
226
                                           windowNumber: [event windowNumber] context: [event context]
226
                                          eventNumber: [event eventNumber] clickCount: [event clickCount] 																						 pressure: [event pressure]];
227
                                            eventNumber: [event eventNumber] clickCount: [event clickCount] 																						 pressure: [event pressure]];
227
    [NSMenu popUpContextMenu: menu withEvent: mouseEvent forView: [[event window] contentView]];
228
      [NSMenu popUpContextMenu: menu withEvent: mouseEvent forView: [[event window] contentView]];
229
    }
228
  }
230
  }
229
  return NS_OK;
231
  return NS_OK;
230
}
232
}
(-)embedding/browser/webBrowser/nsWebBrowser.cpp (-2 / +3 lines)
Line     Link Here 
 Lines 1215-1222   NS_IMETHODIMP nsWebBrowser::Create() Link Here 
1215
   rv = GetContentDOMWindow(getter_AddRefs(domWindow));
1215
   rv = GetContentDOMWindow(getter_AddRefs(domWindow));
1216
   if (NS_SUCCEEDED(rv))
1216
   if (NS_SUCCEEDED(rv))
1217
   {
1217
   {
1218
       mSecurityUI = do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv);
1218
       nsCOMPtr<nsISecureBrowserUI> securityUI =
1219
       if (NS_SUCCEEDED(rv))mSecurityUI->Init(domWindow);
1219
           do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv);
1220
       if (NS_SUCCEEDED(rv)) securityUI->Init(domWindow);
1220
   }
1221
   }
1221
1222
1222
   mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0)
1223
   mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0)
(-)embedding/browser/webBrowser/nsWebBrowser.h (-1 lines)
Line     Link Here 
 Lines 168-174   protected: Link Here 
168
   nativeWindow               mParentNativeWindow;
168
   nativeWindow               mParentNativeWindow;
169
   nsIWebProgressListener    *mProgressListener;
169
   nsIWebProgressListener    *mProgressListener;
170
   nsCOMPtr<nsIWebProgress>      mWebProgress;
170
   nsCOMPtr<nsIWebProgress>      mWebProgress;
171
   nsCOMPtr<nsISecureBrowserUI> mSecurityUI;
172
171
173
   nsCOMPtr<nsIPrintSettings> mPrintSettings;
172
   nsCOMPtr<nsIPrintSettings> mPrintSettings;
174
173
(-)embedding/tests/mfcembed/StdAfx.h (+1 lines)
Line     Link Here 
 Lines 115-120    Link Here 
115
#include "nsIEmbeddingSiteWindow2.h"
115
#include "nsIEmbeddingSiteWindow2.h"
116
#include "nsIWebBrowserFind.h"
116
#include "nsIWebBrowserFind.h"
117
#include "nsIWebBrowserFocus.h"
117
#include "nsIWebBrowserFocus.h"
118
#include "nsIURI.h"
118
119
119
// Printer Includes
120
// Printer Includes
120
#include "nsIWebBrowserPrint.h"
121
#include "nsIWebBrowserPrint.h"
(-)extensions/xmlextras/base/src/nsDOMParser.cpp (+6 lines)
Line     Link Here 
 Lines 333-338   nsDOMParser::Error(nsIDOMEvent* aEvent) Link Here 
333
  return NS_OK;
333
  return NS_OK;
334
}
334
}
335
335
336
NS_IMETHODIMP
337
nsDOMParser::PageRestore(nsIDOMEvent* aEvent)
338
{
339
  return NS_OK;
340
}
341
336
nsDOMParser::nsDOMParser()
342
nsDOMParser::nsDOMParser()
337
  : mLoopingForSyncLoad(PR_FALSE)
343
  : mLoopingForSyncLoad(PR_FALSE)
338
{
344
{
(-)extensions/xmlextras/base/src/nsDOMParser.h (+1 lines)
Line     Link Here 
 Lines 67-72   public: Link Here 
67
  NS_IMETHOD Unload(nsIDOMEvent* aEvent);
67
  NS_IMETHOD Unload(nsIDOMEvent* aEvent);
68
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
68
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
69
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
69
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
70
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent);
70
71
71
private:
72
private:
72
  nsCOMPtr<nsIURI> mBaseURI;
73
  nsCOMPtr<nsIURI> mBaseURI;
(-)extensions/xmlextras/base/src/nsLoadListenerProxy.cpp (+12 lines)
Line     Link Here 
 Lines 121-123   nsLoadListenerProxy::Error(nsIDOMEvent* Link Here 
121
  
121
  
122
  return NS_OK;
122
  return NS_OK;
123
}
123
}
124
125
NS_IMETHODIMP
126
nsLoadListenerProxy::PageRestore(nsIDOMEvent* aEvent)
127
{
128
  nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
129
130
  if (listener) {
131
    return listener->PageRestore(aEvent);
132
  }
133
  
134
  return NS_OK;
135
}
(-)extensions/xmlextras/base/src/nsLoadListenerProxy.h (+1 lines)
Line     Link Here 
 Lines 69-74   public: Link Here 
69
  NS_IMETHOD Unload(nsIDOMEvent* aEvent);
69
  NS_IMETHOD Unload(nsIDOMEvent* aEvent);
70
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
70
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
71
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
71
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
72
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent);
72
73
73
protected:
74
protected:
74
  nsWeakPtr  mParent;
75
  nsWeakPtr  mParent;
(-)extensions/xmlextras/base/src/nsXMLHttpRequest.cpp (+6 lines)
Line     Link Here 
 Lines 1738-1743   nsXMLHttpRequest::Error(nsIDOMEvent* aEv Link Here 
1738
  return NS_OK;
1738
  return NS_OK;
1739
}
1739
}
1740
1740
1741
NS_IMETHODIMP
1742
nsXMLHttpRequest::PageRestore(nsIDOMEvent* aEvent)
1743
{
1744
  return NS_OK;
1745
}
1746
1741
nsresult
1747
nsresult
1742
nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast,
1748
nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast,
1743
                              PRBool aClearEventListeners)
1749
                              PRBool aClearEventListeners)
(-)extensions/xmlextras/base/src/nsXMLHttpRequest.h (+1 lines)
Line     Link Here 
 Lines 97-102   public: Link Here 
97
  NS_IMETHOD Unload(nsIDOMEvent* aEvent);
97
  NS_IMETHOD Unload(nsIDOMEvent* aEvent);
98
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
98
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
99
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
99
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
100
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent);
100
101
101
  // nsIStreamListener
102
  // nsIStreamListener
102
  NS_DECL_NSISTREAMLISTENER
103
  NS_DECL_NSISTREAMLISTENER
(-)extensions/xmlextras/tests/TestXMLExtras.cpp (+1 lines)
Line     Link Here 
 Lines 78-83   public: Link Here 
78
  virtual nsresult Unload(nsIDOMEvent* aEvent) {printf("Unload\n"); return NS_OK;}
78
  virtual nsresult Unload(nsIDOMEvent* aEvent) {printf("Unload\n"); return NS_OK;}
79
  virtual nsresult Abort(nsIDOMEvent* aEvent)  {printf("Abort\n"); return NS_OK;}
79
  virtual nsresult Abort(nsIDOMEvent* aEvent)  {printf("Abort\n"); return NS_OK;}
80
  virtual nsresult Error(nsIDOMEvent* aEvent)  {printf("Error\n"); return NS_OK;}
80
  virtual nsresult Error(nsIDOMEvent* aEvent)  {printf("Error\n"); return NS_OK;}
81
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent) {printf("PageRestore\n"); return NS_OK;}
81
};
82
};
82
83
83
NS_IMPL_ADDREF(nsMyListener)
84
NS_IMPL_ADDREF(nsMyListener)
(-)layout/base/Makefile.in (+1 lines)
Line     Link Here 
 Lines 73-78   REQUIRES = xpcom \ Link Here 
73
		  util \
73
		  util \
74
		  windowwatcher \
74
		  windowwatcher \
75
		  accessibility \
75
		  accessibility \
76
		  shistory \
76
		  $(NULL)
77
		  $(NULL)
77
78
78
XPIDLSRCS	= \
79
XPIDLSRCS	= \
(-)layout/base/nsDocumentViewer.cpp (-86 / +150 lines)
Line     Link Here 
 Lines 148-154    Link Here 
148
#include "nsISupportsPrimitives.h"
148
#include "nsISupportsPrimitives.h"
149
149
150
// PrintOptions is now implemented by PrintSettingsService
150
// PrintOptions is now implemented by PrintSettingsService
151
static const char sPrintSettingsServiceContractID[] = "@mozilla.org/gfx/printsettings-service;1";
152
static const char sPrintOptionsContractID[]         = "@mozilla.org/gfx/printsettings-service;1";
151
static const char sPrintOptionsContractID[]         = "@mozilla.org/gfx/printsettings-service;1";
153
152
154
// Printing Events
153
// Printing Events
 Lines 189-194   static const char sPrintOptionsContractI Link Here 
189
#include "nsISelectionController.h"
188
#include "nsISelectionController.h"
190
189
191
#include "nsBidiUtils.h"
190
#include "nsBidiUtils.h"
191
#include "nsISHEntry.h"
192
192
193
//paint forcing
193
//paint forcing
194
#include "prenv.h"
194
#include "prenv.h"
 Lines 346-352   protected: Link Here 
346
  virtual ~DocumentViewerImpl();
346
  virtual ~DocumentViewerImpl();
347
347
348
private:
348
private:
349
  void ForceRefresh(void);
350
  nsresult MakeWindow(nsIWidget* aParentWidget,
349
  nsresult MakeWindow(nsIWidget* aParentWidget,
351
                      const nsRect& aBounds);
350
                      const nsRect& aBounds);
352
  nsresult InitInternal(nsIWidget* aParentWidget,
351
  nsresult InitInternal(nsIWidget* aParentWidget,
 Lines 398-427   protected: Link Here 
398
  nsCOMPtr<nsIDOMFocusListener> mFocusListener;
397
  nsCOMPtr<nsIDOMFocusListener> mFocusListener;
399
398
400
  nsCOMPtr<nsIContentViewer> mPreviousViewer;
399
  nsCOMPtr<nsIContentViewer> mPreviousViewer;
401
400
  nsCOMPtr<nsISHEntry> mSHEntry;
402
  PRPackedBool  mEnableRendering;
403
  PRPackedBool  mStopped;
404
  PRPackedBool  mLoaded;
405
  PRPackedBool  mDeferredWindowClose;
406
  PRInt16 mNumURLStarts;
407
  PRInt16 mDestroyRefCount;     // a second "refcount" for the document viewer's "destroy"
408
401
409
  nsIWidget* mParentWidget;          // purposely won't be ref counted
402
  nsIWidget* mParentWidget;          // purposely won't be ref counted
410
403
411
  PRPackedBool         mInPermitUnload;
404
  PRInt16 mNumURLStarts;
405
  PRInt16 mDestroyRefCount;    // a second "refcount" for the document viewer's "destroy"
406
407
  unsigned      mEnableRendering : 1;
408
  unsigned      mStopped : 1;
409
  unsigned      mLoaded : 1;
410
  unsigned      mDeferredWindowClose : 1;
411
  // document management data
412
  //   these items are specific to markup documents (html and xml)
413
  //   may consider splitting these out into a subclass
414
  unsigned      mIsSticky : 1;
415
  unsigned      mInPermitUnload : 1;
412
416
413
#ifdef NS_PRINTING
417
#ifdef NS_PRINTING
414
  PRPackedBool          mClosingWhilePrinting;
418
  unsigned      mClosingWhilePrinting : 1;
415
  nsPrintEngine*        mPrintEngine;
419
416
  nsCOMPtr<nsIDOMWindowInternal> mDialogParentWin;
417
#if NS_PRINT_PREVIEW
420
#if NS_PRINT_PREVIEW
418
  // These data member support delayed printing when the document is loading
421
  // These data members support delayed printing when the document is loading
422
  unsigned                         mPrintIsPending : 1;
423
  unsigned                         mPrintDocIsFullyLoaded : 1;
419
  nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
424
  nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
420
  nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
425
  nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
421
  PRPackedBool                     mPrintIsPending;
422
  PRPackedBool                     mPrintDocIsFullyLoaded;
423
#endif // NS_PRINT_PREVIEW
426
#endif // NS_PRINT_PREVIEW
424
427
428
  nsPrintEngine*        mPrintEngine;
429
  nsCOMPtr<nsIDOMWindowInternal> mDialogParentWin;
430
425
#ifdef NS_DEBUG
431
#ifdef NS_DEBUG
426
  FILE* mDebugFile;
432
  FILE* mDebugFile;
427
#endif // NS_DEBUG
433
#endif // NS_DEBUG
 Lines 434-443   protected: Link Here 
434
  nsCString mForceCharacterSet;
440
  nsCString mForceCharacterSet;
435
  nsCString mPrevDocCharacterSet;
441
  nsCString mPrevDocCharacterSet;
436
  
442
  
437
  // document management data
438
  //   these items are specific to markup documents (html and xml)
439
  //   may consider splitting these out into a subclass
440
  PRPackedBool mIsSticky;
441
443
442
};
444
};
443
445
 Lines 494-501   void DocumentViewerImpl::PrepareToStartL Link Here 
494
// Note: operator new zeros our memory, so no need to init things to null.
496
// Note: operator new zeros our memory, so no need to init things to null.
495
DocumentViewerImpl::DocumentViewerImpl(nsPresContext* aPresContext)
497
DocumentViewerImpl::DocumentViewerImpl(nsPresContext* aPresContext)
496
  : mPresContext(aPresContext),
498
  : mPresContext(aPresContext),
497
    mHintCharsetSource(kCharsetUninitialized),
499
    mIsSticky(PR_TRUE),
498
    mIsSticky(PR_TRUE)
500
    mHintCharsetSource(kCharsetUninitialized)
499
{
501
{
500
  PrepareToStartLoad();
502
  PrepareToStartLoad();
501
}
503
}
 Lines 511-519   NS_IMPL_ISUPPORTS7(DocumentViewerImpl, Link Here 
511
513
512
DocumentViewerImpl::~DocumentViewerImpl()
514
DocumentViewerImpl::~DocumentViewerImpl()
513
{
515
{
514
  NS_ASSERTION(!mDocument, "User did not call nsIContentViewer::Close");
515
  if (mDocument) {
516
  if (mDocument) {
516
    Close();
517
    Close();
518
    mDocument->Destroy();
517
  }
519
  }
518
520
519
  NS_ASSERTION(!mPresShell && !mPresContext,
521
  NS_ASSERTION(!mPresShell && !mPresContext,
 Lines 795-813   DocumentViewerImpl::InitInternal(nsIWidg Link Here 
795
      makeCX = PR_TRUE;
797
      makeCX = PR_TRUE;
796
#endif
798
#endif
797
    }
799
    }
798
  }
799
800
800
  if (aDoCreation && mPresContext) {
801
    if (mPresContext) {
801
    // Create the ViewManager and Root View...
802
      // Create the ViewManager and Root View...
802
803
803
    // We must do this before we tell the script global object about
804
      // We must do this before we tell the script global object about
804
    // this new document since doing that will cause us to re-enter
805
      // this new document since doing that will cause us to re-enter
805
    // into nsSubDocumentFrame code through reflows caused by
806
      // into nsSubDocumentFrame code through reflows caused by
806
    // FlushPendingNotifications() calls down the road...
807
      // FlushPendingNotifications() calls down the road...
807
808
808
    rv = MakeWindow(aParentWidget, aBounds);
809
      rv = MakeWindow(aParentWidget, aBounds);
809
    NS_ENSURE_SUCCESS(rv, rv);
810
      NS_ENSURE_SUCCESS(rv, rv);
810
    Hide();
811
      Hide();
812
    }
811
  }
813
  }
812
814
813
  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));
815
  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));
 Lines 1171-1176   DocumentViewerImpl::Unload() Link Here 
1171
}
1173
}
1172
1174
1173
NS_IMETHODIMP
1175
NS_IMETHODIMP
1176
DocumentViewerImpl::Open()
1177
{
1178
  NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
1179
1180
  nsRect bounds;
1181
  mWindow->GetBounds(bounds);
1182
1183
  nsresult rv = InitInternal(mParentWidget, mDeviceContext, bounds,
1184
                             PR_FALSE, PR_FALSE);
1185
  NS_ENSURE_SUCCESS(rv, rv);
1186
1187
  SyncParentSubDocMap();
1188
1189
  // XXX re-enable image animations once that works correctly
1190
1191
  return NS_OK;
1192
}
1193
1194
NS_IMETHODIMP
1174
DocumentViewerImpl::Close()
1195
DocumentViewerImpl::Close()
1175
{
1196
{
1176
  // All callers are supposed to call close to break circular
1197
  // All callers are supposed to call close to break circular
 Lines 1184-1249   DocumentViewerImpl::Close() Link Here 
1184
  // for an object that can be switched in and out so that we don't need
1205
  // for an object that can be switched in and out so that we don't need
1185
  // to disable scripts during paint suppression.
1206
  // to disable scripts during paint suppression.
1186
1207
1187
  if (mDocument) {
1208
  if (!mDocument)
1209
    return NS_OK;
1210
1188
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
1211
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
1189
    // Turn scripting back on
1212
  // Turn scripting back on
1190
    // after PrintPreview had turned it off
1213
  // after PrintPreview had turned it off
1191
    if (GetIsPrintPreview() && mPrintEngine) {
1214
  if (GetIsPrintPreview() && mPrintEngine) {
1192
      mPrintEngine->TurnScriptingOn(PR_TRUE);
1215
    mPrintEngine->TurnScriptingOn(PR_TRUE);
1193
    }
1216
  }
1194
#endif
1217
#endif
1195
1218
1196
    // Break global object circular reference on the document created
1219
  // Break global object circular reference on the document created
1197
    // in the DocViewer Init
1220
  // in the DocViewer Init
1198
    nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();
1221
  nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();
1199
1222
1200
    if (globalObject) {
1223
  if (globalObject) {
1201
      globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);
1224
    globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);
1202
    }
1225
  }
1203
1226
1204
#ifdef NS_PRINTING
1227
#ifdef NS_PRINTING
1205
    // A Close was called while we were printing
1228
  // A Close was called while we were printing
1206
    // so don't clear the ScriptGlobalObject
1229
  // so don't clear the ScriptGlobalObject
1207
    // or clear the mDocument below
1230
  // or clear the mDocument below
1208
    // Also, do an extra addref to keep the viewer from going away.
1231
  // Also, do an extra addref to keep the viewer from going away.
1209
    if (mPrintEngine && !mClosingWhilePrinting) {
1232
  if (mPrintEngine && !mClosingWhilePrinting) {
1210
      mClosingWhilePrinting = PR_TRUE;
1233
    mClosingWhilePrinting = PR_TRUE;
1211
      NS_ADDREF_THIS();
1234
    NS_ADDREF_THIS();
1212
    } else {
1235
  } else {
1213
      // out of band cleanup of webshell
1236
    // out of band cleanup of webshell
1214
      mDocument->SetScriptGlobalObject(nsnull);
1215
    }
1216
#else
1217
    mDocument->SetScriptGlobalObject(nsnull);
1237
    mDocument->SetScriptGlobalObject(nsnull);
1238
  }
1239
#else
1240
  mDocument->SetScriptGlobalObject(nsnull);
1218
#endif
1241
#endif
1219
1242
1220
    if (mFocusListener) {
1243
  if (mFocusListener) {
1221
      // get the DOM event receiver
1244
    // get the DOM event receiver
1222
      nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
1245
    nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
1223
      NS_WARN_IF_FALSE(erP, "No event receiver in document!");
1246
    NS_WARN_IF_FALSE(erP, "No event receiver in document!");
1224
1247
1225
      if (erP) {
1248
    if (erP) {
1226
        erP->RemoveEventListenerByIID(mFocusListener,
1249
      erP->RemoveEventListenerByIID(mFocusListener,
1227
                                      NS_GET_IID(nsIDOMFocusListener));
1250
                                    NS_GET_IID(nsIDOMFocusListener));
1228
      }
1229
    }
1251
    }
1230
  }
1252
  }
1231
1253
1232
#ifdef NS_PRINTING
1233
  // Don't clear the document if we are printing.
1234
  if (!mClosingWhilePrinting) {
1235
    mDocument = nsnull;
1236
  }
1237
#else
1238
    mDocument = nsnull;
1239
#endif
1240
1241
  return NS_OK;
1254
  return NS_OK;
1242
}
1255
}
1243
1256
1244
NS_IMETHODIMP
1257
NS_IMETHODIMP
1245
DocumentViewerImpl::Destroy()
1258
DocumentViewerImpl::Destroy()
1246
{
1259
{
1260
  NS_ASSERTION(mDocument, "No document in Destroy()!");
1261
1247
#ifdef NS_PRINTING
1262
#ifdef NS_PRINTING
1248
  // Here is where we check to see if the docment was still being prepared 
1263
  // Here is where we check to see if the docment was still being prepared 
1249
  // for printing when it was asked to be destroy from someone externally
1264
  // for printing when it was asked to be destroy from someone externally
 Lines 1258-1270   DocumentViewerImpl::Destroy() Link Here 
1258
  }
1273
  }
1259
#endif
1274
#endif
1260
1275
1261
  // Don't let the document get unloaded while we are printing
1276
  // Don't let the document get unloaded while we are printing.
1262
  // this could happen if we hit the back button during printing
1277
  // this could happen if we hit the back button during printing.
1278
  // We also keep the viewer from being cached in session history, since
1279
  // we require all documents there to be sanitized.
1263
  if (mDestroyRefCount != 0) {
1280
  if (mDestroyRefCount != 0) {
1264
    --mDestroyRefCount;
1281
    --mDestroyRefCount;
1265
    return NS_OK;
1282
    return NS_OK;
1266
  }
1283
  }
1267
1284
1285
  // If we were told to put ourselves into session history instead of destroy
1286
  // the presentation, do that now.
1287
  if (mSHEntry) {
1288
    if (mPresShell)
1289
      mPresShell->Freeze();
1290
1291
    // Make sure the presentation isn't torn down by Hide().
1292
    mSHEntry->SetSticky(mIsSticky);
1293
    mIsSticky = PR_TRUE;
1294
1295
    mSHEntry->SetContentViewer(this);
1296
1297
    // Remove our root view from the view hierarchy.
1298
    if (mPresShell) {
1299
      nsIViewManager *vm = mPresShell->GetViewManager();
1300
      if (vm) {
1301
        nsIView *rootView = nsnull;
1302
        vm->GetRootView(rootView);
1303
1304
        if (rootView) {
1305
          nsIView *rootViewParent = rootView->GetParent();
1306
          if (rootViewParent) {
1307
            nsIViewManager *parentVM = rootViewParent->GetViewManager();
1308
            if (parentVM) {
1309
              parentVM->RemoveChild(rootView);
1310
            }
1311
          }
1312
        }
1313
      }
1314
1315
      mPresShell->InvalidateViewManagers();
1316
    }
1317
1318
    mSHEntry = nsnull;
1319
1320
    Hide();
1321
1322
    // This is after Hide() so that the user doesn't see the inputs clear.
1323
    if (mDocument)
1324
      mDocument->Sanitize();
1325
1326
    return NS_OK;
1327
  }
1328
1329
  mDocument->Destroy();
1330
  mDocument = nsnull;
1331
1268
  // All callers are supposed to call destroy to break circular
1332
  // All callers are supposed to call destroy to break circular
1269
  // references.  If we do this stuff in the destructor, the
1333
  // references.  If we do this stuff in the destructor, the
1270
  // destructor might never be called (especially if we're being
1334
  // destructor might never be called (especially if we're being
 Lines 1323-1330   DocumentViewerImpl::Stop(void) Link Here 
1323
    mDocument->StopDocumentLoad();
1387
    mDocument->StopDocumentLoad();
1324
  }
1388
  }
1325
1389
1326
  if (mEnableRendering && (mLoaded || mStopped) && mPresContext)
1390
  if (mEnableRendering && (mLoaded || mStopped) && mPresContext) {
1327
    mPresContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
1391
    mPresContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
1392
  }
1328
1393
1329
  mStopped = PR_TRUE;
1394
  mStopped = PR_TRUE;
1330
1395
 Lines 1669-1675   DocumentViewerImpl::Hide(void) Link Here 
1669
    return NS_OK;
1734
    return NS_OK;
1670
  }
1735
  }
1671
1736
1672
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
1673
  NS_PRECONDITION(mWindow, "null window");
1737
  NS_PRECONDITION(mWindow, "null window");
1674
  if (mWindow) {
1738
  if (mWindow) {
1675
    mWindow->Show(PR_FALSE);
1739
    mWindow->Show(PR_FALSE);
 Lines 1787-1792   DocumentViewerImpl::SetSticky(PRBool aSt Link Here 
1787
}
1851
}
1788
1852
1789
NS_IMETHODIMP
1853
NS_IMETHODIMP
1854
DocumentViewerImpl::SetHistoryEntry(nsISHEntry *aEntry)
1855
{
1856
  mSHEntry = aEntry;
1857
  return NS_OK;
1858
}
1859
1860
NS_IMETHODIMP
1790
DocumentViewerImpl::GetEnableRendering(PRBool* aResult)
1861
DocumentViewerImpl::GetEnableRendering(PRBool* aResult)
1791
{
1862
{
1792
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
1863
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
 Lines 1811-1823   DocumentViewerImpl::RequestWindowClose(P Link Here 
1811
  return NS_OK;
1882
  return NS_OK;
1812
}
1883
}
1813
1884
1814
1815
void
1816
DocumentViewerImpl::ForceRefresh()
1817
{
1818
  mWindow->Invalidate(PR_TRUE);
1819
}
1820
1821
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
1885
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
1822
1886
1823
PR_STATIC_CALLBACK(PRBool)
1887
PR_STATIC_CALLBACK(PRBool)
(-)layout/base/nsIDocumentViewer.h (-1 / +1 lines)
Line     Link Here 
 Lines 45-51   class nsIPresShell; Link Here 
45
class nsIStyleSheet;
45
class nsIStyleSheet;
46
46
47
#define NS_IDOCUMENT_VIEWER_IID \
47
#define NS_IDOCUMENT_VIEWER_IID \
48
 { 0xa6cf9057, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
48
 { 0x09ad1126, 0xb397, 0x11d9,{0xa5, 0x2c, 0x00, 0x11, 0x24, 0x78, 0xd6, 0x26}}
49
49
50
/**
50
/**
51
 * A document viewer is a kind of content viewer that uses NGLayout
51
 * A document viewer is a kind of content viewer that uses NGLayout
(-)layout/base/nsIPresShell.h (-2 / +19 lines)
Line     Link Here 
 Lines 89-96   class nsIStyleSheet; Link Here 
89
class nsCSSFrameConstructor;
89
class nsCSSFrameConstructor;
90
90
91
#define NS_IPRESSHELL_IID     \
91
#define NS_IPRESSHELL_IID     \
92
{ 0x3b864134, 0x4e25, 0x4cd0, \
92
{ 0x3861ee48, 0xb397, 0x11d9, \
93
  {0xa6, 0x9e, 0x34, 0x14, 0x13, 0x18, 0x39, 0x58} }
93
  {0x86, 0x9e, 0x00, 0x11, 0x24, 0x78, 0xd6, 0x26} }
94
94
95
// Constants uses for ScrollFrameIntoView() function
95
// Constants uses for ScrollFrameIntoView() function
96
#define NS_PRESSHELL_SCROLL_TOP      0
96
#define NS_PRESSHELL_SCROLL_TOP      0
 Lines 677-682   public: Link Here 
677
  virtual void ListStyleSheets(FILE *out, PRInt32 aIndent = 0) = 0;
677
  virtual void ListStyleSheets(FILE *out, PRInt32 aIndent = 0) = 0;
678
#endif
678
#endif
679
679
680
  /**
681
   * Stop all active elements (plugins and the caret) in this presentation.
682
   * XXX this should include image animations
683
   */
684
  virtual void Freeze() = 0;
685
686
  /**
687
   * Restarts active elements (plugins) in this presentation.
688
   */
689
  virtual void Thaw() = 0;
690
691
  /**
692
   * Call InvalidateHierarchy() on our view manager and the view manager
693
   * of any child documents, recursively.
694
   */
695
  virtual void InvalidateViewManagers() = 0;
696
680
protected:
697
protected:
681
  // IMPORTANT: The ownership implicit in the following member variables
698
  // IMPORTANT: The ownership implicit in the following member variables
682
  // has been explicitly checked.  If you add any members to this class,
699
  // has been explicitly checked.  If you add any members to this class,
(-)layout/base/nsLayoutAtomList.h (+1 lines)
Line     Link Here 
 Lines 164-169   LAYOUT_ATOM(oncontextmenu, "oncontextmen Link Here 
164
LAYOUT_ATOM(onDOMActivate, "onDOMActivate")
164
LAYOUT_ATOM(onDOMActivate, "onDOMActivate")
165
LAYOUT_ATOM(onDOMFocusIn, "onDOMFocusIn")
165
LAYOUT_ATOM(onDOMFocusIn, "onDOMFocusIn")
166
LAYOUT_ATOM(onDOMFocusOut, "onDOMFocusOut")
166
LAYOUT_ATOM(onDOMFocusOut, "onDOMFocusOut")
167
LAYOUT_ATOM(onDOMPageRestore, "onDOMPageRestore")
167
LAYOUT_ATOM(ondblclick, "ondblclick")
168
LAYOUT_ATOM(ondblclick, "ondblclick")
168
LAYOUT_ATOM(ondragdrop, "ondragdrop")
169
LAYOUT_ATOM(ondragdrop, "ondragdrop")
169
LAYOUT_ATOM(ondragenter, "ondragenter")
170
LAYOUT_ATOM(ondragenter, "ondragenter")
(-)layout/base/nsPresShell.cpp (+164 lines)
Line     Link Here 
 Lines 151-156    Link Here 
151
#include "nsIDOMWindowInternal.h"
151
#include "nsIDOMWindowInternal.h"
152
#include "nsPIDOMWindow.h"
152
#include "nsPIDOMWindow.h"
153
#include "nsIFocusController.h"
153
#include "nsIFocusController.h"
154
#include "nsIPluginInstance.h"
155
#include "nsIObjectFrame.h"
156
#include "nsIPluginHost.h"
157
#include "nsIDocShellTreeNode.h"
154
158
155
// Drag & Drop, Clipboard
159
// Drag & Drop, Clipboard
156
#include "nsWidgetsCID.h"
160
#include "nsWidgetsCID.h"
 Lines 1204-1209   public: Link Here 
1204
  NS_IMETHOD IsReflowLocked(PRBool* aIsLocked);  
1208
  NS_IMETHOD IsReflowLocked(PRBool* aIsLocked);  
1205
1209
1206
  virtual nsresult ReconstructFrames(void);
1210
  virtual nsresult ReconstructFrames(void);
1211
  virtual void Freeze();
1212
  virtual void Thaw();
1213
1214
  virtual void InvalidateViewManagers();
1207
1215
1208
#ifdef IBMBIDI
1216
#ifdef IBMBIDI
1209
  NS_IMETHOD SetCaretBidiLevel(PRUint8 aLevel);
1217
  NS_IMETHOD SetCaretBidiLevel(PRUint8 aLevel);
 Lines 1391-1396   protected: Link Here 
1391
1399
1392
  nsresult GetSelectionForCopy(nsISelection** outSelection);
1400
  nsresult GetSelectionForCopy(nsISelection** outSelection);
1393
1401
1402
  void HideCaret();
1403
1394
  nsICSSStyleSheet*         mPrefStyleSheet; // mStyleSet owns it but we maintain a ref, may be null
1404
  nsICSSStyleSheet*         mPrefStyleSheet; // mStyleSet owns it but we maintain a ref, may be null
1395
#ifdef DEBUG
1405
#ifdef DEBUG
1396
  PRUint32                  mUpdateCount;
1406
  PRUint32                  mUpdateCount;
 Lines 1513-1518   private: Link Here 
1513
  void FireResizeEvent();
1523
  void FireResizeEvent();
1514
  static void sResizeEventCallback(nsITimer* aTimer, void* aPresShell) ;
1524
  static void sResizeEventCallback(nsITimer* aTimer, void* aPresShell) ;
1515
  nsCOMPtr<nsITimer> mResizeEventTimer;
1525
  nsCOMPtr<nsITimer> mResizeEventTimer;
1526
1527
  typedef void (*nsPluginEnumCallback)(PresShell*, nsIContent*);
1528
  void EnumeratePlugins(nsIDOMDocument *aDocument,
1529
                        const nsString &aPluginTag,
1530
                        nsPluginEnumCallback aCallback);
1516
};
1531
};
1517
1532
1518
#ifdef PR_LOGGING
1533
#ifdef PR_LOGGING
 Lines 6470-6475   PresShell::RemoveOverrideStyleSheet(nsIS Link Here 
6470
  return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
6485
  return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
6471
}
6486
}
6472
6487
6488
static void
6489
StopPluginInstance(PresShell *aShell, nsIContent *aContent)
6490
{
6491
  nsIFrame *frame = aShell->FrameManager()->GetPrimaryFrameFor(aContent);
6492
6493
  nsIObjectFrame *objectFrame = nsnull;
6494
  if (frame)
6495
    CallQueryInterface(frame, &objectFrame);
6496
  if (!objectFrame)
6497
    return;
6498
6499
  nsCOMPtr<nsIPluginInstance> instance;
6500
  objectFrame->GetPluginInstance(*getter_AddRefs(instance));
6501
  if (!instance)
6502
    return;
6503
6504
  // Check whether the plugin wants SetWindow to be called before or after
6505
  // Stop/Destroy.  This is similar to nsObjectFrame::Destroy(), but we
6506
  // don't want to destroy the frame just yet.
6507
6508
  PRBool callSetWindowLast = PR_FALSE;
6509
  instance->GetValue(nsPluginInstanceVariable_CallSetWindowAfterDestroyBool,
6510
                     (void *) &callSetWindowLast);
6511
  if (callSetWindowLast) {
6512
    instance->Stop();
6513
    instance->Destroy();
6514
    instance->SetWindow(nsnull);
6515
  } else {
6516
    instance->SetWindow(nsnull);
6517
    instance->Stop();
6518
    instance->Destroy();
6519
  }
6520
6521
  nsCOMPtr<nsIPluginHost> pluginHost =
6522
    do_GetService("@mozilla.org/plugin/host;1");
6523
  if (pluginHost)
6524
    pluginHost->StopPluginInstance(instance);
6525
}
6526
6527
void
6528
PresShell::Freeze()
6529
{
6530
  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
6531
  if (domDoc) {
6532
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("object"), StopPluginInstance);
6533
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("applet"), StopPluginInstance);
6534
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("embed"), StopPluginInstance);
6535
  }
6536
6537
  HideCaret();
6538
}
6539
6540
static void
6541
StartPluginInstance(PresShell *aShell, nsIContent *aContent)
6542
{
6543
  // For now we just reconstruct the frame.
6544
  aShell->RecreateFramesFor(aContent);
6545
}
6546
6547
void
6548
PresShell::Thaw()
6549
{
6550
  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
6551
  if (domDoc) {
6552
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("object"), StartPluginInstance);
6553
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("applet"), StartPluginInstance);
6554
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("embed"), StartPluginInstance);
6555
  }
6556
}
6557
6558
void
6559
PresShell::HideCaret()
6560
{
6561
  if (mCaret)
6562
    mCaret->SetCaretVisible(PR_FALSE);
6563
6564
  if (!mPresContext)
6565
    return;
6566
6567
  nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
6568
  nsCOMPtr<nsIDocShellTreeNode> shell = do_QueryInterface(container);
6569
6570
  if (!shell)
6571
    return;
6572
6573
  PRInt32 childCount = 0;
6574
  shell->GetChildCount(&childCount);
6575
6576
  nsCOMPtr<nsIDocShellTreeItem> child;
6577
  nsCOMPtr<nsIPresShell> childShell;
6578
6579
  for (PRInt32 i = 0; i < childCount; ++i) {
6580
    shell->GetChildAt(i, getter_AddRefs(child));
6581
    childShell = do_GetInterface(child);
6582
    if (childShell)
6583
      NS_STATIC_CAST(PresShell*,
6584
                     NS_STATIC_CAST(nsIPresShell*, childShell))->HideCaret();
6585
  }
6586
}
6587
6588
static PRBool
6589
InvalidateVMCallback(nsIDocument *aDocument, void *aData)
6590
{
6591
  NS_ASSERTION(aDocument, "null document passed to callback");
6592
6593
  nsIPresShell *shell = aDocument->GetShellAt(0);
6594
  if (shell)
6595
    shell->InvalidateViewManagers();
6596
6597
  return PR_TRUE;
6598
}
6599
6600
void
6601
PresShell::InvalidateViewManagers()
6602
{
6603
  if (mViewManager)
6604
    mViewManager->InvalidateHierarchy();
6605
6606
  // Get the list of child documents.
6607
  if (mDocument)
6608
    mDocument->EnumerateSubDocuments(InvalidateVMCallback, nsnull);
6609
}
6610
6473
//--------------------------------------------------------
6611
//--------------------------------------------------------
6474
// Start of protected and private methods on the PresShell
6612
// Start of protected and private methods on the PresShell
6475
//--------------------------------------------------------
6613
//--------------------------------------------------------
 Lines 7038-7043   PresShell::Observe(nsISupports* aSubject Link Here 
7038
  return NS_ERROR_FAILURE;
7176
  return NS_ERROR_FAILURE;
7039
}
7177
}
7040
7178
7179
void
7180
PresShell::EnumeratePlugins(nsIDOMDocument *aDocument,
7181
                            const nsString &aPluginTag,
7182
                            nsPluginEnumCallback aCallback)
7183
{
7184
  nsCOMPtr<nsIDOMNodeList> nodes;
7185
  aDocument->GetElementsByTagName(aPluginTag, getter_AddRefs(nodes));
7186
  if (!nodes)
7187
    return;
7188
7189
  PRUint32 length;
7190
  nodes->GetLength(&length);
7191
7192
  nsCOMPtr<nsIDOMNode> node;
7193
  nsCOMPtr<nsIContent> content;
7194
7195
  //  nsFrameManager *fm = FrameManager();
7196
7197
  for (PRUint32 i = 0; i < length; ++i) {
7198
    nodes->Item(i, getter_AddRefs(node));
7199
    content = do_QueryInterface(node);
7200
    if (content)
7201
      aCallback(this, content);
7202
  }
7203
}
7204
7041
//------------------------------------------------------
7205
//------------------------------------------------------
7042
// End of protected and private methods on the PresShell
7206
// End of protected and private methods on the PresShell
7043
//------------------------------------------------------
7207
//------------------------------------------------------
(-)layout/printing/nsPrintEngine.cpp (-4 / +5 lines)
Line     Link Here 
 Lines 4435-4444   nsPrintEngine::TurnScriptingOn(PRBool aD Link Here 
4435
4435
4436
  // get the script global object
4436
  // get the script global object
4437
  nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject();
4437
  nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject();
4438
  NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject");
4438
  if (scriptGlobalObj) {
4439
  nsIScriptContext *scx = scriptGlobalObj->GetContext();
4439
    nsIScriptContext *scx = scriptGlobalObj->GetContext();
4440
  NS_ASSERTION(scx, "Can't get nsIScriptContext");
4440
    NS_ASSERTION(scx, "Can't get nsIScriptContext");
4441
  scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
4441
    scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
4442
  }
4442
}
4443
}
4443
4444
4444
//-----------------------------------------------------------------
4445
//-----------------------------------------------------------------
(-)layout/xul/base/src/nsMenuPopupFrame.cpp (+3 lines)
Line     Link Here 
 Lines 840-845   nsMenuPopupFrame::SyncViewWithFrame(nsPr Link Here 
840
  // the left or top sides of the screen may be in negative space (main monitor is on the
840
  // the left or top sides of the screen may be in negative space (main monitor is on the
841
  // right, etc). We need to be sure to do the right thing.
841
  // right, etc). We need to be sure to do the right thing.
842
  nsCOMPtr<nsIDOMWindowInternal> window(do_QueryInterface(document->GetScriptGlobalObject()));
842
  nsCOMPtr<nsIDOMWindowInternal> window(do_QueryInterface(document->GetScriptGlobalObject()));
843
  if (!window)
844
    return NS_OK;
845
843
  nsCOMPtr<nsIDOMScreen> screen;
846
  nsCOMPtr<nsIDOMScreen> screen;
844
  window->GetScreen(getter_AddRefs(screen));
847
  window->GetScreen(getter_AddRefs(screen));
845
  PRInt32 screenWidth = 0, screenHeight = 0;
848
  PRInt32 screenWidth = 0, screenHeight = 0;
(-)layout/xul/base/src/nsTitleBarFrame.cpp (-9 / +4 lines)
Line     Link Here 
 Lines 169-183   nsTitleBarFrame::HandleEvent(nsPresConte Link Here 
169
			   nsCOMPtr<nsIDOMWindowInternal>
169
			   nsCOMPtr<nsIDOMWindowInternal>
170
           window(do_QueryInterface(aPresContext->PresShell()->GetDocument()->GetScriptGlobalObject()));
170
           window(do_QueryInterface(aPresContext->PresShell()->GetDocument()->GetScriptGlobalObject()));
171
171
172
172
         if (window) {
173
173
           nsPoint nsMoveBy = aEvent->refPoint - mLastPoint;
174
				 nsPoint nsMoveBy;
174
           window->MoveBy(nsMoveBy.x,nsMoveBy.y);
175
				 nsMoveBy = aEvent->refPoint - mLastPoint;
175
         }
176
				 
177
				 
178
				 window->MoveBy(nsMoveBy.x,nsMoveBy.y);
179
				 
180
				 
181
				 
176
				 
182
				 *aEventStatus = nsEventStatus_eConsumeNoDefault;				
177
				 *aEventStatus = nsEventStatus_eConsumeNoDefault;				
183
				 
178
				 
(-)netwerk/base/public/nsISecureBrowserUI.idl (-2 / +18 lines)
Line     Link Here 
 Lines 41-55    Link Here 
41
#include "nsISupports.idl"
41
#include "nsISupports.idl"
42
42
43
interface nsIDOMWindow;
43
interface nsIDOMWindow;
44
interface nsIDOMElement;
44
interface nsIWebProgress;
45
interface nsIURI;
45
46
46
[scriptable, uuid(081e31e0-a144-11d3-8c7c-00609792278c)]
47
[uuid(625481c5-b2dc-11d9-bc8f-00112478d626)]
48
interface nsISecureBrowserUIState : nsISupports
49
{
50
};
51
52
[scriptable, uuid(c5ca429c-b5c2-11d9-8547-00112478d626)]
47
interface nsISecureBrowserUI : nsISupports
53
interface nsISecureBrowserUI : nsISupports
48
{
54
{
49
    void init(in nsIDOMWindow window);
55
    void init(in nsIDOMWindow window);
50
56
51
    readonly attribute unsigned long state;
57
    readonly attribute unsigned long state;
52
    readonly attribute AString tooltipText;
58
    readonly attribute AString tooltipText;
59
60
    /* Returns an object that encapsulates the current security state. */
61
    nsISecureBrowserUIState captureState();
62
63
    /**
64
     * Restore the state captured by captureState(), firing transition
65
     * notifications as necessary.
66
     */
67
    void transitionToState(in nsISecureBrowserUIState state);
68
                           
53
};
69
};
54
70
55
%{C++
71
%{C++
(-)security/manager/boot/src/nsSecureBrowserUIImpl.cpp (-11 / +71 lines)
Line     Link Here 
 Lines 206-217   nsSecureBrowserUIImpl::Init(nsIDOMWindow Link Here 
206
    rv = svc->AddObserver(this, NS_FORMSUBMIT_SUBJECT, PR_TRUE);
206
    rv = svc->AddObserver(this, NS_FORMSUBMIT_SUBJECT, PR_TRUE);
207
  }
207
  }
208
  
208
  
209
  /* GetWebProgress(mWindow) */
210
  // hook up to the webprogress notifications.
211
  nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(mWindow));
209
  nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(mWindow));
212
  if (!sgo) return NS_ERROR_FAILURE;
210
  if (!sgo) return NS_ERROR_FAILURE;
213
  
211
214
  nsCOMPtr<nsIWebProgress> wp(do_GetInterface(sgo->GetDocShell()));
212
  nsIDocShell *docShell = sgo->GetDocShell();
213
214
  // The Docshell will own the SecureBrowserUI object
215
  if (!docShell)
216
    return NS_ERROR_FAILURE;
217
218
  docShell->SetSecurityUI(this);
219
220
  /* GetWebProgress(mWindow) */
221
  // hook up to the webprogress notifications.
222
  nsCOMPtr<nsIWebProgress> wp(do_GetInterface(docShell));
215
  if (!wp) return NS_ERROR_FAILURE;
223
  if (!wp) return NS_ERROR_FAILURE;
216
  /* end GetWebProgress */
224
  /* end GetWebProgress */
217
  
225
  
 Lines 982-993   nsresult nsSecureBrowserUIImpl::UpdateSe Link Here 
982
    newSecurityState = lis_no_security;
990
    newSecurityState = lis_no_security;
983
  }
991
  }
984
992
993
  return UpdateSecurityState(newSecurityState, aRequest);
994
}
995
996
nsresult
997
nsSecureBrowserUIImpl::UpdateSecurityState(lockIconState aNewState,
998
                                           nsIRequest *aRequest)
999
{
985
  PR_LOG(gSecureDocLog, PR_LOG_DEBUG,
1000
  PR_LOG(gSecureDocLog, PR_LOG_DEBUG,
986
         ("SecureUI:%p: UpdateSecurityState:  old-new  %d - %d\n", this,
1001
         ("SecureUI:%p: UpdateSecurityState:  old-new  %d - %d\n", this,
987
         mPreviousSecurityState, newSecurityState
1002
         mPreviousSecurityState, aNewState
988
          ));
1003
          ));
989
1004
990
  if (mPreviousSecurityState != newSecurityState)
1005
  if (mPreviousSecurityState != aNewState)
991
  {
1006
  {
992
    // must show alert
1007
    // must show alert
993
    
1008
    
 Lines 1032-1038   nsresult nsSecureBrowserUIImpl::UpdateSe Link Here 
1032
    {
1047
    {
1033
      case lis_no_security:
1048
      case lis_no_security:
1034
      case lis_broken_security:
1049
      case lis_broken_security:
1035
        switch (newSecurityState)
1050
        switch (aNewState)
1036
        {
1051
        {
1037
          case lis_no_security:
1052
          case lis_no_security:
1038
          case lis_broken_security:
1053
          case lis_broken_security:
 Lines 1049-1055   nsresult nsSecureBrowserUIImpl::UpdateSe Link Here 
1049
    
1064
    
1050
    if (showWarning)
1065
    if (showWarning)
1051
    {
1066
    {
1052
      switch (newSecurityState)
1067
      switch (aNewState)
1053
      {
1068
      {
1054
        case lis_no_security:
1069
        case lis_no_security:
1055
        case lis_broken_security:
1070
        case lis_broken_security:
 Lines 1070-1078   nsresult nsSecureBrowserUIImpl::UpdateSe Link Here 
1070
      }
1085
      }
1071
    }
1086
    }
1072
1087
1073
    mPreviousSecurityState = newSecurityState;
1088
    mPreviousSecurityState = aNewState;
1074
1089
1075
    if (lis_no_security == newSecurityState)
1090
    if (lis_no_security == aNewState)
1076
    {
1091
    {
1077
      mSSLStatus = nsnull;
1092
      mSSLStatus = nsnull;
1078
      mInfoTooltip.Truncate();
1093
      mInfoTooltip.Truncate();
 Lines 1083-1089   nsresult nsSecureBrowserUIImpl::UpdateSe Link Here 
1083
  {
1098
  {
1084
    PRUint32 newState = STATE_IS_INSECURE;
1099
    PRUint32 newState = STATE_IS_INSECURE;
1085
1100
1086
    switch (newSecurityState)
1101
    switch (aNewState)
1087
    {
1102
    {
1088
      case lis_broken_security:
1103
      case lis_broken_security:
1089
        newState = STATE_IS_BROKEN;
1104
        newState = STATE_IS_BROKEN;
 Lines 1483-1485   ConfirmPostToInsecureFromSecure() Link Here 
1483
1498
1484
  return result;
1499
  return result;
1485
}
1500
}
1501
1502
class nsSecureBrowserUIImpl::State : public nsISecureBrowserUIState
1503
{
1504
public:
1505
  State(lockIconState aState, nsISupports *aSSLStatus);
1506
1507
  lockIconState GetState() const { return mState; }
1508
  nsISupports* GetSSLStatus() { return mSSLStatus; }
1509
1510
  NS_DECL_ISUPPORTS
1511
  NS_DECL_NSISECUREBROWSERUISTATE
1512
1513
private:
1514
  lockIconState mState;
1515
  nsCOMPtr<nsISupports> mSSLStatus;
1516
};
1517
1518
NS_IMPL_ISUPPORTS1(nsSecureBrowserUIImpl::State, nsISecureBrowserUIState)
1519
1520
nsSecureBrowserUIImpl::State::State(lockIconState aState,
1521
                                    nsISupports *aSSLStatus)
1522
  : mState(aState), mSSLStatus(aSSLStatus)
1523
{
1524
}
1525
1526
NS_IMETHODIMP
1527
nsSecureBrowserUIImpl::CaptureState(nsISecureBrowserUIState **aState)
1528
{
1529
  *aState = new State(mPreviousSecurityState, mSSLStatus);
1530
  NS_ENSURE_TRUE(aState, NS_ERROR_OUT_OF_MEMORY);
1531
1532
  NS_ADDREF(*aState);
1533
  return NS_OK;
1534
}
1535
1536
NS_IMETHODIMP
1537
nsSecureBrowserUIImpl::TransitionToState(nsISecureBrowserUIState *aState)
1538
{
1539
  NS_ENSURE_TRUE(aState, NS_ERROR_NULL_POINTER);
1540
1541
  State *state = NS_STATIC_CAST(State*, aState);
1542
1543
  mSSLStatus = state->GetSSLStatus();
1544
  return UpdateSecurityState(state->GetState(), nsnull);
1545
}
(-)security/manager/boot/src/nsSecureBrowserUIImpl.h (+5 lines)
Line     Link Here 
 Lines 121-126   protected: Link Here 
121
  PRInt32 mSubRequestsNoSecurity;
121
  PRInt32 mSubRequestsNoSecurity;
122
122
123
  nsresult UpdateSecurityState(nsIRequest* aRequest);
123
  nsresult UpdateSecurityState(nsIRequest* aRequest);
124
  nsresult UpdateSecurityState(lockIconState aNewState, nsIRequest *aRequest);
124
  nsresult EvaluateAndUpdateSecurityState(nsIRequest *aRequest);
125
  nsresult EvaluateAndUpdateSecurityState(nsIRequest *aRequest);
125
  void UpdateSubrequestMembers(nsIRequest *aRequest);
126
  void UpdateSubrequestMembers(nsIRequest *aRequest);
126
127
 Lines 143-148   protected: Link Here 
143
  // Support functions
144
  // Support functions
144
  nsresult GetNSSDialogs(nsISecurityWarningDialogs **);
145
  nsresult GetNSSDialogs(nsISecurityWarningDialogs **);
145
146
147
  class State;
148
  nsresult HandleStateChange(PRBool aIsToplevel, nsIURI *aURI,
149
                             PRUint32 aLoadFlags, PRUint32 aProgressStateFlgs);
150
146
  PLDHashTable mTransferringRequests;
151
  PLDHashTable mTransferringRequests;
147
};
152
};
148
153
(-)toolkit/components/passwordmgr/base/nsPasswordManager.cpp (-5 / +76 lines)
Line     Link Here 
 Lines 71-76    Link Here 
71
#include "nsIAutoCompleteResult.h"
71
#include "nsIAutoCompleteResult.h"
72
#include "nsIPK11TokenDB.h"
72
#include "nsIPK11TokenDB.h"
73
#include "nsIPK11Token.h"
73
#include "nsIPK11Token.h"
74
#include "nsIScriptGlobalObject.h"
75
#include "nsIWindowWatcher.h"
74
76
75
static const char kPMPropertiesURL[] = "chrome://passwordmgr/locale/passwordmgr.properties";
77
static const char kPMPropertiesURL[] = "chrome://passwordmgr/locale/passwordmgr.properties";
76
static PRBool sRememberPasswords = PR_FALSE;
78
static PRBool sRememberPasswords = PR_FALSE;
 Lines 263-268   nsPasswordManager::Init() Link Here 
263
265
264
  progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
266
  progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
265
267
268
  // Listen for "domwindowopened", this will let us attach our DOMPageRestore
269
  // event listener.
270
271
  obsService->AddObserver(this, "domwindowopened", PR_FALSE);
272
  obsService->AddObserver(this, "domwindowclosed", PR_FALSE);
273
274
  // Also register on any open windows that already exist, since we don't
275
  // get notifications for those.
276
277
  nsCOMPtr<nsIWindowWatcher> watcher =
278
    do_GetService(NS_WINDOWWATCHER_CONTRACTID);
279
  if (watcher) {
280
    nsCOMPtr<nsISimpleEnumerator> enumerator;
281
    watcher->GetWindowEnumerator(getter_AddRefs(enumerator));
282
    if (enumerator) {
283
      PRBool hasMore;
284
      nsCOMPtr<nsISupports> item;
285
      nsCOMPtr<nsIDOMEventTarget> targ;
286
287
      while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) {
288
        enumerator->GetNext(getter_AddRefs(item));
289
        targ = do_QueryInterface(item);
290
        if (targ) {
291
          targ->AddEventListener(NS_LITERAL_STRING("DOMPageRestore"),
292
                                 NS_STATIC_CAST(nsIDOMLoadListener*, this),
293
                                 PR_FALSE);
294
        }
295
      }
296
    }
297
  }
298
266
  // Now read in the signon file
299
  // Now read in the signon file
267
  nsXPIDLCString signonFile;
300
  nsXPIDLCString signonFile;
268
  mPrefBranch->GetCharPref("SignonFileName", getter_Copies(signonFile));
301
  mPrefBranch->GetCharPref("SignonFileName", getter_Copies(signonFile));
 Lines 747-752   nsPasswordManager::Observe(nsISupports* Link Here 
747
    NS_ASSERTION(branch == mPrefBranch, "unexpected pref change notification");
780
    NS_ASSERTION(branch == mPrefBranch, "unexpected pref change notification");
748
781
749
    branch->GetBoolPref("rememberSignons", &sRememberPasswords);
782
    branch->GetBoolPref("rememberSignons", &sRememberPasswords);
783
  } else if (!strcmp(aTopic, "domwindowopened")) {
784
    nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(aSubject);
785
    if (targ) {
786
      targ->AddEventListener(NS_LITERAL_STRING("DOMPageRestore"),
787
                             NS_STATIC_CAST(nsIDOMLoadListener*, this),
788
                             PR_FALSE);
789
    }
790
  } else if (!strcmp(aTopic, "domwindowclosed")) {
791
    nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(aSubject);
792
    if (targ) {
793
      targ->RemoveEventListener(NS_LITERAL_STRING("DOMPageRestore"),
794
                                NS_STATIC_CAST(nsIDOMLoadListener*, this),
795
                                PR_FALSE);
796
    }
750
  }
797
  }
751
798
752
  return NS_OK;
799
  return NS_OK;
 Lines 765-780   nsPasswordManager::OnStateChange(nsIWebP Link Here 
765
      !(aStateFlags & nsIWebProgressListener::STATE_STOP))
812
      !(aStateFlags & nsIWebProgressListener::STATE_STOP))
766
    return NS_OK;
813
    return NS_OK;
767
814
768
  // Don't do anything if the global signon pref is disabled
769
  if (!SingleSignonEnabled())
770
    return NS_OK;
771
772
  nsCOMPtr<nsIDOMWindow> domWin;
815
  nsCOMPtr<nsIDOMWindow> domWin;
773
  nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));
816
  nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));
774
  NS_ENSURE_SUCCESS(rv, rv);
817
  NS_ENSURE_SUCCESS(rv, rv);
775
818
819
  return DoPrefill(domWin);
820
}
821
822
nsresult
823
nsPasswordManager::DoPrefill(nsIDOMWindow *aDOMWindow)
824
{
825
  // Don't do anything if the global signon pref is disabled
826
  if (!SingleSignonEnabled())
827
    return NS_OK;
828
776
  nsCOMPtr<nsIDOMDocument> domDoc;
829
  nsCOMPtr<nsIDOMDocument> domDoc;
777
  domWin->GetDocument(getter_AddRefs(domDoc));
830
  aDOMWindow->GetDocument(getter_AddRefs(domDoc));
778
  NS_ASSERTION(domDoc, "DOM window should always have a document!");
831
  NS_ASSERTION(domDoc, "DOM window should always have a document!");
779
832
780
  // For now, only prefill forms in HTML documents.
833
  // For now, only prefill forms in HTML documents.
 Lines 1568-1573   nsPasswordManager::Error(nsIDOMEvent* aE Link Here 
1568
  return NS_OK;
1621
  return NS_OK;
1569
}
1622
}
1570
1623
1624
NS_IMETHODIMP
1625
nsPasswordManager::PageRestore(nsIDOMEvent* aEvent)
1626
{
1627
  nsCOMPtr<nsIDOMEventTarget> target;
1628
  aEvent->GetTarget(getter_AddRefs(target));
1629
1630
  nsCOMPtr<nsIDocument> doc = do_QueryInterface(target);
1631
  if (doc) {
1632
    nsCOMPtr<nsIDOMWindow> win =
1633
      do_QueryInterface(doc->GetScriptGlobalObject());
1634
    if (win) {
1635
      return DoPrefill(win);
1636
    }
1637
  }
1638
1639
  return NS_OK;
1640
}
1641
1571
1642
1572
// internal methods
1643
// internal methods
1573
1644
(-)toolkit/components/passwordmgr/base/nsPasswordManager.h (+2 lines)
Line     Link Here 
 Lines 136-141   public: Link Here 
136
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
136
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
137
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
137
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
138
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
138
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
139
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent);
139
140
140
  // Autocomplete
141
  // Autocomplete
141
  PRBool AutoCompleteSearch(const nsAString& aSearchString,
142
  PRBool AutoCompleteSearch(const nsAString& aSearchString,
 Lines 157-162   protected: Link Here 
157
  nsresult FillPassword(nsIDOMEvent* aEvent);
158
  nsresult FillPassword(nsIDOMEvent* aEvent);
158
  void AttachToInput(nsIDOMHTMLInputElement* aElement);
159
  void AttachToInput(nsIDOMHTMLInputElement* aElement);
159
  PRBool GetPasswordRealm(nsIURI* aURI, nsACString& aRealm);
160
  PRBool GetPasswordRealm(nsIURI* aURI, nsACString& aRealm);
161
  nsresult DoPrefill(nsIDOMWindow *aDOMWindw);
160
162
161
  static PLDHashOperator PR_CALLBACK FindEntryEnumerator(const nsACString& aKey,
163
  static PLDHashOperator PR_CALLBACK FindEntryEnumerator(const nsACString& aKey,
162
                                                         SignonHashEntry* aEntry,
164
                                                         SignonHashEntry* aEntry,
(-)toolkit/components/satchel/src/nsFormFillController.cpp (+6 lines)
Line     Link Here 
 Lines 880-885   nsFormFillController::Error(nsIDOMEvent Link Here 
880
  return NS_OK;
880
  return NS_OK;
881
}
881
}
882
882
883
NS_IMETHODIMP
884
nsFormFillController::PageRestore(nsIDOMEvent *aLoadEvent)
885
{
886
  return NS_OK;
887
}
888
883
////////////////////////////////////////////////////////////////////////
889
////////////////////////////////////////////////////////////////////////
884
//// nsFormFillController
890
//// nsFormFillController
885
891
(-)toolkit/components/satchel/src/nsFormFillController.h (+1 lines)
Line     Link Here 
 Lines 112-117   public: Link Here 
112
  NS_IMETHOD Unload(nsIDOMEvent *aLoadEvent);
112
  NS_IMETHOD Unload(nsIDOMEvent *aLoadEvent);
113
  NS_IMETHOD Abort(nsIDOMEvent *aLoadEvent);
113
  NS_IMETHOD Abort(nsIDOMEvent *aLoadEvent);
114
  NS_IMETHOD Error(nsIDOMEvent *aLoadEvent);
114
  NS_IMETHOD Error(nsIDOMEvent *aLoadEvent);
115
  NS_IMETHOD PageRestore(nsIDOMEvent* aLoadEvent);
115
116
116
  nsFormFillController();
117
  nsFormFillController();
117
  virtual ~nsFormFillController();
118
  virtual ~nsFormFillController();
(-)toolkit/content/widgets/browser.xml (-5 / +5 lines)
Line     Link Here 
 Lines 484-492    Link Here 
484
        null
484
        null
485
      </field>
485
      </field>
486
486
487
      <field name="securityUI">
487
      <property name="securityUI"
488
        null
488
                onget="return this.docShell.securityUI;"
489
      </field>
489
                onset="this.docShell.securityUI = val;"/>
490
490
491
      <field name="userTypedClear">
491
      <field name="userTypedClear">
492
        true
492
        true
 Lines 544-551    Link Here 
544
            const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
544
            const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
545
            if (!this.hasAttribute("disablesecurity") &&
545
            if (!this.hasAttribute("disablesecurity") &&
546
                SECUREBROWSERUI_CONTRACTID in Components.classes) {
546
                SECUREBROWSERUI_CONTRACTID in Components.classes) {
547
              this.securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID].createInstance(Components.interfaces.nsISecureBrowserUI);
547
              var securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID].createInstance(Components.interfaces.nsISecureBrowserUI);
548
              this.securityUI.init(this.contentWindow);
548
	      securityUI.init(this.contentWindow);
549
            }
549
            }
550
          }
550
          }
551
          catch (e) {
551
          catch (e) {
(-)view/public/nsIViewManager.h (-2 / +8 lines)
Line     Link Here 
 Lines 62-69   enum nsRectVisibility { Link Here 
62
62
63
63
64
#define NS_IVIEWMANAGER_IID   \
64
#define NS_IVIEWMANAGER_IID   \
65
{ 0xd9af8f22, 0xc64d, 0x4036, \
65
{ 0x5a381922, 0xb397, 0x11d9, \
66
  { 0x9e, 0x8b, 0x69, 0x5a, 0x63, 0x69, 0x3f, 0xd3 } }
66
  { 0x8f, 0x7c, 0x00, 0x11, 0x24, 0x78, 0xd6, 0x26 } }
67
67
68
class nsIViewManager : public nsISupports
68
class nsIViewManager : public nsISupports
69
{
69
{
 Lines 566-571   public: Link Here 
566
   * (aFromScroll is false) or scrolled (aFromScroll is true).
566
   * (aFromScroll is false) or scrolled (aFromScroll is true).
567
   */
567
   */
568
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll)=0;
568
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll)=0;
569
570
  /**
571
   * Force any cached information about the view hierarchy (such as the root
572
   * view manager) to be recomputed.  Note that this is non-recursive.
573
   */
574
  NS_IMETHOD InvalidateHierarchy()=0;
569
};
575
};
570
576
571
// Paint timing mode flags
577
// Paint timing mode flags
(-)view/src/nsViewManager.cpp (+19 lines)
Line     Link Here 
 Lines 4440-4442   nsViewManager::ProcessSynthMouseMoveEven Link Here 
4440
  if (!aFromScroll)
4440
  if (!aFromScroll)
4441
    mSynthMouseMoveEventQueue = nsnull;
4441
    mSynthMouseMoveEventQueue = nsnull;
4442
}
4442
}
4443
4444
NS_IMETHODIMP
4445
nsViewManager::InvalidateHierarchy()
4446
{
4447
  if (mRootView) {
4448
    if (mRootViewManager != this) {
4449
      NS_IF_RELEASE(mRootViewManager);
4450
    }
4451
    nsView *parent = mRootView->GetParent();
4452
    if (parent) {
4453
      mRootViewManager = parent->GetViewManager()->RootViewManager();
4454
      NS_ADDREF(mRootViewManager);
4455
    } else {
4456
      mRootViewManager = this;
4457
    }
4458
  }
4459
4460
  return NS_OK;
4461
}
(-)view/src/nsViewManager.h (+2 lines)
Line     Link Here 
 Lines 267-272   public: Link Here 
267
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll);
267
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll);
268
  void ProcessSynthMouseMoveEvent(PRBool aFromScroll);
268
  void ProcessSynthMouseMoveEvent(PRBool aFromScroll);
269
269
270
  NS_IMETHOD InvalidateHierarchy();
271
270
protected:
272
protected:
271
  virtual ~nsViewManager();
273
  virtual ~nsViewManager();
272
274
(-)widget/public/nsGUIEvent.h (+1 lines)
Line     Link Here 
 Lines 235-240   class nsIURI; Link Here 
235
#define NS_IMAGE_ERROR                  (NS_STREAM_EVENT_START + 4)
235
#define NS_IMAGE_ERROR                  (NS_STREAM_EVENT_START + 4)
236
#define NS_SCRIPT_LOAD                  (NS_STREAM_EVENT_START + 5)
236
#define NS_SCRIPT_LOAD                  (NS_STREAM_EVENT_START + 5)
237
#define NS_BEFORE_PAGE_UNLOAD           (NS_STREAM_EVENT_START + 6)
237
#define NS_BEFORE_PAGE_UNLOAD           (NS_STREAM_EVENT_START + 6)
238
#define NS_PAGE_RESTORE                 (NS_STREAM_EVENT_START + 7)
238
 
239
 
239
#define NS_FORM_EVENT_START             1200
240
#define NS_FORM_EVENT_START             1200
240
#define NS_FORM_SUBMIT                  (NS_FORM_EVENT_START)
241
#define NS_FORM_SUBMIT                  (NS_FORM_EVENT_START)
(-)xpcom/threads/nsITimer.idl (-6 / +11 lines)
Line     Link Here 
 Lines 43-54   interface nsIObserver; Link Here 
43
43
44
%{C++
44
%{C++
45
/**
45
/**
46
 * The signature of the timer callback function passed to initWithCallback. This
46
 * The signature of the timer callback function passed to initWithFuncCallback.
47
 * is the function that will get called when the timer expires if the timer is 
47
 * This is the function that will get called when the timer expires if the
48
 * initialized via initWithCallback.
48
 * timer is initialized via initWithFuncCallback.
49
 *
49
 *
50
 * @param aTimer the timer which has expired
50
 * @param aTimer the timer which has expired
51
 * @param aClosure opaque parameter passed to initWithCallback
51
 * @param aClosure opaque parameter passed to initWithFuncCallback
52
 *
52
 *
53
 * Implementers should return the following:
53
 * Implementers should return the following:
54
 *
54
 *
 Lines 82-88   interface nsITimerCallback : nsISupports Link Here 
82
 * delay to avoid the overhead of destroying and creating a timer.  It is not
82
 * delay to avoid the overhead of destroying and creating a timer.  It is not
83
 * necessary to cancel the timer in that case.
83
 * necessary to cancel the timer in that case.
84
 */
84
 */
85
[scriptable, uuid(29ee628e-a3ea-471f-965d-dc9f11d1c183)]
85
[scriptable, uuid(436a83fa-b396-11d9-bcfa-00112478d626)]
86
interface nsITimer : nsISupports
86
interface nsITimer : nsISupports
87
{
87
{
88
  /* Timer types */
88
  /* Timer types */
 Lines 179-187   interface nsITimer : nsISupports Link Here 
179
  attribute unsigned long type;
179
  attribute unsigned long type;
180
180
181
  /**
181
  /**
182
   * The opaque pointer pass to initWithCallback.
182
   * The opaque pointer pass to initWithFuncCallback.
183
   */  
183
   */  
184
  [noscript] readonly attribute voidPtr closure;
184
  [noscript] readonly attribute voidPtr closure;
185
186
  /**
187
   * The nsITimerCallback object passed to initWithCallback.
188
   */
189
  readonly attribute nsITimerCallback callback;
185
};
190
};
186
191
187
%{C++
192
%{C++
(-)xpcom/threads/nsTimerImpl.cpp (+11 lines)
Line     Link Here 
 Lines 331-336   NS_IMETHODIMP nsTimerImpl::GetClosure(vo Link Here 
331
}
331
}
332
332
333
333
334
NS_IMETHODIMP nsTimerImpl::GetCallback(nsITimerCallback **aCallback)
335
{
336
  if (mCallbackType == CALLBACK_TYPE_INTERFACE)
337
    NS_IF_ADDREF(*aCallback = mCallback.i);
338
  else
339
    *aCallback = nsnull;
340
341
  return NS_OK;
342
}
343
344
334
NS_IMETHODIMP nsTimerImpl::GetIdle(PRBool *aIdle)
345
NS_IMETHODIMP nsTimerImpl::GetIdle(PRBool *aIdle)
335
{
346
{
336
  *aIdle = mIdle;
347
  *aIdle = mIdle;
(-)xpfe/components/shistory/public/nsIHistoryEntry.idl (-24 / +24 lines)
Line     Link Here 
 Lines 53-82   interface nsIURI; Link Here 
53
interface nsIHistoryEntry : nsISupports 
53
interface nsIHistoryEntry : nsISupports 
54
{
54
{
55
55
56
/** 
56
    /** 
57
 * A readonly property that returns the URI
57
     * A readonly property that returns the URI
58
 * of the current entry. The object returned is
58
     * of the current entry. The object returned is
59
 * of type nsIURI
59
     * of type nsIURI
60
 */
60
     */
61
readonly attribute nsIURI URI;
61
    readonly attribute nsIURI URI;
62
62
63
/** 
63
    /** 
64
 * A readonly property that returns the title
64
     * A readonly property that returns the title
65
 * of the current entry.  The object returned
65
     * of the current entry.  The object returned
66
 * is a encoded string
66
     * is a encoded string
67
 */
67
     */
68
readonly attribute wstring title;
68
    readonly attribute wstring title;
69
69
70
/** 
70
    /** 
71
 * A readonly property that returns a boolean
71
     * A readonly property that returns a boolean
72
 * flag which indicates if the entry was created as a 
72
     * flag which indicates if the entry was created as a 
73
 * result of a subframe navigation. This flag will be
73
     * result of a subframe navigation. This flag will be
74
 * 'false' when a frameset page is visited for
74
     * 'false' when a frameset page is visited for
75
 * the first time. This flag will be 'true' for all
75
     * the first time. This flag will be 'true' for all
76
 * history entries created as a result of a subframe
76
     * history entries created as a result of a subframe
77
 * navigation.
77
     * navigation.
78
 */
78
     */
79
readonly attribute boolean isSubFrame;
79
    readonly attribute boolean isSubFrame;
80
80
81
};
81
};
82
82
(-)xpfe/components/shistory/public/nsISHEntry.idl (-72 / +110 lines)
Line     Link Here 
 Lines 42-129    Link Here 
42
 * hold all information required to recreate the document from history
42
 * hold all information required to recreate the document from history
43
 * 
43
 * 
44
 */
44
 */
45
#include "nsISupports.idl"
45
#include "nsIHistoryEntry.idl"
46
#include "nsIURI.idl"
47
#include "nsIInputStream.idl"
48
46
49
interface nsILayoutHistoryState;
47
interface nsILayoutHistoryState;
50
interface nsIDOMDocument;
48
interface nsIContentViewer;
49
interface nsIURI;
50
interface nsIInputStream;
51
interface nsIDocShellTreeItem;
52
interface nsISecureBrowserUIState;
53
interface nsISupportsArray;
54
%{C++
55
struct nsRect;
56
%}
57
[ref] native nsRect(nsRect);
51
58
52
[scriptable, uuid(6b596e1f-a3bd-40f9-a7ee-ab3edc7f9960)]
59
[scriptable, uuid(e47bf412-3bc2-4306-a82f-ea2bdf950432)]
53
interface nsISHEntry : nsISupports 
60
interface nsISHEntry : nsIHistoryEntry
54
{
61
{
62
    /** URI for the document */
63
    void setURI(in nsIURI aURI);
55
64
56
/** URI for the document */
65
    /** Referrer URI */
57
void SetURI(in nsIURI aURI);
66
    attribute nsIURI referrerURI;
58
59
/** Referrer URI */
60
attribute nsIURI referrerURI;
61
67
62
/**  DOM Document */
68
    /** Content viewer, for fast restoration of presentation */
63
attribute nsIDOMDocument document;
69
    attribute nsIContentViewer contentViewer;
64
70
65
/** Title for the document */
71
    /** Whether the content viewer is marked "sticky" */
66
void SetTitle(in wstring aTitle);
72
    attribute boolean sticky;
67
73
68
/** Post Data for the document */
74
    /** Saved state of the global window object */
69
attribute nsIInputStream postData;
75
    attribute nsISupports windowState;
70
76
71
/** LayoutHistoryState for scroll position and form values */
77
    /**
72
attribute nsILayoutHistoryState layoutHistoryState;
78
     * Saved position and dimensions of the content viewer; we must adjust the
73
79
     * root view's widget accordingly if this has changed when the presentation
74
/** parent of this entry */
80
     * is restored.
75
attribute nsISHEntry parent;
81
     */
76
82
    [noscript] void getViewerBounds(in nsRect bounds);
77
/**
83
    [noscript] void setViewerBounds([const] in nsRect bounds);
78
 * The loadType for this entry. This is typically loadHistory except
84
79
 * when reload is pressed, it has the appropriate reload flag
85
    /**
80
 */
86
     * Saved child docshells corresponding to contentViewer.  There are weak
81
attribute  unsigned long loadType;
87
     * references since it's assumed that the content viewer's document has
82
88
     * an owning reference to the subdocument for each shell.  The child shells
83
/**
89
     * are restored as children of the parent docshell, in this order, when the
84
 * An ID to help identify this entry from others during
90
     * parent docshell restores a saved presentation.
85
 * subframe navigation
91
     */
86
 */
92
    void addChildShell(in nsIDocShellTreeItem shell);
87
attribute unsigned long ID;
93
    nsIDocShellTreeItem childShellAt(in long index);
88
94
    void clearChildShells();
89
/**
95
90
 * pageIdentifier is an integer that should be the same for two entries
96
    /** Saved security state for the content viewer */
91
 * attached to the same docshell only if the two entries are entries for the
97
    attribute nsISecureBrowserUIState securityState;
92
 * same page in the sense that one could go from the state represented by one
98
93
 * to the state represented by the other simply by scrolling (so the entries
99
    /** Saved refresh URI list for the content viewer */
94
 * are separated by an anchor traversal or a subframe navigation in some other
100
    attribute nsISupportsArray refreshURIList;
95
 * frame).
101
96
 */
102
    /** Title for the document */
97
attribute unsigned long pageIdentifier;
103
    void setTitle(in AString aTitle);
98
104
99
/** attribute to set and get the cache key for the entry */
105
    /** Post Data for the document */
100
attribute nsISupports cacheKey;
106
    attribute nsIInputStream postData;
101
107
102
/** attribute to indicate whether layoutHistoryState should be saved */
108
    /** LayoutHistoryState for scroll position and form values */
103
attribute boolean saveLayoutStateFlag;
109
    attribute nsILayoutHistoryState layoutHistoryState;
104
110
105
/** attribute to indicate whether the page is already expired in cache */
111
    /** parent of this entry */
106
attribute boolean expirationStatus;
112
    attribute nsISHEntry parent;
107
113
108
/** attribute to indicate the content-type of the document that this
114
    /**
109
    is a session history entry for */
115
     * The loadType for this entry. This is typically loadHistory except
110
attribute ACString contentType; 
116
     * when reload is pressed, it has the appropriate reload flag
117
     */
118
    attribute unsigned long loadType;
119
120
    /**
121
     * An ID to help identify this entry from others during
122
     * subframe navigation
123
     */
124
    attribute unsigned long ID;
125
126
    /**
127
     * pageIdentifier is an integer that should be the same for two entries
128
     * attached to the same docshell only if the two entries are entries for
129
     * the same page in the sense that one could go from the state represented
130
     * by one to the state represented by the other simply by scrolling (so the
131
     * entries are separated by an anchor traversal or a subframe navigation in
132
     * some other frame).
133
     */
134
    attribute unsigned long pageIdentifier;
135
136
    /** attribute to set and get the cache key for the entry */
137
    attribute nsISupports cacheKey;
138
139
    /** attribute to indicate whether layoutHistoryState should be saved */
140
    attribute boolean saveLayoutStateFlag;
141
142
    /** attribute to indicate whether the page is already expired in cache */
143
    attribute boolean expirationStatus;
144
145
    /**
146
     * attribute to indicate the content-type of the document that this
147
     * is a session history entry for
148
     */
149
    attribute ACString contentType; 
111
 
150
 
112
/** Set/Get scrollers' positon in anchored pages */
151
    /** Set/Get scrollers' positon in anchored pages */
113
void setScrollPosition(in PRInt32 x, in PRInt32 y);
152
    void setScrollPosition(in long x, in long y);
114
void getScrollPosition(out PRInt32 x, out PRInt32 y);
153
    void getScrollPosition(out long x, out long y);
115
154
116
/** Additional ways to create an entry */
155
    /** Additional ways to create an entry */
117
void create(in nsIURI aURI, in wstring aTitle, in nsIDOMDocument aDocument,
156
    void create(in nsIURI URI, in AString title,
118
            in nsIInputStream aInputStream, in nsILayoutHistoryState aHistoryLayoutState,
157
                in nsIInputStream inputStream,
119
            in nsISupports aCacheKey, in ACString aContentType);
158
                in nsILayoutHistoryState layoutHistoryState,
120
159
                in nsISupports cacheKey, in ACString contentType);
121
nsISHEntry clone();
122
123
/** Attribute that indicates if this entry is for a subframe navigation */
124
void SetIsSubFrame(in boolean aFlag);
125
160
161
    nsISHEntry clone();
126
162
163
    /** Attribute that indicates if this entry is for a subframe navigation */
164
    void setIsSubFrame(in boolean aFlag);
127
};
165
};
128
166
129
167
(-)xpfe/components/shistory/src/Makefile.in (+1 lines)
Line     Link Here 
 Lines 55-60   REQUIRES = xpcom \ Link Here 
55
		  layout \
55
		  layout \
56
		  docshell \
56
		  docshell \
57
		  pref \
57
		  pref \
58
		  gfx \
58
		  $(NULL)
59
		  $(NULL)
59
60
60
CPPSRCS		= nsSHEntry.cpp        \
61
CPPSRCS		= nsSHEntry.cpp        \
(-)xpfe/components/shistory/src/nsSHEntry.cpp (-11 / +122 lines)
Line     Link Here 
 Lines 37-47    Link Here 
37
 *
37
 *
38
 * ***** END LICENSE BLOCK ***** */
38
 * ***** END LICENSE BLOCK ***** */
39
39
40
#ifdef DEBUG_brymer
41
#define DEBUG_PAGE_CACHE
42
#endif
43
40
// Local Includes
44
// Local Includes
41
#include "nsSHEntry.h"
45
#include "nsSHEntry.h"
42
#include "nsXPIDLString.h"
46
#include "nsXPIDLString.h"
43
#include "nsReadableUtils.h"
47
#include "nsReadableUtils.h"
44
#include "nsIDocShellLoadInfo.h"
48
#include "nsIDocShellLoadInfo.h"
49
#include "nsIDocShellTreeItem.h"
45
50
46
static PRUint32 gEntryID = 0;
51
static PRUint32 gEntryID = 0;
47
52
 Lines 58-64   nsSHEntry::nsSHEntry() Link Here 
58
  , mIsFrameNavigation(PR_FALSE)
63
  , mIsFrameNavigation(PR_FALSE)
59
  , mSaveLayoutState(PR_TRUE)
64
  , mSaveLayoutState(PR_TRUE)
60
  , mExpired(PR_FALSE)
65
  , mExpired(PR_FALSE)
66
  , mSticky(PR_TRUE)
61
  , mParent(nsnull)
67
  , mParent(nsnull)
68
  , mViewerBounds(0, 0, 0, 0)
62
{
69
{
63
}
70
}
64
71
 Lines 77-88   nsSHEntry::nsSHEntry(const nsSHEntry &ot Link Here 
77
  , mIsFrameNavigation(other.mIsFrameNavigation)
84
  , mIsFrameNavigation(other.mIsFrameNavigation)
78
  , mSaveLayoutState(other.mSaveLayoutState)
85
  , mSaveLayoutState(other.mSaveLayoutState)
79
  , mExpired(other.mExpired)
86
  , mExpired(other.mExpired)
87
  , mSticky(other.mSticky)
80
  // XXX why not copy mContentType?
88
  // XXX why not copy mContentType?
81
  , mCacheKey(other.mCacheKey)
89
  , mCacheKey(other.mCacheKey)
82
  , mParent(other.mParent)
90
  , mParent(other.mParent)
91
  , mViewerBounds(other.mViewerBounds)
83
{
92
{
84
}
93
}
85
94
95
nsSHEntry::~nsSHEntry()
96
{
97
  mChildren.Clear();
98
  if (mContentViewer)
99
    mContentViewer->Destroy();
100
}
101
86
//*****************************************************************************
102
//*****************************************************************************
87
//    nsSHEntry: nsISupports
103
//    nsSHEntry: nsISupports
88
//*****************************************************************************
104
//*****************************************************************************
 Lines 133-151   NS_IMETHODIMP nsSHEntry::SetReferrerURI( Link Here 
133
  return NS_OK;
149
  return NS_OK;
134
}
150
}
135
151
136
NS_IMETHODIMP nsSHEntry::SetDocument(nsIDOMDocument* aDocument)
152
NS_IMETHODIMP
153
nsSHEntry::SetContentViewer(nsIContentViewer *aViewer)
137
{
154
{
138
  mDocument = aDocument;
155
  mContentViewer = aViewer;
139
  return NS_OK;
156
  return NS_OK;
140
}
157
}
141
158
142
NS_IMETHODIMP nsSHEntry::GetDocument(nsIDOMDocument** aResult)
159
NS_IMETHODIMP
160
nsSHEntry::GetContentViewer(nsIContentViewer **aResult)
143
{
161
{
144
  *aResult = mDocument;
162
  *aResult = mContentViewer;
145
  NS_IF_ADDREF(*aResult);
163
  NS_IF_ADDREF(*aResult);
146
  return NS_OK;
164
  return NS_OK;
147
}
165
}
148
166
167
NS_IMETHODIMP
168
nsSHEntry::SetSticky(PRBool aSticky)
169
{
170
  mSticky = aSticky;
171
  return NS_OK;
172
}
173
174
NS_IMETHODIMP
175
nsSHEntry::GetSticky(PRBool *aSticky)
176
{
177
  *aSticky = mSticky;
178
  return NS_OK;
179
}
180
149
NS_IMETHODIMP nsSHEntry::GetTitle(PRUnichar** aTitle)
181
NS_IMETHODIMP nsSHEntry::GetTitle(PRUnichar** aTitle)
150
{
182
{
151
  // Check for empty title...
183
  // Check for empty title...
 Lines 160-166   NS_IMETHODIMP nsSHEntry::GetTitle(PRUnic Link Here 
160
  return NS_OK;
192
  return NS_OK;
161
}
193
}
162
194
163
NS_IMETHODIMP nsSHEntry::SetTitle(const PRUnichar* aTitle)
195
NS_IMETHODIMP nsSHEntry::SetTitle(const nsAString &aTitle)
164
{
196
{
165
  mTitle = aTitle;
197
  mTitle = aTitle;
166
  return NS_OK;
198
  return NS_OK;
 Lines 297-310   NS_IMETHODIMP nsSHEntry::SetContentType( Link Here 
297
}
329
}
298
330
299
NS_IMETHODIMP
331
NS_IMETHODIMP
300
nsSHEntry::Create(nsIURI * aURI, const PRUnichar * aTitle,
332
nsSHEntry::Create(nsIURI * aURI, const nsAString &aTitle,
301
                  nsIDOMDocument * aDOMDocument, nsIInputStream * aInputStream,
333
                  nsIInputStream * aInputStream,
302
                  nsILayoutHistoryState * aHistoryLayoutState,
334
                  nsILayoutHistoryState * aLayoutHistoryState,
303
                  nsISupports * aCacheKey, const nsACString& aContentType)
335
                  nsISupports * aCacheKey, const nsACString& aContentType)
304
{
336
{
305
  mURI = aURI;
337
  mURI = aURI;
306
  mTitle = aTitle;
338
  mTitle = aTitle;
307
  mDocument = aDOMDocument;
308
  mPostData = aInputStream;
339
  mPostData = aInputStream;
309
  mCacheKey = aCacheKey;
340
  mCacheKey = aCacheKey;
310
  mContentType = aContentType;
341
  mContentType = aContentType;
 Lines 317-325   nsSHEntry::Create(nsIURI * aURI, const P Link Here 
317
  // all subframe navigations, sets the flag to true.
348
  // all subframe navigations, sets the flag to true.
318
  mIsFrameNavigation = PR_FALSE;
349
  mIsFrameNavigation = PR_FALSE;
319
350
320
  // By default we save HistoryLayoutState
351
  // By default we save LayoutHistoryState
321
  mSaveLayoutState = PR_TRUE;
352
  mSaveLayoutState = PR_TRUE;
322
  mLayoutHistoryState = aHistoryLayoutState;
353
  mLayoutHistoryState = aLayoutHistoryState;
323
354
324
  //By default the page is not expired
355
  //By default the page is not expired
325
  mExpired = PR_FALSE;
356
  mExpired = PR_FALSE;
 Lines 358-363   nsSHEntry::SetParent(nsISHEntry * aParen Link Here 
358
  return NS_OK;
389
  return NS_OK;
359
}
390
}
360
391
392
NS_IMETHODIMP
393
nsSHEntry::SetWindowState(nsISupports *aState)
394
{
395
  mWindowState = aState;
396
  return NS_OK;
397
}
398
399
NS_IMETHODIMP
400
nsSHEntry::GetWindowState(nsISupports **aState)
401
{
402
  NS_IF_ADDREF(*aState = mWindowState);
403
  return NS_OK;
404
}
405
406
NS_IMETHODIMP
407
nsSHEntry::SetViewerBounds(const nsRect &aBounds)
408
{
409
  mViewerBounds = aBounds;
410
  return NS_OK;
411
}
412
413
NS_IMETHODIMP
414
nsSHEntry::GetViewerBounds(nsRect &aBounds)
415
{
416
  aBounds = mViewerBounds;
417
  return NS_OK;
418
}
419
361
//*****************************************************************************
420
//*****************************************************************************
362
//    nsSHEntry: nsISHContainer
421
//    nsSHEntry: nsISHContainer
363
//*****************************************************************************
422
//*****************************************************************************
 Lines 416-418   nsSHEntry::GetChildAt(PRInt32 aIndex, ns Link Here 
416
  }
475
  }
417
  return NS_OK;
476
  return NS_OK;
418
}
477
}
478
479
NS_IMETHODIMP
480
nsSHEntry::AddChildShell(nsIDocShellTreeItem *aShell)
481
{
482
  NS_ASSERTION(aShell, "Null child shell added to history entry");
483
  mChildShells.AppendElement(aShell);
484
  return NS_OK;
485
}
486
487
NS_IMETHODIMP
488
nsSHEntry::ChildShellAt(PRInt32 aIndex, nsIDocShellTreeItem **aShell)
489
{
490
  NS_IF_ADDREF(*aShell =
491
               NS_STATIC_CAST(nsIDocShellTreeItem*,
492
                              mChildShells.SafeElementAt(aIndex)));
493
  return NS_OK;
494
}
495
496
NS_IMETHODIMP
497
nsSHEntry::ClearChildShells()
498
{
499
  mChildShells.Clear();
500
  return NS_OK;
501
}
502
503
NS_IMETHODIMP
504
nsSHEntry::GetSecurityState(nsISecureBrowserUIState **aState)
505
{
506
  NS_IF_ADDREF(*aState = mSecurityState);
507
  return NS_OK;
508
}
509
510
NS_IMETHODIMP
511
nsSHEntry::SetSecurityState(nsISecureBrowserUIState *aState)
512
{
513
  mSecurityState = aState;
514
  return NS_OK;
515
}
516
517
NS_IMETHODIMP
518
nsSHEntry::GetRefreshURIList(nsISupportsArray **aList)
519
{
520
  NS_IF_ADDREF(*aList = mRefreshURIList);
521
  return NS_OK;
522
}
523
524
NS_IMETHODIMP
525
nsSHEntry::SetRefreshURIList(nsISupportsArray *aList)
526
{
527
  mRefreshURIList = aList;
528
  return NS_OK;
529
}
(-)xpfe/components/shistory/src/nsSHEntry.h (-5 / +14 lines)
Line     Link Here 
 Lines 44-52    Link Here 
44
#include "nsCOMPtr.h"
44
#include "nsCOMPtr.h"
45
#include "nsCOMArray.h"
45
#include "nsCOMArray.h"
46
#include "nsString.h"
46
#include "nsString.h"
47
#include "nsVoidArray.h"
47
48
48
// Interfaces needed
49
// Interfaces needed
49
#include "nsIDOMDocument.h"
50
#include "nsIContentViewer.h"
50
#include "nsIInputStream.h"
51
#include "nsIInputStream.h"
51
#include "nsILayoutHistoryState.h"
52
#include "nsILayoutHistoryState.h"
52
#include "nsISHEntry.h"
53
#include "nsISHEntry.h"
 Lines 54-62    Link Here 
54
#include "nsIURI.h"
55
#include "nsIURI.h"
55
#include "nsIEnumerator.h"
56
#include "nsIEnumerator.h"
56
#include "nsIHistoryEntry.h"
57
#include "nsIHistoryEntry.h"
58
#include "nsRect.h"
59
#include "nsISecureBrowserUI.h"
60
#include "nsSupportsArray.h"
57
61
58
class nsSHEntry : public nsIHistoryEntry,
62
class nsSHEntry : public nsISHEntry,
59
                  public nsISHEntry,
60
                  public nsISHContainer
63
                  public nsISHContainer
61
{
64
{
62
public: 
65
public: 
 Lines 69-79   public: Link Here 
69
  NS_DECL_NSISHCONTAINER
72
  NS_DECL_NSISHCONTAINER
70
73
71
private:
74
private:
72
  ~nsSHEntry() { mChildren.Clear(); }
75
  ~nsSHEntry();
73
76
74
  nsCOMPtr<nsIURI>                mURI;
77
  nsCOMPtr<nsIURI>                mURI;
75
  nsCOMPtr<nsIURI>                mReferrerURI;
78
  nsCOMPtr<nsIURI>                mReferrerURI;
76
  nsCOMPtr<nsIDOMDocument>        mDocument;
79
  nsCOMPtr<nsIContentViewer>      mContentViewer;
77
  nsString                        mTitle;
80
  nsString                        mTitle;
78
  nsCOMPtr<nsIInputStream>        mPostData;
81
  nsCOMPtr<nsIInputStream>        mPostData;
79
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
82
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
 Lines 86-94   private: Link Here 
86
  PRPackedBool                    mIsFrameNavigation;
89
  PRPackedBool                    mIsFrameNavigation;
87
  PRPackedBool                    mSaveLayoutState;
90
  PRPackedBool                    mSaveLayoutState;
88
  PRPackedBool                    mExpired;
91
  PRPackedBool                    mExpired;
92
  PRPackedBool                    mSticky;
89
  nsCString                       mContentType;
93
  nsCString                       mContentType;
90
  nsCOMPtr<nsISupports>           mCacheKey;
94
  nsCOMPtr<nsISupports>           mCacheKey;
91
  nsISHEntry *                    mParent;  // weak reference
95
  nsISHEntry *                    mParent;  // weak reference
96
  nsCOMPtr<nsISupports>           mWindowState;
97
  nsRect                          mViewerBounds;
98
  nsVoidArray                     mChildShells;
99
  nsCOMPtr<nsISecureBrowserUIState> mSecurityState;
100
  nsCOMPtr<nsISupportsArray>      mRefreshURIList;
92
};
101
};
93
102
94
#endif /* nsSHEntry_h */
103
#endif /* nsSHEntry_h */
(-)xpfe/components/shistory/src/nsSHistory.cpp (-7 / +58 lines)
Line     Link Here 
 Lines 54-62    Link Here 
54
#include "nsIDocShellLoadInfo.h"
54
#include "nsIDocShellLoadInfo.h"
55
#include "nsIServiceManager.h"
55
#include "nsIServiceManager.h"
56
#include "nsIPrefService.h"
56
#include "nsIPrefService.h"
57
#include "nsIURI.h"
58
#include "nsIContentViewer.h"
57
59
58
#define PREF_SHISTORY_SIZE "browser.sessionhistory.max_entries"
60
#define PREF_SHISTORY_SIZE "browser.sessionhistory.max_entries"
61
#define PREF_SHISTORY_VIEWERS "browser.sessionhistory.max_viewers"
62
59
static PRInt32  gHistoryMaxSize = 50;
63
static PRInt32  gHistoryMaxSize = 50;
64
static PRInt32  gHistoryMaxViewers = 0;
60
65
61
enum HistCmd{
66
enum HistCmd{
62
  HIST_CMD_BACK,
67
  HIST_CMD_BACK,
 Lines 69-75   enum HistCmd{ Link Here 
69
//***    nsSHistory: Object Management
74
//***    nsSHistory: Object Management
70
//*****************************************************************************
75
//*****************************************************************************
71
76
72
nsSHistory::nsSHistory() : mListRoot(nsnull), mIndex(-1), mLength(0), mRequestedIndex(-1)
77
nsSHistory::nsSHistory() : mListRoot(nsnull), mIndex(-1), mLength(0), mRequestedIndex(-1), mNumViewers(0)
73
{
78
{
74
}
79
}
75
80
 Lines 104-113   nsSHistory::Init() Link Here 
104
{
109
{
105
  nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
110
  nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
106
  if (prefs) {
111
  if (prefs) {
107
    nsCOMPtr<nsIPrefBranch> defaultBranch;
112
    nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
108
    prefs->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch));
113
    if (branch) {
109
    if (defaultBranch) {
114
      branch->GetIntPref(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
110
      defaultBranch->GetIntPref(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
115
      branch->GetIntPref(PREF_SHISTORY_VIEWERS, &gHistoryMaxViewers);
111
    }
116
    }
112
  }
117
  }
113
  return NS_OK;
118
  return NS_OK;
 Lines 171-177   nsSHistory::AddEntry(nsISHEntry * aSHEnt Link Here 
171
  //Purge History list if it is too long
176
  //Purge History list if it is too long
172
  if ((gHistoryMaxSize >= 0) && (mLength > gHistoryMaxSize))
177
  if ((gHistoryMaxSize >= 0) && (mLength > gHistoryMaxSize))
173
    PurgeHistory(mLength-gHistoryMaxSize);
178
    PurgeHistory(mLength-gHistoryMaxSize);
174
  
179
180
  // Evict content viewers if there are too many.
181
  EvictContentViewers(mIndex - 1, mIndex);
182
175
  return NS_OK;
183
  return NS_OK;
176
}
184
}
177
185
 Lines 207-212   nsSHistory::GetEntryAtIndex(PRInt32 aInd Link Here 
207
    if (NS_SUCCEEDED(rv) && (*aResult)) {
215
    if (NS_SUCCEEDED(rv) && (*aResult)) {
208
      // Set mIndex to the requested index, if asked to do so..
216
      // Set mIndex to the requested index, if asked to do so..
209
      if (aModifyIndex) {
217
      if (aModifyIndex) {
218
        EvictContentViewers(mIndex, aIndex);
210
        mIndex = aIndex;
219
        mIndex = aIndex;
211
      }
220
      }
212
    } //entry
221
    } //entry
 Lines 583-594   nsSHistory::Reload(PRUint32 aReloadFlags Link Here 
583
	return LoadEntry(mIndex, loadType, HIST_CMD_RELOAD);
592
	return LoadEntry(mIndex, loadType, HIST_CMD_RELOAD);
584
}
593
}
585
594
595
void
596
nsSHistory::EvictContentViewers(PRInt32 aFromIndex, PRInt32 aToIndex)
597
{
598
  // To enforce the limit on cached content viewers, we need to release all
599
  // of the content viewers that are no longer in the "window" that now
600
  // ends/begins at aToIndex.
601
602
  PRInt32 startIndex, endIndex;
603
  if (aToIndex > aFromIndex) { // going forward
604
    startIndex = PR_MAX(0, aFromIndex - gHistoryMaxViewers);
605
    endIndex = aToIndex - gHistoryMaxViewers;
606
  } else { // going backward
607
    startIndex = aToIndex + gHistoryMaxViewers;
608
    endIndex = PR_MIN(mLength - 1, aFromIndex + gHistoryMaxViewers);
609
  }
610
611
  nsCOMPtr<nsISHEntry> entry;
612
  nsCOMPtr<nsIContentViewer> viewer;
613
  nsISHTransaction *temp;
614
  nsCOMPtr<nsISHTransaction> trans;
615
  GetTransactionAtIndex(startIndex, getter_AddRefs(trans));
616
617
  for (PRInt32 i = startIndex; trans && i < endIndex; ++i) {
618
    trans->GetSHEntry(getter_AddRefs(entry));
619
    entry->GetContentViewer(getter_AddRefs(viewer));
620
    if (viewer) {
621
      viewer->Destroy();
622
      entry->SetContentViewer(nsnull);
623
    }
624
625
    entry->SetWindowState(nsnull);
626
    temp = trans;
627
    temp->GetNext(getter_AddRefs(trans));
628
  }
629
}
630
586
NS_IMETHODIMP
631
NS_IMETHODIMP
587
nsSHistory::UpdateIndex()
632
nsSHistory::UpdateIndex()
588
{
633
{
589
  // Update the actual index with the right value. 
634
  // Update the actual index with the right value. 
590
  if (mIndex != mRequestedIndex && mRequestedIndex != -1)
635
  if (mIndex != mRequestedIndex && mRequestedIndex != -1) {
636
    // We've just finished a history navigation (back or forward), so enforce
637
    // the max number of content viewers.
638
639
    EvictContentViewers(mIndex, mRequestedIndex);
591
    mIndex = mRequestedIndex;
640
    mIndex = mRequestedIndex;
641
  }
642
592
  return NS_OK;
643
  return NS_OK;
593
}
644
}
594
645
(-)xpfe/components/shistory/src/nsSHistory.h (+3 lines)
Line     Link Here 
 Lines 85-95   protected: Link Here 
85
   nsresult PrintHistory();
85
   nsresult PrintHistory();
86
#endif
86
#endif
87
87
88
  void EvictContentViewers(PRInt32 aFromIndex, PRInt32 aToIndex);
89
88
protected:
90
protected:
89
  nsCOMPtr<nsISHTransaction> mListRoot;
91
  nsCOMPtr<nsISHTransaction> mListRoot;
90
  PRInt32 mIndex;
92
  PRInt32 mIndex;
91
  PRInt32 mLength;
93
  PRInt32 mLength;
92
  PRInt32 mRequestedIndex;
94
  PRInt32 mRequestedIndex;
95
  PRInt32 mNumViewers;
93
  // Session History listener
96
  // Session History listener
94
  nsWeakPtr mListener;
97
  nsWeakPtr mListener;
95
  // Weak reference. Do not refcount this.
98
  // Weak reference. Do not refcount this.

Return to bug 274784