Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: extensions/renderer/script_injection_manager.cc

Issue 1642283002: Deal with frame removal by content scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ImageDocument: Account for detach in DOM mutations Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer/script_injection_manager.h" 5 #include "extensions/renderer/script_injection_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // This assumption is verified in the checkDOMContentLoadedEvent subtest of 155 // This assumption is verified in the checkDOMContentLoadedEvent subtest of
156 // ExecuteScriptApiTest.FrameWithHttp204 (browser_tests). 156 // ExecuteScriptApiTest.FrameWithHttp204 (browser_tests).
157 InvalidateAndResetFrame(); 157 InvalidateAndResetFrame();
158 should_run_idle_ = false; 158 should_run_idle_ = false;
159 manager_->frame_statuses_[render_frame()] = UserScript::DOCUMENT_IDLE; 159 manager_->frame_statuses_[render_frame()] = UserScript::DOCUMENT_IDLE;
160 } 160 }
161 } 161 }
162 162
163 void ScriptInjectionManager::RFOHelper::DidFinishDocumentLoad() { 163 void ScriptInjectionManager::RFOHelper::DidFinishDocumentLoad() {
164 DCHECK(content::RenderThread::Get()); 164 DCHECK(content::RenderThread::Get());
165 base::WeakPtr<RFOHelper> weak_self = weak_factory_.GetWeakPtr();
165 manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_END); 166 manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_END);
167 if (!weak_self.get())
168 return;
166 // We try to run idle in two places: here and DidFinishLoad. 169 // We try to run idle in two places: here and DidFinishLoad.
167 // DidFinishDocumentLoad() corresponds to completing the document's load, 170 // DidFinishDocumentLoad() corresponds to completing the document's load,
168 // whereas DidFinishLoad corresponds to completing the document and all 171 // whereas DidFinishLoad corresponds to completing the document and all
169 // subresources' load. We don't want to hold up script injection for a 172 // subresources' load. We don't want to hold up script injection for a
170 // particularly slow subresource, so we set a delayed task from here - but if 173 // particularly slow subresource, so we set a delayed task from here - but if
171 // we finish everything before that point (i.e., DidFinishLoad() is 174 // we finish everything before that point (i.e., DidFinishLoad() is
172 // triggered), then there's no reason to keep waiting. 175 // triggered), then there's no reason to keep waiting.
173 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 176 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
174 FROM_HERE, 177 FROM_HERE,
175 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle, 178 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle, weak_self),
176 weak_factory_.GetWeakPtr()),
177 base::TimeDelta::FromMilliseconds(kScriptIdleTimeoutInMs)); 179 base::TimeDelta::FromMilliseconds(kScriptIdleTimeoutInMs));
178 } 180 }
179 181
180 void ScriptInjectionManager::RFOHelper::DidFinishLoad() { 182 void ScriptInjectionManager::RFOHelper::DidFinishLoad() {
181 DCHECK(content::RenderThread::Get()); 183 DCHECK(content::RenderThread::Get());
182 // Ensure that we don't block any UI progress by running scripts. 184 // Ensure that we don't block any UI progress by running scripts.
183 base::ThreadTaskRunnerHandle::Get()->PostTask( 185 base::ThreadTaskRunnerHandle::Get()->PostTask(
184 FROM_HERE, 186 FROM_HERE,
185 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle, 187 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
186 weak_factory_.GetWeakPtr())); 188 weak_factory_.GetWeakPtr()));
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 ScriptsRunInfo scripts_run_info(injection->render_frame(), 493 ScriptsRunInfo scripts_run_info(injection->render_frame(),
492 UserScript::RUN_DEFERRED); 494 UserScript::RUN_DEFERRED);
493 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( 495 ScriptInjection::InjectionResult res = injection->OnPermissionGranted(
494 &scripts_run_info); 496 &scripts_run_info);
495 if (res == ScriptInjection::INJECTION_BLOCKED) 497 if (res == ScriptInjection::INJECTION_BLOCKED)
496 running_injections_.push_back(std::move(injection)); 498 running_injections_.push_back(std::move(injection));
497 scripts_run_info.LogRun(); 499 scripts_run_info.LogRun();
498 } 500 }
499 501
500 } // namespace extensions 502 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698