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/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" | |
|
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
| |
| 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 // CHECK host so that non-GTK platform compilers don't complain about unused | |
| 37 // variables. | |
| 38 // TODO(mihaip): remove when ShellWindow has been implemented everywhere. | |
| 39 CHECK(host); | |
| 40 | |
| 41 #if defined(TOOLKIT_USES_GTK) | |
| 42 // This object will delete itself when the window is closed. | |
| 43 return new ShellWindowGtk(host); | |
| 44 #endif | |
| 45 | |
| 46 return NULL; | |
| 47 } | |
| 48 | |
| 49 void ShellWindow::Observe(int type, | |
| 50 const content::NotificationSource& source, | |
| 51 const content::NotificationDetails& details) { | |
| 52 switch (type) { | |
| 53 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | |
| 54 if (content::Details<ExtensionHost>(host_.get()) == details) | |
| 55 Close(); | |
| 56 break; | |
| 57 default: | |
| 58 NOTREACHED() << "Received unexpected notification"; | |
| 59 } | |
| 60 } | |
| OLD | NEW |