Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: extensions/renderer/user_script_injector.cc

Issue 492133002: Renderer changes for wiring up shared memory with declarative injection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests, revert mistaken changes, address nits Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return blink::WebScriptSource(blink::WebString::fromUTF8(source_)); 49 return blink::WebScriptSource(blink::WebString::fromUTF8(source_));
50 } 50 }
51 51
52 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api = 52 base::LazyInstance<GreasemonkeyApiJsString> g_greasemonkey_api =
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 : script_(script), 61 : script_(script),
61 script_id_(script_->id()), 62 script_id_(script_->id()),
62 extension_id_(script_->extension_id()), 63 extension_id_(script_->extension_id()),
64 is_declarative_(is_declarative),
63 user_script_set_observer_(this) { 65 user_script_set_observer_(this) {
64 user_script_set_observer_.Add(script_list); 66 user_script_set_observer_.Add(script_list);
65 } 67 }
66 68
67 UserScriptInjector::~UserScriptInjector() { 69 UserScriptInjector::~UserScriptInjector() {
68 } 70 }
69 71
70 void UserScriptInjector::OnUserScriptsUpdated( 72 void UserScriptInjector::OnUserScriptsUpdated(
71 const std::set<std::string>& changed_extensions, 73 const std::set<std::string>& changed_extensions,
72 const std::vector<UserScript*>& scripts) { 74 const std::vector<UserScript*>& scripts) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 int tab_id, 127 int tab_id,
126 const GURL& top_url) const { 128 const GURL& top_url) const {
127 // 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.
128 // For now, we treat this as an automatic allow. 130 // For now, we treat this as an automatic allow.
129 if (tab_id == -1) 131 if (tab_id == -1)
130 return PermissionsData::ACCESS_ALLOWED; 132 return PermissionsData::ACCESS_ALLOWED;
131 133
132 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 134 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
133 web_frame, web_frame->document().url(), script_->match_about_blank()); 135 web_frame, web_frame->document().url(), script_->match_about_blank());
134 136
135 return extension->permissions_data()->GetContentScriptAccess( 137 // Declarative user scripts use "page access" (from "permissions" section in
136 extension, 138 // manifest) whereas non-declarative user scripts use custom
137 effective_document_url, 139 // "content script access" logic.
138 top_url, 140 if (is_declarative_) {
139 tab_id, 141 return extension->permissions_data()->GetPageAccess(
140 -1, // no process id 142 extension,
141 NULL /* ignore error */); 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 }
142 } 157 }
143 158
144 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( 159 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
145 UserScript::RunLocation run_location) const { 160 UserScript::RunLocation run_location) const {
146 DCHECK_EQ(script_->run_location(), run_location); 161 DCHECK_EQ(script_->run_location(), run_location);
147 162
148 std::vector<blink::WebScriptSource> sources; 163 std::vector<blink::WebScriptSource> sources;
149 const UserScript::FileList& js_scripts = script_->js_scripts(); 164 const UserScript::FileList& js_scripts = script_->js_scripts();
150 bool is_standalone_or_emulate_greasemonkey = 165 bool is_standalone_or_emulate_greasemonkey =
151 script_->is_standalone() || script_->emulate_greasemonkey(); 166 script_->is_standalone() || script_->emulate_greasemonkey();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 220 }
206 221
207 if (ShouldInjectCss(run_location)) 222 if (ShouldInjectCss(run_location))
208 scripts_run_info->num_css += script_->css_scripts().size(); 223 scripts_run_info->num_css += script_->css_scripts().size();
209 } 224 }
210 225
211 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { 226 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) {
212 } 227 }
213 228
214 } // namespace extensions 229 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698