| 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 "components/guest_view/browser/guest_view_manager.h" | 9 #include "components/guest_view/browser/guest_view_manager.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 embedder_routing_id, |
| 113 int view_instance_id, | 113 int view_instance_id, |
| 114 const HostID& host_id, | 114 const HostID& host_id, |
| 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 DeclarativeUserScriptManager::Get(browser_context_) |
| 121 ->declarative_user_script_manager() | |
| 122 ->GetDeclarativeUserScriptMasterByID(host_id); | 121 ->GetDeclarativeUserScriptMasterByID(host_id); |
| 123 DCHECK(master); | 122 DCHECK(master); |
| 124 | 123 |
| 125 // We need to update WebViewRenderState in the IO thread if the guest exists. | 124 // We need to update WebViewRenderState in the IO thread if the guest exists. |
| 126 std::set<int> ids_to_add; | 125 std::set<int> ids_to_add; |
| 127 | 126 |
| 128 int embedder_process_id = | 127 int embedder_process_id = |
| 129 embedder_web_contents->GetRenderProcessHost()->GetID(); | 128 embedder_web_contents->GetRenderProcessHost()->GetID(); |
| 130 GuestMapKey key = std::pair<int, int>(embedder_process_id, view_instance_id); | 129 GuestMapKey key = std::pair<int, int>(embedder_process_id, view_instance_id); |
| 131 GuestContentScriptMap::iterator iter = guest_content_script_map_.find(key); | 130 GuestContentScriptMap::iterator iter = guest_content_script_map_.find(key); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 202 |
| 204 int embedder_process_id = | 203 int embedder_process_id = |
| 205 embedder_web_contents->GetRenderProcessHost()->GetID(); | 204 embedder_web_contents->GetRenderProcessHost()->GetID(); |
| 206 GuestMapKey key = std::pair<int, int>(embedder_process_id, view_instance_id); | 205 GuestMapKey key = std::pair<int, int>(embedder_process_id, view_instance_id); |
| 207 GuestContentScriptMap::iterator script_map_iter = | 206 GuestContentScriptMap::iterator script_map_iter = |
| 208 guest_content_script_map_.find(key); | 207 guest_content_script_map_.find(key); |
| 209 if (script_map_iter == guest_content_script_map_.end()) | 208 if (script_map_iter == guest_content_script_map_.end()) |
| 210 return; | 209 return; |
| 211 | 210 |
| 212 DeclarativeUserScriptMaster* master = | 211 DeclarativeUserScriptMaster* master = |
| 213 ExtensionSystem::Get(browser_context_) | 212 DeclarativeUserScriptManager::Get(browser_context_) |
| 214 ->declarative_user_script_manager() | |
| 215 ->GetDeclarativeUserScriptMasterByID(host_id); | 213 ->GetDeclarativeUserScriptMasterByID(host_id); |
| 216 CHECK(master); | 214 CHECK(master); |
| 217 | 215 |
| 218 // We need to update WebViewRenderState in the IO thread if the guest exists. | 216 // We need to update WebViewRenderState in the IO thread if the guest exists. |
| 219 std::set<int> ids_to_delete; | 217 std::set<int> ids_to_delete; |
| 220 std::set<UserScript> scripts_to_delete; | 218 std::set<UserScript> scripts_to_delete; |
| 221 | 219 |
| 222 // Step 1: removes content scripts from |master| and updates | 220 // Step 1: removes content scripts from |master| and updates |
| 223 // |guest_content_script_map_|. | 221 // |guest_content_script_map_|. |
| 224 std::map<std::string, UserScript>& map = script_map_iter->second; | 222 std::map<std::string, UserScript>& map = script_map_iter->second; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 306 |
| 309 void WebViewContentScriptManager::RunCallbacksIfReady() { | 307 void WebViewContentScriptManager::RunCallbacksIfReady() { |
| 310 if (user_script_loader_observer_.IsObservingSources()) | 308 if (user_script_loader_observer_.IsObservingSources()) |
| 311 return; | 309 return; |
| 312 for (auto& callback : pending_scripts_loading_callbacks_) | 310 for (auto& callback : pending_scripts_loading_callbacks_) |
| 313 callback.Run(); | 311 callback.Run(); |
| 314 pending_scripts_loading_callbacks_.clear(); | 312 pending_scripts_loading_callbacks_.clear(); |
| 315 } | 313 } |
| 316 | 314 |
| 317 } // namespace extensions | 315 } // namespace extensions |
| OLD | NEW |