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

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

Issue 115293005: Add a layer of indirection between Frame and Page (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years 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 | Annotate | Revision Log
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 26 matching lines...) Expand all
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" 46 #include "core/frame/FrameDestructionObserver.h"
47 #include "core/frame/FrameHost.h"
47 #include "core/frame/FrameView.h" 48 #include "core/frame/FrameView.h"
48 #include "core/frame/Settings.h" 49 #include "core/frame/Settings.h"
49 #include "core/frame/animation/AnimationController.h" 50 #include "core/frame/animation/AnimationController.h"
50 #include "core/html/HTMLFrameElementBase.h" 51 #include "core/html/HTMLFrameElementBase.h"
51 #include "core/inspector/InspectorInstrumentation.h" 52 #include "core/inspector/InspectorInstrumentation.h"
52 #include "core/loader/EmptyClients.h" 53 #include "core/loader/EmptyClients.h"
53 #include "core/loader/FrameLoaderClient.h" 54 #include "core/loader/FrameLoaderClient.h"
54 #include "core/page/Chrome.h" 55 #include "core/page/Chrome.h"
55 #include "core/page/ChromeClient.h" 56 #include "core/page/ChromeClient.h"
56 #include "core/page/EventHandler.h" 57 #include "core/page/EventHandler.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 static inline float parentTextZoomFactor(Frame* frame) 97 static inline float parentTextZoomFactor(Frame* frame)
97 { 98 {
98 Frame* parent = frame->tree().parent(); 99 Frame* parent = frame->tree().parent();
99 if (!parent) 100 if (!parent)
100 return 1; 101 return 1;
101 return parent->textZoomFactor(); 102 return parent->textZoomFactor();
102 } 103 }
103 104
104 inline Frame::Frame(PassRefPtr<FrameInit> frameInit) 105 inline Frame::Frame(PassRefPtr<FrameInit> frameInit)
105 : m_page(frameInit->page()) 106 : m_host(frameInit->frameHost())
106 , m_treeNode(this, parentFromOwnerElement(frameInit->ownerElement())) 107 , m_treeNode(this, parentFromOwnerElement(frameInit->ownerElement()))
107 , m_loader(this, frameInit->frameLoaderClient()) 108 , m_loader(this, frameInit->frameLoaderClient())
108 , m_navigationScheduler(this) 109 , m_navigationScheduler(this)
109 , m_script(adoptPtr(new ScriptController(this))) 110 , m_script(adoptPtr(new ScriptController(this)))
110 , m_editor(Editor::create(*this)) 111 , m_editor(Editor::create(*this))
111 , m_spellChecker(SpellChecker::create(*this)) 112 , m_spellChecker(SpellChecker::create(*this))
112 , m_selection(adoptPtr(new FrameSelection(this))) 113 , m_selection(adoptPtr(new FrameSelection(this)))
113 , m_eventHandler(adoptPtr(new EventHandler(this))) 114 , m_eventHandler(adoptPtr(new EventHandler(this)))
114 , m_animationController(adoptPtr(new AnimationController(this))) 115 , m_animationController(adoptPtr(new AnimationController(this)))
115 , m_inputMethodController(InputMethodController::create(*this)) 116 , m_inputMethodController(InputMethodController::create(*this))
116 , m_frameInit(frameInit) 117 , m_frameInit(frameInit)
117 , m_pageZoomFactor(parentPageZoomFactor(this)) 118 , m_pageZoomFactor(parentPageZoomFactor(this))
118 , m_textZoomFactor(parentTextZoomFactor(this)) 119 , m_textZoomFactor(parentTextZoomFactor(this))
119 #if ENABLE(ORIENTATION_EVENTS) 120 #if ENABLE(ORIENTATION_EVENTS)
120 , m_orientation(0) 121 , m_orientation(0)
121 #endif 122 #endif
122 , m_inViewSourceMode(false) 123 , m_inViewSourceMode(false)
123 , m_remotePlatformLayer(0) 124 , m_remotePlatformLayer(0)
124 { 125 {
125 ASSERT(m_page); 126 ASSERT(page());
126 127
127 if (ownerElement()) { 128 if (ownerElement()) {
128 m_page->incrementSubframeCount(); 129 page()->incrementSubframeCount();
129 ownerElement()->setContentFrame(*this); 130 ownerElement()->setContentFrame(*this);
130 } 131 }
131 132
132 #ifndef NDEBUG 133 #ifndef NDEBUG
133 frameCounter.increment(); 134 frameCounter.increment();
134 #endif 135 #endif
135 } 136 }
136 137
137 PassRefPtr<Frame> Frame::create(PassRefPtr<FrameInit> frameInit) 138 PassRefPtr<Frame> Frame::create(PassRefPtr<FrameInit> frameInit)
138 { 139 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 202
202 if (m_view) 203 if (m_view)
203 m_view->unscheduleRelayout(); 204 m_view->unscheduleRelayout();
204 205
205 eventHandler().clear(); 206 eventHandler().clear();
206 207
207 m_view = view; 208 m_view = view;
208 209
209 if (m_view && isMainFrame()) 210 if (m_view && isMainFrame())
210 m_view->setVisibleContentScaleFactor(m_page->pageScaleFactor()); 211 m_view->setVisibleContentScaleFactor(page()->pageScaleFactor());
211 } 212 }
212 213
213 #if ENABLE(ORIENTATION_EVENTS) 214 #if ENABLE(ORIENTATION_EVENTS)
214 void Frame::sendOrientationChangeEvent(int orientation) 215 void Frame::sendOrientationChangeEvent(int orientation)
215 { 216 {
216 m_orientation = orientation; 217 m_orientation = orientation;
217 if (DOMWindow* window = domWindow()) 218 if (DOMWindow* window = domWindow())
218 window->dispatchEvent(Event::create(EventTypeNames::orientationchange)); 219 window->dispatchEvent(Event::create(EventTypeNames::orientationchange));
219 } 220 }
220 #endif // ENABLE(ORIENTATION_EVENTS) 221 #endif // ENABLE(ORIENTATION_EVENTS)
221 222
223 FrameHost* Frame::host() const
224 {
225 return m_host;
226 }
227
228 Page* Frame::page() const
229 {
230 return m_host ? &m_host->page() : nullptr;
231 }
232
222 Settings* Frame::settings() const 233 Settings* Frame::settings() const
223 { 234 {
224 return m_page ? &m_page->settings() : 0; 235 return m_host ? &m_host->settings() : nullptr;
225 } 236 }
226 237
227 void Frame::setPrinting(bool printing, const FloatSize& pageSize, const FloatSiz e& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot shouldAdjustV iewSize) 238 void Frame::setPrinting(bool printing, const FloatSize& pageSize, const FloatSiz e& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot shouldAdjustV iewSize)
228 { 239 {
229 // In setting printing, we should not validate resources already cached for the document. 240 // In setting printing, we should not validate resources already cached for the document.
230 // See https://bugs.webkit.org/show_bug.cgi?id=43704 241 // See https://bugs.webkit.org/show_bug.cgi?id=43704
231 ResourceCacheValidationSuppressor validationSuppressor(document()->fetcher() ); 242 ResourceCacheValidationSuppressor validationSuppressor(document()->fetcher() );
232 243
233 document()->setPrinting(printing); 244 document()->setPrinting(printing);
234 view()->adjustMediaTypeForPrinting(printing); 245 view()->adjustMediaTypeForPrinting(printing);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 document()->dispatchVisibilityStateChangeEvent(); 335 document()->dispatchVisibilityStateChangeEvent();
325 336
326 Vector<RefPtr<Frame> > childFrames; 337 Vector<RefPtr<Frame> > childFrames;
327 for (Frame* child = tree().firstChild(); child; child = child->tree().nextSi bling()) 338 for (Frame* child = tree().firstChild(); child; child = child->tree().nextSi bling())
328 childFrames.append(child); 339 childFrames.append(child);
329 340
330 for (size_t i = 0; i < childFrames.size(); ++i) 341 for (size_t i = 0; i < childFrames.size(); ++i)
331 childFrames[i]->dispatchVisibilityStateChangeEvent(); 342 childFrames[i]->dispatchVisibilityStateChangeEvent();
332 } 343 }
333 344
334 void Frame::willDetachPage() 345 void Frame::willDetachFrameHost()
335 { 346 {
336 // We should never be detatching the page during a Layout. 347 // We should never be detatching the page during a Layout.
337 RELEASE_ASSERT(!m_view || !m_view->isInLayout()); 348 RELEASE_ASSERT(!m_view || !m_view->isInLayout());
338 349
339 if (Frame* parent = tree().parent()) 350 if (Frame* parent = tree().parent())
340 parent->loader().checkLoadComplete(); 351 parent->loader().checkLoadComplete();
341 352
342 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd(); 353 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e nd();
343 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver s.begin(); it != stop; ++it) 354 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver s.begin(); it != stop; ++it)
344 (*it)->willDetachPage(); 355 (*it)->willDetachFrameHost();
345 356
357 // FIXME: Page should take care of updating focus/scrolling instead of Frame .
346 // FIXME: It's unclear as to why this is called more than once, but it is, 358 // FIXME: It's unclear as to why this is called more than once, but it is,
347 // so page() could be NULL. 359 // so page() could be NULL.
348 if (page() && page()->focusController().focusedFrame() == this) 360 if (page() && page()->focusController().focusedFrame() == this)
349 page()->focusController().setFocusedFrame(0); 361 page()->focusController().setFocusedFrame(0);
350 362
351 if (page() && page()->scrollingCoordinator() && m_view) 363 if (page() && page()->scrollingCoordinator() && m_view)
352 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get()); 364 page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get());
353 365
354 script().clearScriptObjects(); 366 script().clearScriptObjects();
355 } 367 }
356 368
357 void Frame::detachFromPage() 369 void Frame::detachFromFrameHost()
358 { 370 {
359 // We should never be detatching the page during a Layout. 371 // We should never be detatching the page during a Layout.
360 RELEASE_ASSERT(!m_view || !m_view->isInLayout()); 372 RELEASE_ASSERT(!m_view || !m_view->isInLayout());
361 m_page = 0; 373 m_host = 0;
362 } 374 }
363 375
364 void Frame::disconnectOwnerElement() 376 void Frame::disconnectOwnerElement()
365 { 377 {
366 if (ownerElement()) { 378 if (ownerElement()) {
367 if (Document* doc = document()) 379 if (Document* doc = document())
368 doc->topDocument()->clearAXObjectCache(); 380 doc->topDocument()->clearAXObjectCache();
369 ownerElement()->clearContentFrame(); 381 ownerElement()->clearContentFrame();
370 if (m_page) 382 if (page())
371 m_page->decrementSubframeCount(); 383 page()->decrementSubframeCount();
372 } 384 }
373 m_frameInit->setOwnerElement(0); 385 m_frameInit->setOwnerElement(0);
374 } 386 }
375 387
376 bool Frame::isMainFrame() const 388 bool Frame::isMainFrame() const
377 { 389 {
378 return m_page && this == m_page->mainFrame(); 390 Page* page = this->page();
391 return page && this == page->mainFrame();
379 } 392 }
380 393
381 String Frame::documentTypeString() const 394 String Frame::documentTypeString() const
382 { 395 {
383 if (DocumentType* doctype = document()->doctype()) 396 if (DocumentType* doctype = document()->doctype())
384 return createMarkup(doctype); 397 return createMarkup(doctype);
385 398
386 return String(); 399 return String();
387 } 400 }
388 401
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 459 }
447 460
448 return 0; 461 return 0;
449 } 462 }
450 463
451 void Frame::createView(const IntSize& viewportSize, const Color& backgroundColor , bool transparent, 464 void Frame::createView(const IntSize& viewportSize, const Color& backgroundColor , bool transparent,
452 ScrollbarMode horizontalScrollbarMode, bool horizontalLock, 465 ScrollbarMode horizontalScrollbarMode, bool horizontalLock,
453 ScrollbarMode verticalScrollbarMode, bool verticalLock) 466 ScrollbarMode verticalScrollbarMode, bool verticalLock)
454 { 467 {
455 ASSERT(this); 468 ASSERT(this);
456 ASSERT(m_page); 469 ASSERT(page());
457 470
458 bool isMainFrame = this->isMainFrame(); 471 bool isMainFrame = this->isMainFrame();
459 472
460 if (isMainFrame && view()) 473 if (isMainFrame && view())
461 view()->setParentVisible(false); 474 view()->setParentVisible(false);
462 475
463 setView(0); 476 setView(0);
464 477
465 RefPtr<FrameView> frameView; 478 RefPtr<FrameView> frameView;
466 if (isMainFrame) { 479 if (isMainFrame) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 { 582 {
570 // Ensure that this method is being called on the main frame of the page. 583 // Ensure that this method is being called on the main frame of the page.
571 ASSERT(isMainFrame()); 584 ASSERT(isMainFrame());
572 585
573 unsigned count = 0; 586 unsigned count = 0;
574 for (const Frame* frame = this; frame; frame = frame->tree().traverseNext()) { 587 for (const Frame* frame = this; frame; frame = frame->tree().traverseNext()) {
575 if (frame->document()) 588 if (frame->document())
576 count += WheelController::from(frame->document())->wheelEventHandler Count(); 589 count += WheelController::from(frame->document())->wheelEventHandler Count();
577 } 590 }
578 591
579 m_page->chrome().client().numWheelEventHandlersChanged(count); 592 m_host->chrome().client().numWheelEventHandlersChanged(count);
580 } 593 }
581 594
582 bool Frame::isURLAllowed(const KURL& url) const 595 bool Frame::isURLAllowed(const KURL& url) const
583 { 596 {
584 // We allow one level of self-reference because some sites depend on that, 597 // We allow one level of self-reference because some sites depend on that,
585 // but we don't allow more than one. 598 // but we don't allow more than one.
586 if (m_page->subframeCount() >= Page::maxNumberOfFrames) 599 if (page()->subframeCount() >= Page::maxNumberOfFrames)
587 return false; 600 return false;
588 bool foundSelfReference = false; 601 bool foundSelfReference = false;
589 for (const Frame* frame = this; frame; frame = frame->tree().parent()) { 602 for (const Frame* frame = this; frame; frame = frame->tree().parent()) {
590 if (equalIgnoringFragmentIdentifier(frame->document()->url(), url)) { 603 if (equalIgnoringFragmentIdentifier(frame->document()->url(), url)) {
591 if (foundSelfReference) 604 if (foundSelfReference)
592 return false; 605 return false;
593 foundSelfReference = true; 606 foundSelfReference = true;
594 } 607 }
595 } 608 }
596 return true; 609 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 m_view->setNodeToDraw(node); // Enable special sub-tree drawing mode. 651 m_view->setNodeToDraw(node); // Enable special sub-tree drawing mode.
639 652
640 // Document::updateLayout may have blown away the original RenderObject. 653 // Document::updateLayout may have blown away the original RenderObject.
641 RenderObject* renderer = node->renderer(); 654 RenderObject* renderer = node->renderer();
642 if (!renderer) 655 if (!renderer)
643 return nullptr; 656 return nullptr;
644 657
645 LayoutRect topLevelRect; 658 LayoutRect topLevelRect;
646 IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLev elRect)); 659 IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLev elRect));
647 660
648 float deviceScaleFactor = 1; 661 // If the node has a renderer, this Frame must be active and have a host.
abarth-chromium 2013/12/15 06:04:23 Can we make this an ASSERT rather than a comment?
649 if (m_page) 662 float deviceScaleFactor = m_host->deviceScaleFactor();
650 deviceScaleFactor = m_page->deviceScaleFactor();
651 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor); 663 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);
652 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor); 664 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);
653 665
654 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(paintingRect.size()); 666 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(paintingRect.size());
655 if (!buffer) 667 if (!buffer)
656 return nullptr; 668 return nullptr;
657 buffer->context()->scale(FloatSize(deviceScaleFactor, deviceScaleFactor)); 669 buffer->context()->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
658 buffer->context()->translate(-paintingRect.x(), -paintingRect.y()); 670 buffer->context()->translate(-paintingRect.x(), -paintingRect.y());
659 buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.ma xY())); 671 buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.ma xY()));
660 672
661 m_view->paintContents(buffer->context(), paintingRect); 673 m_view->paintContents(buffer->context(), paintingRect);
662 674
663 RefPtr<Image> image = buffer->copyImage(); 675 RefPtr<Image> image = buffer->copyImage();
664 return DragImage::create(image.get(), renderer->shouldRespectImageOrientatio n()); 676 return DragImage::create(image.get(), renderer->shouldRespectImageOrientatio n());
665 } 677 }
666 678
667 PassOwnPtr<DragImage> Frame::dragImageForSelection() 679 PassOwnPtr<DragImage> Frame::dragImageForSelection()
668 { 680 {
669 if (!selection().isRange()) 681 if (!selection().isRange())
670 return nullptr; 682 return nullptr;
671 683
672 const ScopedFramePaintingState state(this, 0); 684 const ScopedFramePaintingState state(this, 0);
673 m_view->setPaintBehavior(PaintBehaviorSelectionOnly | PaintBehaviorFlattenCo mpositingLayers); 685 m_view->setPaintBehavior(PaintBehaviorSelectionOnly | PaintBehaviorFlattenCo mpositingLayers);
674 document()->updateLayout(); 686 document()->updateLayout();
675 687
676 IntRect paintingRect = enclosingIntRect(selection().bounds()); 688 IntRect paintingRect = enclosingIntRect(selection().bounds());
677 689
678 float deviceScaleFactor = 1; 690 // If the node has a renderer, this Frame must be active and have a host.
abarth-chromium 2013/12/15 06:04:23 ditto
679 if (m_page) 691 float deviceScaleFactor = m_host->deviceScaleFactor();
680 deviceScaleFactor = m_page->deviceScaleFactor();
681 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor); 692 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);
682 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor); 693 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);
683 694
684 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(paintingRect.size()); 695 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(paintingRect.size());
685 if (!buffer) 696 if (!buffer)
686 return nullptr; 697 return nullptr;
687 buffer->context()->scale(FloatSize(deviceScaleFactor, deviceScaleFactor)); 698 buffer->context()->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
688 buffer->context()->translate(-paintingRect.x(), -paintingRect.y()); 699 buffer->context()->translate(-paintingRect.x(), -paintingRect.y());
689 buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.ma xY())); 700 buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.ma xY()));
690 701
691 m_view->paintContents(buffer->context(), paintingRect); 702 m_view->paintContents(buffer->context(), paintingRect);
692 703
693 RefPtr<Image> image = buffer->copyImage(); 704 RefPtr<Image> image = buffer->copyImage();
694 return DragImage::create(image.get()); 705 return DragImage::create(image.get());
695 } 706 }
696 707
697 double Frame::devicePixelRatio() const 708 double Frame::devicePixelRatio() const
698 { 709 {
699 if (!m_page) 710 if (!m_host)
700 return 0; 711 return 0;
701 712
702 double ratio = m_page->deviceScaleFactor(); 713 double ratio = m_host->deviceScaleFactor();
703 if (RuntimeEnabledFeatures::devicePixelRatioIncludesZoomEnabled()) 714 if (RuntimeEnabledFeatures::devicePixelRatioIncludesZoomEnabled())
704 ratio *= pageZoomFactor(); 715 ratio *= pageZoomFactor();
705 return ratio; 716 return ratio;
706 } 717 }
707 718
708 } // namespace WebCore 719 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698