| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 326 } |
| 327 | 327 |
| 328 ExtensionFunctionDispatcher* ExtensionFunctionDispatcher::Create( | 328 ExtensionFunctionDispatcher* ExtensionFunctionDispatcher::Create( |
| 329 RenderViewHost* render_view_host, | 329 RenderViewHost* render_view_host, |
| 330 Delegate* delegate, | 330 Delegate* delegate, |
| 331 const GURL& url) { | 331 const GURL& url) { |
| 332 ExtensionsService* service = | 332 ExtensionsService* service = |
| 333 render_view_host->process()->profile()->GetExtensionsService(); | 333 render_view_host->process()->profile()->GetExtensionsService(); |
| 334 DCHECK(service); | 334 DCHECK(service); |
| 335 | 335 |
| 336 if (!service->ExtensionBindingsAllowed(url)) |
| 337 return NULL; |
| 338 |
| 336 Extension* extension = service->GetExtensionByURL(url); | 339 Extension* extension = service->GetExtensionByURL(url); |
| 340 if (!extension) |
| 341 extension = service->GetExtensionByWebExtent(url); |
| 342 |
| 337 if (extension) | 343 if (extension) |
| 338 return new ExtensionFunctionDispatcher(render_view_host, delegate, | 344 return new ExtensionFunctionDispatcher(render_view_host, delegate, |
| 339 extension, url); | 345 extension, url); |
| 340 else | 346 else |
| 341 return NULL; | 347 return NULL; |
| 342 } | 348 } |
| 343 | 349 |
| 344 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( | 350 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( |
| 345 RenderViewHost* render_view_host, | 351 RenderViewHost* render_view_host, |
| 346 Delegate* delegate, | 352 Delegate* delegate, |
| 347 Extension* extension, | 353 Extension* extension, |
| 348 const GURL& url) | 354 const GURL& url) |
| 349 : profile_(render_view_host->process()->profile()), | 355 : profile_(render_view_host->process()->profile()), |
| 350 render_view_host_(render_view_host), | 356 render_view_host_(render_view_host), |
| 351 delegate_(delegate), | 357 delegate_(delegate), |
| 352 url_(url), | 358 url_(url), |
| 359 extension_id_(extension->id()), |
| 353 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { | 360 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { |
| 354 // TODO(erikkay) should we do something for these errors in Release? | 361 // TODO(erikkay) should we do something for these errors in Release? |
| 355 DCHECK(url.SchemeIs(chrome::kExtensionScheme)); | |
| 356 DCHECK(extension); | 362 DCHECK(extension); |
| 363 DCHECK(url.SchemeIs(chrome::kExtensionScheme) || |
| 364 extension->location() == Extension::COMPONENT); |
| 357 | 365 |
| 358 // Notify the ExtensionProcessManager that the view was created. | 366 // Notify the ExtensionProcessManager that the view was created. |
| 359 ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); | 367 ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); |
| 360 epm->RegisterExtensionProcess(extension_id(), | 368 epm->RegisterExtensionProcess(extension_id(), |
| 361 render_view_host->process()->id()); | 369 render_view_host->process()->id()); |
| 362 | 370 |
| 363 bool incognito_enabled = | 371 bool incognito_enabled = |
| 364 profile()->GetExtensionsService()->IsIncognitoEnabled(extension); | 372 profile()->GetExtensionsService()->IsIncognitoEnabled(extension); |
| 365 | 373 |
| 366 // If the extension has permission to load chrome://favicon/ resources we need | 374 // If the extension has permission to load chrome://favicon/ resources we need |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 function->set_source_url(params.source_url); | 449 function->set_source_url(params.source_url); |
| 442 function->set_request_id(params.request_id); | 450 function->set_request_id(params.request_id); |
| 443 function->set_has_callback(params.has_callback); | 451 function->set_has_callback(params.has_callback); |
| 444 function->set_user_gesture(params.user_gesture); | 452 function->set_user_gesture(params.user_gesture); |
| 445 ExtensionsService* service = profile()->GetExtensionsService(); | 453 ExtensionsService* service = profile()->GetExtensionsService(); |
| 446 DCHECK(service); | 454 DCHECK(service); |
| 447 Extension* extension = service->GetExtensionById(extension_id(), false); | 455 Extension* extension = service->GetExtensionById(extension_id(), false); |
| 448 DCHECK(extension); | 456 DCHECK(extension); |
| 449 function->set_include_incognito(service->IsIncognitoEnabled(extension)); | 457 function->set_include_incognito(service->IsIncognitoEnabled(extension)); |
| 450 | 458 |
| 459 std::string permission_name = function->name(); |
| 460 size_t separator = permission_name.find_first_of("./"); |
| 461 if (separator != std::string::npos) |
| 462 permission_name = permission_name.substr(0, separator); |
| 463 |
| 464 if (!service->ExtensionBindingsAllowed(function->source_url()) || |
| 465 !extension->HasApiPermission(permission_name)) { |
| 466 render_view_host_->BlockExtensionRequest(function->request_id()); |
| 467 return; |
| 468 } |
| 469 |
| 451 ExtensionsQuotaService* quota = service->quota_service(); | 470 ExtensionsQuotaService* quota = service->quota_service(); |
| 452 if (quota->Assess(extension_id(), function, ¶ms.arguments, | 471 if (quota->Assess(extension_id(), function, ¶ms.arguments, |
| 453 base::TimeTicks::Now())) { | 472 base::TimeTicks::Now())) { |
| 454 // See crbug.com/39178. | 473 // See crbug.com/39178. |
| 455 ExternalProtocolHandler::PermitLaunchUrl(); | 474 ExternalProtocolHandler::PermitLaunchUrl(); |
| 456 | 475 |
| 457 function->Run(); | 476 function->Run(); |
| 458 } else { | 477 } else { |
| 459 render_view_host_->SendExtensionResponse(function->request_id(), false, | 478 render_view_host_->SendExtensionResponse(function->request_id(), false, |
| 460 std::string(), QuotaLimitHeuristic::kGenericOverQuotaError); | 479 std::string(), QuotaLimitHeuristic::kGenericOverQuotaError); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 477 } else { | 496 } else { |
| 478 NOTREACHED(); | 497 NOTREACHED(); |
| 479 base::KillProcess(render_view_host_->process()->GetHandle(), | 498 base::KillProcess(render_view_host_->process()->GetHandle(), |
| 480 ResultCodes::KILLED_BAD_MESSAGE, false); | 499 ResultCodes::KILLED_BAD_MESSAGE, false); |
| 481 } | 500 } |
| 482 } | 501 } |
| 483 | 502 |
| 484 Profile* ExtensionFunctionDispatcher::profile() { | 503 Profile* ExtensionFunctionDispatcher::profile() { |
| 485 return profile_; | 504 return profile_; |
| 486 } | 505 } |
| OLD | NEW |