Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 SiteInstance* site_instance, | 26 SiteInstance* site_instance, |
| 27 int routing_id, | 27 int routing_id, |
| 28 Delegate* delegate, | 28 Delegate* delegate, |
| 29 const std::string& partition_id, | 29 const std::string& partition_id, |
| 30 content::SessionStorageNamespace* session_storage_namespace) | 30 content::SessionStorageNamespace* session_storage_namespace) |
| 31 : delegate_(delegate) { | 31 : delegate_(delegate) { |
| 32 profile_ = Profile::FromBrowserContext( | 32 profile_ = Profile::FromBrowserContext( |
| 33 site_instance->GetBrowserContext()); | 33 site_instance->GetBrowserContext()); |
| 34 | 34 |
| 35 WebContents::CreateParams create_params(profile_, site_instance); | 35 WebContents::CreateParams create_params(profile_, site_instance); |
| 36 create_params.initially_hidden = true; | |
| 36 create_params.routing_id = routing_id; | 37 create_params.routing_id = routing_id; |
| 37 if (session_storage_namespace) { | 38 if (session_storage_namespace) { |
| 38 content::SessionStorageNamespaceMap session_storage_namespace_map; | 39 content::SessionStorageNamespaceMap session_storage_namespace_map; |
| 39 session_storage_namespace_map.insert( | 40 session_storage_namespace_map.insert( |
| 40 std::make_pair(partition_id, session_storage_namespace)); | 41 std::make_pair(partition_id, session_storage_namespace)); |
| 41 web_contents_.reset(WebContents::CreateWithSessionStorage( | 42 web_contents_.reset(WebContents::CreateWithSessionStorage( |
| 42 create_params, session_storage_namespace_map)); | 43 create_params, session_storage_namespace_map)); |
| 43 } else { | 44 } else { |
| 44 web_contents_.reset(WebContents::Create(create_params)); | 45 web_contents_.reset(WebContents::Create(create_params)); |
| 45 } | 46 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 void BackgroundContents::AddNewContents(WebContents* source, | 117 void BackgroundContents::AddNewContents(WebContents* source, |
| 117 WebContents* new_contents, | 118 WebContents* new_contents, |
| 118 WindowOpenDisposition disposition, | 119 WindowOpenDisposition disposition, |
| 119 const gfx::Rect& initial_pos, | 120 const gfx::Rect& initial_pos, |
| 120 bool user_gesture, | 121 bool user_gesture, |
| 121 bool* was_blocked) { | 122 bool* was_blocked) { |
| 122 delegate_->AddWebContents( | 123 delegate_->AddWebContents( |
| 123 new_contents, disposition, initial_pos, user_gesture, was_blocked); | 124 new_contents, disposition, initial_pos, user_gesture, was_blocked); |
| 124 } | 125 } |
| 125 | 126 |
| 127 bool BackgroundContents::IsWebContentsNeverVisible( | |
| 128 content::WebContents* web_contents) { | |
| 129 DCHECK_EQ(extensions::VIEW_TYPE_BACKGROUND_CONTENTS, | |
| 130 extensions::GetViewType(web_contents)); | |
|
jam
2014/04/14 22:43:01
this seems like a redundant dcheck. i would prefer
danakj
2014/04/14 22:47:30
To me it's not so much about trust but to document
| |
| 131 return true; | |
| 132 } | |
| 133 | |
| 126 void BackgroundContents::RenderProcessGone(base::TerminationStatus status) { | 134 void BackgroundContents::RenderProcessGone(base::TerminationStatus status) { |
| 127 content::NotificationService::current()->Notify( | 135 content::NotificationService::current()->Notify( |
| 128 chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, | 136 chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, |
| 129 content::Source<Profile>(profile_), | 137 content::Source<Profile>(profile_), |
| 130 content::Details<BackgroundContents>(this)); | 138 content::Details<BackgroundContents>(this)); |
| 131 | 139 |
| 132 // Our RenderView went away, so we should go away also, so killing the process | 140 // Our RenderView went away, so we should go away also, so killing the process |
| 133 // via the TaskManager doesn't permanently leave a BackgroundContents hanging | 141 // via the TaskManager doesn't permanently leave a BackgroundContents hanging |
| 134 // around the system, blocking future instances from being created | 142 // around the system, blocking future instances from being created |
| 135 // <http://crbug.com/65189>. | 143 // <http://crbug.com/65189>. |
| 136 delete this; | 144 delete this; |
| 137 } | 145 } |
| 138 | 146 |
| 139 void BackgroundContents::Observe(int type, | 147 void BackgroundContents::Observe(int type, |
| 140 const content::NotificationSource& source, | 148 const content::NotificationSource& source, |
| 141 const content::NotificationDetails& details) { | 149 const content::NotificationDetails& details) { |
| 142 // TODO(rafaelw): Implement pagegroup ref-counting so that non-persistent | 150 // TODO(rafaelw): Implement pagegroup ref-counting so that non-persistent |
| 143 // background pages are closed when the last referencing frame is closed. | 151 // background pages are closed when the last referencing frame is closed. |
| 144 switch (type) { | 152 switch (type) { |
| 145 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 153 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
| 146 case chrome::NOTIFICATION_APP_TERMINATING: { | 154 case chrome::NOTIFICATION_APP_TERMINATING: { |
| 147 delete this; | 155 delete this; |
| 148 break; | 156 break; |
| 149 } | 157 } |
| 150 default: | 158 default: |
| 151 NOTREACHED() << "Unexpected notification sent."; | 159 NOTREACHED() << "Unexpected notification sent."; |
| 152 break; | 160 break; |
| 153 } | 161 } |
| 154 } | 162 } |
| OLD | NEW |