Skip to content

Commit

Permalink
feat: Exposing methods required by capturing a hidden webContents (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeker999 committed Mar 23, 2020
1 parent a80f7fc commit 8e30e21
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/api/web-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,25 @@ Returns `Promise<NativeImage>` - Resolves with a [NativeImage](native-image.md)

Captures a snapshot of the page within `rect`. Omitting `rect` will capture the whole visible page.

#### `contents.isBeingCaptured()`

Returns `Boolean` - Whether this page is being captured. It returns true when the capturer count
is large then 0.

#### `contents.incrementCapturerCount([size])`

* `size` [Size](structures/size.md) (optional) - The perferred size for the capturer.

Increase the capturer count by one. The page is considered visible when its browser window is
hidden and the capturer count is non-zero.

This also affects the Page Visibility API.

#### `contents.decrementCapturerCount()`

Decrease the capturer count by one. The page will be set to hidden or occluded state when its
browser window is hidden or occluded and the capturer count reaches zero.

#### `contents.getPrinters()`

Get the system printer list.
Expand Down
20 changes: 20 additions & 0 deletions shell/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,23 @@ v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* args) {
return handle;
}

void WebContents::IncrementCapturerCount(mate::Arguments* args) {
gfx::Size size;

// get size arguments if they exist
args->GetNext(&size);

web_contents()->IncrementCapturerCount(size);
}

void WebContents::DecrementCapturerCount(mate::Arguments* args) {
web_contents()->DecrementCapturerCount();
}

bool WebContents::IsBeingCaptured() {
return web_contents()->IsBeingCaptured();
}

void WebContents::OnCursorChange(const content::WebCursor& cursor) {
const content::CursorInfo& info = cursor.info();

Expand Down Expand Up @@ -2598,6 +2615,9 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setEmbedder", &WebContents::SetEmbedder)
.SetMethod("setDevToolsWebContents", &WebContents::SetDevToolsWebContents)
.SetMethod("getNativeView", &WebContents::GetNativeView)
.SetMethod("incrementCapturerCount", &WebContents::IncrementCapturerCount)
.SetMethod("decrementCapturerCount", &WebContents::DecrementCapturerCount)
.SetMethod("isBeingCaptured", &WebContents::IsBeingCaptured)
.SetMethod("setWebRTCIPHandlingPolicy",
&WebContents::SetWebRTCIPHandlingPolicy)
.SetMethod("getWebRTCIPHandlingPolicy",
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
void SetEmbedder(const WebContents* embedder);
void SetDevToolsWebContents(const WebContents* devtools);
v8::Local<v8::Value> GetNativeView() const;
void IncrementCapturerCount(mate::Arguments* args);
void DecrementCapturerCount(mate::Arguments* args);
bool IsBeingCaptured();

#if BUILDFLAG(ENABLE_PRINTING)
void OnGetDefaultPrinter(base::DictionaryValue print_settings,
Expand Down

0 comments on commit 8e30e21

Please sign in to comment.