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/signin_manager.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
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
,
34 const UserScript
* script
,
37 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
39 #if !defined(OS_CHROMEOS)
40 // NULL in unit tests.
41 if (!g_browser_process
->profile_manager())
44 // We don't have a Profile in this context. That's OK - for our purposes,
45 // we can just check every Profile for its signin process. If any of them
46 // match, block script access.
47 std::vector
<Profile
*> profiles
=
48 g_browser_process
->profile_manager()->GetLoadedProfiles();
49 for (std::vector
<Profile
*>::iterator profile
= profiles
.begin();
50 profile
!= profiles
.end(); ++profile
) {
51 SigninManager
* signin_manager
=
52 SigninManagerFactory::GetForProfile(*profile
);
53 if (signin_manager
&& signin_manager
->IsSigninProcess(process_id
)) {
55 *error
= errors::kCannotScriptSigninPage
;
64 } // namespace extensions