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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h

Issue 1615523002: Transitively keep track of an isolated world's children scripts and worlds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a static world stack instead of a per-world private field Created 4 years, 11 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h
index aeadf0611815e4309a02ae1ff14b3d0e32f98888..500557034989ca5fd6a91d5cec4df1d95a04007a 100644
--- a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h
+++ b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h
@@ -35,6 +35,7 @@
#include "core/CoreExport.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "wtf/MainThread.h"
+#include "wtf/OwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
@@ -60,6 +61,33 @@ template<typename T> class DOMObjectHolder;
// This class represent a collection of DOM wrappers for a specific world.
class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
public:
+ class OriginWorldScope {
+ WTF_MAKE_NONCOPYABLE(OriginWorldScope);
+
+ public:
+ explicit OriginWorldScope(PassRefPtr<DOMWrapperWorld> originWorld)
+ : m_hasPushed(false)
+ {
+ ASSERT(isMainThread());
+ if (originWorld) {
+ DOMWrapperWorld::originWorldStack().append(originWorld);
+ m_hasPushed = true;
+ }
+ }
+
+ ~OriginWorldScope()
+ {
+ ASSERT(isMainThread());
+ // "Pop" the origin world to avoid tainting the entire document.
+ if (m_hasPushed) {
+ DOMWrapperWorld::originWorldStack().removeLast();
+ }
+ }
+
+ private:
+ bool m_hasPushed;
+ };
+
static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1, int extensionGroup = -1);
static const int mainWorldExtensionGroup = 0;
@@ -115,9 +143,23 @@ public:
bool isPrivateScriptIsolatedWorld() const { return m_worldId == PrivateScriptIsolatedWorldId; }
bool isWorkerWorld() const { return m_worldId == WorkerWorldId; }
bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; }
+ DOMWrapperWorld* originWorld()
+ {
+ if (isIsolatedWorld())
+ return this;
+ if (isMainThread() && !originWorldStack().isEmpty())
+ return originWorldStack().last().get();
+ return nullptr;
+ };
+ bool isOfIsolatedWorldOrigin() const
+ {
+ ASSERT(isMainThread());
+ return isIsolatedWorld() ? true : originWorldStack().isEmpty() ? false : originWorldStack().last().get()->isIsolatedWorld();
+ };
int worldId() const { return m_worldId; }
int extensionGroup() const { return m_extensionGroup; }
+
DOMDataStore& domDataStore() const { return *m_domDataStore; }
static void setWorldOfInitializingWindow(DOMWrapperWorld* world)
@@ -133,6 +175,8 @@ public:
private:
DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup);
+ static Vector<RefPtr<DOMWrapperWorld>>& originWorldStack();
+
static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObjectHolderBase>&);
void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>);
void unregisterDOMObjectHolder(DOMObjectHolderBase*);
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698