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_EXTERNAL_INSTALL_ERROR_H_
      6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_
      7 
      8 #include <string>
      9 
     10 #include "base/macros.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "chrome/browser/extensions/extension_install_prompt.h"
     14 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h"
     15 
     16 class Browser;
     17 class ExtensionInstallUI;
     18 class GlobalError;
     19 class GlobalErrorService;
     20 
     21 namespace content {
     22 class BrowserContext;
     23 }
     24 
     25 namespace extensions {
     26 class Extension;
     27 class ExternalInstallManager;
     28 class WebstoreDataFetcher;
     29 
     30 // An error to show the user an extension has been externally installed. The
     31 // error will automatically fetch data about the extension from the webstore (if
     32 // possible) and will handle adding itself to the GlobalErrorService when
     33 // initialized and removing itself from the GlobalErrorService upon
     34 // destruction.
     35 class ExternalInstallError : public ExtensionInstallPrompt::Delegate,
     36                              public WebstoreDataFetcherDelegate {
     37  public:
     38   // The possible types of errors to show. A menu alert adds a menu item to the
     39   // wrench, which spawns an extension install dialog when clicked. The bubble
     40   // alert also adds an item, but spawns a bubble instead (less invasive and
     41   // easier to dismiss).
     42   enum AlertType {
     43     BUBBLE_ALERT,
     44     MENU_ALERT
     45   };
     46 
     47   ExternalInstallError(content::BrowserContext* browser_context,
     48                        const std::string& extension_id,
     49                        AlertType error_type,
     50                        ExternalInstallManager* manager);
     51   virtual ~ExternalInstallError();
     52 
     53   // ExtensionInstallPrompt::Delegate implementation.
     54   virtual void InstallUIProceed() OVERRIDE;
     55   virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
     56 
     57   // Show the associated dialog. This should only be called once the dialog is
     58   // ready.
     59   void ShowDialog(Browser* browser);
     60 
     61   // Return the associated extension, or NULL.
     62   const Extension* GetExtension() const;
     63 
     64   const std::string& extension_id() const { return extension_id_; }
     65   AlertType alert_type() const { return alert_type_; }
     66 
     67  private:
     68   // WebstoreDataFetcherDelegate implementation.
     69   virtual void OnWebstoreRequestFailure() OVERRIDE;
     70   virtual void OnWebstoreResponseParseSuccess(
     71       scoped_ptr<base::DictionaryValue> webstore_data) OVERRIDE;
     72   virtual void OnWebstoreResponseParseFailure(
     73       const std::string& error) OVERRIDE;
     74 
     75   // Called when data fetching has completed (either successfully or not).
     76   void OnFetchComplete();
     77 
     78   // Called when the dialog has been successfully populated, and is ready to be
     79   // shown.
     80   void OnDialogReady(const ExtensionInstallPrompt::ShowParams& show_params,
     81                      ExtensionInstallPrompt::Delegate* prompt_delegate,
     82                      scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
     83 
     84   // The associated BrowserContext.
     85   content::BrowserContext* browser_context_;
     86 
     87   // The id of the external extension.
     88   std::string extension_id_;
     89 
     90   // The type of alert to show the user.
     91   AlertType alert_type_;
     92 
     93   // The owning ExternalInstallManager.
     94   ExternalInstallManager* manager_;
     95 
     96   // The associated GlobalErrorService.
     97   GlobalErrorService* error_service_;
     98 
     99   // The UI for showing the error.
    100   scoped_ptr<ExtensionInstallPrompt> install_ui_;
    101   scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_;
    102 
    103   // The UI for the given error, which will take the form of either a menu
    104   // alert or a bubble alert (depending on the |alert_type_|.
    105   scoped_ptr<GlobalError> global_error_;
    106 
    107   // The WebstoreDataFetcher to use in order to populate the error with webstore
    108   // information of the extension.
    109   scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_;
    110 
    111   base::WeakPtrFactory<ExternalInstallError> weak_factory_;
    112 
    113   DISALLOW_COPY_AND_ASSIGN(ExternalInstallError);
    114 };
    115 
    116 }  // namespace extensions
    117 
    118 #endif  // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_ERROR_H_
    119