1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla gecko code.
17 * The Initial Developer of the Original Code is
18 * Benjamin Smedberg <bsmedberg@covad.net>
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsGlobalHistoryAdapter.h"
40 #include "nsDocShellCID.h"
41 #include "nsServiceManagerUtils.h"
42 #include "nsIComponentRegistrar.h"
43 #include "nsGlobalHistory2Adapter.h"
48 nsGlobalHistoryAdapter::Create(nsISupports
*aOuter
,
55 rv
= NS_ERROR_NO_AGGREGATION
;
59 nsGlobalHistoryAdapter
* adapter
= new nsGlobalHistoryAdapter();
61 rv
= NS_ERROR_OUT_OF_MEMORY
;
67 if (NS_SUCCEEDED(rv
)) {
68 rv
= adapter
->QueryInterface(aIID
, aResult
);
76 nsGlobalHistoryAdapter::RegisterSelf(nsIComponentManager
* aCompMgr
,
78 const char* aLoaderStr
,
80 const nsModuleComponentInfo
*aInfo
)
84 nsCOMPtr
<nsIComponentRegistrar
> compReg( do_QueryInterface(aCompMgr
) );
86 rv
= NS_ERROR_UNEXPECTED
;
90 rv
= compReg
->IsContractIDRegistered(NS_GLOBALHISTORY2_CONTRACTID
, ®istered
);
91 if (NS_FAILED(rv
)) return rv
;
93 // If the embedder has already registered the contractID, we don't want to
94 // register ourself. Ideally the component manager would handle this for us.
100 return compReg
->RegisterFactoryLocation(GetCID(),
101 "nsGlobalHistoryAdapter",
102 NS_GLOBALHISTORY2_CONTRACTID
,
103 aPath
, aLoaderStr
, aType
);
106 nsGlobalHistoryAdapter::nsGlobalHistoryAdapter()
109 nsGlobalHistoryAdapter::~nsGlobalHistoryAdapter()
113 nsGlobalHistoryAdapter::Init()
117 nsCOMPtr
<nsIComponentRegistrar
> compReg
;
118 rv
= NS_GetComponentRegistrar(getter_AddRefs(compReg
));
119 NS_ENSURE_SUCCESS(rv
, rv
);
122 rv
= compReg
->ContractIDToCID(NS_GLOBALHISTORY_CONTRACTID
, &cid
);
124 rv
= NS_ERROR_FACTORY_NOT_REGISTERED
;
128 if (cid
->Equals(nsGlobalHistory2Adapter::GetCID())) {
129 rv
= NS_ERROR_FACTORY_NOT_REGISTERED
;
133 NS_WARNING("Using nsIGlobalHistory2->nsIGlobalHistory adapter.");
134 mHistory
= do_GetService(NS_GLOBALHISTORY_CONTRACTID
, &rv
);
138 NS_IMPL_ISUPPORTS1(nsGlobalHistoryAdapter
, nsIGlobalHistory2
)
141 nsGlobalHistoryAdapter::AddURI(nsIURI
* aURI
, PRBool aRedirect
,
142 PRBool aToplevel
, nsIURI
* aReferrer
)
144 NS_ENSURE_ARG_POINTER(aURI
);
147 // The model is really if we don't know differently then add which basically
148 // means we are supposed to try all the things we know not to allow in and
149 // then if we don't bail go on and allow it in. But here lets compare
150 // against the most common case we know to allow in and go on and say yes
153 PRBool isHTTP
= PR_FALSE
;
154 PRBool isHTTPS
= PR_FALSE
;
156 NS_ENSURE_SUCCESS(rv
= aURI
->SchemeIs("http", &isHTTP
), rv
);
157 NS_ENSURE_SUCCESS(rv
= aURI
->SchemeIs("https", &isHTTPS
), rv
);
159 if (!isHTTP
&& !isHTTPS
) {
160 PRBool isAbout
, isImap
, isNews
, isMailbox
, isViewSource
, isChrome
, isData
;
162 rv
= aURI
->SchemeIs("about", &isAbout
);
163 rv
|= aURI
->SchemeIs("imap", &isImap
);
164 rv
|= aURI
->SchemeIs("news", &isNews
);
165 rv
|= aURI
->SchemeIs("mailbox", &isMailbox
);
166 rv
|= aURI
->SchemeIs("view-source", &isViewSource
);
167 rv
|= aURI
->SchemeIs("chrome", &isChrome
);
168 rv
|= aURI
->SchemeIs("data", &isData
);
169 NS_ENSURE_SUCCESS(rv
, NS_ERROR_FAILURE
);
171 if (isAbout
|| isImap
|| isNews
|| isMailbox
|| isViewSource
|| isChrome
|| isData
) {
177 rv
= aURI
->GetSpec(spec
);
178 NS_ENSURE_SUCCESS(rv
, rv
);
180 return mHistory
->AddPage(spec
.get());
184 nsGlobalHistoryAdapter::IsVisited(nsIURI
* aURI
, PRBool
* aRetval
)
186 NS_ENSURE_ARG_POINTER(aURI
);
189 nsresult rv
= aURI
->GetSpec(spec
);
190 NS_ENSURE_SUCCESS(rv
, rv
);
192 return mHistory
->IsVisited(spec
.get(), aRetval
);
196 nsGlobalHistoryAdapter::SetPageTitle(nsIURI
* aURI
, const nsAString
& aTitle
)
198 return NS_ERROR_NOT_IMPLEMENTED
;