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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Exposed to allow creating mocks. | 46 // Exposed to allow creating mocks. |
47 BackgroundContents::BackgroundContents() | 47 BackgroundContents::BackgroundContents() |
48 : delegate_(NULL), | 48 : delegate_(NULL), |
49 render_view_host_(NULL) { | 49 render_view_host_(NULL) { |
50 } | 50 } |
51 | 51 |
52 BackgroundContents::~BackgroundContents() { | 52 BackgroundContents::~BackgroundContents() { |
53 if (!render_view_host_) // Will be null for unit tests. | 53 if (!render_view_host_) // Will be null for unit tests. |
54 return; | 54 return; |
55 Profile* profile = render_view_host_->process()->profile(); | 55 Profile* profile = Profile::FromBrowserContext( |
| 56 render_view_host_->process()->browser_context()); |
56 NotificationService::current()->Notify( | 57 NotificationService::current()->Notify( |
57 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 58 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
58 Source<Profile>(profile), | 59 Source<Profile>(profile), |
59 Details<BackgroundContents>(this)); | 60 Details<BackgroundContents>(this)); |
60 render_view_host_->Shutdown(); // deletes render_view_host | 61 render_view_host_->Shutdown(); // deletes render_view_host |
61 } | 62 } |
62 | 63 |
63 BackgroundContents* BackgroundContents::GetAsBackgroundContents() { | 64 BackgroundContents* BackgroundContents::GetAsBackgroundContents() { |
64 return this; | 65 return this; |
65 } | 66 } |
(...skipping 19 matching lines...) Expand all Loading... |
85 | 86 |
86 // Note: because BackgroundContents are only available to extension apps, | 87 // Note: because BackgroundContents are only available to extension apps, |
87 // navigation is limited to urls within the app's extent. This is enforced in | 88 // navigation is limited to urls within the app's extent. This is enforced in |
88 // RenderView::decidePolicyForNaviation. If BackgroundContents become | 89 // RenderView::decidePolicyForNaviation. If BackgroundContents become |
89 // available as a part of the web platform, it probably makes sense to have | 90 // available as a part of the web platform, it probably makes sense to have |
90 // some way to scope navigation of a background page to its opener's security | 91 // some way to scope navigation of a background page to its opener's security |
91 // origin. Note: if the first navigation is to a URL outside the app's | 92 // origin. Note: if the first navigation is to a URL outside the app's |
92 // extent a background page will be opened but will remain at about:blank. | 93 // extent a background page will be opened but will remain at about:blank. |
93 url_ = params.url; | 94 url_ = params.url; |
94 | 95 |
95 Profile* profile = render_view_host->process()->profile(); | 96 Profile* profile = Profile::FromBrowserContext( |
| 97 render_view_host->process()->browser_context()); |
96 NotificationService::current()->Notify( | 98 NotificationService::current()->Notify( |
97 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | 99 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
98 Source<Profile>(profile), | 100 Source<Profile>(profile), |
99 Details<BackgroundContents>(this)); | 101 Details<BackgroundContents>(this)); |
100 } | 102 } |
101 | 103 |
102 void BackgroundContents::RunJavaScriptMessage( | 104 void BackgroundContents::RunJavaScriptMessage( |
103 const RenderViewHost* rvh, | 105 const RenderViewHost* rvh, |
104 const string16& message, | 106 const string16& message, |
105 const string16& default_prompt, | 107 const string16& default_prompt, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 success, | 142 success, |
141 user_input); | 143 user_input); |
142 } | 144 } |
143 | 145 |
144 gfx::NativeWindow BackgroundContents::GetDialogRootWindow() { | 146 gfx::NativeWindow BackgroundContents::GetDialogRootWindow() { |
145 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
146 return NULL; | 148 return NULL; |
147 } | 149 } |
148 | 150 |
149 void BackgroundContents::Close(RenderViewHost* render_view_host) { | 151 void BackgroundContents::Close(RenderViewHost* render_view_host) { |
150 Profile* profile = render_view_host->process()->profile(); | 152 Profile* profile = Profile::FromBrowserContext( |
| 153 render_view_host->process()->browser_context()); |
151 NotificationService::current()->Notify( | 154 NotificationService::current()->Notify( |
152 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, | 155 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, |
153 Source<Profile>(profile), | 156 Source<Profile>(profile), |
154 Details<BackgroundContents>(this)); | 157 Details<BackgroundContents>(this)); |
155 delete this; | 158 delete this; |
156 } | 159 } |
157 | 160 |
158 void BackgroundContents::RenderViewGone(RenderViewHost* rvh, | 161 void BackgroundContents::RenderViewGone(RenderViewHost* rvh, |
159 base::TerminationStatus status, | 162 base::TerminationStatus status, |
160 int error_code) { | 163 int error_code) { |
161 Profile* profile = rvh->process()->profile(); | 164 Profile* profile = |
| 165 Profile::FromBrowserContext(rvh->process()->browser_context()); |
162 NotificationService::current()->Notify( | 166 NotificationService::current()->Notify( |
163 chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, | 167 chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, |
164 Source<Profile>(profile), | 168 Source<Profile>(profile), |
165 Details<BackgroundContents>(this)); | 169 Details<BackgroundContents>(this)); |
166 | 170 |
167 // Our RenderView went away, so we should go away also, so killing the process | 171 // Our RenderView went away, so we should go away also, so killing the process |
168 // via the TaskManager doesn't permanently leave a BackgroundContents hanging | 172 // via the TaskManager doesn't permanently leave a BackgroundContents hanging |
169 // around the system, blocking future instances from being created | 173 // around the system, blocking future instances from being created |
170 // (http://crbug.com/65189). | 174 // (http://crbug.com/65189). |
171 delete this; | 175 delete this; |
172 } | 176 } |
173 | 177 |
174 RendererPreferences BackgroundContents::GetRendererPrefs( | 178 RendererPreferences BackgroundContents::GetRendererPrefs( |
175 content::BrowserContext* browser_context) const { | 179 content::BrowserContext* browser_context) const { |
176 Profile* profile = Profile::FromBrowserContext(browser_context); | 180 Profile* profile = Profile::FromBrowserContext(browser_context); |
177 RendererPreferences preferences; | 181 RendererPreferences preferences; |
178 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile); | 182 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile); |
179 return preferences; | 183 return preferences; |
180 } | 184 } |
181 | 185 |
182 WebPreferences BackgroundContents::GetWebkitPrefs() { | 186 WebPreferences BackgroundContents::GetWebkitPrefs() { |
183 // TODO(rafaelw): Consider enabling the webkit_prefs.dom_paste_enabled for | 187 // TODO(rafaelw): Consider enabling the webkit_prefs.dom_paste_enabled for |
184 // apps. | 188 // apps. |
185 Profile* profile = render_view_host_->process()->profile(); | 189 Profile* profile = Profile::FromBrowserContext( |
| 190 render_view_host_->process()->browser_context()); |
186 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, | 191 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, |
187 false); // is_web_ui | 192 false); // is_web_ui |
188 } | 193 } |
189 | 194 |
190 void BackgroundContents::CreateNewWindow( | 195 void BackgroundContents::CreateNewWindow( |
191 int route_id, | 196 int route_id, |
192 const ViewHostMsg_CreateWindow_Params& params) { | 197 const ViewHostMsg_CreateWindow_Params& params) { |
| 198 Profile* profile = Profile::FromBrowserContext( |
| 199 render_view_host_->process()->browser_context()); |
193 delegate_view_helper_.CreateNewWindow( | 200 delegate_view_helper_.CreateNewWindow( |
194 route_id, | 201 route_id, |
195 render_view_host_->process()->profile(), | 202 profile, |
196 render_view_host_->site_instance(), | 203 render_view_host_->site_instance(), |
197 ChromeWebUIFactory::GetInstance()->GetWebUIType( | 204 ChromeWebUIFactory::GetInstance()->GetWebUIType(profile, url_), |
198 render_view_host_->process()->profile(), url_), | |
199 this, | 205 this, |
200 params.window_container_type, | 206 params.window_container_type, |
201 params.frame_name); | 207 params.frame_name); |
202 } | 208 } |
203 | 209 |
204 void BackgroundContents::CreateNewWidget(int route_id, | 210 void BackgroundContents::CreateNewWidget(int route_id, |
205 WebKit::WebPopupType popup_type) { | 211 WebKit::WebPopupType popup_type) { |
206 NOTREACHED(); | 212 NOTREACHED(); |
207 } | 213 } |
208 | 214 |
(...skipping 23 matching lines...) Expand all Loading... |
232 BackgroundContents* | 238 BackgroundContents* |
233 BackgroundContents::GetBackgroundContentsByID(int render_process_id, | 239 BackgroundContents::GetBackgroundContentsByID(int render_process_id, |
234 int render_view_id) { | 240 int render_view_id) { |
235 RenderViewHost* render_view_host = | 241 RenderViewHost* render_view_host = |
236 RenderViewHost::FromID(render_process_id, render_view_id); | 242 RenderViewHost::FromID(render_process_id, render_view_id); |
237 if (!render_view_host) | 243 if (!render_view_host) |
238 return NULL; | 244 return NULL; |
239 | 245 |
240 return render_view_host->delegate()->GetAsBackgroundContents(); | 246 return render_view_host->delegate()->GetAsBackgroundContents(); |
241 } | 247 } |
OLD | NEW |