2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebPageProxy.h"
29 #include "PageClient.h"
30 #include "WebDragSource.h"
31 #include "WebPageMessages.h"
32 #include "WebPopupMenuProxyWin.h"
33 #include "WebProcessProxy.h"
36 #include <WebCore/BitmapInfo.h>
37 #include <WebCore/COMPtr.h>
38 #include <WebCore/ClipboardUtilitiesWin.h>
39 #include <WebCore/SystemInfo.h>
40 #include <WebCore/WCDataObject.h>
41 #include <WebCore/WebCoreInstanceHandle.h>
43 #include <wtf/StdLibExtras.h>
44 #include <wtf/text/StringConcatenate.h>
46 using namespace WebCore;
50 static String userVisibleWebKitVersionString()
52 LPWSTR buildNumberStringPtr;
53 if (!::LoadStringW(instanceHandle(), BUILD_NUMBER, reinterpret_cast<LPWSTR>(&buildNumberStringPtr), 0) || !buildNumberStringPtr)
56 return buildNumberStringPtr;
59 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
61 DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersionForUAString()));
62 DEFINE_STATIC_LOCAL(String, webKitVersion, (userVisibleWebKitVersionString()));
64 return makeString("Mozilla/5.0 (", osVersion, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)", applicationNameForUserAgent.isEmpty() ? "" : " ", applicationNameForUserAgent);
67 void WebPageProxy::setPopupMenuSelectedIndex(int32_t selectedIndex)
69 if (!m_activePopupMenu)
72 static_cast<WebPopupMenuProxyWin*>(m_activePopupMenu.get())->setFocusedIndex(selectedIndex);
75 HWND WebPageProxy::nativeWindow() const
77 return m_pageClient->nativeWindow();
80 void WebPageProxy::scheduleChildWindowGeometryUpdate(const WindowGeometry& geometry)
82 m_pageClient->scheduleChildWindowGeometryUpdate(geometry);
85 void WebPageProxy::didInstallOrUninstallPageOverlay(bool didInstall)
87 m_pageClient->didInstallOrUninstallPageOverlay(didInstall);
90 IntRect WebPageProxy::firstRectForCharacterInSelectedRange(int characterPosition)
93 process()->sendSync(Messages::WebPage::FirstRectForCharacterInSelectedRange(characterPosition), Messages::WebPage::FirstRectForCharacterInSelectedRange::Reply(resultRect), m_pageID);
97 String WebPageProxy::getSelectedText()
100 process()->sendSync(Messages::WebPage::GetSelectedText(), Messages::WebPage::GetSelectedText::Reply(text), m_pageID);
104 bool WebPageProxy::gestureWillBegin(const IntPoint& point)
106 bool canBeginPanning = false;
107 process()->sendSync(Messages::WebPage::GestureWillBegin(point), Messages::WebPage::GestureWillBegin::Reply(canBeginPanning), m_pageID);
108 return canBeginPanning;
111 void WebPageProxy::gestureDidScroll(const IntSize& size)
113 process()->send(Messages::WebPage::GestureDidScroll(size), m_pageID);
116 void WebPageProxy::gestureDidEnd()
118 process()->send(Messages::WebPage::GestureDidEnd(), m_pageID);
121 void WebPageProxy::setGestureReachedScrollingLimit(bool limitReached)
123 m_pageClient->setGestureReachedScrollingLimit(limitReached);
126 void WebPageProxy::startDragDrop(const IntPoint& imageOrigin, const IntPoint& dragPoint, uint64_t okEffect, const HashMap<UINT, Vector<String> >& dataMap, uint64_t fileSize, const String& pathname, const SharedMemory::Handle& fileContentHandle, const IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag)
128 COMPtr<WCDataObject> dataObject;
129 WCDataObject::createInstance(&dataObject, dataMap);
132 RefPtr<SharedMemory> fileContentBuffer = SharedMemory::create(fileContentHandle, SharedMemory::ReadOnly);
133 setFileDescriptorData(dataObject.get(), fileSize, pathname);
134 setFileContentData(dataObject.get(), fileSize, fileContentBuffer->data());
137 RefPtr<SharedMemory> memoryBuffer = SharedMemory::create(dragImageHandle, SharedMemory::ReadOnly);
141 RefPtr<WebDragSource> source = WebDragSource::createInstance();
145 COMPtr<IDragSourceHelper> helper;
146 if (FAILED(::CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDragSourceHelper, reinterpret_cast<LPVOID*>(&helper))))
149 BitmapInfo bitmapInfo = BitmapInfo::create(dragImageSize);
151 OwnPtr<HBITMAP> hbmp = adoptPtr(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &bits, 0, 0));
152 memcpy(bits, memoryBuffer->data(), memoryBuffer->size());
155 sdi.sizeDragImage.cx = bitmapInfo.bmiHeader.biWidth;
156 sdi.sizeDragImage.cy = bitmapInfo.bmiHeader.biHeight;
157 sdi.crColorKey = 0xffffffff;
158 sdi.hbmpDragImage = hbmp.leakPtr();
159 sdi.ptOffset.x = dragPoint.x() - imageOrigin.x();
160 sdi.ptOffset.y = dragPoint.y() - imageOrigin.y();
162 sdi.ptOffset.y = bitmapInfo.bmiHeader.biHeight - sdi.ptOffset.y;
164 helper->InitializeFromBitmap(&sdi, dataObject.get());
166 DWORD effect = DROPEFFECT_NONE;
168 DragOperation operation = DragOperationNone;
169 if (::DoDragDrop(dataObject.get(), source.get(), okEffect, &effect) == DRAGDROP_S_DROP) {
170 if (effect & DROPEFFECT_COPY)
171 operation = DragOperationCopy;
172 else if (effect & DROPEFFECT_LINK)
173 operation = DragOperationLink;
174 else if (effect & DROPEFFECT_MOVE)
175 operation = DragOperationMove;
178 ::GetCursorPos(&globalPoint);
179 POINT localPoint = globalPoint;
180 ::ScreenToClient(m_pageClient->nativeWindow(), &localPoint);
182 dragEnded(localPoint, globalPoint, operation);
185 void WebPageProxy::didChangeCompositionSelection(bool hasComposition)
187 m_pageClient->compositionSelectionChanged(hasComposition);
190 void WebPageProxy::confirmComposition(const String& compositionString)
192 process()->send(Messages::WebPage::ConfirmComposition(compositionString), m_pageID);
195 void WebPageProxy::setComposition(const String& compositionString, Vector<CompositionUnderline>& underlines, int cursorPosition)
197 process()->send(Messages::WebPage::SetComposition(compositionString, underlines, cursorPosition), m_pageID);
201 } // namespace WebKit