Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / browser / extensions / browser_permissions_policy_delegate.cc
blob322605ce353e82452e53118cb88e5cf06a825930
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/browser/extensions/browser_permissions_policy_delegate.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "extensions/common/manifest_constants.h"
13 #if !defined(OS_CHROMEOS)
14 #include "chrome/browser/signin/chrome_signin_client.h"
15 #include "chrome/browser/signin/chrome_signin_client_factory.h"
16 #endif
18 namespace extensions {
20 namespace errors = manifest_errors;
22 BrowserPermissionsPolicyDelegate::BrowserPermissionsPolicyDelegate() {
23 PermissionsData::SetPolicyDelegate(this);
25 BrowserPermissionsPolicyDelegate::~BrowserPermissionsPolicyDelegate() {
26 PermissionsData::SetPolicyDelegate(NULL);
29 bool BrowserPermissionsPolicyDelegate::CanExecuteScriptOnPage(
30 const Extension* extension,
31 const GURL& document_url,
32 const GURL& top_document_url,
33 int tab_id,
34 int process_id,
35 std::string* error) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
38 #if !defined(OS_CHROMEOS)
39 // NULL in unit tests.
40 if (!g_browser_process->profile_manager())
41 return true;
43 // We don't have a Profile in this context. That's OK - for our purposes,
44 // we can just check every Profile for its signin process. If any of them
45 // match, block script access.
46 std::vector<Profile*> profiles =
47 g_browser_process->profile_manager()->GetLoadedProfiles();
48 for (std::vector<Profile*>::iterator profile = profiles.begin();
49 profile != profiles.end(); ++profile) {
50 SigninClient* signin_client =
51 ChromeSigninClientFactory::GetForProfile(*profile);
52 if (signin_client && signin_client->IsSigninProcess(process_id)) {
53 if (error)
54 *error = errors::kCannotScriptSigninPage;
55 return false;
58 #endif
60 return true;
63 } // namespace extensions