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

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

Issue 2838933003: [not-for-commit] kitsune changes + pending kouhei changes (Closed)
Patch Set: 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..ad79c953ad54f509542ad5fa891318b60ec2dd52
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ClassicPendingScript.h
@@ -0,0 +1,100 @@
+// 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);
+
+ // We use PendingScript::Dispose() also as ClassicPendingScript's
+ // prefinalizer so that Dispose() is called before ResourceOwner's
+ // prefinalizer. https://crbug.com/711703
+ // If ResourceOwner's prefinalizer is called before Dispose(), it clears
+ // Resource(), leaving ClassicPendingScript in a half-broken state
+ // (e.g. Resource() is cleared but |streamer_| is not cleared).
+ USING_PRE_FINALIZER(ClassicPendingScript, Dispose);
+
+ 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;
+ bool IsExternal() const override { return GetResource(); }
+ bool ErrorOccurred() const override;
+ bool WasCanceled() const override;
+ void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override;
+ KURL UrlForClassicScript() const override;
+ void RemoveFromMemoryCache() override;
+ void DisposeInternal() override;
+
+ // Supressing crashes on windows bots.
+ void Dispose();
+
+ 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