| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #endif // defined(OS_WIN) | 10 #endif // defined(OS_WIN) |
| (...skipping 2238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2249 extensions::ProcessMap* process_map = extensions_service->process_map(); | 2249 extensions::ProcessMap* process_map = extensions_service->process_map(); |
| 2250 if (!opener_site_instance->GetProcess() || | 2250 if (!opener_site_instance->GetProcess() || |
| 2251 !process_map->Contains( | 2251 !process_map->Contains( |
| 2252 extension->id(), opener_site_instance->GetProcess()->GetID())) { | 2252 extension->id(), opener_site_instance->GetProcess()->GetID())) { |
| 2253 return false; | 2253 return false; |
| 2254 } | 2254 } |
| 2255 | 2255 |
| 2256 // Only allow a single background contents per app. | 2256 // Only allow a single background contents per app. |
| 2257 bool allow_js_access = extensions::BackgroundInfo::AllowJSAccess(extension); | 2257 bool allow_js_access = extensions::BackgroundInfo::AllowJSAccess(extension); |
| 2258 BackgroundContents* existing = | 2258 BackgroundContents* existing = |
| 2259 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); | 2259 service->GetAppBackgroundContents(base::ASCIIToUTF16(extension->id())); |
| 2260 if (existing) { | 2260 if (existing) { |
| 2261 // For non-scriptable background contents, ignore the request altogether, | 2261 // For non-scriptable background contents, ignore the request altogether, |
| 2262 // (returning true, so that a regular WebContents isn't created either). | 2262 // (returning true, so that a regular WebContents isn't created either). |
| 2263 if (!allow_js_access) | 2263 if (!allow_js_access) |
| 2264 return true; | 2264 return true; |
| 2265 // For scriptable background pages, if one already exists, close it (even | 2265 // For scriptable background pages, if one already exists, close it (even |
| 2266 // if it was specified in the manifest). | 2266 // if it was specified in the manifest). |
| 2267 delete existing; | 2267 delete existing; |
| 2268 } | 2268 } |
| 2269 | 2269 |
| 2270 // If script access is not allowed, create the the background contents in a | 2270 // If script access is not allowed, create the the background contents in a |
| 2271 // new SiteInstance, so that a separate process is used. | 2271 // new SiteInstance, so that a separate process is used. |
| 2272 scoped_refptr<content::SiteInstance> site_instance = | 2272 scoped_refptr<content::SiteInstance> site_instance = |
| 2273 allow_js_access ? | 2273 allow_js_access ? |
| 2274 opener_site_instance : | 2274 opener_site_instance : |
| 2275 content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); | 2275 content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); |
| 2276 | 2276 |
| 2277 // Passed all the checks, so this should be created as a BackgroundContents. | 2277 // Passed all the checks, so this should be created as a BackgroundContents. |
| 2278 BackgroundContents* contents = | 2278 BackgroundContents* contents = |
| 2279 service->CreateBackgroundContents(site_instance.get(), | 2279 service->CreateBackgroundContents(site_instance.get(), |
| 2280 route_id, | 2280 route_id, |
| 2281 profile_, | 2281 profile_, |
| 2282 frame_name, | 2282 frame_name, |
| 2283 ASCIIToUTF16(extension->id()), | 2283 base::ASCIIToUTF16(extension->id()), |
| 2284 partition_id, | 2284 partition_id, |
| 2285 session_storage_namespace); | 2285 session_storage_namespace); |
| 2286 | 2286 |
| 2287 // When a separate process is used, the original renderer cannot access the | 2287 // When a separate process is used, the original renderer cannot access the |
| 2288 // new window later, thus we need to navigate the window now. | 2288 // new window later, thus we need to navigate the window now. |
| 2289 if (contents && !allow_js_access) { | 2289 if (contents && !allow_js_access) { |
| 2290 contents->web_contents()->GetController().LoadURL( | 2290 contents->web_contents()->GetController().LoadURL( |
| 2291 target_url, | 2291 target_url, |
| 2292 content::Referrer(), | 2292 content::Referrer(), |
| 2293 content::PAGE_TRANSITION_LINK, | 2293 content::PAGE_TRANSITION_LINK, |
| 2294 std::string()); // No extra headers. | 2294 std::string()); // No extra headers. |
| 2295 } | 2295 } |
| 2296 | 2296 |
| 2297 return contents != NULL; | 2297 return contents != NULL; |
| 2298 } | 2298 } |
| OLD | NEW |