nsIDocumentViewer.idl (11305B)
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/. */ 4 5 #include "nsISupports.idl" 6 7 interface nsIDocShell; 8 interface nsISHEntry; 9 interface nsIPrintSettings; 10 webidl Document; 11 webidl Node; 12 13 %{ C++ 14 #include "mozilla/Maybe.h" 15 #include "nsTArray.h" 16 #include "nsRect.h" 17 #include "Units.h" 18 19 class nsIWidget; 20 class nsPresContext; 21 class nsSubDocumentFrame; 22 class nsDOMNavigationTiming; 23 namespace mozilla { 24 class Encoding; 25 class PresShell; 26 namespace dom { 27 class WindowGlobalChild; 28 } // namespace dom 29 namespace layout { 30 class RemotePrintJobChild; 31 } // namespace layout 32 } // namespace mozilla 33 %} 34 35 [ptr] native nsIWidgetPtr(nsIWidget); 36 [ref] native LayoutDeviceIntRectRef(mozilla::LayoutDeviceIntRect); 37 [ptr] native nsPresContextPtr(nsPresContext); 38 [ptr] native nsSubDocumentFramePtr(nsSubDocumentFrame); 39 [ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming); 40 [ptr] native Encoding(const mozilla::Encoding); 41 [ptr] native PresShellPtr(mozilla::PresShell); 42 [ptr] native RemotePrintJobChildPtr(mozilla::layout::RemotePrintJobChild); 43 [ptr] native WindowGlobalChildPtr(mozilla::dom::WindowGlobalChild); 44 45 [scriptable, builtinclass, uuid(48118355-e9a5-4452-ab18-59cc426fb817)] 46 interface nsIDocumentViewer : nsISupports 47 { 48 [noscript] void init(in nsIWidgetPtr aParentWidget, 49 [const] in LayoutDeviceIntRectRef aBounds, 50 in WindowGlobalChildPtr aWindowActor); 51 52 attribute nsIDocShell container; 53 54 [noscript,notxpcom,nostdcall] void loadStart(in Document aDoc); 55 [can_run_script] void loadComplete(in nsresult aStatus); 56 [notxpcom,nostdcall] readonly attribute boolean loadCompleted; 57 58 [notxpcom,nostdcall] readonly attribute boolean isStopped; 59 60 /** 61 * aAction is passed to PermitUnload to indicate what action to take 62 * if a beforeunload handler wants to prompt the user. 63 * 64 * ePrompt: Prompt and return the user's choice (default). 65 * eDontPromptAndDontUnload: Don't prompt and return false (unload not permitted) 66 * if the document (or its children) asks us to prompt. 67 * eDontPromptAndUnload: Don't prompt and return true (unload permitted) no matter what. 68 * 69 * NOTE: Keep this in sync with PermitUnloadAction in WindowGlobalActors.webidl. 70 */ 71 cenum PermitUnloadAction : 8 { 72 ePrompt = 0, 73 eDontPromptAndDontUnload = 1, 74 eDontPromptAndUnload = 2 75 }; 76 77 /** 78 * The result of dispatching a "beforeunload" event. If `eAllowNavigation`, 79 * no "beforeunload" listener requested to prevent the navigation, or its 80 * request was ignored. If `eRequestBlockNavigation`, a listener did request 81 * to block the navigation, and the user should be prompted. 82 */ 83 cenum PermitUnloadResult : 8 { 84 eContinue = 0, 85 eCanceledByBeforeUnload = 1, 86 eCanceledByNavigate = 2, 87 }; 88 89 /** 90 * Overload PermitUnload method for C++ consumers with no aPermitUnloadFlags 91 * argument. 92 * 93 * ATTENTION: This call may destroy the docshell that owns this viewer. 94 */ 95 %{C++ 96 nsresult PermitUnload(bool* canUnload) { 97 return PermitUnload(ePrompt, canUnload); 98 } 99 %} 100 101 /** 102 * Checks if the document wants to prevent unloading by firing beforeunload on 103 * the document. 104 * The result is returned. 105 * 106 * ATTENTION: This call may destroy the docshell that owns this viewer. 107 */ 108 boolean permitUnload([optional] in nsIDocumentViewer_PermitUnloadAction aAction); 109 110 /** 111 * Exposes whether we're blocked in a call to permitUnload. 112 */ 113 readonly attribute boolean inPermitUnload; 114 115 /** 116 * Dispatches the "beforeunload" event and returns the result, as documented 117 * in the `PermitUnloadResult` enum. 118 */ 119 [noscript,nostdcall,notxpcom] nsIDocumentViewer_PermitUnloadResult dispatchBeforeUnload(); 120 121 /** 122 * Exposes whether we're in the process of firing the beforeunload event. 123 * In this case, the corresponding docshell will not allow navigation. 124 */ 125 readonly attribute boolean beforeUnloadFiring; 126 127 [can_run_script] void pageHide(in boolean isUnload); 128 129 /** 130 * All users of a content viewer are responsible for calling both 131 * close() and destroy(), in that order. 132 * 133 * close() should be called when the load of a new page for the next 134 * content viewer begins, and destroy() should be called when the next 135 * content viewer replaces this one. 136 * 137 * |historyEntry| sets the session history entry for the content viewer. If 138 * this is null, then Destroy() will be called on the document by close(). 139 * If it is non-null, the document will not be destroyed, and the following 140 * actions will happen when destroy() is called (*): 141 * - Sanitize() will be called on the viewer's document 142 * - The content viewer will set the documentViewer property on the 143 * history entry, and release its reference (ownership reversal). 144 * - hide() will be called, and no further destruction will happen. 145 * 146 * (*) unless the document is currently being printed, in which case 147 * it will never be saved in session history. 148 * 149 */ 150 void close(in nsISHEntry historyEntry); 151 void destroy(); 152 153 void stop(); 154 155 /** 156 * Returns the same thing as getDocument(), but for use from script 157 * only. C++ consumers should use getDocument(). 158 */ 159 readonly attribute Document DOMDocument; 160 161 /** 162 * Returns DOMDocument without addrefing. 163 */ 164 [noscript,notxpcom,nostdcall] Document getDocument(); 165 166 /** 167 * Allows setting the document. 168 */ 169 [noscript,nostdcall] void setDocument(in Document aDocument); 170 171 [noscript] void getBounds(in LayoutDeviceIntRectRef aBounds); 172 [noscript] void setBounds([const] in LayoutDeviceIntRectRef aBounds); 173 /** 174 * The 'aFlags' argument to setBoundsWithFlags is a set of these bits. 175 */ 176 const unsigned long eDelayResize = 1; 177 [noscript] void setBoundsWithFlags([const] in LayoutDeviceIntRectRef aBounds, 178 in unsigned long aFlags); 179 180 /** 181 * The previous content viewer, which has been |close|d but not 182 * |destroy|ed. 183 */ 184 [notxpcom,nostdcall] attribute nsIDocumentViewer previousViewer; 185 186 void move(in long aX, in long aY); 187 188 void show(); 189 void hide(); 190 191 attribute boolean sticky; 192 193 /** 194 * Attach the content viewer to its DOM window and docshell. 195 * @param aState A state object that might be useful in attaching the DOM 196 * window. 197 * @param aSHEntry The history entry that the content viewer was stored in. 198 * The entry must have the docshells for all of the child 199 * documents stored in its child shell list. 200 */ 201 void open(in nsISupports aState, in nsISHEntry aSHEntry); 202 203 /** 204 * Clears the current history entry. This is used if we need to clear out 205 * the saved presentation state. 206 */ 207 void clearHistoryEntry(); 208 209 /** 210 * Change the layout to view the document with page layout (like print preview), but 211 * dynamic and editable (like Galley layout). 212 */ 213 void setPageModeForTesting(in boolean aPageMode, 214 in nsIPrintSettings aPrintSettings); 215 216 /** 217 * Sets the print settings for print / print-previewing a subdocument. 218 */ 219 [can_run_script, noscript] 220 void setPrintSettingsForSubdocument(in nsIPrintSettings aPrintSettings, 221 in RemotePrintJobChildPtr aRemotePrintJob); 222 223 /** 224 * Get the history entry that this viewer will save itself into when 225 * destroyed. Can return null 226 */ 227 readonly attribute nsISHEntry historyEntry; 228 229 /** 230 * Indicates when we're in a state where content shouldn't be allowed to 231 * trigger a tab-modal prompt (as opposed to a window-modal prompt) because 232 * we're part way through some operation (eg beforeunload) that shouldn't be 233 * rentrant if the user closes the tab while the prompt is showing. 234 * See bug 613800. 235 */ 236 readonly attribute boolean isTabModalPromptAllowed; 237 238 /** 239 * Returns whether this content viewer is in a hidden state. 240 * 241 * @note Only Gecko internal code should set the attribute! 242 */ 243 attribute boolean isHidden; 244 245 // presShell can be null. 246 [notxpcom,nostdcall] readonly attribute PresShellPtr presShell; 247 // presContext can be null. 248 [notxpcom,nostdcall] readonly attribute nsPresContextPtr presContext; 249 // aDocument must not be null. 250 [noscript] void setDocumentInternal(in Document aDocument, 251 in boolean aForceReuseInnerWindow); 252 /** 253 * Find the view to use as the container view for MakeWindow. Returns 254 * null if this will be the root of a view manager hierarchy. In that 255 * case, if mParentWidget is null then this document should not even 256 * be displayed. 257 */ 258 [noscript,notxpcom,nostdcall] nsSubDocumentFramePtr findContainerFrame(); 259 /** 260 * Set collector for navigation timing data (load, unload events). 261 */ 262 [noscript,notxpcom,nostdcall] void setNavigationTiming(in nsDOMNavigationTimingPtr aTiming); 263 264 /** 265 * The actual full zoom in effect, as modified by the device context. 266 * For a requested full zoom, the device context may choose a slightly 267 * different effectiveFullZoom to accomodate integer rounding of app units 268 * per dev pixel. This property returns the actual zoom amount in use, 269 * though it may not be good user experience to report that a requested zoom 270 * of 90% is actually 89.1%, for example. This value is provided primarily to 271 * support media queries of dppx values, because those queries are matched 272 * against the actual native device pixel ratio and the actual full zoom. 273 * 274 * You should only need this for testing. 275 */ 276 readonly attribute float deviceFullZoomForTest; 277 278 /** 279 * Disable entire author style level (including HTML presentation hints), 280 * for this viewer but not any child viewers. 281 */ 282 attribute boolean authorStyleDisabled; 283 284 /** 285 * Returns the preferred width and height of the content, constrained to the 286 * given maximum values. If either maxWidth or maxHeight is less than or 287 * equal to zero, that dimension is not constrained. 288 * 289 * If a pref width is provided, it is max'd with the min-content size. 290 * 291 * All input and output values are in CSS pixels. 292 */ 293 void getContentSize(in long maxWidth, 294 in long maxHeight, 295 in long prefWidth, 296 out long width, 297 out long height); 298 299 %{C++ 300 mozilla::Maybe<mozilla::CSSIntSize> GetContentSize(int32_t aMaxWidth = 0, int32_t aMaxHeight = 0, int32_t aPrefWidth = 0) { 301 int32_t w = 0; 302 int32_t h = 0; 303 if (NS_SUCCEEDED(GetContentSize(aMaxWidth, aMaxHeight, aPrefWidth, &w, &h))) { 304 return mozilla::Some(mozilla::CSSIntSize(w, h)); 305 } 306 return mozilla::Nothing(); 307 } 308 %} 309 310 [noscript, notxpcom] Encoding getReloadEncodingAndSource(out int32_t aSource); 311 [noscript, notxpcom] void setReloadEncodingAndSource(in Encoding aEncoding, in int32_t aSource); 312 [noscript, notxpcom] void forgetReloadEncoding(); 313 }; 314 315 %{C++ 316 namespace mozilla { 317 namespace dom { 318 319 using XPCOMPermitUnloadAction = nsIDocumentViewer::PermitUnloadAction; 320 using PermitUnloadResult = nsIDocumentViewer::PermitUnloadResult; 321 322 } // namespace dom 323 } // namespace mozilla 324 %}