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/user_script_injector.h" | 5 #include "extensions/renderer/user_script_injector.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 // |script_id| and |routing_id| pair. | 58 // |script_id| and |routing_id| pair. |
59 base::LazyInstance<RoutingInfoMap> g_routing_info_map = | 59 base::LazyInstance<RoutingInfoMap> g_routing_info_map = |
60 LAZY_INSTANCE_INITIALIZER; | 60 LAZY_INSTANCE_INITIALIZER; |
61 | 61 |
62 // Greasemonkey API source that is injected with the scripts. | 62 // Greasemonkey API source that is injected with the scripts. |
63 struct GreasemonkeyApiJsString { | 63 struct GreasemonkeyApiJsString { |
64 GreasemonkeyApiJsString(); | 64 GreasemonkeyApiJsString(); |
65 blink::WebScriptSource GetSource() const; | 65 blink::WebScriptSource GetSource() const; |
66 | 66 |
67 private: | 67 private: |
68 std::string source_; | 68 // Data is owned by ResourceBundle. |
Devlin
2016/08/20 01:58:36
Not quite true, right? fromUTF8() still performs a
lazyboy
2016/08/22 17:09:50
That's right. Removed the comment.
fromUTF8() sti
| |
69 blink::WebString source_; | |
69 }; | 70 }; |
70 | 71 |
71 // The below constructor, monstrous as it is, just makes a WebScriptSource from | 72 // The below constructor, monstrous as it is, just makes a WebScriptSource from |
72 // the GreasemonkeyApiJs resource. | 73 // the GreasemonkeyApiJs resource. |
73 GreasemonkeyApiJsString::GreasemonkeyApiJsString() | 74 GreasemonkeyApiJsString::GreasemonkeyApiJsString() { |
74 : source_(ResourceBundle::GetSharedInstance() | 75 base::StringPiece source_piece = |
75 .GetRawDataResource(IDR_GREASEMONKEY_API_JS) | 76 ResourceBundle::GetSharedInstance().GetRawDataResource( |
76 .as_string()) { | 77 IDR_GREASEMONKEY_API_JS); |
78 source_ = | |
79 blink::WebString::fromUTF8(source_piece.data(), source_piece.length()); | |
77 } | 80 } |
78 | 81 |
79 blink::WebScriptSource GreasemonkeyApiJsString::GetSource() const { | 82 blink::WebScriptSource GreasemonkeyApiJsString::GetSource() const { |
80 return blink::WebScriptSource(blink::WebString::fromUTF8(source_)); | 83 return blink::WebScriptSource(source_); |
81 } | 84 } |
82 | 85 |
83 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api = | 86 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api = |
84 LAZY_INSTANCE_INITIALIZER; | 87 LAZY_INSTANCE_INITIALIZER; |
85 | 88 |
86 } // namespace | 89 } // namespace |
87 | 90 |
88 UserScriptInjector::UserScriptInjector(const UserScript* script, | 91 UserScriptInjector::UserScriptInjector(const UserScript* script, |
89 UserScriptSet* script_list, | 92 UserScriptSet* script_list, |
90 bool is_declarative) | 93 bool is_declarative) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 void UserScriptInjector::OnInjectionComplete( | 285 void UserScriptInjector::OnInjectionComplete( |
283 std::unique_ptr<base::Value> execution_result, | 286 std::unique_ptr<base::Value> execution_result, |
284 UserScript::RunLocation run_location, | 287 UserScript::RunLocation run_location, |
285 content::RenderFrame* render_frame) {} | 288 content::RenderFrame* render_frame) {} |
286 | 289 |
287 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason, | 290 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason, |
288 content::RenderFrame* render_frame) { | 291 content::RenderFrame* render_frame) { |
289 } | 292 } |
290 | 293 |
291 } // namespace extensions | 294 } // namespace extensions |
OLD | NEW |