Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "mozilla/dom/ContainerBoxObject.h"
7 : #include "mozilla/dom/ContainerBoxObjectBinding.h"
8 : #include "nsCOMPtr.h"
9 : #include "nsIDocShell.h"
10 : #include "nsIContent.h"
11 : #include "nsIDocument.h"
12 : #include "nsIFrame.h"
13 : #include "nsSubDocumentFrame.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 0 : ContainerBoxObject::ContainerBoxObject()
19 : {
20 0 : }
21 :
22 0 : ContainerBoxObject::~ContainerBoxObject()
23 : {
24 0 : }
25 :
26 : JSObject*
27 0 : ContainerBoxObject::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
28 : {
29 0 : return ContainerBoxObjectBinding::Wrap(aCx, this, aGivenProto);
30 : }
31 :
32 : already_AddRefed<nsIDocShell>
33 0 : ContainerBoxObject::GetDocShell()
34 : {
35 0 : nsSubDocumentFrame *subDocFrame = do_QueryFrame(GetFrame(false));
36 0 : if (subDocFrame) {
37 : // Ok, the frame for mContent is an nsSubDocumentFrame, it knows how
38 : // to reach the docshell, so ask it...
39 0 : nsCOMPtr<nsIDocShell> ret;
40 0 : subDocFrame->GetDocShell(getter_AddRefs(ret));
41 0 : return ret.forget();
42 : }
43 :
44 0 : if (!mContent) {
45 0 : return nullptr;
46 : }
47 :
48 : // No nsSubDocumentFrame available for mContent, try if there's a mapping
49 : // between mContent's document to mContent's subdocument.
50 :
51 0 : nsIDocument *doc = mContent->GetComposedDoc();
52 :
53 0 : if (!doc) {
54 0 : return nullptr;
55 : }
56 :
57 0 : nsIDocument *sub_doc = doc->GetSubDocumentFor(mContent);
58 :
59 0 : if (!sub_doc) {
60 0 : return nullptr;
61 : }
62 :
63 0 : nsCOMPtr<nsIDocShell> result = sub_doc->GetDocShell();
64 0 : return result.forget();
65 : }
66 :
67 : } // namespace dom
68 : } // namespace mozilla
69 :
70 : nsresult
71 0 : NS_NewContainerBoxObject(nsIBoxObject** aResult)
72 : {
73 0 : NS_ADDREF(*aResult = new mozilla::dom::ContainerBoxObject());
74 0 : return NS_OK;
75 : }
|