Chromium Code Reviews| Index: chrome/browser/ui/extensions/shell_window.cc |
| diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc |
| index f624f95f2636ad32e41dbe970f8f3d201304b42c..055b0d22663ebc4219414158c12fa4d89e5786f7 100644 |
| --- a/chrome/browser/ui/extensions/shell_window.cc |
| +++ b/chrome/browser/ui/extensions/shell_window.cc |
| @@ -8,14 +8,24 @@ |
| #include "chrome/browser/extensions/extension_process_manager.h" |
| #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
| #include "chrome/browser/extensions/extension_window_controller.h" |
| +#include "chrome/browser/extensions/platform_app_registry.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sessions/session_id.h" |
| #include "chrome/common/chrome_notification_types.h" |
| +#include "chrome/common/chrome_view_type.h" |
| #include "chrome/common/extensions/extension.h" |
| +#include "chrome/common/extensions/extension_messages.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/notification_types.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/site_instance.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/common/renderer_preferences.h" |
| + |
| +using content::SiteInstance; |
| +using content::WebContents; |
| namespace internal { |
| @@ -83,24 +93,38 @@ ShellWindow* ShellWindow::Create(Profile* profile, |
| DCHECK(manager); |
| // This object will delete itself when the window is closed. |
| - return ShellWindow::CreateShellWindow( |
| - manager->CreateShellHost(extension, url)); |
| + return ShellWindow::CreateShellWindow(profile, extension, url); |
| +} |
| + |
| +WebContents* ShellWindow::GetAssociatedWebContents() const { |
| + return NULL; |
|
Aaron Boodman
2012/04/27 16:20:31
EFD::Delegate could do this by default.
benwells
2012/05/03 09:22:40
Done.
|
| +} |
| + |
| +bool ShellWindow::OnMessageReceived(const IPC::Message& message) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(ShellWindow, message) |
| + IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| +void ShellWindow::CloseContents(WebContents* contents) { |
| + Close(); |
| +} |
| + |
| +bool ShellWindow::ShouldSuppressDialogs() { |
|
Aaron Boodman
2012/04/27 16:20:31
This seems like it is unnecessarily inversion of c
benwells
2012/05/03 09:22:40
Added todo.
|
| + return true; |
| } |
| void ShellWindow::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| switch (type) { |
| - case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| - if (content::Details<ExtensionHost>(host_.get()) == details) |
| - Close(); |
| - break; |
| case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| const Extension* unloaded_extension = |
| content::Details<UnloadedExtensionInfo>(details)->extension; |
| - // We compare extension IDs and not Extension pointers since ExtensionHost |
| - // nulls out its Extension pointer when it gets this notification. |
| - if (host_->extension_id() == unloaded_extension->id()) |
| + if (extension_ == unloaded_extension) |
| Close(); |
| break; |
| } |
| @@ -112,15 +136,28 @@ void ShellWindow::Observe(int type, |
| } |
| } |
| -ShellWindow::ShellWindow(ExtensionHost* host) |
| - : host_(host) { |
| - // Close the window in response to window.close() and the like. |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| - content::Source<Profile>(host->profile())); |
| - // Also close if the window if the extension has been unloaded (parallels |
| - // NOTIFICATION_EXTENSION_UNLOADED closing the app's tabs in TabStripModel). |
| +ShellWindow::ShellWindow(Profile* profile, |
| + const Extension* extension, |
| + const GURL& url) |
| + : profile_(profile), |
| + extension_(extension), |
| + ALLOW_THIS_IN_INITIALIZER_LIST( |
| + extension_function_dispatcher_(profile, this)) { |
| + web_contents_.reset(WebContents::Create( |
| + profile, SiteInstance::CreateForURL(profile, url), MSG_ROUTING_NONE, NULL, |
| + NULL)); |
| + content::WebContentsObserver::Observe(web_contents_.get()); |
| + web_contents_->SetDelegate(this); |
| + web_contents_->SetViewType(chrome::VIEW_TYPE_APP_SHELL); |
| + web_contents_->GetMutableRendererPrefs()->browser_handles_all_requests = |
| + true; |
| + web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
| + |
| + web_contents_->GetController().LoadURL( |
| + url, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| + std::string()); |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| - content::Source<Profile>(host->profile())); |
| + content::Source<Profile>(profile_)); |
| // Close when the browser is exiting. |
| // TODO(mihaip): we probably don't want this in the long run (when platform |
| // apps are no longer tied to the browser process). |
| @@ -132,7 +169,9 @@ ShellWindow::ShellWindow(ExtensionHost* host) |
| // Make this window available to the extension API. |
| extension_window_controller_.reset( |
| - new internal::ShellWindowController(this, host->profile())); |
| + new internal::ShellWindowController(this, profile_)); |
| + |
| + PlatformAppRegistry::Get(profile_)->AddShellWindow(this); |
| } |
| ShellWindow::~ShellWindow() { |
| @@ -140,6 +179,17 @@ ShellWindow::~ShellWindow() { |
| // last window open. |
| registrar_.RemoveAll(); |
| + PlatformAppRegistry::Get(profile_)->RemoveShellWindow(this); |
| + |
| // Remove shutdown prevention. |
| BrowserList::EndKeepAlive(); |
| } |
| + |
| +Browser* ShellWindow::GetBrowser() { |
|
Aaron Boodman
2012/04/27 16:20:31
EFD::Delegate could do this by default.
benwells
2012/05/03 09:22:40
Done.
|
| + return NULL; |
| +} |
| + |
| +void ShellWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| + extension_function_dispatcher_.Dispatch(params, |
| + web_contents_->GetRenderViewHost()); |
| +} |