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

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

Issue 2633253002: Split content script injections into multiple tasks (Closed)
Patch Set: rebase Created 3 years, 9 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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "content/public/common/browser_side_navigation_policy.h" 16 #include "content/public/common/browser_side_navigation_policy.h"
17 #include "content/public/renderer/render_frame.h" 17 #include "content/public/renderer/render_frame.h"
18 #include "content/public/renderer/render_frame_observer.h" 18 #include "content/public/renderer/render_frame_observer.h"
19 #include "content/public/renderer/render_thread.h" 19 #include "content/public/renderer/render_thread.h"
20 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
21 #include "extensions/common/extension_messages.h" 21 #include "extensions/common/extension_messages.h"
22 #include "extensions/common/extension_set.h" 22 #include "extensions/common/extension_set.h"
23 #include "extensions/common/feature_switch.h"
23 #include "extensions/renderer/extension_frame_helper.h" 24 #include "extensions/renderer/extension_frame_helper.h"
24 #include "extensions/renderer/extension_injection_host.h" 25 #include "extensions/renderer/extension_injection_host.h"
25 #include "extensions/renderer/programmatic_script_injector.h" 26 #include "extensions/renderer/programmatic_script_injector.h"
26 #include "extensions/renderer/renderer_extension_registry.h" 27 #include "extensions/renderer/renderer_extension_registry.h"
27 #include "extensions/renderer/script_injection.h" 28 #include "extensions/renderer/script_injection.h"
28 #include "extensions/renderer/scripts_run_info.h" 29 #include "extensions/renderer/scripts_run_info.h"
29 #include "extensions/renderer/web_ui_injection_host.h" 30 #include "extensions/renderer/web_ui_injection_host.h"
30 #include "ipc/ipc_message_macros.h" 31 #include "ipc/ipc_message_macros.h"
31 #include "third_party/WebKit/public/platform/WebURLError.h" 32 #include "third_party/WebKit/public/platform/WebURLError.h"
32 #include "third_party/WebKit/public/web/WebDocument.h" 33 #include "third_party/WebKit/public/web/WebDocument.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // whereas DidFinishLoad corresponds to completing the document and all 183 // whereas DidFinishLoad corresponds to completing the document and all
183 // subresources' load. We don't want to hold up script injection for a 184 // subresources' load. We don't want to hold up script injection for a
184 // particularly slow subresource, so we set a delayed task from here - but if 185 // particularly slow subresource, so we set a delayed task from here - but if
185 // we finish everything before that point (i.e., DidFinishLoad() is 186 // we finish everything before that point (i.e., DidFinishLoad() is
186 // triggered), then there's no reason to keep waiting. 187 // triggered), then there's no reason to keep waiting.
187 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 188 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
188 FROM_HERE, 189 FROM_HERE,
189 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle, 190 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
190 weak_factory_.GetWeakPtr()), 191 weak_factory_.GetWeakPtr()),
191 base::TimeDelta::FromMilliseconds(kScriptIdleTimeoutInMs)); 192 base::TimeDelta::FromMilliseconds(kScriptIdleTimeoutInMs));
193
194 if (FeatureSwitch::yield_between_content_script_runs()->IsEnabled()) {
195 ExtensionFrameHelper::Get(render_frame())
196 ->ScheduleAtDocumentIdle(
197 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
198 weak_factory_.GetWeakPtr()));
199 }
192 } 200 }
193 201
194 void ScriptInjectionManager::RFOHelper::DidFinishLoad() { 202 void ScriptInjectionManager::RFOHelper::DidFinishLoad() {
195 DCHECK(content::RenderThread::Get()); 203 DCHECK(content::RenderThread::Get());
196 // Ensure that we don't block any UI progress by running scripts. 204 if (!FeatureSwitch::yield_between_content_script_runs()->IsEnabled()) {
197 base::ThreadTaskRunnerHandle::Get()->PostTask( 205 // Ensure that we don't block any UI progress by running scripts.
198 FROM_HERE, 206 base::ThreadTaskRunnerHandle::Get()->PostTask(
199 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle, 207 FROM_HERE, base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
200 weak_factory_.GetWeakPtr())); 208 weak_factory_.GetWeakPtr()));
209 }
201 } 210 }
202 211
203 void ScriptInjectionManager::RFOHelper::FrameDetached() { 212 void ScriptInjectionManager::RFOHelper::FrameDetached() {
204 // The frame is closing - invalidate. 213 // The frame is closing - invalidate.
205 InvalidateAndResetFrame(); 214 InvalidateAndResetFrame();
206 } 215 }
207 216
208 void ScriptInjectionManager::RFOHelper::OnDestruct() { 217 void ScriptInjectionManager::RFOHelper::OnDestruct() {
209 manager_->RemoveObserver(this); 218 manager_->RemoveObserver(this);
210 } 219 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 ScriptsRunInfo scripts_run_info(injection->render_frame(), 523 ScriptsRunInfo scripts_run_info(injection->render_frame(),
515 UserScript::RUN_DEFERRED); 524 UserScript::RUN_DEFERRED);
516 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( 525 ScriptInjection::InjectionResult res = injection->OnPermissionGranted(
517 &scripts_run_info); 526 &scripts_run_info);
518 if (res == ScriptInjection::INJECTION_BLOCKED) 527 if (res == ScriptInjection::INJECTION_BLOCKED)
519 running_injections_.push_back(std::move(injection)); 528 running_injections_.push_back(std::move(injection));
520 scripts_run_info.LogRun(activity_logging_enabled_); 529 scripts_run_info.LogRun(activity_logging_enabled_);
521 } 530 }
522 531
523 } // namespace extensions 532 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698