| 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/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "content/browser/browsing_instance.h" | 15 #include "content/browser/browsing_instance.h" |
| 15 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
| 16 #include "content/browser/site_instance.h" | 17 #include "content/browser/site_instance.h" |
| 17 #include "content/common/notification_service.h" | 18 #include "content/common/notification_service.h" |
| 18 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
| 19 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 20 | 21 |
| 21 //////////////// | 22 //////////////// |
| 22 // BackgroundContents | 23 // BackgroundContents |
| 23 | 24 |
| 24 BackgroundContents::BackgroundContents(SiteInstance* site_instance, | 25 BackgroundContents::BackgroundContents(SiteInstance* site_instance, |
| 25 int routing_id, | 26 int routing_id, |
| 26 Delegate* delegate) | 27 Delegate* delegate) |
| 27 : delegate_(delegate) { | 28 : delegate_(delegate) { |
| 28 Profile* profile = site_instance->browsing_instance()->profile(); | 29 Profile* profile = site_instance->browsing_instance()->profile(); |
| 29 | 30 |
| 30 // TODO(rafaelw): Implement correct session storage. | 31 // TODO(rafaelw): Implement correct session storage. |
| 31 render_view_host_ = new RenderViewHost(site_instance, this, routing_id, NULL); | 32 render_view_host_ = new RenderViewHost(site_instance, this, routing_id, NULL); |
| 32 | 33 |
| 33 // Close ourselves when the application is shutting down. | 34 // Close ourselves when the application is shutting down. |
| 34 registrar_.Add(this, NotificationType::APP_TERMINATING, | 35 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
| 35 NotificationService::AllSources()); | 36 NotificationService::AllSources()); |
| 36 | 37 |
| 37 // Register for our parent profile to shutdown, so we can shut ourselves down | 38 // Register for our parent profile to shutdown, so we can shut ourselves down |
| 38 // as well (should only be called for OTR profiles, as we should receive | 39 // as well (should only be called for OTR profiles, as we should receive |
| 39 // APP_TERMINATING before non-OTR profiles are destroyed). | 40 // APP_TERMINATING before non-OTR profiles are destroyed). |
| 40 registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 41 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 41 Source<Profile>(profile)); | 42 Source<Profile>(profile)); |
| 42 } | 43 } |
| 43 | 44 |
| 44 // Exposed to allow creating mocks. | 45 // Exposed to allow creating mocks. |
| 45 BackgroundContents::BackgroundContents() | 46 BackgroundContents::BackgroundContents() |
| 46 : delegate_(NULL), | 47 : delegate_(NULL), |
| 47 render_view_host_(NULL) { | 48 render_view_host_(NULL) { |
| 48 } | 49 } |
| 49 | 50 |
| 50 BackgroundContents::~BackgroundContents() { | 51 BackgroundContents::~BackgroundContents() { |
| 51 if (!render_view_host_) // Will be null for unit tests. | 52 if (!render_view_host_) // Will be null for unit tests. |
| 52 return; | 53 return; |
| 53 Profile* profile = render_view_host_->process()->profile(); | 54 Profile* profile = render_view_host_->process()->profile(); |
| 54 NotificationService::current()->Notify( | 55 NotificationService::current()->Notify( |
| 55 NotificationType::BACKGROUND_CONTENTS_DELETED, | 56 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 56 Source<Profile>(profile), | 57 Source<Profile>(profile), |
| 57 Details<BackgroundContents>(this)); | 58 Details<BackgroundContents>(this)); |
| 58 render_view_host_->Shutdown(); // deletes render_view_host | 59 render_view_host_->Shutdown(); // deletes render_view_host |
| 59 } | 60 } |
| 60 | 61 |
| 61 BackgroundContents* BackgroundContents::GetAsBackgroundContents() { | 62 BackgroundContents* BackgroundContents::GetAsBackgroundContents() { |
| 62 return this; | 63 return this; |
| 63 } | 64 } |
| 64 | 65 |
| 65 RenderViewHostDelegate::View* BackgroundContents::GetViewDelegate() { | 66 RenderViewHostDelegate::View* BackgroundContents::GetViewDelegate() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 // navigation is limited to urls within the app's extent. This is enforced in | 86 // navigation is limited to urls within the app's extent. This is enforced in |
| 86 // RenderView::decidePolicyForNaviation. If BackgroundContents become | 87 // RenderView::decidePolicyForNaviation. If BackgroundContents become |
| 87 // available as a part of the web platform, it probably makes sense to have | 88 // available as a part of the web platform, it probably makes sense to have |
| 88 // some way to scope navigation of a background page to its opener's security | 89 // some way to scope navigation of a background page to its opener's security |
| 89 // origin. Note: if the first navigation is to a URL outside the app's | 90 // origin. Note: if the first navigation is to a URL outside the app's |
| 90 // extent a background page will be opened but will remain at about:blank. | 91 // extent a background page will be opened but will remain at about:blank. |
| 91 url_ = params.url; | 92 url_ = params.url; |
| 92 | 93 |
| 93 Profile* profile = render_view_host->process()->profile(); | 94 Profile* profile = render_view_host->process()->profile(); |
| 94 NotificationService::current()->Notify( | 95 NotificationService::current()->Notify( |
| 95 NotificationType::BACKGROUND_CONTENTS_NAVIGATED, | 96 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 96 Source<Profile>(profile), | 97 Source<Profile>(profile), |
| 97 Details<BackgroundContents>(this)); | 98 Details<BackgroundContents>(this)); |
| 98 } | 99 } |
| 99 | 100 |
| 100 void BackgroundContents::RunJavaScriptMessage( | 101 void BackgroundContents::RunJavaScriptMessage( |
| 101 const RenderViewHost* rvh, | 102 const RenderViewHost* rvh, |
| 102 const string16& message, | 103 const string16& message, |
| 103 const string16& default_prompt, | 104 const string16& default_prompt, |
| 104 const GURL& frame_url, | 105 const GURL& frame_url, |
| 105 const int flags, | 106 const int flags, |
| 106 IPC::Message* reply_msg, | 107 IPC::Message* reply_msg, |
| 107 bool* did_suppress_message) { | 108 bool* did_suppress_message) { |
| 108 // TODO(rafaelw): Implement. | 109 // TODO(rafaelw): Implement. |
| 109 | 110 |
| 110 // Since we are suppressing messages, just reply as if the user immediately | 111 // Since we are suppressing messages, just reply as if the user immediately |
| 111 // pressed "Cancel". | 112 // pressed "Cancel". |
| 112 OnDialogClosed(reply_msg, false, string16()); | 113 OnDialogClosed(reply_msg, false, string16()); |
| 113 | 114 |
| 114 *did_suppress_message = true; | 115 *did_suppress_message = true; |
| 115 } | 116 } |
| 116 | 117 |
| 117 bool BackgroundContents::PreHandleKeyboardEvent( | 118 bool BackgroundContents::PreHandleKeyboardEvent( |
| 118 const NativeWebKeyboardEvent& event, | 119 const NativeWebKeyboardEvent& event, |
| 119 bool* is_keyboard_shortcut) { | 120 bool* is_keyboard_shortcut) { |
| 120 return false; | 121 return false; |
| 121 } | 122 } |
| 122 | 123 |
| 123 void BackgroundContents::Observe(NotificationType type, | 124 void BackgroundContents::Observe(int type, |
| 124 const NotificationSource& source, | 125 const NotificationSource& source, |
| 125 const NotificationDetails& details) { | 126 const NotificationDetails& details) { |
| 126 // TODO(rafaelw): Implement pagegroup ref-counting so that non-persistent | 127 // TODO(rafaelw): Implement pagegroup ref-counting so that non-persistent |
| 127 // background pages are closed when the last referencing frame is closed. | 128 // background pages are closed when the last referencing frame is closed. |
| 128 switch (type.value) { | 129 switch (type) { |
| 129 case NotificationType::PROFILE_DESTROYED: | 130 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
| 130 case NotificationType::APP_TERMINATING: { | 131 case content::NOTIFICATION_APP_TERMINATING: { |
| 131 delete this; | 132 delete this; |
| 132 break; | 133 break; |
| 133 } | 134 } |
| 134 default: | 135 default: |
| 135 NOTREACHED() << "Unexpected notification sent."; | 136 NOTREACHED() << "Unexpected notification sent."; |
| 136 break; | 137 break; |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 | 140 |
| 140 void BackgroundContents::OnDialogClosed(IPC::Message* reply_msg, | 141 void BackgroundContents::OnDialogClosed(IPC::Message* reply_msg, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 157 } | 158 } |
| 158 | 159 |
| 159 void BackgroundContents::ClearInspectorSettings() { | 160 void BackgroundContents::ClearInspectorSettings() { |
| 160 Profile* profile = render_view_host_->process()->profile(); | 161 Profile* profile = render_view_host_->process()->profile(); |
| 161 RenderViewHostDelegateHelper::ClearInspectorSettings(profile); | 162 RenderViewHostDelegateHelper::ClearInspectorSettings(profile); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void BackgroundContents::Close(RenderViewHost* render_view_host) { | 165 void BackgroundContents::Close(RenderViewHost* render_view_host) { |
| 165 Profile* profile = render_view_host->process()->profile(); | 166 Profile* profile = render_view_host->process()->profile(); |
| 166 NotificationService::current()->Notify( | 167 NotificationService::current()->Notify( |
| 167 NotificationType::BACKGROUND_CONTENTS_CLOSED, | 168 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, |
| 168 Source<Profile>(profile), | 169 Source<Profile>(profile), |
| 169 Details<BackgroundContents>(this)); | 170 Details<BackgroundContents>(this)); |
| 170 delete this; | 171 delete this; |
| 171 } | 172 } |
| 172 | 173 |
| 173 void BackgroundContents::RenderViewGone(RenderViewHost* rvh, | 174 void BackgroundContents::RenderViewGone(RenderViewHost* rvh, |
| 174 base::TerminationStatus status, | 175 base::TerminationStatus status, |
| 175 int error_code) { | 176 int error_code) { |
| 176 Profile* profile = rvh->process()->profile(); | 177 Profile* profile = rvh->process()->profile(); |
| 177 NotificationService::current()->Notify( | 178 NotificationService::current()->Notify( |
| 178 NotificationType::BACKGROUND_CONTENTS_TERMINATED, | 179 chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, |
| 179 Source<Profile>(profile), | 180 Source<Profile>(profile), |
| 180 Details<BackgroundContents>(this)); | 181 Details<BackgroundContents>(this)); |
| 181 | 182 |
| 182 // Our RenderView went away, so we should go away also, so killing the process | 183 // Our RenderView went away, so we should go away also, so killing the process |
| 183 // via the TaskManager doesn't permanently leave a BackgroundContents hanging | 184 // via the TaskManager doesn't permanently leave a BackgroundContents hanging |
| 184 // around the system, blocking future instances from being created | 185 // around the system, blocking future instances from being created |
| 185 // (http://crbug.com/65189). | 186 // (http://crbug.com/65189). |
| 186 delete this; | 187 delete this; |
| 187 } | 188 } |
| 188 | 189 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 BackgroundContents* | 247 BackgroundContents* |
| 247 BackgroundContents::GetBackgroundContentsByID(int render_process_id, | 248 BackgroundContents::GetBackgroundContentsByID(int render_process_id, |
| 248 int render_view_id) { | 249 int render_view_id) { |
| 249 RenderViewHost* render_view_host = | 250 RenderViewHost* render_view_host = |
| 250 RenderViewHost::FromID(render_process_id, render_view_id); | 251 RenderViewHost::FromID(render_process_id, render_view_id); |
| 251 if (!render_view_host) | 252 if (!render_view_host) |
| 252 return NULL; | 253 return NULL; |
| 253 | 254 |
| 254 return render_view_host->delegate()->GetAsBackgroundContents(); | 255 return render_view_host->delegate()->GetAsBackgroundContents(); |
| 255 } | 256 } |
| OLD | NEW |