1// Copyright (c) 2011 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_INSTALL_UI_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_
7#pragma once
8
9#include <string>
10#include <vector>
11
12#include "base/string16.h"
13#include "chrome/browser/extensions/image_loading_tracker.h"
14#include "chrome/common/extensions/url_pattern.h"
15#include "third_party/skia/include/core/SkBitmap.h"
16#include "ui/gfx/native_widget_types.h"
17
18class Extension;
19class MessageLoop;
20class Profile;
21class InfoBarDelegate;
22class TabContents;
23
24// Displays all the UI around extension installation and uninstallation.
25class ExtensionInstallUI : public ImageLoadingTracker::Observer {
26 public:
27  enum PromptType {
28    UNSET_PROMPT_TYPE = -1,
29    INSTALL_PROMPT = 0,
30    RE_ENABLE_PROMPT,
31    NUM_PROMPT_TYPES
32  };
33
34  // A mapping from PromptType to message ID for various dialog content.
35  static const int kTitleIds[NUM_PROMPT_TYPES];
36  static const int kHeadingIds[NUM_PROMPT_TYPES];
37  static const int kButtonIds[NUM_PROMPT_TYPES];
38  static const int kWarningIds[NUM_PROMPT_TYPES];
39
40  class Delegate {
41   public:
42    // We call this method to signal that the installation should continue.
43    virtual void InstallUIProceed() = 0;
44
45    // We call this method to signal that the installation should stop.
46    virtual void InstallUIAbort() = 0;
47
48   protected:
49    virtual ~Delegate() {}
50  };
51
52  explicit ExtensionInstallUI(Profile* profile);
53  virtual ~ExtensionInstallUI();
54
55  // This is called by the installer to verify whether the installation should
56  // proceed. This is declared virtual for testing.
57  //
58  // We *MUST* eventually call either Proceed() or Abort() on |delegate|.
59  virtual void ConfirmInstall(Delegate* delegate, const Extension* extension);
60
61  // This is called by the app handler launcher to verify whether the app
62  // should be re-enabled. This is declared virtual for testing.
63  //
64  // We *MUST* eventually call either Proceed() or Abort() on |delegate|.
65  virtual void ConfirmReEnable(Delegate* delegate, const Extension* extension);
66
67  // Installation was successful. This is declared virtual for testing.
68  virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon);
69
70  // Installation failed. This is declared virtual for testing.
71  virtual void OnInstallFailure(const std::string& error);
72
73  // ImageLoadingTracker::Observer:
74  virtual void OnImageLoaded(
75      SkBitmap* image, const ExtensionResource& resource, int index);
76
77  // Show an infobar for a newly-installed theme.  previous_theme_id
78  // should be empty if the previous theme was the system/default
79  // theme.
80  //
81  // TODO(akalin): Find a better home for this (and
82  // GetNewThemeInstalledInfoBarDelegate()).
83  static void ShowThemeInfoBar(
84      const std::string& previous_theme_id, bool previous_use_system_theme,
85      const Extension* new_theme, Profile* profile);
86
87 private:
88  // Sets the icon that will be used in any UI. If |icon| is NULL, or contains
89  // an empty bitmap, then a default icon will be used instead.
90  void SetIcon(SkBitmap* icon);
91
92  // Starts the process of showing a confirmation UI, which is split into two.
93  // 1) Set off a 'load icon' task.
94  // 2) Handle the load icon response and show the UI (OnImageLoaded).
95  void ShowConfirmation(PromptType prompt_type);
96
97  // Returns the delegate to control the browser's info bar. This is
98  // within its own function due to its platform-specific nature.
99  static InfoBarDelegate* GetNewThemeInstalledInfoBarDelegate(
100      TabContents* tab_contents,
101      const Extension* new_theme,
102      const std::string& previous_theme_id,
103      bool previous_use_system_theme);
104
105  Profile* profile_;
106  MessageLoop* ui_loop_;
107
108  // Used to undo theme installation.
109  std::string previous_theme_id_;
110  bool previous_use_system_theme_;
111
112  // The extensions installation icon.
113  SkBitmap icon_;
114
115  // The extension we are showing the UI for.
116  const Extension* extension_;
117
118  // The delegate we will call Proceed/Abort on after confirmation UI.
119  Delegate* delegate_;
120
121  // The type of prompt we are going to show.
122  PromptType prompt_type_;
123
124  // Keeps track of extension images being loaded on the File thread for the
125  // purpose of showing the install UI.
126  ImageLoadingTracker tracker_;
127};
128
129#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_
130