OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/extensions/shell_window.h" |
| 6 |
| 7 #include "chrome/browser/extensions/extension_process_manager.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/chrome_notification_types.h" |
| 10 #include "content/public/browser/notification_details.h" |
| 11 #include "content/public/browser/notification_source.h" |
| 12 |
| 13 #if defined(TOOLKIT_USES_GTK) |
| 14 #include "chrome/browser/ui/gtk/extensions/shell_window_gtk.h" |
| 15 #endif |
| 16 |
| 17 ShellWindow::ShellWindow(ExtensionHost* host) |
| 18 : host_(host) { |
| 19 // Close the window in response to window.close() and the like. |
| 20 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 21 content::Source<Profile>(host->profile())); |
| 22 } |
| 23 |
| 24 ShellWindow::~ShellWindow() { |
| 25 } |
| 26 |
| 27 ShellWindow* ShellWindow::Create(Profile* profile, |
| 28 const Extension* extension, |
| 29 const GURL& url) { |
| 30 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); |
| 31 DCHECK(manager); |
| 32 if (!manager) |
| 33 return NULL; |
| 34 |
| 35 ExtensionHost* host = manager->CreateShellHost(extension, url); |
| 36 |
| 37 #if defined(TOOLKIT_USES_GTK) |
| 38 // This object will delete itself when the window is closed. |
| 39 return new ShellWindowGtk(host); |
| 40 #endif |
| 41 |
| 42 return NULL; |
| 43 } |
| 44 |
| 45 void ShellWindow::Observe(int type, |
| 46 const content::NotificationSource& source, |
| 47 const content::NotificationDetails& details) { |
| 48 switch (type) { |
| 49 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| 50 if (content::Details<ExtensionHost>(host_.get()) == details) |
| 51 Close(); |
| 52 break; |
| 53 default: |
| 54 NOTREACHED() << "Received unexpected notification"; |
| 55 } |
| 56 } |
OLD | NEW |