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 ShellWindow::ShellWindow(ExtensionHost* host) |
| 14 : host_(host) { |
| 15 // Close the window in response to window.close() and the like. |
| 16 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 17 content::Source<Profile>(host->profile())); |
| 18 } |
| 19 |
| 20 ShellWindow::~ShellWindow() { |
| 21 } |
| 22 |
| 23 ShellWindow* ShellWindow::Create(Profile* profile, |
| 24 const Extension* extension, |
| 25 const GURL& url) { |
| 26 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); |
| 27 DCHECK(manager); |
| 28 if (!manager) |
| 29 return NULL; |
| 30 |
| 31 ExtensionHost* host = manager->CreateShellHost(extension, url); |
| 32 // CHECK host so that non-GTK platform compilers don't complain about unused |
| 33 // variables. |
| 34 // TODO(mihaip): remove when ShellWindow has been implemented everywhere. |
| 35 CHECK(host); |
| 36 |
| 37 #if defined(TOOLKIT_GTK) |
| 38 // This object will delete itself when the window is closed. |
| 39 // TODO(mihaip): remove the #if block when ShellWindow has been implemented |
| 40 // everywhere. |
| 41 return ShellWindow::CreateShellWindow(host); |
| 42 #endif |
| 43 |
| 44 return NULL; |
| 45 } |
| 46 |
| 47 void ShellWindow::Observe(int type, |
| 48 const content::NotificationSource& source, |
| 49 const content::NotificationDetails& details) { |
| 50 switch (type) { |
| 51 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| 52 if (content::Details<ExtensionHost>(host_.get()) == details) |
| 53 Close(); |
| 54 break; |
| 55 default: |
| 56 NOTREACHED() << "Received unexpected notification"; |
| 57 } |
| 58 } |
OLD | NEW |