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/background_contents_service.h" | 7 #include "chrome/browser/background/background_contents_service.h" |
8 #include "chrome/browser/extensions/extension_message_service.h" | 8 #include "chrome/browser/extensions/extension_message_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/renderer_preferences_util.h" | 10 #include "chrome/browser/renderer_preferences_util.h" |
11 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/common/chrome_view_types.h" | 15 #include "chrome/common/chrome_view_types.h" |
16 #include "content/browser/browsing_instance.h" | 16 #include "content/browser/browsing_instance.h" |
17 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "content/browser/site_instance.h" | 18 #include "content/browser/site_instance.h" |
19 #include "content/common/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 | 22 |
23 //////////////// | 23 //////////////// |
24 // BackgroundContents | 24 // BackgroundContents |
25 | 25 |
26 BackgroundContents::BackgroundContents(SiteInstance* site_instance, | 26 BackgroundContents::BackgroundContents(SiteInstance* site_instance, |
27 int routing_id, | 27 int routing_id, |
28 Delegate* delegate) | 28 Delegate* delegate) |
29 : delegate_(delegate) { | 29 : delegate_(delegate) { |
30 Profile* profile = Profile::FromBrowserContext( | 30 Profile* profile = Profile::FromBrowserContext( |
31 site_instance->browsing_instance()->browser_context()); | 31 site_instance->browsing_instance()->browser_context()); |
32 | 32 |
33 // TODO(rafaelw): Implement correct session storage. | 33 // TODO(rafaelw): Implement correct session storage. |
34 render_view_host_ = new RenderViewHost(site_instance, this, routing_id, NULL); | 34 render_view_host_ = new RenderViewHost(site_instance, this, routing_id, NULL); |
35 | 35 |
36 // Close ourselves when the application is shutting down. | 36 // Close ourselves when the application is shutting down. |
37 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | 37 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
38 NotificationService::AllSources()); | 38 content::NotificationService::AllSources()); |
39 | 39 |
40 // Register for our parent profile to shutdown, so we can shut ourselves down | 40 // Register for our parent profile to shutdown, so we can shut ourselves down |
41 // as well (should only be called for OTR profiles, as we should receive | 41 // as well (should only be called for OTR profiles, as we should receive |
42 // APP_TERMINATING before non-OTR profiles are destroyed). | 42 // APP_TERMINATING before non-OTR profiles are destroyed). |
43 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 43 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
44 content::Source<Profile>(profile)); | 44 content::Source<Profile>(profile)); |
45 } | 45 } |
46 | 46 |
47 // Exposed to allow creating mocks. | 47 // Exposed to allow creating mocks. |
48 BackgroundContents::BackgroundContents() | 48 BackgroundContents::BackgroundContents() |
49 : delegate_(NULL), | 49 : delegate_(NULL), |
50 render_view_host_(NULL) { | 50 render_view_host_(NULL) { |
51 } | 51 } |
52 | 52 |
53 BackgroundContents::~BackgroundContents() { | 53 BackgroundContents::~BackgroundContents() { |
54 if (!render_view_host_) // Will be null for unit tests. | 54 if (!render_view_host_) // Will be null for unit tests. |
55 return; | 55 return; |
56 Profile* profile = Profile::FromBrowserContext( | 56 Profile* profile = Profile::FromBrowserContext( |
57 render_view_host_->process()->browser_context()); | 57 render_view_host_->process()->browser_context()); |
58 NotificationService::current()->Notify( | 58 content::NotificationService::current()->Notify( |
59 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 59 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
60 content::Source<Profile>(profile), | 60 content::Source<Profile>(profile), |
61 content::Details<BackgroundContents>(this)); | 61 content::Details<BackgroundContents>(this)); |
62 render_view_host_->Shutdown(); // deletes render_view_host | 62 render_view_host_->Shutdown(); // deletes render_view_host |
63 } | 63 } |
64 | 64 |
65 BackgroundContents* BackgroundContents::GetAsBackgroundContents() { | 65 BackgroundContents* BackgroundContents::GetAsBackgroundContents() { |
66 return this; | 66 return this; |
67 } | 67 } |
68 | 68 |
(...skipping 20 matching lines...) Expand all Loading... |
89 // navigation is limited to urls within the app's extent. This is enforced in | 89 // navigation is limited to urls within the app's extent. This is enforced in |
90 // RenderView::decidePolicyForNaviation. If BackgroundContents become | 90 // RenderView::decidePolicyForNaviation. If BackgroundContents become |
91 // available as a part of the web platform, it probably makes sense to have | 91 // available as a part of the web platform, it probably makes sense to have |
92 // some way to scope navigation of a background page to its opener's security | 92 // some way to scope navigation of a background page to its opener's security |
93 // origin. Note: if the first navigation is to a URL outside the app's | 93 // origin. Note: if the first navigation is to a URL outside the app's |
94 // extent a background page will be opened but will remain at about:blank. | 94 // extent a background page will be opened but will remain at about:blank. |
95 url_ = params.url; | 95 url_ = params.url; |
96 | 96 |
97 Profile* profile = Profile::FromBrowserContext( | 97 Profile* profile = Profile::FromBrowserContext( |
98 render_view_host->process()->browser_context()); | 98 render_view_host->process()->browser_context()); |
99 NotificationService::current()->Notify( | 99 content::NotificationService::current()->Notify( |
100 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | 100 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
101 content::Source<Profile>(profile), | 101 content::Source<Profile>(profile), |
102 content::Details<BackgroundContents>(this)); | 102 content::Details<BackgroundContents>(this)); |
103 } | 103 } |
104 | 104 |
105 void BackgroundContents::RunJavaScriptMessage( | 105 void BackgroundContents::RunJavaScriptMessage( |
106 const RenderViewHost* rvh, | 106 const RenderViewHost* rvh, |
107 const string16& message, | 107 const string16& message, |
108 const string16& default_prompt, | 108 const string16& default_prompt, |
109 const GURL& frame_url, | 109 const GURL& frame_url, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 gfx::NativeWindow BackgroundContents::GetDialogRootWindow() { | 147 gfx::NativeWindow BackgroundContents::GetDialogRootWindow() { |
148 NOTIMPLEMENTED(); | 148 NOTIMPLEMENTED(); |
149 return NULL; | 149 return NULL; |
150 } | 150 } |
151 | 151 |
152 void BackgroundContents::Close(RenderViewHost* render_view_host) { | 152 void BackgroundContents::Close(RenderViewHost* render_view_host) { |
153 Profile* profile = Profile::FromBrowserContext( | 153 Profile* profile = Profile::FromBrowserContext( |
154 render_view_host->process()->browser_context()); | 154 render_view_host->process()->browser_context()); |
155 NotificationService::current()->Notify( | 155 content::NotificationService::current()->Notify( |
156 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, | 156 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, |
157 content::Source<Profile>(profile), | 157 content::Source<Profile>(profile), |
158 content::Details<BackgroundContents>(this)); | 158 content::Details<BackgroundContents>(this)); |
159 delete this; | 159 delete this; |
160 } | 160 } |
161 | 161 |
162 void BackgroundContents::RenderViewGone(RenderViewHost* rvh, | 162 void BackgroundContents::RenderViewGone(RenderViewHost* rvh, |
163 base::TerminationStatus status, | 163 base::TerminationStatus status, |
164 int error_code) { | 164 int error_code) { |
165 Profile* profile = | 165 Profile* profile = |
166 Profile::FromBrowserContext(rvh->process()->browser_context()); | 166 Profile::FromBrowserContext(rvh->process()->browser_context()); |
167 NotificationService::current()->Notify( | 167 content::NotificationService::current()->Notify( |
168 chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, | 168 chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, |
169 content::Source<Profile>(profile), | 169 content::Source<Profile>(profile), |
170 content::Details<BackgroundContents>(this)); | 170 content::Details<BackgroundContents>(this)); |
171 | 171 |
172 // Our RenderView went away, so we should go away also, so killing the process | 172 // Our RenderView went away, so we should go away also, so killing the process |
173 // via the TaskManager doesn't permanently leave a BackgroundContents hanging | 173 // via the TaskManager doesn't permanently leave a BackgroundContents hanging |
174 // around the system, blocking future instances from being created | 174 // around the system, blocking future instances from being created |
175 // (http://crbug.com/65189). | 175 // (http://crbug.com/65189). |
176 delete this; | 176 delete this; |
177 } | 177 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 BackgroundContents* | 249 BackgroundContents* |
250 BackgroundContents::GetBackgroundContentsByID(int render_process_id, | 250 BackgroundContents::GetBackgroundContentsByID(int render_process_id, |
251 int render_view_id) { | 251 int render_view_id) { |
252 RenderViewHost* render_view_host = | 252 RenderViewHost* render_view_host = |
253 RenderViewHost::FromID(render_process_id, render_view_id); | 253 RenderViewHost::FromID(render_process_id, render_view_id); |
254 if (!render_view_host) | 254 if (!render_view_host) |
255 return NULL; | 255 return NULL; |
256 | 256 |
257 return render_view_host->delegate()->GetAsBackgroundContents(); | 257 return render_view_host->delegate()->GetAsBackgroundContents(); |
258 } | 258 } |
OLD | NEW |