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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 ++iter) { | 80 ++iter) { |
81 // We need to compare to |script_id_| (and not to script_->id()) because the | 81 // We need to compare to |script_id_| (and not to script_->id()) because the |
82 // old |script_| may be deleted by now. | 82 // old |script_| may be deleted by now. |
83 if ((*iter)->id() == script_id_) { | 83 if ((*iter)->id() == script_id_) { |
84 script_ = *iter; | 84 script_ = *iter; |
85 break; | 85 break; |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
| 90 UserScript::InjectionType UserScriptInjector::script_type() const { |
| 91 return UserScript::CONTENT_SCRIPT; |
| 92 } |
| 93 |
90 bool UserScriptInjector::ShouldExecuteInChildFrames() const { | 94 bool UserScriptInjector::ShouldExecuteInChildFrames() const { |
91 return false; | 95 return false; |
92 } | 96 } |
93 | 97 |
94 bool UserScriptInjector::ShouldExecuteInMainWorld() const { | 98 bool UserScriptInjector::ShouldExecuteInMainWorld() const { |
95 return false; | 99 return false; |
96 } | 100 } |
97 | 101 |
98 bool UserScriptInjector::IsUserGesture() const { | 102 bool UserScriptInjector::IsUserGesture() const { |
99 return false; | 103 return false; |
100 } | 104 } |
101 | 105 |
102 bool UserScriptInjector::ExpectsResults() const { | 106 bool UserScriptInjector::ExpectsResults() const { |
103 return false; | 107 return false; |
104 } | 108 } |
105 | 109 |
106 bool UserScriptInjector::ShouldInjectJs( | 110 bool UserScriptInjector::ShouldInjectJs( |
107 UserScript::RunLocation run_location) const { | 111 UserScript::RunLocation run_location) const { |
108 return script_->run_location() == run_location && | 112 return script_->run_location() == run_location && |
109 !script_->js_scripts().empty(); | 113 !script_->js_scripts().empty(); |
110 } | 114 } |
111 | 115 |
112 bool UserScriptInjector::ShouldInjectCss( | 116 bool UserScriptInjector::ShouldInjectCss( |
113 UserScript::RunLocation run_location) const { | 117 UserScript::RunLocation run_location) const { |
114 return run_location == UserScript::DOCUMENT_START && | 118 return run_location == UserScript::DOCUMENT_START && |
115 !script_->css_scripts().empty(); | 119 !script_->css_scripts().empty(); |
116 } | 120 } |
117 | 121 |
118 ScriptInjector::AccessType UserScriptInjector::CanExecuteOnFrame( | 122 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( |
119 const Extension* extension, | 123 const Extension* extension, |
120 blink::WebFrame* web_frame, | 124 blink::WebFrame* web_frame, |
121 int tab_id, | 125 int tab_id, |
122 const GURL& top_url) const { | 126 const GURL& top_url) const { |
123 // If we don't have a tab id, we have no UI surface to ask for user consent. | 127 // If we don't have a tab id, we have no UI surface to ask for user consent. |
124 // For now, we treat this as an automatic allow. | 128 // For now, we treat this as an automatic allow. |
125 if (tab_id == -1) | 129 if (tab_id == -1) |
126 return ALLOW_ACCESS; | 130 return PermissionsData::ACCESS_ALLOWED; |
127 | 131 |
128 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 132 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
129 web_frame, web_frame->document().url(), script_->match_about_blank()); | 133 web_frame, web_frame->document().url(), script_->match_about_blank()); |
130 | 134 |
131 return extension->permissions_data()->RequiresActionForScriptExecution( | 135 return extension->permissions_data()->GetContentScriptAccess( |
132 extension, tab_id, web_frame->top()->document().url()) | 136 extension, |
133 ? REQUEST_ACCESS | 137 effective_document_url, |
134 : ALLOW_ACCESS; | 138 top_url, |
| 139 tab_id, |
| 140 -1, // no process id |
| 141 NULL /* ignore error */); |
135 } | 142 } |
136 | 143 |
137 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( | 144 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
138 UserScript::RunLocation run_location) const { | 145 UserScript::RunLocation run_location) const { |
139 DCHECK_EQ(script_->run_location(), run_location); | 146 DCHECK_EQ(script_->run_location(), run_location); |
140 | 147 |
141 std::vector<blink::WebScriptSource> sources; | 148 std::vector<blink::WebScriptSource> sources; |
142 const UserScript::FileList& js_scripts = script_->js_scripts(); | 149 const UserScript::FileList& js_scripts = script_->js_scripts(); |
143 bool is_standalone_or_emulate_greasemonkey = | 150 bool is_standalone_or_emulate_greasemonkey = |
144 script_->is_standalone() || script_->emulate_greasemonkey(); | 151 script_->is_standalone() || script_->emulate_greasemonkey(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 205 } |
199 | 206 |
200 if (ShouldInjectCss(run_location)) | 207 if (ShouldInjectCss(run_location)) |
201 scripts_run_info->num_css += script_->css_scripts().size(); | 208 scripts_run_info->num_css += script_->css_scripts().size(); |
202 } | 209 } |
203 | 210 |
204 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { | 211 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { |
205 } | 212 } |
206 | 213 |
207 } // namespace extensions | 214 } // namespace extensions |
OLD | NEW |