[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 1 | // 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] | d055d8e | 2008-11-18 21:08:02 | [diff] [blame] | 8 | #include "BitmapImage.h" |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 9 | #include "Cursor.h" |
10 | #include "Frame.h" | ||||
11 | #include "FrameView.h" | ||||
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 12 | #include "HostWindow.h" |
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 13 | #include "KURL.h" |
14 | #include "NativeImageSkia.h" | ||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 15 | #include "Page.h" |
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 16 | #include "PasteboardPrivate.h" |
[email protected] | 7082ef02 | 2008-12-20 17:53:36 | [diff] [blame] | 17 | #include "PlatformContextSkia.h" |
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 18 | #include "PlatformString.h" |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 19 | #include "PlatformWidget.h" |
[email protected] | aad0ab5 | 2008-11-18 17:09:20 | [diff] [blame] | 20 | #include "PluginData.h" |
21 | #include "PluginInfoStore.h" | ||||
[email protected] | 3c821eb | 2008-11-18 16:20:51 | [diff] [blame] | 22 | #include "ScrollbarTheme.h" |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 23 | #include "ScrollView.h" |
[email protected] | f0f9717 | 2008-11-18 22:00:59 | [diff] [blame] | 24 | #include "SystemTime.h" |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 25 | #include "Widget.h" |
[email protected] | aa27148 | 2009-02-06 06:25:03 | [diff] [blame] | 26 | #include <wtf/CurrentTime.h> |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 27 | |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 28 | #undef LOG |
[email protected] | aad0ab5 | 2008-11-18 17:09:20 | [diff] [blame] | 29 | #include "base/file_util.h" |
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 30 | #include "base/string_util.h" |
[email protected] | d055d8e | 2008-11-18 21:08:02 | [diff] [blame] | 31 | #include "build/build_config.h" |
[email protected] | 8a6e174 | 2008-12-13 17:18:50 | [diff] [blame] | 32 | #include "googleurl/src/url_util.h" |
[email protected] | 7082ef02 | 2008-12-20 17:53:36 | [diff] [blame] | 33 | #include "skia/ext/skia_utils_win.h" |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 34 | #include "webkit/api/public/WebCursorInfo.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 35 | #include "webkit/api/public/WebScreenInfo.h" |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 36 | #include "webkit/glue/chrome_client_impl.h" |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 37 | #include "webkit/glue/glue_util.h" |
[email protected] | e1c14ce | 2008-11-26 20:40:26 | [diff] [blame] | 38 | #include "webkit/glue/plugins/plugin_instance.h" |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 39 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 40 | #include "webkit/glue/webview_impl.h" |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 41 | |
[email protected] | d055d8e | 2008-11-18 21:08:02 | [diff] [blame] | 42 | #if defined(OS_WIN) |
43 | #include <windows.h> | ||||
44 | #include <vssym32.h> | ||||
[email protected] | d055d8e | 2008-11-18 21:08:02 | [diff] [blame] | 45 | #include "base/gfx/native_theme.h" |
[email protected] | d055d8e | 2008-11-18 21:08:02 | [diff] [blame] | 46 | #endif |
47 | |||||
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 48 | using WebKit::WebCursorInfo; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 49 | using WebKit::WebWidgetClient; |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 50 | |
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 51 | namespace { |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 52 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 53 | gfx::NativeViewId ToNativeId(WebCore::Widget* widget) { |
[email protected] | 098ccbd | 2008-12-20 20:59:09 | [diff] [blame] | 54 | if (!widget) |
55 | return 0; | ||||
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 56 | return widget->root()->hostWindow()->platformWindow(); |
[email protected] | 098ccbd | 2008-12-20 20:59:09 | [diff] [blame] | 57 | } |
58 | |||||
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 59 | ChromeClientImpl* ToChromeClient(WebCore::Widget* widget) { |
60 | WebCore::FrameView* view; | ||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 61 | if (widget->isFrameView()) { |
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 62 | view = static_cast<WebCore::FrameView*>(widget); |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 63 | } else if (widget->parent() && widget->parent()->isFrameView()) { |
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 64 | view = static_cast<WebCore::FrameView*>(widget->parent()); |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 65 | } else { |
66 | return NULL; | ||||
67 | } | ||||
68 | |||||
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 69 | WebCore::Page* page = view->frame() ? view->frame()->page() : NULL; |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 70 | if (!page) |
71 | return NULL; | ||||
72 | |||||
73 | return static_cast<ChromeClientImpl*>(page->chrome()->client()); | ||||
74 | } | ||||
75 | |||||
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 76 | WebWidgetClient* ToWebWidgetClient(WebCore::Widget* widget) { |
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 77 | ChromeClientImpl* chrome_client = ToChromeClient(widget); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 78 | if (!chrome_client || !chrome_client->webview()) |
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 79 | return NULL; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 80 | return chrome_client->webview()->delegate(); |
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 81 | } |
82 | |||||
83 | WebCore::IntRect ToIntRect(const WebKit::WebRect& input) { | ||||
84 | return WebCore::IntRect(input.x, input.y, input.width, input.height); | ||||
85 | } | ||||
86 | |||||
[email protected] | 3ccbdb9 | 2008-11-11 22:25:59 | [diff] [blame] | 87 | } // namespace |
88 | |||||
89 | namespace WebCore { | ||||
90 | |||||
[email protected] | caae541 | 2008-11-14 18:22:47 | [diff] [blame] | 91 | // JavaScript ----------------------------------------------------------------- |
92 | |||||
93 | void ChromiumBridge::notifyJSOutOfMemory(Frame* frame) { | ||||
[email protected] | f499e17 | 2009-03-02 23:24:06 | [diff] [blame] | 94 | if (!frame) |
95 | return; | ||||
96 | |||||
97 | // Dispatch to the delegate of the view that owns the frame. | ||||
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 98 | WebViewImpl* webview = WebFrameImpl::FromFrame(frame)->GetWebViewImpl(); |
99 | if (!webview || !webview->delegate()) | ||||
[email protected] | f499e17 | 2009-03-02 23:24:06 | [diff] [blame] | 100 | return; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 101 | webview->delegate()->JSOutOfMemory(); |
[email protected] | caae541 | 2008-11-14 18:22:47 | [diff] [blame] | 102 | } |
[email protected] | da876590 | 2008-11-13 20:27:07 | [diff] [blame] | 103 | |
[email protected] | aad0ab5 | 2008-11-18 17:09:20 | [diff] [blame] | 104 | // Plugin --------------------------------------------------------------------- |
105 | |||||
[email protected] | e1c14ce | 2008-11-26 20:40:26 | [diff] [blame] | 106 | bool 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] | 1c44469 | 2008-11-12 21:38:57 | [diff] [blame] | 117 | // Protocol ------------------------------------------------------------------- |
118 | |||||
119 | String ChromiumBridge::uiResourceProtocol() { | ||||
120 | return webkit_glue::StdStringToString(webkit_glue::GetUIResourceProtocol()); | ||||
121 | } | ||||
122 | |||||
[email protected] | d055d8e | 2008-11-18 21:08:02 | [diff] [blame] | 123 | |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 124 | // Screen --------------------------------------------------------------------- |
125 | |||||
126 | int ChromiumBridge::screenDepth(Widget* widget) { | ||||
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 127 | WebWidgetClient* client = ToWebWidgetClient(widget); |
128 | if (!client) | ||||
129 | return 0; | ||||
130 | return client->screenInfo().depth; | ||||
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 131 | } |
132 | |||||
133 | int ChromiumBridge::screenDepthPerComponent(Widget* widget) { | ||||
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 134 | WebWidgetClient* client = ToWebWidgetClient(widget); |
135 | if (!client) | ||||
136 | return 0; | ||||
137 | return client->screenInfo().depthPerComponent; | ||||
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 138 | } |
139 | |||||
140 | bool ChromiumBridge::screenIsMonochrome(Widget* widget) { | ||||
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 141 | WebWidgetClient* client = ToWebWidgetClient(widget); |
142 | if (!client) | ||||
143 | return false; | ||||
144 | return client->screenInfo().isMonochrome; | ||||
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 145 | } |
146 | |||||
147 | IntRect ChromiumBridge::screenRect(Widget* widget) { | ||||
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 148 | WebWidgetClient* client = ToWebWidgetClient(widget); |
149 | if (!client) | ||||
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 150 | return IntRect(); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 151 | return ToIntRect(client->screenInfo().rect); |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 152 | } |
153 | |||||
154 | IntRect ChromiumBridge::screenAvailableRect(Widget* widget) { | ||||
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 155 | WebWidgetClient* client = ToWebWidgetClient(widget); |
156 | if (!client) | ||||
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 157 | return IntRect(); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 158 | return ToIntRect(client->screenInfo().availableRect); |
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 159 | } |
160 | |||||
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 161 | // Widget --------------------------------------------------------------------- |
162 | |||||
163 | void ChromiumBridge::widgetSetCursor(Widget* widget, const Cursor& cursor) { | ||||
164 | ChromeClientImpl* chrome_client = ToChromeClient(widget); | ||||
165 | if (chrome_client) | ||||
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 166 | chrome_client->SetCursor(webkit_glue::CursorToWebCursorInfo(cursor)); |
[email protected] | 4c870b4 | 2008-11-06 00:36:52 | [diff] [blame] | 167 | } |
168 | |||||
169 | void ChromiumBridge::widgetSetFocus(Widget* widget) { | ||||
170 | ChromeClientImpl* chrome_client = ToChromeClient(widget); | ||||
171 | if (chrome_client) | ||||
172 | chrome_client->focus(); | ||||
173 | } | ||||
174 | |||||
[email protected] | 5299356 | 2008-10-31 22:28:40 | [diff] [blame] | 175 | } // namespace WebCore |