diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/resource_message_filter.cc | 100 | ||||
-rw-r--r-- | chrome/browser/resource_message_filter.h | 8 | ||||
-rw-r--r-- | chrome/common/ipc_message_utils.h | 24 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 25 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 9 | ||||
-rw-r--r-- | chrome/renderer/renderer_glue.cc | 9 |
6 files changed, 90 insertions, 85 deletions
diff --git a/chrome/browser/resource_message_filter.cc b/chrome/browser/resource_message_filter.cc index 534e447..17c266b 100644 --- a/chrome/browser/resource_message_filter.cc +++ b/chrome/browser/resource_message_filter.cc @@ -25,57 +25,9 @@ #include "chrome/common/render_messages.h" #include "net/base/cookie_monster.h" #include "net/base/mime_util.h" +#include "webkit/glue/webkit_glue.h" #include "webkit/glue/webplugin.h" -void ResourceMessageFilter::OnGetMonitorInfoForWindow( - HWND window, MONITORINFOEX* monitor_info) { - HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY); - monitor_info->cbSize = sizeof(MONITORINFOEX); - GetMonitorInfo(monitor, monitor_info); -} - -void ResourceMessageFilter::OnLoadFont(LOGFONT font) { - // If renderer is running in a sandbox, GetTextMetrics - // can sometimes fail. If a font has not been loaded - // previously, GetTextMetrics will try to load the font - // from the font file. However, the sandboxed renderer does - // not have permissions to access any font files and - // the call fails. So we make the browser pre-load the - // font for us by using a dummy call to GetTextMetrics of - // the same font. - - // Maintain a circular queue for the fonts and DCs to be cached. - // font_index maintains next available location in the queue. - static const int kFontCacheSize = 32; - static HFONT fonts[kFontCacheSize] = {0}; - static HDC hdcs[kFontCacheSize] = {0}; - static size_t font_index = 0; - - UMA_HISTOGRAM_COUNTS_100(L"Memory.CachedFontAndDC", - fonts[kFontCacheSize-1] ? kFontCacheSize : static_cast<int>(font_index)); - - HDC hdc = GetDC(NULL); - HFONT font_handle = CreateFontIndirect(&font); - DCHECK(NULL != font_handle); - - HGDIOBJ old_font = SelectObject(hdc, font_handle); - DCHECK(NULL != old_font); - - TEXTMETRIC tm; - BOOL ret = GetTextMetrics(hdc, &tm); - DCHECK(ret); - - if (fonts[font_index] || hdcs[font_index]) { - // We already have too many fonts, we will delete one and take it's place. - DeleteObject(fonts[font_index]); - ReleaseDC(NULL, hdcs[font_index]); - } - - fonts[font_index] = font_handle; - hdcs[font_index] = hdc; - font_index = (font_index + 1) % kFontCacheSize; -} - ResourceMessageFilter::ResourceMessageFilter( ResourceDispatcherHost* resource_dispatcher_host, PluginService* plugin_service, @@ -161,8 +113,7 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewHostMsg_PluginMessage, OnPluginMessage) IPC_MESSAGE_HANDLER(ViewHostMsg_PluginSyncMessage, OnPluginSyncMessage) IPC_MESSAGE_HANDLER(ViewHostMsg_LoadFont, OnLoadFont) - IPC_MESSAGE_HANDLER(ViewHostMsg_GetMonitorInfoForWindow, - OnGetMonitorInfoForWindow) + IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnGetScreenInfo) IPC_MESSAGE_HANDLER(ViewHostMsg_GetPlugins, OnGetPlugins) IPC_MESSAGE_HANDLER(ViewHostMsg_GetPluginPath, OnGetPluginPath) IPC_MESSAGE_HANDLER(ViewHostMsg_DownloadUrl, OnDownloadUrl) @@ -400,6 +351,53 @@ void ResourceMessageFilter::OnPluginSyncMessage(const std::wstring& dll_path, } } +void ResourceMessageFilter::OnLoadFont(LOGFONT font) { + // If renderer is running in a sandbox, GetTextMetrics + // can sometimes fail. If a font has not been loaded + // previously, GetTextMetrics will try to load the font + // from the font file. However, the sandboxed renderer does + // not have permissions to access any font files and + // the call fails. So we make the browser pre-load the + // font for us by using a dummy call to GetTextMetrics of + // the same font. + + // Maintain a circular queue for the fonts and DCs to be cached. + // font_index maintains next available location in the queue. + static const int kFontCacheSize = 32; + static HFONT fonts[kFontCacheSize] = {0}; + static HDC hdcs[kFontCacheSize] = {0}; + static size_t font_index = 0; + + UMA_HISTOGRAM_COUNTS_100(L"Memory.CachedFontAndDC", + fonts[kFontCacheSize-1] ? kFontCacheSize : static_cast<int>(font_index)); + + HDC hdc = GetDC(NULL); + HFONT font_handle = CreateFontIndirect(&font); + DCHECK(NULL != font_handle); + + HGDIOBJ old_font = SelectObject(hdc, font_handle); + DCHECK(NULL != old_font); + + TEXTMETRIC tm; + BOOL ret = GetTextMetrics(hdc, &tm); + DCHECK(ret); + + if (fonts[font_index] || hdcs[font_index]) { + // We already have too many fonts, we will delete one and take it's place. + DeleteObject(fonts[font_index]); + ReleaseDC(NULL, hdcs[font_index]); + } + + fonts[font_index] = font_handle; + hdcs[font_index] = hdc; + font_index = (font_index + 1) % kFontCacheSize; +} + +void ResourceMessageFilter::OnGetScreenInfo( + gfx::ViewHandle window, webkit_glue::ScreenInfo* results) { + *results = webkit_glue::GetScreenInfoHelper(window); +} + void ResourceMessageFilter::OnGetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { plugin_service_->GetPlugins(refresh, plugins); diff --git a/chrome/browser/resource_message_filter.h b/chrome/browser/resource_message_filter.h index 5cd9d11..1ac4c15 100644 --- a/chrome/browser/resource_message_filter.h +++ b/chrome/browser/resource_message_filter.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H__ #include "base/gfx/rect.h" +#include "base/gfx/native_widget_types.h" #include "base/ref_counted.h" #include "chrome/browser/resource_dispatcher_host.h" #include "chrome/common/ipc_channel_proxy.h" @@ -23,6 +24,10 @@ class PrinterQuery; class PrintJobManager; } +namespace webkit_glue { +struct ScreenInfo; +} + // This class filters out incoming IPC messages for network requests and // processes them on the IPC thread. As a result, network requests are not // delayed by costly UI processing that may be occuring on the main thread of @@ -95,7 +100,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, // Cache fonts for the renderer. See ResourceMessageFilter::OnLoadFont // implementation for more details void OnLoadFont(LOGFONT font); - void OnGetMonitorInfoForWindow(HWND window, MONITORINFOEX* monitor_info); + void OnGetScreenInfo(gfx::ViewHandle window, + webkit_glue::ScreenInfo* results); void OnGetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); void OnGetPluginPath(const GURL& url, const std::string& mime_type, diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index 23a6f06..1a4c3b1 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -313,30 +313,6 @@ struct ParamTraits<SkBitmap> { }; template <> -struct ParamTraits<MONITORINFOEX> { - typedef MONITORINFOEX param_type; - static void Write(Message* m, const param_type& p) { - m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MONITORINFOEX)); - } - static bool Read(const Message* m, void** iter, param_type* r) { - const char *data; - int data_size = 0; - bool result = m->ReadData(iter, &data, &data_size); - if (result && data_size == sizeof(MONITORINFOEX)) { - memcpy(r, data, sizeof(MONITORINFOEX)); - } else { - result = false; - NOTREACHED(); - } - - return result; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"<MONITORINFOEX>")); - } -}; - -template <> struct ParamTraits<std::string> { typedef std::string param_type; static void Write(Message* m, const param_type& p) { diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index edbfaf8..fbc1798 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -24,6 +24,7 @@ #include "webkit/glue/password_form.h" #include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/resource_loader_bridge.h" +#include "webkit/glue/screen_info.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webplugin.h" #include "webkit/glue/webpreferences.h" @@ -1649,6 +1650,30 @@ struct ParamTraits<WebDropData> { } }; +// Traits for ScreenInfo +template <> +struct ParamTraits<webkit_glue::ScreenInfo> { + typedef webkit_glue::ScreenInfo param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, p.depth); + WriteParam(m, p.depth_per_component); + WriteParam(m, p.is_monochrome); + WriteParam(m, p.rect); + WriteParam(m, p.available_rect); + } + static bool Read(const Message* m, void** iter, param_type* p) { + return + ReadParam(m, iter, &p->depth) && + ReadParam(m, iter, &p->depth_per_component) && + ReadParam(m, iter, &p->is_monochrome) && + ReadParam(m, iter, &p->rect) && + ReadParam(m, iter, &p->available_rect); + } + static void Log(const param_type& p, std::wstring* l) { + l->append(L"<webkit_glue::ScreenInfo>"); + } +}; + } // namespace IPC #endif // CHROME_COMMON_RENDER_MESSAGES_H_ diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index b191d41..61da8e7 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -15,6 +15,7 @@ #include "webkit/glue/dom_operations.h" #include "webkit/glue/console_message_level.h" #include "webkit/glue/context_node_types.h" +#include "webkit/glue/screen_info.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webplugin.h" #include "webkit/glue/webinputevent.h" @@ -813,10 +814,10 @@ IPC_BEGIN_MESSAGES(ViewHost, 2) IPC_SYNC_MESSAGE_CONTROL1_0(ViewHostMsg_LoadFont, LOGFONT /* font data */) - // Returns the monitor information corresponding to the HWND. - IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetMonitorInfoForWindow, - HWND /* In: Window handle */, - MONITORINFOEX /* Out: Monitor information */) + // Returns ScreenInfo corresponding to the given window. + IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetScreenInfo, + gfx::ViewHandle /* window */, + webkit_glue::ScreenInfo /* results */) // Send the tooltip text for the current mouse position to the browser. IPC_MESSAGE_ROUTED1(ViewHostMsg_SetTooltipText, diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index 244646e..83e5b95 100644 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -234,14 +234,13 @@ bool webkit_glue::EnsureFontLoaded(HFONT font) { return RenderThread::current()->Send(new ViewHostMsg_LoadFont(logfont)); } -MONITORINFOEX webkit_glue::GetMonitorInfoForWindow(HWND window) { - MONITORINFOEX monitor_info; +webkit_glue::ScreenInfo webkit_glue::GetScreenInfo(gfx::ViewHandle window) { + webkit_glue::ScreenInfo results; RenderThread::current()->Send( - new ViewHostMsg_GetMonitorInfoForWindow(window, &monitor_info)); - return monitor_info; + new ViewHostMsg_GetScreenInfo(window, &results)); + return results; } - #ifndef USING_SIMPLE_RESOURCE_LOADER_BRIDGE // Each RenderView has a ResourceDispatcher. In unit tests, this function may |