Home | History | Annotate | Download | only in extensions
      1 // Copyright 2014 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_EXTENSION_ERROR_CONTROLLER_H_
      6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_CONTROLLER_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "chrome/browser/extensions/extension_error_ui.h"
     10 #include "extensions/common/extension_set.h"
     11 
     12 namespace content {
     13 class BrowserContext;
     14 }
     15 
     16 namespace extensions {
     17 
     18 // The controller for the ExtensionErrorUI. This examines extensions for any
     19 // blacklisted or external extensions in order to notify the user with an error.
     20 // On acceptance, this will acknowledge the extensions.
     21 class ExtensionErrorController : public ExtensionErrorUI::Delegate {
     22  public:
     23   typedef ExtensionErrorUI* (*UICreateMethod)(ExtensionErrorUI::Delegate*);
     24 
     25   ExtensionErrorController(content::BrowserContext* context, bool is_first_run);
     26   virtual ~ExtensionErrorController();
     27 
     28   void ShowErrorIfNeeded();
     29 
     30   // Set the factory method for creating a new ExtensionErrorUI.
     31   static void SetUICreateMethodForTesting(UICreateMethod method);
     32 
     33  private:
     34   // ExtensionErrorUI::Delegate implementation:
     35   virtual content::BrowserContext* GetContext() OVERRIDE;
     36   virtual const ExtensionSet& GetExternalExtensions() OVERRIDE;
     37   virtual const ExtensionSet& GetBlacklistedExtensions() OVERRIDE;
     38   virtual void OnAlertDetails() OVERRIDE;
     39   virtual void OnAlertAccept() OVERRIDE;
     40   virtual void OnAlertClosed() OVERRIDE;
     41 
     42   // Find any extensions that the user should be alerted about (like blacklisted
     43   // extensions).
     44   void IdentifyAlertableExtensions();
     45 
     46   // TODO(rdevlin.cronin): We never seem to use |external_extensions_| here,
     47   // but we do warn about them. Investigate more.
     48   ExtensionSet external_extensions_;
     49 
     50   // The extensions that are blacklisted and need user approval.
     51   ExtensionSet blacklisted_extensions_;
     52 
     53   // The UI component of this controller.
     54   scoped_ptr<ExtensionErrorUI> error_ui_;
     55 
     56   // The BrowserContext with which we are associated.
     57   content::BrowserContext* browser_context_;
     58 
     59   // Whether or not this is the first run. If it is, we avoid noisy errors, and
     60   // silently acknowledge blacklisted extensions.
     61   bool is_first_run_;
     62 
     63   DISALLOW_COPY_AND_ASSIGN(ExtensionErrorController);
     64 };
     65 
     66 }  // namespace extensions
     67 
     68 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_CONTROLLER_H_
     69