Chromium Code Reviews| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 explicit TimedScriptInjectionCallback( | 84 explicit TimedScriptInjectionCallback( |
| 85 base::WeakPtr<ScriptInjection> injection) | 85 base::WeakPtr<ScriptInjection> injection) |
| 86 : ScriptInjectionCallback( | 86 : ScriptInjectionCallback( |
| 87 base::Bind(&TimedScriptInjectionCallback::OnCompleted, | 87 base::Bind(&TimedScriptInjectionCallback::OnCompleted, |
| 88 base::Unretained(this))), | 88 base::Unretained(this))), |
| 89 injection_(injection) {} | 89 injection_(injection) {} |
| 90 ~TimedScriptInjectionCallback() override {} | 90 ~TimedScriptInjectionCallback() override {} |
| 91 | 91 |
| 92 void OnCompleted(const std::vector<v8::Local<v8::Value>>& result) { | 92 void OnCompleted(const std::vector<v8::Local<v8::Value>>& result) { |
| 93 if (injection_) { | 93 if (injection_) { |
| 94 base::TimeDelta elapsed = base::TimeTicks::Now() - start_time_; | 94 base::Optional<base::TimeDelta> elapsed; |
| 95 if (!start_time_.is_null()) | |
|
Devlin
2017/04/06 21:32:08
Can we document this, either here or in OnJsInject
Kunihiko Sakamoto
2017/04/07 01:52:50
Done.
| |
| 96 elapsed = base::TimeTicks::Now() - start_time_; | |
| 95 injection_->OnJsInjectionCompleted(result, elapsed); | 97 injection_->OnJsInjectionCompleted(result, elapsed); |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 | 100 |
| 99 void willExecute() override { start_time_ = base::TimeTicks::Now(); } | 101 void willExecute() override { start_time_ = base::TimeTicks::Now(); } |
| 100 | 102 |
| 101 private: | 103 private: |
| 102 base::WeakPtr<ScriptInjection> injection_; | 104 base::WeakPtr<ScriptInjection> injection_; |
| 103 base::TimeTicks start_time_; | 105 base::TimeTicks start_time_; |
| 104 }; | 106 }; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 option = blink::WebLocalFrame::Synchronous; | 315 option = blink::WebLocalFrame::Synchronous; |
| 314 } | 316 } |
| 315 web_frame->requestExecuteScriptInIsolatedWorld( | 317 web_frame->requestExecuteScriptInIsolatedWorld( |
| 316 world_id, &sources.front(), sources.size(), is_user_gesture, option, | 318 world_id, &sources.front(), sources.size(), is_user_gesture, option, |
| 317 callback.release()); | 319 callback.release()); |
| 318 } | 320 } |
| 319 } | 321 } |
| 320 | 322 |
| 321 void ScriptInjection::OnJsInjectionCompleted( | 323 void ScriptInjection::OnJsInjectionCompleted( |
| 322 const std::vector<v8::Local<v8::Value>>& results, | 324 const std::vector<v8::Local<v8::Value>>& results, |
| 323 base::TimeDelta elapsed) { | 325 base::Optional<base::TimeDelta> elapsed) { |
| 324 DCHECK(!did_inject_js_); | 326 DCHECK(!did_inject_js_); |
| 325 | 327 |
| 326 if (injection_host_->id().type() == HostID::EXTENSIONS) { | 328 if (injection_host_->id().type() == HostID::EXTENSIONS && |
| 327 UMA_HISTOGRAM_TIMES("Extensions.InjectedScriptExecutionTime", elapsed); | 329 elapsed.has_value()) { |
|
Devlin
2017/04/06 21:32:08
nit: base::Optional has an operator bool(), so thi
Kunihiko Sakamoto
2017/04/07 01:52:49
Done.
| |
| 330 UMA_HISTOGRAM_TIMES("Extensions.InjectedScriptExecutionTime", | |
| 331 elapsed.value()); | |
|
Devlin
2017/04/06 21:32:08
optional nit: I'd slightly prefer *elapsed here (a
Kunihiko Sakamoto
2017/04/07 01:52:49
Done.
| |
| 328 switch (run_location_) { | 332 switch (run_location_) { |
| 329 case UserScript::DOCUMENT_START: | 333 case UserScript::DOCUMENT_START: |
| 330 UMA_HISTOGRAM_TIMES( | 334 UMA_HISTOGRAM_TIMES( |
| 331 "Extensions.InjectedScriptExecutionTime.DocumentStart", elapsed); | 335 "Extensions.InjectedScriptExecutionTime.DocumentStart", |
| 336 elapsed.value()); | |
| 332 break; | 337 break; |
| 333 case UserScript::DOCUMENT_END: | 338 case UserScript::DOCUMENT_END: |
| 334 UMA_HISTOGRAM_TIMES( | 339 UMA_HISTOGRAM_TIMES( |
| 335 "Extensions.InjectedScriptExecutionTime.DocumentEnd", elapsed); | 340 "Extensions.InjectedScriptExecutionTime.DocumentEnd", |
| 341 elapsed.value()); | |
| 336 break; | 342 break; |
| 337 case UserScript::DOCUMENT_IDLE: | 343 case UserScript::DOCUMENT_IDLE: |
| 338 UMA_HISTOGRAM_TIMES( | 344 UMA_HISTOGRAM_TIMES( |
| 339 "Extensions.InjectedScriptExecutionTime.DocumentIdle", elapsed); | 345 "Extensions.InjectedScriptExecutionTime.DocumentIdle", |
| 346 elapsed.value()); | |
| 340 break; | 347 break; |
| 341 default: | 348 default: |
| 342 break; | 349 break; |
| 343 } | 350 } |
| 344 } | 351 } |
| 345 | 352 |
| 346 bool expects_results = injector_->ExpectsResults(); | 353 bool expects_results = injector_->ExpectsResults(); |
| 347 if (expects_results) { | 354 if (expects_results) { |
| 348 if (!results.empty() && !results[0].IsEmpty()) { | 355 if (!results.empty() && !results[0].IsEmpty()) { |
| 349 // Right now, we only support returning single results (per frame). | 356 // Right now, we only support returning single results (per frame). |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 376 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets, | 383 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets, |
| 377 size_t* num_injected_stylesheets) { | 384 size_t* num_injected_stylesheets) { |
| 378 std::vector<blink::WebString> css_sources = injector_->GetCssSources( | 385 std::vector<blink::WebString> css_sources = injector_->GetCssSources( |
| 379 run_location_, injected_stylesheets, num_injected_stylesheets); | 386 run_location_, injected_stylesheets, num_injected_stylesheets); |
| 380 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | 387 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); |
| 381 for (const blink::WebString& css : css_sources) | 388 for (const blink::WebString& css : css_sources) |
| 382 web_frame->document().insertStyleSheet(css); | 389 web_frame->document().insertStyleSheet(css); |
| 383 } | 390 } |
| 384 | 391 |
| 385 } // namespace extensions | 392 } // namespace extensions |
| OLD | NEW |