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

Side by Side Diff: Source/bindings/v8/DOMWrapperWorld.h

Issue 345893002: Implement an infrastructure of Blink-in-JS Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 class DOMDataStore; 45 class DOMDataStore;
46 class ExecutionContext; 46 class ExecutionContext;
47 class ScriptController; 47 class ScriptController;
48 48
49 enum WorldIdConstants { 49 enum WorldIdConstants {
50 MainWorldId = 0, 50 MainWorldId = 0,
51 // Embedder isolated worlds can use IDs in [1, 1<<29). 51 // Embedder isolated worlds can use IDs in [1, 1<<29).
52 EmbedderWorldIdLimit = (1 << 29), 52 EmbedderWorldIdLimit = (1 << 29),
53 ScriptPreprocessorIsolatedWorldId, 53 ScriptPreprocessorIsolatedWorldId,
54 BlinkInJSIsolatedWorldId,
abarth-chromium 2014/06/20 15:17:43 PrivateScriptWorldId ?
54 IsolatedWorldIdLimit, 55 IsolatedWorldIdLimit,
55 WorkerWorldId, 56 WorkerWorldId,
56 TestingWorldId, 57 TestingWorldId,
57 }; 58 };
58 59
59 // This class represent a collection of DOM wrappers for a specific world. 60 // This class represent a collection of DOM wrappers for a specific world.
60 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { 61 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
61 public: 62 public:
62 static PassRefPtr<DOMWrapperWorld> create(int worldId = -1, int extensionGro up = -1); 63 static PassRefPtr<DOMWrapperWorld> create(int worldId = -1, int extensionGro up = -1);
63 64
64 static const int mainWorldExtensionGroup = 0; 65 static const int mainWorldExtensionGroup = 0;
66 static const int blinkInJSIsolatedWorldExtensionGroup = 1;
65 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte nsionGroup); 67 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte nsionGroup);
66 ~DOMWrapperWorld(); 68 ~DOMWrapperWorld();
67 void dispose(); 69 void dispose();
68 70
69 static bool isolatedWorldsExist() { return isolatedWorldCount; } 71 static bool isolatedWorldsExist() { return isolatedWorldCount; }
70 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds); 72 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds);
71 73
72 static DOMWrapperWorld& world(v8::Handle<v8::Context> context) 74 static DOMWrapperWorld& world(v8::Handle<v8::Context> context)
73 { 75 {
74 return ScriptState::from(context)->world(); 76 return ScriptState::from(context)->world();
75 } 77 }
76 78
77 static DOMWrapperWorld& current(v8::Isolate* isolate) 79 static DOMWrapperWorld& current(v8::Isolate* isolate)
78 { 80 {
79 if (isMainThread() && worldOfInitializingWindow) { 81 if (isMainThread() && worldOfInitializingWindow) {
80 // It's possible that current() is being called while window is bein g initialized. 82 // It's possible that current() is being called while window is bein g initialized.
81 // In order to make current() workable during the initialization pha se, 83 // In order to make current() workable during the initialization pha se,
82 // we cache the world of the initializing window on worldOfInitializ ingWindow. 84 // we cache the world of the initializing window on worldOfInitializ ingWindow.
83 // If there is no initiazing window, worldOfInitializingWindow is 0. 85 // If there is no initiazing window, worldOfInitializingWindow is 0.
84 return *worldOfInitializingWindow; 86 return *worldOfInitializingWindow;
85 } 87 }
86 return world(isolate->GetCurrentContext()); 88 return world(isolate->GetCurrentContext());
87 } 89 }
88 90
89 static DOMWrapperWorld& mainWorld(); 91 static DOMWrapperWorld& mainWorld();
92 static DOMWrapperWorld& blinkInJSWorld();
90 93
91 // Associates an isolated world (see above for description) with a security 94 // Associates an isolated world (see above for description) with a security
92 // origin. XMLHttpRequest instances used in that world will be considered 95 // origin. XMLHttpRequest instances used in that world will be considered
93 // to come from that origin, not the frame's. 96 // to come from that origin, not the frame's.
94 static void setIsolatedWorldSecurityOrigin(int worldId, PassRefPtr<SecurityO rigin>); 97 static void setIsolatedWorldSecurityOrigin(int worldId, PassRefPtr<SecurityO rigin>);
95 SecurityOrigin* isolatedWorldSecurityOrigin(); 98 SecurityOrigin* isolatedWorldSecurityOrigin();
96 99
97 // Associated an isolated world with a Content Security Policy. Resources 100 // Associated an isolated world with a Content Security Policy. Resources
98 // embedded into the main world's DOM from script executed in an isolated 101 // embedded into the main world's DOM from script executed in an isolated
99 // world should be restricted based on the isolated world's DOM, not the 102 // world should be restricted based on the isolated world's DOM, not the
100 // main world's. 103 // main world's.
101 // 104 //
102 // FIXME: Right now, resource injection simply bypasses the main world's 105 // FIXME: Right now, resource injection simply bypasses the main world's
103 // DOM. More work is necessary to allow the isolated world's policy to be 106 // DOM. More work is necessary to allow the isolated world's policy to be
104 // applied correctly. 107 // applied correctly.
105 static void setIsolatedWorldContentSecurityPolicy(int worldId, const String& policy); 108 static void setIsolatedWorldContentSecurityPolicy(int worldId, const String& policy);
106 bool isolatedWorldHasContentSecurityPolicy(); 109 bool isolatedWorldHasContentSecurityPolicy();
107 110
108 bool isMainWorld() const { return m_worldId == MainWorldId; } 111 bool isMainWorld() const { return m_worldId == MainWorldId; }
112 bool isBlinkInJSIsolatedWorld() const { return m_worldId == BlinkInJSIsolate dWorldId; }
109 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } 113 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; }
110 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; } 114 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; }
111 115
112 int worldId() const { return m_worldId; } 116 int worldId() const { return m_worldId; }
113 int extensionGroup() const { return m_extensionGroup; } 117 int extensionGroup() const { return m_extensionGroup; }
114 DOMDataStore& domDataStore() const { return *m_domDataStore; } 118 DOMDataStore& domDataStore() const { return *m_domDataStore; }
115 119
116 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) 120 static void setWorldOfInitializingWindow(DOMWrapperWorld* world)
117 { 121 {
118 ASSERT(isMainThread()); 122 ASSERT(isMainThread());
119 worldOfInitializingWindow = world; 123 worldOfInitializingWindow = world;
120 } 124 }
121 // FIXME: Remove this method once we fix crbug.com/345014. 125 // FIXME: Remove this method once we fix crbug.com/345014.
122 static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; } 126 static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; }
123 127
124 private: 128 private:
125 DOMWrapperWorld(int worldId, int extensionGroup); 129 DOMWrapperWorld(int worldId, int extensionGroup);
126 130
127 static unsigned isolatedWorldCount; 131 static unsigned isolatedWorldCount;
128 static DOMWrapperWorld* worldOfInitializingWindow; 132 static DOMWrapperWorld* worldOfInitializingWindow;
129 133
130 const int m_worldId; 134 const int m_worldId;
131 const int m_extensionGroup; 135 const int m_extensionGroup;
132 OwnPtr<DOMDataStore> m_domDataStore; 136 OwnPtr<DOMDataStore> m_domDataStore;
133 }; 137 };
134 138
135 } // namespace WebCore 139 } // namespace WebCore
136 140
137 #endif // DOMWrapperWorld_h 141 #endif // DOMWrapperWorld_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698