| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 5 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_util.h" | 9 #include "chrome/browser/extensions/extension_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profiles_state.h" | 11 #include "chrome/browser/profiles/profiles_state.h" |
| 12 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" | 12 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" |
| 13 #include "chrome/browser/ui/user_manager.h" | 13 #include "chrome/browser/ui/user_manager.h" |
| 14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "extensions/browser/extension_prefs.h" | 16 #include "extensions/browser/extension_prefs.h" |
| 17 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
| 19 | 19 |
| 20 using extensions::Extension; | 20 using extensions::Extension; |
| 21 | 21 |
| 22 ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile, | 22 ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile, |
| 23 const std::string& extension_id, | 23 const std::string& extension_id, |
| 24 ExtensionEnableFlowDelegate* delegate) | 24 ExtensionEnableFlowDelegate* delegate) |
| 25 : profile_(profile), | 25 : profile_(profile), |
| 26 extension_id_(extension_id), | 26 extension_id_(extension_id), |
| 27 delegate_(delegate), | 27 delegate_(delegate), |
| 28 parent_contents_(NULL), | 28 parent_contents_(NULL), |
| 29 parent_window_(NULL), | 29 parent_window_(NULL), |
| 30 extension_registry_observer_(this) { | 30 extension_registry_observer_(this), |
| 31 } | 31 weak_ptr_factory_(this) {} |
| 32 | 32 |
| 33 ExtensionEnableFlow::~ExtensionEnableFlow() { | 33 ExtensionEnableFlow::~ExtensionEnableFlow() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 void ExtensionEnableFlow::StartForWebContents( | 36 void ExtensionEnableFlow::StartForWebContents( |
| 37 content::WebContents* parent_contents) { | 37 content::WebContents* parent_contents) { |
| 38 parent_contents_ = parent_contents; | 38 parent_contents_ = parent_contents; |
| 39 parent_window_ = NULL; | 39 parent_window_ = NULL; |
| 40 Run(); | 40 Run(); |
| 41 } | 41 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 service->EnableExtension(extension_id_); | 110 service->EnableExtension(extension_id_); |
| 111 | 111 |
| 112 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us. | 112 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us. |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 | 115 |
| 116 CreatePrompt(); | 116 CreatePrompt(); |
| 117 ExtensionInstallPrompt::PromptType type = | 117 ExtensionInstallPrompt::PromptType type = |
| 118 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(profile_, | 118 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(profile_, |
| 119 extension); | 119 extension); |
| 120 prompt_->ShowDialog(this, extension, nullptr, | 120 prompt_->ShowDialog(base::Bind(&ExtensionEnableFlow::InstallPromptDone, |
| 121 weak_ptr_factory_.GetWeakPtr()), |
| 122 extension, nullptr, |
| 121 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), | 123 make_scoped_ptr(new ExtensionInstallPrompt::Prompt(type)), |
| 122 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 124 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void ExtensionEnableFlow::CreatePrompt() { | 127 void ExtensionEnableFlow::CreatePrompt() { |
| 126 if (!window_getter_.is_null()) | 128 if (!window_getter_.is_null()) |
| 127 parent_window_ = window_getter_.Run(); | 129 parent_window_ = window_getter_.Run(); |
| 128 prompt_.reset(parent_contents_ ? | 130 prompt_.reset(parent_contents_ ? |
| 129 new ExtensionInstallPrompt(parent_contents_) : | 131 new ExtensionInstallPrompt(parent_contents_) : |
| 130 new ExtensionInstallPrompt(profile_, parent_window_)); | 132 new ExtensionInstallPrompt(profile_, parent_window_)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void ExtensionEnableFlow::OnExtensionUninstalled( | 165 void ExtensionEnableFlow::OnExtensionUninstalled( |
| 164 content::BrowserContext* browser_context, | 166 content::BrowserContext* browser_context, |
| 165 const Extension* extension, | 167 const Extension* extension, |
| 166 extensions::UninstallReason reason) { | 168 extensions::UninstallReason reason) { |
| 167 if (extension->id() == extension_id_) { | 169 if (extension->id() == extension_id_) { |
| 168 StopObserving(); | 170 StopObserving(); |
| 169 delegate_->ExtensionEnableFlowAborted(false); | 171 delegate_->ExtensionEnableFlowAborted(false); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| 173 void ExtensionEnableFlow::InstallUIProceed() { | 175 void ExtensionEnableFlow::InstallPromptDone( |
| 174 ExtensionService* service = | 176 ExtensionInstallPrompt::Result result) { |
| 175 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 177 if (result == ExtensionInstallPrompt::Result::ACCEPTED) { |
| 178 ExtensionService* service = |
| 179 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 176 | 180 |
| 177 // The extension can be uninstalled in another window while the UI was | 181 // The extension can be uninstalled in another window while the UI was |
| 178 // showing. Treat it as a cancellation and notify |delegate_|. | 182 // showing. Treat it as a cancellation and notify |delegate_|. |
| 179 const Extension* extension = service->GetExtensionById(extension_id_, true); | 183 const Extension* extension = service->GetExtensionById(extension_id_, true); |
| 180 if (!extension) { | 184 if (!extension) { |
| 181 delegate_->ExtensionEnableFlowAborted(true); | 185 delegate_->ExtensionEnableFlowAborted(true); |
| 182 return; | 186 return; |
| 187 } |
| 188 |
| 189 service->GrantPermissionsAndEnableExtension(extension); |
| 190 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us. |
| 191 } else { |
| 192 delegate_->ExtensionEnableFlowAborted( |
| 193 result == ExtensionInstallPrompt::Result::USER_CANCELED); |
| 194 // |delegate_| may delete us. |
| 183 } | 195 } |
| 184 | |
| 185 service->GrantPermissionsAndEnableExtension(extension); | |
| 186 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us. | |
| 187 } | 196 } |
| 188 | |
| 189 void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) { | |
| 190 delegate_->ExtensionEnableFlowAborted(user_initiated); | |
| 191 // |delegate_| may delete us. | |
| 192 } | |
| OLD | NEW |