| 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/render_view_host_delegate_helper.h" | 5 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/tab_contents/background_contents.h" | 25 #include "chrome/browser/tab_contents/background_contents.h" |
| 26 #include "chrome/browser/user_style_sheet_watcher.h" | 26 #include "chrome/browser/user_style_sheet_watcher.h" |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/chrome_view_types.h" | 28 #include "chrome/common/chrome_view_types.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "content/browser/child_process_security_policy.h" | 30 #include "content/browser/child_process_security_policy.h" |
| 31 #include "content/browser/gpu/gpu_data_manager.h" | 31 #include "content/browser/gpu/gpu_data_manager.h" |
| 32 #include "content/browser/gpu/gpu_process_host.h" | 32 #include "content/browser/gpu/gpu_process_host.h" |
| 33 #include "content/browser/renderer_host/render_view_host.h" | 33 #include "content/browser/renderer_host/render_view_host.h" |
| 34 #include "content/browser/renderer_host/render_process_host.h" | |
| 35 #include "content/browser/renderer_host/render_widget_fullscreen_host.h" | 34 #include "content/browser/renderer_host/render_widget_fullscreen_host.h" |
| 36 #include "content/browser/renderer_host/render_widget_host.h" | 35 #include "content/browser/renderer_host/render_widget_host.h" |
| 37 #include "content/browser/renderer_host/render_widget_host_view.h" | 36 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 38 #include "content/browser/site_instance.h" | 37 #include "content/browser/site_instance.h" |
| 39 #include "content/browser/tab_contents/navigation_details.h" | 38 #include "content/browser/tab_contents/navigation_details.h" |
| 40 #include "content/browser/tab_contents/tab_contents.h" | 39 #include "content/browser/tab_contents/tab_contents.h" |
| 41 #include "content/browser/tab_contents/tab_contents_delegate.h" | 40 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 42 #include "content/browser/tab_contents/tab_contents_view.h" | 41 #include "content/browser/tab_contents/tab_contents_view.h" |
| 43 #include "content/browser/webui/web_ui.h" | 42 #include "content/browser/webui/web_ui.h" |
| 44 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/render_process_host.h" |
| 45 #include "content/common/view_messages.h" | 45 #include "content/common/view_messages.h" |
| 46 #include "net/base/network_change_notifier.h" | 46 #include "net/base/network_change_notifier.h" |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 // Fills |map| with the per-script font prefs under path |map_name|. | 50 // Fills |map| with the per-script font prefs under path |map_name|. |
| 51 void FillFontFamilyMap(const PrefService* prefs, | 51 void FillFontFamilyMap(const PrefService* prefs, |
| 52 const char* map_name, | 52 const char* map_name, |
| 53 WebPreferences::ScriptFontFamilyMap* map) { | 53 WebPreferences::ScriptFontFamilyMap* map) { |
| 54 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { | 54 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 // No BackgroundContents allowed if BackgroundContentsService doesn't exist. | 112 // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
| 113 BackgroundContentsService* service = | 113 BackgroundContentsService* service = |
| 114 BackgroundContentsServiceFactory::GetForProfile(profile); | 114 BackgroundContentsServiceFactory::GetForProfile(profile); |
| 115 if (!service) | 115 if (!service) |
| 116 return NULL; | 116 return NULL; |
| 117 | 117 |
| 118 // Ensure that we're trying to open this from the extension's process. | 118 // Ensure that we're trying to open this from the extension's process. |
| 119 extensions::ProcessMap* process_map = extensions_service->process_map(); | 119 extensions::ProcessMap* process_map = extensions_service->process_map(); |
| 120 if (!site->GetProcess() || | 120 if (!site->GetProcess() || |
| 121 !process_map->Contains(extension->id(), site->GetProcess()->id())) { | 121 !process_map->Contains(extension->id(), site->GetProcess()->GetID())) { |
| 122 return NULL; | 122 return NULL; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Only allow a single background contents per app. If one already exists, | 125 // Only allow a single background contents per app. If one already exists, |
| 126 // close it (even if it was specified in the manifest). | 126 // close it (even if it was specified in the manifest). |
| 127 BackgroundContents* existing = | 127 BackgroundContents* existing = |
| 128 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); | 128 service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); |
| 129 if (existing) { | 129 if (existing) { |
| 130 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; | 130 DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; |
| 131 delete existing; | 131 delete existing; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // TODO(brettw) it seems bogus that we have to call this function on the | 182 // TODO(brettw) it seems bogus that we have to call this function on the |
| 183 // newly created object and give it one of its own member variables. | 183 // newly created object and give it one of its own member variables. |
| 184 new_view->CreateViewForWidget(new_contents->render_view_host()); | 184 new_view->CreateViewForWidget(new_contents->render_view_host()); |
| 185 | 185 |
| 186 // Save the created window associated with the route so we can show it later. | 186 // Save the created window associated with the route so we can show it later. |
| 187 pending_contents_[route_id] = new_contents->render_view_host(); | 187 pending_contents_[route_id] = new_contents->render_view_host(); |
| 188 return new_contents; | 188 return new_contents; |
| 189 } | 189 } |
| 190 | 190 |
| 191 RenderWidgetHostView* RenderViewHostDelegateViewHelper::CreateNewWidget( | 191 RenderWidgetHostView* RenderViewHostDelegateViewHelper::CreateNewWidget( |
| 192 int route_id, WebKit::WebPopupType popup_type, RenderProcessHost* process) { | 192 int route_id, WebKit::WebPopupType popup_type, |
| 193 content::RenderProcessHost* process) { |
| 193 RenderWidgetHost* widget_host = | 194 RenderWidgetHost* widget_host = |
| 194 new RenderWidgetHost(process, route_id); | 195 new RenderWidgetHost(process, route_id); |
| 195 RenderWidgetHostView* widget_view = | 196 RenderWidgetHostView* widget_view = |
| 196 content::GetContentClient()->browser()->CreateViewForWidget(widget_host); | 197 content::GetContentClient()->browser()->CreateViewForWidget(widget_host); |
| 197 // Popups should not get activated. | 198 // Popups should not get activated. |
| 198 widget_view->set_popup_type(popup_type); | 199 widget_view->set_popup_type(popup_type); |
| 199 // Save the created widget associated with the route so we can show it later. | 200 // Save the created widget associated with the route so we can show it later. |
| 200 pending_widget_views_[route_id] = widget_view; | 201 pending_widget_views_[route_id] = widget_view; |
| 201 return widget_view; | 202 return widget_view; |
| 202 } | 203 } |
| 203 | 204 |
| 204 RenderWidgetHostView* | 205 RenderWidgetHostView* |
| 205 RenderViewHostDelegateViewHelper::CreateNewFullscreenWidget( | 206 RenderViewHostDelegateViewHelper::CreateNewFullscreenWidget( |
| 206 int route_id, RenderProcessHost* process) { | 207 int route_id, content::RenderProcessHost* process) { |
| 207 RenderWidgetFullscreenHost* fullscreen_widget_host = | 208 RenderWidgetFullscreenHost* fullscreen_widget_host = |
| 208 new RenderWidgetFullscreenHost(process, route_id); | 209 new RenderWidgetFullscreenHost(process, route_id); |
| 209 RenderWidgetHostView* widget_view = | 210 RenderWidgetHostView* widget_view = |
| 210 content::GetContentClient()->browser()->CreateViewForWidget( | 211 content::GetContentClient()->browser()->CreateViewForWidget( |
| 211 fullscreen_widget_host); | 212 fullscreen_widget_host); |
| 212 pending_widget_views_[route_id] = widget_view; | 213 pending_widget_views_[route_id] = widget_view; |
| 213 return widget_view; | 214 return widget_view; |
| 214 } | 215 } |
| 215 | 216 |
| 216 TabContents* RenderViewHostDelegateViewHelper::GetCreatedWindow(int route_id) { | 217 TabContents* RenderViewHostDelegateViewHelper::GetCreatedWindow(int route_id) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); | 328 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); |
| 328 widget_host_view->InitAsFullscreen(tab_contents->GetRenderWidgetHostView()); | 329 widget_host_view->InitAsFullscreen(tab_contents->GetRenderWidgetHostView()); |
| 329 widget_host_view->GetRenderWidgetHost()->Init(); | 330 widget_host_view->GetRenderWidgetHost()->Init(); |
| 330 return widget_host_view; | 331 return widget_host_view; |
| 331 } | 332 } |
| 332 | 333 |
| 333 // static | 334 // static |
| 334 WebPreferences RenderViewHostDelegateHelper::GetWebkitPrefs( | 335 WebPreferences RenderViewHostDelegateHelper::GetWebkitPrefs( |
| 335 RenderViewHost* rvh) { | 336 RenderViewHost* rvh) { |
| 336 Profile* profile = Profile::FromBrowserContext( | 337 Profile* profile = Profile::FromBrowserContext( |
| 337 rvh->process()->browser_context()); | 338 rvh->process()->GetBrowserContext()); |
| 338 PrefService* prefs = profile->GetPrefs(); | 339 PrefService* prefs = profile->GetPrefs(); |
| 339 WebPreferences web_prefs; | 340 WebPreferences web_prefs; |
| 340 | 341 |
| 341 web_prefs.standard_font_family = | 342 web_prefs.standard_font_family = |
| 342 UTF8ToUTF16(prefs->GetString(prefs::kWebKitStandardFontFamily)); | 343 UTF8ToUTF16(prefs->GetString(prefs::kWebKitStandardFontFamily)); |
| 343 web_prefs.fixed_font_family = | 344 web_prefs.fixed_font_family = |
| 344 UTF8ToUTF16(prefs->GetString(prefs::kWebKitFixedFontFamily)); | 345 UTF8ToUTF16(prefs->GetString(prefs::kWebKitFixedFontFamily)); |
| 345 web_prefs.serif_font_family = | 346 web_prefs.serif_font_family = |
| 346 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSerifFontFamily)); | 347 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSerifFontFamily)); |
| 347 web_prefs.sans_serif_font_family = | 348 web_prefs.sans_serif_font_family = |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 web_prefs.default_encoding = | 532 web_prefs.default_encoding = |
| 532 CharacterEncoding::GetCanonicalEncodingNameByAliasName( | 533 CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
| 533 web_prefs.default_encoding); | 534 web_prefs.default_encoding); |
| 534 if (web_prefs.default_encoding.empty()) { | 535 if (web_prefs.default_encoding.empty()) { |
| 535 prefs->ClearPref(prefs::kDefaultCharset); | 536 prefs->ClearPref(prefs::kDefaultCharset); |
| 536 web_prefs.default_encoding = prefs->GetString(prefs::kDefaultCharset); | 537 web_prefs.default_encoding = prefs->GetString(prefs::kDefaultCharset); |
| 537 } | 538 } |
| 538 DCHECK(!web_prefs.default_encoding.empty()); | 539 DCHECK(!web_prefs.default_encoding.empty()); |
| 539 | 540 |
| 540 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( | 541 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| 541 rvh->process()->id())) { | 542 rvh->process()->GetID())) { |
| 542 web_prefs.loads_images_automatically = true; | 543 web_prefs.loads_images_automatically = true; |
| 543 web_prefs.javascript_enabled = true; | 544 web_prefs.javascript_enabled = true; |
| 544 } | 545 } |
| 545 | 546 |
| 546 web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline(); | 547 web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline(); |
| 547 | 548 |
| 548 ExtensionService* service = profile->GetExtensionService(); | 549 ExtensionService* service = profile->GetExtensionService(); |
| 549 if (service) { | 550 if (service) { |
| 550 const Extension* extension = | 551 const Extension* extension = |
| 551 service->GetExtensionByURL(rvh->site_instance()->site()); | 552 service->GetExtensionByURL(rvh->site_instance()->site()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 580 DictionaryValue* inspector_settings = update.Get(); | 581 DictionaryValue* inspector_settings = update.Get(); |
| 581 inspector_settings->SetWithoutPathExpansion(key, | 582 inspector_settings->SetWithoutPathExpansion(key, |
| 582 Value::CreateStringValue(value)); | 583 Value::CreateStringValue(value)); |
| 583 } | 584 } |
| 584 | 585 |
| 585 void RenderViewHostDelegateHelper::ClearInspectorSettings( | 586 void RenderViewHostDelegateHelper::ClearInspectorSettings( |
| 586 content::BrowserContext* browser_context) { | 587 content::BrowserContext* browser_context) { |
| 587 Profile::FromBrowserContext(browser_context)->GetPrefs()-> | 588 Profile::FromBrowserContext(browser_context)->GetPrefs()-> |
| 588 ClearPref(prefs::kWebKitInspectorSettings); | 589 ClearPref(prefs::kWebKitInspectorSettings); |
| 589 } | 590 } |
| OLD | NEW |