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

Side by Side Diff: third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.cpp

Issue 2057283002: Fix canvas-related crash caused by bad object teardown sequence (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test crash Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 19 matching lines...) Expand all
30 #include "platform/weborigin/SecurityOrigin.h" 30 #include "platform/weborigin/SecurityOrigin.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 CanvasRenderingContext::CanvasRenderingContext(HTMLCanvasElement* canvas, Offscr eenCanvas* offscreenCanvas) 34 CanvasRenderingContext::CanvasRenderingContext(HTMLCanvasElement* canvas, Offscr eenCanvas* offscreenCanvas)
35 : m_canvas(canvas) 35 : m_canvas(canvas)
36 , m_offscreenCanvas(offscreenCanvas) 36 , m_offscreenCanvas(offscreenCanvas)
37 { 37 {
38 } 38 }
39 39
40 void CanvasRenderingContext::dispose()
41 {
42 // HTMLCanvasElement and CanvasRenderingContext have a circular reference.
43 // When the pair is no longer reachable, their destruction order is non-
44 // deterministic, so the first of the two to be destroyed needs to notify
45 // the other in order to break the circular reference. This is to avoid
46 // an error when CanvasRenderingContext2D::didProcessTask() is invoked
47 // after the HTMLCanvasElement is destroyed.
48 if (canvas()) {
49 canvas()->detachContext();
50 m_canvas = nullptr;
51 }
52 }
53
40 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId(co nst String& id) 54 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId(co nst String& id)
41 { 55 {
42 if (id == "2d") 56 if (id == "2d")
43 return Context2d; 57 return Context2d;
44 if (id == "experimental-webgl") 58 if (id == "experimental-webgl")
45 return ContextExperimentalWebgl; 59 return ContextExperimentalWebgl;
46 if (id == "webgl") 60 if (id == "webgl")
47 return ContextWebgl; 61 return ContextWebgl;
48 if (id == "webgl2") 62 if (id == "webgl2")
49 return ContextWebgl2; 63 return ContextWebgl2;
(...skipping 15 matching lines...) Expand all
65 const KURL& sourceURL = imageSource->sourceURL(); 79 const KURL& sourceURL = imageSource->sourceURL();
66 bool hasURL = (sourceURL.isValid() && !sourceURL.isAboutBlankURL()); 80 bool hasURL = (sourceURL.isValid() && !sourceURL.isAboutBlankURL());
67 81
68 if (hasURL) { 82 if (hasURL) {
69 if (sourceURL.protocolIsData() || m_cleanURLs.contains(sourceURL.getStri ng())) 83 if (sourceURL.protocolIsData() || m_cleanURLs.contains(sourceURL.getStri ng()))
70 return false; 84 return false;
71 if (m_dirtyURLs.contains(sourceURL.getString())) 85 if (m_dirtyURLs.contains(sourceURL.getString()))
72 return true; 86 return true;
73 } 87 }
74 88
75 ASSERT(!canvas() == !!destinationSecurityOrigin); // Must have one or the ot her 89 DCHECK_EQ(!canvas(), !!destinationSecurityOrigin); // Must have one or the o ther
76 bool taintOrigin = imageSource->wouldTaintOrigin(destinationSecurityOrigin ? destinationSecurityOrigin : canvas()->getSecurityOrigin()); 90 bool taintOrigin = imageSource->wouldTaintOrigin(destinationSecurityOrigin ? destinationSecurityOrigin : canvas()->getSecurityOrigin());
77 91
78 if (hasURL) { 92 if (hasURL) {
79 if (taintOrigin) 93 if (taintOrigin)
80 m_dirtyURLs.add(sourceURL.getString()); 94 m_dirtyURLs.add(sourceURL.getString());
81 else 95 else
82 m_cleanURLs.add(sourceURL.getString()); 96 m_cleanURLs.add(sourceURL.getString());
83 } 97 }
84 return taintOrigin; 98 return taintOrigin;
85 } 99 }
86 100
87 DEFINE_TRACE(CanvasRenderingContext) 101 DEFINE_TRACE(CanvasRenderingContext)
88 { 102 {
89 visitor->trace(m_canvas); 103 visitor->trace(m_canvas);
90 visitor->trace(m_offscreenCanvas); 104 visitor->trace(m_offscreenCanvas);
91 } 105 }
92 106
93 } // namespace blink 107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698