Attachment #182608: pref'd off patch w/ short circuit and crash fix 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 / +43 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 it is safe to cache the presentation of this document
684
   * and all of its subdocuments. This method checks the following conditions
685
   * recursively:
686
   *  - Some document types, such as plugin documents, cannot be safely cached.
687
   *  - If there are any pending requests, we don't allow the presentation
688
   *    to be cached.  Ideally these requests would be suspended and resumed,
689
   *    but that is difficult in some cases, such as XMLHttpRequest.
690
   *  - If there are any beforeunload or unload listeners, we must fire them
691
   *    for correctness, but this likely puts the document into a state where
692
   *    it would not function correctly if restored.
693
   *
694
   * |aNewRequest| should be the request for a new document which will
695
   * replace this document in the docshell.  The new document's request
696
   * will be ignored when checking for active requests.  If there is no
697
   * request associated with the new document, this parameter may be null.
698
   */
699
  virtual PRBool CanSavePresentation(nsIRequest *aNewRequest) = 0;
700
701
  /**
702
   * Notify the document that its associated ContentViewer is being destroyed.
703
   * This releases circular references so that the document can go away.
704
   * Destroy() is only called on documents that have a content viewer.
705
   */
706
  virtual void Destroy() = 0;
707
668
protected:
708
protected:
669
  ~nsIDocument()
709
  ~nsIDocument()
670
  {
710
  {
(-)content/base/src/nsDocument.cpp (-31 / +201 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 4609-4611   nsDocument::UnsetProperty(nsIAtom *aProp Link Here 
4609
{
4580
{
4610
  return mPropertyTable.UnsetProperty(this, aPropertyName, aStatus);
4581
  return mPropertyTable.UnsetProperty(this, aPropertyName, aStatus);
4611
}
4582
}
4583
4584
nsresult
4585
nsDocument::Sanitize()
4586
{
4587
  // Sanitize the document by resetting all password fields and any form
4588
  // fields with autocomplete=off to their default values.  We do this now,
4589
  // instead of when the presentation is restored, to offer some protection
4590
  // in case there is ever an exploit that allows a cached document to be
4591
  // accessed from a different document.
4592
4593
  // First locate all input elements, regardless of whether they are
4594
  // in a form, and reset the password and autocomplete=off elements.
4595
4596
  nsCOMPtr<nsIDOMNodeList> nodes;
4597
  nsresult rv = GetElementsByTagName(NS_LITERAL_STRING("input"),
4598
                                     getter_AddRefs(nodes));
4599
  NS_ENSURE_SUCCESS(rv, rv);
4600
4601
  PRUint32 length = 0;
4602
  if (nodes)
4603
    nodes->GetLength(&length);
4604
4605
  nsCOMPtr<nsIDOMNode> item;
4606
  nsAutoString value;
4607
  PRUint32 i;
4608
4609
  for (i = 0; i < length; ++i) {
4610
    nodes->Item(i, getter_AddRefs(item));
4611
    NS_ASSERTION(item, "null item in node list!");
4612
4613
    nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(item);
4614
    if (!input)
4615
      continue;
4616
4617
    PRBool resetValue = PR_FALSE;
4618
4619
    input->GetAttribute(NS_LITERAL_STRING("autocomplete"), value);
4620
    if (value.LowerCaseEqualsLiteral("off")) {
4621
      resetValue = PR_TRUE;
4622
    } else {
4623
      input->GetType(value);
4624
      if (value.LowerCaseEqualsLiteral("password"))
4625
        resetValue = PR_TRUE;
4626
    }
4627
4628
    if (resetValue) {
4629
      nsCOMPtr<nsIFormControl> fc = do_QueryInterface(input);
4630
      fc->Reset();
4631
    }
4632
  }
4633
4634
  // Now locate all _form_ elements that have autocomplete=off and reset them
4635
  rv = GetElementsByTagName(NS_LITERAL_STRING("form"), getter_AddRefs(nodes));
4636
  NS_ENSURE_SUCCESS(rv, rv);
4637
4638
  length = 0;
4639
  if (nodes)
4640
    nodes->GetLength(&length);
4641
4642
  for (i = 0; i < length; ++i) {
4643
    nodes->Item(i, getter_AddRefs(item));
4644
    NS_ASSERTION(item, "null item in nodelist");
4645
4646
    nsCOMPtr<nsIDOMHTMLFormElement> form = do_QueryInterface(item);
4647
    if (!form)
4648
      continue;
4649
4650
    form->GetAttribute(NS_LITERAL_STRING("autocomplete"), value);
4651
    if (value.LowerCaseEqualsLiteral("off"))
4652
      form->Reset();
4653
  }
4654
4655
  return NS_OK;
4656
}
4657
4658
struct SubDocEnumArgs
4659
{
4660
  nsIDocument::nsSubDocEnumFunc callback;
4661
  void *data;
4662
};
4663
4664
PR_STATIC_CALLBACK(PLDHashOperator)
4665
SubDocHashEnum(PLDHashTable *table, PLDHashEntryHdr *hdr,
4666
               PRUint32 number, void *arg)
4667
{
4668
  SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr);
4669
  SubDocEnumArgs *args = NS_STATIC_CAST(SubDocEnumArgs*, arg);
4670
4671
  nsIDocument *subdoc = entry->mSubDocument;
4672
  PRBool next = subdoc ? args->callback(subdoc, args->data) : PR_TRUE;
4673
4674
  return next ? PL_DHASH_NEXT : PL_DHASH_STOP;
4675
}
4676
4677
void
4678
nsDocument::EnumerateSubDocuments(nsSubDocEnumFunc aCallback, void *aData)
4679
{
4680
  if (mSubDocuments) {
4681
    SubDocEnumArgs args = { aCallback, aData };
4682
    PL_DHashTableEnumerate(mSubDocuments, SubDocHashEnum, &args);
4683
  }
4684
}
4685
4686
PR_STATIC_CALLBACK(PLDHashOperator)
4687
CanCacheSubDocument(PLDHashTable *table, PLDHashEntryHdr *hdr,
4688
                    PRUint32 number, void *arg)
4689
{
4690
  SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr);
4691
  PRBool *canCacheArg = NS_STATIC_CAST(PRBool*, arg);
4692
4693
  nsIDocument *subdoc = entry->mSubDocument;
4694
4695
  // The aIgnoreRequest we were passed is only for us, so don't pass it on.
4696
  PRBool canCache = subdoc ? subdoc->CanSavePresentation(nsnull) : PR_FALSE;
4697
  if (!canCache) {
4698
    *canCacheArg = PR_FALSE;
4699
    return PL_DHASH_STOP;
4700
  }
4701
4702
  return PL_DHASH_NEXT;
4703
}
4704
4705
#ifdef DEBUG_bryner
4706
#define DEBUG_PAGE_CACHE
4707
#endif
4708
4709
PRBool
4710
nsDocument::CanSavePresentation(nsIRequest *aNewRequest)
4711
{
4712
  // Check our event listneer manager for unload/beforeunload listeners.
4713
  nsCOMPtr<nsIDOMEventReceiver> er = do_QueryInterface(mScriptGlobalObject);
4714
  if (er) {
4715
    nsCOMPtr<nsIEventListenerManager> manager;
4716
    er->GetListenerManager(getter_AddRefs(manager));
4717
    if (manager && manager->HasUnloadListeners()) {
4718
      return PR_FALSE;
4719
    }
4720
  }
4721
4722
  nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
4723
  if (loadGroup) {
4724
    nsCOMPtr<nsISimpleEnumerator> requests;
4725
    loadGroup->GetRequests(getter_AddRefs(requests));
4726
4727
    PRBool hasMore = PR_FALSE;
4728
4729
    while (NS_SUCCEEDED(requests->HasMoreElements(&hasMore)) && hasMore) {
4730
      nsCOMPtr<nsISupports> elem;
4731
      requests->GetNext(getter_AddRefs(elem));
4732
4733
      nsCOMPtr<nsIRequest> request = do_QueryInterface(elem);
4734
      if (request && request != aNewRequest) {
4735
#ifdef DEBUG_PAGE_CACHE
4736
        nsCAutoString requestName, docSpec;
4737
        request->GetName(requestName);
4738
        if (mDocumentURI)
4739
          mDocumentURI->GetSpec(docSpec);
4740
4741
        printf("document %s has request %s\n",
4742
               docSpec.get(), requestName.get());
4743
#endif
4744
        return PR_FALSE;
4745
      }
4746
    }
4747
  }
4748
4749
  PRBool canCache = PR_TRUE;
4750
  if (mSubDocuments)
4751
    PL_DHashTableEnumerate(mSubDocuments, CanCacheSubDocument, &canCache);
4752
4753
  return canCache;
4754
}
4755
4756
void
4757
nsDocument::Destroy()
4758
{
4759
  // The ContentViewer wants to release the document now.  So, tell our content
4760
  // to drop any references to the document so that it can be destroyed.
4761
  PRInt32 count = mChildren.Count();
4762
4763
  mIsGoingAway = PR_TRUE;
4764
4765
  for (PRInt32 indx = 0; indx < count; ++indx) {
4766
    mChildren[indx]->UnbindFromTree();
4767
  }
4768
4769
  // Propagate the out-of-band notification to each PresShell's anonymous
4770
  // content as well. This ensures that there aren't any accidental references
4771
  // left in anonymous content keeping the document alive. (While not strictly
4772
  // necessary -- the PresShell owns us -- it's tidy.)
4773
  for (count = mPresShells.Count() - 1; count >= 0; --count) {
4774
    nsCOMPtr<nsIPresShell> shell =
4775
      NS_STATIC_CAST(nsIPresShell*, mPresShells[count]);
4776
    if (!shell)
4777
      continue;
4778
4779
    shell->ReleaseAnonymousContent();
4780
  }
4781
}
(-)content/base/src/nsDocument.h (-1 / +9 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) CanSavePresentation(nsIRequest *aNewRequest);
539
  virtual NS_HIDDEN_(void) Destroy();
540
533
protected:
541
protected:
534
542
535
  void RetrieveRelevantHeaders(nsIChannel *aChannel);
543
  void RetrieveRelevantHeaders(nsIChannel *aChannel);
 Lines 592-598   protected: Link Here 
592
600
593
  nsHashtable mRadioGroups;
601
  nsHashtable mRadioGroups;
594
602
595
  // True if the document is being destroyed.
603
  // True if the document has been detached from its content viewer.
596
  PRPackedBool mIsGoingAway;
604
  PRPackedBool mIsGoingAway;
597
605
598
  // True if the document is being destroyed.
606
  // True if the document is being destroyed.
(-)content/base/src/nsGenericElement.cpp (-1 / +3 lines)
Line     Link Here 
 Lines 2586-2592   nsGenericElement::SetFocus(nsPresContext Link Here 
2586
PRBool
2586
PRBool
2587
nsGenericElement::ShouldFocus(nsIContent *aContent)
2587
nsGenericElement::ShouldFocus(nsIContent *aContent)
2588
{
2588
{
2589
  PRBool visible = PR_TRUE;
2589
  // Default to false, since if the document is not attached to a window,
2590
  // we should not focus any of its content.
2591
  PRBool visible = PR_FALSE;
2590
2592
2591
  // Figure out if we're focusing an element in an inactive (hidden)
2593
  // Figure out if we're focusing an element in an inactive (hidden)
2592
  // tab (whose docshell is not visible), if so, drop this focus
2594
  // tab (whose docshell is not visible), if so, drop this focus
(-)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 (-3 / +8 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 185-190   public: Link Here 
185
  * Loop pass for evaluation of system event listeners.
184
  * Loop pass for evaluation of system event listeners.
186
  */
185
  */
187
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup) = 0;
186
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup) = 0;
187
188
  /**
189
   * Allows us to quickly determine whether we have unload or beforeunload
190
   * listeners registered.
191
   */
192
  virtual PRBool HasUnloadListeners() = 0;
188
};
193
};
189
194
190
nsresult
195
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 891-896   nsEventListenerManager::GetIdentifiersFo Link Here 
891
    *aArrayType = eEventArrayType_Load;
892
    *aArrayType = eEventArrayType_Load;
892
    *aFlags = NS_EVENT_BITS_LOAD_ERROR;
893
    *aFlags = NS_EVENT_BITS_LOAD_ERROR;
893
  }
894
  }
895
  else if (aType == nsLayoutAtoms::onDOMPageRestore) {
896
    *aArrayType = eEventArrayType_Load;
897
    *aFlags = NS_EVENT_BITS_LOAD_PAGE_RESTORE;
898
  }
894
  else if (aType == nsLayoutAtoms::onpaint) {
899
  else if (aType == nsLayoutAtoms::onpaint) {
895
    *aArrayType = eEventArrayType_Paint;
900
    *aArrayType = eEventArrayType_Paint;
896
    *aFlags = NS_EVENT_BITS_PAINT_PAINT;
901
    *aFlags = NS_EVENT_BITS_PAINT_PAINT;
 Lines 2232-2237   nsEventListenerManager::GetCoordinatesFo Link Here 
2232
  }
2237
  }
2233
}
2238
}
2234
2239
2240
PRBool
2241
nsEventListenerManager::HasUnloadListeners()
2242
{
2243
  nsVoidArray *listeners = GetListenersByType(eEventArrayType_Load, nsnull,
2244
                                              PR_FALSE);
2245
  if (listeners) {
2246
    PRInt32 count = listeners->Count();
2247
    for (PRInt32 i = 0; i < count; ++i) {
2248
      PRUint32 subtype = NS_STATIC_CAST(nsListenerStruct*,
2249
                                        listeners->FastElementAt(i))->mSubType;
2250
      if (subtype == NS_EVENT_BITS_NONE ||
2251
          subtype & (NS_EVENT_BITS_LOAD_UNLOAD |
2252
                     NS_EVENT_BITS_LOAD_BEFORE_UNLOAD))
2253
        return PR_TRUE;
2254
    }
2255
  }
2256
2257
  return PR_FALSE;
2258
}
2259
2235
nsresult
2260
nsresult
2236
NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) 
2261
NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) 
2237
{
2262
{
(-)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 1538-1552   nsGenericHTMLElement::HandleDOMEventForA Link Here 
1538
            // nothing else.
1538
            // nothing else.
1539
            nsCOMPtr<nsPIDOMWindow> win =
1539
            nsCOMPtr<nsPIDOMWindow> win =
1540
              do_QueryInterface(document->GetScriptGlobalObject());
1540
              do_QueryInterface(document->GetScriptGlobalObject());
1541
            nsIFocusController *focusController =
1541
            if (win) {
1542
              win->GetRootFocusController();
1542
              nsIFocusController *focusController =
1543
            PRBool isActive = PR_FALSE;
1543
                win->GetRootFocusController();
1544
            focusController->GetActive(&isActive);
1544
              PRBool isActive = PR_FALSE;
1545
            if (!isActive) {
1545
              focusController->GetActive(&isActive);
1546
              nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
1546
              if (!isActive) {
1547
              if(domElement)
1547
                nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
1548
                focusController->SetFocusedElement(domElement);
1548
                if(domElement)
1549
              break;
1549
                  focusController->SetFocusedElement(domElement);
1550
                break;
1551
              }
1550
            }
1552
            }
1551
  
1553
  
1552
            aPresContext->EventStateManager()->
1554
            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/html/document/src/nsImageDocument.cpp (-24 / +38 lines)
Line     Link Here 
 Lines 104-109   public: Link Here 
104
                                     nsIContentSink*     aSink = nsnull);
104
                                     nsIContentSink*     aSink = nsnull);
105
105
106
  virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
106
  virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
107
  virtual void Destroy();
107
108
108
  NS_DECL_NSIIMAGEDOCUMENT
109
  NS_DECL_NSIIMAGEDOCUMENT
109
110
 Lines 289-314   nsImageDocument::StartDocumentLoad(const Link Here 
289
}
290
}
290
291
291
void
292
void
292
nsImageDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
293
nsImageDocument::Destroy()
293
{
294
{
294
  if (!aScriptGlobalObject) {
295
  // Remove our event listener from the image content.
295
    if (mImageResizingEnabled) {
296
  if (mImageResizingEnabled) {
296
      nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mImageContent);
297
    nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mImageContent);
297
      target->RemoveEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);
298
    target->RemoveEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);
299
  }
298
300
299
      target = do_QueryInterface(mScriptGlobalObject);
301
  // Break reference cycle with mImageContent, if we have one
300
      target->RemoveEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);
302
  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
301
      target->RemoveEventListener(NS_LITERAL_STRING("keypress"), this,
303
  if (imageLoader) {
302
                                  PR_FALSE);
304
    imageLoader->RemoveObserver(this);
303
    }
305
  }
304
306
305
    // Break reference cycle with mImageContent, if we have one
307
  mImageContent = nsnull;
306
    nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
308
307
    if (imageLoader) {
309
  nsMediaDocument::Destroy();
308
      imageLoader->RemoveObserver(this);
310
}
309
    }
311
310
    
312
void
311
    mImageContent = nsnull;
313
nsImageDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
314
{
315
  // If the script global object is changing, we need to unhook our event
316
  // listeners on the window.
317
  nsCOMPtr<nsIDOMEventTarget> target;
318
  if (mImageResizingEnabled && mScriptGlobalObject &&
319
      aScriptGlobalObject != mScriptGlobalObject) {
320
    target = do_QueryInterface(mScriptGlobalObject);
321
    target->RemoveEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);
322
    target->RemoveEventListener(NS_LITERAL_STRING("keypress"), this,
323
                                PR_FALSE);
312
  }
324
  }
313
325
314
  // Set the script global object on the superclass before doing
326
  // Set the script global object on the superclass before doing
 Lines 316-331   nsImageDocument::SetScriptGlobalObject(n Link Here 
316
  nsHTMLDocument::SetScriptGlobalObject(aScriptGlobalObject);
328
  nsHTMLDocument::SetScriptGlobalObject(aScriptGlobalObject);
317
329
318
  if (aScriptGlobalObject) {
330
  if (aScriptGlobalObject) {
319
    // Create synthetic document
331
    if (!mRootContent) {
320
    nsresult rv = CreateSyntheticDocument();
332
      // Create synthetic document
321
    if (NS_FAILED(rv)) {
333
      nsresult rv = CreateSyntheticDocument();
322
      return;
334
      NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");
335
336
      if (mImageResizingEnabled) {
337
        target = do_QueryInterface(mImageContent);
338
        target->AddEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);
339
      }
323
    }
340
    }
324
341
325
    if (mImageResizingEnabled) {
342
    if (mImageResizingEnabled) {
326
      nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mImageContent);
327
      target->AddEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);
328
329
      target = do_QueryInterface(aScriptGlobalObject);
343
      target = do_QueryInterface(aScriptGlobalObject);
330
      target->AddEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);
344
      target->AddEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);
331
      target->AddEventListener(NS_LITERAL_STRING("keypress"), this, PR_FALSE);
345
      target->AddEventListener(NS_LITERAL_STRING("keypress"), this, PR_FALSE);
(-)content/html/document/src/nsPluginDocument.cpp (+10 lines)
Line     Link Here 
 Lines 63-68   public: Link Here 
63
                                     nsIContentSink*     aSink = nsnull);
63
                                     nsIContentSink*     aSink = nsnull);
64
64
65
  virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
65
  virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
66
  virtual PRBool CanSavePresentation(nsIRequest *aNewRequest);
66
67
67
protected:
68
protected:
68
  nsresult CreateSyntheticPluginDocument();
69
  nsresult CreateSyntheticPluginDocument();
 Lines 103-108   nsPluginDocument::SetScriptGlobalObject( Link Here 
103
}
104
}
104
105
105
106
107
PRBool
108
nsPluginDocument::CanSavePresentation(nsIRequest *aNewRequest)
109
{
110
  // Full-page plugins cannot be cached, currently, because we don't have
111
  // the stream listener data to feed to the plugin instance.
112
  return PR_FALSE;
113
}
114
115
106
nsresult
116
nsresult
107
nsPluginDocument::StartDocumentLoad(const char*         aCommand,
117
nsPluginDocument::StartDocumentLoad(const char*         aCommand,
108
                                    nsIChannel*         aChannel,
118
                                    nsIChannel*         aChannel,
(-)content/xbl/src/nsXBLPrototypeHandler.cpp (+2 lines)
Line     Link Here 
 Lines 289-294   nsXBLPrototypeHandler::ExecuteHandler(ns Link Here 
289
          return NS_ERROR_FAILURE;
289
          return NS_ERROR_FAILURE;
290
290
291
        privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
291
        privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
292
        if (!privateWindow)
293
          return NS_ERROR_FAILURE;
292
      }
294
      }
293
295
294
      focusController = privateWindow->GetRootFocusController();
296
      focusController = privateWindow->GetRootFocusController();
(-)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 (-23 / +564 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"
172
175
173
// Number of documents currently loading
176
// Number of documents currently loading
174
static PRInt32 gNumberOfDocumentsLoading = 0;
177
static PRInt32 gNumberOfDocumentsLoading = 0;
 Lines 246-251   nsDocShell::nsDocShell(): Link Here 
246
    mIsBeingDestroyed(PR_FALSE),
249
    mIsBeingDestroyed(PR_FALSE),
247
    mIsExecutingOnLoadHandler(PR_FALSE),
250
    mIsExecutingOnLoadHandler(PR_FALSE),
248
    mIsPrintingOrPP(PR_FALSE),
251
    mIsPrintingOrPP(PR_FALSE),
252
    mSavingOldViewer(PR_FALSE),
249
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
253
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
250
    mChildOffset(0),
254
    mChildOffset(0),
251
    mBusyFlags(BUSY_FLAGS_NONE),
255
    mBusyFlags(BUSY_FLAGS_NONE),
 Lines 1355-1366   nsDocShell::SetCurrentURI(nsIURI *aURI, Link Here 
1355
        isRoot = PR_TRUE;
1359
        isRoot = PR_TRUE;
1356
    }
1360
    }
1357
    if (mLSHE) {
1361
    if (mLSHE) {
1358
      nsCOMPtr<nsIHistoryEntry> historyEntry(do_QueryInterface(mLSHE));
1362
        mLSHE->GetIsSubFrame(&isSubFrame);
1359
      
1360
      // Check if this is a subframe navigation
1361
      if (historyEntry) {
1362
        historyEntry->GetIsSubFrame(&isSubFrame);
1363
      }
1364
    }
1363
    }
1365
1364
1366
    if (!isSubFrame && !isRoot) {
1365
    if (!isSubFrame && !isRoot) {
 Lines 1675-1680   nsDocShell::TabToTreeOwner(PRBool aForwa Link Here 
1675
    return NS_OK;
1674
    return NS_OK;
1676
}
1675
}
1677
1676
1677
NS_IMETHODIMP
1678
nsDocShell::GetSecurityUI(nsISecureBrowserUI **aSecurityUI)
1679
{
1680
    NS_IF_ADDREF(*aSecurityUI = mSecurityUI);
1681
    return NS_OK;
1682
}
1683
1684
NS_IMETHODIMP
1685
nsDocShell::SetSecurityUI(nsISecureBrowserUI *aSecurityUI)
1686
{
1687
    mSecurityUI = aSecurityUI;
1688
    return NS_OK;
1689
}
1690
1678
//*****************************************************************************
1691
//*****************************************************************************
1679
// nsDocShell::nsIDocShellTreeItem
1692
// nsDocShell::nsIDocShellTreeItem
1680
//*****************************************************************************   
1693
//*****************************************************************************   
 Lines 3257-3268   nsDocShell::LoadPage(nsISupports *aPageD Link Here 
3257
    // load the page as view-source
3270
    // load the page as view-source
3258
    //
3271
    //
3259
    if (nsIWebPageDescriptor::DISPLAY_AS_SOURCE == aDisplayType) {
3272
    if (nsIWebPageDescriptor::DISPLAY_AS_SOURCE == aDisplayType) {
3260
        nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(shEntry));
3261
        nsCOMPtr<nsIURI> oldUri, newUri;
3273
        nsCOMPtr<nsIURI> oldUri, newUri;
3262
        nsCString spec, newSpec;
3274
        nsCString spec, newSpec;
3263
3275
3264
        // Create a new view-source URI and replace the original.
3276
        // Create a new view-source URI and replace the original.
3265
        rv = srcHE->GetURI(getter_AddRefs(oldUri));
3277
        rv = shEntry->GetURI(getter_AddRefs(oldUri));
3266
        if (NS_FAILED(rv))
3278
        if (NS_FAILED(rv))
3267
              return rv;
3279
              return rv;
3268
3280
 Lines 3716-3722   nsDocShell::SetTitle(const PRUnichar * a Link Here 
3716
    // would suffice. 
3728
    // would suffice. 
3717
    if (mOSHE && (mLoadType != LOAD_BYPASS_HISTORY) &&
3729
    if (mOSHE && (mLoadType != LOAD_BYPASS_HISTORY) &&
3718
        (mLoadType != LOAD_HISTORY) && (mLoadType != LOAD_ERROR_PAGE)) {
3730
        (mLoadType != LOAD_HISTORY) && (mLoadType != LOAD_ERROR_PAGE)) {
3719
        mOSHE->SetTitle(mTitle.get());    
3731
        mOSHE->SetTitle(mTitle);    
3720
    }
3732
    }
3721
3733
3722
3734
 Lines 4312-4317   nsDocShell::CancelRefreshURITimers() Link Here 
4312
}
4324
}
4313
4325
4314
NS_IMETHODIMP
4326
NS_IMETHODIMP
4327
nsDocShell::SuspendRefreshURIs()
4328
{
4329
    if (mRefreshURIList) {
4330
        PRUint32 n = 0;
4331
        mRefreshURIList->Count(&n);
4332
4333
        for (PRUint32 i = 0;  i < n; ++i) {
4334
            nsCOMPtr<nsITimer> timer = do_QueryElementAt(mRefreshURIList, i);
4335
            if (!timer)
4336
                continue;  // this must be a nsRefreshURI already
4337
4338
            // Replace this timer object with a nsRefreshTimer object.
4339
            nsCOMPtr<nsITimerCallback> callback;
4340
            timer->GetCallback(getter_AddRefs(callback));
4341
4342
            timer->Cancel();
4343
4344
            nsCOMPtr<nsRefreshTimer> rt = do_QueryInterface(callback);
4345
            NS_ASSERTION(rt, "RefreshURIList timer callbacks should only be RefreshTimer objects");
4346
4347
            mRefreshURIList->ReplaceElementAt(rt, i);
4348
        }
4349
    }
4350
4351
    // Suspend refresh URIs for our child shells as well.
4352
    PRInt32 n = mChildList.Count();
4353
4354
    for (PRInt32 i = 0; i < n; ++i) {
4355
        nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
4356
        if (shell)
4357
            shell->SuspendRefreshURIs();
4358
    }
4359
4360
    return NS_OK;
4361
}
4362
4363
NS_IMETHODIMP
4364
nsDocShell::ResumeRefreshURIs()
4365
{
4366
    RefreshURIFromQueue();
4367
4368
    // Resume refresh URIs for our child shells as well.
4369
    PRInt32 n = mChildList.Count();
4370
4371
    for (PRInt32 i = 0; i < n; ++i) {
4372
        nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
4373
        if (shell)
4374
            shell->ResumeRefreshURIs();
4375
    }
4376
4377
    return NS_OK;
4378
}
4379
4380
nsresult
4315
nsDocShell::RefreshURIFromQueue()
4381
nsDocShell::RefreshURIFromQueue()
4316
{
4382
{
4317
    if (!mRefreshURIList)
4383
    if (!mRefreshURIList)
 Lines 4697-4702   nsDocShell::CreateAboutBlankContentViewe Link Here 
4697
  return rv;
4763
  return rv;
4698
}
4764
}
4699
4765
4766
PRBool
4767
nsDocShell::CanSavePresentation(nsIRequest *aNewRequest)
4768
{
4769
    if (!mOSHE)
4770
        return PR_FALSE; // no entry to save into
4771
4772
    // Only save presentation for "normal" loads and link loads.  Anything else
4773
    // probably wants to refetch the page, so caching the old presentation
4774
    // would be incorrect.
4775
    if (mLoadType != LOAD_NORMAL &&
4776
        mLoadType != LOAD_HISTORY &&
4777
        mLoadType != LOAD_LINK)
4778
        return PR_FALSE;
4779
4780
    // If the session history entry has the saveLayoutState flag set to false,
4781
    // then we should not cache the presentation.
4782
    PRBool canSaveState;
4783
    mOSHE->GetSaveLayoutStateFlag(&canSaveState);
4784
    if (canSaveState == PR_FALSE)
4785
        return PR_FALSE;
4786
4787
    // If the document is not done loading, don't cache it.
4788
    nsCOMPtr<nsPIDOMWindow> pWin = do_QueryInterface(mScriptGlobal);
4789
    if (!pWin || pWin->IsLoading())
4790
        return PR_FALSE;
4791
4792
    // Avoid doing the work of saving the presentation state in the case where
4793
    // the content viewer cache is disabled.
4794
    PRInt32 maxViewers = 0;
4795
    mPrefs->GetIntPref("browser.sessionhistory.max_viewers", &maxViewers);
4796
    if (maxViewers == 0)
4797
        return PR_FALSE;
4798
4799
    // If the document does not want its presentation cached, then don't.
4800
    nsCOMPtr<nsIDocument> doc = do_QueryInterface(pWin->GetExtantDocument());
4801
    if (!doc || !doc->CanSavePresentation(aNewRequest))
4802
        return PR_FALSE;
4803
4804
    return PR_TRUE;
4805
}
4806
4807
nsresult
4808
nsDocShell::CaptureState()
4809
{
4810
    nsCOMPtr<nsPIDOMWindow> privWin = do_QueryInterface(mScriptGlobal);
4811
    if (!privWin || !mOSHE)
4812
        return NS_ERROR_FAILURE;
4813
4814
    nsCOMPtr<nsISupports> windowState;
4815
    nsresult rv = privWin->SaveWindowState(getter_AddRefs(windowState));
4816
    NS_ENSURE_SUCCESS(rv, rv);
4817
4818
#ifdef DEBUG_PAGE_CACHE
4819
    nsCOMPtr<nsIURI> uri;
4820
    mOSHE->GetURI(getter_AddRefs(uri));
4821
    nsCAutoString spec;
4822
    if (uri)
4823
        uri->GetSpec(spec);
4824
    printf("Saving presentation into session history\n");
4825
    printf("  SH URI: %s\n", spec.get());
4826
#endif
4827
4828
    rv = mOSHE->SetWindowState(windowState);
4829
    NS_ENSURE_SUCCESS(rv, rv);
4830
4831
    // Suspend refresh URIs and save off the timer queue
4832
    SuspendRefreshURIs();
4833
    rv = mOSHE->SetRefreshURIList(mRefreshURIList);
4834
    NS_ENSURE_SUCCESS(rv, rv);
4835
4836
    mRefreshURIList = nsnull;
4837
4838
    // Capture the current content viewer bounds.
4839
    nsCOMPtr<nsIPresShell> shell;
4840
    nsDocShell::GetPresShell(getter_AddRefs(shell));
4841
    if (shell) {
4842
        nsIViewManager *vm = shell->GetViewManager();
4843
        if (vm) {
4844
            nsIView *rootView = nsnull;
4845
            vm->GetRootView(rootView);
4846
            if (rootView) {
4847
                nsIWidget *widget = rootView->GetWidget();
4848
                if (widget) {
4849
                    nsRect bounds(0, 0, 0, 0);
4850
                    widget->GetBounds(bounds);
4851
                    rv = mOSHE->SetViewerBounds(bounds);
4852
                }
4853
            }
4854
        }
4855
    }
4856
4857
    // Capture the docshell hierarchy.
4858
    mOSHE->ClearChildShells();
4859
4860
    PRInt32 childCount = mChildList.Count();
4861
    for (PRInt32 i = 0; i < childCount; ++i) {
4862
        nsCOMPtr<nsIDocShellTreeItem> childShell = do_QueryInterface(ChildAt(i));
4863
        NS_ASSERTION(childShell, "null child shell");
4864
4865
        mOSHE->AddChildShell(childShell);
4866
    }
4867
4868
    // Capture the security state.
4869
    nsCOMPtr<nsISupports> securityState;
4870
    if (mSecurityUI)
4871
        mSecurityUI->CaptureState(getter_AddRefs(securityState));
4872
4873
    return mOSHE->SetSecurityState(securityState);
4874
}
4875
4876
NS_IMETHODIMP
4877
nsDocShell::FireRestoreEvents()
4878
{
4879
    // These events fire bottom-up, so call this on our children first.
4880
    PRInt32 n = mChildList.Count();
4881
    for (PRInt32 i = 0; i < n; ++i) {
4882
        nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
4883
        if (child) {
4884
            child->FireRestoreEvents();
4885
        }
4886
    }
4887
4888
    // Dispatch events.  This is a little messy.  We need to avoid firing
4889
    // onload so that it is visible from the content DOM window, but we _do_
4890
    // want the chrome to see it for chrome/extensions that look for page load.
4891
    // In addition, we need to fire DOMPageRestore on the content window.
4892
4893
    nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(mContentViewer);
4894
    NS_ASSERTION(docViewer, "should not be called with a null viewer");
4895
4896
    nsCOMPtr<nsIPresShell> shell;
4897
    docViewer->GetPresShell(getter_AddRefs(shell));
4898
    NS_ENSURE_TRUE(shell, NS_ERROR_UNEXPECTED);
4899
4900
    nsEvent event(PR_TRUE, NS_PAGE_LOAD);
4901
    nsEventStatus status = nsEventStatus_eIgnore;
4902
4903
    nsCOMPtr<nsPIDOMWindow> privWin = do_QueryInterface(mScriptGlobal);
4904
    NS_ENSURE_TRUE(privWin, NS_ERROR_UNEXPECTED);
4905
4906
    nsCOMPtr<nsIChromeEventHandler> handler = privWin->GetChromeEventHandler();
4907
4908
    PRUint32 flags = NS_EVENT_FLAG_INIT;
4909
    event.flags |= flags;
4910
    flags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
4911
    flags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
4912
4913
    nsIDOMEvent *domEvt = nsnull;
4914
    nsPresContext *pc = shell->GetPresContext();
4915
4916
    nsresult rv = handler->HandleChromeEvent(pc, &event, &domEvt,
4917
                                             flags & NS_EVENT_CAPTURE_MASK,
4918
                                             &status);
4919
    NS_ENSURE_SUCCESS(rv, rv);
4920
4921
    if (domEvt) {
4922
        nsrefcnt rc;
4923
        NS_RELEASE2(domEvt, rc);
4924
        if (0 != rc) {
4925
            // Okay, so someone in the DOM loop (a listener, JS object)
4926
            // still has a ref to the DOM Event but the internal data
4927
            // hasn't been malloc'd.  Force a copy of the data here so the
4928
            // DOM Event is still valid.
4929
4930
            nsCOMPtr<nsIPrivateDOMEvent> privateEvent =
4931
                do_QueryInterface(domEvt);
4932
4933
            if (privateEvent) {
4934
                privateEvent->DuplicatePrivateData();
4935
            }
4936
        }
4937
    }
4938
4939
    status = nsEventStatus_eIgnore;
4940
    nsEvent restoreEvent(PR_TRUE, NS_PAGE_RESTORE);
4941
4942
    return mScriptGlobal->HandleDOMEvent(pc, &restoreEvent, nsnull,
4943
                                         NS_EVENT_FLAG_INIT, &status);
4944
}
4945
4946
4947
nsresult
4948
nsDocShell::RestorePresentation(nsISHEntry *aSHEntry, PRBool aSavePresentation,
4949
                                PRBool *aRestored)
4950
{
4951
    NS_ASSERTION(mLoadType & LOAD_CMD_HISTORY,
4952
                 "RestorePresentation should only be called for history loads");
4953
4954
    nsCOMPtr<nsIURI> uri;
4955
    aSHEntry->GetURI(getter_AddRefs(uri));
4956
4957
    nsCOMPtr<nsIContentViewer> viewer;
4958
    aSHEntry->GetContentViewer(getter_AddRefs(viewer));
4959
4960
#ifdef DEBUG_PAGE_CACHE
4961
    nsCAutoString spec;
4962
    if (uri)
4963
        uri->GetSpec(spec);
4964
#endif
4965
4966
    *aRestored = PR_FALSE;
4967
4968
    if (!viewer) {
4969
#ifdef DEBUG_PAGE_CACHE
4970
        printf("no saved presentation for uri: %s\n", spec.get());
4971
#endif
4972
        return NS_OK;
4973
    }
4974
4975
    NS_ASSERTION(mContentViewer != viewer, "Restoring existing presentation");
4976
4977
#ifdef DEBUG_PAGE_CACHE
4978
    printf("restoring presentation from session history: %s\n", spec.get());
4979
#endif
4980
4981
    // Save off the root view's parent and sibling so that we can insert the
4982
    // new content viewer's root view at the same position.  Also save the
4983
    // bounds of the root view's widget.
4984
4985
    nsIView *rootViewSibling = nsnull, *rootViewParent = nsnull;
4986
    nsRect newBounds(0, 0, 0, 0);
4987
4988
    nsCOMPtr<nsIPresShell> oldPresShell;
4989
    nsDocShell::GetPresShell(getter_AddRefs(oldPresShell));
4990
    if (oldPresShell) {
4991
        nsIViewManager *vm = oldPresShell->GetViewManager();
4992
        if (vm) {
4993
            nsIView *oldRootView = nsnull;
4994
            vm->GetRootView(oldRootView);
4995
4996
            if (oldRootView) {
4997
                rootViewSibling = oldRootView->GetNextSibling();
4998
                rootViewParent = oldRootView->GetParent();
4999
5000
                nsIWidget *widget = oldRootView->GetWidget();
5001
                if (widget) {
5002
                    widget->GetBounds(newBounds);
5003
                }
5004
            }
5005
        }
5006
    }
5007
5008
    // Transfer ownership to mContentViewer.  By ensuring that either the
5009
    // docshell or the session history, but not both, have references to the
5010
    // content viewer, we prevent the viewer from being torn down after
5011
    // Destroy() is called.
5012
5013
    if (!aSavePresentation)
5014
        FireUnloadNotification();
5015
5016
    mFiredUnloadEvent = PR_FALSE;
5017
5018
    if (mContentViewer) {
5019
        mContentViewer->Close();
5020
5021
        if (aSavePresentation)
5022
            mContentViewer->SetHistoryEntry(mOSHE);
5023
5024
        mContentViewer->Destroy();
5025
    }
5026
5027
    mContentViewer.swap(viewer);
5028
    viewer = nsnull; // force a release to complete ownership transfer
5029
5030
    // Reattach to the window object.
5031
    nsresult rv = mContentViewer->Open();
5032
5033
    // Now remove it from the cached presentation.
5034
    aSHEntry->SetContentViewer(nsnull);
5035
5036
    // Restore our child docshell hierarchy.
5037
    DestroyChildren();
5038
    NS_ENSURE_SUCCESS(rv, rv);
5039
5040
    PRInt32 i = 0;
5041
    nsCOMPtr<nsIDocShellTreeItem> childShell;
5042
    while (NS_SUCCEEDED(aSHEntry->ChildShellAt(i++,
5043
                                               getter_AddRefs(childShell))) &&
5044
           childShell) {
5045
        AddChild(childShell);
5046
    }
5047
5048
    // And release the references in the history entry.
5049
    aSHEntry->ClearChildShells();
5050
5051
    // Restore the sticky state of the viewer.  The viewer has set this state
5052
    // on the history entry in Destroy() just before marking itself non-sticky,
5053
    // to avoid teardown of the presentation.
5054
    PRBool sticky;
5055
    aSHEntry->GetSticky(&sticky);
5056
    mContentViewer->SetSticky(sticky);
5057
5058
    // get the previous content viewer size
5059
    nsRect oldBounds(0, 0, 0, 0);
5060
    aSHEntry->GetViewerBounds(oldBounds);
5061
5062
    nsCOMPtr<nsIPresShell> shell;
5063
    nsDocShell::GetPresShell(getter_AddRefs(shell));
5064
5065
    nsIViewManager *newVM = shell ? shell->GetViewManager() : nsnull;
5066
    nsIView *newRootView = nsnull;
5067
    if (newVM)
5068
        newVM->GetRootView(newRootView);
5069
5070
    // Insert the new root view at the correct location in the view tree.
5071
    if (rootViewParent) {
5072
        nsIViewManager *parentVM = rootViewParent->GetViewManager();
5073
5074
        if (parentVM && newRootView) {
5075
            parentVM->InsertChild(rootViewParent, newRootView,
5076
                                  rootViewSibling, PR_TRUE);
5077
5078
            NS_ASSERTION(newRootView->GetNextSibling() == rootViewSibling,
5079
                         "error in InsertChild");
5080
        }
5081
    }
5082
5083
    // restore the state of the window object
5084
    nsCOMPtr<nsPIDOMWindow> privWin =
5085
        do_GetInterface(NS_STATIC_CAST(nsIInterfaceRequestor*, this));
5086
    NS_ASSERTION(privWin, "could not get nsPIDOMWindow interface");
5087
5088
    nsCOMPtr<nsISupports> windowState;
5089
    aSHEntry->GetWindowState(getter_AddRefs(windowState));
5090
5091
    rv = privWin->RestoreWindowState(windowState);
5092
    NS_ENSURE_SUCCESS(rv, rv);
5093
5094
    aSHEntry->SetWindowState(nsnull);
5095
5096
    // Restore the refresh URI list.  The refresh timers will be restarted
5097
    // when EndPageLoad() is called.
5098
    aSHEntry->GetRefreshURIList(getter_AddRefs(mRefreshURIList));
5099
    aSHEntry->SetRefreshURIList(nsnull);
5100
5101
    // Restore the page title.  Re-setting the current title on the document
5102
    // will update the docshell title and dispatch DOMTitleChanged.
5103
    nsIDocument *doc = shell->GetDocument();
5104
    nsCOMPtr<nsIDOMNSDocument> nsDoc = do_QueryInterface(doc);
5105
    if (doc && nsDoc) {
5106
        const nsAFlatString &title = doc->GetDocumentTitle();
5107
        nsDoc->SetTitle(title);
5108
    }
5109
    
5110
    mOSHE = aSHEntry;
5111
5112
    // mEODForCurrentDocument is true here, so EndPageLoad will not fire
5113
    // onload (we fire that below, in a special way so that the content window
5114
    // does not see it).
5115
    EndPageLoad(nsnull, nsnull, NS_OK);
5116
5117
    // Meta-refresh timers have been restarted for this shell, but not
5118
    // for our children.  Walk the child shells and restart their timers.
5119
    PRInt32 n = mChildList.Count();
5120
    for (i = 0; i < n; ++i) {
5121
        nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
5122
        if (child)
5123
            child->ResumeRefreshURIs();
5124
    }
5125
5126
    nsCOMPtr<nsISHistory> rootSH;
5127
    GetRootSessionHistory(getter_AddRefs(rootSH));
5128
    if (rootSH) {
5129
        nsCOMPtr<nsISHistoryInternal> hist = do_QueryInterface(rootSH);
5130
        hist->UpdateIndex();
5131
    }
5132
5133
    // Make sure this presentation is the same size as the previous
5134
    // presentation.  If this is not the same size we showed it at last time,
5135
    // then we need to resize the widget.
5136
5137
    // XXXbryner   This interacts poorly with Firefox's infobar.  If the old
5138
    // presentation had the infobar visible, then we will resize the new
5139
    // presentation to that smaller size.  However, firing the locationchanged
5140
    // event will hide the infobar, which will immediately resize the window
5141
    // back to the larger size.  A future optimization might be to restore
5142
    // the presentation at the "wrong" size, then fire the locationchanged
5143
    // event and check whether the docshell's new size is the same as the
5144
    // cached viewer size (skipping the resize if they are equal).
5145
5146
    if (newRootView) {
5147
        nsIWidget *widget = newRootView->GetWidget();
5148
        if (widget && !newBounds.IsEmpty() && newBounds != oldBounds) {
5149
#ifdef DEBUG_PAGE_CACHE
5150
            printf("resize widget(%d, %d, %d, %d)\n", newBounds.x,
5151
                   newBounds.y, newBounds.width, newBounds.height);
5152
#endif
5153
5154
            widget->Resize(newBounds.x, newBounds.y, newBounds.width,
5155
                           newBounds.height, PR_FALSE);
5156
        }
5157
    }
5158
5159
    // Reset the security state
5160
    if (mSecurityUI) {
5161
        nsCOMPtr<nsISupports> securityState;
5162
        aSHEntry->GetSecurityState(getter_AddRefs(securityState));
5163
        if (securityState)
5164
            mSecurityUI->TransitionToState(securityState);
5165
    }
5166
5167
    SetCurrentURI(uri);
5168
5169
    // Dispatch onload and DOMPageRestore.
5170
    rv = FireRestoreEvents();
5171
    NS_ENSURE_SUCCESS(rv, rv);
5172
5173
    rv = mContentViewer->Show();
5174
    NS_ENSURE_SUCCESS(rv, rv);
5175
5176
    // Restart plugins
5177
    if (shell)
5178
        shell->Thaw();
5179
5180
    // XXXbryner  Making this invalidate synchronous causes unpainted areas
5181
    // (on Mac, at least) if the above locationchanged event hides Firefox's
5182
    // infobar.  Doing it asynchronously seems to work around the problem, but
5183
    // shouldn't the style change that hides the infobar handle all necessary
5184
    // invalidation, including the newly-exposed area?
5185
5186
    rv = mParentWidget->Invalidate(PR_FALSE);
5187
    NS_ENSURE_SUCCESS(rv, rv);
5188
5189
    *aRestored = PR_TRUE;
5190
    return NS_OK;
5191
}
5192
4700
NS_IMETHODIMP
5193
NS_IMETHODIMP
4701
nsDocShell::CreateContentViewer(const char *aContentType,
5194
nsDocShell::CreateContentViewer(const char *aContentType,
4702
                                nsIRequest * request,
5195
                                nsIRequest * request,
 Lines 4723-4729   nsDocShell::CreateContentViewer(const ch Link Here 
4723
    // is changed within the DocShell - otherwise, javascript will get the
5216
    // is changed within the DocShell - otherwise, javascript will get the
4724
    // wrong information :-(
5217
    // wrong information :-(
4725
    //
5218
    //
4726
    (void) FireUnloadNotification();
5219
5220
    PRBool savePresentation = CanSavePresentation(request);
5221
    if (!savePresentation)
5222
        FireUnloadNotification();
4727
5223
4728
    // Set mFiredUnloadEvent = PR_FALSE so that the unload handler for the
5224
    // Set mFiredUnloadEvent = PR_FALSE so that the unload handler for the
4729
    // *new* document will fire.
5225
    // *new* document will fire.
 Lines 4738-4743   nsDocShell::CreateContentViewer(const ch Link Here 
4738
5234
4739
    PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE);
5235
    PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE);
4740
5236
5237
    if (savePresentation) {
5238
        // The old content viewer will be saved during the call to Embed().
5239
        rv = CaptureState();
5240
        if (NS_SUCCEEDED(rv)) {
5241
            mSavingOldViewer = PR_TRUE;
5242
        } else {
5243
            if (mOSHE) {
5244
                mOSHE->SyncPresentationState();
5245
            }
5246
        }
5247
    }
5248
4741
    // let's try resetting the load group if we need to...
5249
    // let's try resetting the load group if we need to...
4742
    nsCOMPtr<nsILoadGroup> currentLoadGroup;
5250
    nsCOMPtr<nsILoadGroup> currentLoadGroup;
4743
    NS_ENSURE_SUCCESS(aOpenedChannel->
5251
    NS_ENSURE_SUCCESS(aOpenedChannel->
 Lines 4779-4784   nsDocShell::CreateContentViewer(const ch Link Here 
4779
    NS_ENSURE_SUCCESS(Embed(viewer, "", (nsISupports *) nsnull),
5287
    NS_ENSURE_SUCCESS(Embed(viewer, "", (nsISupports *) nsnull),
4780
                      NS_ERROR_FAILURE);
5288
                      NS_ERROR_FAILURE);
4781
5289
5290
    mSavingOldViewer = PR_FALSE;
4782
    mEODForCurrentDocument = PR_FALSE;
5291
    mEODForCurrentDocument = PR_FALSE;
4783
5292
4784
    // if this document is part of a multipart document,
5293
    // if this document is part of a multipart document,
 Lines 5028-5033   nsDocShell::SetupNewViewer(nsIContentVie Link Here 
5028
5537
5029
        mContentViewer->Close();
5538
        mContentViewer->Close();
5030
        aNewViewer->SetPreviousViewer(mContentViewer);
5539
        aNewViewer->SetPreviousViewer(mContentViewer);
5540
5541
        if (mSavingOldViewer) {
5542
            // Tell the old content viewer to hibernate in session history when
5543
            // it is destroyed.
5544
            mContentViewer->SetHistoryEntry(mOSHE);
5545
        }
5546
5031
        mContentViewer = nsnull;
5547
        mContentViewer = nsnull;
5032
    }
5548
    }
5033
5549
 Lines 5568-5574   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5568
                NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
6084
                NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
5569
                nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
6085
                nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
5570
                if (shEntry)
6086
                if (shEntry)
5571
                    shEntry->SetTitle(mTitle.get());
6087
                    shEntry->SetTitle(mTitle);
5572
            }
6088
            }
5573
6089
5574
            return NS_OK;
6090
            return NS_OK;
 Lines 5588-5593   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5588
        }
6104
        }
5589
    }
6105
    }
5590
6106
6107
    // Check for saving the presentation here, before calling Stop().
6108
    // This is necessary so that we can catch any pending requests.
6109
    // Since the new request has not been created yet, we pass null for the
6110
    // new request parameter.
6111
    PRBool savePresentation = CanSavePresentation(nsnull);
6112
5591
    // Don't stop current network activity for javascript: URL's since
6113
    // Don't stop current network activity for javascript: URL's since
5592
    // they might not result in any data, and thus nothing should be
6114
    // 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
6115
    // stopped in those cases. In the case where they do result in
 Lines 5623-5628   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5623
    // been called.
6145
    // been called.
5624
    mLSHE = aSHEntry;
6146
    mLSHE = aSHEntry;
5625
6147
6148
    // If we have a saved content viewer in history, restore and show it now.
6149
    if (aSHEntry) {
6150
        if (savePresentation) {
6151
            rv = CaptureState();
6152
            if (NS_FAILED(rv) && mOSHE)
6153
                mOSHE->SyncPresentationState();
6154
        }
6155
6156
        nsCOMPtr<nsISHEntry> oldEntry = mOSHE;
6157
        PRBool restored;
6158
        rv = RestorePresentation(aSHEntry, savePresentation &&
6159
                                 NS_SUCCEEDED(rv), &restored);
6160
        if (restored)
6161
            return rv;
6162
6163
        // We failed to restore the presentation, so clean up.
6164
        // Both the old and new history entries could potentially be in
6165
        // an inconsistent state.
6166
        if (oldEntry)
6167
            oldEntry->SyncPresentationState();
6168
6169
        aSHEntry->SyncPresentationState();
6170
    }
6171
5626
    nsCOMPtr<nsIRequest> req;
6172
    nsCOMPtr<nsIRequest> req;
5627
    rv = DoURILoad(aURI, aReferrer,
6173
    rv = DoURILoad(aURI, aReferrer,
5628
                   !(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER),
6174
                   !(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER),
 Lines 6520-6531   nsDocShell::AddToSessionHistory(nsIURI * Link Here 
6520
    }
7066
    }
6521
7067
6522
    //Title is set in nsDocShell::SetTitle()
7068
    //Title is set in nsDocShell::SetTitle()
6523
    entry->Create(aURI,         // uri
7069
    entry->Create(aURI,              // uri
6524
                  nsnull,       // Title
7070
                  EmptyString(),     // Title
6525
                  nsnull,       // DOMDocument
7071
                  inputStream,       // Post data stream
6526
                  inputStream,  // Post data stream
7072
                  nsnull,            // LayoutHistory state
6527
                  nsnull,       // LayoutHistory state
7073
                  cacheKey,          // CacheKey
6528
                  cacheKey,     // CacheKey
6529
                  mContentTypeHint); // Content-type
7074
                  mContentTypeHint); // Content-type
6530
    entry->SetReferrerURI(referrerURI);
7075
    entry->SetReferrerURI(referrerURI);
6531
    /* If cache got a 'no-store', ask SH not to store
7076
    /* 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)) {            
7101
        if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {            
6557
            // Replace current entry in session history.
7102
            // Replace current entry in session history.
6558
            PRInt32  index = 0;   
7103
            PRInt32  index = 0;   
6559
            nsCOMPtr<nsIHistoryEntry> hEntry;
6560
            mSessionHistory->GetIndex(&index);
7104
            mSessionHistory->GetIndex(&index);
6561
            nsCOMPtr<nsISHistoryInternal>   shPrivate(do_QueryInterface(mSessionHistory));
7105
            nsCOMPtr<nsISHistoryInternal>   shPrivate(do_QueryInterface(mSessionHistory));
6562
            // Replace the current entry with the new entry
7106
            // Replace the current entry with the new entry
 Lines 6601-6610   nsDocShell::LoadHistoryEntry(nsISHEntry Link Here 
6601
    nsCAutoString contentType;
7145
    nsCAutoString contentType;
6602
7146
6603
    NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
7147
    NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
6604
    nsCOMPtr<nsIHistoryEntry> hEntry(do_QueryInterface(aEntry));
6605
    NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
6606
7148
6607
    NS_ENSURE_SUCCESS(hEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
7149
    NS_ENSURE_SUCCESS(aEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
6608
    NS_ENSURE_SUCCESS(aEntry->GetReferrerURI(getter_AddRefs(referrerURI)),
7150
    NS_ENSURE_SUCCESS(aEntry->GetReferrerURI(getter_AddRefs(referrerURI)),
6609
                      NS_ERROR_FAILURE);
7151
                      NS_ERROR_FAILURE);
6610
    NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
7152
    NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
 Lines 6699-6707   nsDocShell::CloneAndReplace(nsISHEntry * Link Here 
6699
    nsISHEntry *dest = (nsISHEntry *) nsnull;
7241
    nsISHEntry *dest = (nsISHEntry *) nsnull;
6700
    PRUint32 srcID;
7242
    PRUint32 srcID;
6701
    src->GetID(&srcID);
7243
    src->GetID(&srcID);
6702
    nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(src));
6703
7244
6704
    if (!src || !replaceEntry || !srcHE)
7245
    if (!src || !replaceEntry)
6705
        return NS_ERROR_FAILURE;
7246
        return NS_ERROR_FAILURE;
6706
7247
6707
    if (srcID == aCloneID) {
7248
    if (srcID == aCloneID) {
(-)docshell/base/nsDocShell.h (-1 / +53 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();
344
    NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI,
345
    NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI,
345
                                const PRUnichar *aURL,
346
                                const PRUnichar *aURL,
346
                                nsIChannel* aFailedChannel = nsnull);
347
                                nsIChannel* aFailedChannel = nsnull);
 Lines 395-400   protected: Link Here 
395
    PRBool SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
396
    PRBool SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
396
                         PRBool aFireOnLocationChange);
397
                         PRBool aFireOnLocationChange);
397
398
399
    // The following methods deal with saving and restoring content viewers
400
    // in session history.
401
402
    // mContentViewer points to the current content viewer associated with
403
    // this docshell.  When loading a new document, the content viewer is
404
    // either destroyed or stored into a session history entry.  To make sure
405
    // that destruction happens in a controlled fashion, a given content viewer
406
    // is always owned in exactly one of these ways:
407
    //   1) The content viewer is active and owned by a docshell's
408
    //      mContentViewer.
409
    //   2) The content viewer is still being displayed while we begin loading
410
    //      a new document.  The content viewer is owned by the _new_
411
    //      content viewer's mPreviousViewer, and has a pointer to the
412
    //      nsISHEntry where it will eventually be stored.  The content viewer
413
    //      has been close()d by the docshell, which detaches the document from
414
    //      the window object.
415
    //   3) The content viewer is cached in session history.  The nsISHEntry
416
    //      has the only owning reference to the content viewer.  The viewer
417
    //      has released its nsISHEntry pointer to prevent circular ownership.
418
    //
419
    // When restoring a content viewer from session history, open() is called
420
    // to reattach the document to the window object.  The content viewer is
421
    // then placed into mContentViewer and removed from the history entry.
422
    // (mContentViewer is put into session history as described above, if
423
    // applicable).
424
425
    // Determines whether we can safely cache the current mContentViewer in
426
    // session history.  This checks a number of factors such as cache policy,
427
    // pending requests, and unload handlers.  |aNewRequest| should be the
428
    // request for the document to be loaded in place of the current document.
429
    PRBool CanSavePresentation(nsIRequest *aNewRequest);
430
431
    // Captures the state of the supporting elements of the presentation
432
    // (the "window" object, docshell tree, meta-refresh loads, and security
433
    // state) and stores them on |mOSHE|.
434
    nsresult CaptureState();
435
436
    // Restores the presentation stored in |aSHEntry|.  The old presentation
437
    // is saved in session history if |aSavePresentation| is true.
438
    // If a presentation could be restored, |aRestored| is set to true.
439
    nsresult RestorePresentation(nsISHEntry *aSHEntry,
440
                                 PRBool aSavePresentation,
441
                                 PRBool *aRestored);
442
398
protected:
443
protected:
399
    // Override the parent setter from nsDocLoader
444
    // Override the parent setter from nsDocLoader
400
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
445
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
 Lines 426-431   protected: Link Here 
426
    // Indicates that a DocShell in this "docshell tree" is printing
471
    // Indicates that a DocShell in this "docshell tree" is printing
427
    PRPackedBool               mIsPrintingOrPP;
472
    PRPackedBool               mIsPrintingOrPP;
428
473
474
    // Indicates to SetupNewViewer() that we are in the process of saving the
475
    // presentation for mContentViewer.
476
    PRPackedBool               mSavingOldViewer;
477
429
    PRUint32                   mAppType;
478
    PRUint32                   mAppType;
430
479
431
    // Offset in the parent's child list.
480
    // Offset in the parent's child list.
 Lines 474-479   protected: Link Here 
474
    // Transferable hooks/callbacks
523
    // Transferable hooks/callbacks
475
    nsCOMPtr<nsIClipboardDragDropHookList>  mTransferableHookData;
524
    nsCOMPtr<nsIClipboardDragDropHookList>  mTransferableHookData;
476
525
526
    // Secure browser UI object
527
    nsCOMPtr<nsISecureBrowserUI> mSecurityUI;
528
477
    // WEAK REFERENCES BELOW HERE.
529
    // WEAK REFERENCES BELOW HERE.
478
    // Note these are intentionally not addrefd.  Doing so will create a cycle.
530
    // Note these are intentionally not addrefd.  Doing so will create a cycle.
479
    // For that reasons don't use nsCOMPtr.
531
    // 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 (-1 / +32 lines)
Line     Link Here 
 Lines 64-71   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(b0228925-9242-467b-842f-dc739a6e478f)]
69
interface nsIDocShell : nsISupports
70
interface nsIDocShell : nsISupports
70
{
71
{
71
  /**
72
  /**
 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;
350
351
  /**
352
   * Cancel the XPCOM timers for each meta-refresh URI in this docshell,
353
   * and this docshell's children, recursively. The meta-refresh timers can be
354
   * restarted using resumeRefreshURIs().  If the timers are already suspended,
355
   * this has no effect.
356
   */
357
  void suspendRefreshURIs();
358
359
  /**
360
   * Restart the XPCOM timers for each meta-refresh URI in this docshell,
361
   * and this docshell's children, recursively.  If the timers are already
362
   * running, this has no effect.
363
   */
364
  void resumeRefreshURIs();
365
366
  /**
367
   * Fire the onload and DOMPageRestore events as part of restoring a
368
   * presentation from sessino history.  The onload event is fired starting
369
   * at the chrome event handler; the DOMPageRestore event is fired starting
370
   * at the window object.  This first recurses into child docshells so that
371
   * events fire in a bottom-up order.
372
   */
373
  void fireRestoreEvents();
343
};
374
};
344
375
(-)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 / +392 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 "nsInt64.h"
156
157
157
// used for popup blocking, needs to be converted to something
158
// used for popup blocking, needs to be converted to something
158
// belonging to the back-end like nsIContentPolicy
159
// belonging to the back-end like nsIContentPolicy
 Lines 171-176   static PRInt32 gRunningTime Link Here 
171
PRInt32 gTimeoutCnt                                    = 0;
172
PRInt32 gTimeoutCnt                                    = 0;
172
#endif
173
#endif
173
174
175
#ifdef DEBUG_bryner
176
#define DEBUG_PAGE_CACHE
177
#endif
178
174
#define DOM_MIN_TIMEOUT_VALUE 10 // 10ms
179
#define DOM_MIN_TIMEOUT_VALUE 10 // 10ms
175
180
176
// CIDs
181
// CIDs
 Lines 4301-4310   nsGlobalWindow::GetPrivateRoot() Link Here 
4301
    nsIDocument* doc = chromeElement->GetDocument();
4306
    nsIDocument* doc = chromeElement->GetDocument();
4302
    if (doc) {
4307
    if (doc) {
4303
      parent = do_QueryInterface(doc->GetScriptGlobalObject());
4308
      parent = do_QueryInterface(doc->GetScriptGlobalObject());
4304
      nsCOMPtr<nsIDOMWindow> tempParent;
4309
      if (parent) {
4305
      parent->GetTop(getter_AddRefs(tempParent));
4310
        nsCOMPtr<nsIDOMWindow> tempParent;
4306
      return NS_STATIC_CAST(nsGlobalWindow *,
4311
        parent->GetTop(getter_AddRefs(tempParent));
4307
                            NS_STATIC_CAST(nsIDOMWindow*, tempParent));
4312
        return NS_STATIC_CAST(nsGlobalWindow *,
4313
                              NS_STATIC_CAST(nsIDOMWindow*, tempParent));
4314
      }
4308
    }
4315
    }
4309
  }
4316
  }
4310
4317
 Lines 5797-5802   nsGlobalWindow::EnsureSizeUpToDate() Link Here 
5797
  }
5804
  }
5798
}
5805
}
5799
5806
5807
#define WINDOWSTATEHOLDER_IID \
5808
{0xae1c7401, 0xcdee, 0x404a, {0xbd, 0x63, 0x05, 0xc0, 0x35, 0x0d, 0xa7, 0x72}}
5809
5810
class WindowStateHolder : public nsISupports
5811
{
5812
public:
5813
  NS_DEFINE_STATIC_IID_ACCESSOR(WINDOWSTATEHOLDER_IID)
5814
  NS_DECL_ISUPPORTS
5815
5816
  WindowStateHolder(JSContext *cx,  // The JSContext for the window 
5817
                    JSObject *aObject, // An object to save the properties onto
5818
                    nsGlobalWindow *aWindow); // The window to operate on
5819
5820
  // This is the property store object that holds the window properties.
5821
  JSObject* GetObject() { return mJSObj; }
5822
5823
  // Get the listener manager, which holds all event handlers for the window.
5824
  nsIEventListenerManager* GetListenerManager() { return mListenerManager; }
5825
5826
  // Get the contents of focus memory when the state was saved
5827
  // (if the focus was inside of this window).
5828
  nsIDOMElement* GetFocusedElement() { return mFocusedElement; }
5829
  nsIDOMWindowInternal* GetFocusedWindow() { return mFocusedWindow; }
5830
5831
  // Manage the list of saved timeouts for the window.
5832
  nsTimeout* GetSavedTimeouts() { return mSavedTimeouts; }
5833
  nsTimeout** GetTimeoutInsertionPoint() { return mTimeoutInsertionPoint; }
5834
  void ClearSavedTimeouts() { mSavedTimeouts = nsnull; }
5835
5836
private:
5837
  ~WindowStateHolder();
5838
5839
  JSRuntime *mRuntime;
5840
  JSObject *mJSObj;
5841
  nsCOMPtr<nsIEventListenerManager> mListenerManager;
5842
  nsCOMPtr<nsIDOMElement> mFocusedElement;
5843
  nsCOMPtr<nsIDOMWindowInternal> mFocusedWindow;
5844
  nsTimeout *mSavedTimeouts;
5845
  nsTimeout **mTimeoutInsertionPoint;
5846
};
5847
5848
WindowStateHolder::WindowStateHolder(JSContext *cx, JSObject *aObject,
5849
                                     nsGlobalWindow *aWindow)
5850
  : mRuntime(::JS_GetRuntime(cx)), mJSObj(aObject)
5851
{
5852
  NS_ASSERTION(aWindow, "null window");
5853
5854
  aWindow->GetListenerManager(getter_AddRefs(mListenerManager));
5855
5856
  nsIFocusController *fc = aWindow->GetRootFocusController();
5857
  NS_ASSERTION(fc, "null focus controller");
5858
5859
  // We want to save the focused element/window only if they are inside of
5860
  // this window.
5861
5862
  nsCOMPtr<nsIDOMWindowInternal> focusWinInternal;
5863
  fc->GetFocusedWindow(getter_AddRefs(focusWinInternal));
5864
5865
  nsCOMPtr<nsPIDOMWindow> focusedWindow = do_QueryInterface(focusWinInternal);
5866
5867
  while (focusedWindow) {
5868
    if (focusedWindow == aWindow) {
5869
      fc->GetFocusedWindow(getter_AddRefs(mFocusedWindow));
5870
      fc->GetFocusedElement(getter_AddRefs(mFocusedElement));
5871
      break;
5872
    }
5873
5874
    focusedWindow =
5875
      NS_STATIC_CAST(nsGlobalWindow*,
5876
                     NS_STATIC_CAST(nsPIDOMWindow*,
5877
                                    focusedWindow))->GetPrivateParent();
5878
  }
5879
5880
  aWindow->SuspendTimeouts();
5881
5882
  // Clear the timeout list for aWindow (but we don't need to for children)
5883
  mSavedTimeouts = aWindow->mTimeouts;
5884
  mTimeoutInsertionPoint = aWindow->mTimeoutInsertionPoint;
5885
5886
  aWindow->mTimeouts = nsnull;
5887
  aWindow->mTimeoutInsertionPoint = &aWindow->mTimeouts;
5888
5889
  ::JS_AddNamedRoot(cx, &mJSObj, "WindowStateHolder::mJSObj");
5890
}
5891
5892
WindowStateHolder::~WindowStateHolder()
5893
{
5894
  ::JS_RemoveRootRT(mRuntime, &mJSObj);
5895
}
5896
5897
NS_IMPL_ISUPPORTS1(WindowStateHolder, WindowStateHolder)
5898
5899
static JSClass sWindowStateClass = {
5900
  "window state", 0,
5901
  JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
5902
  JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
5903
  JSCLASS_NO_OPTIONAL_MEMBERS
5904
};
5905
5906
static nsresult
5907
CopyJSPropertyArray(JSContext *cx, JSObject *aSource, JSObject *aDest,
5908
                    JSIdArray *props)
5909
{
5910
  jsint length = props->length;
5911
  for (jsint i = 0; i < length; ++i) {
5912
    jsval propname_value;
5913
5914
    if (!::JS_IdToValue(cx, props->vector[i], &propname_value) ||
5915
        !JSVAL_IS_STRING(propname_value)) {
5916
      NS_WARNING("Failed to copy non-string-named window property");
5917
      return NS_ERROR_FAILURE;
5918
    }
5919
5920
    JSString *propname = JSVAL_TO_STRING(propname_value);
5921
    jschar *propname_str = ::JS_GetStringChars(propname);
5922
    NS_ENSURE_TRUE(propname_str, NS_ERROR_FAILURE);
5923
5924
    // We exclude the "location" property because restoring it this way is
5925
    // problematic.  It will "just work" without us explicitly saving or
5926
    // restoring the value.
5927
5928
    if (!nsCRT::strcmp(NS_STATIC_CAST(PRUnichar*, propname_str),
5929
                       NS_LITERAL_STRING("location").get())) {
5930
      continue;
5931
    }
5932
5933
    size_t propname_len = ::JS_GetStringLength(propname);
5934
5935
    JSPropertyOp getter, setter;
5936
    uintN attrs;
5937
    JSBool found;
5938
    if (!::JS_GetUCPropertyAttrsGetterAndSetter(cx, aSource, propname_str,
5939
                                                propname_len, &attrs, &found,
5940
                                                &getter, &setter))
5941
      return NS_ERROR_FAILURE;
5942
5943
    NS_ENSURE_TRUE(found, NS_ERROR_UNEXPECTED);
5944
5945
    jsval propvalue;
5946
    if (!::JS_LookupUCProperty(cx, aSource, propname_str,
5947
                               propname_len, &propvalue))
5948
      return NS_ERROR_FAILURE;
5949
5950
    PRBool res = ::JS_DefineUCProperty(cx, aDest, propname_str, propname_len,
5951
                                       propvalue, getter, setter, attrs);
5952
#ifdef DEBUG_PAGE_CACHE
5953
    if (res)
5954
      printf("Copied window property: %s\n",
5955
             NS_ConvertUTF16toUTF8(NS_STATIC_CAST(PRUnichar*,
5956
                                                  propname_str)).get());
5957
#endif
5958
5959
    if (!res) {
5960
#ifdef DEBUG
5961
      printf("failed to copy property: %s\n",
5962
             NS_ConvertUTF16toUTF8(NS_STATIC_CAST(PRUnichar*,
5963
                                                  propname_str)).get());
5964
#endif
5965
      return NS_ERROR_FAILURE;
5966
    }
5967
  }
5968
5969
  return NS_OK;
5970
}
5971
5972
static nsresult
5973
CopyJSProperties(JSContext *cx, JSObject *aSource, JSObject *aDest)
5974
{
5975
  // Enumerate all of the properties on aSource and install them on aDest.
5976
5977
  JSIdArray *props = ::JS_Enumerate(cx, aSource);
5978
  if (!props) {
5979
#ifdef DEBUG_PAGE_CACHE
5980
    printf("[no properties]\n");
5981
#endif
5982
    return NS_OK;
5983
  }
5984
5985
#ifdef DEBUG_PAGE_CACHE
5986
  printf("props length = %d\n", props->length);
5987
#endif
5988
5989
  nsresult rv = CopyJSPropertyArray(cx, aSource, aDest, props);
5990
  ::JS_DestroyIdArray(cx, props);
5991
  return rv;
5992
}
5993
5994
nsresult
5995
nsGlobalWindow::SaveWindowState(nsISupports **aState)
5996
{
5997
  *aState = nsnull;
5998
5999
  if (!mContext || !mJSObject) {
6000
    // The window may be getting torn down; don't bother saving state.
6001
    return NS_OK;
6002
  }
6003
6004
  JSContext *cx = NS_STATIC_CAST(JSContext*, mContext->GetNativeContext());
6005
  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
6006
6007
  JSObject *stateObj = ::JS_NewObject(cx, &sWindowStateClass, NULL, NULL);
6008
  NS_ENSURE_TRUE(stateObj, NS_ERROR_OUT_OF_MEMORY);
6009
6010
  // The window state object will root the JSObject.
6011
  *aState = new WindowStateHolder(cx, stateObj, this);
6012
  NS_ENSURE_TRUE(*aState, NS_ERROR_OUT_OF_MEMORY);
6013
6014
#ifdef DEBUG_PAGE_CACHE
6015
  printf("saving window state, stateObj = %p\n", stateObj);
6016
#endif
6017
  nsresult rv = CopyJSProperties(cx, mJSObject, stateObj);
6018
  NS_ENSURE_SUCCESS(rv, rv);
6019
6020
  NS_ADDREF(*aState);
6021
  return NS_OK;
6022
}
6023
6024
nsresult
6025
nsGlobalWindow::RestoreWindowState(nsISupports *aState)
6026
{
6027
  if (!mContext || !mJSObject) {
6028
    // The window may be getting torn down; don't bother restoring state.
6029
    return NS_OK;
6030
  }
6031
6032
  JSContext *cx = NS_STATIC_CAST(JSContext*, mContext->GetNativeContext());
6033
  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
6034
6035
  // Note that we don't need to call JS_ClearScope here.  The scope is already
6036
  // cleared by SetNewDocument(), and calling it again here would remove the
6037
  // XPConnect properties.
6038
6039
  nsCOMPtr<WindowStateHolder> holder = do_QueryInterface(aState);
6040
  NS_ENSURE_TRUE(holder, NS_ERROR_FAILURE);
6041
6042
#ifdef DEBUG_PAGE_CACHE
6043
  printf("restoring window state, stateObj = %p\n", holder->GetObject());
6044
#endif
6045
  nsresult rv = CopyJSProperties(cx, holder->GetObject(), mJSObject);
6046
  NS_ENSURE_SUCCESS(rv, rv);
6047
6048
  mListenerManager = holder->GetListenerManager();
6049
6050
  nsIDOMElement *focusedElement = holder->GetFocusedElement();
6051
  nsIDOMWindowInternal *focusedWindow = holder->GetFocusedWindow();
6052
6053
  // If the toplevel window isn't focused, just update the focus controller.
6054
  nsIFocusController *fc = nsGlobalWindow::GetRootFocusController();
6055
  NS_ENSURE_TRUE(fc, NS_ERROR_UNEXPECTED);
6056
6057
  PRBool active;
6058
  fc->GetActive(&active);
6059
  if (active) {
6060
    PRBool didFocusContent = PR_FALSE;
6061
    nsCOMPtr<nsIContent> focusedContent = do_QueryInterface(focusedElement);
6062
6063
    if (focusedContent) {
6064
      // We don't bother checking whether the element or frame is focusable.
6065
      // If it was focusable when we stored the presentation, it must be
6066
      // focusable now.
6067
      PRBool didFocusContent = PR_FALSE;
6068
      nsIDocument *doc = focusedContent->GetCurrentDoc();
6069
      if (doc) {
6070
        nsIPresShell *shell = doc->GetShellAt(0);
6071
        if (shell) {
6072
          nsPresContext *pc = shell->GetPresContext();
6073
          if (pc) {
6074
            pc->EventStateManager()->SetContentState(focusedContent,
6075
                                                     NS_EVENT_STATE_FOCUS);
6076
            didFocusContent = PR_TRUE;
6077
          }
6078
        }
6079
      }
6080
    }
6081
6082
    if (!didFocusContent && focusedWindow)
6083
      focusedWindow->Focus();
6084
  } else if (focusedWindow) {
6085
    // Just update the saved focus memory.
6086
    fc->SetFocusedWindow(focusedWindow);
6087
    fc->SetFocusedElement(focusedElement);
6088
  }
6089
6090
  mTimeouts = holder->GetSavedTimeouts();
6091
  mTimeoutInsertionPoint = holder->GetTimeoutInsertionPoint();
6092
6093
  holder->ClearSavedTimeouts();
6094
6095
  // If our state is being restored from history, we won't be getting an onload
6096
  // event.  Make sure we're marked as being completely loaded.
6097
  mIsDocumentLoaded = PR_TRUE;
6098
6099
  return ResumeTimeouts();
6100
}
6101
6102
void
6103
nsGlobalWindow::SuspendTimeouts()
6104
{
6105
  nsInt64 now = PR_IntervalNow();
6106
  for (nsTimeout *t = mTimeouts; t; t = t->mNext) {
6107
    // Change mWhen to be the time remaining for this timer.
6108
    t->mWhen = PR_MAX(nsInt64(0), nsInt64(t->mWhen) - now);
6109
6110
    // Drop the XPCOM timer; we'll reschedule when restoring the state.
6111
    if (t->mTimer) {
6112
      t->mTimer->Cancel();
6113
      t->mTimer = nsnull;
6114
    }
6115
6116
    // We don't Release() the timeout because we still need it.
6117
  }
6118
6119
  // Suspend our children as well.
6120
  nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(mDocShell);
6121
  if (node) {
6122
    PRInt32 childCount = 0;
6123
    node->GetChildCount(&childCount);
6124
6125
    for (PRInt32 i = 0; i < childCount; ++i) {
6126
      nsCOMPtr<nsIDocShellTreeItem> childShell;
6127
      node->GetChildAt(i, getter_AddRefs(childShell));
6128
      NS_ASSERTION(childShell, "null child shell");
6129
6130
      nsCOMPtr<nsPIDOMWindow> pWin = do_GetInterface(childShell);
6131
      if (pWin) {
6132
        nsGlobalWindow *win =
6133
          NS_STATIC_CAST(nsGlobalWindow*,
6134
                         NS_STATIC_CAST(nsPIDOMWindow*, pWin));
6135
6136
        win->SuspendTimeouts();
6137
      }
6138
    }
6139
  }
6140
}
6141
6142
nsresult
6143
nsGlobalWindow::ResumeTimeouts()
6144
{
6145
  // Restore all of the timeouts, using the stored time remaining.
6146
6147
  nsInt64 now = PR_IntervalNow();
6148
  nsresult rv;
6149
6150
  for (nsTimeout *t = mTimeouts; t; t = t->mNext) {
6151
    PRInt32 interval = PR_MAX(t->mWhen, DOM_MIN_TIMEOUT_VALUE);
6152
    t->mWhen = now + nsInt64(t->mWhen);
6153
6154
    t->mTimer = do_CreateInstance("@mozilla.org/timer;1");
6155
    NS_ENSURE_TRUE(t->mTimer, NS_ERROR_OUT_OF_MEMORY);
6156
6157
    rv = t->mTimer->InitWithFuncCallback(TimerCallback, t, interval,
6158
                                         nsITimer::TYPE_ONE_SHOT);
6159
    NS_ENSURE_SUCCESS(rv, rv);
6160
  }
6161
6162
  // Resume our children as well.
6163
  nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(mDocShell);
6164
  if (node) {
6165
    PRInt32 childCount = 0;
6166
    node->GetChildCount(&childCount);
6167
6168
    for (PRInt32 i = 0; i < childCount; ++i) {
6169
      nsCOMPtr<nsIDocShellTreeItem> childShell;
6170
      node->GetChildAt(i, getter_AddRefs(childShell));
6171
      NS_ASSERTION(childShell, "null child shell");
6172
6173
      nsCOMPtr<nsPIDOMWindow> pWin = do_GetInterface(childShell);
6174
      if (pWin) {
6175
        nsGlobalWindow *win =
6176
          NS_STATIC_CAST(nsGlobalWindow*,
6177
                         NS_STATIC_CAST(nsPIDOMWindow*, pWin));
6178
6179
        rv = win->ResumeTimeouts();
6180
        NS_ENSURE_SUCCESS(rv, rv);
6181
      }
6182
    }
6183
  }
6184
6185
  return NS_OK;
6186
}
6187
5800
// QueryInterface implementation for nsGlobalChromeWindow
6188
// QueryInterface implementation for nsGlobalChromeWindow
5801
NS_INTERFACE_MAP_BEGIN(nsGlobalChromeWindow)
6189
NS_INTERFACE_MAP_BEGIN(nsGlobalChromeWindow)
5802
  NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow)
6190
  NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow)
(-)dom/src/base/nsGlobalWindow.h (+8 lines)
Line     Link Here 
 Lines 105-110   class nsNavigator; Link Here 
105
class nsScreen;
105
class nsScreen;
106
class nsHistory;
106
class nsHistory;
107
class nsIDocShellLoadInfo;
107
class nsIDocShellLoadInfo;
108
class WindowStateHolder;
108
109
109
//*****************************************************************************
110
//*****************************************************************************
110
// nsGlobalWindow: Global Object for Scripting
111
// nsGlobalWindow: Global Object for Scripting
 Lines 204-209   public: Link Here 
204
  virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
205
  virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
205
206
206
  virtual NS_HIDDEN_(void) ClearAllTimeouts();
207
  virtual NS_HIDDEN_(void) ClearAllTimeouts();
208
  virtual NS_HIDDEN_(nsresult) SaveWindowState(nsISupports **aState);
209
  virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState);
207
  
210
  
208
  // nsIDOMViewCSS
211
  // nsIDOMViewCSS
209
  NS_DECL_NSIDOMVIEWCSS
212
  NS_DECL_NSIDOMVIEWCSS
 Lines 220-225   public: Link Here 
220
  static void ShutDown();
223
  static void ShutDown();
221
  static PRBool IsCallerChrome();
224
  static PRBool IsCallerChrome();
222
225
226
  friend class WindowStateHolder;
227
223
protected:
228
protected:
224
  // Object Management
229
  // Object Management
225
  virtual ~nsGlobalWindow();
230
  virtual ~nsGlobalWindow();
 Lines 304-309   protected: Link Here 
304
309
305
  already_AddRefed<nsIWidget> GetMainWidget();
310
  already_AddRefed<nsIWidget> GetMainWidget();
306
311
312
  void SuspendTimeouts();
313
  nsresult ResumeTimeouts();
314
307
  // When adding new member variables, be careful not to create cycles
315
  // When adding new member variables, be careful not to create cycles
308
  // through JavaScript.  If there is any chance that a member variable
316
  // through JavaScript.  If there is any chance that a member variable
309
  // could own objects that are implemented in JavaScript, then those
317
  // could own objects that are implemented in JavaScript, then those
(-)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 1743-1748   nsXMLHttpRequest::Error(nsIDOMEvent* aEv Link Here 
1743
  return NS_OK;
1743
  return NS_OK;
1744
}
1744
}
1745
1745
1746
NS_IMETHODIMP
1747
nsXMLHttpRequest::PageRestore(nsIDOMEvent* aEvent)
1748
{
1749
  return NS_OK;
1750
}
1751
1746
nsresult
1752
nsresult
1747
nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast,
1753
nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast,
1748
                              PRBool aClearEventListeners)
1754
                              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 (-85 / +184 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
#include "nsISHistory.h"
193
#include "nsISHistoryInternal.h"
194
#include "nsIWebNavigation.h"
192
195
193
//paint forcing
196
//paint forcing
194
#include "prenv.h"
197
#include "prenv.h"
 Lines 346-352   protected: Link Here 
346
  virtual ~DocumentViewerImpl();
349
  virtual ~DocumentViewerImpl();
347
350
348
private:
351
private:
349
  void ForceRefresh(void);
350
  nsresult MakeWindow(nsIWidget* aParentWidget,
352
  nsresult MakeWindow(nsIWidget* aParentWidget,
351
                      const nsRect& aBounds);
353
                      const nsRect& aBounds);
352
  nsresult InitInternal(nsIWidget* aParentWidget,
354
  nsresult InitInternal(nsIWidget* aParentWidget,
 Lines 398-427   protected: Link Here 
398
  nsCOMPtr<nsIDOMFocusListener> mFocusListener;
400
  nsCOMPtr<nsIDOMFocusListener> mFocusListener;
399
401
400
  nsCOMPtr<nsIContentViewer> mPreviousViewer;
402
  nsCOMPtr<nsIContentViewer> mPreviousViewer;
401
403
  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
404
409
  nsIWidget* mParentWidget;          // purposely won't be ref counted
405
  nsIWidget* mParentWidget;          // purposely won't be ref counted
410
406
411
  PRPackedBool         mInPermitUnload;
407
  PRInt16 mNumURLStarts;
408
  PRInt16 mDestroyRefCount;    // a second "refcount" for the document viewer's "destroy"
409
410
  unsigned      mEnableRendering : 1;
411
  unsigned      mStopped : 1;
412
  unsigned      mLoaded : 1;
413
  unsigned      mDeferredWindowClose : 1;
414
  // document management data
415
  //   these items are specific to markup documents (html and xml)
416
  //   may consider splitting these out into a subclass
417
  unsigned      mIsSticky : 1;
418
  unsigned      mInPermitUnload : 1;
412
419
413
#ifdef NS_PRINTING
420
#ifdef NS_PRINTING
414
  PRPackedBool          mClosingWhilePrinting;
421
  unsigned      mClosingWhilePrinting : 1;
415
  nsPrintEngine*        mPrintEngine;
422
416
  nsCOMPtr<nsIDOMWindowInternal> mDialogParentWin;
417
#if NS_PRINT_PREVIEW
423
#if NS_PRINT_PREVIEW
418
  // These data member support delayed printing when the document is loading
424
  // These data members support delayed printing when the document is loading
425
  unsigned                         mPrintIsPending : 1;
426
  unsigned                         mPrintDocIsFullyLoaded : 1;
419
  nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
427
  nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
420
  nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
428
  nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
421
  PRPackedBool                     mPrintIsPending;
422
  PRPackedBool                     mPrintDocIsFullyLoaded;
423
#endif // NS_PRINT_PREVIEW
429
#endif // NS_PRINT_PREVIEW
424
430
431
  nsPrintEngine*        mPrintEngine;
432
  nsCOMPtr<nsIDOMWindowInternal> mDialogParentWin;
433
425
#ifdef NS_DEBUG
434
#ifdef NS_DEBUG
426
  FILE* mDebugFile;
435
  FILE* mDebugFile;
427
#endif // NS_DEBUG
436
#endif // NS_DEBUG
 Lines 434-443   protected: Link Here 
434
  nsCString mForceCharacterSet;
443
  nsCString mForceCharacterSet;
435
  nsCString mPrevDocCharacterSet;
444
  nsCString mPrevDocCharacterSet;
436
  
445
  
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
446
442
};
447
};
443
448
 Lines 494-501   void DocumentViewerImpl::PrepareToStartL Link Here 
494
// Note: operator new zeros our memory, so no need to init things to null.
499
// Note: operator new zeros our memory, so no need to init things to null.
495
DocumentViewerImpl::DocumentViewerImpl(nsPresContext* aPresContext)
500
DocumentViewerImpl::DocumentViewerImpl(nsPresContext* aPresContext)
496
  : mPresContext(aPresContext),
501
  : mPresContext(aPresContext),
497
    mHintCharsetSource(kCharsetUninitialized),
502
    mIsSticky(PR_TRUE),
498
    mIsSticky(PR_TRUE)
503
    mHintCharsetSource(kCharsetUninitialized)
499
{
504
{
500
  PrepareToStartLoad();
505
  PrepareToStartLoad();
501
}
506
}
 Lines 511-519   NS_IMPL_ISUPPORTS7(DocumentViewerImpl, Link Here 
511
516
512
DocumentViewerImpl::~DocumentViewerImpl()
517
DocumentViewerImpl::~DocumentViewerImpl()
513
{
518
{
514
  NS_ASSERTION(!mDocument, "User did not call nsIContentViewer::Close");
515
  if (mDocument) {
519
  if (mDocument) {
516
    Close();
520
    Close();
521
    mDocument->Destroy();
517
  }
522
  }
518
523
519
  NS_ASSERTION(!mPresShell && !mPresContext,
524
  NS_ASSERTION(!mPresShell && !mPresContext,
 Lines 795-813   DocumentViewerImpl::InitInternal(nsIWidg Link Here 
795
      makeCX = PR_TRUE;
800
      makeCX = PR_TRUE;
796
#endif
801
#endif
797
    }
802
    }
798
  }
799
803
800
  if (aDoCreation && mPresContext) {
804
    if (mPresContext) {
801
    // Create the ViewManager and Root View...
805
      // Create the ViewManager and Root View...
802
806
803
    // We must do this before we tell the script global object about
807
      // 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
808
      // this new document since doing that will cause us to re-enter
805
    // into nsSubDocumentFrame code through reflows caused by
809
      // into nsSubDocumentFrame code through reflows caused by
806
    // FlushPendingNotifications() calls down the road...
810
      // FlushPendingNotifications() calls down the road...
807
811
808
    rv = MakeWindow(aParentWidget, aBounds);
812
      rv = MakeWindow(aParentWidget, aBounds);
809
    NS_ENSURE_SUCCESS(rv, rv);
813
      NS_ENSURE_SUCCESS(rv, rv);
810
    Hide();
814
      Hide();
815
    }
811
  }
816
  }
812
817
813
  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));
818
  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));
 Lines 1171-1176   DocumentViewerImpl::Unload() Link Here 
1171
}
1176
}
1172
1177
1173
NS_IMETHODIMP
1178
NS_IMETHODIMP
1179
DocumentViewerImpl::Open()
1180
{
1181
  NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
1182
1183
  nsRect bounds;
1184
  mWindow->GetBounds(bounds);
1185
1186
  nsresult rv = InitInternal(mParentWidget, mDeviceContext, bounds,
1187
                             PR_FALSE, PR_FALSE);
1188
  NS_ENSURE_SUCCESS(rv, rv);
1189
1190
  if (mDocument)
1191
    mDocument->SetContainer(mContainer);
1192
1193
  SyncParentSubDocMap();
1194
1195
  // XXX re-enable image animations once that works correctly
1196
1197
  return NS_OK;
1198
}
1199
1200
NS_IMETHODIMP
1174
DocumentViewerImpl::Close()
1201
DocumentViewerImpl::Close()
1175
{
1202
{
1176
  // All callers are supposed to call close to break circular
1203
  // 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
1211
  // for an object that can be switched in and out so that we don't need
1185
  // to disable scripts during paint suppression.
1212
  // to disable scripts during paint suppression.
1186
1213
1187
  if (mDocument) {
1214
  if (!mDocument)
1215
    return NS_OK;
1216
1188
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
1217
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
1189
    // Turn scripting back on
1218
  // Turn scripting back on
1190
    // after PrintPreview had turned it off
1219
  // after PrintPreview had turned it off
1191
    if (GetIsPrintPreview() && mPrintEngine) {
1220
  if (GetIsPrintPreview() && mPrintEngine) {
1192
      mPrintEngine->TurnScriptingOn(PR_TRUE);
1221
    mPrintEngine->TurnScriptingOn(PR_TRUE);
1193
    }
1222
  }
1194
#endif
1223
#endif
1195
1224
1196
    // Break global object circular reference on the document created
1225
  // Break global object circular reference on the document created
1197
    // in the DocViewer Init
1226
  // in the DocViewer Init
1198
    nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();
1227
  nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();
1199
1228
1200
    if (globalObject) {
1229
  if (globalObject) {
1201
      globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);
1230
    globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);
1202
    }
1231
  }
1203
1232
1204
#ifdef NS_PRINTING
1233
#ifdef NS_PRINTING
1205
    // A Close was called while we were printing
1234
  // A Close was called while we were printing
1206
    // so don't clear the ScriptGlobalObject
1235
  // so don't clear the ScriptGlobalObject
1207
    // or clear the mDocument below
1236
  // or clear the mDocument below
1208
    // Also, do an extra addref to keep the viewer from going away.
1237
  // Also, do an extra addref to keep the viewer from going away.
1209
    if (mPrintEngine && !mClosingWhilePrinting) {
1238
  if (mPrintEngine && !mClosingWhilePrinting) {
1210
      mClosingWhilePrinting = PR_TRUE;
1239
    mClosingWhilePrinting = PR_TRUE;
1211
      NS_ADDREF_THIS();
1240
    NS_ADDREF_THIS();
1212
    } else {
1241
  } else
1242
#endif
1243
    {
1213
      // out of band cleanup of webshell
1244
      // out of band cleanup of webshell
1214
      mDocument->SetScriptGlobalObject(nsnull);
1245
      mDocument->SetScriptGlobalObject(nsnull);
1215
    }
1246
    }
1216
#else
1217
    mDocument->SetScriptGlobalObject(nsnull);
1218
#endif
1219
1247
1220
    if (mFocusListener) {
1248
  if (mFocusListener) {
1221
      // get the DOM event receiver
1249
    // get the DOM event receiver
1222
      nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
1250
    nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
1223
      NS_WARN_IF_FALSE(erP, "No event receiver in document!");
1251
    NS_WARN_IF_FALSE(erP, "No event receiver in document!");
1224
1252
1225
      if (erP) {
1253
    if (erP) {
1226
        erP->RemoveEventListenerByIID(mFocusListener,
1254
      erP->RemoveEventListenerByIID(mFocusListener,
1227
                                      NS_GET_IID(nsIDOMFocusListener));
1255
                                    NS_GET_IID(nsIDOMFocusListener));
1228
      }
1229
    }
1256
    }
1230
  }
1257
  }
1231
1258
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;
1259
  return NS_OK;
1242
}
1260
}
1243
1261
1244
NS_IMETHODIMP
1262
NS_IMETHODIMP
1245
DocumentViewerImpl::Destroy()
1263
DocumentViewerImpl::Destroy()
1246
{
1264
{
1265
  NS_ASSERTION(mDocument, "No document in Destroy()!");
1266
1247
#ifdef NS_PRINTING
1267
#ifdef NS_PRINTING
1248
  // Here is where we check to see if the docment was still being prepared 
1268
  // 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
1269
  // for printing when it was asked to be destroy from someone externally
 Lines 1258-1270   DocumentViewerImpl::Destroy() Link Here 
1258
  }
1278
  }
1259
#endif
1279
#endif
1260
1280
1261
  // Don't let the document get unloaded while we are printing
1281
  // Don't let the document get unloaded while we are printing.
1262
  // this could happen if we hit the back button during printing
1282
  // this could happen if we hit the back button during printing.
1283
  // We also keep the viewer from being cached in session history, since
1284
  // we require all documents there to be sanitized.
1263
  if (mDestroyRefCount != 0) {
1285
  if (mDestroyRefCount != 0) {
1264
    --mDestroyRefCount;
1286
    --mDestroyRefCount;
1265
    return NS_OK;
1287
    return NS_OK;
1266
  }
1288
  }
1267
1289
1290
  // If we were told to put ourselves into session history instead of destroy
1291
  // the presentation, do that now.
1292
  PRBool updateHistory = (mSHEntry != nsnull);
1293
1294
  if (mSHEntry) {
1295
    if (mPresShell)
1296
      mPresShell->Freeze();
1297
1298
    // Make sure the presentation isn't torn down by Hide().
1299
    mSHEntry->SetSticky(mIsSticky);
1300
    mIsSticky = PR_TRUE;
1301
1302
    mSHEntry->SetContentViewer(this);
1303
1304
    // Remove our root view from the view hierarchy.
1305
    if (mPresShell) {
1306
      nsIViewManager *vm = mPresShell->GetViewManager();
1307
      if (vm) {
1308
        nsIView *rootView = nsnull;
1309
        vm->GetRootView(rootView);
1310
1311
        if (rootView) {
1312
          nsIView *rootViewParent = rootView->GetParent();
1313
          if (rootViewParent) {
1314
            nsIViewManager *parentVM = rootViewParent->GetViewManager();
1315
            if (parentVM) {
1316
              parentVM->RemoveChild(rootView);
1317
            }
1318
          }
1319
        }
1320
      }
1321
    }
1322
1323
    Hide();
1324
1325
    // This is after Hide() so that the user doesn't see the inputs clear.
1326
    if (mDocument) {
1327
      nsresult rv = mDocument->Sanitize();
1328
      if (NS_FAILED(rv)) {
1329
        // If we failed to sanitize, remove the document immediately.
1330
        mSHEntry->SetContentViewer(nsnull);
1331
        mSHEntry->SyncPresentationState();
1332
      }
1333
    }
1334
1335
1336
    mSHEntry = nsnull;
1337
1338
    // If we put ourselves into session history, make sure there aren't
1339
    // too many content viewers around.  Note: if max_viewers is set to 0,
1340
    // this can reenter Destroy() and dispose of this content viewer!
1341
1342
    nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mContainer);
1343
    if (webNav) {
1344
      nsCOMPtr<nsISHistory> history;
1345
      webNav->GetSessionHistory(getter_AddRefs(history));
1346
      nsCOMPtr<nsISHistoryInternal> historyInt = do_QueryInterface(history);
1347
      if (historyInt) {
1348
        historyInt->EvictContentViewers();
1349
      }
1350
    }
1351
1352
    // Break the link from the document/presentation to the docshell, so that
1353
    // link traversals cannot affect the currently-loaded document.
1354
    // When the presentation is restored, Open() and InitInternal() will reset
1355
    // these pointers to their original values.
1356
1357
    if (mDocument)
1358
      mDocument->SetContainer(nsnull);
1359
    if (mPresContext)
1360
      mPresContext->SetLinkHandler(nsnull);
1361
1362
    return NS_OK;
1363
  }
1364
1365
  mDocument->Destroy();
1366
  mDocument = nsnull;
1367
1268
  // All callers are supposed to call destroy to break circular
1368
  // All callers are supposed to call destroy to break circular
1269
  // references.  If we do this stuff in the destructor, the
1369
  // references.  If we do this stuff in the destructor, the
1270
  // destructor might never be called (especially if we're being
1370
  // destructor might never be called (especially if we're being
 Lines 1323-1329   DocumentViewerImpl::Stop(void) Link Here 
1323
    mDocument->StopDocumentLoad();
1423
    mDocument->StopDocumentLoad();
1324
  }
1424
  }
1325
1425
1326
  if (mEnableRendering && (mLoaded || mStopped) && mPresContext)
1426
  if (mEnableRendering && (mLoaded || mStopped) && mPresContext && !mSHEntry)
1327
    mPresContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
1427
    mPresContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
1328
1428
1329
  mStopped = PR_TRUE;
1429
  mStopped = PR_TRUE;
 Lines 1669-1675   DocumentViewerImpl::Hide(void) Link Here 
1669
    return NS_OK;
1769
    return NS_OK;
1670
  }
1770
  }
1671
1771
1672
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
1673
  NS_PRECONDITION(mWindow, "null window");
1772
  NS_PRECONDITION(mWindow, "null window");
1674
  if (mWindow) {
1773
  if (mWindow) {
1675
    mWindow->Show(PR_FALSE);
1774
    mWindow->Show(PR_FALSE);
 Lines 1787-1792   DocumentViewerImpl::SetSticky(PRBool aSt Link Here 
1787
}
1886
}
1788
1887
1789
NS_IMETHODIMP
1888
NS_IMETHODIMP
1889
DocumentViewerImpl::SetHistoryEntry(nsISHEntry *aEntry)
1890
{
1891
  mSHEntry = aEntry;
1892
  return NS_OK;
1893
}
1894
1895
NS_IMETHODIMP
1790
DocumentViewerImpl::GetEnableRendering(PRBool* aResult)
1896
DocumentViewerImpl::GetEnableRendering(PRBool* aResult)
1791
{
1897
{
1792
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
1898
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
 Lines 1811-1823   DocumentViewerImpl::RequestWindowClose(P Link Here 
1811
  return NS_OK;
1917
  return NS_OK;
1812
}
1918
}
1813
1919
1814
1815
void
1816
DocumentViewerImpl::ForceRefresh()
1817
{
1818
  mWindow->Invalidate(PR_TRUE);
1819
}
1820
1821
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
1920
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
1822
1921
1823
PR_STATIC_CALLBACK(PRBool)
1922
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 / +15 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 679-684   public: Link Here 
679
679
680
  PRBool IsAccessibilityActive() { return mIsAccessibilityActive; }
680
  PRBool IsAccessibilityActive() { return mIsAccessibilityActive; }
681
681
682
  /**
683
   * Stop all active elements (plugins and the caret) in this presentation and
684
   * in the presentations of subdocuments.
685
   * XXX this should include image animations
686
   */
687
  virtual void Freeze() = 0;
688
689
  /**
690
   * Restarts active elements (plugins) in this presentation and in the
691
   * presentations of subdocuments.
692
   */
693
  virtual void Thaw() = 0;
694
682
protected:
695
protected:
683
  // IMPORTANT: The ownership implicit in the following member variables
696
  // IMPORTANT: The ownership implicit in the following member variables
684
  // has been explicitly checked.  If you add any members to this class,
697
  // 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 (+130 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"
154
157
155
// Drag & Drop, Clipboard
158
// Drag & Drop, Clipboard
156
#include "nsWidgetsCID.h"
159
#include "nsWidgetsCID.h"
 Lines 1204-1209   public: Link Here 
1204
  NS_IMETHOD IsReflowLocked(PRBool* aIsLocked);  
1207
  NS_IMETHOD IsReflowLocked(PRBool* aIsLocked);  
1205
1208
1206
  virtual nsresult ReconstructFrames(void);
1209
  virtual nsresult ReconstructFrames(void);
1210
  virtual void Freeze();
1211
  virtual void Thaw();
1207
1212
1208
#ifdef IBMBIDI
1213
#ifdef IBMBIDI
1209
  NS_IMETHOD SetCaretBidiLevel(PRUint8 aLevel);
1214
  NS_IMETHOD SetCaretBidiLevel(PRUint8 aLevel);
 Lines 1513-1518   private: Link Here 
1513
  void FireResizeEvent();
1518
  void FireResizeEvent();
1514
  static void sResizeEventCallback(nsITimer* aTimer, void* aPresShell) ;
1519
  static void sResizeEventCallback(nsITimer* aTimer, void* aPresShell) ;
1515
  nsCOMPtr<nsITimer> mResizeEventTimer;
1520
  nsCOMPtr<nsITimer> mResizeEventTimer;
1521
1522
  typedef void (*nsPluginEnumCallback)(PresShell*, nsIContent*);
1523
  void EnumeratePlugins(nsIDOMDocument *aDocument,
1524
                        const nsString &aPluginTag,
1525
                        nsPluginEnumCallback aCallback);
1516
};
1526
};
1517
1527
1518
#ifdef PR_LOGGING
1528
#ifdef PR_LOGGING
 Lines 6482-6487   PresShell::RemoveOverrideStyleSheet(nsIS Link Here 
6482
  return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
6492
  return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
6483
}
6493
}
6484
6494
6495
static void
6496
StopPluginInstance(PresShell *aShell, nsIContent *aContent)
6497
{
6498
  nsIFrame *frame = aShell->FrameManager()->GetPrimaryFrameFor(aContent);
6499
6500
  nsIObjectFrame *objectFrame = nsnull;
6501
  if (frame)
6502
    CallQueryInterface(frame, &objectFrame);
6503
  if (!objectFrame)
6504
    return;
6505
6506
  nsCOMPtr<nsIPluginInstance> instance;
6507
  objectFrame->GetPluginInstance(*getter_AddRefs(instance));
6508
  if (!instance)
6509
    return;
6510
6511
  // Check whether the plugin wants SetWindow to be called before or after
6512
  // Stop/Destroy.  This is similar to nsObjectFrame::Destroy(), but we
6513
  // don't want to destroy the frame just yet.
6514
6515
  PRBool callSetWindowLast = PR_FALSE;
6516
  instance->GetValue(nsPluginInstanceVariable_CallSetWindowAfterDestroyBool,
6517
                     (void *) &callSetWindowLast);
6518
  if (callSetWindowLast) {
6519
    instance->Stop();
6520
    instance->Destroy();
6521
    instance->SetWindow(nsnull);
6522
  } else {
6523
    instance->SetWindow(nsnull);
6524
    instance->Stop();
6525
    instance->Destroy();
6526
  }
6527
6528
  nsCOMPtr<nsIPluginHost> pluginHost =
6529
    do_GetService("@mozilla.org/plugin/host;1");
6530
  if (pluginHost)
6531
    pluginHost->StopPluginInstance(instance);
6532
}
6533
6534
PR_STATIC_CALLBACK(PRBool)
6535
FreezeSubDocument(nsIDocument *aDocument, void *aData)
6536
{
6537
  nsIPresShell *shell = aDocument->GetShellAt(0);
6538
  if (shell)
6539
    shell->Freeze();
6540
6541
  return PR_TRUE;
6542
}
6543
6544
void
6545
PresShell::Freeze()
6546
{
6547
  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
6548
  if (domDoc) {
6549
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("object"), StopPluginInstance);
6550
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("applet"), StopPluginInstance);
6551
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("embed"), StopPluginInstance);
6552
  }
6553
6554
  if (mCaret)
6555
    mCaret->SetCaretVisible(PR_FALSE);
6556
6557
  if (mDocument)
6558
    mDocument->EnumerateSubDocuments(FreezeSubDocument, nsnull);
6559
}
6560
6561
static void
6562
StartPluginInstance(PresShell *aShell, nsIContent *aContent)
6563
{
6564
  // For now we just reconstruct the frame.
6565
  aShell->RecreateFramesFor(aContent);
6566
}
6567
6568
PR_STATIC_CALLBACK(PRBool)
6569
ThawSubDocument(nsIDocument *aDocument, void *aData)
6570
{
6571
  nsIPresShell *shell = aDocument->GetShellAt(0);
6572
  if (shell)
6573
    shell->Thaw();
6574
6575
  return PR_TRUE;
6576
}
6577
6578
void
6579
PresShell::Thaw()
6580
{
6581
  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
6582
  if (domDoc) {
6583
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("object"), StartPluginInstance);
6584
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("applet"), StartPluginInstance);
6585
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("embed"), StartPluginInstance);
6586
  }
6587
6588
  if (mDocument)
6589
    mDocument->EnumerateSubDocuments(ThawSubDocument, nsnull);
6590
}
6591
6485
//--------------------------------------------------------
6592
//--------------------------------------------------------
6486
// Start of protected and private methods on the PresShell
6593
// Start of protected and private methods on the PresShell
6487
//--------------------------------------------------------
6594
//--------------------------------------------------------
 Lines 7050-7055   PresShell::Observe(nsISupports* aSubject Link Here 
7050
  return NS_ERROR_FAILURE;
7157
  return NS_ERROR_FAILURE;
7051
}
7158
}
7052
7159
7160
void
7161
PresShell::EnumeratePlugins(nsIDOMDocument *aDocument,
7162
                            const nsString &aPluginTag,
7163
                            nsPluginEnumCallback aCallback)
7164
{
7165
  nsCOMPtr<nsIDOMNodeList> nodes;
7166
  aDocument->GetElementsByTagName(aPluginTag, getter_AddRefs(nodes));
7167
  if (!nodes)
7168
    return;
7169
7170
  PRUint32 length;
7171
  nodes->GetLength(&length);
7172
7173
  for (PRUint32 i = 0; i < length; ++i) {
7174
    nsCOMPtr<nsIDOMNode> node;
7175
    nodes->Item(i, getter_AddRefs(node));
7176
7177
    nsCOMPtr<nsIContent> content = do_QueryInterface(node);
7178
    if (content)
7179
      aCallback(this, content);
7180
  }
7181
}
7182
7053
//------------------------------------------------------
7183
//------------------------------------------------------
7054
// End of protected and private methods on the PresShell
7184
// End of protected and private methods on the PresShell
7055
//------------------------------------------------------
7185
//------------------------------------------------------
(-)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 / +10 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;
45
44
46
[scriptable, uuid(081e31e0-a144-11d3-8c7c-00609792278c)]
45
[scriptable, uuid(c5ca429c-b5c2-11d9-8547-00112478d626)]
47
interface nsISecureBrowserUI : nsISupports
46
interface nsISecureBrowserUI : nsISupports
48
{
47
{
49
    void init(in nsIDOMWindow window);
48
    void init(in nsIDOMWindow window);
50
49
51
    readonly attribute unsigned long state;
50
    readonly attribute unsigned long state;
52
    readonly attribute AString tooltipText;
51
    readonly attribute AString tooltipText;
52
53
    /* Returns an object that encapsulates the current security state. */
54
    nsISupports captureState();
55
56
    /**
57
     * Restore the state captured by captureState(), firing transition
58
     * notifications as necessary.
59
     */
60
    void transitionToState(in nsISupports state);
53
};
61
};
54
62
55
%{C++
63
%{C++
(-)security/manager/boot/src/nsSecureBrowserUIImpl.cpp (-11 / +73 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
#define NS_SECUREBROWSERUISTATE_IID \
1503
{0x086c5daf, 0xbb0a, 0x45cb, {0x98, 0x2b, 0xf1, 0x62, 0x49, 0xd5, 0x0e, 0x28}}
1504
1505
class nsSecureBrowserUIImpl::State : public nsISupports
1506
{
1507
public:
1508
  NS_DEFINE_STATIC_IID_ACCESSOR(NS_SECUREBROWSERUISTATE_IID)
1509
  NS_DECL_ISUPPORTS
1510
1511
  State(lockIconState aState, nsISupports *aSSLStatus);
1512
1513
  lockIconState GetState() const { return mState; }
1514
  nsISupports* GetSSLStatus() { return mSSLStatus; }
1515
1516
private:
1517
  lockIconState mState;
1518
  nsCOMPtr<nsISupports> mSSLStatus;
1519
};
1520
1521
NS_IMPL_ISUPPORTS1(nsSecureBrowserUIImpl::State, nsSecureBrowserUIImpl::State)
1522
1523
nsSecureBrowserUIImpl::State::State(lockIconState aState,
1524
                                    nsISupports *aSSLStatus)
1525
  : mState(aState), mSSLStatus(aSSLStatus)
1526
{
1527
}
1528
1529
NS_IMETHODIMP
1530
nsSecureBrowserUIImpl::CaptureState(nsISupports **aState)
1531
{
1532
  *aState = new State(mPreviousSecurityState, mSSLStatus);
1533
  NS_ENSURE_TRUE(aState, NS_ERROR_OUT_OF_MEMORY);
1534
1535
  NS_ADDREF(*aState);
1536
  return NS_OK;
1537
}
1538
1539
NS_IMETHODIMP
1540
nsSecureBrowserUIImpl::TransitionToState(nsISupports *aState)
1541
{
1542
  nsCOMPtr<nsSecureBrowserUIImpl::State> state = do_QueryInterface(aState);
1543
  NS_ENSURE_TRUE(state, NS_ERROR_NULL_POINTER);
1544
1545
  mSSLStatus = state->GetSSLStatus();
1546
  return UpdateSecurityState(state->GetState(), nsnull);
1547
}
(-)security/manager/boot/src/nsSecureBrowserUIImpl.h (+2 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 144-149   protected: Link Here 
144
  nsresult GetNSSDialogs(nsISecurityWarningDialogs **);
145
  nsresult GetNSSDialogs(nsISecurityWarningDialogs **);
145
146
146
  PLDHashTable mTransferringRequests;
147
  PLDHashTable mTransferringRequests;
148
  class State;
147
};
149
};
148
150
149
151
(-)toolkit/components/passwordmgr/base/nsPasswordManager.cpp (-5 / +85 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"
76
#include "nsIDOMNSEvent.h"
74
77
75
static const char kPMPropertiesURL[] = "chrome://passwordmgr/locale/passwordmgr.properties";
78
static const char kPMPropertiesURL[] = "chrome://passwordmgr/locale/passwordmgr.properties";
76
static PRBool sRememberPasswords = PR_FALSE;
79
static PRBool sRememberPasswords = PR_FALSE;
 Lines 263-268   nsPasswordManager::Init() Link Here 
263
266
264
  progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
267
  progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
265
268
269
  // Listen for "domwindowopened", this will let us attach our DOMPageRestore
270
  // event listener.
271
272
  obsService->AddObserver(this, "domwindowopened", PR_FALSE);
273
  obsService->AddObserver(this, "domwindowclosed", PR_FALSE);
274
275
  // Also register on any open windows that already exist, since we don't
276
  // get notifications for those.
277
278
  nsCOMPtr<nsIWindowWatcher> watcher =
279
    do_GetService(NS_WINDOWWATCHER_CONTRACTID);
280
  if (watcher) {
281
    nsCOMPtr<nsISimpleEnumerator> enumerator;
282
    watcher->GetWindowEnumerator(getter_AddRefs(enumerator));
283
    if (enumerator) {
284
      PRBool hasMore;
285
286
      while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) {
287
        nsCOMPtr<nsISupports> item;
288
        enumerator->GetNext(getter_AddRefs(item));
289
290
        nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(item);
291
        if (targ) {
292
          targ->AddEventListener(NS_LITERAL_STRING("DOMPageRestore"),
293
                                 NS_STATIC_CAST(nsIDOMLoadListener*, this),
294
                                 PR_FALSE);
295
        }
296
      }
297
    }
298
  }
299
266
  // Now read in the signon file
300
  // Now read in the signon file
267
  nsXPIDLCString signonFile;
301
  nsXPIDLCString signonFile;
268
  mPrefBranch->GetCharPref("SignonFileName", getter_Copies(signonFile));
302
  mPrefBranch->GetCharPref("SignonFileName", getter_Copies(signonFile));
 Lines 747-752   nsPasswordManager::Observe(nsISupports* Link Here 
747
    NS_ASSERTION(branch == mPrefBranch, "unexpected pref change notification");
781
    NS_ASSERTION(branch == mPrefBranch, "unexpected pref change notification");
748
782
749
    branch->GetBoolPref("rememberSignons", &sRememberPasswords);
783
    branch->GetBoolPref("rememberSignons", &sRememberPasswords);
784
  } else if (!strcmp(aTopic, "domwindowopened")) {
785
    nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(aSubject);
786
    if (targ) {
787
      targ->AddEventListener(NS_LITERAL_STRING("DOMPageRestore"),
788
                             NS_STATIC_CAST(nsIDOMLoadListener*, this),
789
                             PR_FALSE);
790
    }
791
  } else if (!strcmp(aTopic, "domwindowclosed")) {
792
    nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(aSubject);
793
    if (targ) {
794
      targ->RemoveEventListener(NS_LITERAL_STRING("DOMPageRestore"),
795
                                NS_STATIC_CAST(nsIDOMLoadListener*, this),
796
                                PR_FALSE);
797
    }
750
  }
798
  }
751
799
752
  return NS_OK;
800
  return NS_OK;
 Lines 765-780   nsPasswordManager::OnStateChange(nsIWebP Link Here 
765
      !(aStateFlags & nsIWebProgressListener::STATE_STOP))
813
      !(aStateFlags & nsIWebProgressListener::STATE_STOP))
766
    return NS_OK;
814
    return NS_OK;
767
815
768
  // Don't do anything if the global signon pref is disabled
769
  if (!SingleSignonEnabled())
770
    return NS_OK;
771
772
  nsCOMPtr<nsIDOMWindow> domWin;
816
  nsCOMPtr<nsIDOMWindow> domWin;
773
  nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));
817
  nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));
774
  NS_ENSURE_SUCCESS(rv, rv);
818
  NS_ENSURE_SUCCESS(rv, rv);
775
819
820
  return DoPrefill(domWin);
821
}
822
823
nsresult
824
nsPasswordManager::DoPrefill(nsIDOMWindow *aDOMWindow)
825
{
826
  // Don't do anything if the global signon pref is disabled
827
  if (!SingleSignonEnabled())
828
    return NS_OK;
829
776
  nsCOMPtr<nsIDOMDocument> domDoc;
830
  nsCOMPtr<nsIDOMDocument> domDoc;
777
  domWin->GetDocument(getter_AddRefs(domDoc));
831
  aDOMWindow->GetDocument(getter_AddRefs(domDoc));
778
  NS_ASSERTION(domDoc, "DOM window should always have a document!");
832
  NS_ASSERTION(domDoc, "DOM window should always have a document!");
779
833
780
  // For now, only prefill forms in HTML documents.
834
  // For now, only prefill forms in HTML documents.
 Lines 1568-1573   nsPasswordManager::Error(nsIDOMEvent* aE Link Here 
1568
  return NS_OK;
1622
  return NS_OK;
1569
}
1623
}
1570
1624
1625
NS_IMETHODIMP
1626
nsPasswordManager::PageRestore(nsIDOMEvent* aEvent)
1627
{
1628
  // Only autofill for trusted events.
1629
  nsCOMPtr<nsIDOMNSEvent> nsevent = do_QueryInterface(aEvent);
1630
  PRBool trusted = PR_FALSE;
1631
  if (nsevent)
1632
    nsevent->GetIsTrusted(&trusted);
1633
  if (!trusted)
1634
    return NS_OK;
1635
1636
  nsCOMPtr<nsIDOMEventTarget> target;
1637
  aEvent->GetTarget(getter_AddRefs(target));
1638
1639
  nsCOMPtr<nsIDocument> doc = do_QueryInterface(target);
1640
  if (doc) {
1641
    nsCOMPtr<nsIDOMWindow> win =
1642
      do_QueryInterface(doc->GetScriptGlobalObject());
1643
    if (win) {
1644
      return DoPrefill(win);
1645
    }
1646
  }
1647
1648
  return NS_OK;
1649
}
1650
1571
1651
1572
// internal methods
1652
// internal methods
1573
1653
(-)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/components/typeaheadfind/src/nsTypeAheadFind.cpp (+1 lines)
Line     Link Here 
 Lines 104-109   NS_INTERFACE_MAP_BEGIN(nsTypeAheadFind) Link Here 
104
  NS_INTERFACE_MAP_ENTRY(nsITypeAheadFind)
104
  NS_INTERFACE_MAP_ENTRY(nsITypeAheadFind)
105
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITypeAheadFind)
105
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITypeAheadFind)
106
  NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
106
  NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
107
  NS_INTERFACE_MAP_ENTRY(nsIObserver)
107
NS_INTERFACE_MAP_END
108
NS_INTERFACE_MAP_END
108
109
109
NS_IMPL_ADDREF(nsTypeAheadFind)
110
NS_IMPL_ADDREF(nsTypeAheadFind)
(-)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/src/nsView.cpp (+27 lines)
Line     Link Here 
 Lines 491-496   NS_IMETHODIMP nsView::SetFloating(PRBool Link Here 
491
	return NS_OK;
491
	return NS_OK;
492
}
492
}
493
493
494
void nsView::InvalidateHierarchy()
495
{
496
  if (mViewManager->GetRootView() == this)
497
    mViewManager->InvalidateHierarchy();
498
499
  for (nsView *child = mFirstChild; child; child = child->GetNextSibling())
500
    child->InvalidateHierarchy();
501
}
502
494
void nsView::InsertChild(nsView *aChild, nsView *aSibling)
503
void nsView::InsertChild(nsView *aChild, nsView *aSibling)
495
{
504
{
496
  NS_PRECONDITION(nsnull != aChild, "null ptr");
505
  NS_PRECONDITION(nsnull != aChild, "null ptr");
 Lines 512-517   void nsView::InsertChild(nsView *aChild, Link Here 
512
      mFirstChild = aChild;
521
      mFirstChild = aChild;
513
    }
522
    }
514
    aChild->SetParent(this);
523
    aChild->SetParent(this);
524
525
    // If we just inserted a root view, then update the RootViewManager
526
    // on all view managers in the new subtree.
527
528
    nsViewManager *vm = aChild->GetViewManager();
529
    if (vm->GetRootView() == aChild)
530
    {
531
      aChild->InvalidateHierarchy();
532
    }
515
  }
533
  }
516
}
534
}
517
535
 Lines 540-545   void nsView::RemoveChild(nsView *child) Link Here 
540
	    kid = kid->GetNextSibling();
558
	    kid = kid->GetNextSibling();
541
    }
559
    }
542
    NS_ASSERTION(found, "tried to remove non child");
560
    NS_ASSERTION(found, "tried to remove non child");
561
562
    // If we just removed a root view, then update the RootViewManager
563
    // on all view managers in the removed subtree.
564
565
    nsViewManager *vm = child->GetViewManager();
566
    if (vm->GetRootView() == child)
567
    {
568
      child->InvalidateHierarchy();
569
    }
543
  }
570
  }
544
}
571
}
545
572
(-)view/src/nsView.h (+3 lines)
Line     Link Here 
 Lines 291-296   public: Link Here 
291
  void SetPositionIgnoringChildWidgets(nscoord aX, nscoord aY);
291
  void SetPositionIgnoringChildWidgets(nscoord aX, nscoord aY);
292
  nsresult LoadWidget(const nsCID &aClassIID);
292
  nsresult LoadWidget(const nsCID &aClassIID);
293
293
294
  // Update the cached RootViewManager for all view manager descendents.
295
  void InvalidateHierarchy();
296
294
  virtual ~nsView();
297
  virtual ~nsView();
295
298
296
protected:
299
protected:
(-)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
void
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
      NS_ASSERTION(mRootViewManager != this,
4456
                   "Root view had a parent, but it has the same view manager");
4457
    } else {
4458
      mRootViewManager = this;
4459
    }
4460
  }
4461
}
(-)view/src/nsViewManager.h (+3 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
  /* Update the cached RootViewManager pointer on this view manager. */
271
  void InvalidateHierarchy();
272
270
protected:
273
protected:
271
  virtual ~nsViewManager();
274
  virtual ~nsViewManager();
272
275
(-)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 / +129 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
87
attribute unsigned long ID;
93
    /** Append a child shell to the end of our list. */
88
94
    void addChildShell(in nsIDocShellTreeItem shell);
89
/**
95
90
 * pageIdentifier is an integer that should be the same for two entries
96
    /**
91
 * attached to the same docshell only if the two entries are entries for the
97
     * Get the child shell at |index|; returns null if |index| is out of bounds.
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
    nsIDocShellTreeItem childShellAt(in long index);
94
 * are separated by an anchor traversal or a subframe navigation in some other
100
95
 * frame).
101
    /**
96
 */
102
     * Clear the child shell list.
97
attribute unsigned long pageIdentifier;
103
     */
98
104
    void clearChildShells();
99
/** attribute to set and get the cache key for the entry */
105
100
attribute nsISupports cacheKey;
106
    /** Saved security state for the content viewer */
101
107
    attribute nsISupports securityState;
102
/** attribute to indicate whether layoutHistoryState should be saved */
108
103
attribute boolean saveLayoutStateFlag;
109
    /** Saved refresh URI list for the content viewer */
104
110
    attribute nsISupportsArray refreshURIList;
105
/** attribute to indicate whether the page is already expired in cache */
111
106
attribute boolean expirationStatus;
112
    /**
107
113
     * Ensure that the cached presentation members are self-consistent.
108
/** attribute to indicate the content-type of the document that this
114
     * If either |contentViewer| or |windowState| are null, then all of the
109
    is a session history entry for */
115
     * following members are cleared/reset:
110
attribute ACString contentType; 
116
     *  contentViewer, sticky, windowState, viewerBounds, childShells,
117
     *  refreshURIList.
118
     */
119
    void syncPresentationState();
120
121
    /** Title for the document */
122
    void setTitle(in AString aTitle);
123
124
    /** Post Data for the document */
125
    attribute nsIInputStream postData;
126
127
    /** LayoutHistoryState for scroll position and form values */
128
    attribute nsILayoutHistoryState layoutHistoryState;
129
130
    /** parent of this entry */
131
    attribute nsISHEntry parent;
132
133
    /**
134
     * The loadType for this entry. This is typically loadHistory except
135
     * when reload is pressed, it has the appropriate reload flag
136
     */
137
    attribute unsigned long loadType;
138
139
    /**
140
     * An ID to help identify this entry from others during
141
     * subframe navigation
142
     */
143
    attribute unsigned long ID;
144
145
    /**
146
     * pageIdentifier is an integer that should be the same for two entries
147
     * attached to the same docshell only if the two entries are entries for
148
     * the same page in the sense that one could go from the state represented
149
     * by one to the state represented by the other simply by scrolling (so the
150
     * entries are separated by an anchor traversal or a subframe navigation in
151
     * some other frame).
152
     */
153
    attribute unsigned long pageIdentifier;
154
155
    /** attribute to set and get the cache key for the entry */
156
    attribute nsISupports cacheKey;
157
158
    /** attribute to indicate whether layoutHistoryState should be saved */
159
    attribute boolean saveLayoutStateFlag;
160
161
    /** attribute to indicate whether the page is already expired in cache */
162
    attribute boolean expirationStatus;
163
164
    /**
165
     * attribute to indicate the content-type of the document that this
166
     * is a session history entry for
167
     */
168
    attribute ACString contentType; 
111
 
169
 
112
/** Set/Get scrollers' positon in anchored pages */
170
    /** Set/Get scrollers' positon in anchored pages */
113
void setScrollPosition(in PRInt32 x, in PRInt32 y);
171
    void setScrollPosition(in long x, in long y);
114
void getScrollPosition(out PRInt32 x, out PRInt32 y);
172
    void getScrollPosition(out long x, out long y);
115
173
116
/** Additional ways to create an entry */
174
    /** Additional ways to create an entry */
117
void create(in nsIURI aURI, in wstring aTitle, in nsIDOMDocument aDocument,
175
    void create(in nsIURI URI, in AString title,
118
            in nsIInputStream aInputStream, in nsILayoutHistoryState aHistoryLayoutState,
176
                in nsIInputStream inputStream,
119
            in nsISupports aCacheKey, in ACString aContentType);
177
                in nsILayoutHistoryState layoutHistoryState,
120
178
                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
179
180
    nsISHEntry clone();
126
181
182
    /** Attribute that indicates if this entry is for a subframe navigation */
183
    void setIsSubFrame(in boolean aFlag);
127
};
184
};
128
185
129
186
(-)xpfe/components/shistory/public/nsISHistoryInternal.idl (-1 / +8 lines)
Line     Link Here 
 Lines 46-52   interface nsIDocShell; Link Here 
46
46
47
%{C++
47
%{C++
48
#define NS_SHISTORY_INTERNAL_CID \
48
#define NS_SHISTORY_INTERNAL_CID \
49
{0xdd335422, 0xb8b8, 0x11d3, {0xbd, 0xc8, 0x00, 0x50, 0x04, 0x0a, 0x9b, 0x44}}
49
{0x5b4cba4c, 0xbf67, 0x499a, {0xae, 0x2c, 0x3f, 0x76, 0x65, 0x6f, 0x4a, 0x4e}}
50
50
51
#define NS_SHISTORY_INTERNAL_CONTRACTID "@mozilla.org/browser/shistory-internal;1"
51
#define NS_SHISTORY_INTERNAL_CONTRACTID "@mozilla.org/browser/shistory-internal;1"
52
%}
52
%}
 Lines 90-93   interface nsISHistoryInternal: nsISuppor Link Here 
90
   */
90
   */
91
   readonly attribute nsISHistoryListener listener;
91
   readonly attribute nsISHistoryListener listener;
92
92
93
  /**
94
   * Evict content viewers until the number of content viewers is no more than
95
   * browser.sessionhistory.max_viewers.  This is done automatically by
96
   * updateIndex(), but should be called explicitly if a new history entry
97
   * is added and later has a content viewer set.
98
   */
99
   void evictContentViewers();
93
};
100
};
(-)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 / +144 lines)
Line     Link Here 
 Lines 37-47    Link Here 
37
 *
37
 *
38
 * ***** END LICENSE BLOCK ***** */
38
 * ***** END LICENSE BLOCK ***** */
39
39
40
#ifdef DEBUG_bryner
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(PR_TRUE)
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(0, 0, 0, 0)
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(nsISupports **aState)
505
{
506
  NS_IF_ADDREF(*aState = mSecurityState);
507
  return NS_OK;
508
}
509
510
NS_IMETHODIMP
511
nsSHEntry::SetSecurityState(nsISupports *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
}
530
531
NS_IMETHODIMP
532
nsSHEntry::SyncPresentationState()
533
{
534
  if (mContentViewer && mWindowState) {
535
    // If we have a content viewer and a window state, we should be ok.
536
    return NS_OK;
537
  }
538
539
  // If not, then nuke all of the presentation-related members.
540
  if (mContentViewer)
541
    mContentViewer->SetHistoryEntry(nsnull);
542
543
  mContentViewer = nsnull;
544
  mSticky = PR_TRUE;
545
  mWindowState = nsnull;
546
  mViewerBounds.SetRect(0, 0, 0, 0);
547
  mChildShells.Clear();
548
  mSecurityState = nsnull;
549
  mRefreshURIList = nsnull;
550
  return NS_OK;
551
}
(-)xpfe/components/shistory/src/nsSHEntry.h (-5 / +13 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 "nsSupportsArray.h"
57
60
58
class nsSHEntry : public nsIHistoryEntry,
61
class nsSHEntry : public nsISHEntry,
59
                  public nsISHEntry,
60
                  public nsISHContainer
62
                  public nsISHContainer
61
{
63
{
62
public: 
64
public: 
 Lines 69-79   public: Link Here 
69
  NS_DECL_NSISHCONTAINER
71
  NS_DECL_NSISHCONTAINER
70
72
71
private:
73
private:
72
  ~nsSHEntry() { mChildren.Clear(); }
74
  ~nsSHEntry();
73
75
74
  nsCOMPtr<nsIURI>                mURI;
76
  nsCOMPtr<nsIURI>                mURI;
75
  nsCOMPtr<nsIURI>                mReferrerURI;
77
  nsCOMPtr<nsIURI>                mReferrerURI;
76
  nsCOMPtr<nsIDOMDocument>        mDocument;
78
  nsCOMPtr<nsIContentViewer>      mContentViewer;
77
  nsString                        mTitle;
79
  nsString                        mTitle;
78
  nsCOMPtr<nsIInputStream>        mPostData;
80
  nsCOMPtr<nsIInputStream>        mPostData;
79
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
81
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
 Lines 86-94   private: Link Here 
86
  PRPackedBool                    mIsFrameNavigation;
88
  PRPackedBool                    mIsFrameNavigation;
87
  PRPackedBool                    mSaveLayoutState;
89
  PRPackedBool                    mSaveLayoutState;
88
  PRPackedBool                    mExpired;
90
  PRPackedBool                    mExpired;
91
  PRPackedBool                    mSticky;
89
  nsCString                       mContentType;
92
  nsCString                       mContentType;
90
  nsCOMPtr<nsISupports>           mCacheKey;
93
  nsCOMPtr<nsISupports>           mCacheKey;
91
  nsISHEntry *                    mParent;  // weak reference
94
  nsISHEntry *                    mParent;  // weak reference
95
  nsCOMPtr<nsISupports>           mWindowState;
96
  nsRect                          mViewerBounds;
97
  nsVoidArray                     mChildShells;
98
  nsCOMPtr<nsISupports>           mSecurityState;
99
  nsCOMPtr<nsISupportsArray>      mRefreshURIList;
92
};
100
};
93
101
94
#endif /* nsSHEntry_h */
102
#endif /* nsSHEntry_h */
(-)xpfe/components/shistory/src/nsSHistory.cpp (-1 / +76 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 104-114   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) {
112
    // Session history size is only taken from the default prefs branch.
113
    // This means that it's only configurable on a per-application basis.
114
    // The goal of this is to unbreak users who have inadvertently set their
115
    // session history size to -1.
107
    nsCOMPtr<nsIPrefBranch> defaultBranch;
116
    nsCOMPtr<nsIPrefBranch> defaultBranch;
108
    prefs->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch));
117
    prefs->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch));
109
    if (defaultBranch) {
118
    if (defaultBranch) {
110
      defaultBranch->GetIntPref(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
119
      defaultBranch->GetIntPref(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
111
    }
120
    }
121
122
    // The size of the content viewer cache does not suffer from this problem,
123
    // so we allow it to be overridden by user prefs.
124
    nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
125
    if (branch)
126
      branch->GetIntPref(PREF_SHISTORY_VIEWERS, &gHistoryMaxViewers);
112
  }
127
  }
113
  return NS_OK;
128
  return NS_OK;
114
}
129
}
 Lines 207-212   nsSHistory::GetEntryAtIndex(PRInt32 aInd Link Here 
207
    if (NS_SUCCEEDED(rv) && (*aResult)) {
222
    if (NS_SUCCEEDED(rv) && (*aResult)) {
208
      // Set mIndex to the requested index, if asked to do so..
223
      // Set mIndex to the requested index, if asked to do so..
209
      if (aModifyIndex) {
224
      if (aModifyIndex) {
225
        EvictContentViewers(mIndex, aIndex);
210
        mIndex = aIndex;
226
        mIndex = aIndex;
211
      }
227
      }
212
    } //entry
228
    } //entry
 Lines 476-481   nsSHistory::GetListener(nsISHistoryListe Link Here 
476
  return NS_OK;
492
  return NS_OK;
477
}
493
}
478
494
495
NS_IMETHODIMP
496
nsSHistory::EvictContentViewers()
497
{
498
  // This is called after a new entry has been appended to the end of the list.
499
  EvictContentViewers(mIndex - 1, mIndex);
500
  return NS_OK;
501
}
502
479
//*****************************************************************************
503
//*****************************************************************************
480
//    nsSHistory: nsIWebNavigation
504
//    nsSHistory: nsIWebNavigation
481
//*****************************************************************************
505
//*****************************************************************************
 Lines 583-594   nsSHistory::Reload(PRUint32 aReloadFlags Link Here 
583
	return LoadEntry(mIndex, loadType, HIST_CMD_RELOAD);
607
	return LoadEntry(mIndex, loadType, HIST_CMD_RELOAD);
584
}
608
}
585
609
610
void
611
nsSHistory::EvictContentViewers(PRInt32 aFromIndex, PRInt32 aToIndex)
612
{
613
  // To enforce the limit on cached content viewers, we need to release all
614
  // of the content viewers that are no longer in the "window" that now
615
  // ends/begins at aToIndex.
616
617
  PRInt32 startIndex, endIndex;
618
  if (aToIndex > aFromIndex) { // going forward
619
    startIndex = PR_MAX(0, aFromIndex - gHistoryMaxViewers);
620
    endIndex = PR_MAX(0, aToIndex - gHistoryMaxViewers);
621
  } else { // going backward
622
    startIndex = PR_MIN(mLength - 1, aToIndex + gHistoryMaxViewers);
623
    endIndex = PR_MIN(mLength - 1, aFromIndex + gHistoryMaxViewers);
624
  }
625
626
  nsCOMPtr<nsISHTransaction> trans;
627
  GetTransactionAtIndex(startIndex, getter_AddRefs(trans));
628
629
  for (PRInt32 i = startIndex; trans && i < endIndex; ++i) {
630
    nsCOMPtr<nsISHEntry> entry;
631
    trans->GetSHEntry(getter_AddRefs(entry));
632
    nsCOMPtr<nsIContentViewer> viewer;
633
    entry->GetContentViewer(getter_AddRefs(viewer));
634
    if (viewer) {
635
#ifdef DEBUG_PAGE_CACHE 
636
      nsCOMPtr<nsIURI> uri;
637
      entry->GetURI(getter_AddRefs(uri));
638
      nsCAutoString spec;
639
      if (uri)
640
        uri->GetSpec(spec);
641
642
      printf("Evicting content viewer: %s\n", spec.get());
643
#endif
644
645
      viewer->Destroy();
646
      entry->SetContentViewer(nsnull);
647
      entry->SyncPresentationState();
648
    }
649
650
    nsISHTransaction *temp = trans;
651
    temp->GetNext(getter_AddRefs(trans));
652
  }
653
}
654
586
NS_IMETHODIMP
655
NS_IMETHODIMP
587
nsSHistory::UpdateIndex()
656
nsSHistory::UpdateIndex()
588
{
657
{
589
  // Update the actual index with the right value. 
658
  // Update the actual index with the right value. 
590
  if (mIndex != mRequestedIndex && mRequestedIndex != -1)
659
  if (mIndex != mRequestedIndex && mRequestedIndex != -1) {
660
    // We've just finished a history navigation (back or forward), so enforce
661
    // the max number of content viewers.
662
663
    EvictContentViewers(mIndex, mRequestedIndex);
591
    mIndex = mRequestedIndex;
664
    mIndex = mRequestedIndex;
665
  }
666
592
  return NS_OK;
667
  return NS_OK;
593
}
668
}
594
669
(-)xpfe/components/shistory/src/nsSHistory.h (+2 lines)
Line     Link Here 
 Lines 85-90   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;
(-)xpfe/global/resources/content/bindings/browser.xml (-5 / +5 lines)
Line     Link Here 
 Lines 305-313    Link Here 
305
        null
305
        null
306
      </field>
306
      </field>
307
307
308
      <field name="securityUI">
308
      <property name="securityUI"
309
        null
309
                onget="return this.docShell.securityUI;"
310
      </field>
310
                onset="this.docShell.securityUI = val;"/>
311
311
312
      <field name="userTypedClear">
312
      <field name="userTypedClear">
313
        1
313
        1
 Lines 356-363    Link Here 
356
            const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
356
            const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
357
            if (!this.hasAttribute("disablesecurity") &&
357
            if (!this.hasAttribute("disablesecurity") &&
358
                SECUREBROWSERUI_CONTRACTID in Components.classes) {
358
                SECUREBROWSERUI_CONTRACTID in Components.classes) {
359
              this.securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID].createInstance(Components.interfaces.nsISecureBrowserUI);
359
              var securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID].createInstance(Components.interfaces.nsISecureBrowserUI);
360
              this.securityUI.init(this.contentWindow);
360
              securityUI.init(this.contentWindow);
361
            }
361
            }
362
          }
362
          }
363
          catch (e) {
363
          catch (e) {

Return to bug 274784