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

Unified Diff: third_party/WebKit/Source/core/dom/ClassicPendingScript.h

Issue 2653923008: Reland of Split PendingScript into PendingScript and ClassicPendingScript (Closed)
Patch Set: Crash fix by adding Dispose() as ClassicPendingScript prefinalizer Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/ClassicPendingScript.h
diff --git a/third_party/WebKit/Source/core/dom/ClassicPendingScript.h b/third_party/WebKit/Source/core/dom/ClassicPendingScript.h
new file mode 100644
index 0000000000000000000000000000000000000000..1ce437603818b2b7ca9d5581eb76cf7b71ec5364
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ClassicPendingScript.h
@@ -0,0 +1,90 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ClassicPendingScript_h
+#define ClassicPendingScript_h
+
+#include "bindings/core/v8/ScriptStreamer.h"
+#include "core/dom/ClassicScript.h"
+#include "core/dom/PendingScript.h"
+#include "core/loader/resource/ScriptResource.h"
+#include "platform/MemoryCoordinator.h"
+#include "platform/loader/fetch/ResourceOwner.h"
+
+namespace blink {
+
+// PendingScript for a classic script
+// https://html.spec.whatwg.org/#classic-script.
+//
+// TODO(kochi): The comment below is from pre-oilpan age and may not be correct
+// now.
+// A RefPtr alone does not prevent the underlying Resource from purging its data
+// buffer. This class holds a dummy client open for its lifetime in order to
+// guarantee that the data buffer will not be purged.
+class CORE_EXPORT ClassicPendingScript final
+ : public PendingScript,
+ public ResourceOwner<ScriptResource>,
+ public MemoryCoordinatorClient {
+ USING_GARBAGE_COLLECTED_MIXIN(ClassicPendingScript);
+ USING_PRE_FINALIZER(ClassicPendingScript, Dispose);
hiroshige 2017/04/19 01:01:40 I also register Dispose() as ClassicPendingScript.
+
+ public:
+ // For script from an external file.
+ static ClassicPendingScript* Create(ScriptElementBase*, ScriptResource*);
+ // For inline script.
+ static ClassicPendingScript* Create(ScriptElementBase*, const TextPosition&);
+
+ static ClassicPendingScript* CreateForTesting(ScriptResource*);
+
+ ~ClassicPendingScript() override;
+
+ void SetStreamer(ScriptStreamer*);
+ void StreamingFinished();
+
+ DECLARE_TRACE();
+
+ blink::ScriptType GetScriptType() const override {
+ return blink::ScriptType::kClassic;
+ }
+
+ ClassicScript* GetSource(const KURL& document_url,
+ bool& error_occurred) const override;
+ bool IsReady() const override;
+ KURL Url() const override;
+ bool IsExternal() const override { return GetResource(); }
+ bool ErrorOccurred() const override;
+ bool WasCanceled() const override;
+ void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override;
+ void RemoveFromMemoryCache() override;
+ void DisposeInternal() override;
+
+ private:
+ ClassicPendingScript(ScriptElementBase*,
+ ScriptResource*,
+ const TextPosition&,
+ bool is_for_testing = false);
+ ClassicPendingScript() = delete;
+
+ void CheckState() const override;
+
+ // ScriptResourceClient
+ void NotifyFinished(Resource*) override;
+ String DebugName() const override { return "PendingScript"; }
+ void NotifyAppendData(ScriptResource*) override;
+
+ // MemoryCoordinatorClient
+ void OnPurgeMemory() override;
+
+ bool integrity_failure_;
+
+ Member<ScriptStreamer> streamer_;
+
+ // This flag is used to skip non-null checks of |m_element| in unit
+ // tests, because |m_element| can be null in unit tests.
+ const bool is_for_testing_;
+};
+
+} // namespace blink
+
+#endif // PendingScript_h

Powered by Google App Engine
This is Rietveld 408576698