Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: set ts=2 sw=2 et tw=79: |
michael@0 | 3 | * |
michael@0 | 4 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | // Local Includes |
michael@0 | 9 | #include "nsContentTreeOwner.h" |
michael@0 | 10 | #include "nsXULWindow.h" |
michael@0 | 11 | |
michael@0 | 12 | // Helper Classes |
michael@0 | 13 | #include "nsIServiceManager.h" |
michael@0 | 14 | #include "nsAutoPtr.h" |
michael@0 | 15 | |
michael@0 | 16 | // Interfaces needed to be included |
michael@0 | 17 | #include "nsIDOMNode.h" |
michael@0 | 18 | #include "nsIDOMElement.h" |
michael@0 | 19 | #include "nsIDOMNodeList.h" |
michael@0 | 20 | #include "nsIDOMWindow.h" |
michael@0 | 21 | #include "nsIDOMChromeWindow.h" |
michael@0 | 22 | #include "nsIBrowserDOMWindow.h" |
michael@0 | 23 | #include "nsIDOMXULElement.h" |
michael@0 | 24 | #include "nsIEmbeddingSiteWindow.h" |
michael@0 | 25 | #include "nsIPrompt.h" |
michael@0 | 26 | #include "nsIAuthPrompt.h" |
michael@0 | 27 | #include "nsIWindowMediator.h" |
michael@0 | 28 | #include "nsIXULBrowserWindow.h" |
michael@0 | 29 | #include "nsIPrincipal.h" |
michael@0 | 30 | #include "nsIURIFixup.h" |
michael@0 | 31 | #include "nsCDefaultURIFixup.h" |
michael@0 | 32 | #include "nsIWebNavigation.h" |
michael@0 | 33 | #include "nsDocShellCID.h" |
michael@0 | 34 | #include "nsIExternalURLHandlerService.h" |
michael@0 | 35 | #include "nsIMIMEInfo.h" |
michael@0 | 36 | #include "nsIWidget.h" |
michael@0 | 37 | #include "mozilla/BrowserElementParent.h" |
michael@0 | 38 | |
michael@0 | 39 | #include "nsIDOMDocument.h" |
michael@0 | 40 | #include "nsIScriptObjectPrincipal.h" |
michael@0 | 41 | #include "nsIURI.h" |
michael@0 | 42 | #include "nsIDocument.h" |
michael@0 | 43 | #if defined(XP_MACOSX) |
michael@0 | 44 | #include "nsThreadUtils.h" |
michael@0 | 45 | #endif |
michael@0 | 46 | |
michael@0 | 47 | #include "mozilla/Preferences.h" |
michael@0 | 48 | #include "mozilla/dom/Element.h" |
michael@0 | 49 | #include "mozilla/dom/ScriptSettings.h" |
michael@0 | 50 | |
michael@0 | 51 | using namespace mozilla; |
michael@0 | 52 | |
michael@0 | 53 | //***************************************************************************** |
michael@0 | 54 | //*** nsSiteWindow declaration |
michael@0 | 55 | //***************************************************************************** |
michael@0 | 56 | |
michael@0 | 57 | class nsSiteWindow : public nsIEmbeddingSiteWindow |
michael@0 | 58 | { |
michael@0 | 59 | public: |
michael@0 | 60 | nsSiteWindow(nsContentTreeOwner *aAggregator); |
michael@0 | 61 | virtual ~nsSiteWindow(); |
michael@0 | 62 | |
michael@0 | 63 | NS_DECL_ISUPPORTS |
michael@0 | 64 | NS_DECL_NSIEMBEDDINGSITEWINDOW |
michael@0 | 65 | |
michael@0 | 66 | private: |
michael@0 | 67 | nsContentTreeOwner *mAggregator; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | //***************************************************************************** |
michael@0 | 71 | //*** nsContentTreeOwner: Object Management |
michael@0 | 72 | //***************************************************************************** |
michael@0 | 73 | |
michael@0 | 74 | nsContentTreeOwner::nsContentTreeOwner(bool fPrimary) : mXULWindow(nullptr), |
michael@0 | 75 | mPrimary(fPrimary), mContentTitleSetting(false) |
michael@0 | 76 | { |
michael@0 | 77 | // note if this fails, QI on nsIEmbeddingSiteWindow(2) will simply fail |
michael@0 | 78 | mSiteWindow = new nsSiteWindow(this); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | nsContentTreeOwner::~nsContentTreeOwner() |
michael@0 | 82 | { |
michael@0 | 83 | delete mSiteWindow; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | //***************************************************************************** |
michael@0 | 87 | // nsContentTreeOwner::nsISupports |
michael@0 | 88 | //***************************************************************************** |
michael@0 | 89 | |
michael@0 | 90 | NS_IMPL_ADDREF(nsContentTreeOwner) |
michael@0 | 91 | NS_IMPL_RELEASE(nsContentTreeOwner) |
michael@0 | 92 | |
michael@0 | 93 | NS_INTERFACE_MAP_BEGIN(nsContentTreeOwner) |
michael@0 | 94 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner) |
michael@0 | 95 | NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner) |
michael@0 | 96 | NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) |
michael@0 | 97 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) |
michael@0 | 98 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome2) |
michael@0 | 99 | NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome3) |
michael@0 | 100 | NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) |
michael@0 | 101 | NS_INTERFACE_MAP_ENTRY(nsIWindowProvider) |
michael@0 | 102 | // NOTE: This is using aggregation because there are some properties and |
michael@0 | 103 | // method on nsIBaseWindow (which we implement) and on |
michael@0 | 104 | // nsIEmbeddingSiteWindow (which we also implement) that have the same name. |
michael@0 | 105 | // And it just so happens that we want different behavior for these methods |
michael@0 | 106 | // and properties depending on the interface through which they're called |
michael@0 | 107 | // (SetFocus() is a good example here). If it were not for that, we could |
michael@0 | 108 | // ditch the aggregation and just deal with not being able to use NS_DECL_* |
michael@0 | 109 | // macros for this stuff.... |
michael@0 | 110 | NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIEmbeddingSiteWindow, mSiteWindow) |
michael@0 | 111 | NS_INTERFACE_MAP_END |
michael@0 | 112 | |
michael@0 | 113 | //***************************************************************************** |
michael@0 | 114 | // nsContentTreeOwner::nsIInterfaceRequestor |
michael@0 | 115 | //***************************************************************************** |
michael@0 | 116 | |
michael@0 | 117 | NS_IMETHODIMP nsContentTreeOwner::GetInterface(const nsIID& aIID, void** aSink) |
michael@0 | 118 | { |
michael@0 | 119 | NS_ENSURE_ARG_POINTER(aSink); |
michael@0 | 120 | *aSink = 0; |
michael@0 | 121 | |
michael@0 | 122 | if(aIID.Equals(NS_GET_IID(nsIPrompt))) { |
michael@0 | 123 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 124 | return mXULWindow->GetInterface(aIID, aSink); |
michael@0 | 125 | } |
michael@0 | 126 | if(aIID.Equals(NS_GET_IID(nsIAuthPrompt))) { |
michael@0 | 127 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 128 | return mXULWindow->GetInterface(aIID, aSink); |
michael@0 | 129 | } |
michael@0 | 130 | if (aIID.Equals(NS_GET_IID(nsIDocShellTreeItem))) { |
michael@0 | 131 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 132 | nsCOMPtr<nsIDocShell> shell; |
michael@0 | 133 | mXULWindow->GetDocShell(getter_AddRefs(shell)); |
michael@0 | 134 | if (shell) |
michael@0 | 135 | return shell->QueryInterface(aIID, aSink); |
michael@0 | 136 | return NS_ERROR_FAILURE; |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) { |
michael@0 | 140 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 141 | nsCOMPtr<nsIDocShellTreeItem> shell; |
michael@0 | 142 | mXULWindow->GetPrimaryContentShell(getter_AddRefs(shell)); |
michael@0 | 143 | if (shell) { |
michael@0 | 144 | nsCOMPtr<nsIInterfaceRequestor> thing(do_QueryInterface(shell)); |
michael@0 | 145 | if (thing) |
michael@0 | 146 | return thing->GetInterface(aIID, aSink); |
michael@0 | 147 | } |
michael@0 | 148 | return NS_ERROR_FAILURE; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | if (aIID.Equals(NS_GET_IID(nsIXULWindow))) { |
michael@0 | 152 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 153 | return mXULWindow->QueryInterface(aIID, aSink); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | return QueryInterface(aIID, aSink); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | //***************************************************************************** |
michael@0 | 160 | // nsContentTreeOwner::nsIDocShellTreeOwner |
michael@0 | 161 | //***************************************************************************** |
michael@0 | 162 | |
michael@0 | 163 | NS_IMETHODIMP nsContentTreeOwner::FindItemWithName(const char16_t* aName, |
michael@0 | 164 | nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem* aOriginalRequestor, |
michael@0 | 165 | nsIDocShellTreeItem** aFoundItem) |
michael@0 | 166 | { |
michael@0 | 167 | NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); |
michael@0 | 168 | |
michael@0 | 169 | NS_ENSURE_ARG_POINTER(aFoundItem); |
michael@0 | 170 | |
michael@0 | 171 | *aFoundItem = nullptr; |
michael@0 | 172 | |
michael@0 | 173 | bool fIs_Content = false; |
michael@0 | 174 | |
michael@0 | 175 | /* Special Cases */ |
michael@0 | 176 | if (!aName || !*aName) |
michael@0 | 177 | return NS_OK; |
michael@0 | 178 | |
michael@0 | 179 | nsDependentString name(aName); |
michael@0 | 180 | |
michael@0 | 181 | if (name.LowerCaseEqualsLiteral("_blank")) |
michael@0 | 182 | return NS_OK; |
michael@0 | 183 | // _main is an IE target which should be case-insensitive but isn't |
michael@0 | 184 | // see bug 217886 for details |
michael@0 | 185 | if (name.LowerCaseEqualsLiteral("_content") || |
michael@0 | 186 | name.EqualsLiteral("_main")) { |
michael@0 | 187 | // If we're being called with an aRequestor and it's targetable, just |
michael@0 | 188 | // return it -- _main and _content from inside targetable content shells |
michael@0 | 189 | // should just be that content shell. Note that we don't have to worry |
michael@0 | 190 | // about the case when it's not targetable because it's primary -- that |
michael@0 | 191 | // will Just Work when we call GetPrimaryContentShell. |
michael@0 | 192 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 193 | if (aRequestor) { |
michael@0 | 194 | // This better be the root item! |
michael@0 | 195 | #ifdef DEBUG |
michael@0 | 196 | nsCOMPtr<nsIDocShellTreeItem> debugRoot; |
michael@0 | 197 | aRequestor->GetSameTypeRootTreeItem(getter_AddRefs(debugRoot)); |
michael@0 | 198 | NS_ASSERTION(SameCOMIdentity(debugRoot, aRequestor), |
michael@0 | 199 | "Bogus aRequestor"); |
michael@0 | 200 | #endif |
michael@0 | 201 | |
michael@0 | 202 | int32_t count = mXULWindow->mTargetableShells.Count(); |
michael@0 | 203 | for (int32_t i = 0; i < count; ++i) { |
michael@0 | 204 | nsCOMPtr<nsIDocShellTreeItem> item = |
michael@0 | 205 | do_QueryReferent(mXULWindow->mTargetableShells[i]); |
michael@0 | 206 | if (SameCOMIdentity(item, aRequestor)) { |
michael@0 | 207 | NS_ADDREF(*aFoundItem = aRequestor); |
michael@0 | 208 | return NS_OK; |
michael@0 | 209 | } |
michael@0 | 210 | } |
michael@0 | 211 | } |
michael@0 | 212 | mXULWindow->GetPrimaryContentShell(aFoundItem); |
michael@0 | 213 | if(*aFoundItem) |
michael@0 | 214 | return NS_OK; |
michael@0 | 215 | // Fall through and keep looking... |
michael@0 | 216 | fIs_Content = true; |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID)); |
michael@0 | 220 | NS_ENSURE_TRUE(windowMediator, NS_ERROR_FAILURE); |
michael@0 | 221 | |
michael@0 | 222 | nsCOMPtr<nsISimpleEnumerator> windowEnumerator; |
michael@0 | 223 | NS_ENSURE_SUCCESS(windowMediator->GetXULWindowEnumerator(nullptr, |
michael@0 | 224 | getter_AddRefs(windowEnumerator)), NS_ERROR_FAILURE); |
michael@0 | 225 | |
michael@0 | 226 | bool more; |
michael@0 | 227 | |
michael@0 | 228 | windowEnumerator->HasMoreElements(&more); |
michael@0 | 229 | while(more) { |
michael@0 | 230 | nsCOMPtr<nsISupports> nextWindow = nullptr; |
michael@0 | 231 | windowEnumerator->GetNext(getter_AddRefs(nextWindow)); |
michael@0 | 232 | nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow)); |
michael@0 | 233 | NS_ENSURE_TRUE(xulWindow, NS_ERROR_FAILURE); |
michael@0 | 234 | |
michael@0 | 235 | if (fIs_Content) { |
michael@0 | 236 | xulWindow->GetPrimaryContentShell(aFoundItem); |
michael@0 | 237 | } else { |
michael@0 | 238 | // Get all the targetable windows from xulWindow and search them |
michael@0 | 239 | nsRefPtr<nsXULWindow> win; |
michael@0 | 240 | xulWindow->QueryInterface(NS_GET_IID(nsXULWindow), getter_AddRefs(win)); |
michael@0 | 241 | if (win) { |
michael@0 | 242 | int32_t count = win->mTargetableShells.Count(); |
michael@0 | 243 | int32_t i; |
michael@0 | 244 | for (i = 0; i < count && !*aFoundItem; ++i) { |
michael@0 | 245 | nsCOMPtr<nsIDocShellTreeItem> shellAsTreeItem = |
michael@0 | 246 | do_QueryReferent(win->mTargetableShells[i]); |
michael@0 | 247 | if (shellAsTreeItem) { |
michael@0 | 248 | // Get the root tree item of same type, since roots are the only |
michael@0 | 249 | // things that call into the treeowner to look for named items. |
michael@0 | 250 | // XXXbz ideally we could guarantee that mTargetableShells only |
michael@0 | 251 | // contains roots, but the current treeowner apis don't allow |
michael@0 | 252 | // that... yet. |
michael@0 | 253 | nsCOMPtr<nsIDocShellTreeItem> root; |
michael@0 | 254 | shellAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(root)); |
michael@0 | 255 | NS_ASSERTION(root, "Must have root tree item of same type"); |
michael@0 | 256 | shellAsTreeItem.swap(root); |
michael@0 | 257 | if (aRequestor != shellAsTreeItem) { |
michael@0 | 258 | // Do this so we can pass in the tree owner as the |
michael@0 | 259 | // requestor so the child knows not to call back up. |
michael@0 | 260 | nsCOMPtr<nsIDocShellTreeOwner> shellOwner; |
michael@0 | 261 | shellAsTreeItem->GetTreeOwner(getter_AddRefs(shellOwner)); |
michael@0 | 262 | nsCOMPtr<nsISupports> shellOwnerSupports = |
michael@0 | 263 | do_QueryInterface(shellOwner); |
michael@0 | 264 | |
michael@0 | 265 | shellAsTreeItem->FindItemWithName(aName, shellOwnerSupports, |
michael@0 | 266 | aOriginalRequestor, |
michael@0 | 267 | aFoundItem); |
michael@0 | 268 | } |
michael@0 | 269 | } |
michael@0 | 270 | } |
michael@0 | 271 | } |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | if (*aFoundItem) |
michael@0 | 275 | return NS_OK; |
michael@0 | 276 | |
michael@0 | 277 | windowEnumerator->HasMoreElements(&more); |
michael@0 | 278 | } |
michael@0 | 279 | return NS_OK; |
michael@0 | 280 | } |
michael@0 | 281 | |
michael@0 | 282 | NS_IMETHODIMP |
michael@0 | 283 | nsContentTreeOwner::ContentShellAdded(nsIDocShellTreeItem* aContentShell, |
michael@0 | 284 | bool aPrimary, bool aTargetable, |
michael@0 | 285 | const nsAString& aID) |
michael@0 | 286 | { |
michael@0 | 287 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 288 | return mXULWindow->ContentShellAdded(aContentShell, aPrimary, aTargetable, |
michael@0 | 289 | aID); |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | NS_IMETHODIMP |
michael@0 | 293 | nsContentTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell) |
michael@0 | 294 | { |
michael@0 | 295 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 296 | return mXULWindow->ContentShellRemoved(aContentShell); |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | NS_IMETHODIMP |
michael@0 | 300 | nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell) |
michael@0 | 301 | { |
michael@0 | 302 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 303 | return mXULWindow->GetPrimaryContentShell(aShell); |
michael@0 | 304 | } |
michael@0 | 305 | |
michael@0 | 306 | NS_IMETHODIMP |
michael@0 | 307 | nsContentTreeOwner::GetContentWindow(JSContext* aCx, |
michael@0 | 308 | JS::MutableHandle<JS::Value> aVal) |
michael@0 | 309 | { |
michael@0 | 310 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 311 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | NS_IMETHODIMP nsContentTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem, |
michael@0 | 315 | int32_t aCX, int32_t aCY) |
michael@0 | 316 | { |
michael@0 | 317 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 318 | return mXULWindow->SizeShellTo(aShellItem, aCX, aCY); |
michael@0 | 319 | } |
michael@0 | 320 | |
michael@0 | 321 | NS_IMETHODIMP |
michael@0 | 322 | nsContentTreeOwner::SetPersistence(bool aPersistPosition, |
michael@0 | 323 | bool aPersistSize, |
michael@0 | 324 | bool aPersistSizeMode) |
michael@0 | 325 | { |
michael@0 | 326 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 327 | nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); |
michael@0 | 328 | if (!docShellElement) |
michael@0 | 329 | return NS_ERROR_FAILURE; |
michael@0 | 330 | |
michael@0 | 331 | nsAutoString persistString; |
michael@0 | 332 | docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString); |
michael@0 | 333 | |
michael@0 | 334 | bool saveString = false; |
michael@0 | 335 | int32_t index; |
michael@0 | 336 | |
michael@0 | 337 | // Set X |
michael@0 | 338 | index = persistString.Find("screenX"); |
michael@0 | 339 | if (!aPersistPosition && index >= 0) { |
michael@0 | 340 | persistString.Cut(index, 7); |
michael@0 | 341 | saveString = true; |
michael@0 | 342 | } else if (aPersistPosition && index < 0) { |
michael@0 | 343 | persistString.AppendLiteral(" screenX"); |
michael@0 | 344 | saveString = true; |
michael@0 | 345 | } |
michael@0 | 346 | // Set Y |
michael@0 | 347 | index = persistString.Find("screenY"); |
michael@0 | 348 | if (!aPersistPosition && index >= 0) { |
michael@0 | 349 | persistString.Cut(index, 7); |
michael@0 | 350 | saveString = true; |
michael@0 | 351 | } else if (aPersistPosition && index < 0) { |
michael@0 | 352 | persistString.AppendLiteral(" screenY"); |
michael@0 | 353 | saveString = true; |
michael@0 | 354 | } |
michael@0 | 355 | // Set CX |
michael@0 | 356 | index = persistString.Find("width"); |
michael@0 | 357 | if (!aPersistSize && index >= 0) { |
michael@0 | 358 | persistString.Cut(index, 5); |
michael@0 | 359 | saveString = true; |
michael@0 | 360 | } else if (aPersistSize && index < 0) { |
michael@0 | 361 | persistString.AppendLiteral(" width"); |
michael@0 | 362 | saveString = true; |
michael@0 | 363 | } |
michael@0 | 364 | // Set CY |
michael@0 | 365 | index = persistString.Find("height"); |
michael@0 | 366 | if (!aPersistSize && index >= 0) { |
michael@0 | 367 | persistString.Cut(index, 6); |
michael@0 | 368 | saveString = true; |
michael@0 | 369 | } else if (aPersistSize && index < 0) { |
michael@0 | 370 | persistString.AppendLiteral(" height"); |
michael@0 | 371 | saveString = true; |
michael@0 | 372 | } |
michael@0 | 373 | // Set SizeMode |
michael@0 | 374 | index = persistString.Find("sizemode"); |
michael@0 | 375 | if (!aPersistSizeMode && (index >= 0)) { |
michael@0 | 376 | persistString.Cut(index, 8); |
michael@0 | 377 | saveString = true; |
michael@0 | 378 | } else if (aPersistSizeMode && (index < 0)) { |
michael@0 | 379 | persistString.AppendLiteral(" sizemode"); |
michael@0 | 380 | saveString = true; |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | ErrorResult rv; |
michael@0 | 384 | if(saveString) { |
michael@0 | 385 | docShellElement->SetAttribute(NS_LITERAL_STRING("persist"), persistString, rv); |
michael@0 | 386 | } |
michael@0 | 387 | |
michael@0 | 388 | return NS_OK; |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | NS_IMETHODIMP |
michael@0 | 392 | nsContentTreeOwner::GetPersistence(bool* aPersistPosition, |
michael@0 | 393 | bool* aPersistSize, |
michael@0 | 394 | bool* aPersistSizeMode) |
michael@0 | 395 | { |
michael@0 | 396 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 397 | nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); |
michael@0 | 398 | if (!docShellElement) |
michael@0 | 399 | return NS_ERROR_FAILURE; |
michael@0 | 400 | |
michael@0 | 401 | nsAutoString persistString; |
michael@0 | 402 | docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString); |
michael@0 | 403 | |
michael@0 | 404 | // data structure doesn't quite match the question, but it's close enough |
michael@0 | 405 | // for what we want (since this method is never actually called...) |
michael@0 | 406 | if (aPersistPosition) |
michael@0 | 407 | *aPersistPosition = persistString.Find("screenX") >= 0 || persistString.Find("screenY") >= 0 ? true : false; |
michael@0 | 408 | if (aPersistSize) |
michael@0 | 409 | *aPersistSize = persistString.Find("width") >= 0 || persistString.Find("height") >= 0 ? true : false; |
michael@0 | 410 | if (aPersistSizeMode) |
michael@0 | 411 | *aPersistSizeMode = persistString.Find("sizemode") >= 0 ? true : false; |
michael@0 | 412 | |
michael@0 | 413 | return NS_OK; |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | NS_IMETHODIMP |
michael@0 | 417 | nsContentTreeOwner::GetTargetableShellCount(uint32_t* aResult) |
michael@0 | 418 | { |
michael@0 | 419 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 420 | *aResult = mXULWindow->mTargetableShells.Count(); |
michael@0 | 421 | return NS_OK; |
michael@0 | 422 | } |
michael@0 | 423 | |
michael@0 | 424 | //***************************************************************************** |
michael@0 | 425 | // nsContentTreeOwner::nsIWebBrowserChrome3 |
michael@0 | 426 | //***************************************************************************** |
michael@0 | 427 | |
michael@0 | 428 | NS_IMETHODIMP nsContentTreeOwner::OnBeforeLinkTraversal(const nsAString &originalTarget, |
michael@0 | 429 | nsIURI *linkURI, |
michael@0 | 430 | nsIDOMNode *linkNode, |
michael@0 | 431 | bool isAppTab, |
michael@0 | 432 | nsAString &_retval) |
michael@0 | 433 | { |
michael@0 | 434 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 435 | |
michael@0 | 436 | nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow; |
michael@0 | 437 | mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow)); |
michael@0 | 438 | |
michael@0 | 439 | if (xulBrowserWindow) |
michael@0 | 440 | return xulBrowserWindow->OnBeforeLinkTraversal(originalTarget, linkURI, |
michael@0 | 441 | linkNode, isAppTab, _retval); |
michael@0 | 442 | |
michael@0 | 443 | _retval = originalTarget; |
michael@0 | 444 | return NS_OK; |
michael@0 | 445 | } |
michael@0 | 446 | |
michael@0 | 447 | //***************************************************************************** |
michael@0 | 448 | // nsContentTreeOwner::nsIWebBrowserChrome2 |
michael@0 | 449 | //***************************************************************************** |
michael@0 | 450 | |
michael@0 | 451 | NS_IMETHODIMP nsContentTreeOwner::SetStatusWithContext(uint32_t aStatusType, |
michael@0 | 452 | const nsAString &aStatusText, |
michael@0 | 453 | nsISupports *aStatusContext) |
michael@0 | 454 | { |
michael@0 | 455 | // We only allow the status to be set from the primary content shell |
michael@0 | 456 | if (!mPrimary && aStatusType != STATUS_LINK) |
michael@0 | 457 | return NS_OK; |
michael@0 | 458 | |
michael@0 | 459 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 460 | |
michael@0 | 461 | nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow; |
michael@0 | 462 | mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow)); |
michael@0 | 463 | |
michael@0 | 464 | if (xulBrowserWindow) |
michael@0 | 465 | { |
michael@0 | 466 | switch(aStatusType) |
michael@0 | 467 | { |
michael@0 | 468 | case STATUS_SCRIPT: |
michael@0 | 469 | xulBrowserWindow->SetJSStatus(aStatusText); |
michael@0 | 470 | break; |
michael@0 | 471 | case STATUS_LINK: |
michael@0 | 472 | { |
michael@0 | 473 | nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aStatusContext); |
michael@0 | 474 | xulBrowserWindow->SetOverLink(aStatusText, element); |
michael@0 | 475 | break; |
michael@0 | 476 | } |
michael@0 | 477 | } |
michael@0 | 478 | } |
michael@0 | 479 | |
michael@0 | 480 | return NS_OK; |
michael@0 | 481 | } |
michael@0 | 482 | |
michael@0 | 483 | //***************************************************************************** |
michael@0 | 484 | // nsContentTreeOwner::nsIWebBrowserChrome |
michael@0 | 485 | //***************************************************************************** |
michael@0 | 486 | |
michael@0 | 487 | NS_IMETHODIMP nsContentTreeOwner::SetStatus(uint32_t aStatusType, |
michael@0 | 488 | const char16_t* aStatus) |
michael@0 | 489 | { |
michael@0 | 490 | return SetStatusWithContext(aStatusType, |
michael@0 | 491 | aStatus ? static_cast<const nsString &>(nsDependentString(aStatus)) |
michael@0 | 492 | : EmptyString(), |
michael@0 | 493 | nullptr); |
michael@0 | 494 | } |
michael@0 | 495 | |
michael@0 | 496 | NS_IMETHODIMP nsContentTreeOwner::SetWebBrowser(nsIWebBrowser* aWebBrowser) |
michael@0 | 497 | { |
michael@0 | 498 | NS_ERROR("Haven't Implemented this yet"); |
michael@0 | 499 | return NS_ERROR_FAILURE; |
michael@0 | 500 | } |
michael@0 | 501 | |
michael@0 | 502 | NS_IMETHODIMP nsContentTreeOwner::GetWebBrowser(nsIWebBrowser** aWebBrowser) |
michael@0 | 503 | { |
michael@0 | 504 | // Unimplemented, and probably will remain so; xpfe windows have docshells, |
michael@0 | 505 | // not webbrowsers. |
michael@0 | 506 | NS_ENSURE_ARG_POINTER(aWebBrowser); |
michael@0 | 507 | *aWebBrowser = 0; |
michael@0 | 508 | return NS_ERROR_FAILURE; |
michael@0 | 509 | } |
michael@0 | 510 | |
michael@0 | 511 | NS_IMETHODIMP nsContentTreeOwner::SetChromeFlags(uint32_t aChromeFlags) |
michael@0 | 512 | { |
michael@0 | 513 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 514 | return mXULWindow->SetChromeFlags(aChromeFlags); |
michael@0 | 515 | } |
michael@0 | 516 | |
michael@0 | 517 | NS_IMETHODIMP nsContentTreeOwner::GetChromeFlags(uint32_t* aChromeFlags) |
michael@0 | 518 | { |
michael@0 | 519 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 520 | return mXULWindow->GetChromeFlags(aChromeFlags); |
michael@0 | 521 | } |
michael@0 | 522 | |
michael@0 | 523 | NS_IMETHODIMP nsContentTreeOwner::DestroyBrowserWindow() |
michael@0 | 524 | { |
michael@0 | 525 | NS_ERROR("Haven't Implemented this yet"); |
michael@0 | 526 | return NS_ERROR_FAILURE; |
michael@0 | 527 | } |
michael@0 | 528 | |
michael@0 | 529 | NS_IMETHODIMP nsContentTreeOwner::SizeBrowserTo(int32_t aCX, int32_t aCY) |
michael@0 | 530 | { |
michael@0 | 531 | NS_ERROR("Haven't Implemented this yet"); |
michael@0 | 532 | return NS_ERROR_FAILURE; |
michael@0 | 533 | } |
michael@0 | 534 | |
michael@0 | 535 | NS_IMETHODIMP nsContentTreeOwner::ShowAsModal() |
michael@0 | 536 | { |
michael@0 | 537 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 538 | return mXULWindow->ShowModal(); |
michael@0 | 539 | } |
michael@0 | 540 | |
michael@0 | 541 | NS_IMETHODIMP nsContentTreeOwner::IsWindowModal(bool *_retval) |
michael@0 | 542 | { |
michael@0 | 543 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 544 | *_retval = mXULWindow->mContinueModalLoop; |
michael@0 | 545 | return NS_OK; |
michael@0 | 546 | } |
michael@0 | 547 | |
michael@0 | 548 | NS_IMETHODIMP nsContentTreeOwner::ExitModalEventLoop(nsresult aStatus) |
michael@0 | 549 | { |
michael@0 | 550 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 551 | return mXULWindow->ExitModalLoop(aStatus); |
michael@0 | 552 | } |
michael@0 | 553 | |
michael@0 | 554 | //***************************************************************************** |
michael@0 | 555 | // nsContentTreeOwner::nsIBaseWindow |
michael@0 | 556 | //***************************************************************************** |
michael@0 | 557 | |
michael@0 | 558 | NS_IMETHODIMP nsContentTreeOwner::InitWindow(nativeWindow aParentNativeWindow, |
michael@0 | 559 | nsIWidget* parentWidget, int32_t x, int32_t y, int32_t cx, int32_t cy) |
michael@0 | 560 | { |
michael@0 | 561 | // Ignore wigdet parents for now. Don't think those are a vaild thing to call. |
michael@0 | 562 | NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, cx, cy, false), NS_ERROR_FAILURE); |
michael@0 | 563 | |
michael@0 | 564 | return NS_OK; |
michael@0 | 565 | } |
michael@0 | 566 | |
michael@0 | 567 | NS_IMETHODIMP nsContentTreeOwner::Create() |
michael@0 | 568 | { |
michael@0 | 569 | NS_ASSERTION(false, "You can't call this"); |
michael@0 | 570 | return NS_ERROR_UNEXPECTED; |
michael@0 | 571 | } |
michael@0 | 572 | |
michael@0 | 573 | NS_IMETHODIMP nsContentTreeOwner::Destroy() |
michael@0 | 574 | { |
michael@0 | 575 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 576 | return mXULWindow->Destroy(); |
michael@0 | 577 | } |
michael@0 | 578 | |
michael@0 | 579 | NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) |
michael@0 | 580 | { |
michael@0 | 581 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 582 | return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale); |
michael@0 | 583 | } |
michael@0 | 584 | |
michael@0 | 585 | NS_IMETHODIMP nsContentTreeOwner::SetPosition(int32_t aX, int32_t aY) |
michael@0 | 586 | { |
michael@0 | 587 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 588 | return mXULWindow->SetPosition(aX, aY); |
michael@0 | 589 | } |
michael@0 | 590 | |
michael@0 | 591 | NS_IMETHODIMP nsContentTreeOwner::GetPosition(int32_t* aX, int32_t* aY) |
michael@0 | 592 | { |
michael@0 | 593 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 594 | return mXULWindow->GetPosition(aX, aY); |
michael@0 | 595 | } |
michael@0 | 596 | |
michael@0 | 597 | NS_IMETHODIMP nsContentTreeOwner::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) |
michael@0 | 598 | { |
michael@0 | 599 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 600 | return mXULWindow->SetSize(aCX, aCY, aRepaint); |
michael@0 | 601 | } |
michael@0 | 602 | |
michael@0 | 603 | NS_IMETHODIMP nsContentTreeOwner::GetSize(int32_t* aCX, int32_t* aCY) |
michael@0 | 604 | { |
michael@0 | 605 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 606 | return mXULWindow->GetSize(aCX, aCY); |
michael@0 | 607 | } |
michael@0 | 608 | |
michael@0 | 609 | NS_IMETHODIMP nsContentTreeOwner::SetPositionAndSize(int32_t aX, int32_t aY, |
michael@0 | 610 | int32_t aCX, int32_t aCY, bool aRepaint) |
michael@0 | 611 | { |
michael@0 | 612 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 613 | return mXULWindow->SetPositionAndSize(aX, aY, aCX, aCY, aRepaint); |
michael@0 | 614 | } |
michael@0 | 615 | |
michael@0 | 616 | NS_IMETHODIMP nsContentTreeOwner::GetPositionAndSize(int32_t* aX, int32_t* aY, |
michael@0 | 617 | int32_t* aCX, int32_t* aCY) |
michael@0 | 618 | { |
michael@0 | 619 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 620 | return mXULWindow->GetPositionAndSize(aX, aY, aCX, aCY); |
michael@0 | 621 | } |
michael@0 | 622 | |
michael@0 | 623 | NS_IMETHODIMP nsContentTreeOwner::Repaint(bool aForce) |
michael@0 | 624 | { |
michael@0 | 625 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 626 | return mXULWindow->Repaint(aForce); |
michael@0 | 627 | } |
michael@0 | 628 | |
michael@0 | 629 | NS_IMETHODIMP nsContentTreeOwner::GetParentWidget(nsIWidget** aParentWidget) |
michael@0 | 630 | { |
michael@0 | 631 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 632 | return mXULWindow->GetParentWidget(aParentWidget); |
michael@0 | 633 | } |
michael@0 | 634 | |
michael@0 | 635 | NS_IMETHODIMP nsContentTreeOwner::SetParentWidget(nsIWidget* aParentWidget) |
michael@0 | 636 | { |
michael@0 | 637 | NS_ASSERTION(false, "You can't call this"); |
michael@0 | 638 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 639 | } |
michael@0 | 640 | |
michael@0 | 641 | NS_IMETHODIMP nsContentTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow) |
michael@0 | 642 | { |
michael@0 | 643 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 644 | return mXULWindow->GetParentNativeWindow(aParentNativeWindow); |
michael@0 | 645 | } |
michael@0 | 646 | |
michael@0 | 647 | NS_IMETHODIMP nsContentTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow) |
michael@0 | 648 | { |
michael@0 | 649 | NS_ASSERTION(false, "You can't call this"); |
michael@0 | 650 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 651 | } |
michael@0 | 652 | |
michael@0 | 653 | NS_IMETHODIMP nsContentTreeOwner::GetNativeHandle(nsAString& aNativeHandle) |
michael@0 | 654 | { |
michael@0 | 655 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 656 | return mXULWindow->GetNativeHandle(aNativeHandle); |
michael@0 | 657 | } |
michael@0 | 658 | |
michael@0 | 659 | NS_IMETHODIMP nsContentTreeOwner::GetVisibility(bool* aVisibility) |
michael@0 | 660 | { |
michael@0 | 661 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 662 | return mXULWindow->GetVisibility(aVisibility); |
michael@0 | 663 | } |
michael@0 | 664 | |
michael@0 | 665 | NS_IMETHODIMP nsContentTreeOwner::SetVisibility(bool aVisibility) |
michael@0 | 666 | { |
michael@0 | 667 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 668 | return mXULWindow->SetVisibility(aVisibility); |
michael@0 | 669 | } |
michael@0 | 670 | |
michael@0 | 671 | NS_IMETHODIMP nsContentTreeOwner::GetEnabled(bool *aEnabled) |
michael@0 | 672 | { |
michael@0 | 673 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 674 | return mXULWindow->GetEnabled(aEnabled); |
michael@0 | 675 | } |
michael@0 | 676 | |
michael@0 | 677 | NS_IMETHODIMP nsContentTreeOwner::SetEnabled(bool aEnable) |
michael@0 | 678 | { |
michael@0 | 679 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 680 | return mXULWindow->SetEnabled(aEnable); |
michael@0 | 681 | } |
michael@0 | 682 | |
michael@0 | 683 | NS_IMETHODIMP nsContentTreeOwner::GetMainWidget(nsIWidget** aMainWidget) |
michael@0 | 684 | { |
michael@0 | 685 | NS_ENSURE_ARG_POINTER(aMainWidget); |
michael@0 | 686 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 687 | |
michael@0 | 688 | *aMainWidget = mXULWindow->mWindow; |
michael@0 | 689 | NS_IF_ADDREF(*aMainWidget); |
michael@0 | 690 | |
michael@0 | 691 | return NS_OK; |
michael@0 | 692 | } |
michael@0 | 693 | |
michael@0 | 694 | NS_IMETHODIMP nsContentTreeOwner::SetFocus() |
michael@0 | 695 | { |
michael@0 | 696 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 697 | return mXULWindow->SetFocus(); |
michael@0 | 698 | } |
michael@0 | 699 | |
michael@0 | 700 | NS_IMETHODIMP nsContentTreeOwner::GetTitle(char16_t** aTitle) |
michael@0 | 701 | { |
michael@0 | 702 | NS_ENSURE_ARG_POINTER(aTitle); |
michael@0 | 703 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 704 | |
michael@0 | 705 | return mXULWindow->GetTitle(aTitle); |
michael@0 | 706 | } |
michael@0 | 707 | |
michael@0 | 708 | NS_IMETHODIMP nsContentTreeOwner::SetTitle(const char16_t* aTitle) |
michael@0 | 709 | { |
michael@0 | 710 | // We only allow the title to be set from the primary content shell |
michael@0 | 711 | if(!mPrimary || !mContentTitleSetting) |
michael@0 | 712 | return NS_OK; |
michael@0 | 713 | |
michael@0 | 714 | NS_ENSURE_STATE(mXULWindow); |
michael@0 | 715 | |
michael@0 | 716 | nsAutoString title; |
michael@0 | 717 | nsAutoString docTitle(aTitle); |
michael@0 | 718 | |
michael@0 | 719 | if (docTitle.IsEmpty()) |
michael@0 | 720 | docTitle.Assign(mTitleDefault); |
michael@0 | 721 | |
michael@0 | 722 | if (!docTitle.IsEmpty()) { |
michael@0 | 723 | if (!mTitlePreface.IsEmpty()) { |
michael@0 | 724 | // Title will be: "Preface: Doc Title - Mozilla" |
michael@0 | 725 | title.Assign(mTitlePreface); |
michael@0 | 726 | title.Append(docTitle); |
michael@0 | 727 | } |
michael@0 | 728 | else { |
michael@0 | 729 | // Title will be: "Doc Title - Mozilla" |
michael@0 | 730 | title = docTitle; |
michael@0 | 731 | } |
michael@0 | 732 | |
michael@0 | 733 | if (!mWindowTitleModifier.IsEmpty()) |
michael@0 | 734 | title += mTitleSeparator + mWindowTitleModifier; |
michael@0 | 735 | } |
michael@0 | 736 | else |
michael@0 | 737 | title.Assign(mWindowTitleModifier); // Title will just be plain "Mozilla" |
michael@0 | 738 | |
michael@0 | 739 | // |
michael@0 | 740 | // if there is no location bar we modify the title to display at least |
michael@0 | 741 | // the scheme and host (if any) as an anti-spoofing measure. |
michael@0 | 742 | // |
michael@0 | 743 | nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); |
michael@0 | 744 | |
michael@0 | 745 | if (docShellElement) { |
michael@0 | 746 | nsAutoString chromeString; |
michael@0 | 747 | docShellElement->GetAttribute(NS_LITERAL_STRING("chromehidden"), chromeString); |
michael@0 | 748 | if (chromeString.Find(NS_LITERAL_STRING("location")) != kNotFound) { |
michael@0 | 749 | // |
michael@0 | 750 | // location bar is turned off, find the browser location |
michael@0 | 751 | // |
michael@0 | 752 | // use the document's nsPrincipal to find the true owner |
michael@0 | 753 | // in case of javascript: or data: documents |
michael@0 | 754 | // |
michael@0 | 755 | nsCOMPtr<nsIDocShellTreeItem> dsitem; |
michael@0 | 756 | GetPrimaryContentShell(getter_AddRefs(dsitem)); |
michael@0 | 757 | nsCOMPtr<nsIDOMDocument> domdoc(do_GetInterface(dsitem)); |
michael@0 | 758 | nsCOMPtr<nsIScriptObjectPrincipal> doc(do_QueryInterface(domdoc)); |
michael@0 | 759 | if (doc) { |
michael@0 | 760 | nsCOMPtr<nsIURI> uri; |
michael@0 | 761 | nsIPrincipal* principal = doc->GetPrincipal(); |
michael@0 | 762 | if (principal) { |
michael@0 | 763 | principal->GetURI(getter_AddRefs(uri)); |
michael@0 | 764 | if (uri) { |
michael@0 | 765 | // |
michael@0 | 766 | // remove any user:pass information |
michael@0 | 767 | // |
michael@0 | 768 | nsCOMPtr<nsIURIFixup> fixup(do_GetService(NS_URIFIXUP_CONTRACTID)); |
michael@0 | 769 | if (fixup) { |
michael@0 | 770 | nsCOMPtr<nsIURI> tmpuri; |
michael@0 | 771 | nsresult rv = fixup->CreateExposableURI(uri,getter_AddRefs(tmpuri)); |
michael@0 | 772 | if (NS_SUCCEEDED(rv) && tmpuri) { |
michael@0 | 773 | // (don't bother if there's no host) |
michael@0 | 774 | nsAutoCString host; |
michael@0 | 775 | nsAutoCString prepath; |
michael@0 | 776 | tmpuri->GetHost(host); |
michael@0 | 777 | tmpuri->GetPrePath(prepath); |
michael@0 | 778 | if (!host.IsEmpty()) { |
michael@0 | 779 | // |
michael@0 | 780 | // We have a scheme/host, update the title |
michael@0 | 781 | // |
michael@0 | 782 | title.Insert(NS_ConvertUTF8toUTF16(prepath) + |
michael@0 | 783 | mTitleSeparator, 0); |
michael@0 | 784 | } |
michael@0 | 785 | } |
michael@0 | 786 | } |
michael@0 | 787 | } |
michael@0 | 788 | } |
michael@0 | 789 | } |
michael@0 | 790 | } |
michael@0 | 791 | nsIDocument* document = docShellElement->OwnerDoc(); |
michael@0 | 792 | ErrorResult rv; |
michael@0 | 793 | document->SetTitle(title, rv); |
michael@0 | 794 | return rv.ErrorCode(); |
michael@0 | 795 | } |
michael@0 | 796 | |
michael@0 | 797 | return mXULWindow->SetTitle(title.get()); |
michael@0 | 798 | } |
michael@0 | 799 | |
michael@0 | 800 | //***************************************************************************** |
michael@0 | 801 | // nsContentTreeOwner: nsIWindowProvider |
michael@0 | 802 | //***************************************************************************** |
michael@0 | 803 | NS_IMETHODIMP |
michael@0 | 804 | nsContentTreeOwner::ProvideWindow(nsIDOMWindow* aParent, |
michael@0 | 805 | uint32_t aChromeFlags, |
michael@0 | 806 | bool aCalledFromJS, |
michael@0 | 807 | bool aPositionSpecified, |
michael@0 | 808 | bool aSizeSpecified, |
michael@0 | 809 | nsIURI* aURI, |
michael@0 | 810 | const nsAString& aName, |
michael@0 | 811 | const nsACString& aFeatures, |
michael@0 | 812 | bool* aWindowIsNew, |
michael@0 | 813 | nsIDOMWindow** aReturn) |
michael@0 | 814 | { |
michael@0 | 815 | NS_ENSURE_ARG_POINTER(aParent); |
michael@0 | 816 | |
michael@0 | 817 | *aReturn = nullptr; |
michael@0 | 818 | |
michael@0 | 819 | if (!mXULWindow) { |
michael@0 | 820 | // Nothing to do here |
michael@0 | 821 | return NS_OK; |
michael@0 | 822 | } |
michael@0 | 823 | |
michael@0 | 824 | #ifdef DEBUG |
michael@0 | 825 | nsCOMPtr<nsIWebNavigation> parentNav = do_GetInterface(aParent); |
michael@0 | 826 | nsCOMPtr<nsIDocShellTreeOwner> parentOwner = do_GetInterface(parentNav); |
michael@0 | 827 | NS_ASSERTION(SameCOMIdentity(parentOwner, |
michael@0 | 828 | static_cast<nsIDocShellTreeOwner*>(this)), |
michael@0 | 829 | "Parent from wrong docshell tree?"); |
michael@0 | 830 | #endif |
michael@0 | 831 | |
michael@0 | 832 | // If aParent is inside an <iframe mozbrowser> and this isn't a request to |
michael@0 | 833 | // open a modal-type window, we're going to create a new <iframe mozbrowser> |
michael@0 | 834 | // and return its window here. |
michael@0 | 835 | nsCOMPtr<nsIDocShell> docshell = do_GetInterface(aParent); |
michael@0 | 836 | if (docshell && docshell->GetIsInBrowserOrApp() && |
michael@0 | 837 | !(aChromeFlags & (nsIWebBrowserChrome::CHROME_MODAL | |
michael@0 | 838 | nsIWebBrowserChrome::CHROME_OPENAS_DIALOG | |
michael@0 | 839 | nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) { |
michael@0 | 840 | |
michael@0 | 841 | BrowserElementParent::OpenWindowResult opened = |
michael@0 | 842 | BrowserElementParent::OpenWindowInProcess(aParent, aURI, aName, |
michael@0 | 843 | aFeatures, aReturn); |
michael@0 | 844 | |
michael@0 | 845 | // If OpenWindowInProcess handled the open (by opening it or blocking the |
michael@0 | 846 | // popup), tell our caller not to proceed trying to create a new window |
michael@0 | 847 | // through other means. |
michael@0 | 848 | if (opened != BrowserElementParent::OPEN_WINDOW_IGNORED) { |
michael@0 | 849 | *aWindowIsNew = opened == BrowserElementParent::OPEN_WINDOW_ADDED; |
michael@0 | 850 | return *aWindowIsNew ? NS_OK : NS_ERROR_ABORT; |
michael@0 | 851 | } |
michael@0 | 852 | |
michael@0 | 853 | // If we're in an app and the target is _blank, send the url to the OS |
michael@0 | 854 | if (aName.LowerCaseEqualsLiteral("_blank")) { |
michael@0 | 855 | nsCOMPtr<nsIExternalURLHandlerService> exUrlServ( |
michael@0 | 856 | do_GetService(NS_EXTERNALURLHANDLERSERVICE_CONTRACTID)); |
michael@0 | 857 | if (exUrlServ) { |
michael@0 | 858 | |
michael@0 | 859 | nsCOMPtr<nsIHandlerInfo> info; |
michael@0 | 860 | bool found; |
michael@0 | 861 | exUrlServ->GetURLHandlerInfoFromOS(aURI, &found, getter_AddRefs(info)); |
michael@0 | 862 | |
michael@0 | 863 | if (info && found) { |
michael@0 | 864 | info->LaunchWithURI(aURI, nullptr); |
michael@0 | 865 | return NS_ERROR_ABORT; |
michael@0 | 866 | } |
michael@0 | 867 | |
michael@0 | 868 | } |
michael@0 | 869 | } |
michael@0 | 870 | } |
michael@0 | 871 | |
michael@0 | 872 | // the parent window is fullscreen mode or not. |
michael@0 | 873 | bool isFullScreen = false; |
michael@0 | 874 | if (aParent) { |
michael@0 | 875 | aParent->GetFullScreen(&isFullScreen); |
michael@0 | 876 | } |
michael@0 | 877 | |
michael@0 | 878 | // Where should we open this? |
michael@0 | 879 | int32_t containerPref; |
michael@0 | 880 | if (NS_FAILED(Preferences::GetInt("browser.link.open_newwindow", |
michael@0 | 881 | &containerPref))) { |
michael@0 | 882 | return NS_OK; |
michael@0 | 883 | } |
michael@0 | 884 | |
michael@0 | 885 | bool isDisabledOpenNewWindow = |
michael@0 | 886 | isFullScreen && |
michael@0 | 887 | Preferences::GetBool("browser.link.open_newwindow.disabled_in_fullscreen"); |
michael@0 | 888 | |
michael@0 | 889 | if (isDisabledOpenNewWindow && (containerPref == nsIBrowserDOMWindow::OPEN_NEWWINDOW)) { |
michael@0 | 890 | containerPref = nsIBrowserDOMWindow::OPEN_NEWTAB; |
michael@0 | 891 | } |
michael@0 | 892 | |
michael@0 | 893 | if (containerPref != nsIBrowserDOMWindow::OPEN_NEWTAB && |
michael@0 | 894 | containerPref != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW) { |
michael@0 | 895 | // Just open a window normally |
michael@0 | 896 | return NS_OK; |
michael@0 | 897 | } |
michael@0 | 898 | |
michael@0 | 899 | if (aCalledFromJS) { |
michael@0 | 900 | /* Now check our restriction pref. The restriction pref is a power-user's |
michael@0 | 901 | fine-tuning pref. values: |
michael@0 | 902 | 0: no restrictions - divert everything |
michael@0 | 903 | 1: don't divert window.open at all |
michael@0 | 904 | 2: don't divert window.open with features |
michael@0 | 905 | */ |
michael@0 | 906 | int32_t restrictionPref = |
michael@0 | 907 | Preferences::GetInt("browser.link.open_newwindow.restriction", 2); |
michael@0 | 908 | if (restrictionPref < 0 || restrictionPref > 2) { |
michael@0 | 909 | restrictionPref = 2; // Sane default behavior |
michael@0 | 910 | } |
michael@0 | 911 | |
michael@0 | 912 | if (isDisabledOpenNewWindow) { |
michael@0 | 913 | // In browser fullscreen, the window should be opened |
michael@0 | 914 | // in the current window with no features (see bug 803675) |
michael@0 | 915 | restrictionPref = 0; |
michael@0 | 916 | } |
michael@0 | 917 | |
michael@0 | 918 | if (restrictionPref == 1) { |
michael@0 | 919 | return NS_OK; |
michael@0 | 920 | } |
michael@0 | 921 | |
michael@0 | 922 | if (restrictionPref == 2 && |
michael@0 | 923 | // Only continue if there are no size/position features and no special |
michael@0 | 924 | // chrome flags. |
michael@0 | 925 | (aChromeFlags != nsIWebBrowserChrome::CHROME_ALL || |
michael@0 | 926 | aPositionSpecified || aSizeSpecified)) { |
michael@0 | 927 | return NS_OK; |
michael@0 | 928 | } |
michael@0 | 929 | } |
michael@0 | 930 | |
michael@0 | 931 | nsCOMPtr<nsIDOMWindow> domWin; |
michael@0 | 932 | mXULWindow->GetWindowDOMWindow(getter_AddRefs(domWin)); |
michael@0 | 933 | nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(domWin); |
michael@0 | 934 | if (!chromeWin) { |
michael@0 | 935 | // Really odd... but whatever |
michael@0 | 936 | NS_WARNING("nsXULWindow's DOMWindow is not a chrome window"); |
michael@0 | 937 | return NS_OK; |
michael@0 | 938 | } |
michael@0 | 939 | |
michael@0 | 940 | nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin; |
michael@0 | 941 | chromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin)); |
michael@0 | 942 | if (!browserDOMWin) { |
michael@0 | 943 | return NS_OK; |
michael@0 | 944 | } |
michael@0 | 945 | |
michael@0 | 946 | *aWindowIsNew = (containerPref != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW); |
michael@0 | 947 | |
michael@0 | 948 | { |
michael@0 | 949 | dom::AutoNoJSAPI nojsapi; |
michael@0 | 950 | |
michael@0 | 951 | // Get a new rendering area from the browserDOMWin. We don't want |
michael@0 | 952 | // to be starting any loads here, so get it with a null URI. |
michael@0 | 953 | return browserDOMWin->OpenURI(nullptr, aParent, containerPref, |
michael@0 | 954 | nsIBrowserDOMWindow::OPEN_NEW, aReturn); |
michael@0 | 955 | } |
michael@0 | 956 | } |
michael@0 | 957 | |
michael@0 | 958 | //***************************************************************************** |
michael@0 | 959 | // nsContentTreeOwner: Accessors |
michael@0 | 960 | //***************************************************************************** |
michael@0 | 961 | |
michael@0 | 962 | #if defined(XP_MACOSX) |
michael@0 | 963 | class nsContentTitleSettingEvent : public nsRunnable |
michael@0 | 964 | { |
michael@0 | 965 | public: |
michael@0 | 966 | nsContentTitleSettingEvent(dom::Element* dse, const nsAString& wtm) |
michael@0 | 967 | : mElement(dse), |
michael@0 | 968 | mTitleDefault(wtm) {} |
michael@0 | 969 | |
michael@0 | 970 | NS_IMETHOD Run() |
michael@0 | 971 | { |
michael@0 | 972 | ErrorResult rv; |
michael@0 | 973 | mElement->SetAttribute(NS_LITERAL_STRING("titledefault"), mTitleDefault, rv); |
michael@0 | 974 | mElement->RemoveAttribute(NS_LITERAL_STRING("titlemodifier"), rv); |
michael@0 | 975 | return NS_OK; |
michael@0 | 976 | } |
michael@0 | 977 | |
michael@0 | 978 | private: |
michael@0 | 979 | nsCOMPtr<dom::Element> mElement; |
michael@0 | 980 | nsString mTitleDefault; |
michael@0 | 981 | }; |
michael@0 | 982 | #endif |
michael@0 | 983 | |
michael@0 | 984 | void nsContentTreeOwner::XULWindow(nsXULWindow* aXULWindow) |
michael@0 | 985 | { |
michael@0 | 986 | mXULWindow = aXULWindow; |
michael@0 | 987 | if (mXULWindow && mPrimary) { |
michael@0 | 988 | // Get the window title modifiers |
michael@0 | 989 | nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); |
michael@0 | 990 | |
michael@0 | 991 | nsAutoString contentTitleSetting; |
michael@0 | 992 | |
michael@0 | 993 | if(docShellElement) |
michael@0 | 994 | { |
michael@0 | 995 | docShellElement->GetAttribute(NS_LITERAL_STRING("contenttitlesetting"), contentTitleSetting); |
michael@0 | 996 | if(contentTitleSetting.EqualsLiteral("true")) |
michael@0 | 997 | { |
michael@0 | 998 | mContentTitleSetting = true; |
michael@0 | 999 | docShellElement->GetAttribute(NS_LITERAL_STRING("titledefault"), mTitleDefault); |
michael@0 | 1000 | docShellElement->GetAttribute(NS_LITERAL_STRING("titlemodifier"), mWindowTitleModifier); |
michael@0 | 1001 | docShellElement->GetAttribute(NS_LITERAL_STRING("titlepreface"), mTitlePreface); |
michael@0 | 1002 | |
michael@0 | 1003 | #if defined(XP_MACOSX) |
michael@0 | 1004 | // On OS X, treat the titlemodifier like it's the titledefault, and don't ever append |
michael@0 | 1005 | // the separator + appname. |
michael@0 | 1006 | if (mTitleDefault.IsEmpty()) { |
michael@0 | 1007 | NS_DispatchToCurrentThread( |
michael@0 | 1008 | new nsContentTitleSettingEvent(docShellElement, |
michael@0 | 1009 | mWindowTitleModifier)); |
michael@0 | 1010 | mTitleDefault = mWindowTitleModifier; |
michael@0 | 1011 | mWindowTitleModifier.Truncate(); |
michael@0 | 1012 | } |
michael@0 | 1013 | #endif |
michael@0 | 1014 | docShellElement->GetAttribute(NS_LITERAL_STRING("titlemenuseparator"), mTitleSeparator); |
michael@0 | 1015 | } |
michael@0 | 1016 | } |
michael@0 | 1017 | else |
michael@0 | 1018 | { |
michael@0 | 1019 | NS_ERROR("This condition should never happen. If it does, " |
michael@0 | 1020 | "we just won't get a modifier, but it still shouldn't happen."); |
michael@0 | 1021 | } |
michael@0 | 1022 | } |
michael@0 | 1023 | } |
michael@0 | 1024 | |
michael@0 | 1025 | nsXULWindow* nsContentTreeOwner::XULWindow() |
michael@0 | 1026 | { |
michael@0 | 1027 | return mXULWindow; |
michael@0 | 1028 | } |
michael@0 | 1029 | |
michael@0 | 1030 | //***************************************************************************** |
michael@0 | 1031 | //*** nsSiteWindow implementation |
michael@0 | 1032 | //***************************************************************************** |
michael@0 | 1033 | |
michael@0 | 1034 | nsSiteWindow::nsSiteWindow(nsContentTreeOwner *aAggregator) |
michael@0 | 1035 | { |
michael@0 | 1036 | mAggregator = aAggregator; |
michael@0 | 1037 | } |
michael@0 | 1038 | |
michael@0 | 1039 | nsSiteWindow::~nsSiteWindow() |
michael@0 | 1040 | { |
michael@0 | 1041 | } |
michael@0 | 1042 | |
michael@0 | 1043 | NS_IMPL_ADDREF_USING_AGGREGATOR(nsSiteWindow, mAggregator) |
michael@0 | 1044 | NS_IMPL_RELEASE_USING_AGGREGATOR(nsSiteWindow, mAggregator) |
michael@0 | 1045 | |
michael@0 | 1046 | NS_INTERFACE_MAP_BEGIN(nsSiteWindow) |
michael@0 | 1047 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 1048 | NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow) |
michael@0 | 1049 | NS_INTERFACE_MAP_END_AGGREGATED(mAggregator) |
michael@0 | 1050 | |
michael@0 | 1051 | NS_IMETHODIMP |
michael@0 | 1052 | nsSiteWindow::SetDimensions(uint32_t aFlags, |
michael@0 | 1053 | int32_t aX, int32_t aY, int32_t aCX, int32_t aCY) |
michael@0 | 1054 | { |
michael@0 | 1055 | // XXX we're ignoring aFlags |
michael@0 | 1056 | return mAggregator->SetPositionAndSize(aX, aY, aCX, aCY, true); |
michael@0 | 1057 | } |
michael@0 | 1058 | |
michael@0 | 1059 | NS_IMETHODIMP |
michael@0 | 1060 | nsSiteWindow::GetDimensions(uint32_t aFlags, |
michael@0 | 1061 | int32_t *aX, int32_t *aY, int32_t *aCX, int32_t *aCY) |
michael@0 | 1062 | { |
michael@0 | 1063 | // XXX we're ignoring aFlags |
michael@0 | 1064 | return mAggregator->GetPositionAndSize(aX, aY, aCX, aCY); |
michael@0 | 1065 | } |
michael@0 | 1066 | |
michael@0 | 1067 | NS_IMETHODIMP |
michael@0 | 1068 | nsSiteWindow::SetFocus(void) |
michael@0 | 1069 | { |
michael@0 | 1070 | #if 0 |
michael@0 | 1071 | /* This implementation focuses the main document and could make sense. |
michael@0 | 1072 | However this method is actually being used from within |
michael@0 | 1073 | nsGlobalWindow::Focus (providing a hook for MDI embedding apps) |
michael@0 | 1074 | and it's better for our purposes to not pick a document and |
michael@0 | 1075 | focus it, but allow nsGlobalWindow to carry on unhindered. |
michael@0 | 1076 | */ |
michael@0 | 1077 | nsXULWindow *window = mAggregator->XULWindow(); |
michael@0 | 1078 | if (window) { |
michael@0 | 1079 | nsCOMPtr<nsIDocShell> docshell; |
michael@0 | 1080 | window->GetDocShell(getter_AddRefs(docshell)); |
michael@0 | 1081 | nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docshell)); |
michael@0 | 1082 | if (domWindow) |
michael@0 | 1083 | domWindow->Focus(); |
michael@0 | 1084 | } |
michael@0 | 1085 | #endif |
michael@0 | 1086 | return NS_OK; |
michael@0 | 1087 | } |
michael@0 | 1088 | |
michael@0 | 1089 | /* this implementation focuses another window. if there isn't another |
michael@0 | 1090 | window to focus, we do nothing. */ |
michael@0 | 1091 | NS_IMETHODIMP |
michael@0 | 1092 | nsSiteWindow::Blur(void) |
michael@0 | 1093 | { |
michael@0 | 1094 | NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); |
michael@0 | 1095 | |
michael@0 | 1096 | nsCOMPtr<nsISimpleEnumerator> windowEnumerator; |
michael@0 | 1097 | nsCOMPtr<nsIXULWindow> xulWindow; |
michael@0 | 1098 | bool more, foundUs; |
michael@0 | 1099 | nsXULWindow *ourWindow = mAggregator->XULWindow(); |
michael@0 | 1100 | |
michael@0 | 1101 | { |
michael@0 | 1102 | nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID)); |
michael@0 | 1103 | if (windowMediator) |
michael@0 | 1104 | windowMediator->GetZOrderXULWindowEnumerator(0, true, |
michael@0 | 1105 | getter_AddRefs(windowEnumerator)); |
michael@0 | 1106 | } |
michael@0 | 1107 | |
michael@0 | 1108 | if (!windowEnumerator) |
michael@0 | 1109 | return NS_ERROR_FAILURE; |
michael@0 | 1110 | |
michael@0 | 1111 | // step through the top-level windows |
michael@0 | 1112 | foundUs = false; |
michael@0 | 1113 | windowEnumerator->HasMoreElements(&more); |
michael@0 | 1114 | while (more) { |
michael@0 | 1115 | |
michael@0 | 1116 | nsCOMPtr<nsISupports> nextWindow; |
michael@0 | 1117 | nsCOMPtr<nsIXULWindow> nextXULWindow; |
michael@0 | 1118 | |
michael@0 | 1119 | windowEnumerator->GetNext(getter_AddRefs(nextWindow)); |
michael@0 | 1120 | nextXULWindow = do_QueryInterface(nextWindow); |
michael@0 | 1121 | |
michael@0 | 1122 | // got it!(?) |
michael@0 | 1123 | if (foundUs) { |
michael@0 | 1124 | xulWindow = nextXULWindow; |
michael@0 | 1125 | break; |
michael@0 | 1126 | } |
michael@0 | 1127 | |
michael@0 | 1128 | // remember the very first one, in case we have to wrap |
michael@0 | 1129 | if (!xulWindow) |
michael@0 | 1130 | xulWindow = nextXULWindow; |
michael@0 | 1131 | |
michael@0 | 1132 | // look for us |
michael@0 | 1133 | if (nextXULWindow == ourWindow) |
michael@0 | 1134 | foundUs = true; |
michael@0 | 1135 | |
michael@0 | 1136 | windowEnumerator->HasMoreElements(&more); |
michael@0 | 1137 | } |
michael@0 | 1138 | |
michael@0 | 1139 | // change focus to the window we just found |
michael@0 | 1140 | if (xulWindow) { |
michael@0 | 1141 | nsCOMPtr<nsIDocShell> docshell; |
michael@0 | 1142 | xulWindow->GetDocShell(getter_AddRefs(docshell)); |
michael@0 | 1143 | nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docshell)); |
michael@0 | 1144 | if (domWindow) |
michael@0 | 1145 | domWindow->Focus(); |
michael@0 | 1146 | } |
michael@0 | 1147 | return NS_OK; |
michael@0 | 1148 | } |
michael@0 | 1149 | |
michael@0 | 1150 | NS_IMETHODIMP |
michael@0 | 1151 | nsSiteWindow::GetVisibility(bool *aVisibility) |
michael@0 | 1152 | { |
michael@0 | 1153 | return mAggregator->GetVisibility(aVisibility); |
michael@0 | 1154 | } |
michael@0 | 1155 | |
michael@0 | 1156 | NS_IMETHODIMP |
michael@0 | 1157 | nsSiteWindow::SetVisibility(bool aVisibility) |
michael@0 | 1158 | { |
michael@0 | 1159 | return mAggregator->SetVisibility(aVisibility); |
michael@0 | 1160 | } |
michael@0 | 1161 | |
michael@0 | 1162 | NS_IMETHODIMP |
michael@0 | 1163 | nsSiteWindow::GetTitle(char16_t * *aTitle) |
michael@0 | 1164 | { |
michael@0 | 1165 | return mAggregator->GetTitle(aTitle); |
michael@0 | 1166 | } |
michael@0 | 1167 | |
michael@0 | 1168 | NS_IMETHODIMP |
michael@0 | 1169 | nsSiteWindow::SetTitle(const char16_t * aTitle) |
michael@0 | 1170 | { |
michael@0 | 1171 | return mAggregator->SetTitle(aTitle); |
michael@0 | 1172 | } |
michael@0 | 1173 | |
michael@0 | 1174 | NS_IMETHODIMP |
michael@0 | 1175 | nsSiteWindow::GetSiteWindow(void **aSiteWindow) |
michael@0 | 1176 | { |
michael@0 | 1177 | return mAggregator->GetParentNativeWindow(aSiteWindow); |
michael@0 | 1178 | } |
michael@0 | 1179 |