Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / chrome / renderer / extensions / renderer_permissions_policy_delegate.cc
blob5e046cd989bef634a28405300f515f055c12b52b
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.
5 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h"
7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/extensions/extension_constants.h"
10 #include "extensions/common/constants.h"
11 #include "extensions/common/extensions_client.h"
12 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/switches.h"
14 #include "extensions/renderer/dispatcher.h"
16 namespace extensions {
18 namespace errors = manifest_errors;
20 RendererPermissionsPolicyDelegate::RendererPermissionsPolicyDelegate(
21 Dispatcher* dispatcher) : dispatcher_(dispatcher) {
22 PermissionsData::SetPolicyDelegate(this);
24 RendererPermissionsPolicyDelegate::~RendererPermissionsPolicyDelegate() {
25 PermissionsData::SetPolicyDelegate(NULL);
28 bool RendererPermissionsPolicyDelegate::CanExecuteScriptOnPage(
29 const Extension* extension,
30 const GURL& document_url,
31 const GURL& top_document_url,
32 int tab_id,
33 int process_id,
34 std::string* error) {
35 const ExtensionsClient::ScriptingWhitelist& whitelist =
36 ExtensionsClient::Get()->GetScriptingWhitelist();
37 if (std::find(whitelist.begin(), whitelist.end(), extension->id()) !=
38 whitelist.end()) {
39 return true;
42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
43 if (command_line->HasSwitch(::switches::kSigninProcess)) {
44 if (error)
45 *error = errors::kCannotScriptSigninPage;
46 return false;
49 if (dispatcher_->IsExtensionActive(kWebStoreAppId)) {
50 if (error)
51 *error = errors::kCannotScriptGallery;
52 return false;
55 return true;
58 } // namespace extensions