| 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/web_ui_user_script_loader.h" | 5 #include "extensions/browser/web_ui_user_script_loader.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 for (const std::unique_ptr<extensions::UserScript>& script : | 79 for (const std::unique_ptr<extensions::UserScript>& script : |
| 80 *user_scripts_cache_) { | 80 *user_scripts_cache_) { |
| 81 if (added_script_ids.count(script->id()) == 0) | 81 if (added_script_ids.count(script->id()) == 0) |
| 82 continue; | 82 continue; |
| 83 | 83 |
| 84 auto iter = script_render_info_map_.find(script->id()); | 84 auto iter = script_render_info_map_.find(script->id()); |
| 85 DCHECK(iter != script_render_info_map_.end()); | 85 DCHECK(iter != script_render_info_map_.end()); |
| 86 int render_process_id = iter->second.render_process_id; | 86 int render_process_id = iter->second.render_process_id; |
| 87 int render_frame_id = iter->second.render_frame_id; | 87 int render_frame_id = iter->second.render_frame_id; |
| 88 | 88 |
| 89 content::BrowserContext* browser_context = | 89 content::RenderProcessHost* render_process_host = |
| 90 content::RenderProcessHost::FromID(render_process_id) | 90 content::RenderProcessHost::FromID(render_process_id); |
| 91 ->GetBrowserContext(); | |
| 92 | 91 |
| 93 CreateWebUIURLFetchers(script->js_scripts(), browser_context, | 92 // LoadScripts may not be synchronous with AddScripts. Hence the |
| 94 render_process_id, render_frame_id); | 93 // |render_process_host| may no longer be alive. This should fix |
| 95 CreateWebUIURLFetchers(script->css_scripts(), browser_context, | 94 // crbug.com/720331. TODO(karandeepb): Investigate if there are any side |
| 96 render_process_id, render_frame_id); | 95 // effects of the render process host no longer being alive and add a test. |
| 96 if (render_process_host) { |
| 97 content::BrowserContext* browser_context = |
| 98 render_process_host->GetBrowserContext(); |
| 99 |
| 100 CreateWebUIURLFetchers(script->js_scripts(), browser_context, |
| 101 render_process_id, render_frame_id); |
| 102 CreateWebUIURLFetchers(script->css_scripts(), browser_context, |
| 103 render_process_id, render_frame_id); |
| 104 } |
| 97 | 105 |
| 98 script_render_info_map_.erase(script->id()); | 106 script_render_info_map_.erase(script->id()); |
| 99 } | 107 } |
| 100 | 108 |
| 101 // If no fetch is needed, call OnWebUIURLFetchComplete directly. | 109 // If no fetch is needed, call OnWebUIURLFetchComplete directly. |
| 102 if (fetchers_.empty()) { | 110 if (fetchers_.empty()) { |
| 103 OnWebUIURLFetchComplete(); | 111 OnWebUIURLFetchComplete(); |
| 104 return; | 112 return; |
| 105 } | 113 } |
| 106 for (const auto& fetcher : fetchers_) | 114 for (const auto& fetcher : fetchers_) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 164 } |
| 157 | 165 |
| 158 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { | 166 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { |
| 159 content::BrowserThread::PostTask( | 167 content::BrowserThread::PostTask( |
| 160 content::BrowserThread::FILE, FROM_HERE, | 168 content::BrowserThread::FILE, FROM_HERE, |
| 161 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), | 169 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), |
| 162 scripts_loaded_callback_)); | 170 scripts_loaded_callback_)); |
| 163 scripts_loaded_callback_.Reset(); | 171 scripts_loaded_callback_.Reset(); |
| 164 user_scripts_cache_.reset(); | 172 user_scripts_cache_.reset(); |
| 165 } | 173 } |
| OLD | NEW |