InjectedBundle.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2010, 2011, 2012 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. #ifndef InjectedBundle_h
  26. #define InjectedBundle_h
  27. #include "AccessibilityController.h"
  28. #include "EventSendingController.h"
  29. #include "GCController.h"
  30. #include "TestRunner.h"
  31. #include "TextInputController.h"
  32. #include <WebKit2/WKBase.h>
  33. #include <WebKit2/WKRetainPtr.h>
  34. #include <sstream>
  35. #include <wtf/Forward.h>
  36. #include <wtf/OwnPtr.h>
  37. #include <wtf/RefPtr.h>
  38. #include <wtf/Vector.h>
  39. namespace WTR {
  40. class InjectedBundlePage;
  41. class InjectedBundle {
  42. public:
  43. static InjectedBundle& shared();
  44. // Initialize the InjectedBundle.
  45. void initialize(WKBundleRef, WKTypeRef initializationUserData);
  46. WKBundleRef bundle() const { return m_bundle; }
  47. WKBundlePageGroupRef pageGroup() const { return m_pageGroup; }
  48. TestRunner* testRunner() { return m_testRunner.get(); }
  49. GCController* gcController() { return m_gcController.get(); }
  50. EventSendingController* eventSendingController() { return m_eventSendingController.get(); }
  51. TextInputController* textInputController() { return m_textInputController.get(); }
  52. AccessibilityController* accessibilityController() { return m_accessibilityController.get(); }
  53. InjectedBundlePage* page() const;
  54. size_t pageCount() const { return m_pages.size(); }
  55. void closeOtherPages();
  56. void dumpBackForwardListsForAllPages(StringBuilder&);
  57. void done();
  58. void setAudioResult(WKDataRef audioData) { m_audioResult = audioData; }
  59. void setPixelResult(WKImageRef image) { m_pixelResult = image; }
  60. void setRepaintRects(WKArrayRef rects) { m_repaintRects = rects; }
  61. bool isTestRunning() { return m_state == Testing; }
  62. WKBundleFrameRef topLoadingFrame() { return m_topLoadingFrame; }
  63. void setTopLoadingFrame(WKBundleFrameRef frame) { m_topLoadingFrame = frame; }
  64. bool shouldDumpPixels() const { return m_dumpPixels; }
  65. bool useWaitToDumpWatchdogTimer() const { return m_useWaitToDumpWatchdogTimer; }
  66. void outputText(const String&);
  67. void postNewBeforeUnloadReturnValue(bool);
  68. void postAddChromeInputField();
  69. void postRemoveChromeInputField();
  70. void postFocusWebView();
  71. void postSetBackingScaleFactor(double);
  72. void postSetWindowIsKey(bool);
  73. void postSimulateWebNotificationClick(uint64_t notificationID);
  74. // Geolocation.
  75. void setGeolocationPermission(bool);
  76. void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
  77. void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
  78. // Policy delegate.
  79. void setCustomPolicyDelegate(bool enabled, bool permissive);
  80. // Page Visibility.
  81. void setVisibilityState(WKPageVisibilityState, bool isInitialState);
  82. // Work queue.
  83. bool shouldProcessWorkQueue() const;
  84. void processWorkQueue();
  85. void queueBackNavigation(unsigned howFarBackward);
  86. void queueForwardNavigation(unsigned howFarForward);
  87. void queueLoad(WKStringRef url, WKStringRef target);
  88. void queueLoadHTMLString(WKStringRef content, WKStringRef baseURL = 0, WKStringRef unreachableURL = 0);
  89. void queueReload();
  90. void queueLoadingScript(WKStringRef script);
  91. void queueNonLoadingScript(WKStringRef script);
  92. #if PLATFORM(MANX)
  93. void injectSceExtensions(WKBundleFrameRef, WKBundleScriptWorldRef);
  94. #endif
  95. private:
  96. InjectedBundle();
  97. ~InjectedBundle();
  98. static void didCreatePage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
  99. static void willDestroyPage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
  100. static void didInitializePageGroup(WKBundleRef, WKBundlePageGroupRef, const void* clientInfo);
  101. static void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo);
  102. static void didReceiveMessageToPage(WKBundleRef, WKBundlePageRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo);
  103. void didCreatePage(WKBundlePageRef);
  104. void willDestroyPage(WKBundlePageRef);
  105. void didInitializePageGroup(WKBundlePageGroupRef);
  106. void didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody);
  107. void didReceiveMessageToPage(WKBundlePageRef, WKStringRef messageName, WKTypeRef messageBody);
  108. void platformInitialize(WKTypeRef initializationUserData);
  109. void resetLocalSettings();
  110. void beginTesting(WKDictionaryRef initialSettings);
  111. bool booleanForKey(WKDictionaryRef, const char* key);
  112. WKBundleRef m_bundle;
  113. WKBundlePageGroupRef m_pageGroup;
  114. Vector<OwnPtr<InjectedBundlePage> > m_pages;
  115. RefPtr<AccessibilityController> m_accessibilityController;
  116. RefPtr<TestRunner> m_testRunner;
  117. RefPtr<GCController> m_gcController;
  118. RefPtr<EventSendingController> m_eventSendingController;
  119. RefPtr<TextInputController> m_textInputController;
  120. WKBundleFrameRef m_topLoadingFrame;
  121. enum State {
  122. Idle,
  123. Testing,
  124. Stopping
  125. };
  126. State m_state;
  127. bool m_dumpPixels;
  128. bool m_useWaitToDumpWatchdogTimer;
  129. bool m_useWorkQueue;
  130. int m_timeout;
  131. WKRetainPtr<WKDataRef> m_audioResult;
  132. WKRetainPtr<WKImageRef> m_pixelResult;
  133. WKRetainPtr<WKArrayRef> m_repaintRects;
  134. };
  135. } // namespace WTR
  136. #endif // InjectedBundle_h