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" |
| 11 #include "base/macros.h" |
11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
12 #include "base/timer/elapsed_timer.h" | 13 #include "base/timer/elapsed_timer.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "content/public/child/v8_value_converter.h" | 15 #include "content/public/child/v8_value_converter.h" |
15 #include "content/public/renderer/render_frame.h" | 16 #include "content/public/renderer/render_frame.h" |
16 #include "extensions/common/extension_messages.h" | 17 #include "extensions/common/extension_messages.h" |
17 #include "extensions/common/host_id.h" | 18 #include "extensions/common/host_id.h" |
18 #include "extensions/renderer/dom_activity_logger.h" | 19 #include "extensions/renderer/dom_activity_logger.h" |
19 #include "extensions/renderer/extension_frame_helper.h" | 20 #include "extensions/renderer/extension_frame_helper.h" |
20 #include "extensions/renderer/extension_groups.h" | 21 #include "extensions/renderer/extension_groups.h" |
21 #include "extensions/renderer/extensions_renderer_client.h" | 22 #include "extensions/renderer/extensions_renderer_client.h" |
22 #include "extensions/renderer/script_injection_callback.h" | 23 #include "extensions/renderer/script_injection_callback.h" |
23 #include "extensions/renderer/scripts_run_info.h" | 24 #include "extensions/renderer/scripts_run_info.h" |
24 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
25 #include "third_party/WebKit/public/web/WebDocument.h" | 26 #include "third_party/WebKit/public/web/WebDocument.h" |
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 27 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
27 #include "third_party/WebKit/public/web/WebScriptSource.h" | 28 #include "third_party/WebKit/public/web/WebScriptSource.h" |
28 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 29 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
30 | 31 |
31 namespace extensions { | 32 namespace extensions { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 using IsolatedWorldMap = std::map<std::string, int>; | 36 using IsolatedWorldMap = std::map<std::string, int>; |
36 base::LazyInstance<IsolatedWorldMap> g_isolated_worlds = | 37 base::LazyInstance<IsolatedWorldMap> g_isolated_worlds = |
37 LAZY_INSTANCE_INITIALIZER; | 38 LAZY_INSTANCE_INITIALIZER; |
38 | 39 |
39 const int64 kInvalidRequestId = -1; | 40 const int64_t kInvalidRequestId = -1; |
40 | 41 |
41 // The id of the next pending injection. | 42 // The id of the next pending injection. |
42 int64 g_next_pending_id = 0; | 43 int64_t g_next_pending_id = 0; |
43 | 44 |
44 // Gets the isolated world ID to use for the given |injection_host| | 45 // Gets the isolated world ID to use for the given |injection_host| |
45 // in the given |frame|. If no isolated world has been created for that | 46 // in the given |frame|. If no isolated world has been created for that |
46 // |injection_host| one will be created and initialized. | 47 // |injection_host| one will be created and initialized. |
47 int GetIsolatedWorldIdForInstance(const InjectionHost* injection_host, | 48 int GetIsolatedWorldIdForInstance(const InjectionHost* injection_host, |
48 blink::WebLocalFrame* frame) { | 49 blink::WebLocalFrame* frame) { |
49 static int g_next_isolated_world_id = | 50 static int g_next_isolated_world_id = |
50 ExtensionsRendererClient::Get()->GetLowestIsolatedWorldId(); | 51 ExtensionsRendererClient::Get()->GetLowestIsolatedWorldId(); |
51 | 52 |
52 IsolatedWorldMap& isolated_worlds = g_isolated_worlds.Get(); | 53 IsolatedWorldMap& isolated_worlds = g_isolated_worlds.Get(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 312 |
312 void ScriptInjection::InjectCss() { | 313 void ScriptInjection::InjectCss() { |
313 std::vector<std::string> css_sources = | 314 std::vector<std::string> css_sources = |
314 injector_->GetCssSources(run_location_); | 315 injector_->GetCssSources(run_location_); |
315 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | 316 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); |
316 for (const std::string& css : css_sources) | 317 for (const std::string& css : css_sources) |
317 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css)); | 318 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css)); |
318 } | 319 } |
319 | 320 |
320 } // namespace extensions | 321 } // namespace extensions |
OLD | NEW |