Bug 1475139 part 12 - Expose drawSnapshot API to <browser>. r=nika

This commit initially exposes the drawSnapshot API off of <browser>. This
is done by adding a WebIDL binding to FrameLoader and wrapping it in
browser.xml.

Differential Revision: https://phabricator.services.mozilla.com/D6791

--HG--
extra : rebase_source : 9f819b13c102edf42ab2bb2466578751a7a2f647
This commit is contained in:
Ryan Hunt 2018-09-24 21:48:30 -05:00
Родитель 84bbf4f7d0
Коммит 3bb8e3eca9
4 изменённых файлов: 112 добавлений и 0 удалений

Просмотреть файл

@ -80,8 +80,11 @@
#include "mozilla/dom/ChromeMessageSender.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/FrameLoaderBinding.h"
#include "mozilla/gfx/CrossProcessPaint.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "mozilla/layout/RenderFrameParent.h"
#include "mozilla/ServoCSSParser.h"
#include "mozilla/ServoStyleSet.h"
#include "nsGenericHTMLFrameElement.h"
#include "GeckoProfiler.h"
@ -3103,6 +3106,64 @@ nsFrameLoader::Print(uint64_t aOuterWindowID,
#endif
}
already_AddRefed<mozilla::dom::Promise>
nsFrameLoader::DrawSnapshot(double aX,
double aY,
double aW,
double aH,
double aScale,
const nsAString& aBackgroundColor,
mozilla::ErrorResult& aRv)
{
RefPtr<nsIGlobalObject> global = GetOwnerContent()->GetOwnerGlobal();
RefPtr<Promise> promise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<nsIDocument> document = GetOwnerContent()->GetOwnerDocument();
if (NS_WARN_IF(!document)) {
aRv = NS_ERROR_FAILURE;
return nullptr;
}
nsIPresShell* presShell = document->GetShell();
if (NS_WARN_IF(!presShell)) {
aRv = NS_ERROR_FAILURE;
return nullptr;
}
nscolor color;
css::Loader* loader = document->CSSLoader();
ServoStyleSet* set = presShell->StyleSet();
if (NS_WARN_IF(!ServoCSSParser::ComputeColor(set,
NS_RGB(0, 0, 0),
aBackgroundColor,
&color,
nullptr,
loader))) {
aRv = NS_ERROR_FAILURE;
return nullptr;
}
gfx::IntRect rect = gfx::IntRect::RoundOut(gfx::Rect(aX, aY, aW, aH));
if (IsRemoteFrame()) {
gfx::CrossProcessPaint::StartRemote(mRemoteBrowser->GetTabId(),
rect,
aScale,
color,
promise);
} else {
gfx::CrossProcessPaint::StartLocal(mDocShell,
rect,
aScale,
color,
promise);
}
return promise.forget();
}
already_AddRefed<nsITabParent>
nsFrameLoader::GetTabParent()
{

Просмотреть файл

@ -171,6 +171,15 @@ public:
nsIWebProgressListener* aProgressListener,
mozilla::ErrorResult& aRv);
already_AddRefed<mozilla::dom::Promise>
DrawSnapshot(double aX,
double aY,
double aW,
double aH,
double aScale,
const nsAString& aBackgroundColor,
mozilla::ErrorResult& aRv);
void StartPersistence(uint64_t aOuterWindowID,
nsIWebBrowserPersistDocumentReceiver* aRecv,
mozilla::ErrorResult& aRv);

Просмотреть файл

@ -108,6 +108,30 @@ interface FrameLoader {
nsIPrintSettings aPrintSettings,
optional nsIWebProgressListener? aProgressListener = null);
/**
* Renders a region of the frame into an image bitmap.
*
* @param x
* @param y
* @param w
* @param h Specify the area of the window to render, in CSS
* pixels. This is relative to the current scroll position.
* @param scale The scale to render the window at. Use devicePixelRatio
* to have comparable rendering to the OS.
* @param backgroundColor The background color to use.
*
* This API can only be used in the parent process, as content processes
* cannot access the rendering of out of process iframes. This API works
* with remote and local frames.
*/
[Throws]
Promise<ImageBitmap> drawSnapshot(double x,
double y,
double w,
double h,
double scale,
DOMString backgroundColor);
/**
* If false, then the subdocument is not clipped to its CSS viewport, and the
* subdocument's viewport scrollbar(s) are not rendered.

Просмотреть файл

@ -1904,6 +1904,24 @@
</body>
</method>
<method name="drawSnapshot">
<parameter name="x"/>
<parameter name="y"/>
<parameter name="w"/>
<parameter name="h"/>
<parameter name="scale"/>
<parameter name="backgroundColor"/>
<body>
<![CDATA[
if (!this.frameLoader) {
throw Components.Exception("No frame loader.",
Cr.NS_ERROR_FAILURE);
}
return this.frameLoader.drawSnapshot(x, y, w, h, scale, backgroundColor);
]]>
</body>
</method>
<method name="dropLinks">
<parameter name="aLinksCount"/>
<parameter name="aLinks"/>