OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager
.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager
.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/linked_ptr.h" | 8 #include "base/memory/linked_ptr.h" |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 const std::set<UserScript>& scripts) { | 115 const std::set<UserScript>& scripts) { |
116 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 116 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
117 DCHECK(embedder_web_contents); | 117 DCHECK(embedder_web_contents); |
118 | 118 |
119 DeclarativeUserScriptMaster* master = | 119 DeclarativeUserScriptMaster* master = |
120 ExtensionSystem::Get(browser_context_) | 120 ExtensionSystem::Get(browser_context_) |
121 ->declarative_user_script_manager() | 121 ->declarative_user_script_manager() |
122 ->GetDeclarativeUserScriptMasterByID(host_id); | 122 ->GetDeclarativeUserScriptMasterByID(host_id); |
123 DCHECK(master); | 123 DCHECK(master); |
124 | 124 |
| 125 bool is_incognito = browser_context_->IsOffTheRecord(); |
| 126 |
125 // We need to update WebViewRenderState in the IO thread if the guest exists. | 127 // We need to update WebViewRenderState in the IO thread if the guest exists. |
126 std::set<int> ids_to_add; | 128 std::set<int> ids_to_add; |
127 | 129 |
128 int embedder_process_id = | 130 int embedder_process_id = |
129 embedder_web_contents->GetRenderProcessHost()->GetID(); | 131 embedder_web_contents->GetRenderProcessHost()->GetID(); |
130 GuestMapKey key = std::pair<int, int>(embedder_process_id, view_instance_id); | 132 GuestMapKey key = std::pair<int, int>(embedder_process_id, view_instance_id); |
131 GuestContentScriptMap::iterator iter = guest_content_script_map_.find(key); | 133 GuestContentScriptMap::iterator iter = guest_content_script_map_.find(key); |
132 | 134 |
133 // Step 1: finds the entry in guest_content_script_map_ by the given |key|. | 135 // Step 1: finds the entry in guest_content_script_map_ by the given |key|. |
134 // If there isn't any content script added for the given guest yet, insert an | 136 // If there isn't any content script added for the given guest yet, insert an |
(...skipping 12 matching lines...) Expand all Loading... |
147 // script first, and insert the new one. | 149 // script first, and insert the new one. |
148 if (map_iter != map.end()) { | 150 if (map_iter != map.end()) { |
149 master->RemoveScript(map_iter->second); | 151 master->RemoveScript(map_iter->second); |
150 map.erase(map_iter); | 152 map.erase(map_iter); |
151 } | 153 } |
152 map.insert(std::pair<std::string, UserScript>(script.name(), script)); | 154 map.insert(std::pair<std::string, UserScript>(script.name(), script)); |
153 ids_to_add.insert(script.id()); | 155 ids_to_add.insert(script.id()); |
154 } | 156 } |
155 | 157 |
156 // Step 3: adds new scripts to the master. | 158 // Step 3: adds new scripts to the master. |
157 master->AddScripts(scripts, embedder_process_id, embedder_routing_id); | 159 master->AddScripts( |
| 160 scripts, embedder_process_id, embedder_routing_id, is_incognito); |
158 | 161 |
159 // Step 4: creates owner web contents observer for the given | 162 // Step 4: creates owner web contents observer for the given |
160 // |embedder_web_contents| if it doesn't exist. | 163 // |embedder_web_contents| if it doesn't exist. |
161 auto observer_iter = | 164 auto observer_iter = |
162 owner_web_contents_observer_map_.find(embedder_web_contents); | 165 owner_web_contents_observer_map_.find(embedder_web_contents); |
163 if (observer_iter == owner_web_contents_observer_map_.end()) { | 166 if (observer_iter == owner_web_contents_observer_map_.end()) { |
164 linked_ptr<OwnerWebContentsObserver> observer( | 167 linked_ptr<OwnerWebContentsObserver> observer( |
165 new OwnerWebContentsObserver(embedder_web_contents, host_id, this)); | 168 new OwnerWebContentsObserver(embedder_web_contents, host_id, this)); |
166 observer->add_view_instance_id(view_instance_id); | 169 observer->add_view_instance_id(view_instance_id); |
167 owner_web_contents_observer_map_[embedder_web_contents] = observer; | 170 owner_web_contents_observer_map_[embedder_web_contents] = observer; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (iter == guest_content_script_map_.end()) | 264 if (iter == guest_content_script_map_.end()) |
262 return ids; | 265 return ids; |
263 const ContentScriptMap& map = iter->second; | 266 const ContentScriptMap& map = iter->second; |
264 for (const auto& pair : map) | 267 for (const auto& pair : map) |
265 ids.insert(pair.second.id()); | 268 ids.insert(pair.second.id()); |
266 | 269 |
267 return ids; | 270 return ids; |
268 } | 271 } |
269 | 272 |
270 } // namespace extensions | 273 } // namespace extensions |
OLD | NEW |