Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 9837074: Make it so that allow_js_access: false can be used with background pages created by window.open. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indentation. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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 // OS_WIN 10 #endif // OS_WIN
(...skipping 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 2282
2283 void Browser::OpenBookmarkManagerForNode(int64 node_id) { 2283 void Browser::OpenBookmarkManagerForNode(int64 node_id) {
2284 OpenBookmarkManagerWithHash("", node_id); 2284 OpenBookmarkManagerWithHash("", node_id);
2285 } 2285 }
2286 2286
2287 void Browser::OpenBookmarkManagerEditNode(int64 node_id) { 2287 void Browser::OpenBookmarkManagerEditNode(int64 node_id) {
2288 OpenBookmarkManagerWithHash("e=", node_id); 2288 OpenBookmarkManagerWithHash("e=", node_id);
2289 } 2289 }
2290 2290
2291 bool Browser::MaybeCreateBackgroundContents(int route_id, 2291 bool Browser::MaybeCreateBackgroundContents(int route_id,
2292 SiteInstance* site, 2292 WebContents* opener_web_contents,
2293 const GURL& opener_url, 2293 const string16& frame_name,
2294 const string16& frame_name) { 2294 const GURL& target_url) {
2295 GURL opener_url = opener_web_contents->GetURL();
2295 ExtensionService* extensions_service = profile_->GetExtensionService(); 2296 ExtensionService* extensions_service = profile_->GetExtensionService();
2296 2297
2297 if (!opener_url.is_valid() || 2298 if (!opener_url.is_valid() ||
2298 frame_name.empty() || 2299 frame_name.empty() ||
2299 !extensions_service || 2300 !extensions_service ||
2300 !extensions_service->is_ready()) 2301 !extensions_service->is_ready())
2301 return false; 2302 return false;
2302 2303
2303 // Only hosted apps have web extents, so this ensures that only hosted apps 2304 // Only hosted apps have web extents, so this ensures that only hosted apps
2304 // can create BackgroundContents. We don't have to check for background 2305 // can create BackgroundContents. We don't have to check for background
2305 // permission as that is checked in RenderMessageFilter when the CreateWindow 2306 // permission as that is checked in RenderMessageFilter when the CreateWindow
2306 // message is processed. 2307 // message is processed.
2307 const Extension* extension = 2308 const Extension* extension =
2308 extensions_service->extensions()->GetHostedAppByURL( 2309 extensions_service->extensions()->GetHostedAppByURL(
2309 ExtensionURLInfo(opener_url)); 2310 ExtensionURLInfo(opener_url));
2310 if (!extension) 2311 if (!extension)
2311 return false; 2312 return false;
2312 2313
2313 // No BackgroundContents allowed if BackgroundContentsService doesn't exist. 2314 // No BackgroundContents allowed if BackgroundContentsService doesn't exist.
2314 BackgroundContentsService* service = 2315 BackgroundContentsService* service =
2315 BackgroundContentsServiceFactory::GetForProfile(profile_); 2316 BackgroundContentsServiceFactory::GetForProfile(profile_);
2316 if (!service) 2317 if (!service)
2317 return false; 2318 return false;
2318 2319
2319 // Ensure that we're trying to open this from the extension's process. 2320 // Ensure that we're trying to open this from the extension's process.
2321 SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance();
2320 extensions::ProcessMap* process_map = extensions_service->process_map(); 2322 extensions::ProcessMap* process_map = extensions_service->process_map();
2321 if (!site->GetProcess() || 2323 if (!opener_site_instance->GetProcess() ||
2322 !process_map->Contains(extension->id(), site->GetProcess()->GetID())) { 2324 !process_map->Contains(
2325 extension->id(), opener_site_instance->GetProcess()->GetID())) {
2323 return false; 2326 return false;
2324 } 2327 }
2325 2328
2326 // Only allow a single background contents per app. If one already exists, 2329 // Only allow a single background contents per app. If one already exists,
2327 // close it (even if it was specified in the manifest). 2330 // close it (even if it was specified in the manifest).
2328 BackgroundContents* existing = 2331 BackgroundContents* existing =
2329 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); 2332 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
2330 if (existing) { 2333 if (existing) {
2331 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; 2334 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url;
2332 delete existing; 2335 delete existing;
2333 } 2336 }
2334 2337
2338 // If script access is not allowed, create the the background contents in a
2339 // new SiteInstance, so that a separate process is used.
2340 bool allow_js_access = extension->allow_background_js_access();
2341 scoped_refptr<content::SiteInstance> site_instance =
2342 allow_js_access ?
2343 opener_site_instance :
2344 content::SiteInstance::Create(opener_web_contents->GetBrowserContext());
2345
2335 // Passed all the checks, so this should be created as a BackgroundContents. 2346 // Passed all the checks, so this should be created as a BackgroundContents.
2336 BackgroundContents* contents = 2347 BackgroundContents* contents = service->CreateBackgroundContents(
2337 service->CreateBackgroundContents(site, route_id, profile_, frame_name, 2348 site_instance,
2338 ASCIIToUTF16(extension->id())); 2349 route_id,
2350 profile_,
2351 frame_name,
2352 ASCIIToUTF16(extension->id()));
2353
2354 // When a separate process is used, the original renderer cannot access the
2355 // new window later, thus we need to navigate the window now.
2356 if (contents && !allow_js_access) {
2357 contents->web_contents()->GetController().LoadURL(
2358 target_url,
2359 content::Referrer(),
2360 content::PAGE_TRANSITION_LINK,
2361 std::string()); // No extra headers.
2362 }
2363
2339 return contents != NULL; 2364 return contents != NULL;
2340 } 2365 }
2341 2366
2342 void Browser::ShowAppMenu() { 2367 void Browser::ShowAppMenu() {
2343 // We record the user metric for this event in WrenchMenu::RunMenu. 2368 // We record the user metric for this event in WrenchMenu::RunMenu.
2344 window_->ShowAppMenu(); 2369 window_->ShowAppMenu();
2345 } 2370 }
2346 2371
2347 void Browser::ShowAvatarMenu() { 2372 void Browser::ShowAvatarMenu() {
2348 window_->ShowAvatarBubbleFromAvatarButton(); 2373 window_->ShowAvatarBubbleFromAvatarButton();
(...skipping 1716 matching lines...) Expand 10 before | Expand all | Expand 10 after
4065 const history::HistoryAddPageArgs& add_page_args, 4090 const history::HistoryAddPageArgs& add_page_args,
4066 content::NavigationType navigation_type) { 4091 content::NavigationType navigation_type) {
4067 // Don't update history if running as app. 4092 // Don't update history if running as app.
4068 return !IsApplication(); 4093 return !IsApplication();
4069 } 4094 }
4070 4095
4071 bool Browser::ShouldCreateWebContents( 4096 bool Browser::ShouldCreateWebContents(
4072 WebContents* web_contents, 4097 WebContents* web_contents,
4073 int route_id, 4098 int route_id,
4074 WindowContainerType window_container_type, 4099 WindowContainerType window_container_type,
4075 const string16& frame_name) { 4100 const string16& frame_name,
4101 const GURL& target_url) {
4076 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { 4102 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
4077 // If a BackgroundContents is created, suppress the normal WebContents. 4103 // If a BackgroundContents is created, suppress the normal WebContents.
4078 return !MaybeCreateBackgroundContents( 4104 return !MaybeCreateBackgroundContents(
4079 route_id, 4105 route_id, web_contents, frame_name, target_url);
4080 web_contents->GetSiteInstance(),
4081 web_contents->GetURL(),
4082 frame_name);
4083 } 4106 }
4084 4107
4085 return true; 4108 return true;
4086 } 4109 }
4087 4110
4088 void Browser::WebContentsCreated(WebContents* source_contents, 4111 void Browser::WebContentsCreated(WebContents* source_contents,
4089 int64 source_frame_id, 4112 int64 source_frame_id,
4090 const GURL& target_url, 4113 const GURL& target_url,
4091 WebContents* new_contents) { 4114 WebContents* new_contents) {
4092 // Create a TabContentsWrapper now, so all observers are in place, as the 4115 // Create a TabContentsWrapper now, so all observers are in place, as the
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
5676 } else { 5699 } else {
5677 LoginUIServiceFactory::GetForProfile( 5700 LoginUIServiceFactory::GetForProfile(
5678 profile()->GetOriginalProfile())->ShowLoginUI(false); 5701 profile()->GetOriginalProfile())->ShowLoginUI(false);
5679 } 5702 }
5680 #endif 5703 #endif
5681 } 5704 }
5682 5705
5683 void Browser::ToggleSpeechInput() { 5706 void Browser::ToggleSpeechInput() {
5684 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput(); 5707 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput();
5685 } 5708 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698