Merge pull request #1535 from deepak1556/contents_patch
webContents: adding serviceworker helper utilities
This commit is contained in:
commit
9300859983
3 changed files with 60 additions and 0 deletions
|
@ -28,8 +28,11 @@
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
#include "content/public/browser/render_widget_host_view.h"
|
#include "content/public/browser/render_widget_host_view.h"
|
||||||
#include "content/public/browser/resource_request_details.h"
|
#include "content/public/browser/resource_request_details.h"
|
||||||
|
#include "content/public/browser/service_worker_context.h"
|
||||||
|
#include "content/public/browser/storage_partition.h"
|
||||||
#include "content/public/browser/site_instance.h"
|
#include "content/public/browser/site_instance.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
#include "native_mate/callback.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
|
||||||
|
@ -54,6 +57,22 @@ NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content::ServiceWorkerContext* GetServiceWorkerContext(
|
||||||
|
const content::WebContents* web_contents) {
|
||||||
|
auto context = web_contents->GetBrowserContext();
|
||||||
|
auto site_instance = web_contents->GetSiteInstance();
|
||||||
|
if (!context || !site_instance)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
content::StoragePartition* storage_partition =
|
||||||
|
content::BrowserContext::GetStoragePartition(
|
||||||
|
context, site_instance);
|
||||||
|
|
||||||
|
DCHECK(storage_partition);
|
||||||
|
|
||||||
|
return storage_partition->GetServiceWorkerContext();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
WebContents::WebContents(content::WebContents* web_contents)
|
WebContents::WebContents(content::WebContents* web_contents)
|
||||||
|
@ -565,6 +584,27 @@ void WebContents::SetAllowTransparency(bool allow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::HasServiceWorker(
|
||||||
|
const base::Callback<void(bool)>& callback) {
|
||||||
|
auto context = GetServiceWorkerContext(web_contents());
|
||||||
|
if (!context)
|
||||||
|
return;
|
||||||
|
|
||||||
|
context->CheckHasServiceWorker(web_contents()->GetLastCommittedURL(),
|
||||||
|
GURL::EmptyGURL(),
|
||||||
|
callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContents::UnregisterServiceWorker(
|
||||||
|
const base::Callback<void(bool)>& callback) {
|
||||||
|
auto context = GetServiceWorkerContext(web_contents());
|
||||||
|
if (!context)
|
||||||
|
return;
|
||||||
|
|
||||||
|
context->UnregisterServiceWorker(web_contents()->GetLastCommittedURL(),
|
||||||
|
callback);
|
||||||
|
}
|
||||||
|
|
||||||
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
v8::Isolate* isolate) {
|
v8::Isolate* isolate) {
|
||||||
if (template_.IsEmpty())
|
if (template_.IsEmpty())
|
||||||
|
@ -602,6 +642,9 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
.SetMethod("setAutoSize", &WebContents::SetAutoSize)
|
.SetMethod("setAutoSize", &WebContents::SetAutoSize)
|
||||||
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
||||||
.SetMethod("isGuest", &WebContents::is_guest)
|
.SetMethod("isGuest", &WebContents::is_guest)
|
||||||
|
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
|
||||||
|
.SetMethod("unregisterServiceWorker",
|
||||||
|
&WebContents::UnregisterServiceWorker)
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
return mate::ObjectTemplateBuilder(
|
return mate::ObjectTemplateBuilder(
|
||||||
|
|
|
@ -64,6 +64,8 @@ class WebContents : public mate::EventEmitter,
|
||||||
void CloseDevTools();
|
void CloseDevTools();
|
||||||
bool IsDevToolsOpened();
|
bool IsDevToolsOpened();
|
||||||
void InspectElement(int x, int y);
|
void InspectElement(int x, int y);
|
||||||
|
void HasServiceWorker(const base::Callback<void(bool)>&);
|
||||||
|
void UnregisterServiceWorker(const base::Callback<void(bool)>&);
|
||||||
|
|
||||||
// Editing commands.
|
// Editing commands.
|
||||||
void Undo();
|
void Undo();
|
||||||
|
|
|
@ -852,6 +852,21 @@ Executes editing command `replace` in page.
|
||||||
|
|
||||||
Executes editing command `replaceMisspelling` in page.
|
Executes editing command `replaceMisspelling` in page.
|
||||||
|
|
||||||
|
### WebContents.hasServiceWorker(callback)
|
||||||
|
|
||||||
|
* `callback` Function
|
||||||
|
|
||||||
|
Checks if any serviceworker is registered and returns boolean as
|
||||||
|
response to `callback`.
|
||||||
|
|
||||||
|
### WebContents.unregisterServiceWorker(callback)
|
||||||
|
|
||||||
|
* `callback` Function
|
||||||
|
|
||||||
|
Unregisters any serviceworker if present and returns boolean as
|
||||||
|
response to `callback` when the JS promise is fullfilled or false
|
||||||
|
when the JS promise is rejected.
|
||||||
|
|
||||||
### WebContents.send(channel[, args...])
|
### WebContents.send(channel[, args...])
|
||||||
|
|
||||||
* `channel` String
|
* `channel` String
|
||||||
|
|
Loading…
Reference in a new issue