InjectedBundlePageUIClient.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 "InjectedBundlePageUIClient.h"
  27. #include "InjectedBundleHitTestResult.h"
  28. #include "WKAPICast.h"
  29. #include "WKBundleAPICast.h"
  30. #include "WebGraphicsContext.h"
  31. #include "WebSecurityOrigin.h"
  32. #include <wtf/text/WTFString.h>
  33. using namespace WebCore;
  34. namespace WebKit {
  35. void InjectedBundlePageUIClient::willAddMessageToConsole(WebPage* page, const String& message, int32_t lineNumber)
  36. {
  37. if (m_client.willAddMessageToConsole)
  38. m_client.willAddMessageToConsole(toAPI(page), toAPI(message.impl()), lineNumber, m_client.clientInfo);
  39. }
  40. void InjectedBundlePageUIClient::willSetStatusbarText(WebPage* page, const String& statusbarText)
  41. {
  42. if (m_client.willSetStatusbarText)
  43. m_client.willSetStatusbarText(toAPI(page), toAPI(statusbarText.impl()), m_client.clientInfo);
  44. }
  45. void InjectedBundlePageUIClient::willRunJavaScriptAlert(WebPage* page, const String& alertText, WebFrame* frame)
  46. {
  47. if (m_client.willRunJavaScriptAlert)
  48. m_client.willRunJavaScriptAlert(toAPI(page), toAPI(alertText.impl()), toAPI(frame), m_client.clientInfo);
  49. }
  50. void InjectedBundlePageUIClient::willRunJavaScriptConfirm(WebPage* page, const String& message, WebFrame* frame)
  51. {
  52. if (m_client.willRunJavaScriptConfirm)
  53. m_client.willRunJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
  54. }
  55. void InjectedBundlePageUIClient::willRunJavaScriptPrompt(WebPage* page, const String& message, const String& defaultValue, WebFrame* frame)
  56. {
  57. if (m_client.willRunJavaScriptPrompt)
  58. m_client.willRunJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.clientInfo);
  59. }
  60. void InjectedBundlePageUIClient::mouseDidMoveOverElement(WebPage* page, const HitTestResult& coreHitTestResult, WebEvent::Modifiers modifiers, RefPtr<APIObject>& userData)
  61. {
  62. if (!m_client.mouseDidMoveOverElement)
  63. return;
  64. RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(coreHitTestResult);
  65. WKTypeRef userDataToPass = 0;
  66. m_client.mouseDidMoveOverElement(toAPI(page), toAPI(hitTestResult.get()), toAPI(modifiers), &userDataToPass, m_client.clientInfo);
  67. userData = adoptRef(toImpl(userDataToPass));
  68. }
  69. void InjectedBundlePageUIClient::pageDidScroll(WebPage* page)
  70. {
  71. if (!m_client.pageDidScroll)
  72. return;
  73. m_client.pageDidScroll(toAPI(page), m_client.clientInfo);
  74. }
  75. bool InjectedBundlePageUIClient::shouldPaintCustomOverhangArea()
  76. {
  77. return m_client.paintCustomOverhangArea;
  78. }
  79. void InjectedBundlePageUIClient::paintCustomOverhangArea(WebPage* page, GraphicsContext* graphicsContext, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
  80. {
  81. ASSERT(shouldPaintCustomOverhangArea());
  82. RefPtr<WebGraphicsContext> context = WebGraphicsContext::create(graphicsContext);
  83. m_client.paintCustomOverhangArea(toAPI(page), toAPI(context.get()), toAPI(horizontalOverhangArea), toAPI(verticalOverhangArea), toAPI(dirtyRect), m_client.clientInfo);
  84. }
  85. String InjectedBundlePageUIClient::shouldGenerateFileForUpload(WebPage* page, const String& originalFilePath)
  86. {
  87. if (!m_client.shouldGenerateFileForUpload)
  88. return String();
  89. RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.shouldGenerateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo)));
  90. return generatedFilePath ? generatedFilePath->string() : String();
  91. }
  92. String InjectedBundlePageUIClient::generateFileForUpload(WebPage* page, const String& originalFilePath)
  93. {
  94. if (!m_client.shouldGenerateFileForUpload)
  95. return String();
  96. RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.generateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo)));
  97. return generatedFilePath ? generatedFilePath->string() : String();
  98. }
  99. bool InjectedBundlePageUIClient::shouldRubberBandInDirection(WebPage* page, WKScrollDirection direction) const
  100. {
  101. if (!m_client.shouldRubberBandInDirection)
  102. return true;
  103. return m_client.shouldRubberBandInDirection(toAPI(page), direction, m_client.clientInfo);
  104. }
  105. WKBundlePageUIElementVisibility InjectedBundlePageUIClient::statusBarIsVisible(WebPage* page)
  106. {
  107. if (!m_client.statusBarIsVisible)
  108. return WKBundlePageUIElementVisibilityUnknown;
  109. return m_client.statusBarIsVisible(toAPI(page), m_client.clientInfo);
  110. }
  111. WKBundlePageUIElementVisibility InjectedBundlePageUIClient::menuBarIsVisible(WebPage* page)
  112. {
  113. if (!m_client.menuBarIsVisible)
  114. return WKBundlePageUIElementVisibilityUnknown;
  115. return m_client.menuBarIsVisible(toAPI(page), m_client.clientInfo);
  116. }
  117. WKBundlePageUIElementVisibility InjectedBundlePageUIClient::toolbarsAreVisible(WebPage* page)
  118. {
  119. if (!m_client.toolbarsAreVisible)
  120. return WKBundlePageUIElementVisibilityUnknown;
  121. return m_client.toolbarsAreVisible(toAPI(page), m_client.clientInfo);
  122. }
  123. void InjectedBundlePageUIClient::didReachApplicationCacheOriginQuota(WebPage* page, WebSecurityOrigin* origin, int64_t totalBytesNeeded)
  124. {
  125. if (!m_client.didReachApplicationCacheOriginQuota)
  126. return;
  127. m_client.didReachApplicationCacheOriginQuota(toAPI(page), toAPI(origin), totalBytesNeeded, m_client.clientInfo);
  128. }
  129. uint64_t InjectedBundlePageUIClient::didExceedDatabaseQuota(WebPage* page, WebSecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes)
  130. {
  131. if (!m_client.didExceedDatabaseQuota)
  132. return 0;
  133. return m_client.didExceedDatabaseQuota(toAPI(page), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuotaBytes, currentOriginUsageBytes, currentDatabaseUsageBytes, expectedUsageBytes, m_client.clientInfo);
  134. }
  135. String InjectedBundlePageUIClient::plugInStartLabelTitle(const String& mimeType) const
  136. {
  137. if (!m_client.createPlugInStartLabelTitle)
  138. return String();
  139. RefPtr<WebString> title = adoptRef(toImpl(m_client.createPlugInStartLabelTitle(toAPI(mimeType.impl()), m_client.clientInfo)));
  140. return title ? title->string() : String();
  141. }
  142. String InjectedBundlePageUIClient::plugInStartLabelSubtitle(const String& mimeType) const
  143. {
  144. if (!m_client.createPlugInStartLabelSubtitle)
  145. return String();
  146. RefPtr<WebString> subtitle = adoptRef(toImpl(m_client.createPlugInStartLabelSubtitle(toAPI(mimeType.impl()), m_client.clientInfo)));
  147. return subtitle ? subtitle->string() : String();
  148. }
  149. String InjectedBundlePageUIClient::plugInExtraStyleSheet() const
  150. {
  151. if (!m_client.createPlugInExtraStyleSheet)
  152. return String();
  153. RefPtr<WebString> styleSheet = adoptRef(toImpl(m_client.createPlugInExtraStyleSheet(m_client.clientInfo)));
  154. return styleSheet ? styleSheet->string() : String();
  155. }
  156. String InjectedBundlePageUIClient::plugInExtraScript() const
  157. {
  158. if (!m_client.createPlugInExtraScript)
  159. return String();
  160. RefPtr<WebString> script = adoptRef(toImpl(m_client.createPlugInExtraScript(m_client.clientInfo)));
  161. return script ? script->string() : String();
  162. }
  163. } // namespace WebKit