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

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: Removed platform app host, merged into shell window 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/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sessions/session_id.h" 12 #include "chrome/browser/sessions/session_id.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/chrome_view_type.h"
14 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_messages.h"
15 #include "content/public/browser/notification_details.h" 17 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/site_instance.h"
23 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/renderer_preferences.h"
25
26 using content::WebContents;
19 27
20 namespace internal { 28 namespace internal {
21 29
22 class ShellWindowController : public ExtensionWindowController { 30 class ShellWindowController : public ExtensionWindowController {
23 public: 31 public:
24 ShellWindowController(ShellWindow* shell_window, Profile* profile); 32 ShellWindowController(ShellWindow* shell_window, Profile* profile);
25 33
26 // Overriden from ExtensionWindowController 34 // Overriden from ExtensionWindowController
27 virtual int GetWindowId() const OVERRIDE; 35 virtual int GetWindowId() const OVERRIDE;
28 virtual std::string GetWindowTypeText() const OVERRIDE; 36 virtual std::string GetWindowTypeText() const OVERRIDE;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 84
77 } // namespace internal 85 } // namespace internal
78 86
79 ShellWindow* ShellWindow::Create(Profile* profile, 87 ShellWindow* ShellWindow::Create(Profile* profile,
80 const Extension* extension, 88 const Extension* extension,
81 const GURL& url) { 89 const GURL& url) {
82 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); 90 ExtensionProcessManager* manager = profile->GetExtensionProcessManager();
83 DCHECK(manager); 91 DCHECK(manager);
84 92
85 // This object will delete itself when the window is closed. 93 // This object will delete itself when the window is closed.
86 return ShellWindow::CreateShellWindow( 94 return ShellWindow::CreateShellWindow(profile, extension, url);
87 manager->CreateShellHost(extension, url)); 95 }
96
97 WebContents* ShellWindow::GetAssociatedWebContents() const {
98 return NULL;
99 }
100
101 bool ShellWindow::OnMessageReceived(const IPC::Message& message) {
102 bool handled = true;
103 IPC_BEGIN_MESSAGE_MAP(ShellWindow, message)
104 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
105 IPC_MESSAGE_UNHANDLED(handled = false)
106 IPC_END_MESSAGE_MAP()
107 return handled;
108 }
109
110 void ShellWindow::CloseContents(WebContents* contents) {
111 Close();
112 }
113
114 bool ShellWindow::ShouldSuppressDialogs() {
115 return true;
88 } 116 }
89 117
90 void ShellWindow::Observe(int type, 118 void ShellWindow::Observe(int type,
91 const content::NotificationSource& source, 119 const content::NotificationSource& source,
92 const content::NotificationDetails& details) { 120 const content::NotificationDetails& details) {
93 switch (type) { 121 switch (type) {
94 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE:
95 if (content::Details<ExtensionHost>(host_.get()) == details)
96 Close();
97 break;
98 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 122 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
99 const Extension* unloaded_extension = 123 const Extension* unloaded_extension =
100 content::Details<UnloadedExtensionInfo>(details)->extension; 124 content::Details<UnloadedExtensionInfo>(details)->extension;
101 // We compare extension IDs and not Extension pointers since ExtensionHost 125 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(); 126 Close();
105 break; 127 break;
106 } 128 }
107 case content::NOTIFICATION_APP_TERMINATING: 129 case content::NOTIFICATION_APP_TERMINATING:
108 Close(); 130 Close();
109 break; 131 break;
110 default: 132 default:
111 NOTREACHED() << "Received unexpected notification"; 133 NOTREACHED() << "Received unexpected notification";
112 } 134 }
113 } 135 }
114 136
115 ShellWindow::ShellWindow(ExtensionHost* host) 137 ShellWindow::ShellWindow(Profile* profile,
116 : host_(host) { 138 const Extension* extension,
117 // Close the window in response to window.close() and the like. 139 const GURL& url)
118 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 140 : profile_(profile),
119 content::Source<Profile>(host->profile())); 141 extension_(extension),
120 // Also close if the window if the extension has been unloaded (parallels 142 ALLOW_THIS_IN_INITIALIZER_LIST(
121 // NOTIFICATION_EXTENSION_UNLOADED closing the app's tabs in TabStripModel). 143 extension_function_dispatcher_(profile, this)),
144 site_instance_(content::SiteInstance::Create(profile)) {
145 web_contents_.reset(WebContents::Create(
146 profile, site_instance_.get(), MSG_ROUTING_NONE, NULL, NULL));
147 content::WebContentsObserver::Observe(web_contents_.get());
148 web_contents_->SetDelegate(this);
149 web_contents_->SetViewType(chrome::VIEW_TYPE_APP_SHELL);
150 web_contents_->GetMutableRendererPrefs()->browser_handles_all_requests =
151 true;
152 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
Matt Perry 2012/04/25 19:31:58 This line is a good example of why I'm reluctant t
Matt Perry 2012/04/25 22:35:00 BTW I'm just voicing my grievances :). I realize A
benwells 2012/04/25 23:25:25 For context, this patch is why I want to split out
Aaron Boodman 2012/04/27 16:20:31 I hear you. We have many options when these things
153
154 web_contents_->GetController().LoadURL(
155 url, content::Referrer(), content::PAGE_TRANSITION_LINK,
156 std::string());
122 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 157 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
123 content::Source<Profile>(host->profile())); 158 content::Source<Profile>(profile_));
124 // Close when the browser is exiting. 159 // Close when the browser is exiting.
125 // TODO(mihaip): we probably don't want this in the long run (when platform 160 // TODO(mihaip): we probably don't want this in the long run (when platform
126 // apps are no longer tied to the browser process). 161 // apps are no longer tied to the browser process).
127 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, 162 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
128 content::NotificationService::AllSources()); 163 content::NotificationService::AllSources());
129 164
130 // Prevent the browser process from shutting down while this window is open. 165 // Prevent the browser process from shutting down while this window is open.
131 BrowserList::StartKeepAlive(); 166 BrowserList::StartKeepAlive();
132 167
133 // Make this window available to the extension API. 168 // Make this window available to the extension API.
134 extension_window_controller_.reset( 169 extension_window_controller_.reset(
135 new internal::ShellWindowController(this, host->profile())); 170 new internal::ShellWindowController(this, profile_));
136 } 171 }
137 172
138 ShellWindow::~ShellWindow() { 173 ShellWindow::~ShellWindow() {
139 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the 174 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the
140 // last window open. 175 // last window open.
141 registrar_.RemoveAll(); 176 registrar_.RemoveAll();
142 177
143 // Remove shutdown prevention. 178 // Remove shutdown prevention.
144 BrowserList::EndKeepAlive(); 179 BrowserList::EndKeepAlive();
145 } 180 }
181
182 Browser* ShellWindow::GetBrowser() {
183 return NULL;
184 }
185
186 void ShellWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) {
187 extension_function_dispatcher_.Dispatch(params,
188 web_contents_->GetRenderViewHost());
189 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.h ('k') | chrome/browser/ui/gtk/extensions/shell_window_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698