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

Side by Side Diff: chrome/browser/tab_contents/background_contents.cc

Issue 6794035: Move dispatching and sending of the last extension specific messages out of TabContents and Rende... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
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_handler.h"
9 #include "chrome/browser/extensions/extension_message_service.h" 10 #include "chrome/browser/extensions/extension_message_service.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/renderer_preferences_util.h" 12 #include "chrome/browser/renderer_preferences_util.h"
12 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" 13 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
13 #include "chrome/common/extensions/extension_constants.h" 14 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/extension_messages.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "chrome/common/view_types.h" 16 #include "chrome/common/view_types.h"
17 #include "content/browser/browsing_instance.h" 17 #include "content/browser/browsing_instance.h"
18 #include "content/browser/renderer_host/render_process_host.h"
18 #include "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/browser/site_instance.h" 20 #include "content/browser/site_instance.h"
20 #include "content/common/notification_service.h" 21 #include "content/common/notification_service.h"
21 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
22 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
23 24
24 //////////////// 25 ////////////////
25 // BackgroundContents 26 // BackgroundContents
26 27
27 BackgroundContents::BackgroundContents(SiteInstance* site_instance, 28 BackgroundContents::BackgroundContents(SiteInstance* site_instance,
(...skipping 10 matching lines...) Expand all
38 registrar_.Add(this, NotificationType::APP_TERMINATING, 39 registrar_.Add(this, NotificationType::APP_TERMINATING,
39 NotificationService::AllSources()); 40 NotificationService::AllSources());
40 41
41 // Register for our parent profile to shutdown, so we can shut ourselves down 42 // Register for our parent profile to shutdown, so we can shut ourselves down
42 // as well (should only be called for OTR profiles, as we should receive 43 // as well (should only be called for OTR profiles, as we should receive
43 // APP_TERMINATING before non-OTR profiles are destroyed). 44 // APP_TERMINATING before non-OTR profiles are destroyed).
44 registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 45 registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
45 Source<Profile>(profile)); 46 Source<Profile>(profile));
46 desktop_notification_handler_.reset( 47 desktop_notification_handler_.reset(
47 new DesktopNotificationHandler(NULL, site_instance->GetProcess())); 48 new DesktopNotificationHandler(NULL, site_instance->GetProcess()));
49 extension_message_handler_.reset(new ExtensionMessageHandler(
50 render_view_host_->process()->id(), render_view_host_, profile));
48 } 51 }
49 52
50 // Exposed to allow creating mocks. 53 // Exposed to allow creating mocks.
51 BackgroundContents::BackgroundContents() 54 BackgroundContents::BackgroundContents()
52 : delegate_(NULL), 55 : delegate_(NULL),
53 render_view_host_(NULL) { 56 render_view_host_(NULL) {
54 } 57 }
55 58
56 BackgroundContents::~BackgroundContents() { 59 BackgroundContents::~BackgroundContents() {
57 if (!render_view_host_) // Will be null for unit tests. 60 if (!render_view_host_) // Will be null for unit tests.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 Details<BackgroundContents>(this)); 194 Details<BackgroundContents>(this));
192 195
193 // Our RenderView went away, so we should go away also, so killing the process 196 // Our RenderView went away, so we should go away also, so killing the process
194 // via the TaskManager doesn't permanently leave a BackgroundContents hanging 197 // via the TaskManager doesn't permanently leave a BackgroundContents hanging
195 // around the system, blocking future instances from being created 198 // around the system, blocking future instances from being created
196 // (http://crbug.com/65189). 199 // (http://crbug.com/65189).
197 delete this; 200 delete this;
198 } 201 }
199 202
200 bool BackgroundContents::OnMessageReceived(const IPC::Message& message) { 203 bool BackgroundContents::OnMessageReceived(const IPC::Message& message) {
201 bool handled = true; 204 bool handled = desktop_notification_handler_->OnMessageReceived(message);
202 IPC_BEGIN_MESSAGE_MAP(BackgroundContents, message)
203 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
204 IPC_MESSAGE_UNHANDLED(handled = false)
205 IPC_END_MESSAGE_MAP()
206
207 // Forward desktop notification IPCs if any to the
208 // DesktopNotificationHandler.
209 if (!handled) 205 if (!handled)
210 handled = desktop_notification_handler_->OnMessageReceived(message); 206 handled = extension_message_handler_->OnMessageReceived(message);
211 return handled; 207 return handled;
212 } 208 }
213 209
214 RendererPreferences BackgroundContents::GetRendererPrefs( 210 RendererPreferences BackgroundContents::GetRendererPrefs(
215 Profile* profile) const { 211 Profile* profile) const {
216 RendererPreferences preferences; 212 RendererPreferences preferences;
217 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile); 213 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile);
218 return preferences; 214 return preferences;
219 } 215 }
220 216
221 WebPreferences BackgroundContents::GetWebkitPrefs() { 217 WebPreferences BackgroundContents::GetWebkitPrefs() {
222 // TODO(rafaelw): Consider enabling the webkit_prefs.dom_paste_enabled for 218 // TODO(rafaelw): Consider enabling the webkit_prefs.dom_paste_enabled for
223 // apps. 219 // apps.
224 Profile* profile = render_view_host_->process()->profile(); 220 Profile* profile = render_view_host_->process()->profile();
225 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, 221 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile,
226 false); // is_web_ui 222 false); // is_web_ui
227 } 223 }
228 224
229 void BackgroundContents::ProcessWebUIMessage(
230 const ExtensionHostMsg_DomMessage_Params& params) {
231 // TODO(rafaelw): It may make sense for extensions to be able to open
232 // BackgroundContents to chrome-extension://<id> pages. Consider implementing.
233 render_view_host_->BlockExtensionRequest(params.request_id);
234 }
235
236 void BackgroundContents::CreateNewWindow( 225 void BackgroundContents::CreateNewWindow(
237 int route_id, 226 int route_id,
238 const ViewHostMsg_CreateWindow_Params& params) { 227 const ViewHostMsg_CreateWindow_Params& params) {
239 delegate_view_helper_.CreateNewWindow( 228 delegate_view_helper_.CreateNewWindow(
240 route_id, 229 route_id,
241 render_view_host_->process()->profile(), 230 render_view_host_->process()->profile(),
242 render_view_host_->site_instance(), 231 render_view_host_->site_instance(),
243 ChromeWebUIFactory::GetInstance()->GetWebUIType( 232 ChromeWebUIFactory::GetInstance()->GetWebUIType(
244 render_view_host_->process()->profile(), url_), 233 render_view_host_->process()->profile(), url_),
245 this, 234 this,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 BackgroundContents* 267 BackgroundContents*
279 BackgroundContents::GetBackgroundContentsByID(int render_process_id, 268 BackgroundContents::GetBackgroundContentsByID(int render_process_id,
280 int render_view_id) { 269 int render_view_id) {
281 RenderViewHost* render_view_host = 270 RenderViewHost* render_view_host =
282 RenderViewHost::FromID(render_process_id, render_view_id); 271 RenderViewHost::FromID(render_process_id, render_view_id);
283 if (!render_view_host) 272 if (!render_view_host)
284 return NULL; 273 return NULL;
285 274
286 return render_view_host->delegate()->GetAsBackgroundContents(); 275 return render_view_host->delegate()->GetAsBackgroundContents();
287 } 276 }
288
289 void BackgroundContents::OnPostMessage(int port_id,
290 const std::string& message) {
291 Profile* profile = render_view_host_->process()->profile();
292 if (profile->GetExtensionMessageService()) {
293 profile->GetExtensionMessageService()->PostMessageFromRenderer(
294 port_id, message);
295 }
296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698