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

Side by Side Diff: chrome/browser/extensions/active_script_controller.cc

Issue 288053002: Block content scripts from executing until user grants permission (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 "chrome/browser/extensions/active_script_controller.h" 5 #include "chrome/browser/extensions/active_script_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 return LocationBarController::ACTION_NONE; 136 return LocationBarController::ACTION_NONE;
137 } 137 }
138 138
139 void ActiveScriptController::OnNavigated() { 139 void ActiveScriptController::OnNavigated() {
140 LogUMA(); 140 LogUMA();
141 requesting_extensions_.clear(); 141 requesting_extensions_.clear();
142 pending_requests_.clear(); 142 pending_requests_.clear();
143 } 143 }
144 144
145 void ActiveScriptController::OnNotifyExtensionScriptExecution( 145 void ActiveScriptController::OnRequestContentScriptPermission(
146 const std::string& extension_id, 146 const std::string& extension_id,
147 int page_id) { 147 int page_id,
148 int request_id) {
148 if (!Extension::IdIsValid(extension_id)) { 149 if (!Extension::IdIsValid(extension_id)) {
149 NOTREACHED() << "'" << extension_id << "' is not a valid id."; 150 NOTREACHED() << "'" << extension_id << "' is not a valid id.";
150 return; 151 return;
151 } 152 }
152 153
154 // This base::Unretained() is safe, because this can only be called from
155 // itself.
153 GetPermissionForInjection( 156 GetPermissionForInjection(
154 extension_id, 157 extension_id,
155 page_id, 158 page_id,
156 scoped_ptr<const base::Closure>( 159 scoped_ptr<const base::Closure>(new base::Closure(
157 new base::Closure(base::Bind(&base::DoNothing)))); 160 base::Bind(&ActiveScriptController::GrantContentScriptPermission,
161 base::Unretained(this),
162 request_id))));
163 }
164
165 void ActiveScriptController::GrantContentScriptPermission(int request_id) {
166 content::RenderViewHost* render_view_host =
167 web_contents()->GetRenderViewHost();
168 if (render_view_host) {
169 render_view_host->Send(new ExtensionMsg_GrantContentScriptPermission(
170 render_view_host->GetRoutingID(),
171 request_id));
172 }
158 } 173 }
159 174
160 void ActiveScriptController::AddOrProcessRequest( 175 void ActiveScriptController::AddOrProcessRequest(
161 const Extension* extension, 176 const Extension* extension,
162 scoped_ptr<const base::Closure> request) { 177 scoped_ptr<const base::Closure> request) {
163 // If the extension does not require permissions, run it immediately. 178 // If the extension does not require permissions, run it immediately.
164 if (!PermissionsData::RequiresActionForScriptExecution(extension)) { 179 if (!PermissionsData::RequiresActionForScriptExecution(extension)) {
165 request->Run(); 180 request->Run();
166 return; 181 return;
167 } 182 }
(...skipping 13 matching lines...) Expand all
181 // If this was the first entry, notify the location bar that there's a new 196 // If this was the first entry, notify the location bar that there's a new
182 // icon. 197 // icon.
183 if (list->size() == 1u) 198 if (list->size() == 1u)
184 LocationBarController::NotifyChange(web_contents()); 199 LocationBarController::NotifyChange(web_contents());
185 200
186 } 201 }
187 202
188 bool ActiveScriptController::OnMessageReceived(const IPC::Message& message) { 203 bool ActiveScriptController::OnMessageReceived(const IPC::Message& message) {
189 bool handled = true; 204 bool handled = true;
190 IPC_BEGIN_MESSAGE_MAP(ActiveScriptController, message) 205 IPC_BEGIN_MESSAGE_MAP(ActiveScriptController, message)
191 IPC_MESSAGE_HANDLER(ExtensionHostMsg_NotifyExtensionScriptExecution, 206 IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestContentScriptPermission,
192 OnNotifyExtensionScriptExecution) 207 OnRequestContentScriptPermission)
193 IPC_MESSAGE_UNHANDLED(handled = false) 208 IPC_MESSAGE_UNHANDLED(handled = false)
194 IPC_END_MESSAGE_MAP() 209 IPC_END_MESSAGE_MAP()
195 return handled; 210 return handled;
196 } 211 }
197 212
198 void ActiveScriptController::LogUMA() const { 213 void ActiveScriptController::LogUMA() const {
199 UMA_HISTOGRAM_COUNTS_100( 214 UMA_HISTOGRAM_COUNTS_100(
200 "Extensions.ActiveScriptController.ShownActiveScriptsOnPage", 215 "Extensions.ActiveScriptController.ShownActiveScriptsOnPage",
201 pending_requests_.size()); 216 pending_requests_.size());
202 } 217 }
203 218
204 } // namespace extensions 219 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698