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..941cbcdfd7db5dbd877d28321439eb6e7d40da28 100644 |
| --- a/chrome/browser/ui/extensions/shell_window.cc |
| +++ b/chrome/browser/ui/extensions/shell_window.cc |
| @@ -11,11 +11,19 @@ |
| #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::WebContents; |
| namespace internal { |
| @@ -83,24 +91,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; |
| +} |
| + |
| +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() { |
| + 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 +134,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)), |
| + site_instance_(content::SiteInstance::Create(profile)) { |
| + web_contents_.reset(WebContents::Create( |
| + profile, site_instance_.get(), 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(); |
|
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
|
| + |
| + 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 +167,7 @@ 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_)); |
| } |
| ShellWindow::~ShellWindow() { |
| @@ -143,3 +178,12 @@ ShellWindow::~ShellWindow() { |
| // Remove shutdown prevention. |
| BrowserList::EndKeepAlive(); |
| } |
| + |
| +Browser* ShellWindow::GetBrowser() { |
| + return NULL; |
| +} |
| + |
| +void ShellWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| + extension_function_dispatcher_.Dispatch(params, |
| + web_contents_->GetRenderViewHost()); |
| +} |