Home | History | Annotate | Download | only in extensions
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h"
      6 
      7 #include "base/command_line.h"
      8 #include "chrome/common/chrome_switches.h"
      9 #include "chrome/common/extensions/extension_constants.h"
     10 #include "chrome/renderer/extensions/dispatcher.h"
     11 #include "extensions/common/extensions_client.h"
     12 #include "extensions/common/manifest_constants.h"
     13 
     14 namespace extensions {
     15 
     16 namespace errors = manifest_errors;
     17 
     18 RendererPermissionsPolicyDelegate::RendererPermissionsPolicyDelegate(
     19     Dispatcher* dispatcher) : dispatcher_(dispatcher) {
     20   PermissionsData::SetPolicyDelegate(this);
     21 }
     22 RendererPermissionsPolicyDelegate::~RendererPermissionsPolicyDelegate() {
     23   PermissionsData::SetPolicyDelegate(NULL);
     24 }
     25 
     26 bool RendererPermissionsPolicyDelegate::CanExecuteScriptOnPage(
     27     const Extension* extension,
     28     const GURL& document_url,
     29     const GURL& top_document_url,
     30     int tab_id,
     31     const UserScript* script,
     32     int process_id,
     33     std::string* error) {
     34   const ExtensionsClient::ScriptingWhitelist& whitelist =
     35       ExtensionsClient::Get()->GetScriptingWhitelist();
     36   if (std::find(whitelist.begin(), whitelist.end(), extension->id()) !=
     37       whitelist.end()) {
     38     return true;
     39   }
     40 
     41   if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSigninProcess)) {
     42     if (error)
     43       *error = errors::kCannotScriptSigninPage;
     44     return false;
     45   }
     46 
     47   if (dispatcher_->IsExtensionActive(extension_misc::kWebStoreAppId)) {
     48     if (error)
     49       *error = errors::kCannotScriptGallery;
     50     return false;
     51   }
     52 
     53   return true;
     54 }
     55 
     56 }  // namespace extensions
     57