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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if (!manager) { | 102 if (!manager) { |
103 manager = new WebViewContentScriptManager(browser_context); | 103 manager = new WebViewContentScriptManager(browser_context); |
104 browser_context->SetUserData(webview::kWebViewContentScriptManagerKeyName, | 104 browser_context->SetUserData(webview::kWebViewContentScriptManagerKeyName, |
105 manager); | 105 manager); |
106 } | 106 } |
107 return manager; | 107 return manager; |
108 } | 108 } |
109 | 109 |
110 void WebViewContentScriptManager::AddContentScripts( | 110 void WebViewContentScriptManager::AddContentScripts( |
111 content::WebContents* embedder_web_contents, | 111 content::WebContents* embedder_web_contents, |
| 112 int embedder_routing_id, |
112 int view_instance_id, | 113 int view_instance_id, |
113 const HostID& host_id, | 114 const HostID& host_id, |
114 const std::set<UserScript>& scripts) { | 115 const std::set<UserScript>& scripts) { |
115 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 116 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
116 DCHECK(embedder_web_contents); | 117 DCHECK(embedder_web_contents); |
117 | 118 |
118 DeclarativeUserScriptMaster* master = | 119 DeclarativeUserScriptMaster* master = |
119 ExtensionSystem::Get(browser_context_) | 120 ExtensionSystem::Get(browser_context_) |
120 ->declarative_user_script_manager() | 121 ->declarative_user_script_manager() |
121 ->GetDeclarativeUserScriptMasterByID(host_id); | 122 ->GetDeclarativeUserScriptMasterByID(host_id); |
(...skipping 24 matching lines...) Expand all Loading... |
146 // script first, and insert the new one. | 147 // script first, and insert the new one. |
147 if (map_iter != map.end()) { | 148 if (map_iter != map.end()) { |
148 master->RemoveScript(map_iter->second); | 149 master->RemoveScript(map_iter->second); |
149 map.erase(map_iter); | 150 map.erase(map_iter); |
150 } | 151 } |
151 map.insert(std::pair<std::string, UserScript>(script.name(), script)); | 152 map.insert(std::pair<std::string, UserScript>(script.name(), script)); |
152 ids_to_add.insert(script.id()); | 153 ids_to_add.insert(script.id()); |
153 } | 154 } |
154 | 155 |
155 // Step 3: adds new scripts to the master. | 156 // Step 3: adds new scripts to the master. |
156 master->AddScripts(scripts); | 157 master->AddScripts(scripts, embedder_process_id, embedder_routing_id); |
157 | 158 |
158 // Step 4: creates owner web contents observer for the given | 159 // Step 4: creates owner web contents observer for the given |
159 // |embedder_web_contents| if it doesn't exist. | 160 // |embedder_web_contents| if it doesn't exist. |
160 auto observer_iter = | 161 auto observer_iter = |
161 owner_web_contents_observer_map_.find(embedder_web_contents); | 162 owner_web_contents_observer_map_.find(embedder_web_contents); |
162 if (observer_iter == owner_web_contents_observer_map_.end()) { | 163 if (observer_iter == owner_web_contents_observer_map_.end()) { |
163 linked_ptr<OwnerWebContentsObserver> observer( | 164 linked_ptr<OwnerWebContentsObserver> observer( |
164 new OwnerWebContentsObserver(embedder_web_contents, host_id, this)); | 165 new OwnerWebContentsObserver(embedder_web_contents, host_id, this)); |
165 observer->add_view_instance_id(view_instance_id); | 166 observer->add_view_instance_id(view_instance_id); |
166 owner_web_contents_observer_map_[embedder_web_contents] = observer; | 167 owner_web_contents_observer_map_[embedder_web_contents] = observer; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 if (iter == guest_content_script_map_.end()) | 261 if (iter == guest_content_script_map_.end()) |
261 return ids; | 262 return ids; |
262 const ContentScriptMap& map = iter->second; | 263 const ContentScriptMap& map = iter->second; |
263 for (const auto& pair : map) | 264 for (const auto& pair : map) |
264 ids.insert(pair.second.id()); | 265 ids.insert(pair.second.id()); |
265 | 266 |
266 return ids; | 267 return ids; |
267 } | 268 } |
268 | 269 |
269 } // namespace extensions | 270 } // namespace extensions |
OLD | NEW |