PluginProxy.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  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.
  12. *
  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.
  24. */
  25. #include "config.h"
  26. #include "PluginProxy.h"
  27. #if ENABLE(PLUGIN_PROCESS)
  28. #include "DataReference.h"
  29. #include "NPRemoteObjectMap.h"
  30. #include "NPRuntimeUtilities.h"
  31. #include "NPVariantData.h"
  32. #include "PluginController.h"
  33. #include "PluginControllerProxyMessages.h"
  34. #include "PluginCreationParameters.h"
  35. #include "PluginProcessConnection.h"
  36. #include "PluginProcessConnectionManager.h"
  37. #include "ShareableBitmap.h"
  38. #include "WebCoreArgumentCoders.h"
  39. #include "WebEvent.h"
  40. #include "WebProcess.h"
  41. #include "WebProcessConnectionMessages.h"
  42. #include <WebCore/GraphicsContext.h>
  43. #include <WebCore/NotImplemented.h>
  44. #include <WebCore/SharedBuffer.h>
  45. using namespace WebCore;
  46. namespace WebKit {
  47. static uint64_t generatePluginInstanceID()
  48. {
  49. static uint64_t uniquePluginInstanceID;
  50. return ++uniquePluginInstanceID;
  51. }
  52. PassRefPtr<PluginProxy> PluginProxy::create(uint64_t pluginProcessToken, bool isRestartedProcess)
  53. {
  54. return adoptRef(new PluginProxy(pluginProcessToken, isRestartedProcess));
  55. }
  56. PluginProxy::PluginProxy(uint64_t pluginProcessToken, bool isRestartedProcess)
  57. : m_pluginProcessToken(pluginProcessToken)
  58. , m_pluginInstanceID(generatePluginInstanceID())
  59. , m_pluginBackingStoreContainsValidData(false)
  60. , m_isStarted(false)
  61. , m_waitingForPaintInResponseToUpdate(false)
  62. , m_wantsWheelEvents(false)
  63. , m_remoteLayerClientID(0)
  64. , m_waitingOnAsynchronousInitialization(false)
  65. , m_isRestartedProcess(isRestartedProcess)
  66. {
  67. }
  68. PluginProxy::~PluginProxy()
  69. {
  70. }
  71. void PluginProxy::pluginProcessCrashed()
  72. {
  73. controller()->pluginProcessCrashed();
  74. }
  75. bool PluginProxy::initialize(const Parameters& parameters)
  76. {
  77. ASSERT(!m_connection);
  78. m_connection = WebProcess::shared().pluginProcessConnectionManager().getPluginProcessConnection(m_pluginProcessToken);
  79. if (!m_connection)
  80. return false;
  81. // Add the plug-in proxy before creating the plug-in; it needs to be in the map because CreatePlugin
  82. // can call back out to the plug-in proxy.
  83. m_connection->addPluginProxy(this);
  84. // Ask the plug-in process to create a plug-in.
  85. m_pendingPluginCreationParameters = adoptPtr(new PluginCreationParameters);
  86. m_pendingPluginCreationParameters->pluginInstanceID = m_pluginInstanceID;
  87. m_pendingPluginCreationParameters->windowNPObjectID = windowNPObjectID();
  88. m_pendingPluginCreationParameters->parameters = parameters;
  89. m_pendingPluginCreationParameters->userAgent = controller()->userAgent();
  90. m_pendingPluginCreationParameters->contentsScaleFactor = contentsScaleFactor();
  91. m_pendingPluginCreationParameters->isPrivateBrowsingEnabled = controller()->isPrivateBrowsingEnabled();
  92. m_pendingPluginCreationParameters->artificialPluginInitializationDelayEnabled = controller()->artificialPluginInitializationDelayEnabled();
  93. #if USE(ACCELERATED_COMPOSITING)
  94. m_pendingPluginCreationParameters->isAcceleratedCompositingEnabled = controller()->isAcceleratedCompositingEnabled();
  95. #endif
  96. if (!canInitializeAsynchronously())
  97. return initializeSynchronously();
  98. // Remember that we tried to create this plug-in asynchronously in case we need to create it synchronously later.
  99. m_waitingOnAsynchronousInitialization = true;
  100. PluginCreationParameters creationParameters(*m_pendingPluginCreationParameters.get());
  101. m_connection->connection()->send(Messages::WebProcessConnection::CreatePluginAsynchronously(creationParameters), m_pluginInstanceID);
  102. return true;
  103. }
  104. bool PluginProxy::canInitializeAsynchronously() const
  105. {
  106. return controller()->asynchronousPluginInitializationEnabled() && (m_connection->supportsAsynchronousPluginInitialization() || controller()->asynchronousPluginInitializationEnabledForAllPlugins());
  107. }
  108. bool PluginProxy::initializeSynchronously()
  109. {
  110. ASSERT(m_pendingPluginCreationParameters);
  111. m_pendingPluginCreationParameters->asynchronousCreationIncomplete = m_waitingOnAsynchronousInitialization;
  112. bool result = false;
  113. bool wantsWheelEvents = false;
  114. uint32_t remoteLayerClientID = 0;
  115. PluginCreationParameters parameters(*m_pendingPluginCreationParameters.get());
  116. if (!m_connection->connection()->sendSync(Messages::WebProcessConnection::CreatePlugin(parameters), Messages::WebProcessConnection::CreatePlugin::Reply(result, wantsWheelEvents, remoteLayerClientID), 0) || !result)
  117. didFailToCreatePluginInternal();
  118. else
  119. didCreatePluginInternal(wantsWheelEvents, remoteLayerClientID);
  120. return result;
  121. }
  122. void PluginProxy::didCreatePlugin(bool wantsWheelEvents, uint32_t remoteLayerClientID)
  123. {
  124. // We might have tried to create the plug-in sychronously while waiting on the asynchronous reply,
  125. // in which case we should ignore this message.
  126. if (!m_waitingOnAsynchronousInitialization)
  127. return;
  128. didCreatePluginInternal(wantsWheelEvents, remoteLayerClientID);
  129. }
  130. void PluginProxy::didFailToCreatePlugin()
  131. {
  132. // We might have tried to create the plug-in sychronously while waiting on the asynchronous reply,
  133. // in which case we should ignore this message.
  134. if (!m_waitingOnAsynchronousInitialization)
  135. return;
  136. didFailToCreatePluginInternal();
  137. }
  138. void PluginProxy::didCreatePluginInternal(bool wantsWheelEvents, uint32_t remoteLayerClientID)
  139. {
  140. m_wantsWheelEvents = wantsWheelEvents;
  141. m_remoteLayerClientID = remoteLayerClientID;
  142. m_isStarted = true;
  143. controller()->didInitializePlugin();
  144. // Whether synchronously or asynchronously, this plug-in was created and we shouldn't need to remember
  145. // anything about how.
  146. m_pendingPluginCreationParameters.clear();
  147. m_waitingOnAsynchronousInitialization = false;
  148. }
  149. void PluginProxy::didFailToCreatePluginInternal()
  150. {
  151. // Calling out to the connection and the controller could potentially cause the plug-in proxy to go away, so protect it here.
  152. RefPtr<PluginProxy> protect(this);
  153. m_connection->removePluginProxy(this);
  154. controller()->didFailToInitializePlugin();
  155. // Whether synchronously or asynchronously, this plug-in failed to create and we shouldn't need to remember
  156. // anything about how.
  157. m_pendingPluginCreationParameters.clear();
  158. m_waitingOnAsynchronousInitialization = false;
  159. }
  160. void PluginProxy::destroy()
  161. {
  162. m_isStarted = false;
  163. if (!m_connection)
  164. return;
  165. m_connection->connection()->sendSync(Messages::WebProcessConnection::DestroyPlugin(m_pluginInstanceID, m_waitingOnAsynchronousInitialization), Messages::WebProcessConnection::DestroyPlugin::Reply(), 0);
  166. m_connection->removePluginProxy(this);
  167. }
  168. void PluginProxy::paint(GraphicsContext* graphicsContext, const IntRect& dirtyRect)
  169. {
  170. if (!needsBackingStore() || !m_backingStore)
  171. return;
  172. if (!m_pluginBackingStoreContainsValidData) {
  173. m_connection->connection()->sendSync(Messages::PluginControllerProxy::PaintEntirePlugin(), Messages::PluginControllerProxy::PaintEntirePlugin::Reply(), m_pluginInstanceID);
  174. // Blit the plug-in backing store into our own backing store.
  175. OwnPtr<WebCore::GraphicsContext> graphicsContext = m_backingStore->createGraphicsContext();
  176. graphicsContext->applyDeviceScaleFactor(contentsScaleFactor());
  177. graphicsContext->setCompositeOperation(CompositeCopy);
  178. m_pluginBackingStore->paint(*graphicsContext, contentsScaleFactor(), IntPoint(), pluginBounds());
  179. m_pluginBackingStoreContainsValidData = true;
  180. }
  181. m_backingStore->paint(*graphicsContext, contentsScaleFactor(), dirtyRect.location(), dirtyRect);
  182. if (m_waitingForPaintInResponseToUpdate) {
  183. m_waitingForPaintInResponseToUpdate = false;
  184. m_connection->connection()->send(Messages::PluginControllerProxy::DidUpdate(), m_pluginInstanceID);
  185. return;
  186. }
  187. }
  188. bool PluginProxy::supportsSnapshotting() const
  189. {
  190. if (m_waitingOnAsynchronousInitialization)
  191. return false;
  192. bool isSupported = false;
  193. if (m_connection && !m_connection->connection()->sendSync(Messages::PluginControllerProxy::SupportsSnapshotting(), Messages::PluginControllerProxy::SupportsSnapshotting::Reply(isSupported), m_pluginInstanceID))
  194. return false;
  195. return isSupported;
  196. }
  197. PassRefPtr<ShareableBitmap> PluginProxy::snapshot()
  198. {
  199. ShareableBitmap::Handle snapshotStoreHandle;
  200. m_connection->connection()->sendSync(Messages::PluginControllerProxy::Snapshot(), Messages::PluginControllerProxy::Snapshot::Reply(snapshotStoreHandle), m_pluginInstanceID);
  201. if (snapshotStoreHandle.isNull())
  202. return 0;
  203. RefPtr<ShareableBitmap> snapshotBuffer = ShareableBitmap::create(snapshotStoreHandle);
  204. return snapshotBuffer.release();
  205. }
  206. bool PluginProxy::isTransparent()
  207. {
  208. // This should never be called from the web process.
  209. ASSERT_NOT_REACHED();
  210. return false;
  211. }
  212. bool PluginProxy::wantsWheelEvents()
  213. {
  214. return m_wantsWheelEvents;
  215. }
  216. void PluginProxy::geometryDidChange()
  217. {
  218. ASSERT(m_isStarted);
  219. ShareableBitmap::Handle pluginBackingStoreHandle;
  220. if (updateBackingStore()) {
  221. // Create a new plug-in backing store.
  222. m_pluginBackingStore = ShareableBitmap::createShareable(m_backingStore->size(), ShareableBitmap::SupportsAlpha);
  223. if (!m_pluginBackingStore)
  224. return;
  225. // Create a handle to the plug-in backing store so we can send it over.
  226. if (!m_pluginBackingStore->createHandle(pluginBackingStoreHandle)) {
  227. m_pluginBackingStore = nullptr;
  228. return;
  229. }
  230. m_pluginBackingStoreContainsValidData = false;
  231. }
  232. m_connection->connection()->send(Messages::PluginControllerProxy::GeometryDidChange(m_pluginSize, m_clipRect, m_pluginToRootViewTransform, contentsScaleFactor(), pluginBackingStoreHandle), m_pluginInstanceID, CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
  233. }
  234. void PluginProxy::geometryDidChange(const IntSize& pluginSize, const IntRect& clipRect, const AffineTransform& pluginToRootViewTransform)
  235. {
  236. if (pluginSize == m_pluginSize && m_clipRect == clipRect && m_pluginToRootViewTransform == pluginToRootViewTransform) {
  237. // Nothing to do.
  238. return;
  239. }
  240. m_pluginSize = pluginSize;
  241. m_clipRect = clipRect;
  242. m_pluginToRootViewTransform = pluginToRootViewTransform;
  243. geometryDidChange();
  244. }
  245. void PluginProxy::visibilityDidChange()
  246. {
  247. ASSERT(m_isStarted);
  248. notImplemented();
  249. }
  250. void PluginProxy::frameDidFinishLoading(uint64_t requestID)
  251. {
  252. m_connection->connection()->send(Messages::PluginControllerProxy::FrameDidFinishLoading(requestID), m_pluginInstanceID);
  253. }
  254. void PluginProxy::frameDidFail(uint64_t requestID, bool wasCancelled)
  255. {
  256. m_connection->connection()->send(Messages::PluginControllerProxy::FrameDidFail(requestID, wasCancelled), m_pluginInstanceID);
  257. }
  258. void PluginProxy::didEvaluateJavaScript(uint64_t requestID, const WTF::String& result)
  259. {
  260. m_connection->connection()->send(Messages::PluginControllerProxy::DidEvaluateJavaScript(requestID, result), m_pluginInstanceID);
  261. }
  262. void PluginProxy::streamDidReceiveResponse(uint64_t streamID, const KURL& responseURL, uint32_t streamLength, uint32_t lastModifiedTime, const WTF::String& mimeType, const WTF::String& headers, const String& /* suggestedFileName */)
  263. {
  264. m_connection->connection()->send(Messages::PluginControllerProxy::StreamDidReceiveResponse(streamID, responseURL.string(), streamLength, lastModifiedTime, mimeType, headers), m_pluginInstanceID);
  265. }
  266. void PluginProxy::streamDidReceiveData(uint64_t streamID, const char* bytes, int length)
  267. {
  268. m_connection->connection()->send(Messages::PluginControllerProxy::StreamDidReceiveData(streamID, CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(bytes), length)), m_pluginInstanceID);
  269. }
  270. void PluginProxy::streamDidFinishLoading(uint64_t streamID)
  271. {
  272. m_connection->connection()->send(Messages::PluginControllerProxy::StreamDidFinishLoading(streamID), m_pluginInstanceID);
  273. }
  274. void PluginProxy::streamDidFail(uint64_t streamID, bool wasCancelled)
  275. {
  276. m_connection->connection()->send(Messages::PluginControllerProxy::StreamDidFail(streamID, wasCancelled), m_pluginInstanceID);
  277. }
  278. void PluginProxy::manualStreamDidReceiveResponse(const KURL& responseURL, uint32_t streamLength, uint32_t lastModifiedTime, const WTF::String& mimeType, const WTF::String& headers, const String& /* suggestedFileName */)
  279. {
  280. m_connection->connection()->send(Messages::PluginControllerProxy::ManualStreamDidReceiveResponse(responseURL.string(), streamLength, lastModifiedTime, mimeType, headers), m_pluginInstanceID);
  281. }
  282. void PluginProxy::manualStreamDidReceiveData(const char* bytes, int length)
  283. {
  284. m_connection->connection()->send(Messages::PluginControllerProxy::ManualStreamDidReceiveData(CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(bytes), length)), m_pluginInstanceID);
  285. }
  286. void PluginProxy::manualStreamDidFinishLoading()
  287. {
  288. m_connection->connection()->send(Messages::PluginControllerProxy::ManualStreamDidFinishLoading(), m_pluginInstanceID);
  289. }
  290. void PluginProxy::manualStreamDidFail(bool wasCancelled)
  291. {
  292. m_connection->connection()->send(Messages::PluginControllerProxy::ManualStreamDidFail(wasCancelled), m_pluginInstanceID);
  293. }
  294. bool PluginProxy::handleMouseEvent(const WebMouseEvent& mouseEvent)
  295. {
  296. if (m_waitingOnAsynchronousInitialization)
  297. return false;
  298. bool handled = false;
  299. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::HandleMouseEvent(mouseEvent), Messages::PluginControllerProxy::HandleMouseEvent::Reply(handled), m_pluginInstanceID))
  300. return false;
  301. return handled;
  302. }
  303. bool PluginProxy::handleWheelEvent(const WebWheelEvent& wheelEvent)
  304. {
  305. if (m_waitingOnAsynchronousInitialization)
  306. return false;
  307. bool handled = false;
  308. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::HandleWheelEvent(wheelEvent), Messages::PluginControllerProxy::HandleWheelEvent::Reply(handled), m_pluginInstanceID))
  309. return false;
  310. return handled;
  311. }
  312. bool PluginProxy::handleMouseEnterEvent(const WebMouseEvent& mouseEnterEvent)
  313. {
  314. if (m_waitingOnAsynchronousInitialization)
  315. return false;
  316. bool handled = false;
  317. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::HandleMouseEnterEvent(mouseEnterEvent), Messages::PluginControllerProxy::HandleMouseEnterEvent::Reply(handled), m_pluginInstanceID))
  318. return false;
  319. return handled;
  320. }
  321. bool PluginProxy::handleMouseLeaveEvent(const WebMouseEvent& mouseLeaveEvent)
  322. {
  323. if (m_waitingOnAsynchronousInitialization)
  324. return false;
  325. bool handled = false;
  326. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::HandleMouseLeaveEvent(mouseLeaveEvent), Messages::PluginControllerProxy::HandleMouseLeaveEvent::Reply(handled), m_pluginInstanceID))
  327. return false;
  328. return handled;
  329. }
  330. bool PluginProxy::handleContextMenuEvent(const WebMouseEvent&)
  331. {
  332. // We don't know if the plug-in has handled mousedown event by displaying a context menu, so we never want WebKit to show a default one.
  333. return true;
  334. }
  335. bool PluginProxy::handleKeyboardEvent(const WebKeyboardEvent& keyboardEvent)
  336. {
  337. if (m_waitingOnAsynchronousInitialization)
  338. return false;
  339. bool handled = false;
  340. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::HandleKeyboardEvent(keyboardEvent), Messages::PluginControllerProxy::HandleKeyboardEvent::Reply(handled), m_pluginInstanceID))
  341. return false;
  342. return handled;
  343. }
  344. void PluginProxy::setFocus(bool hasFocus)
  345. {
  346. m_connection->connection()->send(Messages::PluginControllerProxy::SetFocus(hasFocus), m_pluginInstanceID);
  347. }
  348. bool PluginProxy::handleEditingCommand(const String& commandName, const String& argument)
  349. {
  350. if (m_waitingOnAsynchronousInitialization)
  351. return false;
  352. bool handled = false;
  353. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::HandleEditingCommand(commandName, argument), Messages::PluginControllerProxy::HandleEditingCommand::Reply(handled), m_pluginInstanceID))
  354. return false;
  355. return handled;
  356. }
  357. bool PluginProxy::isEditingCommandEnabled(const String& commandName)
  358. {
  359. if (m_waitingOnAsynchronousInitialization)
  360. return false;
  361. bool enabled = false;
  362. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::IsEditingCommandEnabled(commandName), Messages::PluginControllerProxy::IsEditingCommandEnabled::Reply(enabled), m_pluginInstanceID))
  363. return false;
  364. return enabled;
  365. }
  366. bool PluginProxy::handlesPageScaleFactor()
  367. {
  368. if (m_waitingOnAsynchronousInitialization)
  369. return false;
  370. bool handled = false;
  371. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::HandlesPageScaleFactor(), Messages::PluginControllerProxy::HandlesPageScaleFactor::Reply(handled), m_pluginInstanceID))
  372. return false;
  373. return handled;
  374. }
  375. NPObject* PluginProxy::pluginScriptableNPObject()
  376. {
  377. // Sending the synchronous Messages::PluginControllerProxy::GetPluginScriptableNPObject message can cause us to dispatch an
  378. // incoming synchronous message that ends up destroying the PluginProxy object.
  379. PluginController::PluginDestructionProtector protector(controller());
  380. uint64_t pluginScriptableNPObjectID = 0;
  381. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::GetPluginScriptableNPObject(), Messages::PluginControllerProxy::GetPluginScriptableNPObject::Reply(pluginScriptableNPObjectID), m_pluginInstanceID))
  382. return 0;
  383. if (!pluginScriptableNPObjectID)
  384. return 0;
  385. return m_connection->npRemoteObjectMap()->createNPObjectProxy(pluginScriptableNPObjectID, this);
  386. }
  387. #if PLATFORM(MAC)
  388. void PluginProxy::windowFocusChanged(bool hasFocus)
  389. {
  390. m_connection->connection()->send(Messages::PluginControllerProxy::WindowFocusChanged(hasFocus), m_pluginInstanceID);
  391. }
  392. void PluginProxy::windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates)
  393. {
  394. m_connection->connection()->send(Messages::PluginControllerProxy::WindowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates), m_pluginInstanceID);
  395. }
  396. void PluginProxy::windowVisibilityChanged(bool isVisible)
  397. {
  398. m_connection->connection()->send(Messages::PluginControllerProxy::WindowVisibilityChanged(isVisible), m_pluginInstanceID);
  399. }
  400. uint64_t PluginProxy::pluginComplexTextInputIdentifier() const
  401. {
  402. return m_pluginInstanceID;
  403. }
  404. void PluginProxy::sendComplexTextInput(const String& textInput)
  405. {
  406. m_connection->connection()->send(Messages::PluginControllerProxy::SendComplexTextInput(textInput), m_pluginInstanceID);
  407. }
  408. #endif
  409. void PluginProxy::contentsScaleFactorChanged(float)
  410. {
  411. geometryDidChange();
  412. }
  413. void PluginProxy::storageBlockingStateChanged(bool isStorageBlockingEnabled)
  414. {
  415. m_connection->connection()->send(Messages::PluginControllerProxy::StorageBlockingStateChanged(isStorageBlockingEnabled), m_pluginInstanceID);
  416. }
  417. void PluginProxy::privateBrowsingStateChanged(bool isPrivateBrowsingEnabled)
  418. {
  419. m_connection->connection()->send(Messages::PluginControllerProxy::PrivateBrowsingStateChanged(isPrivateBrowsingEnabled), m_pluginInstanceID);
  420. }
  421. bool PluginProxy::getFormValue(String& formValue)
  422. {
  423. bool returnValue;
  424. if (!m_connection->connection()->sendSync(Messages::PluginControllerProxy::GetFormValue(), Messages::PluginControllerProxy::GetFormValue::Reply(returnValue, formValue), m_pluginInstanceID))
  425. return false;
  426. return returnValue;
  427. }
  428. bool PluginProxy::handleScroll(ScrollDirection, ScrollGranularity)
  429. {
  430. return false;
  431. }
  432. Scrollbar* PluginProxy::horizontalScrollbar()
  433. {
  434. return 0;
  435. }
  436. Scrollbar* PluginProxy::verticalScrollbar()
  437. {
  438. return 0;
  439. }
  440. void PluginProxy::loadURL(uint64_t requestID, const String& method, const String& urlString, const String& target, const HTTPHeaderMap& headerFields, const Vector<uint8_t>& httpBody, bool allowPopups)
  441. {
  442. controller()->loadURL(requestID, method, urlString, target, headerFields, httpBody, allowPopups);
  443. }
  444. void PluginProxy::proxiesForURL(const String& urlString, String& proxyString)
  445. {
  446. proxyString = controller()->proxiesForURL(urlString);
  447. }
  448. void PluginProxy::cookiesForURL(const String& urlString, String& cookieString)
  449. {
  450. cookieString = controller()->cookiesForURL(urlString);
  451. }
  452. void PluginProxy::setCookiesForURL(const String& urlString, const String& cookieString)
  453. {
  454. controller()->setCookiesForURL(urlString, cookieString);
  455. }
  456. void PluginProxy::getAuthenticationInfo(const ProtectionSpace& protectionSpace, bool& returnValue, String& username, String& password)
  457. {
  458. returnValue = controller()->getAuthenticationInfo(protectionSpace, username, password);
  459. }
  460. float PluginProxy::contentsScaleFactor()
  461. {
  462. return controller()->contentsScaleFactor();
  463. }
  464. bool PluginProxy::updateBackingStore()
  465. {
  466. if (m_pluginSize.isEmpty() || !needsBackingStore())
  467. return false;
  468. IntSize backingStoreSize = m_pluginSize;
  469. backingStoreSize.scale(contentsScaleFactor());
  470. if (!m_backingStore) {
  471. m_backingStore = ShareableBitmap::create(backingStoreSize, ShareableBitmap::SupportsAlpha);
  472. return true;
  473. }
  474. if (backingStoreSize != m_backingStore->size()) {
  475. // The backing store already exists, just resize it.
  476. return m_backingStore->resize(backingStoreSize);
  477. }
  478. return false;
  479. }
  480. uint64_t PluginProxy::windowNPObjectID()
  481. {
  482. NPObject* windowScriptNPObject = controller()->windowScriptNPObject();
  483. if (!windowScriptNPObject)
  484. return 0;
  485. uint64_t windowNPObjectID = m_connection->npRemoteObjectMap()->registerNPObject(windowScriptNPObject, this);
  486. releaseNPObject(windowScriptNPObject);
  487. return windowNPObjectID;
  488. }
  489. IntRect PluginProxy::pluginBounds()
  490. {
  491. return IntRect(IntPoint(), m_pluginSize);
  492. }
  493. void PluginProxy::getPluginElementNPObject(uint64_t& pluginElementNPObjectID)
  494. {
  495. NPObject* pluginElementNPObject = controller()->pluginElementNPObject();
  496. if (!pluginElementNPObject) {
  497. pluginElementNPObjectID = 0;
  498. return;
  499. }
  500. pluginElementNPObjectID = m_connection->npRemoteObjectMap()->registerNPObject(pluginElementNPObject, this);
  501. releaseNPObject(pluginElementNPObject);
  502. }
  503. void PluginProxy::evaluate(const NPVariantData& npObjectAsVariantData, const String& scriptString, bool allowPopups, bool& returnValue, NPVariantData& resultData)
  504. {
  505. PluginController::PluginDestructionProtector protector(controller());
  506. NPVariant npObjectAsVariant = m_connection->npRemoteObjectMap()->npVariantDataToNPVariant(npObjectAsVariantData, this);
  507. if (!NPVARIANT_IS_OBJECT(npObjectAsVariant) || !(NPVARIANT_TO_OBJECT(npObjectAsVariant))) {
  508. returnValue = false;
  509. return;
  510. }
  511. NPVariant result;
  512. returnValue = controller()->evaluate(NPVARIANT_TO_OBJECT(npObjectAsVariant), scriptString, &result, allowPopups);
  513. if (!returnValue)
  514. return;
  515. // Convert the NPVariant to an NPVariantData.
  516. resultData = m_connection->npRemoteObjectMap()->npVariantToNPVariantData(result, this);
  517. // And release the result.
  518. releaseNPVariantValue(&result);
  519. releaseNPVariantValue(&npObjectAsVariant);
  520. }
  521. void PluginProxy::cancelStreamLoad(uint64_t streamID)
  522. {
  523. controller()->cancelStreamLoad(streamID);
  524. }
  525. void PluginProxy::cancelManualStreamLoad()
  526. {
  527. controller()->cancelManualStreamLoad();
  528. }
  529. void PluginProxy::setStatusbarText(const String& statusbarText)
  530. {
  531. controller()->setStatusbarText(statusbarText);
  532. }
  533. #if PLUGIN_ARCHITECTURE(X11)
  534. void PluginProxy::createPluginContainer(uint64_t& windowID)
  535. {
  536. windowID = controller()->createPluginContainer();
  537. }
  538. void PluginProxy::windowedPluginGeometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect, uint64_t windowID)
  539. {
  540. controller()->windowedPluginGeometryDidChange(frameRect, clipRect, windowID);
  541. }
  542. #endif
  543. void PluginProxy::update(const IntRect& paintedRect)
  544. {
  545. if (paintedRect == pluginBounds())
  546. m_pluginBackingStoreContainsValidData = true;
  547. if (m_backingStore) {
  548. // Blit the plug-in backing store into our own backing store.
  549. OwnPtr<GraphicsContext> graphicsContext = m_backingStore->createGraphicsContext();
  550. graphicsContext->applyDeviceScaleFactor(contentsScaleFactor());
  551. graphicsContext->setCompositeOperation(CompositeCopy);
  552. m_pluginBackingStore->paint(*graphicsContext, contentsScaleFactor(), paintedRect.location(), paintedRect);
  553. }
  554. // Ask the controller to invalidate the rect for us.
  555. m_waitingForPaintInResponseToUpdate = true;
  556. controller()->invalidate(paintedRect);
  557. }
  558. IntPoint PluginProxy::convertToRootView(const IntPoint& point) const
  559. {
  560. return m_pluginToRootViewTransform.mapPoint(point);
  561. }
  562. PassRefPtr<WebCore::SharedBuffer> PluginProxy::liveResourceData() const
  563. {
  564. return 0;
  565. }
  566. } // namespace WebKit
  567. #endif // ENABLE(PLUGIN_PROCESS)