OLD | NEW |
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.h" | 5 #include "extensions/renderer/script_injection.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 // static | 113 // static |
114 void ScriptInjection::RemoveIsolatedWorld(const std::string& host_id) { | 114 void ScriptInjection::RemoveIsolatedWorld(const std::string& host_id) { |
115 g_isolated_worlds.Get().erase(host_id); | 115 g_isolated_worlds.Get().erase(host_id); |
116 } | 116 } |
117 | 117 |
118 ScriptInjection::ScriptInjection( | 118 ScriptInjection::ScriptInjection( |
119 std::unique_ptr<ScriptInjector> injector, | 119 std::unique_ptr<ScriptInjector> injector, |
120 content::RenderFrame* render_frame, | 120 content::RenderFrame* render_frame, |
121 std::unique_ptr<const InjectionHost> injection_host, | 121 std::unique_ptr<const InjectionHost> injection_host, |
122 UserScript::RunLocation run_location) | 122 UserScript::RunLocation run_location, |
| 123 bool log_activity) |
123 : injector_(std::move(injector)), | 124 : injector_(std::move(injector)), |
124 render_frame_(render_frame), | 125 render_frame_(render_frame), |
125 injection_host_(std::move(injection_host)), | 126 injection_host_(std::move(injection_host)), |
126 run_location_(run_location), | 127 run_location_(run_location), |
127 request_id_(kInvalidRequestId), | 128 request_id_(kInvalidRequestId), |
128 complete_(false), | 129 complete_(false), |
129 did_inject_js_(false), | 130 did_inject_js_(false), |
| 131 log_activity_(log_activity), |
130 frame_watcher_(new FrameWatcher(render_frame, this)), | 132 frame_watcher_(new FrameWatcher(render_frame, this)), |
131 weak_ptr_factory_(this) { | 133 weak_ptr_factory_(this) { |
132 CHECK(injection_host_.get()); | 134 CHECK(injection_host_.get()); |
133 } | 135 } |
134 | 136 |
135 ScriptInjection::~ScriptInjection() { | 137 ScriptInjection::~ScriptInjection() { |
136 if (!complete_) | 138 if (!complete_) |
137 NotifyWillNotInject(ScriptInjector::WONT_INJECT); | 139 NotifyWillNotInject(ScriptInjector::WONT_INJECT); |
138 } | 140 } |
139 | 141 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 : GetIsolatedWorldIdForInstance(injection_host_.get(), | 248 : GetIsolatedWorldIdForInstance(injection_host_.get(), |
247 web_frame); | 249 web_frame); |
248 bool is_user_gesture = injector_->IsUserGesture(); | 250 bool is_user_gesture = injector_->IsUserGesture(); |
249 | 251 |
250 std::unique_ptr<blink::WebScriptExecutionCallback> callback( | 252 std::unique_ptr<blink::WebScriptExecutionCallback> callback( |
251 new ScriptInjectionCallback( | 253 new ScriptInjectionCallback( |
252 base::Bind(&ScriptInjection::OnJsInjectionCompleted, | 254 base::Bind(&ScriptInjection::OnJsInjectionCompleted, |
253 weak_ptr_factory_.GetWeakPtr()))); | 255 weak_ptr_factory_.GetWeakPtr()))); |
254 | 256 |
255 base::ElapsedTimer exec_timer; | 257 base::ElapsedTimer exec_timer; |
256 if (injection_host_->id().type() == HostID::EXTENSIONS) | 258 if (injection_host_->id().type() == HostID::EXTENSIONS && log_activity_) |
257 DOMActivityLogger::AttachToWorld(world_id, injection_host_->id().id()); | 259 DOMActivityLogger::AttachToWorld(world_id, injection_host_->id().id()); |
258 if (in_main_world) { | 260 if (in_main_world) { |
259 // We only inject in the main world for javascript: urls. | 261 // We only inject in the main world for javascript: urls. |
260 DCHECK_EQ(1u, sources.size()); | 262 DCHECK_EQ(1u, sources.size()); |
261 | 263 |
262 web_frame->requestExecuteScriptAndReturnValue(sources.front(), | 264 web_frame->requestExecuteScriptAndReturnValue(sources.front(), |
263 is_user_gesture, | 265 is_user_gesture, |
264 callback.release()); | 266 callback.release()); |
265 } else { | 267 } else { |
266 web_frame->requestExecuteScriptInIsolatedWorld( | 268 web_frame->requestExecuteScriptInIsolatedWorld( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 313 |
312 void ScriptInjection::InjectCss() { | 314 void ScriptInjection::InjectCss() { |
313 std::vector<std::string> css_sources = | 315 std::vector<std::string> css_sources = |
314 injector_->GetCssSources(run_location_); | 316 injector_->GetCssSources(run_location_); |
315 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | 317 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); |
316 for (const std::string& css : css_sources) | 318 for (const std::string& css : css_sources) |
317 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css)); | 319 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css)); |
318 } | 320 } |
319 | 321 |
320 } // namespace extensions | 322 } // namespace extensions |
OLD | NEW |