Index: chrome/browser/ui/views/screensaver_extension_dialog.cc |
diff --git a/chrome/browser/ui/views/screensaver_extension_dialog.cc b/chrome/browser/ui/views/screensaver_extension_dialog.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e4ee9074af4e44e283acf5192c439140041ef594 |
--- /dev/null |
+++ b/chrome/browser/ui/views/screensaver_extension_dialog.cc |
@@ -0,0 +1,137 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/screensaver_extension_dialog.h" |
+ |
+#include "base/bind.h" |
+#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/sessions/restore_tab_helper.h" |
+#include "chrome/browser/ui/views/extensions/extension_dialog.h" |
+#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/extensions/extension.h" |
+#include "chrome/common/extensions/extension_file_util.h" |
+ |
+using content::BrowserThread; |
+ |
+namespace { |
+ |
+ScreensaverExtensionDialog* g_instance = NULL; |
+ |
+} // namespace |
+ |
+namespace browser { |
+ |
+void ShowScreensaverDialog() { |
+ ScreensaverExtensionDialog::ShowScreensaverDialog(); |
+} |
+ |
+void CloseScreensaverDialog() { |
+ ScreensaverExtensionDialog::CloseScreensaverDialog(); |
+} |
+ |
+} // namespace browser |
+ |
+// static |
+void ScreensaverExtensionDialog::ShowScreensaverDialog() { |
+ 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.
|
+ return; |
+ |
+ g_instance = new ScreensaverExtensionDialog(); |
+ g_instance->Show(); |
+} |
+ |
+// static |
+void ScreensaverExtensionDialog::CloseScreensaverDialog() { |
+ if (g_instance) |
+ g_instance->Close(); |
+} |
+ |
+ScreensaverExtensionDialog::ScreensaverExtensionDialog() |
+ : screensaver_extension_(NULL) { |
+} |
+ |
+void ScreensaverExtensionDialog::LoadExtension() { |
+ 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.
|
+ std::string extension_path = CommandLine::ForCurrentProcess()-> |
+ GetSwitchValueASCII(switches::kKioskModeScreensaverPath); |
+ 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.
|
+ FilePath(extension_path), |
+ Extension::COMPONENT, |
+ Extension::NO_FLAGS, |
+ &error); |
+ |
+ if (!screensaver_extension_) { |
+ LOG(ERROR) << "Could not load screensaver extension from: " << |
+ extension_path; |
+ return; |
+ } |
+ |
+ BrowserThread::PostTask(BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind( |
+ &ScreensaverExtensionDialog::Show, |
+ base::Unretained(this))); |
+ |
+} |
+ |
+void ScreensaverExtensionDialog::Show() { |
+ if (!screensaver_extension_) { |
+ BrowserThread::PostTask(BrowserThread::FILE, |
+ FROM_HERE, |
+ base::Bind( |
+ &ScreensaverExtensionDialog::LoadExtension, |
+ base::Unretained(this))); |
+ return; |
+ } |
+ |
+ 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.
|
+ screensaver_extension_->id() + |
+ "/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.
|
+ |
+ 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.
|
+ 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
|
+ screensaver_extension_)) { |
+ extension_dialog_ = ExtensionDialog::ShowFullscreen(screensaver_url, |
+ default_profile, |
+ string16(), |
+ this); |
+ } else { |
+ LOG(ERROR) << "Couldn't add screensaver extension to profile."; |
+ } |
+} |
+ |
+void ScreensaverExtensionDialog::Close() { |
+ extension_dialog_->Close(); |
+ extension_dialog_ = NULL; |
+} |
+ |
+ScreensaverExtensionDialog::~ScreensaverExtensionDialog() { |
+ 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
|
+ extension_dialog_->ObserverDestroyed(); |
+} |
+ |
+void ScreensaverExtensionDialog::ExtensionDialogClosing( |
+ ExtensionDialog* dialog) { |
+ // Release our reference to the dialog to allow it to close. |
+ extension_dialog_ = NULL; |
+} |
+ |
+void ScreensaverExtensionDialog::ExtensionTerminated( |
+ ExtensionDialog* dialog) { |
+ 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
|
+ base::Bind(&ScreensaverExtensionDialog::ReloadAndShow, |
+ base::Unretained(this))); |
+ dialog->Close(); |
+} |
+ |
+void ScreensaverExtensionDialog::ReloadAndShow() { |
+ ProfileManager::GetDefaultProfile()->GetExtensionService()->ReloadExtension( |
+ screensaver_extension_->id()); |
+ |
+ Show(); |
+} |