| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); | 327 RenderWidgetHostView* widget_host_view = GetCreatedWidget(route_id); |
| 328 widget_host_view->InitAsFullscreen(tab_contents->GetRenderWidgetHostView()); | 328 widget_host_view->InitAsFullscreen(tab_contents->GetRenderWidgetHostView()); |
| 329 widget_host_view->GetRenderWidgetHost()->Init(); | 329 widget_host_view->GetRenderWidgetHost()->Init(); |
| 330 return widget_host_view; | 330 return widget_host_view; |
| 331 } | 331 } |
| 332 | 332 |
| 333 // static | 333 // static |
| 334 WebPreferences RenderViewHostDelegateHelper::GetWebkitPrefs( | 334 WebPreferences RenderViewHostDelegateHelper::GetWebkitPrefs( |
| 335 RenderViewHost* rvh) { | 335 RenderViewHost* rvh) { |
| 336 Profile* profile = Profile::FromBrowserContext( | 336 Profile* profile = Profile::FromBrowserContext( |
| 337 rvh->process()->browser_context()); | 337 rvh->process()->GetBrowserContext()); |
| 338 PrefService* prefs = profile->GetPrefs(); | 338 PrefService* prefs = profile->GetPrefs(); |
| 339 WebPreferences web_prefs; | 339 WebPreferences web_prefs; |
| 340 | 340 |
| 341 web_prefs.standard_font_family = | 341 web_prefs.standard_font_family = |
| 342 UTF8ToUTF16(prefs->GetString(prefs::kWebKitStandardFontFamily)); | 342 UTF8ToUTF16(prefs->GetString(prefs::kWebKitStandardFontFamily)); |
| 343 web_prefs.fixed_font_family = | 343 web_prefs.fixed_font_family = |
| 344 UTF8ToUTF16(prefs->GetString(prefs::kWebKitFixedFontFamily)); | 344 UTF8ToUTF16(prefs->GetString(prefs::kWebKitFixedFontFamily)); |
| 345 web_prefs.serif_font_family = | 345 web_prefs.serif_font_family = |
| 346 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSerifFontFamily)); | 346 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSerifFontFamily)); |
| 347 web_prefs.sans_serif_font_family = | 347 web_prefs.sans_serif_font_family = |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 web_prefs.default_encoding = | 531 web_prefs.default_encoding = |
| 532 CharacterEncoding::GetCanonicalEncodingNameByAliasName( | 532 CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
| 533 web_prefs.default_encoding); | 533 web_prefs.default_encoding); |
| 534 if (web_prefs.default_encoding.empty()) { | 534 if (web_prefs.default_encoding.empty()) { |
| 535 prefs->ClearPref(prefs::kDefaultCharset); | 535 prefs->ClearPref(prefs::kDefaultCharset); |
| 536 web_prefs.default_encoding = prefs->GetString(prefs::kDefaultCharset); | 536 web_prefs.default_encoding = prefs->GetString(prefs::kDefaultCharset); |
| 537 } | 537 } |
| 538 DCHECK(!web_prefs.default_encoding.empty()); | 538 DCHECK(!web_prefs.default_encoding.empty()); |
| 539 | 539 |
| 540 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( | 540 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| 541 rvh->process()->id())) { | 541 rvh->process()->GetID())) { |
| 542 web_prefs.loads_images_automatically = true; | 542 web_prefs.loads_images_automatically = true; |
| 543 web_prefs.javascript_enabled = true; | 543 web_prefs.javascript_enabled = true; |
| 544 } | 544 } |
| 545 | 545 |
| 546 web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline(); | 546 web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline(); |
| 547 | 547 |
| 548 ExtensionService* service = profile->GetExtensionService(); | 548 ExtensionService* service = profile->GetExtensionService(); |
| 549 if (service) { | 549 if (service) { |
| 550 const Extension* extension = | 550 const Extension* extension = |
| 551 service->GetExtensionByURL(rvh->site_instance()->site()); | 551 service->GetExtensionByURL(rvh->site_instance()->site()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 579 DictionaryValue* inspector_settings = update.Get(); | 579 DictionaryValue* inspector_settings = update.Get(); |
| 580 inspector_settings->SetWithoutPathExpansion(key, | 580 inspector_settings->SetWithoutPathExpansion(key, |
| 581 Value::CreateStringValue(value)); | 581 Value::CreateStringValue(value)); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void RenderViewHostDelegateHelper::ClearInspectorSettings( | 584 void RenderViewHostDelegateHelper::ClearInspectorSettings( |
| 585 content::BrowserContext* browser_context) { | 585 content::BrowserContext* browser_context) { |
| 586 Profile::FromBrowserContext(browser_context)->GetPrefs()-> | 586 Profile::FromBrowserContext(browser_context)->GetPrefs()-> |
| 587 ClearPref(prefs::kWebKitInspectorSettings); | 587 ClearPref(prefs::kWebKitInspectorSettings); |
| 588 } | 588 } |
| OLD | NEW |