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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 LAZY_INSTANCE_INITIALIZER; | 53 LAZY_INSTANCE_INITIALIZER; |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 UserScriptInjector::UserScriptInjector( | 57 UserScriptInjector::UserScriptInjector( |
58 const UserScript* script, | 58 const UserScript* script, |
59 UserScriptSet* script_list, | 59 UserScriptSet* script_list, |
60 bool is_declarative) | 60 bool is_declarative) |
61 : script_(script), | 61 : script_(script), |
62 script_id_(script_->id()), | 62 script_id_(script_->id()), |
63 extension_id_(script_->extension_id()), | 63 extension_id_(script_->extension_id()), |
Devlin
2015/02/09 17:40:25
Things like this will need to be updated soon.
Xi Han
2015/02/09 23:28:11
You are absolutely right. I will have a patch to d
| |
64 is_declarative_(is_declarative), | 64 is_declarative_(is_declarative), |
65 user_script_set_observer_(this) { | 65 user_script_set_observer_(this) { |
66 user_script_set_observer_.Add(script_list); | 66 user_script_set_observer_.Add(script_list); |
67 } | 67 } |
68 | 68 |
69 UserScriptInjector::~UserScriptInjector() { | 69 UserScriptInjector::~UserScriptInjector() { |
70 } | 70 } |
71 | 71 |
72 void UserScriptInjector::OnUserScriptsUpdated( | 72 void UserScriptInjector::OnUserScriptsUpdated( |
73 const std::set<std::string>& changed_extensions, | 73 const std::set<std::string>& changed_extensions, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 !script_->js_scripts().empty(); | 115 !script_->js_scripts().empty(); |
116 } | 116 } |
117 | 117 |
118 bool UserScriptInjector::ShouldInjectCss( | 118 bool UserScriptInjector::ShouldInjectCss( |
119 UserScript::RunLocation run_location) const { | 119 UserScript::RunLocation run_location) const { |
120 return run_location == UserScript::DOCUMENT_START && | 120 return run_location == UserScript::DOCUMENT_START && |
121 !script_->css_scripts().empty(); | 121 !script_->css_scripts().empty(); |
122 } | 122 } |
123 | 123 |
124 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( | 124 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( |
125 const Extension* extension, | 125 const Host* host, |
126 blink::WebFrame* web_frame, | 126 blink::WebFrame* web_frame, |
127 int tab_id, | 127 int tab_id, |
128 const GURL& top_url) const { | 128 const GURL& top_url) const { |
129 // If we don't have a tab id, we have no UI surface to ask for user consent. | 129 // If we don't have a tab id, we have no UI surface to ask for user consent. |
130 // For now, we treat this as an automatic allow. | 130 // For now, we treat this as an automatic allow. |
131 if (tab_id == -1) | 131 if (tab_id == -1) |
132 return PermissionsData::ACCESS_ALLOWED; | 132 return PermissionsData::ACCESS_ALLOWED; |
133 | 133 |
134 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 134 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
135 web_frame, web_frame->document().url(), script_->match_about_blank()); | 135 web_frame, web_frame->document().url(), script_->match_about_blank()); |
136 | 136 return host->CanExecuteOnFrame( |
137 // Declarative user scripts use "page access" (from "permissions" section in | 137 effective_document_url, top_url, tab_id, is_declarative_); |
138 // manifest) whereas non-declarative user scripts use custom | |
139 // "content script access" logic. | |
140 if (is_declarative_) { | |
141 return extension->permissions_data()->GetPageAccess( | |
142 extension, | |
143 effective_document_url, | |
144 top_url, | |
145 tab_id, | |
146 -1, // no process id | |
147 NULL /* ignore error */); | |
148 } else { | |
149 return extension->permissions_data()->GetContentScriptAccess( | |
150 extension, | |
151 effective_document_url, | |
152 top_url, | |
153 tab_id, | |
154 -1, // no process id | |
155 NULL /* ignore error */); | |
156 } | |
157 } | 138 } |
158 | 139 |
159 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( | 140 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
160 UserScript::RunLocation run_location) const { | 141 UserScript::RunLocation run_location) const { |
161 DCHECK_EQ(script_->run_location(), run_location); | 142 DCHECK_EQ(script_->run_location(), run_location); |
162 | 143 |
163 std::vector<blink::WebScriptSource> sources; | 144 std::vector<blink::WebScriptSource> sources; |
164 const UserScript::FileList& js_scripts = script_->js_scripts(); | 145 const UserScript::FileList& js_scripts = script_->js_scripts(); |
165 bool is_standalone_or_emulate_greasemonkey = | 146 bool is_standalone_or_emulate_greasemonkey = |
166 script_->is_standalone() || script_->emulate_greasemonkey(); | 147 script_->is_standalone() || script_->emulate_greasemonkey(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 } | 201 } |
221 | 202 |
222 if (ShouldInjectCss(run_location)) | 203 if (ShouldInjectCss(run_location)) |
223 scripts_run_info->num_css += script_->css_scripts().size(); | 204 scripts_run_info->num_css += script_->css_scripts().size(); |
224 } | 205 } |
225 | 206 |
226 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { | 207 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { |
227 } | 208 } |
228 | 209 |
229 } // namespace extensions | 210 } // namespace extensions |
OLD | NEW |