dom/browser-element/BrowserElementParent.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial