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/browser/extensions/browser_permissions_policy_delegate.h"
      6 
      7 #include "chrome/browser/browser_process.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #include "chrome/browser/profiles/profile_manager.h"
     10 #include "chrome/common/extensions/extension_manifest_constants.h"
     11 #include "content/public/browser/browser_thread.h"
     12 
     13 #if !defined(OS_CHROMEOS)
     14 #include "chrome/browser/signin/signin_manager.h"
     15 #include "chrome/browser/signin/signin_manager_factory.h"
     16 #endif
     17 
     18 namespace extensions {
     19 
     20 namespace errors = extension_manifest_errors;
     21 
     22 BrowserPermissionsPolicyDelegate::BrowserPermissionsPolicyDelegate() {
     23   PermissionsData::SetPolicyDelegate(this);
     24 }
     25 BrowserPermissionsPolicyDelegate::~BrowserPermissionsPolicyDelegate() {
     26   PermissionsData::SetPolicyDelegate(NULL);
     27 }
     28 
     29 bool BrowserPermissionsPolicyDelegate::CanExecuteScriptOnPage(
     30     const Extension* extension,
     31     const GURL& document_url,
     32     const GURL& top_document_url,
     33     int tab_id,
     34     const UserScript* script,
     35     int process_id,
     36     std::string* error) {
     37   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
     38 
     39 #if !defined(OS_CHROMEOS)
     40   // NULL in unit tests.
     41   if (!g_browser_process->profile_manager())
     42     return true;
     43 
     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)) {
     54       if (error)
     55         *error = errors::kCannotScriptSigninPage;
     56       return false;
     57     }
     58   }
     59 #endif
     60 
     61   return true;
     62 }
     63 
     64 }  // namespace extensions
     65