| OLD | NEW |
| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 const String& policy); | 126 const String& policy); |
| 127 bool IsolatedWorldHasContentSecurityPolicy(); | 127 bool IsolatedWorldHasContentSecurityPolicy(); |
| 128 | 128 |
| 129 bool IsMainWorld() const { return world_type_ == WorldType::kMain; } | 129 bool IsMainWorld() const { return world_type_ == WorldType::kMain; } |
| 130 bool IsWorkerWorld() const { return world_type_ == WorldType::kWorker; } | 130 bool IsWorkerWorld() const { return world_type_ == WorldType::kWorker; } |
| 131 bool IsIsolatedWorld() const { return world_type_ == WorldType::kIsolated; } | 131 bool IsIsolatedWorld() const { return world_type_ == WorldType::kIsolated; } |
| 132 | 132 |
| 133 int GetWorldId() const { return world_id_; } | 133 int GetWorldId() const { return world_id_; } |
| 134 DOMDataStore& DomDataStore() const { return *dom_data_store_; } | 134 DOMDataStore& DomDataStore() const { return *dom_data_store_; } |
| 135 | 135 |
| 136 public: | |
| 137 template <typename T> | 136 template <typename T> |
| 138 void RegisterDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); | 137 void RegisterDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); |
| 139 | 138 |
| 140 private: | 139 private: |
| 141 DOMWrapperWorld(v8::Isolate*, WorldType, int world_id); | 140 DOMWrapperWorld(v8::Isolate*, WorldType, int world_id); |
| 142 | 141 |
| 143 static void WeakCallbackForDOMObjectHolder( | 142 static void WeakCallbackForDOMObjectHolder( |
| 144 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); | 143 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); |
| 145 void RegisterDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); | 144 void RegisterDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); |
| 146 void UnregisterDOMObjectHolder(DOMObjectHolderBase*); | 145 void UnregisterDOMObjectHolder(DOMObjectHolderBase*); |
| 147 | 146 |
| 148 static unsigned number_of_non_main_worlds_in_main_thread_; | 147 static unsigned number_of_non_main_worlds_in_main_thread_; |
| 149 | 148 |
| 150 // Returns an identifier for a given world type. This must not be called for | 149 // Returns an identifier for a given world type. This must not be called for |
| 151 // WorldType::IsolatedWorld because an identifier for the world is given from | 150 // WorldType::IsolatedWorld because an identifier for the world is given from |
| 152 // out of DOMWrapperWorld. | 151 // out of DOMWrapperWorld. |
| 153 static int GenerateWorldIdForType(WorldType); | 152 static int GenerateWorldIdForType(WorldType); |
| 154 | 153 |
| 154 // Dissociates all wrappers in all worlds associated with |script_wrappable|. |
| 155 // |
| 156 // Do not use this function except for DOMWindow. Only DOMWindow needs to |
| 157 // dissociate wrappers from the ScriptWrappable because of the following two |
| 158 // reasons. |
| 159 // |
| 160 // Reason 1) Case of the main world |
| 161 // A DOMWindow may be collected by Blink GC *before* V8 GC collects the |
| 162 // wrapper because the wrapper object associated with a DOMWindow is a global |
| 163 // proxy, which remains after navigations. We don't want V8 GC to reset the |
| 164 // weak persistent handle to a wrapper within the DOMWindow |
| 165 // (ScriptWrappable::main_world_wrapper_) *after* Blink GC collects the |
| 166 // DOMWindow because it's use-after-free. Thus, we need to dissociate the |
| 167 // wrapper in advance. |
| 168 // |
| 169 // Reason 2) Case of isolated worlds |
| 170 // As same, a DOMWindow may be collected before the wrapper gets collected. |
| 171 // A DOMWrapperMap supports mapping from ScriptWrappable* to v8::Global<T>, |
| 172 // and we don't want to leave an entry of an already-dead DOMWindow* to the |
| 173 // persistent handle for the global proxy object, especially considering that |
| 174 // the address to the already-dead DOMWindow* may be re-used. |
| 175 friend class DOMWindow; |
| 176 static void DissociateDOMWindowWrappersInAllWorlds(ScriptWrappable*); |
| 177 |
| 155 const WorldType world_type_; | 178 const WorldType world_type_; |
| 156 const int world_id_; | 179 const int world_id_; |
| 157 std::unique_ptr<DOMDataStore> dom_data_store_; | 180 std::unique_ptr<DOMDataStore> dom_data_store_; |
| 158 HashSet<std::unique_ptr<DOMObjectHolderBase>> dom_object_holders_; | 181 HashSet<std::unique_ptr<DOMObjectHolderBase>> dom_object_holders_; |
| 159 }; | 182 }; |
| 160 | 183 |
| 161 } // namespace blink | 184 } // namespace blink |
| 162 | 185 |
| 163 #endif // DOMWrapperWorld_h | 186 #endif // DOMWrapperWorld_h |
| OLD | NEW |