Bug 451040 ? Passwords Manager Empty after convert to MozStorage. r=gavin
[wine-gecko.git] / docshell / base / nsGlobalHistoryAdapter.cpp
blobde25ed57a8e8d8079d40de56c5168717bd91a21b
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
13 * License.
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.
22 * Contributor(s):
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"
44 #include "nsIURI.h"
45 #include "nsString.h"
47 nsresult
48 nsGlobalHistoryAdapter::Create(nsISupports *aOuter,
49 REFNSIID aIID,
50 void **aResult)
52 nsresult rv;
54 if (aOuter) {
55 rv = NS_ERROR_NO_AGGREGATION;
56 return rv;
59 nsGlobalHistoryAdapter* adapter = new nsGlobalHistoryAdapter();
60 if (!adapter) {
61 rv = NS_ERROR_OUT_OF_MEMORY;
62 return rv;
65 NS_ADDREF(adapter);
66 rv = adapter->Init();
67 if (NS_SUCCEEDED(rv)) {
68 rv = adapter->QueryInterface(aIID, aResult);
70 NS_RELEASE(adapter);
72 return rv;
75 nsresult
76 nsGlobalHistoryAdapter::RegisterSelf(nsIComponentManager* aCompMgr,
77 nsIFile* aPath,
78 const char* aLoaderStr,
79 const char* aType,
80 const nsModuleComponentInfo *aInfo)
82 nsresult rv;
83 PRBool registered;
84 nsCOMPtr<nsIComponentRegistrar> compReg( do_QueryInterface(aCompMgr) );
85 if (!compReg) {
86 rv = NS_ERROR_UNEXPECTED;
87 return rv;
90 rv = compReg->IsContractIDRegistered(NS_GLOBALHISTORY2_CONTRACTID, &registered);
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.
95 if (registered) {
96 rv = NS_OK;
97 return rv;
100 return compReg->RegisterFactoryLocation(GetCID(),
101 "nsGlobalHistoryAdapter",
102 NS_GLOBALHISTORY2_CONTRACTID,
103 aPath, aLoaderStr, aType);
106 nsGlobalHistoryAdapter::nsGlobalHistoryAdapter()
109 nsGlobalHistoryAdapter::~nsGlobalHistoryAdapter()
112 nsresult
113 nsGlobalHistoryAdapter::Init()
115 nsresult rv;
117 nsCOMPtr<nsIComponentRegistrar> compReg;
118 rv = NS_GetComponentRegistrar(getter_AddRefs(compReg));
119 NS_ENSURE_SUCCESS(rv, rv);
121 nsCID *cid;
122 rv = compReg->ContractIDToCID(NS_GLOBALHISTORY_CONTRACTID, &cid);
123 if (NS_FAILED(rv)) {
124 rv = NS_ERROR_FACTORY_NOT_REGISTERED;
125 return rv;
128 if (cid->Equals(nsGlobalHistory2Adapter::GetCID())) {
129 rv = NS_ERROR_FACTORY_NOT_REGISTERED;
130 return rv;
133 NS_WARNING("Using nsIGlobalHistory2->nsIGlobalHistory adapter.");
134 mHistory = do_GetService(NS_GLOBALHISTORY_CONTRACTID, &rv);
135 return rv;
138 NS_IMPL_ISUPPORTS1(nsGlobalHistoryAdapter, nsIGlobalHistory2)
140 NS_IMETHODIMP
141 nsGlobalHistoryAdapter::AddURI(nsIURI* aURI, PRBool aRedirect,
142 PRBool aToplevel, nsIURI* aReferrer)
144 NS_ENSURE_ARG_POINTER(aURI);
145 nsresult rv;
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
151 // to it.
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) {
172 return NS_OK;
176 nsCAutoString spec;
177 rv = aURI->GetSpec(spec);
178 NS_ENSURE_SUCCESS(rv, rv);
180 return mHistory->AddPage(spec.get());
183 NS_IMETHODIMP
184 nsGlobalHistoryAdapter::IsVisited(nsIURI* aURI, PRBool* aRetval)
186 NS_ENSURE_ARG_POINTER(aURI);
188 nsCAutoString spec;
189 nsresult rv = aURI->GetSpec(spec);
190 NS_ENSURE_SUCCESS(rv, rv);
192 return mHistory->IsVisited(spec.get(), aRetval);
195 NS_IMETHODIMP
196 nsGlobalHistoryAdapter::SetPageTitle(nsIURI* aURI, const nsAString& aTitle)
198 return NS_ERROR_NOT_IMPLEMENTED;