WebPlatformStrategies.mm 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. #import "WebPlatformStrategies.h"
  26. #import "WebFrameNetworkingContext.h"
  27. #import "WebPluginDatabase.h"
  28. #import "WebPluginPackage.h"
  29. #import <WebCore/BlockExceptions.h>
  30. #import <WebCore/Color.h>
  31. #import <WebCore/Page.h>
  32. #import <WebCore/PageGroup.h>
  33. #import <WebCore/PlatformCookieJar.h>
  34. #import <WebCore/PlatformPasteboard.h>
  35. #import <WebKitSystemInterface.h>
  36. using namespace WebCore;
  37. void WebPlatformStrategies::initializeIfNecessary()
  38. {
  39. static WebPlatformStrategies* platformStrategies;
  40. if (!platformStrategies) {
  41. platformStrategies = new WebPlatformStrategies;
  42. setPlatformStrategies(platformStrategies);
  43. }
  44. }
  45. WebPlatformStrategies::WebPlatformStrategies()
  46. {
  47. }
  48. CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
  49. {
  50. return this;
  51. }
  52. DatabaseStrategy* WebPlatformStrategies::createDatabaseStrategy()
  53. {
  54. return this;
  55. }
  56. LoaderStrategy* WebPlatformStrategies::createLoaderStrategy()
  57. {
  58. return this;
  59. }
  60. PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
  61. {
  62. return this;
  63. }
  64. PluginStrategy* WebPlatformStrategies::createPluginStrategy()
  65. {
  66. return this;
  67. }
  68. SharedWorkerStrategy* WebPlatformStrategies::createSharedWorkerStrategy()
  69. {
  70. return this;
  71. }
  72. StorageStrategy* WebPlatformStrategies::createStorageStrategy()
  73. {
  74. return this;
  75. }
  76. VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy()
  77. {
  78. return this;
  79. }
  80. String WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
  81. {
  82. return WebCore::cookiesForDOM(session, firstParty, url);
  83. }
  84. void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, const String& cookieString)
  85. {
  86. WebCore::setCookiesFromDOM(session, firstParty, url, cookieString);
  87. }
  88. bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
  89. {
  90. return WebCore::cookiesEnabled(session, firstParty, url);
  91. }
  92. String WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
  93. {
  94. return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url);
  95. }
  96. bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, Vector<Cookie>& rawCookies)
  97. {
  98. return WebCore::getRawCookies(session, firstParty, url, rawCookies);
  99. }
  100. void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& cookieName)
  101. {
  102. WebCore::deleteCookie(session, url, cookieName);
  103. }
  104. void WebPlatformStrategies::refreshPlugins()
  105. {
  106. [[WebPluginDatabase sharedDatabaseIfExists] refresh];
  107. }
  108. void WebPlatformStrategies::getPluginInfo(const Page* page, Vector<PluginInfo>& plugins)
  109. {
  110. BEGIN_BLOCK_OBJC_EXCEPTIONS;
  111. // WebKit1 has no application plug-ins, so we don't need to add them here.
  112. if (!page->mainFrame()->loader()->subframeLoader()->allowPlugins(NotAboutToInstantiatePlugin))
  113. return;
  114. NSArray* pluginsArray = [[WebPluginDatabase sharedDatabase] plugins];
  115. for (unsigned int i = 0; i < [pluginsArray count]; ++i) {
  116. WebPluginPackage *plugin = [pluginsArray objectAtIndex:i];
  117. plugins.append([plugin pluginInfo]);
  118. }
  119. END_BLOCK_OBJC_EXCEPTIONS;
  120. }
  121. bool WebPlatformStrategies::isLinkVisited(Page* page, LinkHash hash, const KURL&, const AtomicString&)
  122. {
  123. return page->group().isLinkVisited(hash);
  124. }
  125. void WebPlatformStrategies::addVisitedLink(Page* page, LinkHash hash)
  126. {
  127. return page->group().addVisitedLinkHash(hash);
  128. }
  129. void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
  130. {
  131. PlatformPasteboard(pasteboardName).getTypes(types);
  132. }
  133. PassRefPtr<SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
  134. {
  135. return PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
  136. }
  137. void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
  138. {
  139. PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
  140. }
  141. String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
  142. {
  143. return PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
  144. }
  145. void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard)
  146. {
  147. PlatformPasteboard(toPasteboard).copy(fromPasteboard);
  148. }
  149. int WebPlatformStrategies::changeCount(const String &pasteboardName)
  150. {
  151. return PlatformPasteboard(pasteboardName).changeCount();
  152. }
  153. String WebPlatformStrategies::uniqueName()
  154. {
  155. return PlatformPasteboard::uniqueName();
  156. }
  157. Color WebPlatformStrategies::color(const String& pasteboardName)
  158. {
  159. return PlatformPasteboard(pasteboardName).color();
  160. }
  161. KURL WebPlatformStrategies::url(const String& pasteboardName)
  162. {
  163. return PlatformPasteboard(pasteboardName).url();
  164. }
  165. void WebPlatformStrategies::addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
  166. {
  167. PlatformPasteboard(pasteboardName).addTypes(pasteboardTypes);
  168. }
  169. void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
  170. {
  171. PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
  172. }
  173. void WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName)
  174. {
  175. PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
  176. }
  177. void WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
  178. {
  179. PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
  180. }
  181. void WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
  182. {
  183. PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);
  184. }