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

Side by Side Diff: Source/core/svg/graphics/SVGImage.cpp

Issue 185613003: Oilpan: Delay frameDetached() so it won't dispatch event inside ~SVGImage (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add comments 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/svg/graphics/SVGImageChromeClient.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) 2006 Eric Seidel <eric@webkit.org> 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "platform/graphics/ImageObserver.h" 50 #include "platform/graphics/ImageObserver.h"
51 #include "wtf/PassRefPtr.h" 51 #include "wtf/PassRefPtr.h"
52 52
53 namespace WebCore { 53 namespace WebCore {
54 54
55 SVGImage::SVGImage(ImageObserver* observer) 55 SVGImage::SVGImage(ImageObserver* observer)
56 : Image(observer) 56 : Image(observer)
57 { 57 {
58 } 58 }
59 59
60 // Delay destruction of Page attached to SVGImage.
61 // We need to call |loader().frameDetached()| before disposing a Page, however
62 // the call is non-trivial and involves touching/creating on-heap objects
63 // which is not possible from a GarbageCollected object finalizer.
64 // To circumvent this, DelayedSVGImageDestructor will delay the call to
65 // the end of current event loop.
66 class DelayedSVGImageDestructor {
67 public:
68 void add(PassOwnPtr<SVGImageChromeClient> chromeClient, PassOwnPtr<Page> pag e)
69 {
70 Entry entry;
71 entry.chromeClient = chromeClient.leakPtr();
eseidel 2014/03/10 21:49:09 Why not just use an OwnPtr and then call .clear()
72 entry.page = page.leakPtr();
73
74 m_entries.append(entry);
75 m_detachTimer.startOneShot(0.0);
76 }
77
78 static DelayedSVGImageDestructor* get()
79 {
80 DEFINE_STATIC_LOCAL(DelayedSVGImageDestructor, delayed, ());
81 return &delayed;
82 }
83
84 private:
85 DelayedSVGImageDestructor()
86 : m_detachTimer(this, &DelayedSVGImageDestructor::detachTimerFired)
87 {
88 }
89
90 void detachTimerFired(Timer<DelayedSVGImageDestructor>*)
91 {
92 Vector<Entry>::const_iterator it = m_entries.begin();
93 Vector<Entry>::const_iterator itEnd = m_entries.end();
94 for (; it != itEnd; ++it) {
95 it->page->mainFrame()->loader().frameDetached();
96 delete it->page;
97 delete it->chromeClient;
98 }
99
100 m_entries.clear();
101 }
102
103 struct Entry {
104 SVGImageChromeClient* chromeClient;
105 Page* page;
106 };
107 Vector<Entry> m_entries;
108 Timer<DelayedSVGImageDestructor> m_detachTimer;
109 };
110
60 SVGImage::~SVGImage() 111 SVGImage::~SVGImage()
61 { 112 {
62 if (m_page) { 113 m_chromeClient->clearImage();
63 // Store m_page in a local variable, clearing m_page, so that SVGImageCh romeClient knows we're destructed. 114 DelayedSVGImageDestructor::get()->add(m_chromeClient.release(), m_page.relea se());
64 OwnPtr<Page> currentPage = m_page.release();
65 currentPage->mainFrame()->loader().frameDetached(); // Break both the lo ader and view references to the frame
66 }
67
68 // Verify that page teardown destroyed the Chrome
69 ASSERT(!m_chromeClient || !m_chromeClient->image());
70 } 115 }
71 116
72 bool SVGImage::isInSVGImage(const Element* element) 117 bool SVGImage::isInSVGImage(const Element* element)
73 { 118 {
74 ASSERT(element); 119 ASSERT(element);
75 120
76 Page* page = element->document().page(); 121 Page* page = element->document().page();
77 if (!page) 122 if (!page)
78 return false; 123 return false;
79 124
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 460
416 return m_page; 461 return m_page;
417 } 462 }
418 463
419 String SVGImage::filenameExtension() const 464 String SVGImage::filenameExtension() const
420 { 465 {
421 return "svg"; 466 return "svg";
422 } 467 }
423 468
424 } 469 }
OLDNEW
« no previous file with comments | « no previous file | Source/core/svg/graphics/SVGImageChromeClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698