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

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

Issue 348313003: Create withheld permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test fix Created 6 years, 5 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 | Annotate | Revision Log
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"
11 #include "extensions/common/constants.h"
11 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
12 #include "extensions/common/permissions/permissions_data.h" 13 #include "extensions/common/permissions/permissions_data.h"
13 #include "extensions/renderer/script_context.h" 14 #include "extensions/renderer/script_context.h"
14 #include "extensions/renderer/scripts_run_info.h" 15 #include "extensions/renderer/scripts_run_info.h"
15 #include "grit/extensions_renderer_resources.h" 16 #include "grit/extensions_renderer_resources.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 17 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebFrame.h" 18 #include "third_party/WebKit/public/web/WebFrame.h"
18 #include "third_party/WebKit/public/web/WebScriptSource.h" 19 #include "third_party/WebKit/public/web/WebScriptSource.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 ++iter) { 81 ++iter) {
81 // We need to compare to |script_id_| (and not to script_->id()) because the 82 // We need to compare to |script_id_| (and not to script_->id()) because the
82 // old |script_| may be deleted by now. 83 // old |script_| may be deleted by now.
83 if ((*iter)->id() == script_id_) { 84 if ((*iter)->id() == script_id_) {
84 script_ = *iter; 85 script_ = *iter;
85 break; 86 break;
86 } 87 }
87 } 88 }
88 } 89 }
89 90
91 extension_misc::InjectedScriptType UserScriptInjector::script_type() const {
92 return extension_misc::CONTENT_SCRIPT;
93 }
94
90 bool UserScriptInjector::ShouldExecuteInChildFrames() const { 95 bool UserScriptInjector::ShouldExecuteInChildFrames() const {
91 return false; 96 return false;
92 } 97 }
93 98
94 bool UserScriptInjector::ShouldExecuteInMainWorld() const { 99 bool UserScriptInjector::ShouldExecuteInMainWorld() const {
95 return false; 100 return false;
96 } 101 }
97 102
98 bool UserScriptInjector::IsUserGesture() const { 103 bool UserScriptInjector::IsUserGesture() const {
99 return false; 104 return false;
100 } 105 }
101 106
102 bool UserScriptInjector::ExpectsResults() const { 107 bool UserScriptInjector::ExpectsResults() const {
103 return false; 108 return false;
104 } 109 }
105 110
106 bool UserScriptInjector::ShouldInjectJs( 111 bool UserScriptInjector::ShouldInjectJs(
107 UserScript::RunLocation run_location) const { 112 UserScript::RunLocation run_location) const {
108 return script_->run_location() == run_location && 113 return script_->run_location() == run_location &&
109 !script_->js_scripts().empty(); 114 !script_->js_scripts().empty();
110 } 115 }
111 116
112 bool UserScriptInjector::ShouldInjectCss( 117 bool UserScriptInjector::ShouldInjectCss(
113 UserScript::RunLocation run_location) const { 118 UserScript::RunLocation run_location) const {
114 return run_location == UserScript::DOCUMENT_START && 119 return run_location == UserScript::DOCUMENT_START &&
115 !script_->css_scripts().empty(); 120 !script_->css_scripts().empty();
116 } 121 }
117 122
118 ScriptInjector::AccessType UserScriptInjector::CanExecuteOnFrame( 123 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame(
119 const Extension* extension, 124 const Extension* extension,
120 blink::WebFrame* web_frame, 125 blink::WebFrame* web_frame,
121 int tab_id, 126 int tab_id,
122 const GURL& top_url) const { 127 const GURL& top_url) const {
123 // If we don't have a tab id, we have no UI surface to ask for user consent. 128 // 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. 129 // For now, we treat this as an automatic allow.
125 if (tab_id == -1) 130 if (tab_id == -1)
126 return ALLOW_ACCESS; 131 return PermissionsData::ALLOW_ACCESS;
127 132
128 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 133 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
129 web_frame, web_frame->document().url(), script_->match_about_blank()); 134 web_frame, web_frame->document().url(), script_->match_about_blank());
130 135
131 return extension->permissions_data()->RequiresActionForScriptExecution( 136 return extension->permissions_data()
132 extension, tab_id, web_frame->top()->document().url()) 137 ->CanRunContentScriptOnPageWithUserConsent(
133 ? REQUEST_ACCESS 138 extension,
134 : ALLOW_ACCESS; 139 effective_document_url,
140 top_url,
141 tab_id,
142 -1, // no process id
143 NULL /* ignore error */);
135 } 144 }
136 145
137 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( 146 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
138 UserScript::RunLocation run_location) const { 147 UserScript::RunLocation run_location) const {
139 DCHECK_EQ(script_->run_location(), run_location); 148 DCHECK_EQ(script_->run_location(), run_location);
140 149
141 std::vector<blink::WebScriptSource> sources; 150 std::vector<blink::WebScriptSource> sources;
142 const UserScript::FileList& js_scripts = script_->js_scripts(); 151 const UserScript::FileList& js_scripts = script_->js_scripts();
143 bool is_standalone_or_emulate_greasemonkey = 152 bool is_standalone_or_emulate_greasemonkey =
144 script_->is_standalone() || script_->emulate_greasemonkey(); 153 script_->is_standalone() || script_->emulate_greasemonkey();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 207 }
199 208
200 if (ShouldInjectCss(run_location)) 209 if (ShouldInjectCss(run_location))
201 scripts_run_info->num_css += script_->css_scripts().size(); 210 scripts_run_info->num_css += script_->css_scripts().size();
202 } 211 }
203 212
204 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { 213 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) {
205 } 214 }
206 215
207 } // namespace extensions 216 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698