Home | History | Annotate | Download | only in permissions
      1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_PERMISSIONS_PERMISSIONS_API_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_PERMISSIONS_PERMISSIONS_API_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "chrome/browser/extensions/chrome_extension_function.h"
     12 #include "chrome/browser/extensions/extension_install_prompt.h"
     13 #include "extensions/common/permissions/permission_set.h"
     14 
     15 class ExtensionService;
     16 
     17 namespace extensions {
     18 
     19 // chrome.permissions.contains
     20 class PermissionsContainsFunction : public ChromeSyncExtensionFunction {
     21  public:
     22   DECLARE_EXTENSION_FUNCTION("permissions.contains", PERMISSIONS_CONTAINS)
     23 
     24  protected:
     25   virtual ~PermissionsContainsFunction() {}
     26 
     27   // ExtensionFunction:
     28   virtual bool RunImpl() OVERRIDE;
     29 };
     30 
     31 // chrome.permissions.getAll
     32 class PermissionsGetAllFunction : public ChromeSyncExtensionFunction {
     33  public:
     34   DECLARE_EXTENSION_FUNCTION("permissions.getAll", PERMISSIONS_GETALL)
     35 
     36  protected:
     37   virtual ~PermissionsGetAllFunction() {}
     38 
     39   // ExtensionFunction:
     40   virtual bool RunImpl() OVERRIDE;
     41 };
     42 
     43 // chrome.permissions.remove
     44 class PermissionsRemoveFunction : public ChromeSyncExtensionFunction {
     45  public:
     46   DECLARE_EXTENSION_FUNCTION("permissions.remove", PERMISSIONS_REMOVE)
     47 
     48  protected:
     49   virtual ~PermissionsRemoveFunction() {}
     50 
     51   // ExtensionFunction:
     52   virtual bool RunImpl() OVERRIDE;
     53 };
     54 
     55 // chrome.permissions.request
     56 class PermissionsRequestFunction : public ChromeAsyncExtensionFunction,
     57                                    public ExtensionInstallPrompt::Delegate {
     58  public:
     59   DECLARE_EXTENSION_FUNCTION("permissions.request", PERMISSIONS_REQUEST)
     60 
     61   PermissionsRequestFunction();
     62 
     63   // FOR TESTS ONLY to bypass the confirmation UI.
     64   static void SetAutoConfirmForTests(bool should_proceed);
     65   static void SetIgnoreUserGestureForTests(bool ignore);
     66 
     67   // ExtensionInstallPrompt::Delegate:
     68   virtual void InstallUIProceed() OVERRIDE;
     69   virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
     70 
     71  protected:
     72   virtual ~PermissionsRequestFunction();
     73 
     74   // ExtensionFunction:
     75   virtual bool RunImpl() OVERRIDE;
     76 
     77  private:
     78   scoped_ptr<ExtensionInstallPrompt> install_ui_;
     79   scoped_refptr<extensions::PermissionSet> requested_permissions_;
     80 };
     81 
     82 }  // namespace extensions
     83 
     84 #endif  // CHROME_BROWSER_EXTENSIONS_API_PERMISSIONS_PERMISSIONS_API_H_
     85