diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-17 23:00:59 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-17 23:00:59 +0000 |
commit | 2fab253a61e797b461b21671af7942521b749ee3 (patch) | |
tree | 6d61d2cbf0dd13956924fd7323a3c7506422dadd /webkit/glue | |
parent | 5220e732b9c11a4309c6f5a45a27d4658087b1ed (diff) | |
download | chromium_src-2fab253a61e797b461b21671af7942521b749ee3.zip chromium_src-2fab253a61e797b461b21671af7942521b749ee3.tar.gz chromium_src-2fab253a61e797b461b21671af7942521b749ee3.tar.bz2 |
Remove webview's dependency on webpreferences.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/165513
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23589 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/inspector_client_impl.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webpreferences.cc | 76 | ||||
-rw-r--r-- | webkit/glue/webpreferences.h | 6 | ||||
-rw-r--r-- | webkit/glue/webview.h | 24 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 122 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 8 | ||||
-rw-r--r-- | webkit/glue/webworker_impl.cc | 5 |
7 files changed, 120 insertions, 123 deletions
diff --git a/webkit/glue/inspector_client_impl.cc b/webkit/glue/inspector_client_impl.cc index 377798a..3d3585e 100644 --- a/webkit/glue/inspector_client_impl.cc +++ b/webkit/glue/inspector_client_impl.cc @@ -223,7 +223,7 @@ void WebInspectorClient::LoadSettings() { settings_.set(new SettingsMap); String data = webkit_glue::StdWStringToString( - inspected_web_view_->GetPreferences().inspector_settings); + inspected_web_view_->GetInspectorSettings()); if (data.isEmpty()) return; diff --git a/webkit/glue/webpreferences.cc b/webkit/glue/webpreferences.cc new file mode 100644 index 0000000..86a8c7a --- /dev/null +++ b/webkit/glue/webpreferences.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/glue/webpreferences.h" + +#include "base/string_util.h" +#include "webkit/api/public/WebKit.h" +#include "webkit/api/public/WebSettings.h" +#include "webkit/api/public/WebString.h" +#include "webkit/api/public/WebURL.h" +#include "webkit/glue/webkit_glue.h" +#include "webkit/glue/webview.h" + +using WebKit::WebSettings; +using WebKit::WebURL; + +void WebPreferences::Apply(WebView* web_view) const { + WebSettings* settings = web_view->GetSettings(); + settings->setStandardFontFamily(WideToUTF16Hack(standard_font_family)); + settings->setFixedFontFamily(WideToUTF16Hack(fixed_font_family)); + settings->setSerifFontFamily(WideToUTF16Hack(serif_font_family)); + settings->setSansSerifFontFamily(WideToUTF16Hack(sans_serif_font_family)); + settings->setCursiveFontFamily(WideToUTF16Hack(cursive_font_family)); + settings->setFantasyFontFamily(WideToUTF16Hack(fantasy_font_family)); + settings->setDefaultFontSize(default_font_size); + settings->setDefaultFixedFontSize(default_fixed_font_size); + settings->setMinimumFontSize(minimum_font_size); + settings->setMinimumLogicalFontSize(minimum_logical_font_size); + settings->setDefaultTextEncodingName(WideToUTF16Hack(default_encoding)); + settings->setJavaScriptEnabled(javascript_enabled); + settings->setWebSecurityEnabled(web_security_enabled); + settings->setJavaScriptCanOpenWindowsAutomatically( + javascript_can_open_windows_automatically); + settings->setLoadsImagesAutomatically(loads_images_automatically); + settings->setPluginsEnabled(plugins_enabled); + settings->setDOMPasteAllowed(dom_paste_enabled); + settings->setDeveloperExtrasEnabled(developer_extras_enabled); + settings->setShrinksStandaloneImagesToFit(shrinks_standalone_images_to_fit); + settings->setUsesEncodingDetector(uses_universal_detector); + settings->setTextAreasAreResizable(text_areas_are_resizable); + settings->setAllowScriptsToCloseWindows(allow_scripts_to_close_windows); + if (user_style_sheet_enabled) + settings->setUserStyleSheetLocation(user_style_sheet_location); + else + settings->setUserStyleSheetLocation(WebURL()); + settings->setUsesPageCache(uses_page_cache); + settings->setDownloadableBinaryFontsEnabled(remote_fonts_enabled); + settings->setXSSAuditorEnabled(xss_auditor_enabled); + settings->setLocalStorageEnabled(local_storage_enabled); + settings->setSessionStorageEnabled(session_storage_enabled); + settings->setOfflineWebApplicationCacheEnabled(application_cache_enabled); + + // This setting affects the behavior of links in an editable region: + // clicking the link should select it rather than navigate to it. + // Safari uses the same default. It is unlikley an embedder would want to + // change this, since it would break existing rich text editors. + settings->setEditableLinkBehaviorNeverLive(); + + settings->setFontRenderingModeNormal(); + settings->setJavaEnabled(java_enabled); + + // Turn this on to cause WebCore to paint the resize corner for us. + settings->setShouldPaintCustomScrollbars(true); + + settings->setDatabasesEnabled(WebKit::databasesEnabled()); + + // Mitigate attacks from local HTML files by not granting file:// URLs + // universal access. + settings->setAllowUniversalAccessFromFileURLs(false); + + // We prevent WebKit from checking if it needs to add a "text direction" + // submenu to a context menu. it is not only because we don't need the result + // but also because it cause a possible crash in Editor::hasBidiSelection(). + settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded(); +} diff --git a/webkit/glue/webpreferences.h b/webkit/glue/webpreferences.h index cf71900..c48339fa 100644 --- a/webkit/glue/webpreferences.h +++ b/webkit/glue/webpreferences.h @@ -5,7 +5,7 @@ // A struct for managing webkit's settings. // // Adding new values to this class probably involves updating -// WebViewImpl::SetPreferences, common/render_messages.h, and +// WebKit::WebSettings, common/render_messages.h, and // browser/profile.cc. #ifndef WEBKIT_GLUE_WEBPREFERENCES_H__ @@ -14,6 +14,8 @@ #include <string> #include "googleurl/src/gurl.h" +class WebView; + struct WebPreferences { std::wstring standard_font_family; std::wstring fixed_font_family; @@ -87,6 +89,8 @@ struct WebPreferences { application_cache_enabled(false), user_style_sheet_enabled(false) { } + + void Apply(WebView* web_view) const; }; #endif // WEBKIT_GLUE_WEBPREFERENCES_H__ diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index c329452..4b9c098 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -19,7 +19,6 @@ struct WebPoint; } struct MediaPlayerAction; -struct WebPreferences; class GURL; class WebDevToolsAgent; class WebViewDelegate; @@ -49,9 +48,13 @@ class WebView : public WebKit::WebWidget { WebView() {} virtual ~WebView() {} - // This method creates a WebView that is initially sized to an empty rect. - static WebView* Create(WebViewDelegate* delegate, - const WebPreferences& prefs); + // This method creates a WebView that is NOT yet initialized. You will need + // to call InitializeMainFrame to finish the initialization. + static WebView* Create(); + + // After creating a WebView, you should immediately call this function. + // You can optionally modify the settings (via GetSettings()) in between. + virtual void InitializeMainFrame(WebViewDelegate* delegate) = 0; // Tells all Page instances of this view to update the visited link state for // the specified hash. @@ -62,8 +65,8 @@ class WebView : public WebKit::WebWidget { static void ResetVisitedLinkState(); // Returns the delegate for this WebView. This is the pointer that was - // passed to WebView::Create. The caller must check this value before using - // it, it will be NULL during closing of the view. + // passed to WebView::Initialize. The caller must check this value before + // using it, it will be NULL during closing of the view. virtual WebViewDelegate* GetDelegate() = 0; // Instructs the EditorClient whether to pass editing notifications on to a @@ -143,16 +146,15 @@ class WebView : public WebKit::WebWidget { // image doesn't have a frame at the specified size, the first is returned. virtual bool DownloadImage(int id, const GURL& image_url, int image_size) = 0; - // Replace the standard setting for the WebView with |preferences|. - // TODO(jorlow): Remove in favor of the GetWebSettings() interface below. - virtual void SetPreferences(const WebPreferences& preferences) = 0; - virtual const WebPreferences& GetPreferences() = 0; - // Gets a WebSettings object that can be used to modify the behavior of this // WebView. The object is deleted by this class on destruction, so you must // not use it beyond WebView's lifetime. virtual WebKit::WebSettings* GetSettings() = 0; + // Settings used by inspector. + virtual const std::wstring& GetInspectorSettings() const = 0; + virtual void SetInspectorSettings(const std::wstring& settings) = 0; + // Set the encoding of the current main frame. The value comes from // the encoding menu. WebKit uses the function named // SetCustomTextEncodingName to do override encoding job. diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index e94baac..aa19fcc 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -59,14 +59,11 @@ MSVC_POP_WARNING(); #include "base/keyboard_codes.h" #include "base/logging.h" #include "base/message_loop.h" -#include "base/string_util.h" #include "webkit/api/public/WebDragData.h" #include "webkit/api/public/WebInputEvent.h" -#include "webkit/api/public/WebKit.h" #include "webkit/api/public/WebPoint.h" #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebString.h" -#include "webkit/api/public/WebURL.h" #include "webkit/api/src/WebInputEventConversion.h" #include "webkit/api/src/WebSettingsImpl.h" #include "webkit/glue/chrome_client_impl.h" @@ -80,10 +77,8 @@ MSVC_POP_WARNING(); #include "webkit/glue/inspector_client_impl.h" #include "webkit/glue/searchable_form_data.h" #include "webkit/glue/webdevtoolsagent_impl.h" -#include "webkit/glue/webdropdata.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpopupmenu_impl.h" -#include "webkit/glue/webpreferences.h" #include "webkit/glue/webdevtoolsagent.h" #include "webkit/glue/webdevtoolsclient.h" #include "webkit/glue/webview_delegate.h" @@ -118,7 +113,6 @@ using WebKit::WebTextDirection; using WebKit::WebTextDirectionDefault; using WebKit::WebTextDirectionLeftToRight; using WebKit::WebTextDirectionRightToLeft; -using WebKit::WebURL; using webkit_glue::ImageResourceFetcher; @@ -319,33 +313,31 @@ static const WebCore::PopupContainerSettings kAutocompletePopupSettings = { // WebView ---------------------------------------------------------------- /*static*/ -WebView* WebView::Create(WebViewDelegate* delegate, - const WebPreferences& prefs) { +WebView* WebView::Create() { WebViewImpl* instance = new WebViewImpl(); instance->AddRef(); - instance->SetPreferences(prefs); + return instance; +} +void WebViewImpl::InitializeMainFrame(WebViewDelegate* delegate) { // NOTE: The WebFrameImpl takes a reference to itself within InitMainFrame // and releases that reference once the corresponding Frame is destroyed. scoped_refptr<WebFrameImpl> main_frame = new WebFrameImpl(); // Set the delegate before initializing the frame, so that notifications like // DidCreateDataSource make their way to the client. - instance->delegate_ = delegate; - main_frame->InitMainFrame(instance); + delegate_ = delegate; + main_frame->InitMainFrame(this); WebDevToolsAgentDelegate* tools_delegate = delegate->GetWebDevToolsAgentDelegate(); - if (tools_delegate) { - instance->devtools_agent_.reset( - new WebDevToolsAgentImpl(instance, tools_delegate)); - } + if (tools_delegate) + devtools_agent_.reset(new WebDevToolsAgentImpl(this, tools_delegate)); // Restrict the access to the local file system // (see WebView.mm WebView::_commonInitializationWithFrameName). FrameLoader::setLocalLoadPolicy( FrameLoader::AllowLocalLoadsForLocalOnly); - return instance; } // static @@ -1382,96 +1374,6 @@ bool WebViewImpl::DownloadImage(int id, const GURL& image_url, return true; } -void WebViewImpl::SetPreferences(const WebPreferences& preferences) { - if (!page_.get()) - return; - - // Keep a local copy of the preferences struct for GetPreferences. - webprefs_ = preferences; - - WebSettings* settings = GetSettings(); - - settings->setStandardFontFamily(WideToUTF16Hack( - preferences.standard_font_family)); - settings->setFixedFontFamily(WideToUTF16Hack( - preferences.fixed_font_family)); - settings->setSerifFontFamily(WideToUTF16Hack( - preferences.serif_font_family)); - settings->setSansSerifFontFamily(WideToUTF16Hack( - preferences.sans_serif_font_family)); - settings->setCursiveFontFamily(WideToUTF16Hack( - preferences.cursive_font_family)); - settings->setFantasyFontFamily(WideToUTF16Hack( - preferences.fantasy_font_family)); - settings->setDefaultFontSize(preferences.default_font_size); - settings->setDefaultFixedFontSize(preferences.default_fixed_font_size); - settings->setMinimumFontSize(preferences.minimum_font_size); - settings->setMinimumLogicalFontSize(preferences.minimum_logical_font_size); - settings->setDefaultTextEncodingName(WideToUTF16Hack( - preferences.default_encoding)); - settings->setJavaScriptEnabled(preferences.javascript_enabled); - settings->setWebSecurityEnabled(preferences.web_security_enabled); - settings->setJavaScriptCanOpenWindowsAutomatically( - preferences.javascript_can_open_windows_automatically); - settings->setLoadsImagesAutomatically( - preferences.loads_images_automatically); - settings->setPluginsEnabled(preferences.plugins_enabled); - settings->setDOMPasteAllowed(preferences.dom_paste_enabled); - settings->setDeveloperExtrasEnabled(preferences.developer_extras_enabled); - settings->setShrinksStandaloneImagesToFit( - preferences.shrinks_standalone_images_to_fit); - settings->setUsesEncodingDetector(preferences.uses_universal_detector); - settings->setTextAreasAreResizable(preferences.text_areas_are_resizable); - settings->setAllowScriptsToCloseWindows( - preferences.allow_scripts_to_close_windows); - if (preferences.user_style_sheet_enabled) - settings->setUserStyleSheetLocation(preferences.user_style_sheet_location); - else - settings->setUserStyleSheetLocation(WebURL()); - settings->setUsesPageCache(preferences.uses_page_cache); - settings->setDownloadableBinaryFontsEnabled(preferences.remote_fonts_enabled); - settings->setXSSAuditorEnabled(preferences.xss_auditor_enabled); - settings->setLocalStorageEnabled(preferences.local_storage_enabled); - settings->setSessionStorageEnabled(preferences.session_storage_enabled); - settings->setOfflineWebApplicationCacheEnabled(preferences.application_cache_enabled); - - // This setting affects the behavior of links in an editable region: - // clicking the link should select it rather than navigate to it. - // Safari uses the same default. It is unlikley an embedder would want to - // change this, since it would break existing rich text editors. - settings->setEditableLinkBehaviorNeverLive(); - - settings->setFontRenderingModeNormal(); - settings->setJavaEnabled(preferences.java_enabled); - - // Turn this on to cause WebCore to paint the resize corner for us. - settings->setShouldPaintCustomScrollbars(true); - -#if ENABLE(DATABASE) - settings->setDatabasesEnabled(WebKit::databasesEnabled()); -#endif - - // Mitigate attacks from local HTML files by not granting file:// URLs - // universal access. - settings->setAllowUniversalAccessFromFileURLs(false); - - // We prevent WebKit from checking if it needs to add a "text direction" - // submenu to a context menu. it is not only because we don't need the result - // but also because it cause a possible crash in Editor::hasBidiSelection(). - settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded(); - -#if defined(OS_WIN) - // RenderTheme is a singleton that needs to know the default font size to - // draw some form controls. We let it know each time the size changes. - WebCore::RenderThemeChromiumWin::setDefaultFontSize( - preferences.default_font_size); -#endif -} - -const WebPreferences& WebViewImpl::GetPreferences() { - return webprefs_; -} - WebSettings* WebViewImpl::GetSettings() { if (!web_settings_.get()) web_settings_.reset(new WebSettingsImpl(page_->settings())); @@ -1479,6 +1381,14 @@ WebSettings* WebViewImpl::GetSettings() { return web_settings_.get(); } +const std::wstring& WebViewImpl::GetInspectorSettings() const { + return inspector_settings_; +} + +void WebViewImpl::SetInspectorSettings(const std::wstring& settings) { + inspector_settings_ = settings; +} + // Set the encoding of the current main frame to the one selected by // a user in the encoding menu. void WebViewImpl::SetPageEncoding(const std::wstring& encoding_name) { diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 17b139b..91e05b9 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -73,6 +73,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { virtual void setTextDirection(WebKit::WebTextDirection direction); // WebView methods: + virtual void InitializeMainFrame(WebViewDelegate* delegate); virtual bool ShouldClose(); virtual void ClosePage(); virtual WebViewDelegate* GetDelegate(); @@ -89,9 +90,9 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { virtual void SetBackForwardListSize(int size); virtual void SetInitialFocus(bool reverse); virtual bool DownloadImage(int id, const GURL& image_url, int image_size); - virtual void SetPreferences(const WebPreferences& preferences); - virtual const WebPreferences& GetPreferences(); virtual WebKit::WebSettings* GetSettings(); + virtual const std::wstring& GetInspectorSettings() const; + virtual void SetInspectorSettings(const std::wstring& settings); virtual void SetPageEncoding(const std::wstring& encoding_name); virtual std::wstring GetMainFrameEncodingName(); virtual void ZoomIn(bool text_only); @@ -362,6 +363,9 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { // Whether the webview is rendering transparently. bool is_transparent_; + // Inspector settings. + std::wstring inspector_settings_; + // HACK: current_input_event is for ChromeClientImpl::show(), until we can fix // WebKit to pass enough information up into ChromeClient::show() so we can // decide if the window.open event was caused by a middle-mouse click diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc index da8a273..3b33614 100644 --- a/webkit/glue/webworker_impl.cc +++ b/webkit/glue/webworker_impl.cc @@ -149,8 +149,9 @@ void WebWorkerImpl::startWorkerContext(const WebURL& script_url, // loading requests from the worker context to the rest of WebKit and Chromium // infrastructure. DCHECK(!web_view_); - web_view_ = WebView::Create(WorkerWebViewDelegate::worker_delegate(), - WebPreferences()); + web_view_ = WebView::Create(); + WebPreferences().Apply(web_view_); + web_view_->InitializeMainFrame(WorkerWebViewDelegate::worker_delegate()); WebFrameImpl* web_frame = static_cast<WebFrameImpl*>(web_view_->GetMainFrame()); |