Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: Source/core/frame/LocalFrame.cpp

Issue 183713002: Add Frame and RemoteFrame classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed unneeded method definition Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/frame/LocalFrame.h ('k') | Source/core/frame/RemoteFrame.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Simon Hausmann <hausmann@kde.org> 5 * 2000 Simon Hausmann <hausmann@kde.org>
6 * 2000 Stefan Schimanski <1Stein@gmx.de> 6 * 2000 Stefan Schimanski <1Stein@gmx.de>
7 * 2001 George Staikos <staikos@kde.org> 7 * 2001 George Staikos <staikos@kde.org>
8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> 9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com>
10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
(...skipping 25 matching lines...) Expand all
36 #include "core/dom/WheelController.h" 36 #include "core/dom/WheelController.h"
37 #include "core/editing/Editor.h" 37 #include "core/editing/Editor.h"
38 #include "core/editing/FrameSelection.h" 38 #include "core/editing/FrameSelection.h"
39 #include "core/editing/InputMethodController.h" 39 #include "core/editing/InputMethodController.h"
40 #include "core/editing/SpellChecker.h" 40 #include "core/editing/SpellChecker.h"
41 #include "core/editing/htmlediting.h" 41 #include "core/editing/htmlediting.h"
42 #include "core/editing/markup.h" 42 #include "core/editing/markup.h"
43 #include "core/events/Event.h" 43 #include "core/events/Event.h"
44 #include "core/fetch/ResourceFetcher.h" 44 #include "core/fetch/ResourceFetcher.h"
45 #include "core/frame/DOMWindow.h" 45 #include "core/frame/DOMWindow.h"
46 #include "core/frame/FrameDestructionObserver.h"
47 #include "core/frame/FrameHost.h" 46 #include "core/frame/FrameHost.h"
48 #include "core/frame/FrameView.h" 47 #include "core/frame/FrameView.h"
49 #include "core/frame/Settings.h" 48 #include "core/frame/Settings.h"
50 #include "core/html/HTMLFrameElementBase.h" 49 #include "core/html/HTMLFrameElementBase.h"
51 #include "core/inspector/InspectorInstrumentation.h" 50 #include "core/inspector/InspectorInstrumentation.h"
52 #include "core/loader/EmptyClients.h"
53 #include "core/loader/FrameLoaderClient.h" 51 #include "core/loader/FrameLoaderClient.h"
54 #include "core/page/Chrome.h" 52 #include "core/page/Chrome.h"
55 #include "core/page/ChromeClient.h"
56 #include "core/page/EventHandler.h" 53 #include "core/page/EventHandler.h"
57 #include "core/page/FocusController.h" 54 #include "core/page/FocusController.h"
58 #include "core/page/Page.h"
59 #include "core/page/scrolling/ScrollingCoordinator.h" 55 #include "core/page/scrolling/ScrollingCoordinator.h"
60 #include "core/rendering/HitTestResult.h" 56 #include "core/rendering/HitTestResult.h"
61 #include "core/rendering/RenderLayer.h" 57 #include "core/rendering/RenderLayer.h"
62 #include "core/rendering/RenderPart.h" 58 #include "core/rendering/RenderPart.h"
63 #include "core/rendering/RenderView.h" 59 #include "core/rendering/RenderView.h"
64 #include "core/rendering/compositing/RenderLayerCompositor.h" 60 #include "core/rendering/compositing/RenderLayerCompositor.h"
65 #include "core/svg/SVGDocument.h" 61 #include "core/svg/SVGDocument.h"
66 #include "platform/DragImage.h" 62 #include "platform/DragImage.h"
67 #include "platform/graphics/GraphicsContext.h" 63 #include "platform/graphics/GraphicsContext.h"
68 #include "platform/graphics/ImageBuffer.h" 64 #include "platform/graphics/ImageBuffer.h"
69 #include "public/platform/WebLayer.h"
70 #include "wtf/PassOwnPtr.h" 65 #include "wtf/PassOwnPtr.h"
71 #include "wtf/RefCountedLeakCounter.h"
72 #include "wtf/StdLibExtras.h" 66 #include "wtf/StdLibExtras.h"
73 67
74 using namespace std; 68 using namespace std;
75 69
76 namespace WebCore { 70 namespace WebCore {
77 71
78 using namespace HTMLNames; 72 using namespace HTMLNames;
79 73
80 namespace {
81
82 int64_t generateFrameID()
83 {
84 // Initialize to the current time to reduce the likelihood of generating
85 // identifiers that overlap with those from past/future browser sessions.
86 static int64_t next = static_cast<int64_t>(currentTime() * 1000000.0);
87 return ++next;
88 }
89
90 } // namespace
91
92 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, frameCounter, ("LocalFrame" ));
93
94 static inline float parentPageZoomFactor(LocalFrame* frame) 74 static inline float parentPageZoomFactor(LocalFrame* frame)
95 { 75 {
96 LocalFrame* parent = frame->tree().parent(); 76 LocalFrame* parent = frame->tree().parent();
97 if (!parent) 77 if (!parent)
98 return 1; 78 return 1;
99 return parent->pageZoomFactor(); 79 return parent->pageZoomFactor();
100 } 80 }
101 81
102 static inline float parentTextZoomFactor(LocalFrame* frame) 82 static inline float parentTextZoomFactor(LocalFrame* frame)
103 { 83 {
104 LocalFrame* parent = frame->tree().parent(); 84 LocalFrame* parent = frame->tree().parent();
105 if (!parent) 85 if (!parent)
106 return 1; 86 return 1;
107 return parent->textZoomFactor(); 87 return parent->textZoomFactor();
108 } 88 }
109 89
110 inline LocalFrame::LocalFrame(PassRefPtr<FrameInit> frameInit) 90 inline LocalFrame::LocalFrame(PassRefPtr<FrameInit> frameInit)
111 : m_frameID(generateFrameID()) 91 : Frame(frameInit)
112 , m_host(frameInit->frameHost())
113 , m_treeNode(this) 92 , m_treeNode(this)
114 , m_loader(this, frameInit->frameLoaderClient()) 93 , m_loader(this, m_frameInit->frameLoaderClient())
115 , m_navigationScheduler(this) 94 , m_navigationScheduler(this)
116 , m_script(adoptPtr(new ScriptController(this))) 95 , m_script(adoptPtr(new ScriptController(this)))
117 , m_editor(Editor::create(*this)) 96 , m_editor(Editor::create(*this))
118 , m_spellChecker(SpellChecker::create(*this)) 97 , m_spellChecker(SpellChecker::create(*this))
119 , m_selection(adoptPtr(new FrameSelection(this))) 98 , m_selection(adoptPtr(new FrameSelection(this)))
120 , m_eventHandler(adoptPtr(new EventHandler(this))) 99 , m_eventHandler(adoptPtr(new EventHandler(this)))
121 , m_inputMethodController(InputMethodController::create(*this)) 100 , m_inputMethodController(InputMethodController::create(*this))
122 , m_frameInit(frameInit)
123 , m_pageZoomFactor(parentPageZoomFactor(this)) 101 , m_pageZoomFactor(parentPageZoomFactor(this))
124 , m_textZoomFactor(parentTextZoomFactor(this)) 102 , m_textZoomFactor(parentTextZoomFactor(this))
125 , m_orientation(0) 103 , m_orientation(0)
126 , m_inViewSourceMode(false) 104 , m_inViewSourceMode(false)
127 , m_remotePlatformLayer(0)
128 { 105 {
129 ASSERT(page());
130
131 if (ownerElement()) { 106 if (ownerElement()) {
132 page()->incrementSubframeCount(); 107 page()->incrementSubframeCount();
133 ownerElement()->setContentFrame(*this); 108 ownerElement()->setContentFrame(*this);
134 } 109 }
135
136 #ifndef NDEBUG
137 frameCounter.increment();
138 #endif
139 } 110 }
140 111
141 PassRefPtr<LocalFrame> LocalFrame::create(PassRefPtr<FrameInit> frameInit) 112 PassRefPtr<LocalFrame> LocalFrame::create(PassRefPtr<FrameInit> frameInit)
142 { 113 {
143 RefPtr<LocalFrame> frame = adoptRef(new LocalFrame(frameInit)); 114 RefPtr<LocalFrame> frame = adoptRef(new LocalFrame(frameInit));
144 if (!frame->ownerElement()) 115 if (!frame->ownerElement())
145 frame->page()->setMainFrame(frame); 116 frame->page()->setMainFrame(frame);
146 InspectorInstrumentation::frameAttachedToParent(frame.get()); 117 InspectorInstrumentation::frameAttachedToParent(frame.get());
147 return frame.release(); 118 return frame.release();
148 } 119 }
149 120
150 LocalFrame::~LocalFrame() 121 LocalFrame::~LocalFrame()
151 { 122 {
152 setView(nullptr); 123 setView(nullptr);
153 loader().clear(); 124 loader().clear();
154 setDOMWindow(nullptr); 125 setDOMWindow(nullptr);
155 126
156 // FIXME: We should not be doing all this work inside the destructor
157
158 #ifndef NDEBUG
159 frameCounter.decrement();
160 #endif
161
162 disconnectOwnerElement(); 127 disconnectOwnerElement();
163
164 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd();
165 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver s.begin(); it != stop; ++it)
166 (*it)->frameDestroyed();
167 } 128 }
168 129
169 bool LocalFrame::inScope(TreeScope* scope) const 130 bool LocalFrame::inScope(TreeScope* scope) const
170 { 131 {
171 ASSERT(scope); 132 ASSERT(scope);
172 Document* doc = document(); 133 Document* doc = document();
173 if (!doc) 134 if (!doc)
174 return false; 135 return false;
175 HTMLFrameOwnerElement* owner = doc->ownerElement(); 136 HTMLFrameOwnerElement* owner = doc->ownerElement();
176 if (!owner) 137 if (!owner)
177 return false; 138 return false;
178 return owner->treeScope() == scope; 139 return owner->treeScope() == scope;
179 } 140 }
180 141
181 void LocalFrame::addDestructionObserver(FrameDestructionObserver* observer)
182 {
183 m_destructionObservers.add(observer);
184 }
185
186 void LocalFrame::removeDestructionObserver(FrameDestructionObserver* observer)
187 {
188 m_destructionObservers.remove(observer);
189 }
190
191 void LocalFrame::setView(PassRefPtr<FrameView> view) 142 void LocalFrame::setView(PassRefPtr<FrameView> view)
192 { 143 {
193 // We the custom scroll bars as early as possible to prevent m_doc->detach() 144 // We the custom scroll bars as early as possible to prevent m_doc->detach()
194 // from messing with the view such that its scroll bars won't be torn down. 145 // from messing with the view such that its scroll bars won't be torn down.
195 // FIXME: We should revisit this. 146 // FIXME: We should revisit this.
196 if (m_view) 147 if (m_view)
197 m_view->prepareForDetach(); 148 m_view->prepareForDetach();
198 149
199 // Prepare for destruction now, so any unload event handlers get run and the DOMWindow is 150 // Prepare for destruction now, so any unload event handlers get run and the DOMWindow is
200 // notified. If we wait until the view is destroyed, then things won't be ho oked up enough for 151 // notified. If we wait until the view is destroyed, then things won't be ho oked up enough for
(...skipping 14 matching lines...) Expand all
215 void LocalFrame::sendOrientationChangeEvent(int orientation) 166 void LocalFrame::sendOrientationChangeEvent(int orientation)
216 { 167 {
217 if (!RuntimeEnabledFeatures::orientationEventEnabled()) 168 if (!RuntimeEnabledFeatures::orientationEventEnabled())
218 return; 169 return;
219 170
220 m_orientation = orientation; 171 m_orientation = orientation;
221 if (DOMWindow* window = domWindow()) 172 if (DOMWindow* window = domWindow())
222 window->dispatchEvent(Event::create(EventTypeNames::orientationchange)); 173 window->dispatchEvent(Event::create(EventTypeNames::orientationchange));
223 } 174 }
224 175
225 FrameHost* LocalFrame::host() const
226 {
227 return m_host;
228 }
229
230 Page* LocalFrame::page() const
231 {
232 if (m_host)
233 return &m_host->page();
234 return 0;
235 }
236
237 Settings* LocalFrame::settings() const
238 {
239 if (m_host)
240 return &m_host->settings();
241 return 0;
242 }
243
244 void LocalFrame::setPrinting(bool printing, const FloatSize& pageSize, const Flo atSize& originalPageSize, float maximumShrinkRatio) 176 void LocalFrame::setPrinting(bool printing, const FloatSize& pageSize, const Flo atSize& originalPageSize, float maximumShrinkRatio)
245 { 177 {
246 // In setting printing, we should not validate resources already cached for the document. 178 // In setting printing, we should not validate resources already cached for the document.
247 // See https://bugs.webkit.org/show_bug.cgi?id=43704 179 // See https://bugs.webkit.org/show_bug.cgi?id=43704
248 ResourceCacheValidationSuppressor validationSuppressor(document()->fetcher() ); 180 ResourceCacheValidationSuppressor validationSuppressor(document()->fetcher() );
249 181
250 document()->setPrinting(printing); 182 document()->setPrinting(printing);
251 view()->adjustMediaTypeForPrinting(printing); 183 view()->adjustMediaTypeForPrinting(printing);
252 184
253 document()->styleResolverChanged(RecalcStyleImmediately); 185 document()->styleResolverChanged(RecalcStyleImmediately);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 float ratio = originalSize.width() / originalSize.height(); 218 float ratio = originalSize.width() / originalSize.height();
287 resultSize.setHeight(floorf(expectedSize.height())); 219 resultSize.setHeight(floorf(expectedSize.height()));
288 resultSize.setWidth(floorf(resultSize.height() * ratio)); 220 resultSize.setWidth(floorf(resultSize.height() * ratio));
289 } 221 }
290 return resultSize; 222 return resultSize;
291 } 223 }
292 224
293 void LocalFrame::setDOMWindow(PassRefPtr<DOMWindow> domWindow) 225 void LocalFrame::setDOMWindow(PassRefPtr<DOMWindow> domWindow)
294 { 226 {
295 InspectorInstrumentation::frameWindowDiscarded(this, m_domWindow.get()); 227 InspectorInstrumentation::frameWindowDiscarded(this, m_domWindow.get());
296 if (m_domWindow)
297 m_domWindow->reset();
298 if (domWindow) 228 if (domWindow)
299 script().clearWindowShell(); 229 script().clearWindowShell();
300 m_domWindow = domWindow; 230 Frame::setDOMWindow(domWindow);
301 }
302
303 static ChromeClient& emptyChromeClient()
304 {
305 DEFINE_STATIC_LOCAL(EmptyChromeClient, client, ());
306 return client;
307 }
308
309 ChromeClient& LocalFrame::chromeClient() const
310 {
311 if (Page* page = this->page())
312 return page->chrome().client();
313 return emptyChromeClient();
314 }
315
316 Document* LocalFrame::document() const
317 {
318 return m_domWindow ? m_domWindow->document() : 0;
319 }
320
321 RenderView* LocalFrame::contentRenderer() const
322 {
323 return document() ? document()->renderView() : 0;
324 } 231 }
325 232
326 RenderPart* LocalFrame::ownerRenderer() const 233 RenderPart* LocalFrame::ownerRenderer() const
327 { 234 {
328 if (!ownerElement()) 235 if (!ownerElement())
329 return 0; 236 return 0;
330 RenderObject* object = ownerElement()->renderer(); 237 RenderObject* object = ownerElement()->renderer();
331 if (!object) 238 if (!object)
332 return 0; 239 return 0;
333 // FIXME: If <object> is ever fixed to disassociate itself from frames 240 // FIXME: If <object> is ever fixed to disassociate itself from frames
(...skipping 19 matching lines...) Expand all
353 } 260 }
354 261
355 void LocalFrame::willDetachFrameHost() 262 void LocalFrame::willDetachFrameHost()
356 { 263 {
357 // We should never be detatching the page during a Layout. 264 // We should never be detatching the page during a Layout.
358 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout()); 265 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
359 266
360 if (LocalFrame* parent = tree().parent()) 267 if (LocalFrame* parent = tree().parent())
361 parent->loader().checkLoadComplete(); 268 parent->loader().checkLoadComplete();
362 269
363 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd(); 270 Frame::willDetachFrameHost();
364 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver s.begin(); it != stop; ++it) 271 script().clearScriptObjects();
365 (*it)->willDetachFrameHost();
366
367 // FIXME: Page should take care of updating focus/scrolling instead of Local Frame.
368 // FIXME: It's unclear as to why this is called more than once, but it is,
369 // so page() could be NULL.
370 if (page() && page()->focusController().focusedFrame() == this)
371 page()->focusController().setFocusedFrame(nullptr);
372 272
373 if (page() && page()->scrollingCoordinator() && m_view) 273 if (page() && page()->scrollingCoordinator() && m_view)
374 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get()); 274 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get());
375
376 script().clearScriptObjects();
377 } 275 }
378 276
379 void LocalFrame::detachFromFrameHost() 277 void LocalFrame::detachFromFrameHost()
380 { 278 {
381 // We should never be detatching the page during a Layout. 279 // We should never be detatching the page during a Layout.
382 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout()); 280 RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
383 m_host = 0; 281 Frame::detachFromFrameHost();
384 } 282 }
385 283
386 void LocalFrame::disconnectOwnerElement() 284 void LocalFrame::disconnectOwnerElement()
387 { 285 {
388 if (ownerElement()) { 286 if (ownerElement()) {
389 if (Document* doc = document()) 287 if (Document* doc = document())
390 doc->topDocument().clearAXObjectCache(); 288 doc->topDocument().clearAXObjectCache();
391 ownerElement()->clearContentFrame(); 289 ownerElement()->clearContentFrame();
392 if (page()) 290 if (page())
393 page()->decrementSubframeCount(); 291 page()->decrementSubframeCount();
394 } 292 }
395 m_frameInit->setOwnerElement(0); 293 m_frameInit->setOwnerElement(0);
396 } 294 }
397 295
398 bool LocalFrame::isMainFrame() const
399 {
400 Page* page = this->page();
401 return page && this == page->mainFrame();
402 }
403
404 String LocalFrame::documentTypeString() const 296 String LocalFrame::documentTypeString() const
405 { 297 {
406 if (DocumentType* doctype = document()->doctype()) 298 if (DocumentType* doctype = document()->doctype())
407 return createMarkup(doctype); 299 return createMarkup(doctype);
408 300
409 return String(); 301 return String();
410 } 302 }
411 303
412 String LocalFrame::selectedText() const 304 String LocalFrame::selectedText() const
413 { 305 {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 { 632 {
741 if (!m_host) 633 if (!m_host)
742 return 0; 634 return 0;
743 635
744 double ratio = m_host->deviceScaleFactor(); 636 double ratio = m_host->deviceScaleFactor();
745 ratio *= pageZoomFactor(); 637 ratio *= pageZoomFactor();
746 return ratio; 638 return ratio;
747 } 639 }
748 640
749 } // namespace WebCore 641 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/frame/LocalFrame.h ('k') | Source/core/frame/RemoteFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698