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

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

Issue 10815028: Make ActiveTabPermissionManager also grant the tabs permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add API test and fix a bug (woo) Created 8 years, 4 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
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extension_function_dispatcher.h" 5 #include "chrome/browser/extensions/extension_function_dispatcher.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 int routing_id, 129 int routing_id,
130 const ExtensionHostMsg_Request_Params& params) { 130 const ExtensionHostMsg_Request_Params& params) {
131 const Extension* extension = 131 const Extension* extension =
132 extension_info_map->extensions().GetByID(params.extension_id); 132 extension_info_map->extensions().GetByID(params.extension_id);
133 133
134 scoped_refptr<ExtensionFunction> function( 134 scoped_refptr<ExtensionFunction> function(
135 CreateExtensionFunction(params, extension, render_process_id, 135 CreateExtensionFunction(params, extension, render_process_id,
136 extension_info_map->process_map(), 136 extension_info_map->process_map(),
137 g_global_io_data.Get().api.get(), 137 g_global_io_data.Get().api.get(),
138 profile, 138 profile,
139 ipc_sender, routing_id)); 139 ipc_sender, NULL, routing_id));
140 if (!function) { 140 if (!function) {
141 LogFailure(extension, params.name, kAccessDenied); 141 LogFailure(extension, params.name, kAccessDenied);
142 return; 142 return;
143 } 143 }
144 144
145 IOThreadExtensionFunction* function_io = 145 IOThreadExtensionFunction* function_io =
146 function->AsIOThreadExtensionFunction(); 146 function->AsIOThreadExtensionFunction();
147 if (!function_io) { 147 if (!function_io) {
148 NOTREACHED(); 148 NOTREACHED();
149 return; 149 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (!extension) 186 if (!extension)
187 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo( 187 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo(
188 WebSecurityOrigin::createFromString(params.source_origin), 188 WebSecurityOrigin::createFromString(params.source_origin),
189 params.source_url)); 189 params.source_url));
190 190
191 scoped_refptr<ExtensionFunction> function( 191 scoped_refptr<ExtensionFunction> function(
192 CreateExtensionFunction(params, extension, 192 CreateExtensionFunction(params, extension,
193 render_view_host->GetProcess()->GetID(), 193 render_view_host->GetProcess()->GetID(),
194 *(service->process_map()), 194 *(service->process_map()),
195 extensions::ExtensionAPI::GetSharedInstance(), 195 extensions::ExtensionAPI::GetSharedInstance(),
196 profile(), render_view_host, 196 profile(), render_view_host, render_view_host,
197 render_view_host->GetRoutingID())); 197 render_view_host->GetRoutingID()));
198 if (!function) { 198 if (!function) {
199 LogFailure(extension, params.name, kAccessDenied); 199 LogFailure(extension, params.name, kAccessDenied);
200 return; 200 return;
201 } 201 }
202 202
203 UIThreadExtensionFunction* function_ui = 203 UIThreadExtensionFunction* function_ui =
204 function->AsUIThreadExtensionFunction(); 204 function->AsUIThreadExtensionFunction();
205 if (!function_ui) { 205 if (!function_ui) {
206 NOTREACHED(); 206 NOTREACHED();
207 return; 207 return;
208 } 208 }
209 function_ui->SetRenderViewHost(render_view_host);
210 function_ui->set_dispatcher(AsWeakPtr()); 209 function_ui->set_dispatcher(AsWeakPtr());
211 function_ui->set_profile(profile_); 210 function_ui->set_profile(profile_);
212 function->set_include_incognito(service->CanCrossIncognito(extension)); 211 function->set_include_incognito(service->CanCrossIncognito(extension));
213 212
214 ExtensionsQuotaService* quota = service->quota_service(); 213 ExtensionsQuotaService* quota = service->quota_service();
215 if (quota->Assess(extension->id(), function, &params.arguments, 214 if (quota->Assess(extension->id(), function, &params.arguments,
216 base::TimeTicks::Now())) { 215 base::TimeTicks::Now())) {
217 // See crbug.com/39178. 216 // See crbug.com/39178.
218 ExternalProtocolHandler::PermitLaunchUrl(); 217 ExternalProtocolHandler::PermitLaunchUrl();
219 218
(...skipping 24 matching lines...) Expand all
244 243
245 // static 244 // static
246 ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( 245 ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction(
247 const ExtensionHostMsg_Request_Params& params, 246 const ExtensionHostMsg_Request_Params& params,
248 const Extension* extension, 247 const Extension* extension,
249 int requesting_process_id, 248 int requesting_process_id,
250 const extensions::ProcessMap& process_map, 249 const extensions::ProcessMap& process_map,
251 extensions::ExtensionAPI* api, 250 extensions::ExtensionAPI* api,
252 void* profile, 251 void* profile,
253 IPC::Sender* ipc_sender, 252 IPC::Sender* ipc_sender,
253 RenderViewHost* render_view_host,
254 int routing_id) { 254 int routing_id) {
255 if (!extension) { 255 if (!extension) {
256 LOG(ERROR) << "Specified extension does not exist."; 256 LOG(ERROR) << "Specified extension does not exist.";
257 SendAccessDenied(ipc_sender, routing_id, params.request_id); 257 SendAccessDenied(ipc_sender, routing_id, params.request_id);
258 return NULL; 258 return NULL;
259 } 259 }
260 260
261 if (api->IsPrivileged(params.name) && 261 if (api->IsPrivileged(params.name) &&
262 !process_map.Contains(extension->id(), requesting_process_id)) { 262 !process_map.Contains(extension->id(), requesting_process_id)) {
263 LOG(ERROR) << "Extension API called from incorrect process " 263 LOG(ERROR) << "Extension API called from incorrect process "
264 << requesting_process_id 264 << requesting_process_id
265 << " from URL " << params.source_url.spec(); 265 << " from URL " << params.source_url.spec();
266 SendAccessDenied(ipc_sender, routing_id, params.request_id); 266 SendAccessDenied(ipc_sender, routing_id, params.request_id);
267 return NULL; 267 return NULL;
268 } 268 }
269 269
270 if (!extension->HasAPIPermission(params.name)) {
271 LOG(ERROR) << "Extension " << extension->id() << " does not have "
272 << "permission to function: " << params.name;
273 SendAccessDenied(ipc_sender, routing_id, params.request_id);
274 return NULL;
275 }
276
277 ExtensionFunction* function = 270 ExtensionFunction* function =
278 ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name); 271 ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name);
279 function->SetArgs(&params.arguments); 272 function->SetArgs(&params.arguments);
280 function->set_source_url(params.source_url); 273 function->set_source_url(params.source_url);
281 function->set_request_id(params.request_id); 274 function->set_request_id(params.request_id);
282 function->set_has_callback(params.has_callback); 275 function->set_has_callback(params.has_callback);
283 function->set_user_gesture(params.user_gesture); 276 function->set_user_gesture(params.user_gesture);
284 function->set_extension(extension); 277 function->set_extension(extension);
285 function->set_profile_id(profile); 278 function->set_profile_id(profile);
279
280 UIThreadExtensionFunction* function_ui =
281 function->AsUIThreadExtensionFunction();
282 if (function_ui) {
283 function_ui->SetRenderViewHost(render_view_host);
not at google - send to devlin 2012/08/02 12:23:47 I needed to make this change because the render_vi
284 }
285
286 if (!function->HasPermission()) {
287 LOG(ERROR) << "Extension " << extension->id() << " does not have "
288 << "permission to function: " << params.name;
289 SendAccessDenied(ipc_sender, routing_id, params.request_id);
290 return NULL;
291 }
292
286 return function; 293 return function;
287 } 294 }
288 295
289 // static 296 // static
290 void ExtensionFunctionDispatcher::SendAccessDenied( 297 void ExtensionFunctionDispatcher::SendAccessDenied(
291 IPC::Sender* ipc_sender, int routing_id, int request_id) { 298 IPC::Sender* ipc_sender, int routing_id, int request_id) {
292 ListValue empty_list; 299 ListValue empty_list;
293 ipc_sender->Send(new ExtensionMsg_Response( 300 ipc_sender->Send(new ExtensionMsg_Response(
294 routing_id, request_id, false, empty_list, 301 routing_id, request_id, false, empty_list,
295 "Access to extension API denied.")); 302 "Access to extension API denied."));
296 } 303 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698