OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/extensions/external_install_ui.h" | 5 #include "chrome/browser/extensions/external_install_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // content::NotificationObserver: | 94 // content::NotificationObserver: |
95 virtual void Observe(int type, | 95 virtual void Observe(int type, |
96 const content::NotificationSource& source, | 96 const content::NotificationSource& source, |
97 const content::NotificationDetails& details) OVERRIDE; | 97 const content::NotificationDetails& details) OVERRIDE; |
98 | 98 |
99 // Show the install dialog to the user. | 99 // Show the install dialog to the user. |
100 void ShowInstallUI(); | 100 void ShowInstallUI(); |
101 | 101 |
102 // The UI for showing the install dialog when enabling. | 102 // The UI for showing the install dialog when enabling. |
103 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 103 scoped_ptr<ExtensionInstallPrompt> install_ui_; |
104 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt_; | 104 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_; |
105 | 105 |
106 Browser* browser_; | 106 Browser* browser_; |
107 base::WeakPtr<ExtensionService> service_weak_; | 107 base::WeakPtr<ExtensionService> service_weak_; |
108 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_; | 108 scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_; |
109 content::NotificationRegistrar registrar_; | 109 content::NotificationRegistrar registrar_; |
110 std::string extension_id_; | 110 std::string extension_id_; |
111 bool use_global_error_; | 111 bool use_global_error_; |
112 | 112 |
113 DISALLOW_COPY_AND_ASSIGN(ExternalInstallDialogDelegate); | 113 DISALLOW_COPY_AND_ASSIGN(ExternalInstallDialogDelegate); |
114 }; | 114 }; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Listen to extension load notifications. | 160 // Listen to extension load notifications. |
161 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 161 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
162 extension_registry_observer_; | 162 extension_registry_observer_; |
163 | 163 |
164 DISALLOW_COPY_AND_ASSIGN(ExternalInstallMenuAlert); | 164 DISALLOW_COPY_AND_ASSIGN(ExternalInstallMenuAlert); |
165 }; | 165 }; |
166 | 166 |
167 // Shows a menu item and a global error bubble, replacing the install dialog. | 167 // Shows a menu item and a global error bubble, replacing the install dialog. |
168 class ExternalInstallGlobalError : public ExternalInstallMenuAlert { | 168 class ExternalInstallGlobalError : public ExternalInstallMenuAlert { |
169 public: | 169 public: |
170 ExternalInstallGlobalError(ExtensionService* service, | 170 ExternalInstallGlobalError( |
171 const Extension* extension, | 171 ExtensionService* service, |
172 ExternalInstallDialogDelegate* delegate, | 172 const Extension* extension, |
173 const ExtensionInstallPrompt::Prompt& prompt); | 173 ExternalInstallDialogDelegate* delegate, |
| 174 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt); |
174 virtual ~ExternalInstallGlobalError(); | 175 virtual ~ExternalInstallGlobalError(); |
175 | 176 |
176 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; | 177 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; |
177 virtual bool HasBubbleView() OVERRIDE; | 178 virtual bool HasBubbleView() OVERRIDE; |
178 virtual gfx::Image GetBubbleViewIcon() OVERRIDE; | 179 virtual gfx::Image GetBubbleViewIcon() OVERRIDE; |
179 virtual base::string16 GetBubbleViewTitle() OVERRIDE; | 180 virtual base::string16 GetBubbleViewTitle() OVERRIDE; |
180 virtual std::vector<base::string16> GetBubbleViewMessages() OVERRIDE; | 181 virtual std::vector<base::string16> GetBubbleViewMessages() OVERRIDE; |
181 virtual base::string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; | 182 virtual base::string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; |
182 virtual base::string16 GetBubbleViewCancelButtonLabel() OVERRIDE; | 183 virtual base::string16 GetBubbleViewCancelButtonLabel() OVERRIDE; |
183 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; | 184 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; |
184 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; | 185 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; |
185 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; | 186 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; |
186 | 187 |
187 protected: | 188 protected: |
188 // Ref-counted, but needs to be disposed of if we are dismissed without | 189 // Ref-counted, but needs to be disposed of if we are dismissed without |
189 // having been clicked (perhaps because the user enabled the extension | 190 // having been clicked (perhaps because the user enabled the extension |
190 // manually). | 191 // manually). |
191 ExternalInstallDialogDelegate* delegate_; | 192 ExternalInstallDialogDelegate* delegate_; |
192 const ExtensionInstallPrompt::Prompt* prompt_; | 193 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_; |
193 | 194 |
194 private: | 195 private: |
195 DISALLOW_COPY_AND_ASSIGN(ExternalInstallGlobalError); | 196 DISALLOW_COPY_AND_ASSIGN(ExternalInstallGlobalError); |
196 }; | 197 }; |
197 | 198 |
198 static void CreateExternalInstallGlobalError( | 199 static void CreateExternalInstallGlobalError( |
199 base::WeakPtr<ExtensionService> service, | 200 base::WeakPtr<ExtensionService> service, |
200 const std::string& extension_id, | 201 const std::string& extension_id, |
201 const ExtensionInstallPrompt::ShowParams& show_params, | 202 const ExtensionInstallPrompt::ShowParams& show_params, |
202 ExtensionInstallPrompt::Delegate* prompt_delegate, | 203 ExtensionInstallPrompt::Delegate* prompt_delegate, |
203 const ExtensionInstallPrompt::Prompt& prompt) { | 204 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt) { |
204 if (!service.get()) | 205 if (!service.get()) |
205 return; | 206 return; |
206 const Extension* extension = service->GetInstalledExtension(extension_id); | 207 const Extension* extension = service->GetInstalledExtension(extension_id); |
207 if (!extension) | 208 if (!extension) |
208 return; | 209 return; |
209 GlobalErrorService* error_service = | 210 GlobalErrorService* error_service = |
210 GlobalErrorServiceFactory::GetForProfile(service->profile()); | 211 GlobalErrorServiceFactory::GetForProfile(service->profile()); |
211 if (error_service->GetGlobalErrorByMenuItemCommandID(kMenuCommandId)) | 212 if (error_service->GetGlobalErrorByMenuItemCommandID(kMenuCommandId)) |
212 return; | 213 return; |
213 | 214 |
(...skipping 21 matching lines...) Expand all Loading... |
235 Browser* browser, | 236 Browser* browser, |
236 ExtensionService* service, | 237 ExtensionService* service, |
237 const Extension* extension, | 238 const Extension* extension, |
238 bool use_global_error) | 239 bool use_global_error) |
239 : browser_(browser), | 240 : browser_(browser), |
240 service_weak_(service->AsWeakPtr()), | 241 service_weak_(service->AsWeakPtr()), |
241 extension_id_(extension->id()), | 242 extension_id_(extension->id()), |
242 use_global_error_(use_global_error) { | 243 use_global_error_(use_global_error) { |
243 AddRef(); // Balanced in Proceed or Abort. | 244 AddRef(); // Balanced in Proceed or Abort. |
244 | 245 |
245 prompt_.reset(new ExtensionInstallPrompt::Prompt( | 246 prompt_ = new ExtensionInstallPrompt::Prompt( |
246 ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT)); | 247 ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT); |
247 | 248 |
248 // If we don't have a browser, we can't go to the webstore to fetch data. | 249 // If we don't have a browser, we can't go to the webstore to fetch data. |
249 // This should only happen in tests. | 250 // This should only happen in tests. |
250 if (!browser) { | 251 if (!browser) { |
251 ShowInstallUI(); | 252 ShowInstallUI(); |
252 return; | 253 return; |
253 } | 254 } |
254 | 255 |
255 // Make sure to be notified if the owning profile is destroyed. | 256 // Make sure to be notified if the owning profile is destroyed. |
256 registrar_.Add(this, | 257 registrar_.Add(this, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 install_ui_.reset( | 318 install_ui_.reset( |
318 ExtensionInstallUI::CreateInstallPromptWithBrowser(browser_)); | 319 ExtensionInstallUI::CreateInstallPromptWithBrowser(browser_)); |
319 | 320 |
320 const ExtensionInstallPrompt::ShowDialogCallback callback = | 321 const ExtensionInstallPrompt::ShowDialogCallback callback = |
321 use_global_error_ ? | 322 use_global_error_ ? |
322 base::Bind(&CreateExternalInstallGlobalError, | 323 base::Bind(&CreateExternalInstallGlobalError, |
323 service_weak_, | 324 service_weak_, |
324 extension_id_) : | 325 extension_id_) : |
325 ExtensionInstallPrompt::GetDefaultShowDialogCallback(); | 326 ExtensionInstallPrompt::GetDefaultShowDialogCallback(); |
326 | 327 |
327 install_ui_->ConfirmExternalInstall(this, extension, callback, *prompt_); | 328 install_ui_->ConfirmExternalInstall(this, extension, callback, prompt_); |
328 } | 329 } |
329 | 330 |
330 ExternalInstallDialogDelegate::~ExternalInstallDialogDelegate() { | 331 ExternalInstallDialogDelegate::~ExternalInstallDialogDelegate() { |
331 } | 332 } |
332 | 333 |
333 void ExternalInstallDialogDelegate::InstallUIProceed() { | 334 void ExternalInstallDialogDelegate::InstallUIProceed() { |
334 const Extension* extension = NULL; | 335 const Extension* extension = NULL; |
335 if (service_weak_.get() && | 336 if (service_weak_.get() && |
336 (extension = service_weak_->GetInstalledExtension(extension_id_))) { | 337 (extension = service_weak_->GetInstalledExtension(extension_id_))) { |
337 service_weak_->GrantPermissionsAndEnableExtension(extension); | 338 service_weak_->GrantPermissionsAndEnableExtension(extension); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 service_->AcknowledgeExternalExtension(extension_->id()); | 455 service_->AcknowledgeExternalExtension(extension_->id()); |
455 delete this; | 456 delete this; |
456 } | 457 } |
457 | 458 |
458 // ExternalInstallGlobalError ----------------------------------------------- | 459 // ExternalInstallGlobalError ----------------------------------------------- |
459 | 460 |
460 ExternalInstallGlobalError::ExternalInstallGlobalError( | 461 ExternalInstallGlobalError::ExternalInstallGlobalError( |
461 ExtensionService* service, | 462 ExtensionService* service, |
462 const Extension* extension, | 463 const Extension* extension, |
463 ExternalInstallDialogDelegate* delegate, | 464 ExternalInstallDialogDelegate* delegate, |
464 const ExtensionInstallPrompt::Prompt& prompt) | 465 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt) |
465 : ExternalInstallMenuAlert(service, extension), | 466 : ExternalInstallMenuAlert(service, extension), |
466 delegate_(delegate), | 467 delegate_(delegate), |
467 prompt_(&prompt) { | 468 prompt_(prompt) { |
468 } | 469 } |
469 | 470 |
470 ExternalInstallGlobalError::~ExternalInstallGlobalError() { | 471 ExternalInstallGlobalError::~ExternalInstallGlobalError() { |
471 if (delegate_) | 472 if (delegate_) |
472 delegate_->Release(); | 473 delegate_->Release(); |
473 } | 474 } |
474 | 475 |
475 void ExternalInstallGlobalError::ExecuteMenuItem(Browser* browser) { | 476 void ExternalInstallGlobalError::ExecuteMenuItem(Browser* browser) { |
476 ShowBubbleView(browser); | 477 ShowBubbleView(browser); |
477 } | 478 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 | 582 |
582 bool HasExternalInstallBubble(ExtensionService* service) { | 583 bool HasExternalInstallBubble(ExtensionService* service) { |
583 GlobalErrorService* error_service = | 584 GlobalErrorService* error_service = |
584 GlobalErrorServiceFactory::GetForProfile(service->profile()); | 585 GlobalErrorServiceFactory::GetForProfile(service->profile()); |
585 GlobalError* error = error_service->GetGlobalErrorByMenuItemCommandID( | 586 GlobalError* error = error_service->GetGlobalErrorByMenuItemCommandID( |
586 kMenuCommandId); | 587 kMenuCommandId); |
587 return error && error->HasBubbleView(); | 588 return error && error->HasBubbleView(); |
588 } | 589 } |
589 | 590 |
590 } // namespace extensions | 591 } // namespace extensions |
OLD | NEW |