Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_BrowserElementHelpers_h
6 #define mozilla_BrowserElementHelpers_h
8 #include "nsAString.h"
9 #include "mozilla/gfx/Point.h"
10 #include "mozilla/gfx/Rect.h"
11 #include "Units.h"
12 #include "mozilla/dom/Element.h"
14 class nsIDOMWindow;
15 class nsIURI;
17 namespace mozilla {
19 namespace dom {
20 class TabParent;
21 }
23 /**
24 * BrowserElementParent implements a portion of the parent-process side of
25 * <iframe mozbrowser>.
26 *
27 * Most of the parent-process side of <iframe mozbrowser> is implemented in
28 * BrowserElementParent.js. This file implements the few parts of this
29 * functionality which must be written in C++.
30 *
31 * We don't communicate with the JS code that lives in BrowserElementParent.js;
32 * the JS and C++ parts are completely separate.
33 */
34 class BrowserElementParent
35 {
36 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 */
47 enum OpenWindowResult {
48 OPEN_WINDOW_ADDED,
49 OPEN_WINDOW_IGNORED,
50 OPEN_WINDOW_CANCELLED
51 };
53 /**
54 * Handle a window.open call from an out-of-process <iframe mozbrowser>.
55 *
56 * window.open inside <iframe mozbrowser> doesn't actually open a new
57 * top-level window. Instead, the "embedder" (the document which contains
58 * the <iframe mozbrowser> whose content called window.open) gets the
59 * opportunity to place a new <iframe mozbrowser> in the DOM somewhere. This
60 * new "popup" iframe acts as the opened window.
61 *
62 * This method proceeds in three steps.
63 *
64 * 1) We fire a mozbrowseropenwindow CustomEvent on the opener
65 * iframe element. This event's detail is an instance of
66 * OpenWindowEventDetail.
67 *
68 * 2) The embedder (the document which contains the opener iframe) can accept
69 * the window.open request by inserting event.detail.frameElement (an iframe
70 * element) into the DOM somewhere.
71 *
72 * 3) If the embedder accepted the window.open request, we return true and
73 * set aPopupTabParent's frame element to event.detail.frameElement.
74 * Otherwise, we return false.
75 *
76 * @param aURL the URL the new window should load. The empty string is
77 * allowed.
78 * @param aOpenerTabParent the TabParent whose TabChild called window.open.
79 * @param aPopupTabParent the TabParent inside which the opened window will
80 * live.
81 * @return an OpenWindowresult that describes whether the embedder added the
82 * frame to a document and whether it called preventDefault to prevent
83 * the platform from handling the open request.
84 */
85 static OpenWindowResult
86 OpenWindowOOP(dom::TabParent* aOpenerTabParent,
87 dom::TabParent* aPopupTabParent,
88 const nsAString& aURL,
89 const nsAString& aName,
90 const nsAString& aFeatures);
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(nsIDOMWindow* aOpenerWindow,
105 nsIURI* aURI,
106 const nsAString& aName,
107 const nsACString& aFeatures,
108 nsIDOMWindow** aReturnWindow);
110 /**
111 * Fire a mozbrowserasyncscroll CustomEvent on the given TabParent's frame element.
112 * This event's detail is an AsyncScrollEventDetail dictionary.
113 *
114 * @param aContentRect: The portion of the page which is currently visible
115 * onscreen in CSS pixels.
116 *
117 * @param aContentSize: The content width/height in CSS pixels.
118 *
119 * aContentRect.top + aContentRect.height may be larger than aContentSize.height.
120 * This indicates that the content is over-scrolled, which occurs when the
121 * page "rubber-bands" after being scrolled all the way to the bottom.
122 * Similarly, aContentRect.left + aContentRect.width may be greater than
123 * contentSize.width, and both left and top may be negative.
124 */
125 static bool
126 DispatchAsyncScrollEvent(dom::TabParent* aTabParent,
127 const CSSRect& aContentRect,
128 const CSSSize& aContentSize);
130 private:
131 static OpenWindowResult
132 DispatchOpenWindowEvent(dom::Element* aOpenerFrameElement,
133 dom::Element* aPopupFrameElement,
134 const nsAString& aURL,
135 const nsAString& aName,
136 const nsAString& aFeatures);
137 };
139 } // namespace mozilla
141 #endif