OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/html/HTMLIFrameElement.h" | 6 #include "core/html/HTMLIFrameElement.h" |
7 | 7 |
8 #include "gen/sky/core/HTMLNames.h" | 8 #include "gen/sky/core/HTMLNames.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/html/parser/HTMLParserIdioms.h" | 10 #include "core/html/parser/HTMLParserIdioms.h" |
11 #include "core/loader/FrameLoaderClient.h" | 11 #include "core/loader/FrameLoaderClient.h" |
12 #include "core/rendering/RenderIFrame.h" | 12 #include "core/rendering/RenderIFrame.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(Document& document) | 16 PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(Document& document) |
17 { | 17 { |
18 return adoptRef(new HTMLIFrameElement(document)); | 18 return adoptRef(new HTMLIFrameElement(document)); |
19 } | 19 } |
20 | 20 |
21 HTMLIFrameElement::HTMLIFrameElement(Document& document) | 21 HTMLIFrameElement::HTMLIFrameElement(Document& document) |
22 : HTMLElement(HTMLNames::iframeTag, document), | 22 : HTMLElement(HTMLNames::iframeTag, document), |
23 m_contentView(nullptr) | 23 m_contentView(nullptr) |
24 { | 24 { |
25 } | 25 } |
26 | 26 |
27 HTMLIFrameElement::~HTMLIFrameElement() | 27 HTMLIFrameElement::~HTMLIFrameElement() |
28 { | 28 { |
| 29 if (m_contentView) |
| 30 m_contentView->RemoveObserver(this); |
29 } | 31 } |
30 | 32 |
31 Node::InsertionNotificationRequest HTMLIFrameElement::insertedInto(ContainerNode
* insertionPoint) | 33 Node::InsertionNotificationRequest HTMLIFrameElement::insertedInto(ContainerNode
* insertionPoint) |
32 { | 34 { |
33 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi
nt); | 35 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi
nt); |
34 if (insertionPoint->inDocument()) | 36 if (insertionPoint->inDocument()) |
35 createView(); | 37 createView(); |
36 return result; | 38 return result; |
37 } | 39 } |
38 | 40 |
39 void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint) | 41 void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint) |
40 { | 42 { |
41 HTMLElement::removedFrom(insertionPoint); | 43 HTMLElement::removedFrom(insertionPoint); |
42 if (insertionPoint->inDocument()) { | 44 if (m_contentView) |
43 // TODO(mpcomplete): Tear down the mojo View. | 45 m_contentView->Destroy(); |
44 } | |
45 } | 46 } |
46 | 47 |
47 RenderObject* HTMLIFrameElement::createRenderer(RenderStyle* style) | 48 RenderObject* HTMLIFrameElement::createRenderer(RenderStyle* style) |
48 { | 49 { |
49 return new RenderIFrame(this); | 50 return new RenderIFrame(this); |
50 } | 51 } |
51 | 52 |
52 void HTMLIFrameElement::OnViewDestroyed(mojo::View* view) | 53 void HTMLIFrameElement::OnViewDestroyed(mojo::View* view) |
53 { | 54 { |
54 DCHECK_EQ(view, m_contentView); | 55 DCHECK_EQ(view, m_contentView); |
55 m_contentView = nullptr; | 56 m_contentView = nullptr; |
56 } | 57 } |
57 | 58 |
58 void HTMLIFrameElement::createView() | 59 void HTMLIFrameElement::createView() |
59 { | 60 { |
60 String urlString = stripLeadingAndTrailingHTMLSpaces(getAttribute(HTMLNames:
:srcAttr)); | 61 String urlString = stripLeadingAndTrailingHTMLSpaces(getAttribute(HTMLNames:
:srcAttr)); |
61 if (urlString.isEmpty()) | 62 if (urlString.isEmpty()) |
62 urlString = blankURL().string(); | 63 urlString = blankURL().string(); |
63 | 64 |
64 LocalFrame* parentFrame = document().frame(); | 65 LocalFrame* parentFrame = document().frame(); |
65 if (!parentFrame) | 66 if (!parentFrame) |
66 return; | 67 return; |
67 | 68 |
68 KURL url = document().completeURL(urlString); | 69 KURL url = document().completeURL(urlString); |
69 m_contentView = parentFrame->loaderClient()->createChildFrame(url); | 70 m_contentView = parentFrame->loaderClient()->createChildFrame(url); |
| 71 if (m_contentView) |
| 72 m_contentView->AddObserver(this); |
70 } | 73 } |
71 | 74 |
72 } | 75 } |
OLD | NEW |