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/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 2266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2277 | 2277 |
2278 void Browser::OpenBookmarkManagerForNode(int64 node_id) { | 2278 void Browser::OpenBookmarkManagerForNode(int64 node_id) { |
2279 OpenBookmarkManagerWithHash("", node_id); | 2279 OpenBookmarkManagerWithHash("", node_id); |
2280 } | 2280 } |
2281 | 2281 |
2282 void Browser::OpenBookmarkManagerEditNode(int64 node_id) { | 2282 void Browser::OpenBookmarkManagerEditNode(int64 node_id) { |
2283 OpenBookmarkManagerWithHash("e=", node_id); | 2283 OpenBookmarkManagerWithHash("e=", node_id); |
2284 } | 2284 } |
2285 | 2285 |
2286 bool Browser::MaybeCreateBackgroundContents(int route_id, | 2286 bool Browser::MaybeCreateBackgroundContents(int route_id, |
2287 SiteInstance* site, | 2287 WebContents* opener_web_contents, |
2288 const GURL& opener_url, | 2288 const string16& frame_name, |
2289 const string16& frame_name) { | 2289 const GURL& target_url) { |
2290 GURL opener_url = opener_web_contents->GetURL(); | |
2290 ExtensionService* extensions_service = profile_->GetExtensionService(); | 2291 ExtensionService* extensions_service = profile_->GetExtensionService(); |
2291 | 2292 |
2292 if (!opener_url.is_valid() || | 2293 if (!opener_url.is_valid() || |
2293 frame_name.empty() || | 2294 frame_name.empty() || |
2294 !extensions_service || | 2295 !extensions_service || |
2295 !extensions_service->is_ready()) | 2296 !extensions_service->is_ready()) |
2296 return false; | 2297 return false; |
2297 | 2298 |
2298 // Only hosted apps have web extents, so this ensures that only hosted apps | 2299 // Only hosted apps have web extents, so this ensures that only hosted apps |
2299 // can create BackgroundContents. We don't have to check for background | 2300 // can create BackgroundContents. We don't have to check for background |
2300 // permission as that is checked in RenderMessageFilter when the CreateWindow | 2301 // permission as that is checked in RenderMessageFilter when the CreateWindow |
2301 // message is processed. | 2302 // message is processed. |
2302 const Extension* extension = | 2303 const Extension* extension = |
2303 extensions_service->extensions()->GetHostedAppByURL( | 2304 extensions_service->extensions()->GetHostedAppByURL( |
2304 ExtensionURLInfo(opener_url)); | 2305 ExtensionURLInfo(opener_url)); |
2305 if (!extension) | 2306 if (!extension) |
2306 return false; | 2307 return false; |
2307 | 2308 |
2308 // No BackgroundContents allowed if BackgroundContentsService doesn't exist. | 2309 // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
2309 BackgroundContentsService* service = | 2310 BackgroundContentsService* service = |
2310 BackgroundContentsServiceFactory::GetForProfile(profile_); | 2311 BackgroundContentsServiceFactory::GetForProfile(profile_); |
2311 if (!service) | 2312 if (!service) |
2312 return false; | 2313 return false; |
2313 | 2314 |
2314 // Ensure that we're trying to open this from the extension's process. | 2315 // Ensure that we're trying to open this from the extension's process. |
2316 SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance(); | |
2315 extensions::ProcessMap* process_map = extensions_service->process_map(); | 2317 extensions::ProcessMap* process_map = extensions_service->process_map(); |
2316 if (!site->GetProcess() || | 2318 if (!opener_site_instance->GetProcess() || |
2317 !process_map->Contains(extension->id(), site->GetProcess()->GetID())) { | 2319 !process_map->Contains( |
2320 extension->id(), opener_site_instance->GetProcess()->GetID())) { | |
2318 return false; | 2321 return false; |
2319 } | 2322 } |
2320 | 2323 |
2321 // Only allow a single background contents per app. If one already exists, | 2324 // Only allow a single background contents per app. If one already exists, |
2322 // close it (even if it was specified in the manifest). | 2325 // close it (even if it was specified in the manifest). |
2323 BackgroundContents* existing = | 2326 BackgroundContents* existing = |
2324 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); | 2327 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); |
2325 if (existing) { | 2328 if (existing) { |
2326 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; | 2329 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; |
2327 delete existing; | 2330 delete existing; |
2328 } | 2331 } |
2329 | 2332 |
2333 // If script access is not allowed, created the the background contents in a | |
Charlie Reis
2012/03/27 23:19:27
nit: create
Mihai Parparita -not on Chrome
2012/03/28 20:29:01
Done.
| |
2334 // new SiteInstance, so that a separate process is used. | |
2335 bool allow_js_access = extension->allow_background_js_access(); | |
2336 scoped_refptr<content::SiteInstance> site_instance = | |
2337 allow_js_access ? | |
2338 opener_site_instance : | |
2339 content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); | |
2340 | |
2330 // Passed all the checks, so this should be created as a BackgroundContents. | 2341 // Passed all the checks, so this should be created as a BackgroundContents. |
2331 BackgroundContents* contents = | 2342 BackgroundContents* contents = service->CreateBackgroundContents( |
2332 service->CreateBackgroundContents(site, route_id, profile_, frame_name, | 2343 site_instance, |
2333 ASCIIToUTF16(extension->id())); | 2344 route_id, |
2345 profile_, | |
2346 frame_name, | |
2347 ASCIIToUTF16(extension->id())); | |
2348 | |
2349 // When a separate process is used, the original renderer cannot access the | |
2350 // new window later, thus we need to navigate the window now. | |
2351 if (contents && !allow_js_access) { | |
2352 contents->web_contents()->GetController().LoadURL( | |
2353 target_url, | |
2354 content::Referrer(), | |
2355 content::PAGE_TRANSITION_LINK, | |
2356 std::string()); // No extra headers. | |
2357 } | |
2358 | |
2334 return contents != NULL; | 2359 return contents != NULL; |
2335 } | 2360 } |
2336 | 2361 |
2337 void Browser::ShowAppMenu() { | 2362 void Browser::ShowAppMenu() { |
2338 // We record the user metric for this event in WrenchMenu::RunMenu. | 2363 // We record the user metric for this event in WrenchMenu::RunMenu. |
2339 window_->ShowAppMenu(); | 2364 window_->ShowAppMenu(); |
2340 } | 2365 } |
2341 | 2366 |
2342 void Browser::ShowAvatarMenu() { | 2367 void Browser::ShowAvatarMenu() { |
2343 window_->ShowAvatarBubbleFromAvatarButton(); | 2368 window_->ShowAvatarBubbleFromAvatarButton(); |
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 } |
OLD | NEW |