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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 1667843003: Make Resource RefCountedWillBeGarbageCollectedFinalized, attempt #2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix known issues Created 4 years, 10 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed.
6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "platform/weborigin/SecurityOrigin.h" 52 #include "platform/weborigin/SecurityOrigin.h"
53 #include "public/platform/WebFrameScheduler.h" 53 #include "public/platform/WebFrameScheduler.h"
54 #include "wtf/StdLibExtras.h" 54 #include "wtf/StdLibExtras.h"
55 #include "wtf/text/StringBuilder.h" 55 #include "wtf/text/StringBuilder.h"
56 #include "wtf/text/StringHash.h" 56 #include "wtf/text/StringHash.h"
57 57
58 namespace blink { 58 namespace blink {
59 59
60 ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt arted) 60 ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt arted)
61 : m_element(element) 61 : m_element(element)
62 , m_resource(0)
63 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) 62 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst())
64 , m_parserInserted(parserInserted) 63 , m_parserInserted(parserInserted)
65 , m_isExternalScript(false) 64 , m_isExternalScript(false)
66 , m_alreadyStarted(alreadyStarted) 65 , m_alreadyStarted(alreadyStarted)
67 , m_haveFiredLoad(false) 66 , m_haveFiredLoad(false)
68 , m_willBeParserExecuted(false) 67 , m_willBeParserExecuted(false)
69 , m_readyToBeParserExecuted(false) 68 , m_readyToBeParserExecuted(false)
70 , m_willExecuteWhenDocumentFinishedParsing(false) 69 , m_willExecuteWhenDocumentFinishedParsing(false)
71 , m_forceAsync(!parserInserted) 70 , m_forceAsync(!parserInserted)
72 , m_willExecuteInOrder(false) 71 , m_willExecuteInOrder(false)
73 { 72 {
74 ASSERT(m_element); 73 ASSERT(m_element);
75 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite()) 74 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite())
76 m_startLineNumber = element->document().scriptableDocumentParser()->line Number(); 75 m_startLineNumber = element->document().scriptableDocumentParser()->line Number();
77 #if ENABLE(OILPAN)
78 ThreadState::current()->registerPreFinalizer(this);
79 #endif
80 } 76 }
81 77
82 ScriptLoader::~ScriptLoader() 78 ScriptLoader::~ScriptLoader()
83 { 79 {
84 #if !ENABLE(OILPAN)
85 detach();
86 #endif
87 } 80 }
88 81
89 DEFINE_TRACE(ScriptLoader) 82 DEFINE_TRACE(ScriptLoader)
90 { 83 {
91 visitor->trace(m_element); 84 visitor->trace(m_element);
85 visitor->trace(m_resource);
92 visitor->trace(m_pendingScript); 86 visitor->trace(m_pendingScript);
93 } 87 }
94 88
95 void ScriptLoader::didNotifySubtreeInsertionsToDocument() 89 void ScriptLoader::didNotifySubtreeInsertionsToDocument()
96 { 90 {
97 if (!m_parserInserted) 91 if (!m_parserInserted)
98 prepareScript(); // FIXME: Provide a real starting line number here. 92 prepareScript(); // FIXME: Provide a real starting line number here.
99 } 93 }
100 94
101 void ScriptLoader::childrenChanged() 95 void ScriptLoader::childrenChanged()
102 { 96 {
103 if (!m_parserInserted && m_element->inDocument()) 97 if (!m_parserInserted && m_element->inDocument())
104 prepareScript(); // FIXME: Provide a real starting line number here. 98 prepareScript(); // FIXME: Provide a real starting line number here.
105 } 99 }
106 100
107 void ScriptLoader::handleSourceAttribute(const String& sourceUrl) 101 void ScriptLoader::handleSourceAttribute(const String& sourceUrl)
108 { 102 {
109 if (ignoresLoadRequest() || sourceUrl.isEmpty()) 103 if (ignoresLoadRequest() || sourceUrl.isEmpty())
110 return; 104 return;
111 105
112 prepareScript(); // FIXME: Provide a real starting line number here. 106 prepareScript(); // FIXME: Provide a real starting line number here.
113 } 107 }
114 108
115 void ScriptLoader::handleAsyncAttribute() 109 void ScriptLoader::handleAsyncAttribute()
116 { 110 {
117 m_forceAsync = false; 111 m_forceAsync = false;
118 } 112 }
119 113
120 void ScriptLoader::detach() 114 void ScriptLoader::detach()
haraken 2016/02/04 23:56:30 Who calls ScriptLoader::detach() after this CL? Ma
Nate Chapin 2016/02/06 00:34:07 ScriptRunner::notifyScriptLoadError uses it. I thi
121 { 115 {
122 if (!m_pendingScript) 116 if (!m_pendingScript)
123 return; 117 return;
124 m_pendingScript->stopWatchingForLoad(this); 118 m_pendingScript->dispose();
125 m_pendingScript->releaseElementAndClear();
126 m_pendingScript = nullptr; 119 m_pendingScript = nullptr;
127 } 120 }
128 121
129 // Helper function 122 // Helper function
130 static bool isLegacySupportedJavaScriptLanguage(const String& language) 123 static bool isLegacySupportedJavaScriptLanguage(const String& language)
131 { 124 {
132 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3. 125 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3.
133 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. 126 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript.
134 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. 127 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't.
135 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. 128 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace.
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 RefPtrWillBeRawPtr<Element> element = m_pendingScript->releaseElementAndClea r(); 440 RefPtrWillBeRawPtr<Element> element = m_pendingScript->releaseElementAndClea r();
448 ALLOW_UNUSED_LOCAL(element); 441 ALLOW_UNUSED_LOCAL(element);
449 if (errorOccurred) { 442 if (errorOccurred) {
450 dispatchErrorEvent(); 443 dispatchErrorEvent();
451 } else if (!m_resource->wasCanceled()) { 444 } else if (!m_resource->wasCanceled()) {
452 if (executeScript(source)) 445 if (executeScript(source))
453 dispatchLoadEvent(); 446 dispatchLoadEvent();
454 else 447 else
455 dispatchErrorEvent(); 448 dispatchErrorEvent();
456 } 449 }
457 m_resource = 0; 450 m_resource = nullptr;
458 } 451 }
459 452
460 void ScriptLoader::notifyFinished(Resource* resource) 453 void ScriptLoader::notifyFinished(Resource* resource)
461 { 454 {
462 ASSERT(!m_willBeParserExecuted); 455 ASSERT(!m_willBeParserExecuted);
463 456
464 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document()); 457 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document());
465 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum ent().get(); 458 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum ent().get();
466 if (!contextDocument) 459 if (!contextDocument)
467 return; 460 return;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (isHTMLScriptLoader(element)) 518 if (isHTMLScriptLoader(element))
526 return toHTMLScriptElement(element)->loader(); 519 return toHTMLScriptElement(element)->loader();
527 520
528 if (isSVGScriptLoader(element)) 521 if (isSVGScriptLoader(element))
529 return toSVGScriptElement(element)->loader(); 522 return toSVGScriptElement(element)->loader();
530 523
531 return 0; 524 return 0;
532 } 525 }
533 526
534 } // namespace blink 527 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698