Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // Local Includes |
michael@0 | 7 | #include "nsWebBrowser.h" |
michael@0 | 8 | |
michael@0 | 9 | // Helper Classes |
michael@0 | 10 | #include "nsGfxCIID.h" |
michael@0 | 11 | #include "nsWidgetsCID.h" |
michael@0 | 12 | |
michael@0 | 13 | //Interfaces Needed |
michael@0 | 14 | #include "nsReadableUtils.h" |
michael@0 | 15 | #include "nsIComponentManager.h" |
michael@0 | 16 | #include "nsIDOMDocument.h" |
michael@0 | 17 | #include "nsIDOMWindow.h" |
michael@0 | 18 | #include "nsIDOMElement.h" |
michael@0 | 19 | #include "nsIInterfaceRequestor.h" |
michael@0 | 20 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 21 | #include "nsIWebBrowserChrome.h" |
michael@0 | 22 | #include "nsPIDOMWindow.h" |
michael@0 | 23 | #include "nsIWebProgress.h" |
michael@0 | 24 | #include "nsIWebProgressListener.h" |
michael@0 | 25 | #include "nsIWebBrowserFocus.h" |
michael@0 | 26 | #include "nsIWebBrowserStream.h" |
michael@0 | 27 | #include "nsIPresShell.h" |
michael@0 | 28 | #include "nsIURIContentListener.h" |
michael@0 | 29 | #include "nsISHistoryListener.h" |
michael@0 | 30 | #include "nsIURI.h" |
michael@0 | 31 | #include "nsIWebBrowserPersist.h" |
michael@0 | 32 | #include "nsCWebBrowserPersist.h" |
michael@0 | 33 | #include "nsIServiceManager.h" |
michael@0 | 34 | #include "nsAutoPtr.h" |
michael@0 | 35 | #include "nsFocusManager.h" |
michael@0 | 36 | #include "Layers.h" |
michael@0 | 37 | #include "gfxContext.h" |
michael@0 | 38 | #include "nsILoadContext.h" |
michael@0 | 39 | |
michael@0 | 40 | // for painting the background window |
michael@0 | 41 | #include "mozilla/LookAndFeel.h" |
michael@0 | 42 | |
michael@0 | 43 | // Printing Includes |
michael@0 | 44 | #ifdef NS_PRINTING |
michael@0 | 45 | #include "nsIWebBrowserPrint.h" |
michael@0 | 46 | #include "nsIContentViewer.h" |
michael@0 | 47 | #endif |
michael@0 | 48 | |
michael@0 | 49 | // PSM2 includes |
michael@0 | 50 | #include "nsISecureBrowserUI.h" |
michael@0 | 51 | #include "nsXULAppAPI.h" |
michael@0 | 52 | |
michael@0 | 53 | using namespace mozilla; |
michael@0 | 54 | using namespace mozilla::layers; |
michael@0 | 55 | |
michael@0 | 56 | static NS_DEFINE_CID(kChildCID, NS_CHILD_CID); |
michael@0 | 57 | |
michael@0 | 58 | |
michael@0 | 59 | //***************************************************************************** |
michael@0 | 60 | //*** nsWebBrowser: Object Management |
michael@0 | 61 | //***************************************************************************** |
michael@0 | 62 | |
michael@0 | 63 | nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nullptr), |
michael@0 | 64 | mInitInfo(nullptr), |
michael@0 | 65 | mContentType(typeContentWrapper), |
michael@0 | 66 | mActivating(false), |
michael@0 | 67 | mShouldEnableHistory(true), |
michael@0 | 68 | mIsActive(true), |
michael@0 | 69 | mParentNativeWindow(nullptr), |
michael@0 | 70 | mProgressListener(nullptr), |
michael@0 | 71 | mBackgroundColor(0), |
michael@0 | 72 | mPersistCurrentState(nsIWebBrowserPersist::PERSIST_STATE_READY), |
michael@0 | 73 | mPersistResult(NS_OK), |
michael@0 | 74 | mPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_NONE), |
michael@0 | 75 | mStream(nullptr), |
michael@0 | 76 | mParentWidget(nullptr), |
michael@0 | 77 | mListenerArray(nullptr) |
michael@0 | 78 | { |
michael@0 | 79 | mInitInfo = new nsWebBrowserInitInfo(); |
michael@0 | 80 | mWWatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID); |
michael@0 | 81 | NS_ASSERTION(mWWatch, "failed to get WindowWatcher"); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | nsWebBrowser::~nsWebBrowser() |
michael@0 | 85 | { |
michael@0 | 86 | InternalDestroy(); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | NS_IMETHODIMP nsWebBrowser::InternalDestroy() |
michael@0 | 90 | { |
michael@0 | 91 | |
michael@0 | 92 | if (mInternalWidget) { |
michael@0 | 93 | mInternalWidget->SetWidgetListener(nullptr); |
michael@0 | 94 | mInternalWidget->Destroy(); |
michael@0 | 95 | mInternalWidget = nullptr; // Force release here. |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | SetDocShell(nullptr); |
michael@0 | 99 | |
michael@0 | 100 | if(mDocShellTreeOwner) |
michael@0 | 101 | { |
michael@0 | 102 | mDocShellTreeOwner->WebBrowser(nullptr); |
michael@0 | 103 | NS_RELEASE(mDocShellTreeOwner); |
michael@0 | 104 | } |
michael@0 | 105 | if(mInitInfo) |
michael@0 | 106 | { |
michael@0 | 107 | delete mInitInfo; |
michael@0 | 108 | mInitInfo = nullptr; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | if (mListenerArray) { |
michael@0 | 112 | for (uint32_t i = 0, end = mListenerArray->Length(); i < end; i++) { |
michael@0 | 113 | nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); |
michael@0 | 114 | delete state; |
michael@0 | 115 | } |
michael@0 | 116 | delete mListenerArray; |
michael@0 | 117 | mListenerArray = nullptr; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | return NS_OK; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | |
michael@0 | 124 | //***************************************************************************** |
michael@0 | 125 | // nsWebBrowser::nsISupports |
michael@0 | 126 | //***************************************************************************** |
michael@0 | 127 | |
michael@0 | 128 | NS_IMPL_ADDREF(nsWebBrowser) |
michael@0 | 129 | NS_IMPL_RELEASE(nsWebBrowser) |
michael@0 | 130 | |
michael@0 | 131 | NS_INTERFACE_MAP_BEGIN(nsWebBrowser) |
michael@0 | 132 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowser) |
michael@0 | 133 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowser) |
michael@0 | 134 | NS_INTERFACE_MAP_ENTRY(nsIWebNavigation) |
michael@0 | 135 | NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) |
michael@0 | 136 | NS_INTERFACE_MAP_ENTRY(nsIScrollable) |
michael@0 | 137 | NS_INTERFACE_MAP_ENTRY(nsITextScroll) |
michael@0 | 138 | NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem) |
michael@0 | 139 | NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) |
michael@0 | 140 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowserSetup) |
michael@0 | 141 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowserPersist) |
michael@0 | 142 | NS_INTERFACE_MAP_ENTRY(nsICancelable) |
michael@0 | 143 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowserFocus) |
michael@0 | 144 | NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) |
michael@0 | 145 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowserStream) |
michael@0 | 146 | NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) |
michael@0 | 147 | NS_INTERFACE_MAP_END |
michael@0 | 148 | |
michael@0 | 149 | ///***************************************************************************** |
michael@0 | 150 | // nsWebBrowser::nsIInterfaceRequestor |
michael@0 | 151 | //***************************************************************************** |
michael@0 | 152 | |
michael@0 | 153 | NS_IMETHODIMP nsWebBrowser::GetInterface(const nsIID& aIID, void** aSink) |
michael@0 | 154 | { |
michael@0 | 155 | NS_ENSURE_ARG_POINTER(aSink); |
michael@0 | 156 | |
michael@0 | 157 | if(NS_SUCCEEDED(QueryInterface(aIID, aSink))) |
michael@0 | 158 | return NS_OK; |
michael@0 | 159 | |
michael@0 | 160 | if (mDocShell) { |
michael@0 | 161 | #ifdef NS_PRINTING |
michael@0 | 162 | if (aIID.Equals(NS_GET_IID(nsIWebBrowserPrint))) { |
michael@0 | 163 | nsCOMPtr<nsIContentViewer> viewer; |
michael@0 | 164 | mDocShell->GetContentViewer(getter_AddRefs(viewer)); |
michael@0 | 165 | if (!viewer) |
michael@0 | 166 | return NS_NOINTERFACE; |
michael@0 | 167 | |
michael@0 | 168 | nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint(do_QueryInterface(viewer)); |
michael@0 | 169 | nsIWebBrowserPrint* print = (nsIWebBrowserPrint*)webBrowserPrint.get(); |
michael@0 | 170 | NS_ASSERTION(print, "This MUST support this interface!"); |
michael@0 | 171 | NS_ADDREF(print); |
michael@0 | 172 | *aSink = print; |
michael@0 | 173 | return NS_OK; |
michael@0 | 174 | } |
michael@0 | 175 | #endif |
michael@0 | 176 | return mDocShellAsReq->GetInterface(aIID, aSink); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | return NS_NOINTERFACE; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | //***************************************************************************** |
michael@0 | 183 | // nsWebBrowser::nsIWebBrowser |
michael@0 | 184 | //***************************************************************************** |
michael@0 | 185 | |
michael@0 | 186 | // listeners that currently support registration through AddWebBrowserListener: |
michael@0 | 187 | // - nsIWebProgressListener |
michael@0 | 188 | NS_IMETHODIMP nsWebBrowser::AddWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID) |
michael@0 | 189 | { |
michael@0 | 190 | NS_ENSURE_ARG_POINTER(aListener); |
michael@0 | 191 | |
michael@0 | 192 | nsresult rv = NS_OK; |
michael@0 | 193 | if (!mWebProgress) { |
michael@0 | 194 | // The window hasn't been created yet, so queue up the listener. They'll be |
michael@0 | 195 | // registered when the window gets created. |
michael@0 | 196 | nsAutoPtr<nsWebBrowserListenerState> state; |
michael@0 | 197 | state = new nsWebBrowserListenerState(); |
michael@0 | 198 | if (!state) return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 199 | |
michael@0 | 200 | state->mWeakPtr = aListener; |
michael@0 | 201 | state->mID = aIID; |
michael@0 | 202 | |
michael@0 | 203 | if (!mListenerArray) { |
michael@0 | 204 | mListenerArray = new nsTArray<nsWebBrowserListenerState*>(); |
michael@0 | 205 | if (!mListenerArray) { |
michael@0 | 206 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 207 | } |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | if (!mListenerArray->AppendElement(state)) { |
michael@0 | 211 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | // We're all set now; don't delete |state| after this point |
michael@0 | 215 | state.forget(); |
michael@0 | 216 | } else { |
michael@0 | 217 | nsCOMPtr<nsISupports> supports(do_QueryReferent(aListener)); |
michael@0 | 218 | if (!supports) return NS_ERROR_INVALID_ARG; |
michael@0 | 219 | rv = BindListener(supports, aIID); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | return rv; |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | NS_IMETHODIMP nsWebBrowser::BindListener(nsISupports *aListener, const nsIID& aIID) { |
michael@0 | 226 | NS_ENSURE_ARG_POINTER(aListener); |
michael@0 | 227 | NS_ASSERTION(mWebProgress, "this should only be called after we've retrieved a progress iface"); |
michael@0 | 228 | nsresult rv = NS_OK; |
michael@0 | 229 | |
michael@0 | 230 | // register this listener for the specified interface id |
michael@0 | 231 | if (aIID.Equals(NS_GET_IID(nsIWebProgressListener))) { |
michael@0 | 232 | nsCOMPtr<nsIWebProgressListener> listener = do_QueryInterface(aListener, &rv); |
michael@0 | 233 | if (NS_FAILED(rv)) return rv; |
michael@0 | 234 | NS_ENSURE_STATE(mWebProgress); |
michael@0 | 235 | rv = mWebProgress->AddProgressListener(listener, nsIWebProgress::NOTIFY_ALL); |
michael@0 | 236 | } |
michael@0 | 237 | else if (aIID.Equals(NS_GET_IID(nsISHistoryListener))) { |
michael@0 | 238 | nsCOMPtr<nsISHistory> shistory(do_GetInterface(mDocShell, &rv)); |
michael@0 | 239 | if (NS_FAILED(rv)) return rv; |
michael@0 | 240 | nsCOMPtr<nsISHistoryListener> listener(do_QueryInterface(aListener, &rv)); |
michael@0 | 241 | if (NS_FAILED(rv)) return rv; |
michael@0 | 242 | rv = shistory->AddSHistoryListener(listener); |
michael@0 | 243 | } |
michael@0 | 244 | return rv; |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | NS_IMETHODIMP nsWebBrowser::RemoveWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID) |
michael@0 | 248 | { |
michael@0 | 249 | NS_ENSURE_ARG_POINTER(aListener); |
michael@0 | 250 | |
michael@0 | 251 | nsresult rv = NS_OK; |
michael@0 | 252 | if (!mWebProgress) { |
michael@0 | 253 | // if there's no-one to register the listener w/, and we don't have a queue going, |
michael@0 | 254 | // the the called is calling Remove before an Add which doesn't make sense. |
michael@0 | 255 | if (!mListenerArray) return NS_ERROR_FAILURE; |
michael@0 | 256 | |
michael@0 | 257 | // iterate the array and remove the queued listener |
michael@0 | 258 | int32_t count = mListenerArray->Length(); |
michael@0 | 259 | while (count > 0) { |
michael@0 | 260 | nsWebBrowserListenerState *state = mListenerArray->ElementAt(count); |
michael@0 | 261 | NS_ASSERTION(state, "list construction problem"); |
michael@0 | 262 | |
michael@0 | 263 | if (state->Equals(aListener, aIID)) { |
michael@0 | 264 | // this is the one, pull it out. |
michael@0 | 265 | mListenerArray->RemoveElementAt(count); |
michael@0 | 266 | break; |
michael@0 | 267 | } |
michael@0 | 268 | count--; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | // if we've emptied the array, get rid of it. |
michael@0 | 272 | if (0 >= mListenerArray->Length()) { |
michael@0 | 273 | for (uint32_t i = 0, end = mListenerArray->Length(); i < end; i++) { |
michael@0 | 274 | nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); |
michael@0 | 275 | delete state; |
michael@0 | 276 | } |
michael@0 | 277 | delete mListenerArray; |
michael@0 | 278 | mListenerArray = nullptr; |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | } else { |
michael@0 | 282 | nsCOMPtr<nsISupports> supports(do_QueryReferent(aListener)); |
michael@0 | 283 | if (!supports) return NS_ERROR_INVALID_ARG; |
michael@0 | 284 | rv = UnBindListener(supports, aIID); |
michael@0 | 285 | } |
michael@0 | 286 | |
michael@0 | 287 | return rv; |
michael@0 | 288 | } |
michael@0 | 289 | |
michael@0 | 290 | NS_IMETHODIMP nsWebBrowser::UnBindListener(nsISupports *aListener, const nsIID& aIID) { |
michael@0 | 291 | NS_ENSURE_ARG_POINTER(aListener); |
michael@0 | 292 | NS_ASSERTION(mWebProgress, "this should only be called after we've retrieved a progress iface"); |
michael@0 | 293 | nsresult rv = NS_OK; |
michael@0 | 294 | |
michael@0 | 295 | // remove the listener for the specified interface id |
michael@0 | 296 | if (aIID.Equals(NS_GET_IID(nsIWebProgressListener))) { |
michael@0 | 297 | nsCOMPtr<nsIWebProgressListener> listener = do_QueryInterface(aListener, &rv); |
michael@0 | 298 | if (NS_FAILED(rv)) return rv; |
michael@0 | 299 | NS_ENSURE_STATE(mWebProgress); |
michael@0 | 300 | rv = mWebProgress->RemoveProgressListener(listener); |
michael@0 | 301 | } |
michael@0 | 302 | else if (aIID.Equals(NS_GET_IID(nsISHistoryListener))) { |
michael@0 | 303 | nsCOMPtr<nsISHistory> shistory(do_GetInterface(mDocShell, &rv)); |
michael@0 | 304 | if (NS_FAILED(rv)) return rv; |
michael@0 | 305 | nsCOMPtr<nsISHistoryListener> listener(do_QueryInterface(aListener, &rv)); |
michael@0 | 306 | if (NS_FAILED(rv)) return rv; |
michael@0 | 307 | rv = shistory->RemoveSHistoryListener(listener); |
michael@0 | 308 | } |
michael@0 | 309 | return rv; |
michael@0 | 310 | } |
michael@0 | 311 | |
michael@0 | 312 | NS_IMETHODIMP nsWebBrowser::EnableGlobalHistory(bool aEnable) |
michael@0 | 313 | { |
michael@0 | 314 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 315 | |
michael@0 | 316 | return mDocShell->SetUseGlobalHistory(aEnable); |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | NS_IMETHODIMP nsWebBrowser::GetContainerWindow(nsIWebBrowserChrome** aTopWindow) |
michael@0 | 320 | { |
michael@0 | 321 | NS_ENSURE_ARG_POINTER(aTopWindow); |
michael@0 | 322 | |
michael@0 | 323 | if(mDocShellTreeOwner) { |
michael@0 | 324 | *aTopWindow = mDocShellTreeOwner->GetWebBrowserChrome().take(); |
michael@0 | 325 | } else { |
michael@0 | 326 | *aTopWindow = nullptr; |
michael@0 | 327 | } |
michael@0 | 328 | |
michael@0 | 329 | return NS_OK; |
michael@0 | 330 | } |
michael@0 | 331 | |
michael@0 | 332 | NS_IMETHODIMP nsWebBrowser::SetContainerWindow(nsIWebBrowserChrome* aTopWindow) |
michael@0 | 333 | { |
michael@0 | 334 | NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); |
michael@0 | 335 | return mDocShellTreeOwner->SetWebBrowserChrome(aTopWindow); |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | NS_IMETHODIMP nsWebBrowser::GetParentURIContentListener(nsIURIContentListener** |
michael@0 | 339 | aParentContentListener) |
michael@0 | 340 | { |
michael@0 | 341 | NS_ENSURE_ARG_POINTER(aParentContentListener); |
michael@0 | 342 | *aParentContentListener = nullptr; |
michael@0 | 343 | |
michael@0 | 344 | // get the interface from the docshell |
michael@0 | 345 | nsCOMPtr<nsIURIContentListener> listener(do_GetInterface(mDocShell)); |
michael@0 | 346 | |
michael@0 | 347 | if (listener) |
michael@0 | 348 | return listener->GetParentContentListener(aParentContentListener); |
michael@0 | 349 | return NS_OK; |
michael@0 | 350 | } |
michael@0 | 351 | |
michael@0 | 352 | NS_IMETHODIMP nsWebBrowser::SetParentURIContentListener(nsIURIContentListener* |
michael@0 | 353 | aParentContentListener) |
michael@0 | 354 | { |
michael@0 | 355 | // get the interface from the docshell |
michael@0 | 356 | nsCOMPtr<nsIURIContentListener> listener(do_GetInterface(mDocShell)); |
michael@0 | 357 | |
michael@0 | 358 | if (listener) |
michael@0 | 359 | return listener->SetParentContentListener(aParentContentListener); |
michael@0 | 360 | return NS_ERROR_FAILURE; |
michael@0 | 361 | } |
michael@0 | 362 | |
michael@0 | 363 | NS_IMETHODIMP nsWebBrowser::GetContentDOMWindow(nsIDOMWindow **_retval) |
michael@0 | 364 | { |
michael@0 | 365 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 366 | nsresult rv = NS_OK; |
michael@0 | 367 | nsCOMPtr<nsIDOMWindow> retval = do_GetInterface(mDocShell, &rv); |
michael@0 | 368 | if (NS_FAILED(rv)) return rv; |
michael@0 | 369 | |
michael@0 | 370 | *_retval = retval; |
michael@0 | 371 | NS_ADDREF(*_retval); |
michael@0 | 372 | return rv; |
michael@0 | 373 | } |
michael@0 | 374 | |
michael@0 | 375 | NS_IMETHODIMP nsWebBrowser::GetIsActive(bool *rv) |
michael@0 | 376 | { |
michael@0 | 377 | *rv = mIsActive; |
michael@0 | 378 | return NS_OK; |
michael@0 | 379 | } |
michael@0 | 380 | |
michael@0 | 381 | NS_IMETHODIMP nsWebBrowser::SetIsActive(bool aIsActive) |
michael@0 | 382 | { |
michael@0 | 383 | // Set our copy of the value |
michael@0 | 384 | mIsActive = aIsActive; |
michael@0 | 385 | |
michael@0 | 386 | // If we have a docshell, pass on the request |
michael@0 | 387 | if (mDocShell) |
michael@0 | 388 | return mDocShell->SetIsActive(aIsActive); |
michael@0 | 389 | return NS_OK; |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | //***************************************************************************** |
michael@0 | 393 | // nsWebBrowser::nsIDocShellTreeItem |
michael@0 | 394 | //***************************************************************************** |
michael@0 | 395 | |
michael@0 | 396 | NS_IMETHODIMP nsWebBrowser::GetName(nsAString& aName) |
michael@0 | 397 | { |
michael@0 | 398 | if(mDocShell) |
michael@0 | 399 | mDocShell->GetName(aName); |
michael@0 | 400 | else |
michael@0 | 401 | aName = mInitInfo->name; |
michael@0 | 402 | |
michael@0 | 403 | return NS_OK; |
michael@0 | 404 | } |
michael@0 | 405 | |
michael@0 | 406 | NS_IMETHODIMP nsWebBrowser::SetName(const nsAString& aName) |
michael@0 | 407 | { |
michael@0 | 408 | if(mDocShell) |
michael@0 | 409 | { |
michael@0 | 410 | return mDocShell->SetName(aName); |
michael@0 | 411 | } |
michael@0 | 412 | else |
michael@0 | 413 | mInitInfo->name = aName; |
michael@0 | 414 | |
michael@0 | 415 | return NS_OK; |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | NS_IMETHODIMP nsWebBrowser::NameEquals(const char16_t *aName, bool *_retval) |
michael@0 | 419 | { |
michael@0 | 420 | NS_ENSURE_ARG_POINTER(aName); |
michael@0 | 421 | NS_ENSURE_ARG_POINTER(_retval); |
michael@0 | 422 | if(mDocShell) |
michael@0 | 423 | { |
michael@0 | 424 | return mDocShell->NameEquals(aName, _retval); |
michael@0 | 425 | } |
michael@0 | 426 | else |
michael@0 | 427 | *_retval = mInitInfo->name.Equals(aName); |
michael@0 | 428 | |
michael@0 | 429 | return NS_OK; |
michael@0 | 430 | } |
michael@0 | 431 | |
michael@0 | 432 | /* virtual */ int32_t |
michael@0 | 433 | nsWebBrowser::ItemType() |
michael@0 | 434 | { |
michael@0 | 435 | return mContentType; |
michael@0 | 436 | } |
michael@0 | 437 | |
michael@0 | 438 | NS_IMETHODIMP nsWebBrowser::GetItemType(int32_t* aItemType) |
michael@0 | 439 | { |
michael@0 | 440 | NS_ENSURE_ARG_POINTER(aItemType); |
michael@0 | 441 | |
michael@0 | 442 | *aItemType = ItemType(); |
michael@0 | 443 | return NS_OK; |
michael@0 | 444 | } |
michael@0 | 445 | |
michael@0 | 446 | NS_IMETHODIMP nsWebBrowser::SetItemType(int32_t aItemType) |
michael@0 | 447 | { |
michael@0 | 448 | NS_ENSURE_TRUE((aItemType == typeContentWrapper || aItemType == typeChromeWrapper), NS_ERROR_FAILURE); |
michael@0 | 449 | mContentType = aItemType; |
michael@0 | 450 | if (mDocShell) |
michael@0 | 451 | mDocShell->SetItemType(mContentType == typeChromeWrapper |
michael@0 | 452 | ? static_cast<int32_t>(typeChrome) |
michael@0 | 453 | : static_cast<int32_t>(typeContent)); |
michael@0 | 454 | return NS_OK; |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | NS_IMETHODIMP nsWebBrowser::GetParent(nsIDocShellTreeItem** aParent) |
michael@0 | 458 | { |
michael@0 | 459 | *aParent = nullptr; |
michael@0 | 460 | return NS_OK; |
michael@0 | 461 | } |
michael@0 | 462 | |
michael@0 | 463 | NS_IMETHODIMP nsWebBrowser::GetSameTypeParent(nsIDocShellTreeItem** aParent) |
michael@0 | 464 | { |
michael@0 | 465 | *aParent = nullptr; |
michael@0 | 466 | |
michael@0 | 467 | return NS_OK; |
michael@0 | 468 | } |
michael@0 | 469 | |
michael@0 | 470 | NS_IMETHODIMP nsWebBrowser::GetRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) |
michael@0 | 471 | { |
michael@0 | 472 | NS_ENSURE_ARG_POINTER(aRootTreeItem); |
michael@0 | 473 | *aRootTreeItem = static_cast<nsIDocShellTreeItem*>(this); |
michael@0 | 474 | |
michael@0 | 475 | nsCOMPtr<nsIDocShellTreeItem> parent; |
michael@0 | 476 | NS_ENSURE_SUCCESS(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); |
michael@0 | 477 | while(parent) |
michael@0 | 478 | { |
michael@0 | 479 | *aRootTreeItem = parent; |
michael@0 | 480 | NS_ENSURE_SUCCESS((*aRootTreeItem)->GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); |
michael@0 | 481 | } |
michael@0 | 482 | NS_ADDREF(*aRootTreeItem); |
michael@0 | 483 | return NS_OK; |
michael@0 | 484 | } |
michael@0 | 485 | |
michael@0 | 486 | NS_IMETHODIMP nsWebBrowser::GetSameTypeRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) |
michael@0 | 487 | { |
michael@0 | 488 | NS_ENSURE_ARG_POINTER(aRootTreeItem); |
michael@0 | 489 | *aRootTreeItem = static_cast<nsIDocShellTreeItem*>(this); |
michael@0 | 490 | |
michael@0 | 491 | nsCOMPtr<nsIDocShellTreeItem> parent; |
michael@0 | 492 | NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); |
michael@0 | 493 | while(parent) |
michael@0 | 494 | { |
michael@0 | 495 | *aRootTreeItem = parent; |
michael@0 | 496 | NS_ENSURE_SUCCESS((*aRootTreeItem)->GetSameTypeParent(getter_AddRefs(parent)), |
michael@0 | 497 | NS_ERROR_FAILURE); |
michael@0 | 498 | } |
michael@0 | 499 | NS_ADDREF(*aRootTreeItem); |
michael@0 | 500 | return NS_OK; |
michael@0 | 501 | } |
michael@0 | 502 | |
michael@0 | 503 | NS_IMETHODIMP nsWebBrowser::FindItemWithName(const char16_t *aName, |
michael@0 | 504 | nsISupports* aRequestor, nsIDocShellTreeItem* aOriginalRequestor, |
michael@0 | 505 | nsIDocShellTreeItem **_retval) |
michael@0 | 506 | { |
michael@0 | 507 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 508 | NS_ASSERTION(mDocShellTreeOwner, "This should always be set when in this situation"); |
michael@0 | 509 | |
michael@0 | 510 | return mDocShell->FindItemWithName(aName, |
michael@0 | 511 | static_cast<nsIDocShellTreeOwner*>(mDocShellTreeOwner), |
michael@0 | 512 | aOriginalRequestor, _retval); |
michael@0 | 513 | } |
michael@0 | 514 | |
michael@0 | 515 | NS_IMETHODIMP nsWebBrowser::GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner) |
michael@0 | 516 | { |
michael@0 | 517 | NS_ENSURE_ARG_POINTER(aTreeOwner); |
michael@0 | 518 | *aTreeOwner = nullptr; |
michael@0 | 519 | if(mDocShellTreeOwner) |
michael@0 | 520 | { |
michael@0 | 521 | if (mDocShellTreeOwner->mTreeOwner) |
michael@0 | 522 | { |
michael@0 | 523 | *aTreeOwner = mDocShellTreeOwner->mTreeOwner; |
michael@0 | 524 | } |
michael@0 | 525 | else |
michael@0 | 526 | { |
michael@0 | 527 | *aTreeOwner = mDocShellTreeOwner; |
michael@0 | 528 | } |
michael@0 | 529 | } |
michael@0 | 530 | NS_IF_ADDREF(*aTreeOwner); |
michael@0 | 531 | return NS_OK; |
michael@0 | 532 | } |
michael@0 | 533 | |
michael@0 | 534 | NS_IMETHODIMP nsWebBrowser::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) |
michael@0 | 535 | { |
michael@0 | 536 | NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); |
michael@0 | 537 | return mDocShellTreeOwner->SetTreeOwner(aTreeOwner); |
michael@0 | 538 | } |
michael@0 | 539 | |
michael@0 | 540 | //***************************************************************************** |
michael@0 | 541 | // nsWebBrowser::nsIDocShellTreeItem |
michael@0 | 542 | //***************************************************************************** |
michael@0 | 543 | |
michael@0 | 544 | NS_IMETHODIMP nsWebBrowser::GetChildCount(int32_t * aChildCount) |
michael@0 | 545 | { |
michael@0 | 546 | NS_ENSURE_ARG_POINTER(aChildCount); |
michael@0 | 547 | *aChildCount = 0; |
michael@0 | 548 | return NS_OK; |
michael@0 | 549 | } |
michael@0 | 550 | |
michael@0 | 551 | NS_IMETHODIMP nsWebBrowser::AddChild(nsIDocShellTreeItem * aChild) |
michael@0 | 552 | { |
michael@0 | 553 | return NS_ERROR_UNEXPECTED; |
michael@0 | 554 | } |
michael@0 | 555 | |
michael@0 | 556 | NS_IMETHODIMP nsWebBrowser::RemoveChild(nsIDocShellTreeItem * aChild) |
michael@0 | 557 | { |
michael@0 | 558 | return NS_ERROR_UNEXPECTED; |
michael@0 | 559 | } |
michael@0 | 560 | |
michael@0 | 561 | NS_IMETHODIMP nsWebBrowser::GetChildAt(int32_t aIndex, |
michael@0 | 562 | nsIDocShellTreeItem ** aChild) |
michael@0 | 563 | { |
michael@0 | 564 | return NS_ERROR_UNEXPECTED; |
michael@0 | 565 | } |
michael@0 | 566 | |
michael@0 | 567 | NS_IMETHODIMP nsWebBrowser::FindChildWithName( |
michael@0 | 568 | const char16_t * aName, |
michael@0 | 569 | bool aRecurse, bool aSameType, |
michael@0 | 570 | nsIDocShellTreeItem * aRequestor, |
michael@0 | 571 | nsIDocShellTreeItem * aOriginalRequestor, |
michael@0 | 572 | nsIDocShellTreeItem ** _retval) |
michael@0 | 573 | { |
michael@0 | 574 | NS_ENSURE_ARG_POINTER(_retval); |
michael@0 | 575 | |
michael@0 | 576 | *_retval = nullptr; |
michael@0 | 577 | return NS_OK; |
michael@0 | 578 | } |
michael@0 | 579 | |
michael@0 | 580 | //***************************************************************************** |
michael@0 | 581 | // nsWebBrowser::nsIWebNavigation |
michael@0 | 582 | //***************************************************************************** |
michael@0 | 583 | |
michael@0 | 584 | NS_IMETHODIMP nsWebBrowser::GetCanGoBack(bool* aCanGoBack) |
michael@0 | 585 | { |
michael@0 | 586 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 587 | |
michael@0 | 588 | return mDocShellAsNav->GetCanGoBack(aCanGoBack); |
michael@0 | 589 | } |
michael@0 | 590 | |
michael@0 | 591 | NS_IMETHODIMP nsWebBrowser::GetCanGoForward(bool* aCanGoForward) |
michael@0 | 592 | { |
michael@0 | 593 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 594 | |
michael@0 | 595 | return mDocShellAsNav->GetCanGoForward(aCanGoForward); |
michael@0 | 596 | } |
michael@0 | 597 | |
michael@0 | 598 | NS_IMETHODIMP nsWebBrowser::GoBack() |
michael@0 | 599 | { |
michael@0 | 600 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 601 | |
michael@0 | 602 | return mDocShellAsNav->GoBack(); |
michael@0 | 603 | } |
michael@0 | 604 | |
michael@0 | 605 | NS_IMETHODIMP nsWebBrowser::GoForward() |
michael@0 | 606 | { |
michael@0 | 607 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 608 | |
michael@0 | 609 | return mDocShellAsNav->GoForward(); |
michael@0 | 610 | } |
michael@0 | 611 | |
michael@0 | 612 | NS_IMETHODIMP nsWebBrowser::LoadURIWithBase(const char16_t* aURI, |
michael@0 | 613 | uint32_t aLoadFlags, |
michael@0 | 614 | nsIURI* aReferringURI, |
michael@0 | 615 | nsIInputStream* aPostDataStream, |
michael@0 | 616 | nsIInputStream* aExtraHeaderStream, |
michael@0 | 617 | nsIURI* aBaseURI) |
michael@0 | 618 | { |
michael@0 | 619 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 620 | |
michael@0 | 621 | return mDocShellAsNav->LoadURIWithBase(aURI, |
michael@0 | 622 | aLoadFlags, |
michael@0 | 623 | aReferringURI, |
michael@0 | 624 | aPostDataStream, |
michael@0 | 625 | aExtraHeaderStream, |
michael@0 | 626 | aBaseURI); |
michael@0 | 627 | } |
michael@0 | 628 | |
michael@0 | 629 | NS_IMETHODIMP nsWebBrowser::LoadURI(const char16_t* aURI, |
michael@0 | 630 | uint32_t aLoadFlags, |
michael@0 | 631 | nsIURI* aReferringURI, |
michael@0 | 632 | nsIInputStream* aPostDataStream, |
michael@0 | 633 | nsIInputStream* aExtraHeaderStream) |
michael@0 | 634 | { |
michael@0 | 635 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 636 | |
michael@0 | 637 | return mDocShellAsNav->LoadURI(aURI, |
michael@0 | 638 | aLoadFlags, |
michael@0 | 639 | aReferringURI, |
michael@0 | 640 | aPostDataStream, |
michael@0 | 641 | aExtraHeaderStream); |
michael@0 | 642 | } |
michael@0 | 643 | |
michael@0 | 644 | NS_IMETHODIMP nsWebBrowser::Reload(uint32_t aReloadFlags) |
michael@0 | 645 | { |
michael@0 | 646 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 647 | |
michael@0 | 648 | return mDocShellAsNav->Reload(aReloadFlags); |
michael@0 | 649 | } |
michael@0 | 650 | |
michael@0 | 651 | NS_IMETHODIMP nsWebBrowser::GotoIndex(int32_t aIndex) |
michael@0 | 652 | { |
michael@0 | 653 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 654 | |
michael@0 | 655 | return mDocShellAsNav->GotoIndex(aIndex); |
michael@0 | 656 | } |
michael@0 | 657 | |
michael@0 | 658 | NS_IMETHODIMP nsWebBrowser::Stop(uint32_t aStopFlags) |
michael@0 | 659 | { |
michael@0 | 660 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 661 | |
michael@0 | 662 | return mDocShellAsNav->Stop(aStopFlags); |
michael@0 | 663 | } |
michael@0 | 664 | |
michael@0 | 665 | NS_IMETHODIMP nsWebBrowser::GetCurrentURI(nsIURI** aURI) |
michael@0 | 666 | { |
michael@0 | 667 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 668 | |
michael@0 | 669 | return mDocShellAsNav->GetCurrentURI(aURI); |
michael@0 | 670 | } |
michael@0 | 671 | |
michael@0 | 672 | NS_IMETHODIMP nsWebBrowser::GetReferringURI(nsIURI** aURI) |
michael@0 | 673 | { |
michael@0 | 674 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 675 | |
michael@0 | 676 | return mDocShellAsNav->GetReferringURI(aURI); |
michael@0 | 677 | } |
michael@0 | 678 | |
michael@0 | 679 | NS_IMETHODIMP nsWebBrowser::SetSessionHistory(nsISHistory* aSessionHistory) |
michael@0 | 680 | { |
michael@0 | 681 | if(mDocShell) |
michael@0 | 682 | return mDocShellAsNav->SetSessionHistory(aSessionHistory); |
michael@0 | 683 | else |
michael@0 | 684 | mInitInfo->sessionHistory = aSessionHistory; |
michael@0 | 685 | |
michael@0 | 686 | return NS_OK; |
michael@0 | 687 | } |
michael@0 | 688 | |
michael@0 | 689 | NS_IMETHODIMP nsWebBrowser::GetSessionHistory(nsISHistory** aSessionHistory) |
michael@0 | 690 | { |
michael@0 | 691 | NS_ENSURE_ARG_POINTER(aSessionHistory); |
michael@0 | 692 | if(mDocShell) |
michael@0 | 693 | return mDocShellAsNav->GetSessionHistory(aSessionHistory); |
michael@0 | 694 | else |
michael@0 | 695 | *aSessionHistory = mInitInfo->sessionHistory; |
michael@0 | 696 | |
michael@0 | 697 | NS_IF_ADDREF(*aSessionHistory); |
michael@0 | 698 | |
michael@0 | 699 | return NS_OK; |
michael@0 | 700 | } |
michael@0 | 701 | |
michael@0 | 702 | |
michael@0 | 703 | NS_IMETHODIMP nsWebBrowser::GetDocument(nsIDOMDocument** aDocument) |
michael@0 | 704 | { |
michael@0 | 705 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 706 | |
michael@0 | 707 | return mDocShellAsNav->GetDocument(aDocument); |
michael@0 | 708 | } |
michael@0 | 709 | |
michael@0 | 710 | |
michael@0 | 711 | //***************************************************************************** |
michael@0 | 712 | // nsWebBrowser::nsIWebBrowserSetup |
michael@0 | 713 | //***************************************************************************** |
michael@0 | 714 | |
michael@0 | 715 | /* void setProperty (in unsigned long aId, in unsigned long aValue); */ |
michael@0 | 716 | NS_IMETHODIMP nsWebBrowser::SetProperty(uint32_t aId, uint32_t aValue) |
michael@0 | 717 | { |
michael@0 | 718 | nsresult rv = NS_OK; |
michael@0 | 719 | |
michael@0 | 720 | switch (aId) |
michael@0 | 721 | { |
michael@0 | 722 | case nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS: |
michael@0 | 723 | { |
michael@0 | 724 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 725 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 726 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 727 | NS_ERROR_INVALID_ARG); |
michael@0 | 728 | mDocShell->SetAllowPlugins(!!aValue); |
michael@0 | 729 | } |
michael@0 | 730 | break; |
michael@0 | 731 | case nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT: |
michael@0 | 732 | { |
michael@0 | 733 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 734 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 735 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 736 | NS_ERROR_INVALID_ARG); |
michael@0 | 737 | mDocShell->SetAllowJavascript(!!aValue); |
michael@0 | 738 | } |
michael@0 | 739 | break; |
michael@0 | 740 | case nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS: |
michael@0 | 741 | { |
michael@0 | 742 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 743 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 744 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 745 | NS_ERROR_INVALID_ARG); |
michael@0 | 746 | mDocShell->SetAllowMetaRedirects(!!aValue); |
michael@0 | 747 | } |
michael@0 | 748 | break; |
michael@0 | 749 | case nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES: |
michael@0 | 750 | { |
michael@0 | 751 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 752 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 753 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 754 | NS_ERROR_INVALID_ARG); |
michael@0 | 755 | mDocShell->SetAllowSubframes(!!aValue); |
michael@0 | 756 | } |
michael@0 | 757 | break; |
michael@0 | 758 | case nsIWebBrowserSetup::SETUP_ALLOW_IMAGES: |
michael@0 | 759 | { |
michael@0 | 760 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 761 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 762 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 763 | NS_ERROR_INVALID_ARG); |
michael@0 | 764 | mDocShell->SetAllowImages(!!aValue); |
michael@0 | 765 | } |
michael@0 | 766 | break; |
michael@0 | 767 | case nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH: |
michael@0 | 768 | { |
michael@0 | 769 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 770 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 771 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 772 | NS_ERROR_INVALID_ARG); |
michael@0 | 773 | mDocShell->SetAllowDNSPrefetch(!!aValue); |
michael@0 | 774 | } |
michael@0 | 775 | break; |
michael@0 | 776 | case nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY: |
michael@0 | 777 | { |
michael@0 | 778 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 779 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 780 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 781 | NS_ERROR_INVALID_ARG); |
michael@0 | 782 | rv = EnableGlobalHistory(!!aValue); |
michael@0 | 783 | mShouldEnableHistory = aValue; |
michael@0 | 784 | } |
michael@0 | 785 | break; |
michael@0 | 786 | case nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT: |
michael@0 | 787 | { |
michael@0 | 788 | // obsolete |
michael@0 | 789 | } |
michael@0 | 790 | break; |
michael@0 | 791 | case nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER: |
michael@0 | 792 | { |
michael@0 | 793 | NS_ENSURE_TRUE((aValue == static_cast<uint32_t>(true) || |
michael@0 | 794 | aValue == static_cast<uint32_t>(false)), |
michael@0 | 795 | NS_ERROR_INVALID_ARG); |
michael@0 | 796 | SetItemType(aValue ? static_cast<int32_t>(typeChromeWrapper) |
michael@0 | 797 | : static_cast<int32_t>(typeContentWrapper)); |
michael@0 | 798 | } |
michael@0 | 799 | break; |
michael@0 | 800 | default: |
michael@0 | 801 | rv = NS_ERROR_INVALID_ARG; |
michael@0 | 802 | |
michael@0 | 803 | } |
michael@0 | 804 | return rv; |
michael@0 | 805 | } |
michael@0 | 806 | |
michael@0 | 807 | |
michael@0 | 808 | //***************************************************************************** |
michael@0 | 809 | // nsWebBrowser::nsIWebProgressListener |
michael@0 | 810 | //***************************************************************************** |
michael@0 | 811 | |
michael@0 | 812 | /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */ |
michael@0 | 813 | NS_IMETHODIMP nsWebBrowser::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, uint32_t aStateFlags, nsresult aStatus) |
michael@0 | 814 | { |
michael@0 | 815 | if (mPersist) |
michael@0 | 816 | { |
michael@0 | 817 | mPersist->GetCurrentState(&mPersistCurrentState); |
michael@0 | 818 | } |
michael@0 | 819 | if (aStateFlags & STATE_IS_NETWORK && aStateFlags & STATE_STOP) |
michael@0 | 820 | { |
michael@0 | 821 | mPersist = nullptr; |
michael@0 | 822 | } |
michael@0 | 823 | if (mProgressListener) |
michael@0 | 824 | { |
michael@0 | 825 | return mProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus); |
michael@0 | 826 | } |
michael@0 | 827 | return NS_OK; |
michael@0 | 828 | } |
michael@0 | 829 | |
michael@0 | 830 | /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ |
michael@0 | 831 | NS_IMETHODIMP nsWebBrowser::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, int32_t aCurSelfProgress, int32_t aMaxSelfProgress, int32_t aCurTotalProgress, int32_t aMaxTotalProgress) |
michael@0 | 832 | { |
michael@0 | 833 | if (mPersist) |
michael@0 | 834 | { |
michael@0 | 835 | mPersist->GetCurrentState(&mPersistCurrentState); |
michael@0 | 836 | } |
michael@0 | 837 | if (mProgressListener) |
michael@0 | 838 | { |
michael@0 | 839 | return mProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); |
michael@0 | 840 | } |
michael@0 | 841 | return NS_OK; |
michael@0 | 842 | } |
michael@0 | 843 | |
michael@0 | 844 | /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location, in unsigned long aFlags); */ |
michael@0 | 845 | NS_IMETHODIMP nsWebBrowser::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location, uint32_t aFlags) |
michael@0 | 846 | { |
michael@0 | 847 | if (mProgressListener) |
michael@0 | 848 | { |
michael@0 | 849 | return mProgressListener->OnLocationChange(aWebProgress, aRequest, location, aFlags); |
michael@0 | 850 | } |
michael@0 | 851 | return NS_OK; |
michael@0 | 852 | } |
michael@0 | 853 | |
michael@0 | 854 | /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ |
michael@0 | 855 | NS_IMETHODIMP nsWebBrowser::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const char16_t *aMessage) |
michael@0 | 856 | { |
michael@0 | 857 | if (mProgressListener) |
michael@0 | 858 | { |
michael@0 | 859 | return mProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage); |
michael@0 | 860 | } |
michael@0 | 861 | return NS_OK; |
michael@0 | 862 | } |
michael@0 | 863 | |
michael@0 | 864 | /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ |
michael@0 | 865 | NS_IMETHODIMP nsWebBrowser::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, uint32_t state) |
michael@0 | 866 | { |
michael@0 | 867 | if (mProgressListener) |
michael@0 | 868 | { |
michael@0 | 869 | return mProgressListener->OnSecurityChange(aWebProgress, aRequest, state); |
michael@0 | 870 | } |
michael@0 | 871 | return NS_OK; |
michael@0 | 872 | } |
michael@0 | 873 | |
michael@0 | 874 | //***************************************************************************** |
michael@0 | 875 | // nsWebBrowser::nsIWebBrowserPersist |
michael@0 | 876 | //***************************************************************************** |
michael@0 | 877 | |
michael@0 | 878 | /* attribute unsigned long persistFlags; */ |
michael@0 | 879 | NS_IMETHODIMP nsWebBrowser::GetPersistFlags(uint32_t *aPersistFlags) |
michael@0 | 880 | { |
michael@0 | 881 | NS_ENSURE_ARG_POINTER(aPersistFlags); |
michael@0 | 882 | nsresult rv = NS_OK; |
michael@0 | 883 | if (mPersist) |
michael@0 | 884 | { |
michael@0 | 885 | rv = mPersist->GetPersistFlags(&mPersistFlags); |
michael@0 | 886 | } |
michael@0 | 887 | *aPersistFlags = mPersistFlags; |
michael@0 | 888 | return rv; |
michael@0 | 889 | } |
michael@0 | 890 | NS_IMETHODIMP nsWebBrowser::SetPersistFlags(uint32_t aPersistFlags) |
michael@0 | 891 | { |
michael@0 | 892 | nsresult rv = NS_OK; |
michael@0 | 893 | mPersistFlags = aPersistFlags; |
michael@0 | 894 | if (mPersist) |
michael@0 | 895 | { |
michael@0 | 896 | rv = mPersist->SetPersistFlags(mPersistFlags); |
michael@0 | 897 | mPersist->GetPersistFlags(&mPersistFlags); |
michael@0 | 898 | } |
michael@0 | 899 | return rv; |
michael@0 | 900 | } |
michael@0 | 901 | |
michael@0 | 902 | |
michael@0 | 903 | /* readonly attribute unsigned long currentState; */ |
michael@0 | 904 | NS_IMETHODIMP nsWebBrowser::GetCurrentState(uint32_t *aCurrentState) |
michael@0 | 905 | { |
michael@0 | 906 | NS_ENSURE_ARG_POINTER(aCurrentState); |
michael@0 | 907 | if (mPersist) |
michael@0 | 908 | { |
michael@0 | 909 | mPersist->GetCurrentState(&mPersistCurrentState); |
michael@0 | 910 | } |
michael@0 | 911 | *aCurrentState = mPersistCurrentState; |
michael@0 | 912 | return NS_OK; |
michael@0 | 913 | } |
michael@0 | 914 | |
michael@0 | 915 | /* readonly attribute nsresult result; */ |
michael@0 | 916 | NS_IMETHODIMP nsWebBrowser::GetResult(nsresult *aResult) |
michael@0 | 917 | { |
michael@0 | 918 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 919 | if (mPersist) |
michael@0 | 920 | { |
michael@0 | 921 | mPersist->GetResult(&mPersistResult); |
michael@0 | 922 | } |
michael@0 | 923 | *aResult = mPersistResult; |
michael@0 | 924 | return NS_OK; |
michael@0 | 925 | } |
michael@0 | 926 | |
michael@0 | 927 | /* attribute nsIWebBrowserPersistProgress progressListener; */ |
michael@0 | 928 | NS_IMETHODIMP nsWebBrowser::GetProgressListener(nsIWebProgressListener * *aProgressListener) |
michael@0 | 929 | { |
michael@0 | 930 | NS_ENSURE_ARG_POINTER(aProgressListener); |
michael@0 | 931 | *aProgressListener = mProgressListener; |
michael@0 | 932 | NS_IF_ADDREF(*aProgressListener); |
michael@0 | 933 | return NS_OK; |
michael@0 | 934 | } |
michael@0 | 935 | |
michael@0 | 936 | NS_IMETHODIMP nsWebBrowser::SetProgressListener(nsIWebProgressListener * aProgressListener) |
michael@0 | 937 | { |
michael@0 | 938 | mProgressListener = aProgressListener; |
michael@0 | 939 | return NS_OK; |
michael@0 | 940 | } |
michael@0 | 941 | |
michael@0 | 942 | /* void saveURI (in nsIURI aURI, in nsIURI aReferrer, |
michael@0 | 943 | in nsISupports aCacheKey, in nsIInputStream aPostData, in wstring aExtraHeaders, |
michael@0 | 944 | in nsISupports aFile, in nsILoadContext aPrivacyContext); */ |
michael@0 | 945 | NS_IMETHODIMP nsWebBrowser::SaveURI( |
michael@0 | 946 | nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer, nsIInputStream *aPostData, |
michael@0 | 947 | const char *aExtraHeaders, nsISupports *aFile, nsILoadContext* aPrivacyContext) |
michael@0 | 948 | { |
michael@0 | 949 | return SavePrivacyAwareURI(aURI, aCacheKey, aReferrer, aPostData, aExtraHeaders, |
michael@0 | 950 | aFile, aPrivacyContext && aPrivacyContext->UsePrivateBrowsing()); |
michael@0 | 951 | } |
michael@0 | 952 | |
michael@0 | 953 | NS_IMETHODIMP nsWebBrowser::SavePrivacyAwareURI( |
michael@0 | 954 | nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer, nsIInputStream *aPostData, |
michael@0 | 955 | const char *aExtraHeaders, nsISupports *aFile, bool aIsPrivate) |
michael@0 | 956 | { |
michael@0 | 957 | if (mPersist) |
michael@0 | 958 | { |
michael@0 | 959 | uint32_t currentState; |
michael@0 | 960 | mPersist->GetCurrentState(¤tState); |
michael@0 | 961 | if (currentState == PERSIST_STATE_FINISHED) |
michael@0 | 962 | { |
michael@0 | 963 | mPersist = nullptr; |
michael@0 | 964 | } |
michael@0 | 965 | else |
michael@0 | 966 | { |
michael@0 | 967 | // You can't save again until the last save has completed |
michael@0 | 968 | return NS_ERROR_FAILURE; |
michael@0 | 969 | } |
michael@0 | 970 | } |
michael@0 | 971 | |
michael@0 | 972 | nsCOMPtr<nsIURI> uri; |
michael@0 | 973 | if (aURI) |
michael@0 | 974 | { |
michael@0 | 975 | uri = aURI; |
michael@0 | 976 | } |
michael@0 | 977 | else |
michael@0 | 978 | { |
michael@0 | 979 | nsresult rv = GetCurrentURI(getter_AddRefs(uri)); |
michael@0 | 980 | if (NS_FAILED(rv)) |
michael@0 | 981 | { |
michael@0 | 982 | return NS_ERROR_FAILURE; |
michael@0 | 983 | } |
michael@0 | 984 | } |
michael@0 | 985 | |
michael@0 | 986 | // Create a throwaway persistence object to do the work |
michael@0 | 987 | nsresult rv; |
michael@0 | 988 | mPersist = do_CreateInstance(NS_WEBBROWSERPERSIST_CONTRACTID, &rv); |
michael@0 | 989 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 990 | mPersist->SetProgressListener(this); |
michael@0 | 991 | mPersist->SetPersistFlags(mPersistFlags); |
michael@0 | 992 | mPersist->GetCurrentState(&mPersistCurrentState); |
michael@0 | 993 | rv = mPersist->SavePrivacyAwareURI(uri, aCacheKey, aReferrer, aPostData, |
michael@0 | 994 | aExtraHeaders, aFile, aIsPrivate); |
michael@0 | 995 | if (NS_FAILED(rv)) |
michael@0 | 996 | { |
michael@0 | 997 | mPersist = nullptr; |
michael@0 | 998 | } |
michael@0 | 999 | return rv; |
michael@0 | 1000 | } |
michael@0 | 1001 | |
michael@0 | 1002 | /* void saveChannel (in nsIChannel aChannel, in nsISupports aFile); */ |
michael@0 | 1003 | NS_IMETHODIMP nsWebBrowser::SaveChannel( |
michael@0 | 1004 | nsIChannel* aChannel, nsISupports *aFile) |
michael@0 | 1005 | { |
michael@0 | 1006 | if (mPersist) |
michael@0 | 1007 | { |
michael@0 | 1008 | uint32_t currentState; |
michael@0 | 1009 | mPersist->GetCurrentState(¤tState); |
michael@0 | 1010 | if (currentState == PERSIST_STATE_FINISHED) |
michael@0 | 1011 | { |
michael@0 | 1012 | mPersist = nullptr; |
michael@0 | 1013 | } |
michael@0 | 1014 | else |
michael@0 | 1015 | { |
michael@0 | 1016 | // You can't save again until the last save has completed |
michael@0 | 1017 | return NS_ERROR_FAILURE; |
michael@0 | 1018 | } |
michael@0 | 1019 | } |
michael@0 | 1020 | |
michael@0 | 1021 | // Create a throwaway persistence object to do the work |
michael@0 | 1022 | nsresult rv; |
michael@0 | 1023 | mPersist = do_CreateInstance(NS_WEBBROWSERPERSIST_CONTRACTID, &rv); |
michael@0 | 1024 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 1025 | mPersist->SetProgressListener(this); |
michael@0 | 1026 | mPersist->SetPersistFlags(mPersistFlags); |
michael@0 | 1027 | mPersist->GetCurrentState(&mPersistCurrentState); |
michael@0 | 1028 | rv = mPersist->SaveChannel(aChannel, aFile); |
michael@0 | 1029 | if (NS_FAILED(rv)) |
michael@0 | 1030 | { |
michael@0 | 1031 | mPersist = nullptr; |
michael@0 | 1032 | } |
michael@0 | 1033 | return rv; |
michael@0 | 1034 | } |
michael@0 | 1035 | |
michael@0 | 1036 | /* void saveDocument (in nsIDOMDocument document, in nsISupports aFile, in nsISupports aDataPath); */ |
michael@0 | 1037 | NS_IMETHODIMP nsWebBrowser::SaveDocument( |
michael@0 | 1038 | nsIDOMDocument *aDocument, nsISupports *aFile, nsISupports *aDataPath, |
michael@0 | 1039 | const char *aOutputContentType, uint32_t aEncodingFlags, uint32_t aWrapColumn) |
michael@0 | 1040 | { |
michael@0 | 1041 | if (mPersist) |
michael@0 | 1042 | { |
michael@0 | 1043 | uint32_t currentState; |
michael@0 | 1044 | mPersist->GetCurrentState(¤tState); |
michael@0 | 1045 | if (currentState == PERSIST_STATE_FINISHED) |
michael@0 | 1046 | { |
michael@0 | 1047 | mPersist = nullptr; |
michael@0 | 1048 | } |
michael@0 | 1049 | else |
michael@0 | 1050 | { |
michael@0 | 1051 | // You can't save again until the last save has completed |
michael@0 | 1052 | return NS_ERROR_FAILURE; |
michael@0 | 1053 | } |
michael@0 | 1054 | } |
michael@0 | 1055 | |
michael@0 | 1056 | // Use the specified DOM document, or if none is specified, the one |
michael@0 | 1057 | // attached to the web browser. |
michael@0 | 1058 | |
michael@0 | 1059 | nsCOMPtr<nsIDOMDocument> doc; |
michael@0 | 1060 | if (aDocument) |
michael@0 | 1061 | { |
michael@0 | 1062 | doc = do_QueryInterface(aDocument); |
michael@0 | 1063 | } |
michael@0 | 1064 | else |
michael@0 | 1065 | { |
michael@0 | 1066 | GetDocument(getter_AddRefs(doc)); |
michael@0 | 1067 | } |
michael@0 | 1068 | if (!doc) |
michael@0 | 1069 | { |
michael@0 | 1070 | return NS_ERROR_FAILURE; |
michael@0 | 1071 | } |
michael@0 | 1072 | |
michael@0 | 1073 | // Create a throwaway persistence object to do the work |
michael@0 | 1074 | nsresult rv; |
michael@0 | 1075 | mPersist = do_CreateInstance(NS_WEBBROWSERPERSIST_CONTRACTID, &rv); |
michael@0 | 1076 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 1077 | mPersist->SetProgressListener(this); |
michael@0 | 1078 | mPersist->SetPersistFlags(mPersistFlags); |
michael@0 | 1079 | mPersist->GetCurrentState(&mPersistCurrentState); |
michael@0 | 1080 | rv = mPersist->SaveDocument(doc, aFile, aDataPath, aOutputContentType, aEncodingFlags, aWrapColumn); |
michael@0 | 1081 | if (NS_FAILED(rv)) |
michael@0 | 1082 | { |
michael@0 | 1083 | mPersist = nullptr; |
michael@0 | 1084 | } |
michael@0 | 1085 | return rv; |
michael@0 | 1086 | } |
michael@0 | 1087 | |
michael@0 | 1088 | /* void cancelSave(); */ |
michael@0 | 1089 | NS_IMETHODIMP nsWebBrowser::CancelSave() |
michael@0 | 1090 | { |
michael@0 | 1091 | if (mPersist) |
michael@0 | 1092 | { |
michael@0 | 1093 | return mPersist->CancelSave(); |
michael@0 | 1094 | } |
michael@0 | 1095 | return NS_OK; |
michael@0 | 1096 | } |
michael@0 | 1097 | |
michael@0 | 1098 | /* void cancel(nsresult aReason); */ |
michael@0 | 1099 | NS_IMETHODIMP nsWebBrowser::Cancel(nsresult aReason) |
michael@0 | 1100 | { |
michael@0 | 1101 | if (mPersist) |
michael@0 | 1102 | { |
michael@0 | 1103 | return mPersist->Cancel(aReason); |
michael@0 | 1104 | } |
michael@0 | 1105 | return NS_OK; |
michael@0 | 1106 | } |
michael@0 | 1107 | |
michael@0 | 1108 | |
michael@0 | 1109 | |
michael@0 | 1110 | |
michael@0 | 1111 | //***************************************************************************** |
michael@0 | 1112 | // nsWebBrowser::nsIBaseWindow |
michael@0 | 1113 | //***************************************************************************** |
michael@0 | 1114 | |
michael@0 | 1115 | NS_IMETHODIMP nsWebBrowser::InitWindow(nativeWindow aParentNativeWindow, |
michael@0 | 1116 | nsIWidget* aParentWidget, int32_t aX, int32_t aY, int32_t aCX, int32_t aCY) |
michael@0 | 1117 | { |
michael@0 | 1118 | NS_ENSURE_ARG(aParentNativeWindow || aParentWidget); |
michael@0 | 1119 | NS_ENSURE_STATE(!mDocShell || mInitInfo); |
michael@0 | 1120 | |
michael@0 | 1121 | if(aParentWidget) |
michael@0 | 1122 | NS_ENSURE_SUCCESS(SetParentWidget(aParentWidget), NS_ERROR_FAILURE); |
michael@0 | 1123 | else |
michael@0 | 1124 | NS_ENSURE_SUCCESS(SetParentNativeWindow(aParentNativeWindow), |
michael@0 | 1125 | NS_ERROR_FAILURE); |
michael@0 | 1126 | |
michael@0 | 1127 | NS_ENSURE_SUCCESS(SetPositionAndSize(aX, aY, aCX, aCY, false), |
michael@0 | 1128 | NS_ERROR_FAILURE); |
michael@0 | 1129 | |
michael@0 | 1130 | return NS_OK; |
michael@0 | 1131 | } |
michael@0 | 1132 | |
michael@0 | 1133 | NS_IMETHODIMP nsWebBrowser::Create() |
michael@0 | 1134 | { |
michael@0 | 1135 | NS_ENSURE_STATE(!mDocShell && (mParentNativeWindow || mParentWidget)); |
michael@0 | 1136 | |
michael@0 | 1137 | nsresult rv = EnsureDocShellTreeOwner(); |
michael@0 | 1138 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 1139 | |
michael@0 | 1140 | nsCOMPtr<nsIWidget> docShellParentWidget(mParentWidget); |
michael@0 | 1141 | if(!mParentWidget) // We need to create a widget |
michael@0 | 1142 | { |
michael@0 | 1143 | // Create the widget |
michael@0 | 1144 | mInternalWidget = do_CreateInstance(kChildCID, &rv); |
michael@0 | 1145 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 1146 | |
michael@0 | 1147 | docShellParentWidget = mInternalWidget; |
michael@0 | 1148 | nsWidgetInitData widgetInit; |
michael@0 | 1149 | |
michael@0 | 1150 | widgetInit.clipChildren = true; |
michael@0 | 1151 | |
michael@0 | 1152 | widgetInit.mWindowType = eWindowType_child; |
michael@0 | 1153 | nsIntRect bounds(mInitInfo->x, mInitInfo->y, mInitInfo->cx, mInitInfo->cy); |
michael@0 | 1154 | |
michael@0 | 1155 | mInternalWidget->SetWidgetListener(this); |
michael@0 | 1156 | mInternalWidget->Create(nullptr, mParentNativeWindow, bounds, nullptr, &widgetInit); |
michael@0 | 1157 | } |
michael@0 | 1158 | |
michael@0 | 1159 | nsCOMPtr<nsIDocShell> docShell(do_CreateInstance("@mozilla.org/docshell;1", &rv)); |
michael@0 | 1160 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 1161 | rv = SetDocShell(docShell); |
michael@0 | 1162 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 1163 | |
michael@0 | 1164 | // get the system default window background colour |
michael@0 | 1165 | LookAndFeel::GetColor(LookAndFeel::eColorID_WindowBackground, |
michael@0 | 1166 | &mBackgroundColor); |
michael@0 | 1167 | |
michael@0 | 1168 | // the docshell has been set so we now have our listener registrars. |
michael@0 | 1169 | if (mListenerArray) { |
michael@0 | 1170 | // we had queued up some listeners, let's register them now. |
michael@0 | 1171 | uint32_t count = mListenerArray->Length(); |
michael@0 | 1172 | uint32_t i = 0; |
michael@0 | 1173 | NS_ASSERTION(count > 0, "array construction problem"); |
michael@0 | 1174 | while (i < count) { |
michael@0 | 1175 | nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); |
michael@0 | 1176 | NS_ASSERTION(state, "array construction problem"); |
michael@0 | 1177 | nsCOMPtr<nsISupports> listener = do_QueryReferent(state->mWeakPtr); |
michael@0 | 1178 | NS_ASSERTION(listener, "bad listener"); |
michael@0 | 1179 | (void)BindListener(listener, state->mID); |
michael@0 | 1180 | i++; |
michael@0 | 1181 | } |
michael@0 | 1182 | for (uint32_t i = 0, end = mListenerArray->Length(); i < end; i++) { |
michael@0 | 1183 | nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); |
michael@0 | 1184 | delete state; |
michael@0 | 1185 | } |
michael@0 | 1186 | delete mListenerArray; |
michael@0 | 1187 | mListenerArray = nullptr; |
michael@0 | 1188 | } |
michael@0 | 1189 | |
michael@0 | 1190 | // HACK ALERT - this registration registers the nsDocShellTreeOwner as a |
michael@0 | 1191 | // nsIWebBrowserListener so it can setup its MouseListener in one of the |
michael@0 | 1192 | // progress callbacks. If we can register the MouseListener another way, this |
michael@0 | 1193 | // registration can go away, and nsDocShellTreeOwner can stop implementing |
michael@0 | 1194 | // nsIWebProgressListener. |
michael@0 | 1195 | nsCOMPtr<nsISupports> supports = nullptr; |
michael@0 | 1196 | (void)mDocShellTreeOwner->QueryInterface(NS_GET_IID(nsIWebProgressListener), |
michael@0 | 1197 | static_cast<void**>(getter_AddRefs(supports))); |
michael@0 | 1198 | (void)BindListener(supports, NS_GET_IID(nsIWebProgressListener)); |
michael@0 | 1199 | |
michael@0 | 1200 | NS_ENSURE_SUCCESS(mDocShellAsWin->InitWindow(nullptr, |
michael@0 | 1201 | docShellParentWidget, mInitInfo->x, mInitInfo->y, mInitInfo->cx, |
michael@0 | 1202 | mInitInfo->cy), NS_ERROR_FAILURE); |
michael@0 | 1203 | |
michael@0 | 1204 | mDocShell->SetName(mInitInfo->name); |
michael@0 | 1205 | if (mContentType == typeChromeWrapper) |
michael@0 | 1206 | { |
michael@0 | 1207 | mDocShell->SetItemType(nsIDocShellTreeItem::typeChrome); |
michael@0 | 1208 | } |
michael@0 | 1209 | else |
michael@0 | 1210 | { |
michael@0 | 1211 | mDocShell->SetItemType(nsIDocShellTreeItem::typeContent); |
michael@0 | 1212 | } |
michael@0 | 1213 | mDocShell->SetTreeOwner(mDocShellTreeOwner); |
michael@0 | 1214 | |
michael@0 | 1215 | // If the webbrowser is a content docshell item then we won't hear any |
michael@0 | 1216 | // events from subframes. To solve that we install our own chrome event handler |
michael@0 | 1217 | // that always gets called (even for subframes) for any bubbling event. |
michael@0 | 1218 | |
michael@0 | 1219 | if (!mInitInfo->sessionHistory) { |
michael@0 | 1220 | mInitInfo->sessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID, &rv); |
michael@0 | 1221 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 1222 | } |
michael@0 | 1223 | mDocShellAsNav->SetSessionHistory(mInitInfo->sessionHistory); |
michael@0 | 1224 | |
michael@0 | 1225 | if (XRE_GetProcessType() == GeckoProcessType_Default) { |
michael@0 | 1226 | // Hook up global history. Do not fail if we can't - just warn. |
michael@0 | 1227 | rv = EnableGlobalHistory(mShouldEnableHistory); |
michael@0 | 1228 | NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "EnableGlobalHistory() failed"); |
michael@0 | 1229 | } |
michael@0 | 1230 | |
michael@0 | 1231 | NS_ENSURE_SUCCESS(mDocShellAsWin->Create(), NS_ERROR_FAILURE); |
michael@0 | 1232 | |
michael@0 | 1233 | // Hook into the OnSecurityChange() notification for lock/unlock icon |
michael@0 | 1234 | // updates |
michael@0 | 1235 | nsCOMPtr<nsIDOMWindow> domWindow; |
michael@0 | 1236 | rv = GetContentDOMWindow(getter_AddRefs(domWindow)); |
michael@0 | 1237 | if (NS_SUCCEEDED(rv)) |
michael@0 | 1238 | { |
michael@0 | 1239 | // this works because the implementation of nsISecureBrowserUI |
michael@0 | 1240 | // (nsSecureBrowserUIImpl) gets a docShell from the domWindow, |
michael@0 | 1241 | // and calls docShell->SetSecurityUI(this); |
michael@0 | 1242 | nsCOMPtr<nsISecureBrowserUI> securityUI = |
michael@0 | 1243 | do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); |
michael@0 | 1244 | if (NS_SUCCEEDED(rv)) |
michael@0 | 1245 | securityUI->Init(domWindow); |
michael@0 | 1246 | } |
michael@0 | 1247 | |
michael@0 | 1248 | mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0) |
michael@0 | 1249 | mDocShellTreeOwner->AddChromeListeners(); |
michael@0 | 1250 | |
michael@0 | 1251 | delete mInitInfo; |
michael@0 | 1252 | mInitInfo = nullptr; |
michael@0 | 1253 | |
michael@0 | 1254 | return NS_OK; |
michael@0 | 1255 | } |
michael@0 | 1256 | |
michael@0 | 1257 | NS_IMETHODIMP nsWebBrowser::Destroy() |
michael@0 | 1258 | { |
michael@0 | 1259 | InternalDestroy(); |
michael@0 | 1260 | |
michael@0 | 1261 | if(!mInitInfo) |
michael@0 | 1262 | mInitInfo = new nsWebBrowserInitInfo(); |
michael@0 | 1263 | |
michael@0 | 1264 | return NS_OK; |
michael@0 | 1265 | } |
michael@0 | 1266 | |
michael@0 | 1267 | NS_IMETHODIMP nsWebBrowser::GetUnscaledDevicePixelsPerCSSPixel(double *aScale) |
michael@0 | 1268 | { |
michael@0 | 1269 | *aScale = mParentWidget ? mParentWidget->GetDefaultScale().scale : 1.0; |
michael@0 | 1270 | return NS_OK; |
michael@0 | 1271 | } |
michael@0 | 1272 | |
michael@0 | 1273 | NS_IMETHODIMP nsWebBrowser::SetPosition(int32_t aX, int32_t aY) |
michael@0 | 1274 | { |
michael@0 | 1275 | int32_t cx = 0; |
michael@0 | 1276 | int32_t cy = 0; |
michael@0 | 1277 | |
michael@0 | 1278 | GetSize(&cx, &cy); |
michael@0 | 1279 | |
michael@0 | 1280 | return SetPositionAndSize(aX, aY, cx, cy, false); |
michael@0 | 1281 | } |
michael@0 | 1282 | |
michael@0 | 1283 | NS_IMETHODIMP nsWebBrowser::GetPosition(int32_t* aX, int32_t* aY) |
michael@0 | 1284 | { |
michael@0 | 1285 | return GetPositionAndSize(aX, aY, nullptr, nullptr); |
michael@0 | 1286 | } |
michael@0 | 1287 | |
michael@0 | 1288 | NS_IMETHODIMP nsWebBrowser::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) |
michael@0 | 1289 | { |
michael@0 | 1290 | int32_t x = 0; |
michael@0 | 1291 | int32_t y = 0; |
michael@0 | 1292 | |
michael@0 | 1293 | GetPosition(&x, &y); |
michael@0 | 1294 | |
michael@0 | 1295 | return SetPositionAndSize(x, y, aCX, aCY, aRepaint); |
michael@0 | 1296 | } |
michael@0 | 1297 | |
michael@0 | 1298 | NS_IMETHODIMP nsWebBrowser::GetSize(int32_t* aCX, int32_t* aCY) |
michael@0 | 1299 | { |
michael@0 | 1300 | return GetPositionAndSize(nullptr, nullptr, aCX, aCY); |
michael@0 | 1301 | } |
michael@0 | 1302 | |
michael@0 | 1303 | NS_IMETHODIMP nsWebBrowser::SetPositionAndSize(int32_t aX, int32_t aY, |
michael@0 | 1304 | int32_t aCX, int32_t aCY, bool aRepaint) |
michael@0 | 1305 | { |
michael@0 | 1306 | if(!mDocShell) |
michael@0 | 1307 | { |
michael@0 | 1308 | mInitInfo->x = aX; |
michael@0 | 1309 | mInitInfo->y = aY; |
michael@0 | 1310 | mInitInfo->cx = aCX; |
michael@0 | 1311 | mInitInfo->cy = aCY; |
michael@0 | 1312 | } |
michael@0 | 1313 | else |
michael@0 | 1314 | { |
michael@0 | 1315 | int32_t doc_x = aX; |
michael@0 | 1316 | int32_t doc_y = aY; |
michael@0 | 1317 | |
michael@0 | 1318 | // If there is an internal widget we need to make the docShell coordinates |
michael@0 | 1319 | // relative to the internal widget rather than the calling app's parent. |
michael@0 | 1320 | // We also need to resize our widget then. |
michael@0 | 1321 | if(mInternalWidget) |
michael@0 | 1322 | { |
michael@0 | 1323 | doc_x = doc_y = 0; |
michael@0 | 1324 | NS_ENSURE_SUCCESS(mInternalWidget->Resize(aX, aY, aCX, aCY, aRepaint), |
michael@0 | 1325 | NS_ERROR_FAILURE); |
michael@0 | 1326 | } |
michael@0 | 1327 | // Now reposition/ resize the doc |
michael@0 | 1328 | NS_ENSURE_SUCCESS(mDocShellAsWin->SetPositionAndSize(doc_x, doc_y, aCX, aCY, |
michael@0 | 1329 | aRepaint), NS_ERROR_FAILURE); |
michael@0 | 1330 | } |
michael@0 | 1331 | |
michael@0 | 1332 | return NS_OK; |
michael@0 | 1333 | } |
michael@0 | 1334 | |
michael@0 | 1335 | NS_IMETHODIMP nsWebBrowser::GetPositionAndSize(int32_t* aX, int32_t* aY, |
michael@0 | 1336 | int32_t* aCX, int32_t* aCY) |
michael@0 | 1337 | { |
michael@0 | 1338 | if(!mDocShell) |
michael@0 | 1339 | { |
michael@0 | 1340 | if(aX) |
michael@0 | 1341 | *aX = mInitInfo->x; |
michael@0 | 1342 | if(aY) |
michael@0 | 1343 | *aY = mInitInfo->y; |
michael@0 | 1344 | if(aCX) |
michael@0 | 1345 | *aCX = mInitInfo->cx; |
michael@0 | 1346 | if(aCY) |
michael@0 | 1347 | *aCY = mInitInfo->cy; |
michael@0 | 1348 | } |
michael@0 | 1349 | else |
michael@0 | 1350 | { |
michael@0 | 1351 | if(mInternalWidget) |
michael@0 | 1352 | { |
michael@0 | 1353 | nsIntRect bounds; |
michael@0 | 1354 | NS_ENSURE_SUCCESS(mInternalWidget->GetBounds(bounds), NS_ERROR_FAILURE); |
michael@0 | 1355 | |
michael@0 | 1356 | if(aX) |
michael@0 | 1357 | *aX = bounds.x; |
michael@0 | 1358 | if(aY) |
michael@0 | 1359 | *aY = bounds.y; |
michael@0 | 1360 | if(aCX) |
michael@0 | 1361 | *aCX = bounds.width; |
michael@0 | 1362 | if(aCY) |
michael@0 | 1363 | *aCY = bounds.height; |
michael@0 | 1364 | return NS_OK; |
michael@0 | 1365 | } |
michael@0 | 1366 | else |
michael@0 | 1367 | return mDocShellAsWin->GetPositionAndSize(aX, aY, aCX, aCY); // Can directly return this as it is the |
michael@0 | 1368 | } |
michael@0 | 1369 | return NS_OK; |
michael@0 | 1370 | } |
michael@0 | 1371 | |
michael@0 | 1372 | NS_IMETHODIMP nsWebBrowser::Repaint(bool aForce) |
michael@0 | 1373 | { |
michael@0 | 1374 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1375 | return mDocShellAsWin->Repaint(aForce); // Can directly return this as it is the |
michael@0 | 1376 | } // same interface, thus same returns. |
michael@0 | 1377 | |
michael@0 | 1378 | NS_IMETHODIMP nsWebBrowser::GetParentWidget(nsIWidget** aParentWidget) |
michael@0 | 1379 | { |
michael@0 | 1380 | NS_ENSURE_ARG_POINTER(aParentWidget); |
michael@0 | 1381 | |
michael@0 | 1382 | *aParentWidget = mParentWidget; |
michael@0 | 1383 | |
michael@0 | 1384 | NS_IF_ADDREF(*aParentWidget); |
michael@0 | 1385 | |
michael@0 | 1386 | return NS_OK; |
michael@0 | 1387 | } |
michael@0 | 1388 | |
michael@0 | 1389 | NS_IMETHODIMP nsWebBrowser::SetParentWidget(nsIWidget* aParentWidget) |
michael@0 | 1390 | { |
michael@0 | 1391 | NS_ENSURE_STATE(!mDocShell); |
michael@0 | 1392 | |
michael@0 | 1393 | mParentWidget = aParentWidget; |
michael@0 | 1394 | if(mParentWidget) |
michael@0 | 1395 | mParentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET); |
michael@0 | 1396 | else |
michael@0 | 1397 | mParentNativeWindow = nullptr; |
michael@0 | 1398 | |
michael@0 | 1399 | return NS_OK; |
michael@0 | 1400 | } |
michael@0 | 1401 | |
michael@0 | 1402 | NS_IMETHODIMP nsWebBrowser::GetParentNativeWindow(nativeWindow* aParentNativeWindow) |
michael@0 | 1403 | { |
michael@0 | 1404 | NS_ENSURE_ARG_POINTER(aParentNativeWindow); |
michael@0 | 1405 | |
michael@0 | 1406 | *aParentNativeWindow = mParentNativeWindow; |
michael@0 | 1407 | |
michael@0 | 1408 | return NS_OK; |
michael@0 | 1409 | } |
michael@0 | 1410 | |
michael@0 | 1411 | NS_IMETHODIMP nsWebBrowser::SetParentNativeWindow(nativeWindow aParentNativeWindow) |
michael@0 | 1412 | { |
michael@0 | 1413 | NS_ENSURE_STATE(!mDocShell); |
michael@0 | 1414 | |
michael@0 | 1415 | mParentNativeWindow = aParentNativeWindow; |
michael@0 | 1416 | |
michael@0 | 1417 | return NS_OK; |
michael@0 | 1418 | } |
michael@0 | 1419 | |
michael@0 | 1420 | NS_IMETHODIMP nsWebBrowser::GetNativeHandle(nsAString& aNativeHandle) |
michael@0 | 1421 | { |
michael@0 | 1422 | // the nativeHandle should be accessed from nsIXULWindow |
michael@0 | 1423 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 1424 | } |
michael@0 | 1425 | |
michael@0 | 1426 | NS_IMETHODIMP nsWebBrowser::GetVisibility(bool* visibility) |
michael@0 | 1427 | { |
michael@0 | 1428 | NS_ENSURE_ARG_POINTER(visibility); |
michael@0 | 1429 | |
michael@0 | 1430 | if(!mDocShell) |
michael@0 | 1431 | *visibility = mInitInfo->visible; |
michael@0 | 1432 | else |
michael@0 | 1433 | NS_ENSURE_SUCCESS(mDocShellAsWin->GetVisibility(visibility), NS_ERROR_FAILURE); |
michael@0 | 1434 | |
michael@0 | 1435 | return NS_OK; |
michael@0 | 1436 | } |
michael@0 | 1437 | |
michael@0 | 1438 | NS_IMETHODIMP nsWebBrowser::SetVisibility(bool aVisibility) |
michael@0 | 1439 | { |
michael@0 | 1440 | if(!mDocShell) |
michael@0 | 1441 | mInitInfo->visible = aVisibility; |
michael@0 | 1442 | else |
michael@0 | 1443 | { |
michael@0 | 1444 | NS_ENSURE_SUCCESS(mDocShellAsWin->SetVisibility(aVisibility), NS_ERROR_FAILURE); |
michael@0 | 1445 | if(mInternalWidget) |
michael@0 | 1446 | mInternalWidget->Show(aVisibility); |
michael@0 | 1447 | } |
michael@0 | 1448 | |
michael@0 | 1449 | return NS_OK; |
michael@0 | 1450 | } |
michael@0 | 1451 | |
michael@0 | 1452 | NS_IMETHODIMP nsWebBrowser::GetEnabled(bool* aEnabled) |
michael@0 | 1453 | { |
michael@0 | 1454 | if (mInternalWidget) { |
michael@0 | 1455 | *aEnabled = mInternalWidget->IsEnabled(); |
michael@0 | 1456 | return NS_OK; |
michael@0 | 1457 | } |
michael@0 | 1458 | |
michael@0 | 1459 | return NS_ERROR_FAILURE; |
michael@0 | 1460 | } |
michael@0 | 1461 | |
michael@0 | 1462 | NS_IMETHODIMP nsWebBrowser::SetEnabled(bool aEnabled) |
michael@0 | 1463 | { |
michael@0 | 1464 | if (mInternalWidget) |
michael@0 | 1465 | return mInternalWidget->Enable(aEnabled); |
michael@0 | 1466 | return NS_ERROR_FAILURE; |
michael@0 | 1467 | } |
michael@0 | 1468 | |
michael@0 | 1469 | NS_IMETHODIMP nsWebBrowser::GetMainWidget(nsIWidget** mainWidget) |
michael@0 | 1470 | { |
michael@0 | 1471 | NS_ENSURE_ARG_POINTER(mainWidget); |
michael@0 | 1472 | |
michael@0 | 1473 | if(mInternalWidget) |
michael@0 | 1474 | *mainWidget = mInternalWidget; |
michael@0 | 1475 | else |
michael@0 | 1476 | *mainWidget = mParentWidget; |
michael@0 | 1477 | |
michael@0 | 1478 | NS_IF_ADDREF(*mainWidget); |
michael@0 | 1479 | |
michael@0 | 1480 | return NS_OK; |
michael@0 | 1481 | } |
michael@0 | 1482 | |
michael@0 | 1483 | NS_IMETHODIMP nsWebBrowser::SetFocus() |
michael@0 | 1484 | { |
michael@0 | 1485 | nsCOMPtr<nsIDOMWindow> window = do_GetInterface(mDocShell); |
michael@0 | 1486 | NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); |
michael@0 | 1487 | |
michael@0 | 1488 | nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); |
michael@0 | 1489 | return fm ? fm->SetFocusedWindow(window) : NS_OK; |
michael@0 | 1490 | } |
michael@0 | 1491 | |
michael@0 | 1492 | NS_IMETHODIMP nsWebBrowser::GetTitle(char16_t** aTitle) |
michael@0 | 1493 | { |
michael@0 | 1494 | NS_ENSURE_ARG_POINTER(aTitle); |
michael@0 | 1495 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1496 | |
michael@0 | 1497 | NS_ENSURE_SUCCESS(mDocShellAsWin->GetTitle(aTitle), NS_ERROR_FAILURE); |
michael@0 | 1498 | |
michael@0 | 1499 | return NS_OK; |
michael@0 | 1500 | } |
michael@0 | 1501 | |
michael@0 | 1502 | NS_IMETHODIMP nsWebBrowser::SetTitle(const char16_t* aTitle) |
michael@0 | 1503 | { |
michael@0 | 1504 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1505 | |
michael@0 | 1506 | NS_ENSURE_SUCCESS(mDocShellAsWin->SetTitle(aTitle), NS_ERROR_FAILURE); |
michael@0 | 1507 | |
michael@0 | 1508 | return NS_OK; |
michael@0 | 1509 | } |
michael@0 | 1510 | |
michael@0 | 1511 | //***************************************************************************** |
michael@0 | 1512 | // nsWebBrowser::nsIScrollable |
michael@0 | 1513 | //***************************************************************************** |
michael@0 | 1514 | |
michael@0 | 1515 | NS_IMETHODIMP nsWebBrowser::GetDefaultScrollbarPreferences(int32_t aScrollOrientation, |
michael@0 | 1516 | int32_t* aScrollbarPref) |
michael@0 | 1517 | { |
michael@0 | 1518 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1519 | |
michael@0 | 1520 | return mDocShellAsScrollable->GetDefaultScrollbarPreferences(aScrollOrientation, |
michael@0 | 1521 | aScrollbarPref); |
michael@0 | 1522 | } |
michael@0 | 1523 | |
michael@0 | 1524 | NS_IMETHODIMP nsWebBrowser::SetDefaultScrollbarPreferences(int32_t aScrollOrientation, |
michael@0 | 1525 | int32_t aScrollbarPref) |
michael@0 | 1526 | { |
michael@0 | 1527 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1528 | |
michael@0 | 1529 | return mDocShellAsScrollable->SetDefaultScrollbarPreferences(aScrollOrientation, |
michael@0 | 1530 | aScrollbarPref); |
michael@0 | 1531 | } |
michael@0 | 1532 | |
michael@0 | 1533 | NS_IMETHODIMP nsWebBrowser::GetScrollbarVisibility(bool* aVerticalVisible, |
michael@0 | 1534 | bool* aHorizontalVisible) |
michael@0 | 1535 | { |
michael@0 | 1536 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1537 | |
michael@0 | 1538 | return mDocShellAsScrollable->GetScrollbarVisibility(aVerticalVisible, |
michael@0 | 1539 | aHorizontalVisible); |
michael@0 | 1540 | } |
michael@0 | 1541 | |
michael@0 | 1542 | //***************************************************************************** |
michael@0 | 1543 | // nsWebBrowser::nsITextScroll |
michael@0 | 1544 | //***************************************************************************** |
michael@0 | 1545 | |
michael@0 | 1546 | NS_IMETHODIMP nsWebBrowser::ScrollByLines(int32_t aNumLines) |
michael@0 | 1547 | { |
michael@0 | 1548 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1549 | |
michael@0 | 1550 | return mDocShellAsTextScroll->ScrollByLines(aNumLines); |
michael@0 | 1551 | } |
michael@0 | 1552 | |
michael@0 | 1553 | NS_IMETHODIMP nsWebBrowser::ScrollByPages(int32_t aNumPages) |
michael@0 | 1554 | { |
michael@0 | 1555 | NS_ENSURE_STATE(mDocShell); |
michael@0 | 1556 | |
michael@0 | 1557 | return mDocShellAsTextScroll->ScrollByPages(aNumPages); |
michael@0 | 1558 | } |
michael@0 | 1559 | |
michael@0 | 1560 | |
michael@0 | 1561 | //***************************************************************************** |
michael@0 | 1562 | // nsWebBrowser: Listener Helpers |
michael@0 | 1563 | //***************************************************************************** |
michael@0 | 1564 | |
michael@0 | 1565 | NS_IMETHODIMP nsWebBrowser::SetDocShell(nsIDocShell* aDocShell) |
michael@0 | 1566 | { |
michael@0 | 1567 | nsCOMPtr<nsIDocShell> kungFuDeathGrip(mDocShell); |
michael@0 | 1568 | if(aDocShell) |
michael@0 | 1569 | { |
michael@0 | 1570 | NS_ENSURE_TRUE(!mDocShell, NS_ERROR_FAILURE); |
michael@0 | 1571 | |
michael@0 | 1572 | nsCOMPtr<nsIInterfaceRequestor> req(do_QueryInterface(aDocShell)); |
michael@0 | 1573 | nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(aDocShell)); |
michael@0 | 1574 | nsCOMPtr<nsIWebNavigation> nav(do_QueryInterface(aDocShell)); |
michael@0 | 1575 | nsCOMPtr<nsIScrollable> scrollable(do_QueryInterface(aDocShell)); |
michael@0 | 1576 | nsCOMPtr<nsITextScroll> textScroll(do_QueryInterface(aDocShell)); |
michael@0 | 1577 | nsCOMPtr<nsIWebProgress> progress(do_GetInterface(aDocShell)); |
michael@0 | 1578 | NS_ENSURE_TRUE(req && baseWin && nav && scrollable && textScroll && progress, |
michael@0 | 1579 | NS_ERROR_FAILURE); |
michael@0 | 1580 | |
michael@0 | 1581 | mDocShell = aDocShell; |
michael@0 | 1582 | mDocShellAsReq = req; |
michael@0 | 1583 | mDocShellAsWin = baseWin; |
michael@0 | 1584 | mDocShellAsNav = nav; |
michael@0 | 1585 | mDocShellAsScrollable = scrollable; |
michael@0 | 1586 | mDocShellAsTextScroll = textScroll; |
michael@0 | 1587 | mWebProgress = progress; |
michael@0 | 1588 | |
michael@0 | 1589 | // By default, do not allow DNS prefetch, so we don't break our frozen |
michael@0 | 1590 | // API. Embeddors who decide to enable it should do so manually. |
michael@0 | 1591 | mDocShell->SetAllowDNSPrefetch(false); |
michael@0 | 1592 | |
michael@0 | 1593 | // It's possible to call setIsActive() on us before we have a docshell. |
michael@0 | 1594 | // If we're getting a docshell now, pass along our desired value. The |
michael@0 | 1595 | // default here (true) matches the default of the docshell, so this is |
michael@0 | 1596 | // a no-op unless setIsActive(false) has been called on us. |
michael@0 | 1597 | mDocShell->SetIsActive(mIsActive); |
michael@0 | 1598 | } |
michael@0 | 1599 | else |
michael@0 | 1600 | { |
michael@0 | 1601 | if (mDocShellTreeOwner) |
michael@0 | 1602 | mDocShellTreeOwner->RemoveFromWatcher(); // evil twin of Add in Create() |
michael@0 | 1603 | if (mDocShellAsWin) |
michael@0 | 1604 | mDocShellAsWin->Destroy(); |
michael@0 | 1605 | |
michael@0 | 1606 | mDocShell = nullptr; |
michael@0 | 1607 | mDocShellAsReq = nullptr; |
michael@0 | 1608 | mDocShellAsWin = nullptr; |
michael@0 | 1609 | mDocShellAsNav = nullptr; |
michael@0 | 1610 | mDocShellAsScrollable = nullptr; |
michael@0 | 1611 | mDocShellAsTextScroll = nullptr; |
michael@0 | 1612 | mWebProgress = nullptr; |
michael@0 | 1613 | } |
michael@0 | 1614 | |
michael@0 | 1615 | return NS_OK; |
michael@0 | 1616 | } |
michael@0 | 1617 | |
michael@0 | 1618 | NS_IMETHODIMP nsWebBrowser::EnsureDocShellTreeOwner() |
michael@0 | 1619 | { |
michael@0 | 1620 | if(mDocShellTreeOwner) |
michael@0 | 1621 | return NS_OK; |
michael@0 | 1622 | |
michael@0 | 1623 | mDocShellTreeOwner = new nsDocShellTreeOwner(); |
michael@0 | 1624 | NS_ENSURE_TRUE(mDocShellTreeOwner, NS_ERROR_OUT_OF_MEMORY); |
michael@0 | 1625 | |
michael@0 | 1626 | NS_ADDREF(mDocShellTreeOwner); |
michael@0 | 1627 | mDocShellTreeOwner->WebBrowser(this); |
michael@0 | 1628 | |
michael@0 | 1629 | return NS_OK; |
michael@0 | 1630 | } |
michael@0 | 1631 | |
michael@0 | 1632 | static void DrawThebesLayer(ThebesLayer* aLayer, |
michael@0 | 1633 | gfxContext* aContext, |
michael@0 | 1634 | const nsIntRegion& aRegionToDraw, |
michael@0 | 1635 | DrawRegionClip aClip, |
michael@0 | 1636 | const nsIntRegion& aRegionToInvalidate, |
michael@0 | 1637 | void* aCallbackData) |
michael@0 | 1638 | { |
michael@0 | 1639 | nscolor* color = static_cast<nscolor*>(aCallbackData); |
michael@0 | 1640 | aContext->NewPath(); |
michael@0 | 1641 | aContext->SetColor(gfxRGBA(*color)); |
michael@0 | 1642 | nsIntRect dirtyRect = aRegionToDraw.GetBounds(); |
michael@0 | 1643 | aContext->Rectangle(gfxRect(dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height)); |
michael@0 | 1644 | aContext->Fill(); |
michael@0 | 1645 | } |
michael@0 | 1646 | |
michael@0 | 1647 | void nsWebBrowser::WindowRaised(nsIWidget* aWidget) |
michael@0 | 1648 | { |
michael@0 | 1649 | #if defined(DEBUG_smaug) |
michael@0 | 1650 | nsCOMPtr<nsIDOMDocument> domDocument = do_GetInterface(mDocShell); |
michael@0 | 1651 | nsAutoString documentURI; |
michael@0 | 1652 | domDocument->GetDocumentURI(documentURI); |
michael@0 | 1653 | printf("nsWebBrowser::NS_ACTIVATE %p %s\n", (void*)this, |
michael@0 | 1654 | NS_ConvertUTF16toUTF8(documentURI).get()); |
michael@0 | 1655 | #endif |
michael@0 | 1656 | Activate(); |
michael@0 | 1657 | } |
michael@0 | 1658 | |
michael@0 | 1659 | void nsWebBrowser::WindowLowered(nsIWidget* aWidget) |
michael@0 | 1660 | { |
michael@0 | 1661 | #if defined(DEBUG_smaug) |
michael@0 | 1662 | nsCOMPtr<nsIDOMDocument> domDocument = do_GetInterface(mDocShell); |
michael@0 | 1663 | nsAutoString documentURI; |
michael@0 | 1664 | domDocument->GetDocumentURI(documentURI); |
michael@0 | 1665 | printf("nsWebBrowser::NS_DEACTIVATE %p %s\n", (void*)this, |
michael@0 | 1666 | NS_ConvertUTF16toUTF8(documentURI).get()); |
michael@0 | 1667 | #endif |
michael@0 | 1668 | Deactivate(); |
michael@0 | 1669 | } |
michael@0 | 1670 | |
michael@0 | 1671 | bool nsWebBrowser::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) |
michael@0 | 1672 | { |
michael@0 | 1673 | LayerManager* layerManager = aWidget->GetLayerManager(); |
michael@0 | 1674 | NS_ASSERTION(layerManager, "Must be in paint event"); |
michael@0 | 1675 | |
michael@0 | 1676 | layerManager->BeginTransaction(); |
michael@0 | 1677 | nsRefPtr<ThebesLayer> root = layerManager->CreateThebesLayer(); |
michael@0 | 1678 | if (root) { |
michael@0 | 1679 | nsIntRect dirtyRect = aRegion.GetBounds(); |
michael@0 | 1680 | root->SetVisibleRegion(dirtyRect); |
michael@0 | 1681 | layerManager->SetRoot(root); |
michael@0 | 1682 | } |
michael@0 | 1683 | |
michael@0 | 1684 | layerManager->EndTransaction(DrawThebesLayer, &mBackgroundColor); |
michael@0 | 1685 | return true; |
michael@0 | 1686 | } |
michael@0 | 1687 | |
michael@0 | 1688 | NS_IMETHODIMP nsWebBrowser::GetPrimaryContentWindow(nsIDOMWindow** aDOMWindow) |
michael@0 | 1689 | { |
michael@0 | 1690 | *aDOMWindow = 0; |
michael@0 | 1691 | |
michael@0 | 1692 | nsCOMPtr<nsIDocShellTreeItem> item; |
michael@0 | 1693 | NS_ENSURE_TRUE(mDocShellTreeOwner, NS_ERROR_FAILURE); |
michael@0 | 1694 | mDocShellTreeOwner->GetPrimaryContentShell(getter_AddRefs(item)); |
michael@0 | 1695 | NS_ENSURE_TRUE(item, NS_ERROR_FAILURE); |
michael@0 | 1696 | |
michael@0 | 1697 | nsCOMPtr<nsIDocShell> docShell; |
michael@0 | 1698 | docShell = do_QueryInterface(item); |
michael@0 | 1699 | NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); |
michael@0 | 1700 | |
michael@0 | 1701 | nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(docShell); |
michael@0 | 1702 | NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE); |
michael@0 | 1703 | |
michael@0 | 1704 | *aDOMWindow = domWindow; |
michael@0 | 1705 | NS_ADDREF(*aDOMWindow); |
michael@0 | 1706 | return NS_OK; |
michael@0 | 1707 | |
michael@0 | 1708 | } |
michael@0 | 1709 | //***************************************************************************** |
michael@0 | 1710 | // nsWebBrowser::nsIWebBrowserFocus |
michael@0 | 1711 | //***************************************************************************** |
michael@0 | 1712 | |
michael@0 | 1713 | /* void activate (); */ |
michael@0 | 1714 | NS_IMETHODIMP nsWebBrowser::Activate(void) |
michael@0 | 1715 | { |
michael@0 | 1716 | nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); |
michael@0 | 1717 | nsCOMPtr<nsIDOMWindow> window = do_GetInterface(mDocShell); |
michael@0 | 1718 | if (fm && window) |
michael@0 | 1719 | return fm->WindowRaised(window); |
michael@0 | 1720 | return NS_OK; |
michael@0 | 1721 | } |
michael@0 | 1722 | |
michael@0 | 1723 | /* void deactivate (); */ |
michael@0 | 1724 | NS_IMETHODIMP nsWebBrowser::Deactivate(void) |
michael@0 | 1725 | { |
michael@0 | 1726 | nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); |
michael@0 | 1727 | nsCOMPtr<nsIDOMWindow> window = do_GetInterface(mDocShell); |
michael@0 | 1728 | if (fm && window) |
michael@0 | 1729 | return fm->WindowLowered(window); |
michael@0 | 1730 | return NS_OK; |
michael@0 | 1731 | } |
michael@0 | 1732 | |
michael@0 | 1733 | /* void setFocusAtFirstElement (); */ |
michael@0 | 1734 | NS_IMETHODIMP nsWebBrowser::SetFocusAtFirstElement(void) |
michael@0 | 1735 | { |
michael@0 | 1736 | return NS_OK; |
michael@0 | 1737 | } |
michael@0 | 1738 | |
michael@0 | 1739 | /* void setFocusAtLastElement (); */ |
michael@0 | 1740 | NS_IMETHODIMP nsWebBrowser::SetFocusAtLastElement(void) |
michael@0 | 1741 | { |
michael@0 | 1742 | return NS_OK; |
michael@0 | 1743 | } |
michael@0 | 1744 | |
michael@0 | 1745 | /* attribute nsIDOMWindow focusedWindow; */ |
michael@0 | 1746 | NS_IMETHODIMP nsWebBrowser::GetFocusedWindow(nsIDOMWindow * *aFocusedWindow) |
michael@0 | 1747 | { |
michael@0 | 1748 | NS_ENSURE_ARG_POINTER(aFocusedWindow); |
michael@0 | 1749 | *aFocusedWindow = nullptr; |
michael@0 | 1750 | |
michael@0 | 1751 | nsCOMPtr<nsIDOMWindow> window = do_GetInterface(mDocShell); |
michael@0 | 1752 | NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); |
michael@0 | 1753 | |
michael@0 | 1754 | nsCOMPtr<nsIDOMElement> focusedElement; |
michael@0 | 1755 | nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); |
michael@0 | 1756 | return fm ? fm->GetFocusedElementForWindow(window, true, aFocusedWindow, |
michael@0 | 1757 | getter_AddRefs(focusedElement)) : NS_OK; |
michael@0 | 1758 | } |
michael@0 | 1759 | |
michael@0 | 1760 | NS_IMETHODIMP nsWebBrowser::SetFocusedWindow(nsIDOMWindow * aFocusedWindow) |
michael@0 | 1761 | { |
michael@0 | 1762 | nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); |
michael@0 | 1763 | return fm ? fm->SetFocusedWindow(aFocusedWindow) : NS_OK; |
michael@0 | 1764 | } |
michael@0 | 1765 | |
michael@0 | 1766 | /* attribute nsIDOMElement focusedElement; */ |
michael@0 | 1767 | NS_IMETHODIMP nsWebBrowser::GetFocusedElement(nsIDOMElement * *aFocusedElement) |
michael@0 | 1768 | { |
michael@0 | 1769 | NS_ENSURE_ARG_POINTER(aFocusedElement); |
michael@0 | 1770 | |
michael@0 | 1771 | nsCOMPtr<nsIDOMWindow> window = do_GetInterface(mDocShell); |
michael@0 | 1772 | NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); |
michael@0 | 1773 | |
michael@0 | 1774 | nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); |
michael@0 | 1775 | return fm ? fm->GetFocusedElementForWindow(window, true, nullptr, aFocusedElement) : NS_OK; |
michael@0 | 1776 | } |
michael@0 | 1777 | |
michael@0 | 1778 | NS_IMETHODIMP nsWebBrowser::SetFocusedElement(nsIDOMElement * aFocusedElement) |
michael@0 | 1779 | { |
michael@0 | 1780 | nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); |
michael@0 | 1781 | return fm ? fm->SetFocus(aFocusedElement, 0) : NS_OK; |
michael@0 | 1782 | } |
michael@0 | 1783 | |
michael@0 | 1784 | //***************************************************************************** |
michael@0 | 1785 | // nsWebBrowser::nsIWebBrowserStream |
michael@0 | 1786 | //***************************************************************************** |
michael@0 | 1787 | |
michael@0 | 1788 | /* void openStream(in nsIURI aBaseURI, in ACString aContentType); */ |
michael@0 | 1789 | NS_IMETHODIMP nsWebBrowser::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType) |
michael@0 | 1790 | { |
michael@0 | 1791 | nsresult rv; |
michael@0 | 1792 | |
michael@0 | 1793 | if (!mStream) { |
michael@0 | 1794 | mStream = new nsEmbedStream(); |
michael@0 | 1795 | if (!mStream) |
michael@0 | 1796 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 1797 | |
michael@0 | 1798 | mStreamGuard = do_QueryInterface(mStream); |
michael@0 | 1799 | mStream->InitOwner(this); |
michael@0 | 1800 | rv = mStream->Init(); |
michael@0 | 1801 | if (NS_FAILED(rv)) |
michael@0 | 1802 | return rv; |
michael@0 | 1803 | } |
michael@0 | 1804 | |
michael@0 | 1805 | return mStream->OpenStream(aBaseURI, aContentType); |
michael@0 | 1806 | } |
michael@0 | 1807 | |
michael@0 | 1808 | /* void appendToStream([const, array, size_is(aLen)] in octet aData, |
michael@0 | 1809 | * in unsigned long aLen); */ |
michael@0 | 1810 | NS_IMETHODIMP nsWebBrowser::AppendToStream(const uint8_t *aData, uint32_t aLen) |
michael@0 | 1811 | { |
michael@0 | 1812 | if (!mStream) |
michael@0 | 1813 | return NS_ERROR_FAILURE; |
michael@0 | 1814 | |
michael@0 | 1815 | return mStream->AppendToStream(aData, aLen); |
michael@0 | 1816 | } |
michael@0 | 1817 | |
michael@0 | 1818 | /* void closeStream (); */ |
michael@0 | 1819 | NS_IMETHODIMP nsWebBrowser::CloseStream() |
michael@0 | 1820 | { |
michael@0 | 1821 | nsresult rv; |
michael@0 | 1822 | |
michael@0 | 1823 | if (!mStream) |
michael@0 | 1824 | return NS_ERROR_FAILURE; |
michael@0 | 1825 | rv = mStream->CloseStream(); |
michael@0 | 1826 | |
michael@0 | 1827 | // release |
michael@0 | 1828 | mStream = 0; |
michael@0 | 1829 | mStreamGuard = 0; |
michael@0 | 1830 | |
michael@0 | 1831 | return rv; |
michael@0 | 1832 | } |