WebPage.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef WebPage_h
  19. #define WebPage_h
  20. #include "BlackBerryGlobal.h"
  21. #include "JavaScriptVariant.h"
  22. #include <BlackBerryPlatformGuardedPointer.h>
  23. #include <BlackBerryPlatformInputEvents.h>
  24. #include <BlackBerryPlatformString.h>
  25. #include <BlackBerryPlatformWebContext.h>
  26. #include <JavaScriptCore/JSBase.h>
  27. #include <imf/input_data.h>
  28. #include <network/NetworkRequest.h>
  29. #include <string>
  30. #include <vector>
  31. namespace WebCore {
  32. class ChromeClientBlackBerry;
  33. class Frame;
  34. class FrameLoaderClientBlackBerry;
  35. }
  36. class WebDOMDocument;
  37. class WebDOMNode;
  38. template<typename T> class SharedArray;
  39. namespace BlackBerry {
  40. namespace Platform {
  41. class FloatPoint;
  42. class IntPoint;
  43. class IntRect;
  44. class IntSize;
  45. class KeyboardEvent;
  46. class MouseEvent;
  47. class TouchEvent;
  48. class TouchPoint;
  49. class ViewportAccessor;
  50. }
  51. namespace WebKit {
  52. class BackingStore;
  53. class BackingStoreClient;
  54. class BackingStorePrivate;
  55. class InRegionScroller;
  56. class PagePopup;
  57. class RenderQueue;
  58. class WebCookieJar;
  59. class WebOverlay;
  60. class WebPageClient;
  61. class WebPageCompositor;
  62. class WebPageGroupLoadDeferrer;
  63. class WebPagePrivate;
  64. class WebSettings;
  65. class WebTapHighlight;
  66. class WebViewportArguments;
  67. enum JavaScriptDataType { JSUndefined = 0, JSNull, JSBoolean, JSNumber, JSString, JSObject, JSException, JSDataTypeMax };
  68. enum SelectionExpansionType { Word = 0, Sentence, Paragraph, NextParagraph };
  69. enum ActivationStateType { ActivationActive, ActivationInactive, ActivationStandby };
  70. enum TargetDetectionStrategy {PointBased, RectBased, FocusBased};
  71. class BLACKBERRY_EXPORT WebPage : public Platform::GuardedPointerBase {
  72. public:
  73. WebPage(WebPageClient*, const BlackBerry::Platform::String& pageGroupName, const Platform::IntRect&);
  74. void destroy();
  75. WebPageClient* client() const;
  76. void loadFile(const BlackBerry::Platform::String& path, const BlackBerry::Platform::String& overrideContentType = BlackBerry::Platform::String::emptyString());
  77. void loadString(const BlackBerry::Platform::String&, const BlackBerry::Platform::String& baseURL, const BlackBerry::Platform::String& contentType = BlackBerry::Platform::String::fromAscii("text/html"), const BlackBerry::Platform::String& failingURL = BlackBerry::Platform::String::emptyString());
  78. void load(const Platform::NetworkRequest&, bool needReferer = false);
  79. bool executeJavaScript(const BlackBerry::Platform::String& script, JavaScriptDataType& returnType, BlackBerry::Platform::String& returnValue);
  80. // This will execute the script even if in-page JavaScript is disabled.
  81. bool executeJavaScriptInIsolatedWorld(const BlackBerry::Platform::String& script, JavaScriptDataType& returnType, BlackBerry::Platform::String& returnValue);
  82. // Takes a UTF16 encoded script that is used explicitly by the pattern matching code
  83. bool executeJavaScriptInIsolatedWorld(const std::wstring& script, JavaScriptDataType& returnType, BlackBerry::Platform::String& returnValue);
  84. void executeJavaScriptFunction(const std::vector<BlackBerry::Platform::String> &function, const std::vector<JavaScriptVariant> &args, JavaScriptVariant& returnValue);
  85. void initializeIconDataBase();
  86. void stopLoading();
  87. bool dispatchBeforeUnloadEvent();
  88. // This will force any unload handlers to run.
  89. void prepareToDestroy();
  90. void enableCrossSiteXHR();
  91. void addOriginAccessWhitelistEntry(const BlackBerry::Platform::String& sourceOrigin, const BlackBerry::Platform::String& destinationOrigin, bool allowDestinationSubdomains);
  92. void removeOriginAccessWhitelistEntry(const BlackBerry::Platform::String& sourceOrigin, const BlackBerry::Platform::String& destinationOrigin, bool allowDestinationSubdomains);
  93. void reload();
  94. void reloadFromCache();
  95. WebSettings* settings() const;
  96. WebCookieJar* cookieJar() const;
  97. bool isLoading() const;
  98. void setVisible(bool);
  99. bool isVisible() const;
  100. void setScreenOrientation(int);
  101. void applyPendingOrientationIfNeeded();
  102. Platform::ViewportAccessor* webkitThreadViewportAccessor() const;
  103. // Returns the size of the visual viewport.
  104. Platform::IntSize viewportSize() const;
  105. // Sets the sizes of the visual viewport and the layout viewport.
  106. void setViewportSize(const Platform::IntSize& viewportSize, const Platform::IntSize& defaultLayoutSize, bool ensureFocusElementVisible = true);
  107. void resetVirtualViewportOnCommitted(bool reset);
  108. void setVirtualViewportSize(const Platform::IntSize&);
  109. // Returns the size of the layout viewport.
  110. Platform::IntSize defaultLayoutSize() const;
  111. // Set the size of the layout viewport, in document coordinates, independently of the visual viewport.
  112. void setDefaultLayoutSize(const Platform::IntSize&);
  113. bool mouseEvent(const Platform::MouseEvent&, bool* wheelDeltaAccepted = 0);
  114. // Handles native javascript touch events.
  115. bool touchEvent(const Platform::TouchEvent&);
  116. // For conversion to mouse events.
  117. void touchEventCancel();
  118. void touchPointAsMouseEvent(const Platform::TouchPoint&, unsigned modifiers = 0);
  119. void playSoundIfAnchorIsTarget() const;
  120. // Returns true if the key stroke was handled by WebKit.
  121. bool keyEvent(const Platform::KeyboardEvent&);
  122. BlackBerry::Platform::String title() const;
  123. BlackBerry::Platform::String selectedText() const;
  124. BlackBerry::Platform::String cutSelectedText();
  125. void insertText(const BlackBerry::Platform::String&);
  126. void clearCurrentInputField();
  127. void cut();
  128. void copy();
  129. void paste();
  130. void selectAll();
  131. // Text encoding.
  132. BlackBerry::Platform::String textEncoding();
  133. BlackBerry::Platform::String forcedTextEncoding();
  134. void setForcedTextEncoding(const BlackBerry::Platform::String&);
  135. // Scroll position provided should be in document coordinates.
  136. // Use webkitThreadViewportAccessor() to retrieve the scroll position.
  137. void setDocumentScrollPosition(const Platform::IntPoint&);
  138. void notifyInRegionScrollStopped();
  139. void setDocumentScrollOriginPoint(const Platform::IntPoint&);
  140. BackingStore* backingStore() const;
  141. InRegionScroller* inRegionScroller() const;
  142. bool blockZoom(const Platform::IntPoint& documentTargetPoint);
  143. void zoomAnimationFinished(double finalScale, const Platform::FloatPoint& finalDocumentScrollPosition, bool shouldConstrainScrollingToContentEdge);
  144. void resetBlockZoom();
  145. bool isAtInitialZoom() const;
  146. bool isMaxZoomed() const;
  147. bool isMinZoomed() const;
  148. bool pinchZoomAboutPoint(double scale, const Platform::FloatPoint& documentFocalPoint);
  149. bool isUserScalable() const;
  150. void setUserScalable(bool);
  151. double currentScale() const;
  152. double initialScale() const;
  153. double zoomToFitScale() const;
  154. void setInitialScale(double);
  155. double minimumScale() const;
  156. void setMinimumScale(double);
  157. double maximumScale() const;
  158. void setMaximumScale(double);
  159. void assignFocus(Platform::FocusDirection);
  160. void setFocused(bool);
  161. void focusNextField();
  162. void focusPreviousField();
  163. void submitForm();
  164. void clearBrowsingData();
  165. void clearHistory();
  166. void clearCookies();
  167. void clearCache();
  168. void clearLocalStorage();
  169. void clearCredentials();
  170. void clearAutofillData();
  171. void clearNeverRememberSites();
  172. void clearWebFileSystem();
  173. void runLayoutTests();
  174. // Find the next utf8 string in the given direction.
  175. // Case sensitivity, wrapping, and highlighting all matches are also toggleable.
  176. bool findNextString(const char*, bool forward, bool caseSensitive, bool wrap, bool highlightAllMatches, bool selectActiveMatchOnClear);
  177. JSGlobalContextRef globalContext() const;
  178. unsigned timeoutForJavaScriptExecution() const;
  179. void setTimeoutForJavaScriptExecution(unsigned ms);
  180. void setCaretHighlightStyle(Platform::CaretHighlightStyle);
  181. // IMF functions.
  182. bool setBatchEditingActive(bool);
  183. bool setInputSelection(unsigned start, unsigned end);
  184. int inputCaretPosition() const;
  185. bool deleteTextRelativeToCursor(unsigned leftOffset, unsigned rightOffset);
  186. spannable_string_t* selectedText(int32_t flags);
  187. spannable_string_t* textBeforeCursor(int32_t length, int32_t flags);
  188. spannable_string_t* textAfterCursor(int32_t length, int32_t flags);
  189. extracted_text_t* extractedTextRequest(extracted_text_request_t*, int32_t flags);
  190. int32_t setComposingRegion(int32_t start, int32_t end);
  191. int32_t finishComposition();
  192. int32_t setComposingText(spannable_string_t*, int32_t relativeCursorPosition);
  193. int32_t commitText(spannable_string_t*, int32_t relativeCursorPosition);
  194. void setSpellCheckingEnabled(bool);
  195. void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*);
  196. bool isInputMode() const;
  197. void setDocumentSelection(const Platform::IntPoint& documentStartPoint, const Platform::IntPoint& documentEndPoint);
  198. void setDocumentCaretPosition(const Platform::IntPoint&);
  199. void selectAtDocumentPoint(const Platform::IntPoint&, SelectionExpansionType = Word);
  200. void expandSelection(bool isScrollStarted);
  201. void setOverlayExpansionPixelHeight(int);
  202. void setParagraphExpansionPixelScrollMargin(const Platform::IntSize&);
  203. void setSelectionDocumentViewportSize(const Platform::IntSize&);
  204. void selectionCancelled();
  205. bool selectionContainsDocumentPoint(const Platform::IntPoint&);
  206. void popupListClosed(int size, const bool* selecteds);
  207. void popupListClosed(int index);
  208. void setDateTimeInput(const BlackBerry::Platform::String& value);
  209. void setColorInput(const BlackBerry::Platform::String& value);
  210. static void onNetworkAvailabilityChanged(bool available);
  211. static void onCertificateStoreLocationSet(const BlackBerry::Platform::String& caPath);
  212. BlackBerry::Platform::String textHasAttribute(const BlackBerry::Platform::String& query) const;
  213. Platform::WebContext webContext(TargetDetectionStrategy) const;
  214. typedef intptr_t BackForwardId;
  215. struct BackForwardEntry {
  216. BlackBerry::Platform::String url;
  217. BlackBerry::Platform::String originalUrl;
  218. BlackBerry::Platform::String title;
  219. BlackBerry::Platform::String networkToken;
  220. BackForwardId id;
  221. bool lastVisitWasHTTPNonGet;
  222. };
  223. bool canGoBackOrForward(int delta) const;
  224. // Returns false if there is no page for the given delta (eg.
  225. // attempt to go back with -1 when on the first page).
  226. bool goBackOrForward(int delta);
  227. void goToBackForwardEntry(BackForwardId);
  228. int backForwardListLength() const;
  229. void getBackForwardList(SharedArray<BackForwardEntry>& result) const;
  230. void releaseBackForwardEntry(BackForwardId) const;
  231. void clearBackForwardList(bool keepCurrentPage) const;
  232. void addVisitedLink(const unsigned short* url, unsigned length);
  233. bool defersLoading() const;
  234. bool isEnableLocalAccessToAllCookies() const;
  235. void setEnableLocalAccessToAllCookies(bool);
  236. void enableDNSPrefetch();
  237. void disableDNSPrefetch();
  238. bool isDNSPrefetchEnabled() const;
  239. void enableWebInspector();
  240. void disableWebInspector();
  241. bool isWebInspectorEnabled();
  242. void enablePasswordEcho();
  243. void disablePasswordEcho();
  244. void dispatchInspectorMessage(const BlackBerry::Platform::String& message);
  245. void inspectCurrentContextElement();
  246. Platform::IntPoint adjustDocumentScrollPosition(const Platform::IntPoint& documentScrollPosition, const Platform::IntRect& documentPaddingRect);
  247. Platform::IntSize fixedElementSizeDelta();
  248. // FIXME: Needs API review on this header. See PR #120402.
  249. void notifyPagePause();
  250. void notifyPageResume();
  251. void notifyPageBackground();
  252. void notifyPageForeground();
  253. void notifyPageFullScreenAllowed();
  254. void notifyPageFullScreenExit();
  255. void notifyDeviceIdleStateChange(bool enterIdle);
  256. void notifyAppActivationStateChange(ActivationStateType);
  257. void notifySwipeEvent();
  258. void notifyScreenPowerStateChanged(bool powered);
  259. void notifyFullScreenVideoExited(bool done);
  260. void clearPluginSiteData();
  261. void setExtraPluginDirectory(const BlackBerry::Platform::String& path);
  262. void updateDisabledPluginFiles(const BlackBerry::Platform::String& fileName, bool disabled);
  263. void setJavaScriptCanAccessClipboard(bool);
  264. bool isWebGLEnabled() const;
  265. void setWebGLEnabled(bool);
  266. void destroyWebPageCompositor();
  267. void setUserViewportArguments(const WebViewportArguments&);
  268. void resetUserViewportArguments();
  269. WebTapHighlight* tapHighlight() const;
  270. WebTapHighlight* selectionHighlight() const;
  271. // Adds an overlay that can be modified on the WebKit thread, and
  272. // whose attributes can be overridden on the compositing thread.
  273. void addOverlay(WebOverlay*);
  274. void removeOverlay(WebOverlay*);
  275. // Adds an overlay that can only be modified on the compositing thread.
  276. void addCompositingThreadOverlay(WebOverlay*);
  277. void removeCompositingThreadOverlay(WebOverlay*);
  278. // Popup client
  279. void initPopupWebView(BlackBerry::WebKit::WebPage*);
  280. void autofillTextField(const BlackBerry::Platform::String&);
  281. BlackBerry::Platform::String renderTreeAsText();
  282. void updateNotificationPermission(const BlackBerry::Platform::String& requestId, bool allowed);
  283. void notificationClicked(const BlackBerry::Platform::String& notificationId);
  284. void notificationClosed(const BlackBerry::Platform::String& notificationId);
  285. void notificationError(const BlackBerry::Platform::String& notificationId);
  286. void notificationShown(const BlackBerry::Platform::String& notificationId);
  287. void animateToScaleAndDocumentScrollPosition(double destinationZoomScale, const BlackBerry::Platform::FloatPoint& destinationScrollPosition, bool shouldConstrainScrollingToContentEdge = true);
  288. bool isProcessingUserGesture() const;
  289. void setShowDebugBorders(bool);
  290. private:
  291. virtual ~WebPage();
  292. friend class WebKit::BackingStore;
  293. friend class WebKit::BackingStoreClient;
  294. friend class WebKit::BackingStorePrivate;
  295. friend class WebKit::PagePopup;
  296. friend class WebKit::RenderQueue;
  297. friend class WebKit::WebPageCompositor;
  298. friend class WebKit::WebPageGroupLoadDeferrer;
  299. friend class WebKit::WebPagePrivate;
  300. friend class WebCore::ChromeClientBlackBerry;
  301. friend class WebCore::FrameLoaderClientBlackBerry;
  302. WebPagePrivate* d;
  303. };
  304. }
  305. }
  306. #endif // WebPage_h