Chromium Code Reviews| 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/ui/views/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/extensions/extension_service.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/profiles/profile_manager.h" | |
| 13 #include "chrome/browser/sessions/restore_tab_helper.h" | |
| 14 #include "chrome/browser/ui/views/extensions/extension_dialog.h" | |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "chrome/common/extensions/extension.h" | |
| 17 #include "chrome/common/extensions/extension_file_util.h" | |
| 18 | |
| 19 using content::BrowserThread; | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 ScreensaverExtensionDialog* g_instance = NULL; | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 namespace browser { | |
| 28 | |
| 29 void ShowScreensaverDialog() { | |
| 30 ScreensaverExtensionDialog::ShowScreensaverDialog(); | |
| 31 } | |
| 32 | |
| 33 void CloseScreensaverDialog() { | |
| 34 ScreensaverExtensionDialog::CloseScreensaverDialog(); | |
| 35 } | |
| 36 | |
| 37 } // namespace browser | |
| 38 | |
| 39 // static | |
| 40 void ScreensaverExtensionDialog::ShowScreensaverDialog() { | |
| 41 if (g_instance) | |
|
Yoyo Zhou
2012/02/24 21:51:05
So once the screensaver is closed, it will never a
rkc
2012/02/25 02:14:02
This is incorrect code, fixed.
Done.
| |
| 42 return; | |
| 43 | |
| 44 g_instance = new ScreensaverExtensionDialog(); | |
| 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 : screensaver_extension_(NULL) { | |
| 56 } | |
| 57 | |
| 58 void ScreensaverExtensionDialog::LoadExtension() { | |
| 59 std::string error; | |
|
sky
2012/02/24 05:03:53
If this needs to run on a specific thread, DCHECK
rkc
2012/02/25 02:14:02
Done.
| |
| 60 std::string extension_path = CommandLine::ForCurrentProcess()-> | |
| 61 GetSwitchValueASCII(switches::kKioskModeScreensaverPath); | |
| 62 screensaver_extension_ = extension_file_util::LoadExtension( | |
|
Yoyo Zhou
2012/02/24 21:51:05
This should probably call Extension::Create, but s
rkc
2012/02/25 02:14:02
Answered below.
| |
| 63 FilePath(extension_path), | |
| 64 Extension::COMPONENT, | |
| 65 Extension::NO_FLAGS, | |
| 66 &error); | |
| 67 | |
| 68 if (!screensaver_extension_) { | |
| 69 LOG(ERROR) << "Could not load screensaver extension from: " << | |
| 70 extension_path; | |
| 71 return; | |
| 72 } | |
| 73 | |
| 74 BrowserThread::PostTask(BrowserThread::UI, | |
| 75 FROM_HERE, | |
| 76 base::Bind( | |
| 77 &ScreensaverExtensionDialog::Show, | |
| 78 base::Unretained(this))); | |
| 79 | |
| 80 } | |
| 81 | |
| 82 void ScreensaverExtensionDialog::Show() { | |
| 83 if (!screensaver_extension_) { | |
| 84 BrowserThread::PostTask(BrowserThread::FILE, | |
| 85 FROM_HERE, | |
| 86 base::Bind( | |
| 87 &ScreensaverExtensionDialog::LoadExtension, | |
| 88 base::Unretained(this))); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 GURL screensaver_url("chrome-extension://" + | |
|
sky
2012/02/24 05:03:53
Surely there must be constants for this sort of th
Yoyo Zhou
2012/02/24 21:51:05
Use Extension::GetResourceURL for this.
rkc
2012/02/25 02:14:02
Done.
rkc
2012/02/25 02:14:02
Done.
| |
| 93 screensaver_extension_->id() + | |
| 94 "/background.html"); | |
|
Yoyo Zhou
2012/02/24 21:51:05
Why hardcode this? Also, there seems to be no reas
rkc
2012/02/25 02:14:02
Done.
| |
| 95 | |
| 96 Profile* default_profile = ProfileManager::GetDefaultProfile(); | |
|
Yoyo Zhou
2012/02/24 21:51:05
Are you sure this will be the correct profile? I'm
rkc
2012/02/25 02:14:02
This is the only profile available during login.
| |
| 97 if (default_profile->GetExtensionService()->AddExtension( | |
|
Yoyo Zhou
2012/02/24 21:51:05
If this is a component extension it should use Com
rkc
2012/02/25 02:14:02
This isn't a component extension but we need it lo
| |
| 98 screensaver_extension_)) { | |
| 99 extension_dialog_ = ExtensionDialog::ShowFullscreen(screensaver_url, | |
| 100 default_profile, | |
| 101 string16(), | |
| 102 this); | |
| 103 } else { | |
| 104 LOG(ERROR) << "Couldn't add screensaver extension to profile."; | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void ScreensaverExtensionDialog::Close() { | |
| 109 extension_dialog_->Close(); | |
| 110 extension_dialog_ = NULL; | |
| 111 } | |
| 112 | |
| 113 ScreensaverExtensionDialog::~ScreensaverExtensionDialog() { | |
| 114 if (extension_dialog_) | |
|
sky
2012/02/24 05:03:53
Who deletes this class?
rkc
2012/02/25 02:14:02
I believe extension_dialog_ deletes itself by call
| |
| 115 extension_dialog_->ObserverDestroyed(); | |
| 116 } | |
| 117 | |
| 118 void ScreensaverExtensionDialog::ExtensionDialogClosing( | |
| 119 ExtensionDialog* dialog) { | |
| 120 // Release our reference to the dialog to allow it to close. | |
| 121 extension_dialog_ = NULL; | |
| 122 } | |
| 123 | |
| 124 void ScreensaverExtensionDialog::ExtensionTerminated( | |
| 125 ExtensionDialog* dialog) { | |
| 126 MessageLoop::current()->PostTask(FROM_HERE, | |
|
sky
2012/02/24 05:03:53
Why does this need to be delayed?
rkc
2012/02/25 02:14:02
If we don't delay this, the extension hasn't actua
| |
| 127 base::Bind(&ScreensaverExtensionDialog::ReloadAndShow, | |
| 128 base::Unretained(this))); | |
| 129 dialog->Close(); | |
| 130 } | |
| 131 | |
| 132 void ScreensaverExtensionDialog::ReloadAndShow() { | |
| 133 ProfileManager::GetDefaultProfile()->GetExtensionService()->ReloadExtension( | |
| 134 screensaver_extension_->id()); | |
| 135 | |
| 136 Show(); | |
| 137 } | |
| OLD | NEW |