bug #40867 (r=bzarsky@mit.edu, sr=jst@netscape.com, a=asa@mozilla.org) Add new caching API to allow view-source to load from the cache and not the network.
git-svn-id: svn://10.0.0.236/trunk@117874 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -34,4 +34,5 @@ nsIContentViewer.idl
|
||||
nsIContentViewerEdit.idl
|
||||
nsIContentViewerFile.idl
|
||||
nsIURIFixup.idl
|
||||
nsIEditorDocShell.idl
|
||||
nsIEditorDocShell.idl
|
||||
nsIWebPageDescriptor.idl
|
||||
|
||||
@@ -81,6 +81,7 @@ XPIDLSRCS = \
|
||||
nsIContentViewerFile.idl \
|
||||
nsIURIFixup.idl \
|
||||
nsIEditorDocShell.idl \
|
||||
nsIWebPageDescriptor.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
||||
@@ -75,6 +75,7 @@ XPIDLSRCS= \
|
||||
.\nsIWebNavigation.idl \
|
||||
.\nsIURIFixup.idl \
|
||||
.\nsIEditorDocShell.idl \
|
||||
.\nsIWebPageDescriptor.idl \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
|
||||
@@ -271,6 +271,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIContentViewerContainer)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIEditorDocShell)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebPageDescriptor)
|
||||
NS_INTERFACE_MAP_END_THREADSAFE
|
||||
|
||||
///*****************************************************************************
|
||||
@@ -2552,6 +2553,83 @@ nsDocShell::GetSessionHistory(nsISHistory ** aSessionHistory)
|
||||
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsDocShell::nsIWebPageDescriptor
|
||||
//*****************************************************************************
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::LoadPage(nsISupports *aPageDescriptor, PRUint32 aDisplayType)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(aPageDescriptor));
|
||||
|
||||
// Currently, the opaque 'page descriptor' is an nsISHEntry...
|
||||
if (!shEntry) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
|
||||
//
|
||||
// load the page as view-source
|
||||
//
|
||||
if (nsIWebPageDescriptor::DISPLAY_AS_SOURCE == aDisplayType) {
|
||||
nsCOMPtr<nsIHistoryEntry> srcHE(do_QueryInterface(shEntry));
|
||||
nsCOMPtr<nsIURI> oldUri, newUri;
|
||||
nsCString spec, newSpec;
|
||||
|
||||
// Create a new view-source URI and replace the original.
|
||||
rv = srcHE->GetURI(getter_AddRefs(oldUri));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
oldUri->GetSpec(spec);
|
||||
newSpec.Append(NS_LITERAL_CSTRING("view-source:"));
|
||||
newSpec.Append(spec);
|
||||
|
||||
rv = NS_NewURI(getter_AddRefs(newUri), newSpec);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
shEntry->SetURI(newUri);
|
||||
|
||||
// NULL out inappropriate cloned attributes...
|
||||
shEntry->SetParent(nsnull);
|
||||
shEntry->SetIsSubFrame(PR_FALSE);
|
||||
}
|
||||
|
||||
rv = LoadHistoryEntry(shEntry, LOAD_HISTORY);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetCurrentDescriptor(nsISupports **aPageDescriptor)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISHEntry> src;
|
||||
|
||||
if (!aPageDescriptor) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*aPageDescriptor = nsnull;
|
||||
|
||||
src = mOSHE ? mOSHE : mLSHE;
|
||||
if (src) {
|
||||
nsCOMPtr<nsISupports> sup;;
|
||||
nsCOMPtr<nsISHEntry> dest;
|
||||
|
||||
rv = src->Clone(getter_AddRefs(dest));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
sup = do_QueryInterface(dest);
|
||||
*aPageDescriptor = sup;
|
||||
|
||||
NS_ADDREF(*aPageDescriptor);
|
||||
}
|
||||
|
||||
return (*aPageDescriptor) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
// nsDocShell::nsIBaseWindow
|
||||
//*****************************************************************************
|
||||
@@ -5600,46 +5678,16 @@ nsDocShell::CloneAndReplace(nsISHEntry * src, PRUint32 aCloneID,
|
||||
NS_IF_ADDREF(*resultEntry);
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCOMPtr<nsIInputStream> postdata;
|
||||
nsCOMPtr<nsILayoutHistoryState> LHS;
|
||||
nsCOMPtr<nsIURI> referrerURI;
|
||||
PRUnichar *title = nsnull;
|
||||
nsCOMPtr<nsISHEntry> parent;
|
||||
PRBool expirationStatus;
|
||||
PRBool layoutStatus;
|
||||
nsCOMPtr<nsISupports> cacheKey;
|
||||
PRUint32 id;
|
||||
result = nsComponentManager::CreateInstance(NS_SHENTRY_CONTRACTID, NULL,
|
||||
NS_GET_IID(nsISHEntry),
|
||||
(void **) &dest);
|
||||
// Clone the SHEntry...
|
||||
result = src->Clone(&dest);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
srcHE->GetURI(getter_AddRefs(uri));
|
||||
src->GetReferrerURI(getter_AddRefs(referrerURI));
|
||||
src->GetPostData(getter_AddRefs(postdata));
|
||||
srcHE->GetTitle(&title);
|
||||
src->GetLayoutHistoryState(getter_AddRefs(LHS));
|
||||
//XXX Is this correct? parent is a weak ref in nsISHEntry
|
||||
src->GetParent(getter_AddRefs(parent));
|
||||
src->GetID(&id);
|
||||
src->GetExpirationStatus(&expirationStatus);
|
||||
src->GetSaveLayoutStateFlag(&layoutStatus);
|
||||
src->GetCacheKey(getter_AddRefs(cacheKey));
|
||||
|
||||
// XXX do we care much about valid values for these uri, title etc....
|
||||
dest->SetURI(uri);
|
||||
dest->SetReferrerURI(referrerURI);
|
||||
dest->SetPostData(postdata);
|
||||
dest->SetLayoutHistoryState(LHS);
|
||||
dest->SetTitle(title);
|
||||
dest->SetParent(parent);
|
||||
dest->SetID(id);
|
||||
// This entry is for a frame...
|
||||
dest->SetIsSubFrame(PR_TRUE);
|
||||
dest->SetExpirationStatus(expirationStatus);
|
||||
dest->SetSaveLayoutStateFlag(layoutStatus);
|
||||
dest->SetCacheKey(cacheKey);
|
||||
|
||||
// Transfer the owning reference to 'resultEntry'. From this point on
|
||||
// 'dest' is *not* an owning reference...
|
||||
*resultEntry = dest;
|
||||
|
||||
PRInt32 childCount = 0;
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIWebPageDescriptor.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsISHContainer.h"
|
||||
#include "nsIDocShellLoadInfo.h"
|
||||
@@ -154,6 +155,7 @@ class nsDocShell : public nsIDocShell,
|
||||
public nsIRefreshURI,
|
||||
public nsIWebProgressListener,
|
||||
public nsIEditorDocShell,
|
||||
public nsIWebPageDescriptor,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
friend class nsDSURIContentListener;
|
||||
@@ -179,6 +181,7 @@ public:
|
||||
NS_DECL_NSIREFRESHURI
|
||||
NS_DECL_NSICONTENTVIEWERCONTAINER
|
||||
NS_DECL_NSIEDITORDOCSHELL
|
||||
NS_DECL_NSIWEBPAGEDESCRIPTOR
|
||||
|
||||
nsresult SetLoadCookie(nsISupports * aCookie);
|
||||
nsresult GetLoadCookie(nsISupports ** aResult);
|
||||
|
||||
65
mozilla/docshell/base/nsIWebPageDescriptor.idl
Normal file
65
mozilla/docshell/base/nsIWebPageDescriptor.idl
Normal file
@@ -0,0 +1,65 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* The nsIWebPageDescriptor interface allows content being displayed in one
|
||||
* window to be loaded into another window without refetching it from the
|
||||
* network.
|
||||
*
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(6f30b676-3710-4c2c-80b1-0395fb26516e)]
|
||||
interface nsIWebPageDescriptor : nsISupports
|
||||
{
|
||||
const unsigned long DISPLAY_AS_SOURCE = 0x0001;
|
||||
const unsigned long DISPLAY_NORMAL = 0x0002;
|
||||
|
||||
/**
|
||||
* Tells the object to load the page specified by the page descriptor
|
||||
*
|
||||
* @return NS_OK -
|
||||
* NS_ERROR_FAILURE -
|
||||
*/
|
||||
void LoadPage(in nsISupports aPageDescriptor, in unsigned long aDisplayType);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the page descriptor for the curent document.
|
||||
*/
|
||||
readonly attribute nsISupports currentDescriptor;
|
||||
};
|
||||
Reference in New Issue
Block a user