Attachment #181463: new patch 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
}
(-)browser/app/profile/firefox.js (+1 lines)
Line     Link Here 
 Lines 192-197   pref("browser.search.basic.min_ver", "0. Link Here 
192
192
193
pref("browser.history.grouping", "day");
193
pref("browser.history.grouping", "day");
194
pref("browser.sessionhistory.max_entries", 50);
194
pref("browser.sessionhistory.max_entries", 50);
195
pref("browser.sessionhistory.max_viewers", 5);
195
196
196
// handle external links
197
// handle external links
197
// 0=default window, 1=current window/tab, 2=new window, 3=new tab in most recent window
198
// 0=default window, 1=current window/tab, 2=new window, 3=new tab in most recent window
(-)content/base/public/nsIDocument.h (+14 lines)
Line     Link Here 
 Lines 52-57    Link Here 
52
#include "nsCRT.h"
52
#include "nsCRT.h"
53
#include "mozFlushType.h"
53
#include "mozFlushType.h"
54
#include "nsPropertyTable.h"
54
#include "nsPropertyTable.h"
55
#include "pldhash.h"
55
56
56
class nsIAtom;
57
class nsIAtom;
57
class nsIContent;
58
class nsIContent;
 Lines 665-670   public: Link Here 
665
    return mPartID;
666
    return mPartID;
666
  }
667
  }
667
668
669
  /**
670
   * Sanitize the document by resetting all input elements and forms that have
671
   * autocomplete=off to their default values.
672
   */
673
  virtual nsresult Sanitize() = 0;
674
675
  /**
676
   * Enumerate all subdocuments.
677
   */
678
  typedef PRBool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
679
  virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
680
                                     void *aData) = 0;
681
668
protected:
682
protected:
669
  ~nsIDocument()
683
  ~nsIDocument()
670
  {
684
  {
(-)content/base/src/nsDocument.cpp (-31 / +110 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"
129
130
130
#include "nsICharsetAlias.h"
131
#include "nsICharsetAlias.h"
131
static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
132
static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
 Lines 1847-1883   nsDocument::GetScriptGlobalObject() cons Link Here 
1847
void
1848
void
1848
nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
1849
nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
1849
{
1850
{
1850
  // XXX HACK ALERT! If the script context owner is null, the document
1851
  // will soon be going away. So tell our content that to lose its
1852
  // reference to the document. This has to be done before we actually
1853
  // set the script context owner to null so that the content elements
1854
  // can remove references to their script objects.
1855
  if (!aScriptGlobalObject) {
1856
    PRInt32 count, indx;
1857
1858
    count = mChildren.Count();
1859
1860
    mIsGoingAway = PR_TRUE;
1861
1862
    for (indx = 0; indx < count; ++indx) {
1863
      mChildren[indx]->UnbindFromTree();
1864
    }
1865
1866
    // Propagate the out-of-band notification to each PresShell's
1867
    // anonymous content as well. This ensures that there aren't any
1868
    // accidental script references left in anonymous content keeping
1869
    // the document alive. (While not strictly necessary -- the
1870
    // PresShell owns us -- it's tidy.)
1871
    for (count = mPresShells.Count() - 1; count >= 0; --count) {
1872
      nsCOMPtr<nsIPresShell> shell =
1873
        NS_STATIC_CAST(nsIPresShell*, mPresShells[count]);
1874
      if (!shell)
1875
        continue;
1876
1877
      shell->ReleaseAnonymousContent();
1878
    }
1879
  }
1880
1881
  mScriptGlobalObject = aScriptGlobalObject;
1851
  mScriptGlobalObject = aScriptGlobalObject;
1882
}
1852
}
1883
1853
 Lines 4574-4576   nsDocument::UnsetProperty(nsIAtom *aProp Link Here 
4574
{
4544
{
4575
  return mPropertyTable.UnsetProperty(this, aPropertyName, aStatus);
4545
  return mPropertyTable.UnsetProperty(this, aPropertyName, aStatus);
4576
}
4546
}
4547
4548
nsresult
4549
nsDocument::Sanitize()
4550
{
4551
    // Sanitize the document by resetting all password fields and any form
4552
    // fields with autocomplete=off to their default values.  We do this now,
4553
    // instead of when the presentation is restored, to offer some protection
4554
    // in case there is ever an exploit that allows a cached document to be
4555
    // accessed from a different document.
4556
4557
    // First locate all input elements, regardless of whether they are
4558
    // in a form, and reset the password and autocomplete=off elements.
4559
4560
    nsCOMPtr<nsIDOMNodeList> nodes;
4561
    nsresult rv = GetElementsByTagName(NS_LITERAL_STRING("input"),
4562
                                       getter_AddRefs(nodes));
4563
    NS_ENSURE_SUCCESS(rv, rv);
4564
4565
    PRUint32 length = 0;
4566
    if (nodes)
4567
        nodes->GetLength(&length);
4568
4569
    nsCOMPtr<nsIDOMNode> item;
4570
    nsCOMPtr<nsIDOMHTMLInputElement> input;
4571
    nsAutoString value;
4572
    PRUint32 i;
4573
4574
    for (i = 0; i < length; ++i) {
4575
        nodes->Item(i, getter_AddRefs(item));
4576
        NS_ASSERTION(item, "null item in node list!");
4577
4578
        input = do_QueryInterface(item);
4579
        if (!input)
4580
            continue;
4581
4582
        PRBool resetValue = PR_FALSE;
4583
4584
        input->GetAttribute(NS_LITERAL_STRING("autocomplete"), value);
4585
        if (value.LowerCaseEqualsLiteral("off")) {
4586
            resetValue = PR_TRUE;
4587
        } else {
4588
            input->GetType(value);
4589
            if (value.LowerCaseEqualsLiteral("password"))
4590
                resetValue = PR_TRUE;
4591
        }
4592
4593
        if (resetValue) {
4594
            nsCOMPtr<nsIFormControl> fc = do_QueryInterface(input);
4595
            fc->Reset();
4596
        }
4597
    }
4598
4599
    // Now locate all _form_ elements that have autocomplete=off and reset them
4600
    rv = GetElementsByTagName(NS_LITERAL_STRING("form"),
4601
                              getter_AddRefs(nodes));
4602
    NS_ENSURE_SUCCESS(rv, rv);
4603
4604
    length = 0;
4605
    if (nodes)
4606
        nodes->GetLength(&length);
4607
4608
    nsCOMPtr<nsIDOMHTMLFormElement> form;
4609
4610
    for (i = 0; i < length; ++i) {
4611
        nodes->Item(i, getter_AddRefs(item));
4612
        NS_ASSERTION(item, "null item in nodelist");
4613
4614
        form = do_QueryInterface(item);
4615
        if (!form)
4616
            continue;
4617
4618
        form->GetAttribute(NS_LITERAL_STRING("autocomplete"), value);
4619
        if (value.LowerCaseEqualsLiteral("off"))
4620
            form->Reset();
4621
    }
4622
4623
    return NS_OK;
4624
}
4625
4626
struct SubDocEnumData
4627
{
4628
  nsIDocument::nsSubDocEnumFunc callback;
4629
  void *data;
4630
};
4631
4632
PR_STATIC_CALLBACK(PLDHashOperator)
4633
SubDocHashEnum(PLDHashTable *table, PLDHashEntryHdr *hdr,
4634
               PRUint32 number, void *arg)
4635
{
4636
  SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr);
4637
  SubDocEnumData *data = NS_STATIC_CAST(SubDocEnumData*, arg);
4638
4639
  nsIDocument *subdoc = entry->mSubDocument;
4640
  PRBool next = PR_TRUE;
4641
4642
  if (subdoc)
4643
    next = data->callback(subdoc, data->data);
4644
4645
  return next ? PL_DHASH_NEXT : PL_DHASH_STOP;
4646
}
4647
4648
void
4649
nsDocument::EnumerateSubDocuments(nsSubDocEnumFunc aCallback, void *aData)
4650
{
4651
  if (mSubDocuments) {
4652
    SubDocEnumData data = { aCallback, aData };
4653
    PL_DHashTableEnumerate(mSubDocuments, SubDocHashEnum, &data);
4654
  }
4655
}
(-)content/base/src/nsDocument.h (+5 lines)
Line     Link Here 
 Lines 524-529   public: Link Here 
524
  virtual NS_HIDDEN_(void*) UnsetProperty(nsIAtom  *aPropertyName,
524
  virtual NS_HIDDEN_(void*) UnsetProperty(nsIAtom  *aPropertyName,
525
                                          nsresult *aStatus = nsnull);
525
                                          nsresult *aStatus = nsnull);
526
526
527
  virtual NS_HIDDEN_(nsresult) Sanitize();
528
529
  virtual NS_HIDDEN_(void) EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
530
                                                 void *aData);
531
527
protected:
532
protected:
528
533
529
  void RetrieveRelevantHeaders(nsIChannel *aChannel);
534
  void RetrieveRelevantHeaders(nsIChannel *aChannel);
(-)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 (+6 lines)
Line     Link Here 
 Lines 182-187   public: Link Here 
182
  * Loop pass for evaluation of system event listeners.
182
  * Loop pass for evaluation of system event listeners.
183
  */
183
  */
184
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup) = 0;
184
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup) = 0;
185
186
  /**
187
   * Allows us to quickly determine if we have unload or beforeunload
188
   * listeners registered.
189
   */
190
  virtual PRBool HasUnloadListeners() = 0;
185
};
191
};
186
192
187
nsresult
193
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 / +24 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 885-890   nsEventListenerManager::GetIdentifiersFo Link Here 
885
    *aArrayType = eEventArrayType_Load;
886
    *aArrayType = eEventArrayType_Load;
886
    *aFlags = NS_EVENT_BITS_LOAD_ERROR;
887
    *aFlags = NS_EVENT_BITS_LOAD_ERROR;
887
  }
888
  }
889
  else if (aType == nsLayoutAtoms::onDOMPageRestore) {
890
    *aArrayType = eEventArrayType_Load;
891
    *aFlags = NS_EVENT_BITS_LOAD_PAGE_RESTORE;
892
  }
888
  else if (aType == nsLayoutAtoms::onpaint) {
893
  else if (aType == nsLayoutAtoms::onpaint) {
889
    *aArrayType = eEventArrayType_Paint;
894
    *aArrayType = eEventArrayType_Paint;
890
    *aFlags = NS_EVENT_BITS_PAINT_PAINT;
895
    *aFlags = NS_EVENT_BITS_PAINT_PAINT;
 Lines 2207-2212   void nsEventListenerManager::GetCoordina Link Here 
2207
  }
2212
  }
2208
}
2213
}
2209
2214
2215
PRBool
2216
nsEventListenerManager::HasUnloadListeners()
2217
{
2218
  nsVoidArray *listeners = GetListenersByType(eEventArrayType_Load, nsnull,
2219
                                              PR_FALSE);
2220
  if (listeners) {
2221
    PRInt32 count = listeners->Count();
2222
    for (PRInt32 i = 0; i < count; ++i) {
2223
      PRUint32 subtype = NS_STATIC_CAST(nsListenerStruct*,
2224
                                        listeners->FastElementAt(i))->mSubType;
2225
      if (subtype == NS_EVENT_BITS_NONE || subtype & NS_EVENT_BITS_LOAD_UNLOAD)
2226
        return PR_TRUE;
2227
    }
2228
  }
2229
2230
  return PR_FALSE;
2231
}
2232
2210
nsresult
2233
nsresult
2211
NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) 
2234
NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) 
2212
{
2235
{
(-)content/events/src/nsEventListenerManager.h (+3 lines)
Line     Link Here 
 Lines 163-168   public: Link Here 
163
163
164
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
164
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
165
165
166
  virtual PRBool HasUnloadListeners();
167
166
  static nsresult GetIdentifiersForType(nsIAtom* aType,
168
  static nsresult GetIdentifiersForType(nsIAtom* aType,
167
                                        EventArrayType* aArrayType,
169
                                        EventArrayType* aArrayType,
168
                                        PRInt32* aSubType);
170
                                        PRInt32* aSubType);
 Lines 300-305   protected: Link Here 
300
#define NS_EVENT_BITS_LOAD_ABORT             0x04
302
#define NS_EVENT_BITS_LOAD_ABORT             0x04
301
#define NS_EVENT_BITS_LOAD_ERROR             0x08
303
#define NS_EVENT_BITS_LOAD_ERROR             0x08
302
#define NS_EVENT_BITS_LOAD_BEFORE_UNLOAD     0x10
304
#define NS_EVENT_BITS_LOAD_BEFORE_UNLOAD     0x10
305
#define NS_EVENT_BITS_LOAD_PAGE_RESTORE      0x20
303
306
304
//nsIDOMXULListener
307
//nsIDOMXULListener
305
#define NS_EVENT_BITS_XUL_NONE               0x00
308
#define NS_EVENT_BITS_XUL_NONE               0x00
(-)content/html/content/src/nsGenericHTMLElement.cpp (-9 / +11 lines)
Line     Link Here 
 Lines 1525-1539   nsGenericHTMLElement::HandleDOMEventForA Link Here 
1525
            // nothing else.
1525
            // nothing else.
1526
            nsCOMPtr<nsPIDOMWindow> win =
1526
            nsCOMPtr<nsPIDOMWindow> win =
1527
              do_QueryInterface(document->GetScriptGlobalObject());
1527
              do_QueryInterface(document->GetScriptGlobalObject());
1528
            nsIFocusController *focusController =
1528
            if (win) {
1529
              win->GetRootFocusController();
1529
              nsIFocusController *focusController =
1530
            PRBool isActive = PR_FALSE;
1530
                win->GetRootFocusController();
1531
            focusController->GetActive(&isActive);
1531
              PRBool isActive = PR_FALSE;
1532
            if (!isActive) {
1532
              focusController->GetActive(&isActive);
1533
              nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
1533
              if (!isActive) {
1534
              if(domElement)
1534
                nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
1535
                focusController->SetFocusedElement(domElement);
1535
                if(domElement)
1536
              break;
1536
                  focusController->SetFocusedElement(domElement);
1537
                break;
1538
              }
1537
            }
1539
            }
1538
  
1540
  
1539
            aPresContext->EventStateManager()->
1541
            aPresContext->EventStateManager()->
(-)content/html/content/src/nsHTMLInputElement.cpp (-15 / +19 lines)
Line     Link Here 
 Lines 1069-1082   nsHTMLInputElement::SetFocus(nsPresConte Link Here 
1069
  // nothing else.
1069
  // nothing else.
1070
  nsCOMPtr<nsPIDOMWindow> win =
1070
  nsCOMPtr<nsPIDOMWindow> win =
1071
    do_QueryInterface(doc->GetScriptGlobalObject());
1071
    do_QueryInterface(doc->GetScriptGlobalObject());
1072
  nsIFocusController *focusController = win->GetRootFocusController();
1072
  if (win) {
1073
  PRBool isActive = PR_FALSE;
1073
    nsIFocusController *focusController = win->GetRootFocusController();
1074
  focusController->GetActive(&isActive);
1074
    PRBool isActive = PR_FALSE;
1075
  if (!isActive) {
1075
    focusController->GetActive(&isActive);
1076
    focusController->SetFocusedWindow(win);
1076
    if (!isActive) {
1077
    focusController->SetFocusedElement(this);
1077
      focusController->SetFocusedWindow(win);
1078
      focusController->SetFocusedElement(this);
1078
1079
1079
    return;
1080
      return;
1081
    }
1080
  }
1082
  }
1081
1083
1082
  aPresContext->EventStateManager()->SetContentState(this,
1084
  aPresContext->EventStateManager()->SetContentState(this,
 Lines 1119-1132   nsHTMLInputElement::Select() Link Here 
1119
    // nothing else.
1121
    // nothing else.
1120
    nsCOMPtr<nsPIDOMWindow> win =
1122
    nsCOMPtr<nsPIDOMWindow> win =
1121
      do_QueryInterface(doc->GetScriptGlobalObject());
1123
      do_QueryInterface(doc->GetScriptGlobalObject());
1122
    nsIFocusController *focusController = win->GetRootFocusController();
1124
    if (win) {
1123
    PRBool isActive = PR_FALSE;
1125
      nsIFocusController *focusController = win->GetRootFocusController();
1124
    focusController->GetActive(&isActive);
1126
      PRBool isActive = PR_FALSE;
1125
    if (!isActive) {
1127
      focusController->GetActive(&isActive);
1126
      focusController->SetFocusedWindow(win);
1128
      if (!isActive) {
1127
      focusController->SetFocusedElement(this);
1129
        focusController->SetFocusedWindow(win);
1128
      SelectAll(presContext);
1130
        focusController->SetFocusedElement(this);
1129
      return NS_OK;
1131
        SelectAll(presContext);
1132
        return NS_OK;
1133
      }
1130
    }
1134
    }
1131
1135
1132
    // Just like SetFocus() but without the ScrollIntoView()!
1136
    // Just like SetFocus() but without the ScrollIntoView()!
(-)content/xbl/src/nsXBLPrototypeHandler.cpp (-1 / +2 lines)
Line     Link Here 
 Lines 291-297   nsXBLPrototypeHandler::ExecuteHandler(ns Link Here 
291
        privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
291
        privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
292
      }
292
      }
293
293
294
      focusController = privateWindow->GetRootFocusController();
294
      if (privateWindow)
295
        focusController = privateWindow->GetRootFocusController();
295
    }
296
    }
296
297
297
    NS_LossyConvertUCS2toASCII command(mHandlerText);
298
    NS_LossyConvertUCS2toASCII command(mHandlerText);
(-)content/xbl/src/nsXBLService.cpp (-5 / +6 lines)
Line     Link Here 
 Lines 229-239   public: Link Here 
229
  NS_DECL_NSIREQUESTOBSERVER
229
  NS_DECL_NSIREQUESTOBSERVER
230
230
231
  NS_IMETHOD Load(nsIDOMEvent* aEvent);
231
  NS_IMETHOD Load(nsIDOMEvent* aEvent);
232
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent) { return NS_OK; };
232
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent) { return NS_OK; }
233
  NS_IMETHOD Unload(nsIDOMEvent* aEvent) { return NS_OK; };
233
  NS_IMETHOD Unload(nsIDOMEvent* aEvent) { return NS_OK; }
234
  NS_IMETHOD Abort(nsIDOMEvent* aEvent) { return NS_OK; };
234
  NS_IMETHOD Abort(nsIDOMEvent* aEvent) { return NS_OK; }
235
  NS_IMETHOD Error(nsIDOMEvent* aEvent) { return NS_OK; };
235
  NS_IMETHOD Error(nsIDOMEvent* aEvent) { return NS_OK; }
236
  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; };
236
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent) { return NS_OK; }
237
  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
237
238
238
#ifdef MOZ_XUL
239
#ifdef MOZ_XUL
239
  static nsIXULPrototypeCache* gXULCache;
240
  static nsIXULPrototypeCache* gXULCache;
(-)docshell/base/nsDocShell.cpp (-23 / +415 lines)
Line     Link Here 
 Lines 166-174   static NS_DEFINE_CID(kDOMScriptObjectFac Link Here 
166
166
167
#if defined(DEBUG_bryner)
167
#if defined(DEBUG_bryner)
168
//#define DEBUG_DOCSHELL_FOCUS
168
//#define DEBUG_DOCSHELL_FOCUS
169
#define DEBUG_PAGE_CACHE
169
#endif
170
#endif
170
171
171
#include "plevent.h"
172
#include "plevent.h"
173
#include "nsGUIEvent.h"
174
#include "nsIPrivateDOMEvent.h"
175
#include "nsIDOMEventReceiver.h"
176
#include "nsIEventListenerManager.h"
172
177
173
// Number of documents currently loading
178
// Number of documents currently loading
174
static PRInt32 gNumberOfDocumentsLoading = 0;
179
static PRInt32 gNumberOfDocumentsLoading = 0;
 Lines 1355-1366   nsDocShell::SetCurrentURI(nsIURI *aURI, Link Here 
1355
        isRoot = PR_TRUE;
1360
        isRoot = PR_TRUE;
1356
    }
1361
    }
1357
    if (mLSHE) {
1362
    if (mLSHE) {
1358
      nsCOMPtr<nsIHistoryEntry> historyEntry(do_QueryInterface(mLSHE));
1363
        mLSHE->GetIsSubFrame(&isSubFrame);
1359
      
1360
      // Check if this is a subframe navigation
1361
      if (historyEntry) {
1362
        historyEntry->GetIsSubFrame(&isSubFrame);
1363
      }
1364
    }
1364
    }
1365
1365
1366
    if (!isSubFrame && !isRoot) {
1366
    if (!isSubFrame && !isRoot) {
 Lines 3261-3272   nsDocShell::LoadPage(nsISupports *aPageD Link Here 
3261
    // load the page as view-source
3261
    // load the page as view-source
3262
    //
3262
    //
3263
    if (nsIWebPageDescriptor::DISPLAY_AS_SOURCE == aDisplayType) {
3263
    if (nsIWebPageDescriptor::DISPLAY_AS_SOURCE == aDisplayType) {
3264
        nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(shEntry));
3265
        nsCOMPtr<nsIURI> oldUri, newUri;
3264
        nsCOMPtr<nsIURI> oldUri, newUri;
3266
        nsCString spec, newSpec;
3265
        nsCString spec, newSpec;
3267
3266
3268
        // Create a new view-source URI and replace the original.
3267
        // Create a new view-source URI and replace the original.
3269
        rv = srcHE->GetURI(getter_AddRefs(oldUri));
3268
        rv = shEntry->GetURI(getter_AddRefs(oldUri));
3270
        if (NS_FAILED(rv))
3269
        if (NS_FAILED(rv))
3271
              return rv;
3270
              return rv;
3272
3271
 Lines 3720-3726   nsDocShell::SetTitle(const PRUnichar * a Link Here 
3720
    // would suffice. 
3719
    // would suffice. 
3721
    if (mOSHE && (mLoadType != LOAD_BYPASS_HISTORY) &&
3720
    if (mOSHE && (mLoadType != LOAD_BYPASS_HISTORY) &&
3722
        (mLoadType != LOAD_HISTORY) && (mLoadType != LOAD_ERROR_PAGE)) {
3721
        (mLoadType != LOAD_HISTORY) && (mLoadType != LOAD_ERROR_PAGE)) {
3723
        mOSHE->SetTitle(mTitle.get());    
3722
        mOSHE->SetTitle(mTitle);    
3724
    }
3723
    }
3725
3724
3726
3725
 Lines 4701-4706   nsDocShell::CreateAboutBlankContentViewe Link Here 
4701
  return rv;
4700
  return rv;
4702
}
4701
}
4703
4702
4703
PRBool
4704
nsDocShell::CanSavePresentation()
4705
{
4706
    // If the document is not done loading, don't cache it.
4707
    nsCOMPtr<nsPIDOMWindow> pWin = do_QueryInterface(mScriptGlobal);
4708
    if (pWin && pWin->IsLoading())
4709
        return PR_FALSE;
4710
4711
    // Only save presentation for "normal" loads and link loads.  Anything else
4712
    // probably wants to refetch the page, so caching the old presentation
4713
    // would be incorrect.
4714
    if (mLoadType != LOAD_NORMAL &&
4715
        mLoadType != LOAD_HISTORY &&
4716
        mLoadType != LOAD_LINK)
4717
        return PR_FALSE;
4718
4719
    // If there is an unload or beforeunload listener on the window, then we do
4720
    // not save the presentation into the session history cache.
4721
    nsCOMPtr<nsIDOMEventReceiver> er = do_QueryInterface(mScriptGlobal);
4722
    if (er) {
4723
        nsCOMPtr<nsIEventListenerManager> eventManager;
4724
        er->GetListenerManager(getter_AddRefs(eventManager));
4725
4726
        if (eventManager && eventManager->HasUnloadListeners())
4727
            return PR_FALSE;
4728
    }
4729
4730
    // If the session history entry has the saveLayoutState flag set to false,
4731
    // then we should not cache the presentation.
4732
4733
    if (!mOSHE)
4734
        return PR_FALSE; // no entry to save into
4735
4736
    PRBool canSaveState;
4737
    mOSHE->GetSaveLayoutStateFlag(&canSaveState);
4738
    return canSaveState;
4739
}
4740
4741
// CaptureState() is called when saving presentation into session history,
4742
// before any teardown of the document or content viewer.
4743
4744
nsresult
4745
nsDocShell::CaptureState()
4746
{
4747
    nsCOMPtr<nsPIDOMWindow> privWin = do_QueryInterface(mScriptGlobal);
4748
    if (!privWin || !mOSHE)
4749
        return NS_ERROR_FAILURE;
4750
4751
    nsCOMPtr<nsISupports> windowState;
4752
    nsresult rv = privWin->SaveWindowState(getter_AddRefs(windowState));
4753
    NS_ENSURE_SUCCESS(rv, rv);
4754
4755
#ifdef DEBUG_PAGE_CACHE
4756
    nsCOMPtr<nsIURI> uri;
4757
    mOSHE->GetURI(getter_AddRefs(uri));
4758
    nsCAutoString spec;
4759
    if (uri)
4760
        uri->GetSpec(spec);
4761
    printf("Saving presentation into session history\n");
4762
    printf("  SH URI: %s\n", spec.get());
4763
#endif
4764
4765
    rv = mOSHE->SetWindowState(windowState);
4766
    NS_ENSURE_SUCCESS(rv, rv);
4767
4768
    nsCOMPtr<nsIPresShell> shell;
4769
    nsDocShell::GetPresShell(getter_AddRefs(shell));
4770
    if (shell) {
4771
        nsIViewManager *vm = shell->GetViewManager();
4772
        if (vm) {
4773
            nsIView *rootView = nsnull;
4774
            vm->GetRootView(rootView);
4775
            if (rootView) {
4776
                nsIWidget *widget = rootView->GetWidget();
4777
                if (widget) {
4778
                    nsRect bounds(0, 0, 0, 0);
4779
                    widget->GetBounds(bounds);
4780
                    rv = mOSHE->SetViewerBounds(bounds);
4781
                }
4782
            }
4783
        }
4784
    }
4785
4786
    // Capture the docshell hierarchy
4787
    PRInt32 childCount = mChildList.Count();
4788
    nsCOMPtr<nsIDocShellTreeItem> childShell;
4789
    mOSHE->ClearChildShells();
4790
4791
    for (PRInt32 i = 0; i < childCount; ++i) {
4792
        childShell = do_QueryInterface(ChildAt(i));
4793
        NS_ASSERTION(childShell, "null child shell");
4794
4795
        mOSHE->AddChildShell(childShell);
4796
    }
4797
4798
    return rv;
4799
}
4800
4801
nsresult
4802
nsDocShell::RestorePresentation(nsIURI *aURI, nsISHEntry *aSHEntry)
4803
{
4804
    nsCOMPtr<nsIContentViewer> viewer;
4805
    aSHEntry->GetContentViewer(getter_AddRefs(viewer));
4806
4807
#ifdef DEBUG_PAGE_CACHE
4808
    nsCAutoString spec;
4809
    if (aURI)
4810
        aURI->GetSpec(spec);
4811
#endif
4812
4813
    if (!viewer) {
4814
#ifdef DEBUG_PAGE_CACHE
4815
        printf("no saved presentation for uri: %s\n", spec.get());
4816
#endif
4817
        return NS_ERROR_FAILURE;
4818
    }
4819
4820
    NS_ASSERTION(mContentViewer != viewer, "Restoring existing presentation");
4821
4822
#ifdef DEBUG_PAGE_CACHE
4823
    printf("restoring presentation from session history: %s\n", spec.get());
4824
#endif
4825
4826
    // Save off the root view's parent and sibling so that we can insert the
4827
    // new content viewer's root view at the same position.  Also save the
4828
    // bounds of the root view's widget.
4829
4830
    nsIView *rootViewSibling = nsnull, *rootViewParent = nsnull;
4831
    nsRect newBounds(0, 0, 0, 0);
4832
4833
    nsCOMPtr<nsIPresShell> oldPresShell;
4834
    nsDocShell::GetPresShell(getter_AddRefs(oldPresShell));
4835
    if (oldPresShell) {
4836
        nsIViewManager *vm = oldPresShell->GetViewManager();
4837
        if (vm) {
4838
            nsIView *oldRootView = nsnull;
4839
            vm->GetRootView(oldRootView);
4840
4841
            if (oldRootView) {
4842
                rootViewSibling = oldRootView->GetNextSibling();
4843
                rootViewParent = oldRootView->GetParent();
4844
4845
                nsIWidget *widget = oldRootView->GetWidget();
4846
                if (widget) {
4847
                    widget->GetBounds(newBounds);
4848
                }
4849
            }
4850
        }
4851
    }
4852
4853
    // Transfer ownership to mContentViewer.  By ensuring that either the
4854
    // docshell or the session history, but not both, have references to the
4855
    // content viewer, we prevent the viewer from being torn down after
4856
    // Destroy() is called.
4857
4858
    PRBool savePresentation = CanSavePresentation();
4859
    if (!savePresentation)
4860
        FireUnloadNotification();
4861
4862
    mFiredUnloadEvent = PR_FALSE;
4863
4864
    if (mContentViewer) {
4865
        mContentViewer->Close();
4866
4867
        if (savePresentation)
4868
            mContentViewer->SetHistoryEntry(mOSHE);
4869
4870
        mContentViewer->Destroy();
4871
    }
4872
4873
    mContentViewer.swap(viewer);
4874
    viewer = nsnull; // force a release to complete ownership transfer
4875
4876
    // Pulling the viewer out of the CachedPresentation will thaw() it.
4877
    // We must first open it to prevent pending destruction.
4878
    nsresult rv = mContentViewer->Open();
4879
    NS_ENSURE_SUCCESS(rv, rv);
4880
4881
    // Now remove it from the cached presentation.
4882
    aSHEntry->SetContentViewer(nsnull);
4883
4884
    // Restore our child docshell hierarchy.
4885
    PRInt32 i = 0;
4886
    nsCOMPtr<nsIDocShellTreeItem> childShell;
4887
4888
    DestroyChildren();
4889
    while (NS_SUCCEEDED(aSHEntry->ChildShellAt(i++,
4890
                                               getter_AddRefs(childShell))) &&
4891
           childShell) {
4892
        AddChild(childShell);
4893
    }
4894
4895
    // And release the references in the history entry.
4896
    aSHEntry->ClearChildShells();
4897
4898
    // restore the sticky state of the viewer
4899
    PRBool sticky;
4900
    aSHEntry->GetSticky(&sticky);
4901
    mContentViewer->SetSticky(sticky);
4902
4903
    // save the previous content viewer size
4904
    nsRect oldBounds(0, 0, 0, 0);
4905
    aSHEntry->GetViewerBounds(oldBounds);
4906
4907
    // Insert the new root view at the correct location in the view tree.
4908
    if (rootViewParent) {
4909
        nsIViewManager *parentVM = rootViewParent->GetViewManager();
4910
4911
        nsCOMPtr<nsIPresShell> shell;
4912
        nsDocShell::GetPresShell(getter_AddRefs(shell));
4913
4914
        if (parentVM && shell) {
4915
            nsIViewManager *newVM = shell->GetViewManager();
4916
            if (newVM) {
4917
                nsIView *newRootView = nsnull;
4918
                newVM->GetRootView(newRootView);
4919
                if (newRootView) {
4920
                    parentVM->InsertChild(rootViewParent, newRootView,
4921
                                          rootViewSibling, PR_TRUE);
4922
4923
                    NS_ASSERTION(newRootView->GetNextSibling() ==
4924
                                 rootViewSibling,
4925
                                 "error in InsertChild");
4926
4927
                    if (oldPresShell)
4928
                        oldPresShell->InvalidateViewManagers();
4929
                }
4930
            }
4931
        }
4932
    }
4933
4934
    // restore the state of the window object
4935
    nsCOMPtr<nsPIDOMWindow> privWin =
4936
        do_GetInterface(NS_STATIC_CAST(nsIInterfaceRequestor*, this));
4937
    NS_ASSERTION(privWin, "could not get nsPIDOMWindow interface");
4938
4939
    nsCOMPtr<nsISupports> windowState;
4940
    aSHEntry->GetWindowState(getter_AddRefs(windowState));
4941
4942
    rv = privWin->RestoreWindowState(windowState);
4943
    NS_ENSURE_SUCCESS(rv, rv);
4944
4945
    aSHEntry->SetWindowState(nsnull);
4946
4947
    mOSHE = aSHEntry;
4948
    EndPageLoad(nsnull, nsnull, NS_OK);
4949
4950
    nsCOMPtr<nsISHistory> rootSH;
4951
    GetRootSessionHistory(getter_AddRefs(rootSH));
4952
    if (rootSH && (mLoadType & LOAD_CMD_HISTORY)) {
4953
        nsCOMPtr<nsISHistoryInternal> hist = do_QueryInterface(rootSH);
4954
        hist->UpdateIndex();
4955
    }
4956
4957
    // Make sure this presentation is the same size as the previous
4958
    // presentation.  If this is not the same size we showed it at last time,
4959
    // then we need to resize the widget.
4960
4961
    // XXXbryner   This interacts poorly with Firefox's infobar.  If the old
4962
    // presentation had the infobar visible, then we will resize the new
4963
    // presentation to that smaller size.  However, firing the locationchanged
4964
    // event will hide the infobar, which will immediately resize the window
4965
    // back to the larger size.  A future optimization might be to restore
4966
    // the presentation at the "wrong" size, then fire the locationchanged
4967
    // event and check whether the docshell's new size is the same as the
4968
    // cached viewer size (skipping the resize if they are equal).
4969
4970
    nsCOMPtr<nsIPresShell> shell;
4971
    nsDocShell::GetPresShell(getter_AddRefs(shell));
4972
4973
    if (shell) {
4974
        nsIViewManager *vm = shell->GetViewManager();
4975
        if (vm) {
4976
            nsIView *rootView = nsnull;
4977
            vm->GetRootView(rootView);
4978
4979
            if (rootView) {
4980
                nsIWidget *widget = rootView->GetWidget();
4981
                if (widget && !newBounds.IsEmpty()) {
4982
#ifdef DEBUG_PAGE_CACHE
4983
                    printf("resize widget(%d, %d, %d, %d)\n", newBounds.x,
4984
                           newBounds.y, newBounds.width, newBounds.height);
4985
#endif
4986
4987
                    widget->Resize(newBounds.x, newBounds.y, newBounds.width,
4988
                                   newBounds.height, PR_FALSE);
4989
                }
4990
            }
4991
        }
4992
    }
4993
4994
    SetCurrentURI(aURI);
4995
4996
    // Dispatch events.  This is a little messy.  We need to avoid firing
4997
    // onload so that it is visible from the content DOM window, but we _do_
4998
    // want the chrome to see it for chrome/extensions that look for page load.
4999
    // In addition, we need to fire DOMPageRestore on the content window.
5000
5001
    nsEvent event(NS_PAGE_LOAD);
5002
    nsEventStatus status = nsEventStatus_eIgnore;
5003
5004
    nsCOMPtr<nsIChromeEventHandler> handler = privWin->GetChromeEventHandler();
5005
5006
    nsCOMPtr<nsPresContext> presContext;
5007
    GetPresContext(getter_AddRefs(presContext));
5008
5009
    PRUint32 flags = NS_EVENT_FLAG_INIT;
5010
    event.flags |= flags;
5011
    flags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
5012
    flags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
5013
5014
    nsIDOMEvent *domEvt = nsnull;
5015
5016
    rv = handler->HandleChromeEvent(presContext, &event, &domEvt,
5017
                                    flags & NS_EVENT_CAPTURE_MASK, &status);
5018
    NS_ENSURE_SUCCESS(rv, rv);
5019
5020
    if (domEvt) {
5021
        nsrefcnt rc;
5022
        NS_RELEASE2(domEvt, rc);
5023
        if (0 != rc) {
5024
            // Okay, so someone in the DOM loop (a listener, JS object)
5025
            // still has a ref to the DOM Event but the internal data
5026
            // hasn't been malloc'd.  Force a copy of the data here so the
5027
            // DOM Event is still valid.
5028
5029
            nsCOMPtr<nsIPrivateDOMEvent> privateEvent =
5030
                do_QueryInterface(domEvt);
5031
5032
            if (privateEvent) {
5033
                privateEvent->DuplicatePrivateData();
5034
            }
5035
        }
5036
    }
5037
5038
    if (mScriptGlobal) {
5039
        nsEventStatus status = nsEventStatus_eIgnore;
5040
        nsEvent restoreEvent(NS_PAGE_RESTORE);
5041
5042
        nsCOMPtr<nsPresContext> presContext;
5043
        nsDocShell::GetPresContext(getter_AddRefs(presContext));
5044
5045
        if (presContext) {
5046
            mScriptGlobal->HandleDOMEvent(presContext, &restoreEvent, nsnull,
5047
                                          NS_EVENT_FLAG_INIT, &status);
5048
        }
5049
    }
5050
5051
    rv = mContentViewer->Show();
5052
    NS_ENSURE_SUCCESS(rv, rv);
5053
5054
    // Restart plugins
5055
    if (shell)
5056
        shell->StartPlugins();
5057
5058
    // XXXbryner  Making this invalidate synchronous causes unpainted areas
5059
    // (on Mac, at least) if the above locationchanged event hides Firefox's
5060
    // infobar.  Doing it asynchronously seems to work around the problem, but
5061
    // shouldn't the style change that hides the infobar handle all necessary
5062
    // invalidation, including the newly-exposed area?
5063
5064
    return mParentWidget->Invalidate(PR_FALSE);
5065
}
5066
4704
NS_IMETHODIMP
5067
NS_IMETHODIMP
4705
nsDocShell::CreateContentViewer(const char *aContentType,
5068
nsDocShell::CreateContentViewer(const char *aContentType,
4706
                                nsIRequest * request,
5069
                                nsIRequest * request,
 Lines 4727-4733   nsDocShell::CreateContentViewer(const ch Link Here 
4727
    // is changed within the DocShell - otherwise, javascript will get the
5090
    // is changed within the DocShell - otherwise, javascript will get the
4728
    // wrong information :-(
5091
    // wrong information :-(
4729
    //
5092
    //
4730
    (void) FireUnloadNotification();
5093
5094
    PRBool savePresentation = CanSavePresentation();
5095
    if (!savePresentation)
5096
        FireUnloadNotification();
4731
5097
4732
    // Set mFiredUnloadEvent = PR_FALSE so that the unload handler for the
5098
    // Set mFiredUnloadEvent = PR_FALSE so that the unload handler for the
4733
    // *new* document will fire.
5099
    // *new* document will fire.
 Lines 4742-4747   nsDocShell::CreateContentViewer(const ch Link Here 
4742
5108
4743
    PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE);
5109
    PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE);
4744
5110
5111
    if (savePresentation) {
5112
        // The old content viewer will be saved during the call to Embed().
5113
        rv = CaptureState();
5114
        // XXX this isn't really fatal, necessarily...
5115
        // should we try to fire unload if NS_FAILED(rv) ?
5116
    }
5117
4745
    // let's try resetting the load group if we need to...
5118
    // let's try resetting the load group if we need to...
4746
    nsCOMPtr<nsILoadGroup> currentLoadGroup;
5119
    nsCOMPtr<nsILoadGroup> currentLoadGroup;
4747
    NS_ENSURE_SUCCESS(aOpenedChannel->
5120
    NS_ENSURE_SUCCESS(aOpenedChannel->
 Lines 5005-5010   nsDocShell::SetupNewViewer(nsIContentVie Link Here 
5005
5378
5006
    // Ensure that the content viewer is destroyed *after* the GC - bug 71515
5379
    // Ensure that the content viewer is destroyed *after* the GC - bug 71515
5007
    nsCOMPtr<nsIContentViewer> kungfuDeathGrip = mContentViewer;
5380
    nsCOMPtr<nsIContentViewer> kungfuDeathGrip = mContentViewer;
5381
    nsCOMPtr<nsIDOMDocument> oldDocument;
5008
    if (mContentViewer) {
5382
    if (mContentViewer) {
5009
        // Stop any activity that may be happening in the old document before
5383
        // Stop any activity that may be happening in the old document before
5010
        // releasing it...
5384
        // releasing it...
 Lines 5030-5037   nsDocShell::SetupNewViewer(nsIContentVie Link Here 
5030
            }
5404
            }
5031
        }
5405
        }
5032
5406
5407
        mContentViewer->GetDOMDocument(getter_AddRefs(oldDocument));
5408
5033
        mContentViewer->Close();
5409
        mContentViewer->Close();
5034
        aNewViewer->SetPreviousViewer(mContentViewer);
5410
        aNewViewer->SetPreviousViewer(mContentViewer);
5411
5412
        if (CanSavePresentation()) {
5413
            // Tell the old content viewer to hibernate in session history when
5414
            // it is destroyed.
5415
            mContentViewer->SetHistoryEntry(mOSHE);
5416
        }
5417
5035
        mContentViewer = nsnull;
5418
        mContentViewer = nsnull;
5036
    }
5419
    }
5037
5420
 Lines 5572-5578   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5572
                NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
5955
                NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
5573
                nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
5956
                nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(hEntry));
5574
                if (shEntry)
5957
                if (shEntry)
5575
                    shEntry->SetTitle(mTitle.get());
5958
                    shEntry->SetTitle(mTitle);
5576
            }
5959
            }
5577
5960
5578
            return NS_OK;
5961
            return NS_OK;
 Lines 5627-5632   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
5627
    // been called.
6010
    // been called.
5628
    mLSHE = aSHEntry;
6011
    mLSHE = aSHEntry;
5629
6012
6013
    // If we have a saved content viewer in history, restore and show it now.
6014
    if (aSHEntry) {
6015
        if (!CanSavePresentation())
6016
            FireUnloadNotification();
6017
6018
        mFiredUnloadEvent = PR_FALSE;
6019
6020
        CaptureState();
6021
6022
        rv = RestorePresentation(aURI, aSHEntry);
6023
        if (NS_SUCCEEDED(rv))
6024
            return rv;
6025
    }
6026
5630
    nsCOMPtr<nsIRequest> req;
6027
    nsCOMPtr<nsIRequest> req;
5631
    rv = DoURILoad(aURI, aReferrer,
6028
    rv = DoURILoad(aURI, aReferrer,
5632
                   !(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER),
6029
                   !(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER),
 Lines 6524-6535   nsDocShell::AddToSessionHistory(nsIURI * Link Here 
6524
    }
6921
    }
6525
6922
6526
    //Title is set in nsDocShell::SetTitle()
6923
    //Title is set in nsDocShell::SetTitle()
6527
    entry->Create(aURI,         // uri
6924
    entry->Create(aURI,              // uri
6528
                  nsnull,       // Title
6925
                  EmptyString(),     // Title
6529
                  nsnull,       // DOMDocument
6926
                  inputStream,       // Post data stream
6530
                  inputStream,  // Post data stream
6927
                  nsnull,            // LayoutHistory state
6531
                  nsnull,       // LayoutHistory state
6928
                  cacheKey,          // CacheKey
6532
                  cacheKey,     // CacheKey
6533
                  mContentTypeHint); // Content-type
6929
                  mContentTypeHint); // Content-type
6534
    entry->SetReferrerURI(referrerURI);
6930
    entry->SetReferrerURI(referrerURI);
6535
    /* If cache got a 'no-store', ask SH not to store
6931
    /* If cache got a 'no-store', ask SH not to store
 Lines 6560-6566   nsDocShell::AddToSessionHistory(nsIURI * Link Here 
6560
        if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {            
6956
        if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {            
6561
            // Replace current entry in session history.
6957
            // Replace current entry in session history.
6562
            PRInt32  index = 0;   
6958
            PRInt32  index = 0;   
6563
            nsCOMPtr<nsIHistoryEntry> hEntry;
6564
            mSessionHistory->GetIndex(&index);
6959
            mSessionHistory->GetIndex(&index);
6565
            nsCOMPtr<nsISHistoryInternal>   shPrivate(do_QueryInterface(mSessionHistory));
6960
            nsCOMPtr<nsISHistoryInternal>   shPrivate(do_QueryInterface(mSessionHistory));
6566
            // Replace the current entry with the new entry
6961
            // Replace the current entry with the new entry
 Lines 6605-6614   nsDocShell::LoadHistoryEntry(nsISHEntry Link Here 
6605
    nsCAutoString contentType;
7000
    nsCAutoString contentType;
6606
7001
6607
    NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
7002
    NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE);
6608
    nsCOMPtr<nsIHistoryEntry> hEntry(do_QueryInterface(aEntry));
6609
    NS_ENSURE_TRUE(hEntry, NS_ERROR_FAILURE);
6610
7003
6611
    NS_ENSURE_SUCCESS(hEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
7004
    NS_ENSURE_SUCCESS(aEntry->GetURI(getter_AddRefs(uri)), NS_ERROR_FAILURE);
6612
    NS_ENSURE_SUCCESS(aEntry->GetReferrerURI(getter_AddRefs(referrerURI)),
7005
    NS_ENSURE_SUCCESS(aEntry->GetReferrerURI(getter_AddRefs(referrerURI)),
6613
                      NS_ERROR_FAILURE);
7006
                      NS_ERROR_FAILURE);
6614
    NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
7007
    NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)),
 Lines 6703-6711   nsDocShell::CloneAndReplace(nsISHEntry * Link Here 
6703
    nsISHEntry *dest = (nsISHEntry *) nsnull;
7096
    nsISHEntry *dest = (nsISHEntry *) nsnull;
6704
    PRUint32 srcID;
7097
    PRUint32 srcID;
6705
    src->GetID(&srcID);
7098
    src->GetID(&srcID);
6706
    nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(src));
6707
7099
6708
    if (!src || !replaceEntry || !srcHE)
7100
    if (!src || !replaceEntry)
6709
        return NS_ERROR_FAILURE;
7101
        return NS_ERROR_FAILURE;
6710
7102
6711
    if (srcID == aCloneID) {
7103
    if (srcID == aCloneID) {
(-)docshell/base/nsDocShell.h (+4 lines)
Line     Link Here 
 Lines 395-400   protected: Link Here 
395
    PRBool SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
395
    PRBool SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
396
                         PRBool aFireOnLocationChange);
396
                         PRBool aFireOnLocationChange);
397
397
398
    PRBool CanSavePresentation();
399
    nsresult CaptureState();
400
    nsresult RestorePresentation(nsIURI *aURI, nsISHEntry *aSHEntry);
401
398
protected:
402
protected:
399
    // Override the parent setter from nsDocLoader
403
    // Override the parent setter from nsDocLoader
400
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
404
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
(-)docshell/base/nsIContentViewer.idl (+18 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 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
87
   */
88
  void setHistoryEntry(in nsISHEntry entry);
71
};
89
};
(-)dom/public/base/nsPIDOMWindow.h (+12 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.
149
  virtual nsresult SaveWindowState(nsISupports **aState) = 0;
150
151
  // Restore the window state from aState.
152
  virtual nsresult RestoreWindowState(nsISupports *aState) = 0;
153
142
protected:
154
protected:
143
  nsPIDOMWindow()
155
  nsPIDOMWindow()
144
    : mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE),
156
    : 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 / +335 lines)
Line     Link Here 
 Lines 153-158    Link Here 
153
153
154
#include "nsIBindingManager.h"
154
#include "nsIBindingManager.h"
155
#include "nsIXBLService.h"
155
#include "nsIXBLService.h"
156
#include "nsIDOMNSHTMLElement.h"
157
#include "nsIDOMXULElement.h"
156
158
157
// used for popup blocking, needs to be converted to something
159
// used for popup blocking, needs to be converted to something
158
// belonging to the back-end like nsIContentPolicy
160
// belonging to the back-end like nsIContentPolicy
 Lines 171-176   static PRInt32 gRunningTime Link Here 
171
PRInt32 gTimeoutCnt                                    = 0;
173
PRInt32 gTimeoutCnt                                    = 0;
172
#endif
174
#endif
173
175
176
#ifdef DEBUG_bryner
177
#define DEBUG_PAGE_CACHE
178
#endif
179
174
#define DOM_MIN_TIMEOUT_VALUE 10 // 10ms
180
#define DOM_MIN_TIMEOUT_VALUE 10 // 10ms
175
181
176
// CIDs
182
// CIDs
 Lines 4272-4281   nsGlobalWindow::GetPrivateRoot() Link Here 
4272
    nsIDocument* doc = chromeElement->GetDocument();
4278
    nsIDocument* doc = chromeElement->GetDocument();
4273
    if (doc) {
4279
    if (doc) {
4274
      parent = do_QueryInterface(doc->GetScriptGlobalObject());
4280
      parent = do_QueryInterface(doc->GetScriptGlobalObject());
4275
      nsCOMPtr<nsIDOMWindow> tempParent;
4281
      if (parent) {
4276
      parent->GetTop(getter_AddRefs(tempParent));
4282
        nsCOMPtr<nsIDOMWindow> tempParent;
4277
      return NS_STATIC_CAST(nsGlobalWindow *,
4283
        parent->GetTop(getter_AddRefs(tempParent));
4278
                            NS_STATIC_CAST(nsIDOMWindow*, tempParent));
4284
        return NS_STATIC_CAST(nsGlobalWindow *,
4285
                              NS_STATIC_CAST(nsIDOMWindow*, tempParent));
4286
      }
4279
    }
4287
    }
4280
  }
4288
  }
4281
4289
 Lines 5740-5745   nsGlobalWindow::EnsureSizeUpToDate() Link Here 
5740
  }
5748
  }
5741
}
5749
}
5742
5750
5751
#define WINDOWSTATEHOLDER_IID \
5752
{0xae1c7401, 0xcdee, 0x404a, {0xbd, 0x63, 0x05, 0xc0, 0x35, 0x0d, 0xa7, 0x72}}
5753
5754
class WindowStateHolder : public nsISupports
5755
{
5756
public:
5757
  NS_DEFINE_STATIC_IID_ACCESSOR(WINDOWSTATEHOLDER_IID)
5758
  NS_DECL_ISUPPORTS
5759
5760
  WindowStateHolder(JSContext *cx, JSObject *aObject, nsGlobalWindow *aWindow);
5761
5762
  JSObject* GetObject() { return mJSObj; }
5763
  nsIEventListenerManager* GetListenerManager() { return mListenerManager; }
5764
  nsIDOMElement* GetFocusedElement() { return mFocusedElement; }
5765
  nsIDOMWindowInternal* GetFocusedWindow() { return mFocusedWindow; }
5766
  nsTimeout* GetSavedTimeouts() { return mSavedTimeouts; }
5767
  void ClearSavedTimeouts() { mSavedTimeouts = nsnull; }
5768
5769
private:
5770
  ~WindowStateHolder();
5771
5772
  JSRuntime *mRuntime;
5773
  JSObject *mJSObj;
5774
  nsCOMPtr<nsIEventListenerManager> mListenerManager;
5775
  nsCOMPtr<nsIDOMElement> mFocusedElement;
5776
  nsCOMPtr<nsIDOMWindowInternal> mFocusedWindow;
5777
  nsTimeout *mSavedTimeouts;
5778
};
5779
5780
WindowStateHolder::WindowStateHolder(JSContext *cx, JSObject *aObject,
5781
                                     nsGlobalWindow *aWindow)
5782
  : mRuntime(::JS_GetRuntime(cx)), mJSObj(aObject), mSavedTimeouts(nsnull)
5783
{
5784
  NS_ASSERTION(aWindow, "null window");
5785
5786
  aWindow->GetListenerManager(getter_AddRefs(mListenerManager));
5787
5788
  nsIFocusController *fc = aWindow->GetRootFocusController();
5789
  NS_ASSERTION(fc, "null focus controller");
5790
5791
  // We want to save the focused element/window only if they are inside of
5792
  // this window.
5793
5794
  nsCOMPtr<nsIDOMWindowInternal> focusWinInternal;
5795
  fc->GetFocusedWindow(getter_AddRefs(focusWinInternal));
5796
5797
  nsPIDOMWindow *focusedWindow =
5798
    NS_STATIC_CAST(nsPIDOMWindow*,
5799
                   NS_STATIC_CAST(nsGlobalWindow*,
5800
                                  NS_STATIC_CAST(nsIDOMWindowInternal*,
5801
                                                 focusWinInternal)));
5802
5803
  while (focusedWindow) {
5804
    if (focusedWindow == aWindow) {
5805
      fc->GetFocusedWindow(getter_AddRefs(mFocusedWindow));
5806
      fc->GetFocusedElement(getter_AddRefs(mFocusedElement));
5807
      break;
5808
    }
5809
5810
    focusedWindow =
5811
      NS_STATIC_CAST(nsGlobalWindow*, focusedWindow)->GetPrivateParent();
5812
  }
5813
5814
  aWindow->SuspendTimeouts();
5815
5816
  // Clear the timeout list for aWindow (but we don't need to for children)
5817
  mSavedTimeouts = aWindow->mTimeouts;
5818
  aWindow->mTimeouts = nsnull;
5819
5820
  ::JS_AddNamedRoot(cx, &mJSObj, "WindowStateHolder::mJSObj");
5821
}
5822
5823
WindowStateHolder::~WindowStateHolder()
5824
{
5825
  ::JS_RemoveRootRT(mRuntime, &mJSObj);
5826
}
5827
5828
NS_IMPL_ISUPPORTS1(WindowStateHolder, WindowStateHolder)
5829
5830
static JSClass sWindowStateClass = {
5831
  "window state", 0,
5832
  JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
5833
  JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
5834
  JSCLASS_NO_OPTIONAL_MEMBERS
5835
};
5836
5837
static void
5838
CopyJSPropertyArray(JSContext *cx, JSObject *aSource, JSObject *aDest,
5839
                    JSIdArray *props)
5840
{
5841
  jsint length = props->length;
5842
  jsint i;
5843
  for (i = 0; i < length; ++i) {
5844
    jsval propname_value;
5845
5846
    if (!::JS_IdToValue(cx, props->vector[i], &propname_value) ||
5847
        !JSVAL_IS_STRING(propname_value)) {
5848
      NS_WARNING("Failed to copy non-string window property\n");
5849
      continue;
5850
    }
5851
5852
    char *propname_str = ::JS_GetStringBytes(JSVAL_TO_STRING(propname_value));
5853
5854
    uintN attrs;
5855
    JSBool found;
5856
    if (!::JS_GetPropertyAttributes(cx, aSource, propname_str, &attrs, &found))
5857
      continue;
5858
5859
    if (!found)
5860
      continue;
5861
5862
    jsval propvalue;
5863
    if (!::JS_GetProperty(cx, aSource, propname_str, &propvalue)) {
5864
      NS_WARNING("property was found, but get failed");
5865
      continue;
5866
    }
5867
5868
    PRBool res = ::JS_DefineProperty(cx, aDest, propname_str, propvalue,
5869
                                     NULL, NULL, attrs);
5870
#ifdef DEBUG_PAGE_CACHE
5871
    if (res)
5872
      printf("Copied window property: %s\n", propname_str);
5873
#endif
5874
5875
#ifdef DEBUG
5876
    if (!res)
5877
      printf("failed to copy property: %s\n", propname_str);
5878
#endif
5879
  }
5880
}
5881
5882
static void
5883
CopyJSProperties(JSContext *cx, JSObject *aSource, JSObject *aDest)
5884
{
5885
  // Enumerate all of the properties on aSource and install them on aDest.
5886
5887
  JSIdArray *props = ::JS_Enumerate(cx, aSource);
5888
  if (!props) {
5889
#ifdef DEBUG_PAGE_CACHE
5890
    printf("[no properties]\n");
5891
#endif
5892
    return;
5893
  }
5894
5895
#ifdef DEBUG_PAGE_CACHE
5896
  printf("props length = %d\n", props->length);
5897
#endif
5898
5899
  CopyJSPropertyArray(cx, aSource, aDest, props);
5900
  ::JS_DestroyIdArray(cx, props);
5901
}
5902
5903
nsresult
5904
nsGlobalWindow::SaveWindowState(nsISupports **aState)
5905
{
5906
  *aState = nsnull;
5907
5908
  if (!mContext || !mJSObject) {
5909
    // The window may be getting torn down; don't bother saving state.
5910
    return NS_OK;
5911
  }
5912
5913
  JSContext *cx = NS_STATIC_CAST(JSContext*, mContext->GetNativeContext());
5914
  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
5915
5916
  JSObject *stateObj = ::JS_NewObject(cx, &sWindowStateClass, NULL, NULL);
5917
  NS_ENSURE_TRUE(stateObj, NS_ERROR_OUT_OF_MEMORY);
5918
5919
#ifdef DEBUG_PAGE_CACHE
5920
  printf("saving window state, stateObj = %p\n", stateObj);
5921
#endif
5922
  CopyJSProperties(cx, mJSObject, stateObj);
5923
5924
  *aState = new WindowStateHolder(cx, stateObj, this);
5925
  NS_ENSURE_TRUE(*aState, NS_ERROR_OUT_OF_MEMORY);
5926
5927
  NS_ADDREF(*aState);
5928
  return NS_OK;
5929
}
5930
5931
nsresult
5932
nsGlobalWindow::RestoreWindowState(nsISupports *aState)
5933
{
5934
  if (!mContext || !mJSObject) {
5935
    // The window may be getting torn down; don't bother restoring state.
5936
    return NS_OK;
5937
  }
5938
5939
  JSContext *cx = NS_STATIC_CAST(JSContext*, mContext->GetNativeContext());
5940
  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
5941
5942
  // Note that we don't need to call JS_ClearScope here.  The scope is already
5943
  // cleared by SetNewDocument(), and calling it again here will remove the
5944
  // XPConnect properties.
5945
5946
  nsCOMPtr<WindowStateHolder> holder = do_QueryInterface(aState);
5947
  if (holder) {
5948
#ifdef DEBUG_PAGE_CACHE
5949
    printf("restoring window state, stateObj = %p\n", holder->GetObject());
5950
#endif
5951
    CopyJSProperties(cx, holder->GetObject(), mJSObject);
5952
    mListenerManager = holder->GetListenerManager();
5953
5954
    nsIDOMElement *focusedElement = holder->GetFocusedElement();
5955
    if (focusedElement) {
5956
      nsCOMPtr<nsIDOMNSHTMLElement> htmlElement =
5957
        do_QueryInterface(focusedElement);
5958
      if (htmlElement) {
5959
        htmlElement->Focus();
5960
      } else {
5961
        nsCOMPtr<nsIDOMXULElement> xulElement =
5962
          do_QueryInterface(focusedElement);
5963
        if (xulElement) {
5964
          xulElement->Focus();
5965
        }
5966
      }
5967
    } else {
5968
      nsIDOMWindowInternal *focusedWindow = holder->GetFocusedWindow();
5969
      if (focusedWindow) {
5970
        focusedWindow->Focus();
5971
      }
5972
    }
5973
  }
5974
5975
  mTimeouts = holder->GetSavedTimeouts();
5976
  holder->ClearSavedTimeouts();
5977
5978
  return ResumeTimeouts();
5979
}
5980
5981
void
5982
nsGlobalWindow::SuspendTimeouts()
5983
{
5984
  PRInt64 now = PR_IntervalNow();
5985
  for (nsTimeout *t = mTimeouts; t; t = t->mNext) {
5986
    // For each non-interval timeout, we change mWhen to be the time remaining.
5987
    if (!t->mInterval)
5988
      t->mWhen = PR_MAX(0, t->mWhen - now);
5989
5990
    // Drop the XPCOM timer; we'll reschedule when restoring the state.
5991
    if (t->mTimer) {
5992
      t->mTimer->Cancel();
5993
      t->mTimer = nsnull;
5994
    }
5995
5996
    // We don't Release() the timeout because we still need it.
5997
  }
5998
5999
  // Suspend our children as well.
6000
  nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(mDocShell);
6001
  if (node) {
6002
    PRInt32 childCount = 0;
6003
    node->GetChildCount(&childCount);
6004
6005
    nsCOMPtr<nsIDocShellTreeItem> childShell;
6006
    for (PRInt32 i = 0; i < childCount; ++i) {
6007
      node->GetChildAt(i, getter_AddRefs(childShell));
6008
      NS_ASSERTION(childShell, "null child shell");
6009
6010
      nsCOMPtr<nsPIDOMWindow> pWin = do_GetInterface(childShell);
6011
      if (pWin) {
6012
        nsGlobalWindow *win =
6013
          NS_STATIC_CAST(nsGlobalWindow*,
6014
                         NS_STATIC_CAST(nsPIDOMWindow*, pWin));
6015
6016
        win->SuspendTimeouts();
6017
      }
6018
    }
6019
  }
6020
}
6021
6022
nsresult
6023
nsGlobalWindow::ResumeTimeouts()
6024
{
6025
  // Restore all of the timeouts.  Interval timeouts are rescheduled as before;
6026
  // non-interval timers are scheduled using the stored time remaining.
6027
6028
  PRInt64 now = PR_IntervalNow();
6029
  nsresult rv;
6030
6031
  for (nsTimeout *t = mTimeouts; t; t = t->mNext) {
6032
    PRInt32 interval;
6033
    if (t->mInterval) {
6034
      interval = t->mInterval;
6035
    } else {
6036
      interval = t->mWhen;
6037
      t->mWhen += now;
6038
    }
6039
6040
    t->mTimer = do_CreateInstance("@mozilla.org/timer;1");
6041
    NS_ENSURE_TRUE(t->mTimer, NS_ERROR_OUT_OF_MEMORY);
6042
6043
    rv = t->mTimer->InitWithFuncCallback(TimerCallback, t, interval,
6044
                                         nsITimer::TYPE_ONE_SHOT);
6045
    NS_ENSURE_SUCCESS(rv, rv);
6046
  }
6047
6048
  // Resume our children as well.
6049
  nsCOMPtr<nsIDocShellTreeNode> node = do_QueryInterface(mDocShell);
6050
  if (node) {
6051
    PRInt32 childCount = 0;
6052
    node->GetChildCount(&childCount);
6053
6054
    nsCOMPtr<nsIDocShellTreeItem> childShell;
6055
    for (PRInt32 i = 0; i < childCount; ++i) {
6056
      node->GetChildAt(i, getter_AddRefs(childShell));
6057
      NS_ASSERTION(childShell, "null child shell");
6058
6059
      nsCOMPtr<nsPIDOMWindow> pWin = do_GetInterface(childShell);
6060
      if (pWin) {
6061
        nsGlobalWindow *win =
6062
          NS_STATIC_CAST(nsGlobalWindow*,
6063
                         NS_STATIC_CAST(nsPIDOMWindow*, pWin));
6064
6065
        rv = win->ResumeTimeouts();
6066
        NS_ENSURE_SUCCESS(rv, rv);
6067
      }
6068
    }
6069
  }
6070
6071
  return NS_OK;
6072
}
6073
5743
// QueryInterface implementation for nsGlobalChromeWindow
6074
// QueryInterface implementation for nsGlobalChromeWindow
5744
NS_INTERFACE_MAP_BEGIN(nsGlobalChromeWindow)
6075
NS_INTERFACE_MAP_BEGIN(nsGlobalChromeWindow)
5745
  NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow)
6076
  NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow)
(-)dom/src/base/nsGlobalWindow.h (-1 / +7 lines)
Line     Link Here 
 Lines 199-205   public: Link Here 
199
  virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
199
  virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
200
200
201
  virtual NS_HIDDEN_(void) ClearAllTimeouts();
201
  virtual NS_HIDDEN_(void) ClearAllTimeouts();
202
  
202
  virtual NS_HIDDEN_(nsresult) SaveWindowState(nsISupports **aState);
203
  virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState);
204
  virtual NS_HIDDEN_(void) SuspendTimeouts();
205
  virtual NS_HIDDEN_(nsresult) ResumeTimeouts();
206
203
  // nsIDOMViewCSS
207
  // nsIDOMViewCSS
204
  NS_DECL_NSIDOMVIEWCSS
208
  NS_DECL_NSIDOMVIEWCSS
205
209
 Lines 215-220   public: Link Here 
215
  static void ShutDown();
219
  static void ShutDown();
216
  static PRBool IsCallerChrome();
220
  static PRBool IsCallerChrome();
217
221
222
  friend class WindowStateHolder;
223
218
protected:
224
protected:
219
  // Object Management
225
  // Object Management
220
  virtual ~nsGlobalWindow();
226
  virtual ~nsGlobalWindow();
(-)embedding/browser/cocoa/src/CHClickListener.mm (-16 / +18 lines)
Line     Link Here 
 Lines 203-230   CHClickListener::MouseDown(nsIDOMEvent* Link Here 
203
    nsCOMPtr<nsIScriptGlobalObject> sgo;
203
    nsCOMPtr<nsIScriptGlobalObject> sgo;
204
    doc->GetScriptGlobalObject(getter_AddRefs(sgo));
204
    doc->GetScriptGlobalObject(getter_AddRefs(sgo));
205
    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(sgo);
205
    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(sgo);
206
    PRInt32 scrollX, scrollY;
206
    if (window) {
207
    window->GetScrollX(&scrollX);
207
      PRInt32 scrollX, scrollY;
208
    window->GetScrollY(&scrollY);
208
      window->GetScrollX(&scrollX);
209
    xDelta += scrollX; // Normal direction.
209
      window->GetScrollY(&scrollY);
210
    yDelta -= scrollY; // Remember, y is flipped.
210
      xDelta += scrollX; // Normal direction.
211
      yDelta -= scrollY; // Remember, y is flipped.
211
    
212
    
212
#define XMENUOFFSET 20
213
#define XMENUOFFSET 20
213
#define MENUHEIGHT 20
214
#define MENUHEIGHT 20
214
    
215
    
215
    xDelta += XMENUOFFSET;
216
      xDelta += XMENUOFFSET;
216
    yDelta -= MENUHEIGHT*(selIndex+1);
217
      yDelta -= MENUHEIGHT*(selIndex+1);
217
    
218
    
218
    NSEvent* event = [NSApp currentEvent];
219
      NSEvent* event = [NSApp currentEvent];
219
    NSPoint point = [event locationInWindow];
220
      NSPoint point = [event locationInWindow];
220
    point.x -= xDelta;
221
      point.x -= xDelta;
221
    point.y -= yDelta;
222
      point.y -= yDelta;
222
223
223
    NSEvent* mouseEvent = [NSEvent mouseEventWithType: NSLeftMouseDown location: point
224
      NSEvent* mouseEvent = [NSEvent mouseEventWithType: NSLeftMouseDown location: point
224
                                        modifierFlags: 0 timestamp: [event timestamp]
225
                                          modifierFlags: 0 timestamp: [event timestamp]
225
                                         windowNumber: [event windowNumber] context: [event context]
226
                                           windowNumber: [event windowNumber] context: [event context]
226
                                          eventNumber: [event eventNumber] clickCount: [event clickCount] 																						 pressure: [event pressure]];
227
                                            eventNumber: [event eventNumber] clickCount: [event clickCount] 																						 pressure: [event pressure]];
227
    [NSMenu popUpContextMenu: menu withEvent: mouseEvent forView: [[event window] contentView]];
228
      [NSMenu popUpContextMenu: menu withEvent: mouseEvent forView: [[event window] contentView]];
229
    }
228
  }
230
  }
229
  return NS_OK;
231
  return NS_OK;
230
}
232
}
(-)embedding/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 1731-1736   nsXMLHttpRequest::Error(nsIDOMEvent* aEv Link Here 
1731
  return NS_OK;
1731
  return NS_OK;
1732
}
1732
}
1733
1733
1734
NS_IMETHODIMP
1735
nsXMLHttpRequest::PageRestore(nsIDOMEvent* aEvent)
1736
{
1737
  return NS_OK;
1738
}
1739
1734
nsresult
1740
nsresult
1735
nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast,
1741
nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast,
1736
                              PRBool aClearEventListeners)
1742
                              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 / +149 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 "nsView.h"
192
193
193
//paint forcing
194
//paint forcing
194
#include "prenv.h"
195
#include "prenv.h"
 Lines 346-352   protected: Link Here 
346
  virtual ~DocumentViewerImpl();
347
  virtual ~DocumentViewerImpl();
347
348
348
private:
349
private:
349
  void ForceRefresh(void);
350
  nsresult MakeWindow(nsIWidget* aParentWidget,
350
  nsresult MakeWindow(nsIWidget* aParentWidget,
351
                      const nsRect& aBounds);
351
                      const nsRect& aBounds);
352
  nsresult InitInternal(nsIWidget* aParentWidget,
352
  nsresult InitInternal(nsIWidget* aParentWidget,
 Lines 398-427   protected: Link Here 
398
  nsCOMPtr<nsIDOMFocusListener> mFocusListener;
398
  nsCOMPtr<nsIDOMFocusListener> mFocusListener;
399
399
400
  nsCOMPtr<nsIContentViewer> mPreviousViewer;
400
  nsCOMPtr<nsIContentViewer> mPreviousViewer;
401
401
  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
402
409
  nsIWidget* mParentWidget;          // purposely won't be ref counted
403
  nsIWidget* mParentWidget;          // purposely won't be ref counted
410
404
411
  PRPackedBool         mInPermitUnload;
405
  PRInt16 mNumURLStarts;
406
  PRInt16 mDestroyRefCount;    // a second "refcount" for the document viewer's "destroy"
407
408
  unsigned      mEnableRendering : 1;
409
  unsigned      mStopped : 1;
410
  unsigned      mLoaded : 1;
411
  unsigned      mDeferredWindowClose : 1;
412
  // document management data
413
  //   these items are specific to markup documents (html and xml)
414
  //   may consider splitting these out into a subclass
415
  unsigned      mIsSticky : 1;
416
  unsigned      mInPermitUnload : 1;
412
417
413
#ifdef NS_PRINTING
418
#ifdef NS_PRINTING
414
  PRPackedBool          mClosingWhilePrinting;
419
  unsigned      mClosingWhilePrinting : 1;
415
  nsPrintEngine*        mPrintEngine;
420
416
  nsCOMPtr<nsIDOMWindowInternal> mDialogParentWin;
417
#if NS_PRINT_PREVIEW
421
#if NS_PRINT_PREVIEW
418
  // These data member support delayed printing when the document is loading
422
  // These data members support delayed printing when the document is loading
423
  unsigned                         mPrintIsPending : 1;
424
  unsigned                         mPrintDocIsFullyLoaded : 1;
419
  nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
425
  nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
420
  nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
426
  nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
421
  PRPackedBool                     mPrintIsPending;
422
  PRPackedBool                     mPrintDocIsFullyLoaded;
423
#endif // NS_PRINT_PREVIEW
427
#endif // NS_PRINT_PREVIEW
424
428
429
  nsPrintEngine*        mPrintEngine;
430
  nsCOMPtr<nsIDOMWindowInternal> mDialogParentWin;
431
425
#ifdef NS_DEBUG
432
#ifdef NS_DEBUG
426
  FILE* mDebugFile;
433
  FILE* mDebugFile;
427
#endif // NS_DEBUG
434
#endif // NS_DEBUG
 Lines 434-443   protected: Link Here 
434
  nsCString mForceCharacterSet;
441
  nsCString mForceCharacterSet;
435
  nsCString mPrevDocCharacterSet;
442
  nsCString mPrevDocCharacterSet;
436
  
443
  
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
444
442
};
445
};
443
446
 Lines 494-501   void DocumentViewerImpl::PrepareToStartL Link Here 
494
// Note: operator new zeros our memory, so no need to init things to null.
497
// Note: operator new zeros our memory, so no need to init things to null.
495
DocumentViewerImpl::DocumentViewerImpl(nsPresContext* aPresContext)
498
DocumentViewerImpl::DocumentViewerImpl(nsPresContext* aPresContext)
496
  : mPresContext(aPresContext),
499
  : mPresContext(aPresContext),
497
    mHintCharsetSource(kCharsetUninitialized),
500
    mIsSticky(PR_TRUE),
498
    mIsSticky(PR_TRUE)
501
    mHintCharsetSource(kCharsetUninitialized)
499
{
502
{
500
  PrepareToStartLoad();
503
  PrepareToStartLoad();
501
}
504
}
 Lines 795-813   DocumentViewerImpl::InitInternal(nsIWidg Link Here 
795
      makeCX = PR_TRUE;
798
      makeCX = PR_TRUE;
796
#endif
799
#endif
797
    }
800
    }
798
  }
799
801
800
  if (aDoCreation && mPresContext) {
802
    if (mPresContext) {
801
    // Create the ViewManager and Root View...
803
      // Create the ViewManager and Root View...
802
804
803
    // We must do this before we tell the script global object about
805
      // 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
806
      // this new document since doing that will cause us to re-enter
805
    // into nsSubDocumentFrame code through reflows caused by
807
      // into nsSubDocumentFrame code through reflows caused by
806
    // FlushPendingNotifications() calls down the road...
808
      // FlushPendingNotifications() calls down the road...
807
809
808
    rv = MakeWindow(aParentWidget, aBounds);
810
      rv = MakeWindow(aParentWidget, aBounds);
809
    NS_ENSURE_SUCCESS(rv, rv);
811
      NS_ENSURE_SUCCESS(rv, rv);
810
    Hide();
812
      Hide();
813
    }
811
  }
814
  }
812
815
813
  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));
816
  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));
 Lines 1171-1176   DocumentViewerImpl::Unload() Link Here 
1171
}
1174
}
1172
1175
1173
NS_IMETHODIMP
1176
NS_IMETHODIMP
1177
DocumentViewerImpl::Open()
1178
{
1179
  NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
1180
1181
  nsRect bounds;
1182
  mWindow->GetBounds(bounds);
1183
1184
  nsresult rv = InitInternal(mParentWidget, mDeviceContext, bounds,
1185
                             PR_FALSE, PR_FALSE);
1186
  NS_ENSURE_SUCCESS(rv, rv);
1187
1188
  SyncParentSubDocMap();
1189
1190
  // XXX re-enable image animations once that works correctly
1191
1192
  return NS_OK;
1193
}
1194
1195
NS_IMETHODIMP
1174
DocumentViewerImpl::Close()
1196
DocumentViewerImpl::Close()
1175
{
1197
{
1176
  // All callers are supposed to call close to break circular
1198
  // 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
1206
  // for an object that can be switched in and out so that we don't need
1185
  // to disable scripts during paint suppression.
1207
  // to disable scripts during paint suppression.
1186
1208
1187
  if (mDocument) {
1209
  if (!mDocument)
1210
    return NS_OK;
1211
1188
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
1212
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
1189
    // Turn scripting back on
1213
  // Turn scripting back on
1190
    // after PrintPreview had turned it off
1214
  // after PrintPreview had turned it off
1191
    if (GetIsPrintPreview() && mPrintEngine) {
1215
  if (GetIsPrintPreview() && mPrintEngine) {
1192
      mPrintEngine->TurnScriptingOn(PR_TRUE);
1216
    mPrintEngine->TurnScriptingOn(PR_TRUE);
1193
    }
1217
  }
1194
#endif
1218
#endif
1195
1219
1196
    // Break global object circular reference on the document created
1220
  // Break global object circular reference on the document created
1197
    // in the DocViewer Init
1221
  // in the DocViewer Init
1198
    nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();
1222
  nsIScriptGlobalObject* globalObject = mDocument->GetScriptGlobalObject();
1199
1223
1200
    if (globalObject) {
1224
  if (globalObject) {
1201
      globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);
1225
    globalObject->SetNewDocument(nsnull, PR_TRUE, PR_TRUE);
1202
    }
1226
  }
1203
1227
1204
#ifdef NS_PRINTING
1228
#ifdef NS_PRINTING
1205
    // A Close was called while we were printing
1229
  // A Close was called while we were printing
1206
    // so don't clear the ScriptGlobalObject
1230
  // so don't clear the ScriptGlobalObject
1207
    // or clear the mDocument below
1231
  // or clear the mDocument below
1208
    // Also, do an extra addref to keep the viewer from going away.
1232
  // Also, do an extra addref to keep the viewer from going away.
1209
    if (mPrintEngine && !mClosingWhilePrinting) {
1233
  if (mPrintEngine && !mClosingWhilePrinting) {
1210
      mClosingWhilePrinting = PR_TRUE;
1234
    mClosingWhilePrinting = PR_TRUE;
1211
      NS_ADDREF_THIS();
1235
    NS_ADDREF_THIS();
1212
    } else {
1236
  } else {
1213
      // out of band cleanup of webshell
1237
    // out of band cleanup of webshell
1214
      mDocument->SetScriptGlobalObject(nsnull);
1215
    }
1216
#else
1217
    mDocument->SetScriptGlobalObject(nsnull);
1238
    mDocument->SetScriptGlobalObject(nsnull);
1239
  }
1240
#else
1241
  mDocument->SetScriptGlobalObject(nsnull);
1218
#endif
1242
#endif
1219
1243
1220
    if (mFocusListener) {
1244
  if (mFocusListener) {
1221
      // get the DOM event receiver
1245
    // get the DOM event receiver
1222
      nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
1246
    nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));
1223
      NS_WARN_IF_FALSE(erP, "No event receiver in document!");
1247
    NS_WARN_IF_FALSE(erP, "No event receiver in document!");
1224
1248
1225
      if (erP) {
1249
    if (erP) {
1226
        erP->RemoveEventListenerByIID(mFocusListener,
1250
      erP->RemoveEventListenerByIID(mFocusListener,
1227
                                      NS_GET_IID(nsIDOMFocusListener));
1251
                                    NS_GET_IID(nsIDOMFocusListener));
1228
      }
1229
    }
1252
    }
1230
  }
1253
  }
1231
1254
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;
1255
  return NS_OK;
1242
}
1256
}
1243
1257
1244
NS_IMETHODIMP
1258
NS_IMETHODIMP
1245
DocumentViewerImpl::Destroy()
1259
DocumentViewerImpl::Destroy()
1246
{
1260
{
1261
  NS_ASSERTION(mDocument, "No document in Destroy()!");
1262
1247
#ifdef NS_PRINTING
1263
#ifdef NS_PRINTING
1248
  // Here is where we check to see if the docment was still being prepared 
1264
  // 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
1265
  // for printing when it was asked to be destroy from someone externally
 Lines 1258-1270   DocumentViewerImpl::Destroy() Link Here 
1258
  }
1274
  }
1259
#endif
1275
#endif
1260
1276
1261
  // Don't let the document get unloaded while we are printing
1277
  // Don't let the document get unloaded while we are printing.
1262
  // this could happen if we hit the back button during printing
1278
  // this could happen if we hit the back button during printing.
1279
  // We also keep the viewer from being cached in session history, since
1280
  // we require all documents there to be sanitized.
1263
  if (mDestroyRefCount != 0) {
1281
  if (mDestroyRefCount != 0) {
1264
    --mDestroyRefCount;
1282
    --mDestroyRefCount;
1265
    return NS_OK;
1283
    return NS_OK;
1266
  }
1284
  }
1267
1285
1286
  // If we were told to put ourselves into session history instead of destroy
1287
  // the presentation, do that now.
1288
  if (mSHEntry) {
1289
    if (mPresShell)
1290
      mPresShell->StopPlugins();
1291
1292
    // Make sure the presentation isn't torn down by Hide().
1293
    mSHEntry->SetSticky(mIsSticky);
1294
    mIsSticky = PR_TRUE;
1295
1296
    mSHEntry->SetContentViewer(this);
1297
1298
    // Remove our root view from the view hierarchy.
1299
    if (mPresShell) {
1300
      nsIViewManager *vm = mPresShell->GetViewManager();
1301
      if (vm) {
1302
        nsIView *rootView = nsnull;
1303
        vm->GetRootView(rootView);
1304
1305
        if (rootView) {
1306
          nsIView *rootViewParent = rootView->GetParent();
1307
          if (rootViewParent) {
1308
            nsIViewManager *parentVM = rootViewParent->GetViewManager();
1309
            if (parentVM) {
1310
              parentVM->RemoveChild(rootView);
1311
            }
1312
          }
1313
        }
1314
      }
1315
1316
      mPresShell->InvalidateViewManagers();
1317
    }
1318
1319
    mSHEntry = nsnull;
1320
1321
    Hide();
1322
1323
    // This is after Hide() so that the user doesn't see the inputs clear.
1324
    if (mDocument)
1325
      mDocument->Sanitize();
1326
1327
    return NS_OK;
1328
  }
1329
1330
  mDocument = nsnull;
1331
1268
  // All callers are supposed to call destroy to break circular
1332
  // All callers are supposed to call destroy to break circular
1269
  // references.  If we do this stuff in the destructor, the
1333
  // references.  If we do this stuff in the destructor, the
1270
  // destructor might never be called (especially if we're being
1334
  // destructor might never be called (especially if we're being
 Lines 1323-1330   DocumentViewerImpl::Stop(void) Link Here 
1323
    mDocument->StopDocumentLoad();
1387
    mDocument->StopDocumentLoad();
1324
  }
1388
  }
1325
1389
1326
  if (mEnableRendering && (mLoaded || mStopped) && mPresContext)
1390
  if (mEnableRendering && (mLoaded || mStopped) && mPresContext) {
1327
    mPresContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
1391
    mPresContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
1392
  }
1328
1393
1329
  mStopped = PR_TRUE;
1394
  mStopped = PR_TRUE;
1330
1395
 Lines 1669-1675   DocumentViewerImpl::Hide(void) Link Here 
1669
    return NS_OK;
1734
    return NS_OK;
1670
  }
1735
  }
1671
1736
1672
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
1673
  NS_PRECONDITION(mWindow, "null window");
1737
  NS_PRECONDITION(mWindow, "null window");
1674
  if (mWindow) {
1738
  if (mWindow) {
1675
    mWindow->Show(PR_FALSE);
1739
    mWindow->Show(PR_FALSE);
 Lines 1787-1792   DocumentViewerImpl::SetSticky(PRBool aSt Link Here 
1787
}
1851
}
1788
1852
1789
NS_IMETHODIMP
1853
NS_IMETHODIMP
1854
DocumentViewerImpl::SetHistoryEntry(nsISHEntry *aEntry)
1855
{
1856
  mSHEntry = aEntry;
1857
  return NS_OK;
1858
}
1859
1860
NS_IMETHODIMP
1790
DocumentViewerImpl::GetEnableRendering(PRBool* aResult)
1861
DocumentViewerImpl::GetEnableRendering(PRBool* aResult)
1791
{
1862
{
1792
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
1863
  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
 Lines 1811-1823   DocumentViewerImpl::RequestWindowClose(P Link Here 
1811
  return NS_OK;
1882
  return NS_OK;
1812
}
1883
}
1813
1884
1814
1815
void
1816
DocumentViewerImpl::ForceRefresh()
1817
{
1818
  mWindow->Invalidate(PR_TRUE);
1819
}
1820
1821
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
1885
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
1822
1886
1823
PR_STATIC_CALLBACK(PRBool)
1887
PR_STATIC_CALLBACK(PRBool)
(-)layout/base/nsIDocumentViewer.h (-1 / +1 lines)
Line     Link Here 
 Lines 45-51   class nsIPresShell; Link Here 
45
class nsIStyleSheet;
45
class nsIStyleSheet;
46
46
47
#define NS_IDOCUMENT_VIEWER_IID \
47
#define NS_IDOCUMENT_VIEWER_IID \
48
 { 0xa6cf9057, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
48
 { 0xfb255d77, 0xaae5, 0x11d9,{0xa6, 0x2a, 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 (+16 lines)
Line     Link Here 
 Lines 677-682   public: Link Here 
677
  virtual void ListStyleSheets(FILE *out, PRInt32 aIndent = 0) = 0;
677
  virtual void ListStyleSheets(FILE *out, PRInt32 aIndent = 0) = 0;
678
#endif
678
#endif
679
679
680
  /**
681
   * Start all plugins in this shell.
682
   */
683
  virtual void StartPlugins() = 0;
684
685
  /**
686
   * Stop all plugins in this shell.
687
   */
688
  virtual void StopPlugins() = 0;
689
690
  /**
691
   * Call InvalidateHierarchy() on our view manager and the view manager
692
   * of any child documents, recursively.
693
   */
694
  virtual void InvalidateViewManagers() = 0;
695
680
protected:
696
protected:
681
  // IMPORTANT: The ownership implicit in the following member variables
697
  // IMPORTANT: The ownership implicit in the following member variables
682
  // has been explicitly checked.  If you add any members to this class,
698
  // 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 (+131 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 "nsPIPluginInstancePeer.h"
157
#include "nsPluginNativeWindow.h"
158
#include "nsIPluginHost.h"
154
159
155
// Drag & Drop, Clipboard
160
// Drag & Drop, Clipboard
156
#include "nsWidgetsCID.h"
161
#include "nsWidgetsCID.h"
 Lines 1204-1209   public: Link Here 
1204
  NS_IMETHOD IsReflowLocked(PRBool* aIsLocked);  
1209
  NS_IMETHOD IsReflowLocked(PRBool* aIsLocked);  
1205
1210
1206
  virtual nsresult ReconstructFrames(void);
1211
  virtual nsresult ReconstructFrames(void);
1212
  virtual void StartPlugins();
1213
  virtual void StopPlugins();
1214
1215
  virtual void InvalidateViewManagers();
1207
1216
1208
#ifdef IBMBIDI
1217
#ifdef IBMBIDI
1209
  NS_IMETHOD SetCaretBidiLevel(PRUint8 aLevel);
1218
  NS_IMETHOD SetCaretBidiLevel(PRUint8 aLevel);
 Lines 1513-1518   private: Link Here 
1513
  void FireResizeEvent();
1522
  void FireResizeEvent();
1514
  static void sResizeEventCallback(nsITimer* aTimer, void* aPresShell) ;
1523
  static void sResizeEventCallback(nsITimer* aTimer, void* aPresShell) ;
1515
  nsCOMPtr<nsITimer> mResizeEventTimer;
1524
  nsCOMPtr<nsITimer> mResizeEventTimer;
1525
1526
  typedef void (*nsPluginEnumCallback)(PresShell*, nsIContent*);
1527
  void EnumeratePlugins(nsIDOMDocument *aDocument,
1528
                        const nsString &aPluginTag,
1529
                        nsPluginEnumCallback aCallback);
1516
};
1530
};
1517
1531
1518
#ifdef PR_LOGGING
1532
#ifdef PR_LOGGING
 Lines 6470-6475   PresShell::RemoveOverrideStyleSheet(nsIS Link Here 
6470
  return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
6484
  return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
6471
}
6485
}
6472
6486
6487
static void
6488
StartPluginInstance(PresShell *aShell, nsIContent *aContent)
6489
{
6490
  // For now we just reconstruct the frame.
6491
  aShell->RecreateFramesFor(aContent);
6492
}
6493
6494
void
6495
PresShell::StartPlugins()
6496
{
6497
  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
6498
  if (domDoc) {
6499
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("object"), StartPluginInstance);
6500
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("applet"), StartPluginInstance);
6501
    EnumeratePlugins(domDoc, NS_LITERAL_STRING("embed"), StartPluginInstance);
6502
  }
6503
}
6504
6505
static void
6506
StopPluginInstance(PresShell *aShell, nsIContent *aContent)
6507
{
6508
  nsIFrame *frame = aShell->FrameManager()->GetPrimaryFrameFor(aContent);
6509
6510
  nsIObjectFrame *objectFrame = nsnull;
6511
  if (frame)
6512
    CallQueryInterface(frame, &objectFrame);
6513
  if (!objectFrame)
6514
    return;
6515
6516
  nsCOMPtr<nsIPluginInstance> instance;
6517
  objectFrame->GetPluginInstance(*getter_AddRefs(instance));
6518
  if (!instance)
6519
    return;
6520
6521
  // Check whether the plugin wants SetWindow to be called before or after
6522
  // Stop/Destroy.  This is similar to nsObjectFrame::Destroy(), but we
6523
  // don't want to destroy the frame just yet.
6524
6525
  PRBool callSetWindowLast = PR_FALSE;
6526
  instance->GetValue(nsPluginInstanceVariable_CallSetWindowAfterDestroyBool,
6527
                     (void *) &callSetWindowLast);
6528
  if (callSetWindowLast) {
6529
    instance->Stop();
6530
    instance->Destroy();
6531
    instance->SetWindow(nsnull);
6532
  } else {
6533
    instance->SetWindow(nsnull);
6534
    instance->Stop();
6535
    instance->Destroy();
6536
  }
6537
6538
  nsCOMPtr<nsIPluginHost> pluginHost =
6539
    do_GetService("@mozilla.org/plugin/host;1");
6540
  if (pluginHost)
6541
    pluginHost->StopPluginInstance(instance);
6542
}
6543
6544
void
6545
PresShell::StopPlugins()
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
6555
static PRBool
6556
InvalidateVMCallback(nsIDocument *aDocument, void *aData)
6557
{
6558
  NS_ASSERTION(aDocument, "null document passed to callback");
6559
6560
  nsIPresShell *shell = aDocument->GetShellAt(0);
6561
  if (shell)
6562
    shell->InvalidateViewManagers();
6563
6564
  return PR_TRUE;
6565
}
6566
6567
void
6568
PresShell::InvalidateViewManagers()
6569
{
6570
  if (mViewManager)
6571
    mViewManager->InvalidateHierarchy();
6572
6573
  // Get the list of child documents.
6574
  if (mDocument)
6575
    mDocument->EnumerateSubDocuments(InvalidateVMCallback, nsnull);
6576
}
6577
6473
//--------------------------------------------------------
6578
//--------------------------------------------------------
6474
// Start of protected and private methods on the PresShell
6579
// Start of protected and private methods on the PresShell
6475
//--------------------------------------------------------
6580
//--------------------------------------------------------
 Lines 7038-7043   PresShell::Observe(nsISupports* aSubject Link Here 
7038
  return NS_ERROR_FAILURE;
7143
  return NS_ERROR_FAILURE;
7039
}
7144
}
7040
7145
7146
void
7147
PresShell::EnumeratePlugins(nsIDOMDocument *aDocument,
7148
                            const nsString &aPluginTag,
7149
                            nsPluginEnumCallback aCallback)
7150
{
7151
  nsCOMPtr<nsIDOMNodeList> nodes;
7152
  aDocument->GetElementsByTagName(aPluginTag, getter_AddRefs(nodes));
7153
  if (!nodes)
7154
    return;
7155
7156
  PRUint32 length;
7157
  nodes->GetLength(&length);
7158
7159
  nsCOMPtr<nsIDOMNode> node;
7160
  nsCOMPtr<nsIContent> content;
7161
7162
  //  nsFrameManager *fm = FrameManager();
7163
7164
  for (PRUint32 i = 0; i < length; ++i) {
7165
    nodes->Item(i, getter_AddRefs(node));
7166
    content = do_QueryInterface(node);
7167
    if (content)
7168
      aCallback(this, content);
7169
  }
7170
}
7171
7041
//------------------------------------------------------
7172
//------------------------------------------------------
7042
// End of protected and private methods on the PresShell
7173
// End of protected and private methods on the PresShell
7043
//------------------------------------------------------
7174
//------------------------------------------------------
(-)layout/printing/nsPrintEngine.cpp (-4 / +5 lines)
Line     Link Here 
 Lines 4438-4447   nsPrintEngine::TurnScriptingOn(PRBool aD Link Here 
4438
4438
4439
  // get the script global object
4439
  // get the script global object
4440
  nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject();
4440
  nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject();
4441
  NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject");
4441
  if (scriptGlobalObj) {
4442
  nsIScriptContext *scx = scriptGlobalObj->GetContext();
4442
    nsIScriptContext *scx = scriptGlobalObj->GetContext();
4443
  NS_ASSERTION(scx, "Can't get nsIScriptContext");
4443
    NS_ASSERTION(scx, "Can't get nsIScriptContext");
4444
  scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
4444
    scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
4445
  }
4445
}
4446
}
4446
4447
4447
//-----------------------------------------------------------------
4448
//-----------------------------------------------------------------
(-)layout/xul/base/src/nsMenuPopupFrame.cpp (+3 lines)
Line     Link Here 
 Lines 941-946   nsMenuPopupFrame::SyncViewWithFrame(nsPr Link Here 
941
  // the left or top sides of the screen may be in negative space (main monitor is on the
941
  // the left or top sides of the screen may be in negative space (main monitor is on the
942
  // right, etc). We need to be sure to do the right thing.
942
  // right, etc). We need to be sure to do the right thing.
943
  nsCOMPtr<nsIDOMWindowInternal> window(do_QueryInterface(document->GetScriptGlobalObject()));
943
  nsCOMPtr<nsIDOMWindowInternal> window(do_QueryInterface(document->GetScriptGlobalObject()));
944
  if (!window)
945
    return NS_OK;
946
944
  nsCOMPtr<nsIDOMScreen> screen;
947
  nsCOMPtr<nsIDOMScreen> screen;
945
  window->GetScreen(getter_AddRefs(screen));
948
  window->GetScreen(getter_AddRefs(screen));
946
  PRInt32 screenWidth = 0, screenHeight = 0;
949
  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
				 
(-)security/manager/boot/src/nsSecureBrowserUIImpl.cpp (-2 / +3 lines)
Line     Link Here 
 Lines 347-354   nsSecureBrowserUIImpl::Notify(nsIContent Link Here 
347
347
348
  nsCOMPtr<nsIDOMWindow> postingWindow(do_QueryInterface(document->GetScriptGlobalObject()));
348
  nsCOMPtr<nsIDOMWindow> postingWindow(do_QueryInterface(document->GetScriptGlobalObject()));
349
  
349
  
350
  PRBool isChild;
350
  PRBool isChild = PR_FALSE;
351
  IsChildOfDomWindow(mWindow, postingWindow, &isChild);
351
  if (postingWindow)
352
    IsChildOfDomWindow(mWindow, postingWindow, &isChild);
352
  
353
  
353
  // This notify call is not for our window, ignore it.
354
  // This notify call is not for our window, ignore it.
354
  if (!isChild)
355
  if (!isChild)
(-)toolkit/components/passwordmgr/base/nsPasswordManager.cpp (-5 / +76 lines)
Line     Link Here 
 Lines 71-76    Link Here 
71
#include "nsIAutoCompleteResult.h"
71
#include "nsIAutoCompleteResult.h"
72
#include "nsIPK11TokenDB.h"
72
#include "nsIPK11TokenDB.h"
73
#include "nsIPK11Token.h"
73
#include "nsIPK11Token.h"
74
#include "nsIScriptGlobalObject.h"
75
#include "nsIWindowWatcher.h"
74
76
75
static const char kPMPropertiesURL[] = "chrome://passwordmgr/locale/passwordmgr.properties";
77
static const char kPMPropertiesURL[] = "chrome://passwordmgr/locale/passwordmgr.properties";
76
static PRBool sRememberPasswords = PR_FALSE;
78
static PRBool sRememberPasswords = PR_FALSE;
 Lines 263-268   nsPasswordManager::Init() Link Here 
263
265
264
  progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
266
  progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
265
267
268
  // Listen for "domwindowopened", this will let us attach our DOMPageRestore
269
  // event listener.
270
271
  obsService->AddObserver(this, "domwindowopened", PR_FALSE);
272
  obsService->AddObserver(this, "domwindowclosed", PR_FALSE);
273
274
  // Also register on any open windows that already exist, since we don't
275
  // get notifications for those.
276
277
  nsCOMPtr<nsIWindowWatcher> watcher =
278
    do_GetService(NS_WINDOWWATCHER_CONTRACTID);
279
  if (watcher) {
280
    nsCOMPtr<nsISimpleEnumerator> enumerator;
281
    watcher->GetWindowEnumerator(getter_AddRefs(enumerator));
282
    if (enumerator) {
283
      PRBool hasMore;
284
      nsCOMPtr<nsISupports> item;
285
      nsCOMPtr<nsIDOMEventTarget> targ;
286
287
      while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) {
288
        enumerator->GetNext(getter_AddRefs(item));
289
        targ = do_QueryInterface(item);
290
        if (targ) {
291
          targ->AddEventListener(NS_LITERAL_STRING("DOMPageRestore"),
292
                                 NS_STATIC_CAST(nsIDOMLoadListener*, this),
293
                                 PR_FALSE);
294
        }
295
      }
296
    }
297
  }
298
266
  // Now read in the signon file
299
  // Now read in the signon file
267
  nsXPIDLCString signonFile;
300
  nsXPIDLCString signonFile;
268
  mPrefBranch->GetCharPref("SignonFileName", getter_Copies(signonFile));
301
  mPrefBranch->GetCharPref("SignonFileName", getter_Copies(signonFile));
 Lines 747-752   nsPasswordManager::Observe(nsISupports* Link Here 
747
    NS_ASSERTION(branch == mPrefBranch, "unexpected pref change notification");
780
    NS_ASSERTION(branch == mPrefBranch, "unexpected pref change notification");
748
781
749
    branch->GetBoolPref("rememberSignons", &sRememberPasswords);
782
    branch->GetBoolPref("rememberSignons", &sRememberPasswords);
783
  } else if (!strcmp(aTopic, "domwindowopened")) {
784
    nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(aSubject);
785
    if (targ) {
786
      targ->AddEventListener(NS_LITERAL_STRING("DOMPageRestore"),
787
                             NS_STATIC_CAST(nsIDOMLoadListener*, this),
788
                             PR_FALSE);
789
    }
790
  } else if (!strcmp(aTopic, "domwindowclosed")) {
791
    nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(aSubject);
792
    if (targ) {
793
      targ->RemoveEventListener(NS_LITERAL_STRING("DOMPageRestore"),
794
                                NS_STATIC_CAST(nsIDOMLoadListener*, this),
795
                                PR_FALSE);
796
    }
750
  }
797
  }
751
798
752
  return NS_OK;
799
  return NS_OK;
 Lines 765-780   nsPasswordManager::OnStateChange(nsIWebP Link Here 
765
      !(aStateFlags & nsIWebProgressListener::STATE_STOP))
812
      !(aStateFlags & nsIWebProgressListener::STATE_STOP))
766
    return NS_OK;
813
    return NS_OK;
767
814
768
  // Don't do anything if the global signon pref is disabled
769
  if (!SingleSignonEnabled())
770
    return NS_OK;
771
772
  nsCOMPtr<nsIDOMWindow> domWin;
815
  nsCOMPtr<nsIDOMWindow> domWin;
773
  nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));
816
  nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));
774
  NS_ENSURE_SUCCESS(rv, rv);
817
  NS_ENSURE_SUCCESS(rv, rv);
775
818
819
  return DoPrefill(domWin);
820
}
821
822
nsresult
823
nsPasswordManager::DoPrefill(nsIDOMWindow *aDOMWindow)
824
{
825
  // Don't do anything if the global signon pref is disabled
826
  if (!SingleSignonEnabled())
827
    return NS_OK;
828
776
  nsCOMPtr<nsIDOMDocument> domDoc;
829
  nsCOMPtr<nsIDOMDocument> domDoc;
777
  domWin->GetDocument(getter_AddRefs(domDoc));
830
  aDOMWindow->GetDocument(getter_AddRefs(domDoc));
778
  NS_ASSERTION(domDoc, "DOM window should always have a document!");
831
  NS_ASSERTION(domDoc, "DOM window should always have a document!");
779
832
780
  // For now, only prefill forms in HTML documents.
833
  // For now, only prefill forms in HTML documents.
 Lines 1568-1573   nsPasswordManager::Error(nsIDOMEvent* aE Link Here 
1568
  return NS_OK;
1621
  return NS_OK;
1569
}
1622
}
1570
1623
1624
NS_IMETHODIMP
1625
nsPasswordManager::PageRestore(nsIDOMEvent* aEvent)
1626
{
1627
  nsCOMPtr<nsIDOMEventTarget> target;
1628
  aEvent->GetTarget(getter_AddRefs(target));
1629
1630
  nsCOMPtr<nsIDocument> doc = do_QueryInterface(target);
1631
  if (doc) {
1632
    nsCOMPtr<nsIDOMWindow> win =
1633
      do_QueryInterface(doc->GetScriptGlobalObject());
1634
    if (win) {
1635
      return DoPrefill(win);
1636
    }
1637
  }
1638
1639
  return NS_OK;
1640
}
1641
1571
1642
1572
// internal methods
1643
// internal methods
1573
1644
(-)toolkit/components/passwordmgr/base/nsPasswordManager.h (+2 lines)
Line     Link Here 
 Lines 136-141   public: Link Here 
136
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
136
  NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
137
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
137
  NS_IMETHOD Abort(nsIDOMEvent* aEvent);
138
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
138
  NS_IMETHOD Error(nsIDOMEvent* aEvent);
139
  NS_IMETHOD PageRestore(nsIDOMEvent* aEvent);
139
140
140
  // Autocomplete
141
  // Autocomplete
141
  PRBool AutoCompleteSearch(const nsAString& aSearchString,
142
  PRBool AutoCompleteSearch(const nsAString& aSearchString,
 Lines 157-162   protected: Link Here 
157
  nsresult FillPassword(nsIDOMEvent* aEvent);
158
  nsresult FillPassword(nsIDOMEvent* aEvent);
158
  void AttachToInput(nsIDOMHTMLInputElement* aElement);
159
  void AttachToInput(nsIDOMHTMLInputElement* aElement);
159
  PRBool GetPasswordRealm(nsIURI* aURI, nsACString& aRealm);
160
  PRBool GetPasswordRealm(nsIURI* aURI, nsACString& aRealm);
161
  nsresult DoPrefill(nsIDOMWindow *aDOMWindw);
160
162
161
  static PLDHashOperator PR_CALLBACK FindEntryEnumerator(const nsACString& aKey,
163
  static PLDHashOperator PR_CALLBACK FindEntryEnumerator(const nsACString& aKey,
162
                                                         SignonHashEntry* aEntry,
164
                                                         SignonHashEntry* aEntry,
(-)toolkit/components/satchel/src/nsFormFillController.cpp (+6 lines)
Line     Link Here 
 Lines 870-875   nsFormFillController::Error(nsIDOMEvent Link Here 
870
  return NS_OK;
870
  return NS_OK;
871
}
871
}
872
872
873
NS_IMETHODIMP
874
nsFormFillController::PageRestore(nsIDOMEvent *aLoadEvent)
875
{
876
  return NS_OK;
877
}
878
873
////////////////////////////////////////////////////////////////////////
879
////////////////////////////////////////////////////////////////////////
874
//// nsFormFillController
880
//// nsFormFillController
875
881
(-)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();
(-)view/public/nsIViewManager.h (+6 lines)
Line     Link Here 
 Lines 566-571   public: Link Here 
566
   * (aFromScroll is false) or scrolled (aFromScroll is true).
566
   * (aFromScroll is false) or scrolled (aFromScroll is true).
567
   */
567
   */
568
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll)=0;
568
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll)=0;
569
570
  /**
571
   * Force any cached information about the view hierarchy (such as the root
572
   * view manager) to be recomputed.  Note that this is non-recursive.
573
   */
574
  NS_IMETHOD InvalidateHierarchy()=0;
569
};
575
};
570
576
571
// Paint timing mode flags
577
// Paint timing mode flags
(-)view/src/nsViewManager.cpp (+19 lines)
Line     Link Here 
 Lines 4433-4435   nsViewManager::ProcessSynthMouseMoveEven Link Here 
4433
  if (!aFromScroll)
4433
  if (!aFromScroll)
4434
    mSynthMouseMoveEventQueue = nsnull;
4434
    mSynthMouseMoveEventQueue = nsnull;
4435
}
4435
}
4436
4437
NS_IMETHODIMP
4438
nsViewManager::InvalidateHierarchy()
4439
{
4440
  if (mRootView) {
4441
    if (mRootViewManager != this) {
4442
      NS_IF_RELEASE(mRootViewManager);
4443
    }
4444
    nsView *parent = mRootView->GetParent();
4445
    if (parent) {
4446
      mRootViewManager = parent->GetViewManager()->RootViewManager();
4447
      NS_ADDREF(mRootViewManager);
4448
    } else {
4449
      mRootViewManager = this;
4450
    }
4451
  }
4452
4453
  return NS_OK;
4454
}
(-)view/src/nsViewManager.h (+2 lines)
Line     Link Here 
 Lines 269-274   public: Link Here 
269
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll);
269
  NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll);
270
  void ProcessSynthMouseMoveEvent(PRBool aFromScroll);
270
  void ProcessSynthMouseMoveEvent(PRBool aFromScroll);
271
271
272
  NS_IMETHOD InvalidateHierarchy();
273
272
protected:
274
protected:
273
  virtual ~nsViewManager();
275
  virtual ~nsViewManager();
274
276
(-)widget/public/nsGUIEvent.h (+1 lines)
Line     Link Here 
 Lines 234-239   class nsIURI; Link Here 
234
#define NS_IMAGE_ERROR                  (NS_STREAM_EVENT_START + 4)
234
#define NS_IMAGE_ERROR                  (NS_STREAM_EVENT_START + 4)
235
#define NS_SCRIPT_LOAD                  (NS_STREAM_EVENT_START + 5)
235
#define NS_SCRIPT_LOAD                  (NS_STREAM_EVENT_START + 5)
236
#define NS_BEFORE_PAGE_UNLOAD           (NS_STREAM_EVENT_START + 6)
236
#define NS_BEFORE_PAGE_UNLOAD           (NS_STREAM_EVENT_START + 6)
237
#define NS_PAGE_RESTORE                 (NS_STREAM_EVENT_START + 7)
237
 
238
 
238
#define NS_FORM_EVENT_START             1200
239
#define NS_FORM_EVENT_START             1200
239
#define NS_FORM_SUBMIT                  (NS_FORM_EVENT_START)
240
#define NS_FORM_SUBMIT                  (NS_FORM_EVENT_START)
(-)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 / +103 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
%{C++
53
struct nsRect;
54
%}
55
[ref] native nsRect(nsRect);
51
56
52
[scriptable, uuid(6b596e1f-a3bd-40f9-a7ee-ab3edc7f9960)]
57
[scriptable, uuid(e47bf412-3bc2-4306-a82f-ea2bdf950432)]
53
interface nsISHEntry : nsISupports 
58
interface nsISHEntry : nsIHistoryEntry
54
{
59
{
60
    /** URI for the document */
61
    void setURI(in nsIURI aURI);
55
62
56
/** URI for the document */
63
    /** Referrer URI */
57
void SetURI(in nsIURI aURI);
64
    attribute nsIURI referrerURI;
58
59
/** Referrer URI */
60
attribute nsIURI referrerURI;
61
65
62
/**  DOM Document */
66
    /** Content viewer, for fast restoration of presentation */
63
attribute nsIDOMDocument document;
67
    attribute nsIContentViewer contentViewer;
64
68
65
/** Title for the document */
69
    /** Whether the content viewer is marked "sticky" */
66
void SetTitle(in wstring aTitle);
70
    attribute boolean sticky;
67
71
68
/** Post Data for the document */
72
    /** Saved state of the global window object */
69
attribute nsIInputStream postData;
73
    attribute nsISupports windowState;
70
74
71
/** LayoutHistoryState for scroll position and form values */
75
    /**
72
attribute nsILayoutHistoryState layoutHistoryState;
76
     * Saved position and dimensions of the content viewer; we must adjust the
73
77
     * root view's widget accordingly if this has changed when the presentation
74
/** parent of this entry */
78
     * is restored.
75
attribute nsISHEntry parent;
79
     */
76
80
    [noscript] void getViewerBounds(in nsRect bounds);
77
/**
81
    [noscript] void setViewerBounds([const] in nsRect bounds);
78
 * The loadType for this entry. This is typically loadHistory except
82
79
 * when reload is pressed, it has the appropriate reload flag
83
    /**
80
 */
84
     * Saved child docshells corresponding to contentViewer.  There are weak
81
attribute  unsigned long loadType;
85
     * references since it's assumed that the content viewer's document has
82
86
     * an owning reference to the subdocument for each shell.  The child shells
83
/**
87
     * are restored as children of the parent docshell, in this order, when the
84
 * An ID to help identify this entry from others during
88
     * parent docshell restores a saved presentation.
85
 * subframe navigation
89
     */
86
 */
90
    void addChildShell(in nsIDocShellTreeItem shell);
87
attribute unsigned long ID;
91
    nsIDocShellTreeItem childShellAt(in long index);
88
92
    void clearChildShells();
89
/**
93
90
 * pageIdentifier is an integer that should be the same for two entries
94
91
 * attached to the same docshell only if the two entries are entries for the
95
    /** Title for the document */
92
 * same page in the sense that one could go from the state represented by one
96
    void setTitle(in AString aTitle);
93
 * to the state represented by the other simply by scrolling (so the entries
97
94
 * are separated by an anchor traversal or a subframe navigation in some other
98
    /** Post Data for the document */
95
 * frame).
99
    attribute nsIInputStream postData;
96
 */
100
97
attribute unsigned long pageIdentifier;
101
    /** LayoutHistoryState for scroll position and form values */
98
102
    attribute nsILayoutHistoryState layoutHistoryState;
99
/** attribute to set and get the cache key for the entry */
103
100
attribute nsISupports cacheKey;
104
    /** parent of this entry */
101
105
    attribute nsISHEntry parent;
102
/** attribute to indicate whether layoutHistoryState should be saved */
106
103
attribute boolean saveLayoutStateFlag;
107
    /**
104
108
     * The loadType for this entry. This is typically loadHistory except
105
/** attribute to indicate whether the page is already expired in cache */
109
     * when reload is pressed, it has the appropriate reload flag
106
attribute boolean expirationStatus;
110
     */
107
111
    attribute unsigned long loadType;
108
/** attribute to indicate the content-type of the document that this
112
109
    is a session history entry for */
113
    /**
110
attribute ACString contentType; 
114
     * An ID to help identify this entry from others during
115
     * subframe navigation
116
     */
117
    attribute unsigned long ID;
118
119
    /**
120
     * pageIdentifier is an integer that should be the same for two entries
121
     * attached to the same docshell only if the two entries are entries for
122
     * the same page in the sense that one could go from the state represented
123
     * by one to the state represented by the other simply by scrolling (so the
124
     * entries are separated by an anchor traversal or a subframe navigation in
125
     * some other frame).
126
     */
127
    attribute unsigned long pageIdentifier;
128
129
    /** attribute to set and get the cache key for the entry */
130
    attribute nsISupports cacheKey;
131
132
    /** attribute to indicate whether layoutHistoryState should be saved */
133
    attribute boolean saveLayoutStateFlag;
134
135
    /** attribute to indicate whether the page is already expired in cache */
136
    attribute boolean expirationStatus;
137
138
    /**
139
     * attribute to indicate the content-type of the document that this
140
     * is a session history entry for
141
     */
142
    attribute ACString contentType; 
111
 
143
 
112
/** Set/Get scrollers' positon in anchored pages */
144
    /** Set/Get scrollers' positon in anchored pages */
113
void setScrollPosition(in PRInt32 x, in PRInt32 y);
145
    void setScrollPosition(in long x, in long y);
114
void getScrollPosition(out PRInt32 x, out PRInt32 y);
146
    void getScrollPosition(out long x, out long y);
115
147
116
/** Additional ways to create an entry */
148
    /** Additional ways to create an entry */
117
void create(in nsIURI aURI, in wstring aTitle, in nsIDOMDocument aDocument,
149
    void create(in nsIURI URI, in AString title,
118
            in nsIInputStream aInputStream, in nsILayoutHistoryState aHistoryLayoutState,
150
                in nsIInputStream inputStream,
119
            in nsISupports aCacheKey, in ACString aContentType);
151
                in nsILayoutHistoryState layoutHistoryState,
120
152
                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
153
154
    nsISHEntry clone();
126
155
156
    /** Attribute that indicates if this entry is for a subframe navigation */
157
    void setIsSubFrame(in boolean aFlag);
127
};
158
};
128
159
129
160
(-)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 / +94 lines)
Line     Link Here 
 Lines 37-47    Link Here 
37
 *
37
 *
38
 * ***** END LICENSE BLOCK ***** */
38
 * ***** END LICENSE BLOCK ***** */
39
39
40
#ifdef DEBUG_brymer
41
#define DEBUG_PAGE_CACHE
42
#endif
43
40
// Local Includes
44
// Local Includes
41
#include "nsSHEntry.h"
45
#include "nsSHEntry.h"
42
#include "nsXPIDLString.h"
46
#include "nsXPIDLString.h"
43
#include "nsReadableUtils.h"
47
#include "nsReadableUtils.h"
44
#include "nsIDocShellLoadInfo.h"
48
#include "nsIDocShellLoadInfo.h"
49
#include "nsIDocShellTreeItem.h"
45
50
46
static PRUint32 gEntryID = 0;
51
static PRUint32 gEntryID = 0;
47
52
 Lines 58-64   nsSHEntry::nsSHEntry() Link Here 
58
  , mIsFrameNavigation(PR_FALSE)
63
  , mIsFrameNavigation(PR_FALSE)
59
  , mSaveLayoutState(PR_TRUE)
64
  , mSaveLayoutState(PR_TRUE)
60
  , mExpired(PR_FALSE)
65
  , mExpired(PR_FALSE)
66
  , mSticky(PR_TRUE)
61
  , mParent(nsnull)
67
  , mParent(nsnull)
68
  , mViewerBounds(0, 0, 0, 0)
62
{
69
{
63
}
70
}
64
71
 Lines 77-86   nsSHEntry::nsSHEntry(const nsSHEntry &ot Link Here 
77
  , mIsFrameNavigation(other.mIsFrameNavigation)
84
  , mIsFrameNavigation(other.mIsFrameNavigation)
78
  , mSaveLayoutState(other.mSaveLayoutState)
85
  , mSaveLayoutState(other.mSaveLayoutState)
79
  , mExpired(other.mExpired)
86
  , mExpired(other.mExpired)
87
  , mSticky(other.mSticky)
80
  // XXX why not copy mContentType?
88
  // XXX why not copy mContentType?
81
  , mCacheKey(other.mCacheKey)
89
  , mCacheKey(other.mCacheKey)
82
  , mParent(other.mParent)
90
  , mParent(other.mParent)
91
  , mViewerBounds(other.mViewerBounds)
92
{
93
}
94
95
nsSHEntry::~nsSHEntry()
83
{
96
{
97
  mChildren.Clear();
98
  if (mContentViewer)
99
    mContentViewer->Destroy();
84
}
100
}
85
101
86
//*****************************************************************************
102
//*****************************************************************************
 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
}
(-)xpfe/components/shistory/src/nsSHEntry.h (-5 / +10 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"
57
59
58
class nsSHEntry : public nsIHistoryEntry,
60
class nsSHEntry : public nsISHEntry,
59
                  public nsISHEntry,
60
                  public nsISHContainer
61
                  public nsISHContainer
61
{
62
{
62
public: 
63
public: 
 Lines 69-79   public: Link Here 
69
  NS_DECL_NSISHCONTAINER
70
  NS_DECL_NSISHCONTAINER
70
71
71
private:
72
private:
72
  ~nsSHEntry() { mChildren.Clear(); }
73
  ~nsSHEntry();
73
74
74
  nsCOMPtr<nsIURI>                mURI;
75
  nsCOMPtr<nsIURI>                mURI;
75
  nsCOMPtr<nsIURI>                mReferrerURI;
76
  nsCOMPtr<nsIURI>                mReferrerURI;
76
  nsCOMPtr<nsIDOMDocument>        mDocument;
77
  nsCOMPtr<nsIContentViewer>      mContentViewer;
77
  nsString                        mTitle;
78
  nsString                        mTitle;
78
  nsCOMPtr<nsIInputStream>        mPostData;
79
  nsCOMPtr<nsIInputStream>        mPostData;
79
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
80
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
 Lines 86-94   private: Link Here 
86
  PRPackedBool                    mIsFrameNavigation;
87
  PRPackedBool                    mIsFrameNavigation;
87
  PRPackedBool                    mSaveLayoutState;
88
  PRPackedBool                    mSaveLayoutState;
88
  PRPackedBool                    mExpired;
89
  PRPackedBool                    mExpired;
90
  PRPackedBool                    mSticky;
89
  nsCString                       mContentType;
91
  nsCString                       mContentType;
90
  nsCOMPtr<nsISupports>           mCacheKey;
92
  nsCOMPtr<nsISupports>           mCacheKey;
91
  nsISHEntry *                    mParent;  // weak reference
93
  nsISHEntry *                    mParent;  // weak reference
94
  nsCOMPtr<nsISupports>           mWindowState;
95
  nsRect                          mViewerBounds;
96
  nsVoidArray                     mChildShells;
92
};
97
};
93
98
94
#endif /* nsSHEntry_h */
99
#endif /* nsSHEntry_h */
(-)xpfe/components/shistory/src/nsSHistory.cpp (-7 / +58 lines)
Line     Link Here 
 Lines 54-62    Link Here 
54
#include "nsIDocShellLoadInfo.h"
54
#include "nsIDocShellLoadInfo.h"
55
#include "nsIServiceManager.h"
55
#include "nsIServiceManager.h"
56
#include "nsIPrefService.h"
56
#include "nsIPrefService.h"
57
#include "nsIURI.h"
58
#include "nsIContentViewer.h"
57
59
58
#define PREF_SHISTORY_SIZE "browser.sessionhistory.max_entries"
60
#define PREF_SHISTORY_SIZE "browser.sessionhistory.max_entries"
61
#define PREF_SHISTORY_VIEWERS "browser.sessionhistory.max_viewers"
62
59
static PRInt32  gHistoryMaxSize = 50;
63
static PRInt32  gHistoryMaxSize = 50;
64
static PRInt32  gHistoryMaxViewers = 0;
60
65
61
enum HistCmd{
66
enum HistCmd{
62
  HIST_CMD_BACK,
67
  HIST_CMD_BACK,
 Lines 69-75   enum HistCmd{ Link Here 
69
//***    nsSHistory: Object Management
74
//***    nsSHistory: Object Management
70
//*****************************************************************************
75
//*****************************************************************************
71
76
72
nsSHistory::nsSHistory() : mListRoot(nsnull), mIndex(-1), mLength(0), mRequestedIndex(-1)
77
nsSHistory::nsSHistory() : mListRoot(nsnull), mIndex(-1), mLength(0), mRequestedIndex(-1), mNumViewers(0)
73
{
78
{
74
}
79
}
75
80
 Lines 104-113   nsSHistory::Init() Link Here 
104
{
109
{
105
  nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
110
  nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
106
  if (prefs) {
111
  if (prefs) {
107
    nsCOMPtr<nsIPrefBranch> defaultBranch;
112
    nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
108
    prefs->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch));
113
    if (branch) {
109
    if (defaultBranch) {
114
      branch->GetIntPref(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
110
      defaultBranch->GetIntPref(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
115
      branch->GetIntPref(PREF_SHISTORY_VIEWERS, &gHistoryMaxViewers);
111
    }
116
    }
112
  }
117
  }
113
  return NS_OK;
118
  return NS_OK;
 Lines 171-177   nsSHistory::AddEntry(nsISHEntry * aSHEnt Link Here 
171
  //Purge History list if it is too long
176
  //Purge History list if it is too long
172
  if ((gHistoryMaxSize >= 0) && (mLength > gHistoryMaxSize))
177
  if ((gHistoryMaxSize >= 0) && (mLength > gHistoryMaxSize))
173
    PurgeHistory(mLength-gHistoryMaxSize);
178
    PurgeHistory(mLength-gHistoryMaxSize);
174
  
179
180
  // Evict content viewers if there are too many.
181
  EvictContentViewers(mIndex - 1, mIndex);
182
175
  return NS_OK;
183
  return NS_OK;
176
}
184
}
177
185
 Lines 207-212   nsSHistory::GetEntryAtIndex(PRInt32 aInd Link Here 
207
    if (NS_SUCCEEDED(rv) && (*aResult)) {
215
    if (NS_SUCCEEDED(rv) && (*aResult)) {
208
      // Set mIndex to the requested index, if asked to do so..
216
      // Set mIndex to the requested index, if asked to do so..
209
      if (aModifyIndex) {
217
      if (aModifyIndex) {
218
        EvictContentViewers(mIndex, aIndex);
210
        mIndex = aIndex;
219
        mIndex = aIndex;
211
      }
220
      }
212
    } //entry
221
    } //entry
 Lines 583-594   nsSHistory::Reload(PRUint32 aReloadFlags Link Here 
583
	return LoadEntry(mIndex, loadType, HIST_CMD_RELOAD);
592
	return LoadEntry(mIndex, loadType, HIST_CMD_RELOAD);
584
}
593
}
585
594
595
void
596
nsSHistory::EvictContentViewers(PRInt32 aFromIndex, PRInt32 aToIndex)
597
{
598
  // To enforce the limit on cached content viewers, we need to release all
599
  // of the content viewers that are no longer in the "window" that now
600
  // ends/begins at aToIndex.
601
602
  PRInt32 startIndex, endIndex;
603
  if (aToIndex > aFromIndex) { // going forward
604
    startIndex = PR_MAX(0, aFromIndex - gHistoryMaxViewers);
605
    endIndex = aToIndex - gHistoryMaxViewers;
606
  } else { // going backward
607
    startIndex = aToIndex + gHistoryMaxViewers;
608
    endIndex = PR_MIN(mLength - 1, aFromIndex + gHistoryMaxViewers);
609
  }
610
611
  nsCOMPtr<nsISHEntry> entry;
612
  nsCOMPtr<nsIContentViewer> viewer;
613
  nsISHTransaction *temp;
614
  nsCOMPtr<nsISHTransaction> trans;
615
  GetTransactionAtIndex(startIndex, getter_AddRefs(trans));
616
617
  for (PRInt32 i = startIndex; trans && i < endIndex; ++i) {
618
    trans->GetSHEntry(getter_AddRefs(entry));
619
    entry->GetContentViewer(getter_AddRefs(viewer));
620
    if (viewer) {
621
      viewer->Destroy();
622
      entry->SetContentViewer(nsnull);
623
    }
624
625
    entry->SetWindowState(nsnull);
626
    temp = trans;
627
    temp->GetNext(getter_AddRefs(trans));
628
  }
629
}
630
586
NS_IMETHODIMP
631
NS_IMETHODIMP
587
nsSHistory::UpdateIndex()
632
nsSHistory::UpdateIndex()
588
{
633
{
589
  // Update the actual index with the right value. 
634
  // Update the actual index with the right value. 
590
  if (mIndex != mRequestedIndex && mRequestedIndex != -1)
635
  if (mIndex != mRequestedIndex && mRequestedIndex != -1) {
636
    // We've just finished a history navigation (back or forward), so enforce
637
    // the max number of content viewers.
638
639
    EvictContentViewers(mIndex, mRequestedIndex);
591
    mIndex = mRequestedIndex;
640
    mIndex = mRequestedIndex;
641
  }
642
592
  return NS_OK;
643
  return NS_OK;
593
}
644
}
594
645
(-)xpfe/components/shistory/src/nsSHistory.h (+3 lines)
Line     Link Here 
 Lines 85-95   protected: Link Here 
85
   nsresult PrintHistory();
85
   nsresult PrintHistory();
86
#endif
86
#endif
87
87
88
  void EvictContentViewers(PRInt32 aFromIndex, PRInt32 aToIndex);
89
88
protected:
90
protected:
89
  nsCOMPtr<nsISHTransaction> mListRoot;
91
  nsCOMPtr<nsISHTransaction> mListRoot;
90
  PRInt32 mIndex;
92
  PRInt32 mIndex;
91
  PRInt32 mLength;
93
  PRInt32 mLength;
92
  PRInt32 mRequestedIndex;
94
  PRInt32 mRequestedIndex;
95
  PRInt32 mNumViewers;
93
  // Session History listener
96
  // Session History listener
94
  nsWeakPtr mListener;
97
  nsWeakPtr mListener;
95
  // Weak reference. Do not refcount this.
98
  // Weak reference. Do not refcount this.

Return to bug 274784