BrowserElementParent.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_BrowserElementHelpers_h
  6. #define mozilla_BrowserElementHelpers_h
  7. #include "nsAString.h"
  8. #include "mozilla/gfx/Point.h"
  9. #include "mozilla/gfx/Rect.h"
  10. #include "Units.h"
  11. #include "mozilla/dom/Element.h"
  12. class nsIDOMWindow;
  13. class nsIURI;
  14. namespace mozilla {
  15. namespace dom {
  16. class TabParent;
  17. } // namespace dom
  18. namespace layers {
  19. struct TextureFactoryIdentifier;
  20. } // namespace layers
  21. namespace layout {
  22. class PRenderFrameParent;
  23. } // namespace layout
  24. /**
  25. * BrowserElementParent implements a portion of the parent-process side of
  26. * <iframe mozbrowser>.
  27. *
  28. * Most of the parent-process side of <iframe mozbrowser> is implemented in
  29. * BrowserElementParent.js. This file implements the few parts of this
  30. * functionality which must be written in C++.
  31. *
  32. * We don't communicate with the JS code that lives in BrowserElementParent.js;
  33. * the JS and C++ parts are completely separate.
  34. */
  35. class BrowserElementParent
  36. {
  37. public:
  38. /**
  39. * Possible results from a window.open call.
  40. * ADDED - The frame was added to a document (i.e. handled by the embedder).
  41. * IGNORED - The frame was not added to a document and the embedder didn't
  42. * call preventDefault() to prevent the platform from handling the call.
  43. * CANCELLED - The frame was not added to a document, but the embedder still
  44. * called preventDefault() to prevent the platform from handling the call.
  45. */
  46. enum OpenWindowResult {
  47. OPEN_WINDOW_ADDED,
  48. OPEN_WINDOW_IGNORED,
  49. OPEN_WINDOW_CANCELLED
  50. };
  51. /**
  52. * Handle a window.open call from an out-of-process <iframe mozbrowser>.
  53. *
  54. * window.open inside <iframe mozbrowser> doesn't actually open a new
  55. * top-level window. Instead, the "embedder" (the document which contains
  56. * the <iframe mozbrowser> whose content called window.open) gets the
  57. * opportunity to place a new <iframe mozbrowser> in the DOM somewhere. This
  58. * new "popup" iframe acts as the opened window.
  59. *
  60. * This method proceeds in three steps.
  61. *
  62. * 1) We fire a mozbrowseropenwindow CustomEvent on the opener
  63. * iframe element. This event's detail is an instance of
  64. * OpenWindowEventDetail.
  65. *
  66. * 2) The embedder (the document which contains the opener iframe) can accept
  67. * the window.open request by inserting event.detail.frameElement (an iframe
  68. * element) into the DOM somewhere.
  69. *
  70. * 3) If the embedder accepted the window.open request, we return true and
  71. * set aPopupTabParent's frame element to event.detail.frameElement.
  72. * Otherwise, we return false.
  73. *
  74. * @param aURL the URL the new window should load. The empty string is
  75. * allowed.
  76. * @param aOpenerTabParent the TabParent whose TabChild called window.open.
  77. * @param aPopupTabParent the TabParent inside which the opened window will
  78. * live.
  79. * @return an OpenWindowresult that describes whether the embedder added the
  80. * frame to a document and whether it called preventDefault to prevent
  81. * the platform from handling the open request.
  82. */
  83. static OpenWindowResult
  84. OpenWindowOOP(dom::TabParent* aOpenerTabParent,
  85. dom::TabParent* aPopupTabParent,
  86. layout::PRenderFrameParent* aRenderFrame,
  87. const nsAString& aURL,
  88. const nsAString& aName,
  89. const nsAString& aFeatures,
  90. layers::TextureFactoryIdentifier* aTextureFactoryIdentifier,
  91. uint64_t* aLayersId);
  92. /**
  93. * Handle a window.open call from an in-process <iframe mozbrowser>.
  94. *
  95. * (These parameter types are silly, but they match what our caller has in
  96. * hand. Feel free to add an override, if they are inconvenient to you.)
  97. *
  98. * @param aURI the URI the new window should load. May be null.
  99. * @return an OpenWindowResult that describes whether the browser added the
  100. * frame to a document or whether they called preventDefault to prevent
  101. * the platform from handling the open request
  102. */
  103. static OpenWindowResult
  104. OpenWindowInProcess(nsPIDOMWindowOuter* aOpenerWindow,
  105. nsIURI* aURI,
  106. const nsAString& aName,
  107. const nsACString& aFeatures,
  108. bool aForceNoOpener,
  109. mozIDOMWindowProxy** aReturnWindow);
  110. private:
  111. static OpenWindowResult
  112. DispatchOpenWindowEvent(dom::Element* aOpenerFrameElement,
  113. dom::Element* aPopupFrameElement,
  114. const nsAString& aURL,
  115. const nsAString& aName,
  116. const nsAString& aFeatures);
  117. };
  118. } // namespace mozilla
  119. #endif