| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/background_contents.h" | 5 #include "chrome/browser/tab_contents/background_contents.h" |
| 6 | 6 |
| 7 #include "chrome/browser/background_contents_service.h" | 7 #include "chrome/browser/background_contents_service.h" |
| 8 #include "chrome/browser/desktop_notification_handler.h" | 8 #include "chrome/browser/desktop_notification_handler.h" |
| 9 #include "chrome/browser/extensions/extension_message_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/renderer_preferences_util.h" | 11 #include "chrome/browser/renderer_preferences_util.h" |
| 11 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" | 12 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
| 12 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 13 #include "chrome/common/extensions/extension_messages.h" | 14 #include "chrome/common/extensions/extension_messages.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/common/view_types.h" | 16 #include "chrome/common/view_types.h" |
| 16 #include "content/browser/browsing_instance.h" | 17 #include "content/browser/browsing_instance.h" |
| 17 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
| 18 #include "content/browser/site_instance.h" | 19 #include "content/browser/site_instance.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 base::TerminationStatus status, | 185 base::TerminationStatus status, |
| 185 int error_code) { | 186 int error_code) { |
| 186 // Our RenderView went away, so we should go away also, so killing the process | 187 // Our RenderView went away, so we should go away also, so killing the process |
| 187 // via the TaskManager doesn't permanently leave a BackgroundContents hanging | 188 // via the TaskManager doesn't permanently leave a BackgroundContents hanging |
| 188 // around the system, blocking future instances from being created | 189 // around the system, blocking future instances from being created |
| 189 // (http://crbug.com/65189). | 190 // (http://crbug.com/65189). |
| 190 delete this; | 191 delete this; |
| 191 } | 192 } |
| 192 | 193 |
| 193 bool BackgroundContents::OnMessageReceived(const IPC::Message& message) { | 194 bool BackgroundContents::OnMessageReceived(const IPC::Message& message) { |
| 195 bool handled = true; |
| 196 IPC_BEGIN_MESSAGE_MAP(BackgroundContents, message) |
| 197 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) |
| 198 IPC_MESSAGE_UNHANDLED(handled = false) |
| 199 IPC_END_MESSAGE_MAP() |
| 200 |
| 194 // Forward desktop notification IPCs if any to the | 201 // Forward desktop notification IPCs if any to the |
| 195 // DesktopNotificationHandler. | 202 // DesktopNotificationHandler. |
| 196 return desktop_notification_handler_->OnMessageReceived(message); | 203 if (!handled) |
| 204 handled = desktop_notification_handler_->OnMessageReceived(message); |
| 205 return handled; |
| 197 } | 206 } |
| 198 | 207 |
| 199 RendererPreferences BackgroundContents::GetRendererPrefs( | 208 RendererPreferences BackgroundContents::GetRendererPrefs( |
| 200 Profile* profile) const { | 209 Profile* profile) const { |
| 201 RendererPreferences preferences; | 210 RendererPreferences preferences; |
| 202 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile); | 211 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile); |
| 203 return preferences; | 212 return preferences; |
| 204 } | 213 } |
| 205 | 214 |
| 206 WebPreferences BackgroundContents::GetWebkitPrefs() { | 215 WebPreferences BackgroundContents::GetWebkitPrefs() { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 BackgroundContents* | 272 BackgroundContents* |
| 264 BackgroundContents::GetBackgroundContentsByID(int render_process_id, | 273 BackgroundContents::GetBackgroundContentsByID(int render_process_id, |
| 265 int render_view_id) { | 274 int render_view_id) { |
| 266 RenderViewHost* render_view_host = | 275 RenderViewHost* render_view_host = |
| 267 RenderViewHost::FromID(render_process_id, render_view_id); | 276 RenderViewHost::FromID(render_process_id, render_view_id); |
| 268 if (!render_view_host) | 277 if (!render_view_host) |
| 269 return NULL; | 278 return NULL; |
| 270 | 279 |
| 271 return render_view_host->delegate()->GetAsBackgroundContents(); | 280 return render_view_host->delegate()->GetAsBackgroundContents(); |
| 272 } | 281 } |
| 282 |
| 283 void BackgroundContents::OnPostMessage(int port_id, |
| 284 const std::string& message) { |
| 285 Profile* profile = render_view_host_->process()->profile(); |
| 286 if (profile->GetExtensionMessageService()) { |
| 287 profile->GetExtensionMessageService()->PostMessageFromRenderer( |
| 288 port_id, message); |
| 289 } |
| 290 } |
| OLD | NEW |