blob: 9d35344668432babd693a90e8c0a465ec5698bb3 [file] [log] [blame]
[email protected]52993562008-10-31 22:28:401// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2// source code is governed by a BSD-style license that can be found in the
3// LICENSE file.
4
5#include "config.h"
6#include "ChromiumBridge.h"
7
[email protected]d055d8e2008-11-18 21:08:028#include "BitmapImage.h"
[email protected]4c870b42008-11-06 00:36:529#include "Cursor.h"
10#include "Frame.h"
11#include "FrameView.h"
[email protected]52993562008-10-31 22:28:4012#include "HostWindow.h"
[email protected]3ccbdb92008-11-11 22:25:5913#include "KURL.h"
14#include "NativeImageSkia.h"
[email protected]4c870b42008-11-06 00:36:5215#include "Page.h"
[email protected]3ccbdb92008-11-11 22:25:5916#include "PasteboardPrivate.h"
[email protected]7082ef022008-12-20 17:53:3617#include "PlatformContextSkia.h"
[email protected]3ccbdb92008-11-11 22:25:5918#include "PlatformString.h"
[email protected]52993562008-10-31 22:28:4019#include "PlatformWidget.h"
[email protected]aad0ab52008-11-18 17:09:2020#include "PluginData.h"
21#include "PluginInfoStore.h"
[email protected]3c821eb2008-11-18 16:20:5122#include "ScrollbarTheme.h"
[email protected]52993562008-10-31 22:28:4023#include "ScrollView.h"
[email protected]f0f97172008-11-18 22:00:5924#include "SystemTime.h"
[email protected]52993562008-10-31 22:28:4025#include "Widget.h"
[email protected]aa271482009-02-06 06:25:0326#include <wtf/CurrentTime.h>
[email protected]52993562008-10-31 22:28:4027
[email protected]4c870b42008-11-06 00:36:5228#undef LOG
[email protected]aad0ab52008-11-18 17:09:2029#include "base/file_util.h"
[email protected]3ccbdb92008-11-11 22:25:5930#include "base/string_util.h"
[email protected]d055d8e2008-11-18 21:08:0231#include "build/build_config.h"
[email protected]8a6e1742008-12-13 17:18:5032#include "googleurl/src/url_util.h"
[email protected]7082ef022008-12-20 17:53:3633#include "skia/ext/skia_utils_win.h"
[email protected]7c51b0ee2009-07-08 21:49:3034#include "webkit/api/public/WebCursorInfo.h"
[email protected]afdcf5c2009-05-10 20:30:4135#include "webkit/api/public/WebScreenInfo.h"
[email protected]4c870b42008-11-06 00:36:5236#include "webkit/glue/chrome_client_impl.h"
[email protected]52993562008-10-31 22:28:4037#include "webkit/glue/glue_util.h"
[email protected]e1c14ce2008-11-26 20:40:2638#include "webkit/glue/plugins/plugin_instance.h"
[email protected]52993562008-10-31 22:28:4039#include "webkit/glue/webkit_glue.h"
[email protected]12456fa2009-04-01 23:07:1940#include "webkit/glue/webview_impl.h"
[email protected]52993562008-10-31 22:28:4041
[email protected]d055d8e2008-11-18 21:08:0242#if defined(OS_WIN)
43#include <windows.h>
44#include <vssym32.h>
[email protected]d055d8e2008-11-18 21:08:0245#include "base/gfx/native_theme.h"
[email protected]d055d8e2008-11-18 21:08:0246#endif
47
[email protected]7c51b0ee2009-07-08 21:49:3048using WebKit::WebCursorInfo;
[email protected]4873c7d2009-07-16 06:36:2849using WebKit::WebWidgetClient;
[email protected]7c51b0ee2009-07-08 21:49:3050
[email protected]3ccbdb92008-11-11 22:25:5951namespace {
[email protected]52993562008-10-31 22:28:4052
[email protected]18bcc3c2009-01-27 21:39:1553gfx::NativeViewId ToNativeId(WebCore::Widget* widget) {
[email protected]098ccbd2008-12-20 20:59:0954 if (!widget)
55 return 0;
[email protected]18bcc3c2009-01-27 21:39:1556 return widget->root()->hostWindow()->platformWindow();
[email protected]098ccbd2008-12-20 20:59:0957}
58
[email protected]3ccbdb92008-11-11 22:25:5959ChromeClientImpl* ToChromeClient(WebCore::Widget* widget) {
60 WebCore::FrameView* view;
[email protected]4c870b42008-11-06 00:36:5261 if (widget->isFrameView()) {
[email protected]3ccbdb92008-11-11 22:25:5962 view = static_cast<WebCore::FrameView*>(widget);
[email protected]4c870b42008-11-06 00:36:5263 } else if (widget->parent() && widget->parent()->isFrameView()) {
[email protected]3ccbdb92008-11-11 22:25:5964 view = static_cast<WebCore::FrameView*>(widget->parent());
[email protected]4c870b42008-11-06 00:36:5265 } else {
66 return NULL;
67 }
68
[email protected]3ccbdb92008-11-11 22:25:5969 WebCore::Page* page = view->frame() ? view->frame()->page() : NULL;
[email protected]4c870b42008-11-06 00:36:5270 if (!page)
71 return NULL;
72
73 return static_cast<ChromeClientImpl*>(page->chrome()->client());
74}
75
[email protected]4873c7d2009-07-16 06:36:2876WebWidgetClient* ToWebWidgetClient(WebCore::Widget* widget) {
[email protected]12456fa2009-04-01 23:07:1977 ChromeClientImpl* chrome_client = ToChromeClient(widget);
[email protected]4873c7d2009-07-16 06:36:2878 if (!chrome_client || !chrome_client->webview())
[email protected]12456fa2009-04-01 23:07:1979 return NULL;
[email protected]4873c7d2009-07-16 06:36:2880 return chrome_client->webview()->delegate();
[email protected]12456fa2009-04-01 23:07:1981}
82
83WebCore::IntRect ToIntRect(const WebKit::WebRect& input) {
84 return WebCore::IntRect(input.x, input.y, input.width, input.height);
85}
86
[email protected]3ccbdb92008-11-11 22:25:5987} // namespace
88
89namespace WebCore {
90
[email protected]caae5412008-11-14 18:22:4791// JavaScript -----------------------------------------------------------------
92
93void ChromiumBridge::notifyJSOutOfMemory(Frame* frame) {
[email protected]f499e172009-03-02 23:24:0694 if (!frame)
95 return;
96
97 // Dispatch to the delegate of the view that owns the frame.
[email protected]4873c7d2009-07-16 06:36:2898 WebViewImpl* webview = WebFrameImpl::FromFrame(frame)->GetWebViewImpl();
99 if (!webview || !webview->delegate())
[email protected]f499e172009-03-02 23:24:06100 return;
[email protected]4873c7d2009-07-16 06:36:28101 webview->delegate()->JSOutOfMemory();
[email protected]caae5412008-11-14 18:22:47102}
[email protected]da8765902008-11-13 20:27:07103
[email protected]aad0ab52008-11-18 17:09:20104// Plugin ---------------------------------------------------------------------
105
[email protected]e1c14ce2008-11-26 20:40:26106bool ChromiumBridge::popupsAllowed(NPP npp) {
107 bool popups_allowed = false;
108 if (npp) {
109 NPAPI::PluginInstance* plugin_instance =
110 reinterpret_cast<NPAPI::PluginInstance*>(npp->ndata);
111 if (plugin_instance)
112 popups_allowed = plugin_instance->popups_allowed();
113 }
114 return popups_allowed;
115}
116
[email protected]1c444692008-11-12 21:38:57117// Protocol -------------------------------------------------------------------
118
119String ChromiumBridge::uiResourceProtocol() {
120 return webkit_glue::StdStringToString(webkit_glue::GetUIResourceProtocol());
121}
122
[email protected]d055d8e2008-11-18 21:08:02123
[email protected]52993562008-10-31 22:28:40124// Screen ---------------------------------------------------------------------
125
126int ChromiumBridge::screenDepth(Widget* widget) {
[email protected]4873c7d2009-07-16 06:36:28127 WebWidgetClient* client = ToWebWidgetClient(widget);
128 if (!client)
129 return 0;
130 return client->screenInfo().depth;
[email protected]52993562008-10-31 22:28:40131}
132
133int ChromiumBridge::screenDepthPerComponent(Widget* widget) {
[email protected]4873c7d2009-07-16 06:36:28134 WebWidgetClient* client = ToWebWidgetClient(widget);
135 if (!client)
136 return 0;
137 return client->screenInfo().depthPerComponent;
[email protected]52993562008-10-31 22:28:40138}
139
140bool ChromiumBridge::screenIsMonochrome(Widget* widget) {
[email protected]4873c7d2009-07-16 06:36:28141 WebWidgetClient* client = ToWebWidgetClient(widget);
142 if (!client)
143 return false;
144 return client->screenInfo().isMonochrome;
[email protected]52993562008-10-31 22:28:40145}
146
147IntRect ChromiumBridge::screenRect(Widget* widget) {
[email protected]4873c7d2009-07-16 06:36:28148 WebWidgetClient* client = ToWebWidgetClient(widget);
149 if (!client)
[email protected]12456fa2009-04-01 23:07:19150 return IntRect();
[email protected]4873c7d2009-07-16 06:36:28151 return ToIntRect(client->screenInfo().rect);
[email protected]52993562008-10-31 22:28:40152}
153
154IntRect ChromiumBridge::screenAvailableRect(Widget* widget) {
[email protected]4873c7d2009-07-16 06:36:28155 WebWidgetClient* client = ToWebWidgetClient(widget);
156 if (!client)
[email protected]12456fa2009-04-01 23:07:19157 return IntRect();
[email protected]4873c7d2009-07-16 06:36:28158 return ToIntRect(client->screenInfo().availableRect);
[email protected]52993562008-10-31 22:28:40159}
160
[email protected]4c870b42008-11-06 00:36:52161// Widget ---------------------------------------------------------------------
162
163void ChromiumBridge::widgetSetCursor(Widget* widget, const Cursor& cursor) {
164 ChromeClientImpl* chrome_client = ToChromeClient(widget);
165 if (chrome_client)
[email protected]7c51b0ee2009-07-08 21:49:30166 chrome_client->SetCursor(webkit_glue::CursorToWebCursorInfo(cursor));
[email protected]4c870b42008-11-06 00:36:52167}
168
169void ChromiumBridge::widgetSetFocus(Widget* widget) {
170 ChromeClientImpl* chrome_client = ToChromeClient(widget);
171 if (chrome_client)
172 chrome_client->focus();
173}
174
[email protected]52993562008-10-31 22:28:40175} // namespace WebCore