Chromium Code Reviews| Index: chrome/browser/ui/extensions/shell_window.cc |
| diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e8147bf6eba091e129952509a9afbe8e9b2b6757 |
| --- /dev/null |
| +++ b/chrome/browser/ui/extensions/shell_window.cc |
| @@ -0,0 +1,60 @@ |
| +// 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/extensions/shell_window.h" |
| + |
| +#include "chrome/browser/extensions/extension_process_manager.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "content/public/browser/notification_source.h" |
| + |
| +#if defined(TOOLKIT_USES_GTK) |
| +#include "chrome/browser/ui/gtk/extensions/shell_window_gtk.h" |
|
sky
2012/01/06 20:10:25
General pattern for these sort of things is to def
Mihai Parparita -not on Chrome
2012/01/06 21:33:19
Done (I was following the pattern of ExtensionHost
|
| +#endif |
| + |
| +ShellWindow::ShellWindow(ExtensionHost* host) |
| + : host_(host) { |
| + // Close the window in response to window.close() and the like. |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| + content::Source<Profile>(host->profile())); |
| +} |
| + |
| +ShellWindow::~ShellWindow() { |
| +} |
| + |
| +ShellWindow* ShellWindow::Create(Profile* profile, |
| + const Extension* extension, |
| + const GURL& url) { |
| + ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); |
| + DCHECK(manager); |
| + if (!manager) |
| + return NULL; |
| + |
| + ExtensionHost* host = manager->CreateShellHost(extension, url); |
| + // CHECK host so that non-GTK platform compilers don't complain about unused |
| + // variables. |
| + // TODO(mihaip): remove when ShellWindow has been implemented everywhere. |
| + CHECK(host); |
| + |
| +#if defined(TOOLKIT_USES_GTK) |
| + // This object will delete itself when the window is closed. |
| + return new ShellWindowGtk(host); |
| +#endif |
| + |
| + return NULL; |
| +} |
| + |
| +void ShellWindow::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + switch (type) { |
| + case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| + if (content::Details<ExtensionHost>(host_.get()) == details) |
| + Close(); |
| + break; |
| + default: |
| + NOTREACHED() << "Received unexpected notification"; |
| + } |
| +} |