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