Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 10119003: Pull shell window stuff out of ExtensionHost and put in ShellWindow (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: More stuff Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/extensions/shell_window.h" 5 #include "chrome/browser/ui/extensions/shell_window.h"
6 6
7 #include "chrome/browser/ui/browser_list.h" 7 #include "chrome/browser/ui/browser_list.h"
8 #include "chrome/browser/extensions/extension_process_manager.h" 8 #include "chrome/browser/extensions/extension_process_manager.h"
9 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 9 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
10 #include "chrome/browser/extensions/extension_window_controller.h" 10 #include "chrome/browser/extensions/extension_window_controller.h"
11 #include "chrome/browser/extensions/platform_app_host.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sessions/session_id.h" 13 #include "chrome/browser/sessions/session_id.h"
13 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
15 #include "content/public/browser/notification_details.h" 16 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/notification_types.h" 19 #include "content/public/browser/notification_types.h"
19 20
20 namespace internal { 21 namespace internal {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } // namespace internal 78 } // namespace internal
78 79
79 ShellWindow* ShellWindow::Create(Profile* profile, 80 ShellWindow* ShellWindow::Create(Profile* profile,
80 const Extension* extension, 81 const Extension* extension,
81 const GURL& url) { 82 const GURL& url) {
82 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); 83 ExtensionProcessManager* manager = profile->GetExtensionProcessManager();
83 DCHECK(manager); 84 DCHECK(manager);
84 85
85 // This object will delete itself when the window is closed. 86 // This object will delete itself when the window is closed.
86 return ShellWindow::CreateShellWindow( 87 return ShellWindow::CreateShellWindow(
87 manager->CreateShellHost(extension, url)); 88 new PlatformAppHost(profile, url), extension);
88 } 89 }
89 90
90 void ShellWindow::Observe(int type, 91 void ShellWindow::Observe(int type,
91 const content::NotificationSource& source, 92 const content::NotificationSource& source,
92 const content::NotificationDetails& details) { 93 const content::NotificationDetails& details) {
93 switch (type) { 94 switch (type) {
94 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: 95 // TODO(benwells): Use new PLATFORM_HOST_VIEW_SHOULD_CLOSE
95 if (content::Details<ExtensionHost>(host_.get()) == details) 96 // case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE:
96 Close(); 97 // if (content::Details<ExtensionHost>(host_.get()) == details)
97 break; 98 // Close();
99 // break;
98 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 100 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
99 const Extension* unloaded_extension = 101 const Extension* unloaded_extension =
100 content::Details<UnloadedExtensionInfo>(details)->extension; 102 content::Details<UnloadedExtensionInfo>(details)->extension;
101 // We compare extension IDs and not Extension pointers since ExtensionHost 103 if (extension_ == unloaded_extension)
102 // nulls out its Extension pointer when it gets this notification.
103 if (host_->extension_id() == unloaded_extension->id())
104 Close(); 104 Close();
105 break; 105 break;
106 } 106 }
107 case content::NOTIFICATION_APP_TERMINATING: 107 case content::NOTIFICATION_APP_TERMINATING:
108 Close(); 108 Close();
109 break; 109 break;
110 default: 110 default:
111 NOTREACHED() << "Received unexpected notification"; 111 NOTREACHED() << "Received unexpected notification";
112 } 112 }
113 } 113 }
114 114
115 ShellWindow::ShellWindow(ExtensionHost* host) 115 ShellWindow::ShellWindow(PlatformAppHost* host, const Extension* extension)
116 : host_(host) { 116 : host_(host),
117 extension_(extension) {
117 // Close the window in response to window.close() and the like. 118 // Close the window in response to window.close() and the like.
118 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 119 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
119 content::Source<Profile>(host->profile())); 120 content::Source<Profile>(host->profile()));
120 // Also close if the window if the extension has been unloaded (parallels 121 // Also close if the window if the extension has been unloaded (parallels
121 // NOTIFICATION_EXTENSION_UNLOADED closing the app's tabs in TabStripModel). 122 // NOTIFICATION_EXTENSION_UNLOADED closing the app's tabs in TabStripModel).
122 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 123 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
123 content::Source<Profile>(host->profile())); 124 content::Source<Profile>(host->profile()));
124 // Close when the browser is exiting. 125 // Close when the browser is exiting.
125 // TODO(mihaip): we probably don't want this in the long run (when platform 126 // TODO(mihaip): we probably don't want this in the long run (when platform
126 // apps are no longer tied to the browser process). 127 // apps are no longer tied to the browser process).
127 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, 128 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
128 content::NotificationService::AllSources()); 129 content::NotificationService::AllSources());
129 130
130 // Prevent the browser process from shutting down while this window is open. 131 // Prevent the browser process from shutting down while this window is open.
131 BrowserList::StartKeepAlive(); 132 BrowserList::StartKeepAlive();
132 133
133 // Make this window available to the extension API. 134 // Make this window available to the extension API.
134 extension_window_controller_.reset( 135 extension_window_controller_.reset(
135 new internal::ShellWindowController(this, host->profile())); 136 new internal::ShellWindowController(this, host->profile()));
136 } 137 }
137 138
138 ShellWindow::~ShellWindow() { 139 ShellWindow::~ShellWindow() {
139 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the 140 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the
140 // last window open. 141 // last window open.
141 registrar_.RemoveAll(); 142 registrar_.RemoveAll();
142 143
143 // Remove shutdown prevention. 144 // Remove shutdown prevention.
144 BrowserList::EndKeepAlive(); 145 BrowserList::EndKeepAlive();
145 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698