| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/ui/screensaver_extension_dialog.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/profiles/profile_manager.h" | |
| 14 #include "chrome/browser/sessions/restore_tab_helper.h" | |
| 15 #include "chrome/browser/ui/views/extensions/extension_dialog.h" | |
| 16 #include "chrome/common/chrome_switches.h" | |
| 17 #include "chrome/common/extensions/extension.h" | |
| 18 #include "chrome/common/extensions/extension_file_util.h" | |
| 19 | |
| 20 using content::BrowserThread; | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 ScreensaverExtensionDialog* g_instance = NULL; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 namespace browser { | |
| 29 | |
| 30 void ShowScreensaverDialog(scoped_refptr<Extension> extension) { | |
| 31 ScreensaverExtensionDialog::ShowScreensaverDialog(extension); | |
| 32 } | |
| 33 | |
| 34 void CloseScreensaverDialog() { | |
| 35 ScreensaverExtensionDialog::CloseScreensaverDialog(); | |
| 36 } | |
| 37 | |
| 38 } // namespace browser | |
| 39 | |
| 40 // static | |
| 41 void ScreensaverExtensionDialog::ShowScreensaverDialog( | |
| 42 scoped_refptr<Extension> extension) { | |
| 43 if (!g_instance) | |
| 44 g_instance = new ScreensaverExtensionDialog(extension); | |
| 45 g_instance->Show(); | |
| 46 } | |
| 47 | |
| 48 // static | |
| 49 void ScreensaverExtensionDialog::CloseScreensaverDialog() { | |
| 50 if (g_instance) | |
| 51 g_instance->Close(); | |
| 52 } | |
| 53 | |
| 54 ScreensaverExtensionDialog::ScreensaverExtensionDialog( | |
| 55 scoped_refptr<Extension> extension) | |
| 56 : screensaver_extension_(extension) { | |
| 57 } | |
| 58 | |
| 59 void ScreensaverExtensionDialog::Show() { | |
| 60 if (!screensaver_extension_) | |
| 61 return; | |
| 62 | |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 64 Profile* default_profile = ProfileManager::GetDefaultProfile(); | |
| 65 if (default_profile->GetExtensionService()->AddExtension( | |
| 66 screensaver_extension_)) { | |
| 67 extension_dialog_ = ExtensionDialog::ShowFullscreen( | |
| 68 screensaver_extension_->GetFullLaunchURL(), | |
| 69 default_profile, | |
| 70 string16(), | |
| 71 this); | |
| 72 } else { | |
| 73 LOG(ERROR) << "Couldn't add screensaver extension to profile."; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 void ScreensaverExtensionDialog::Close() { | |
| 78 if (extension_dialog_) { | |
| 79 extension_dialog_->Close(); | |
| 80 extension_dialog_ = NULL; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 ScreensaverExtensionDialog::~ScreensaverExtensionDialog() { | |
| 85 if (extension_dialog_) | |
| 86 extension_dialog_->ObserverDestroyed(); | |
| 87 } | |
| 88 | |
| 89 void ScreensaverExtensionDialog::ExtensionDialogClosing( | |
| 90 ExtensionDialog* dialog) { | |
| 91 // Release our reference to the dialog to allow it to close. | |
| 92 extension_dialog_ = NULL; | |
| 93 } | |
| 94 | |
| 95 void ScreensaverExtensionDialog::ExtensionTerminated( | |
| 96 ExtensionDialog* dialog) { | |
| 97 // This needs to be run 'slightly' delayed. When we get the extension | |
| 98 // terminated notification, the extension isn't fully unloaded yet. There | |
| 99 // is no good way to get around this. The correct solution will be to | |
| 100 // not need to reload the extension at all - but the current wiring in | |
| 101 // ExtensionViewsHost makes that not possible. | |
| 102 MessageLoop::current()->PostTask(FROM_HERE, | |
| 103 base::Bind(&ScreensaverExtensionDialog::ReloadAndShow, | |
| 104 base::Unretained(this))); | |
| 105 dialog->Close(); | |
| 106 } | |
| 107 | |
| 108 void ScreensaverExtensionDialog::ReloadAndShow() { | |
| 109 ProfileManager::GetDefaultProfile()->GetExtensionService()->ReloadExtension( | |
| 110 screensaver_extension_->id()); | |
| 111 | |
| 112 Show(); | |
| 113 } | |
| OLD | NEW |