Index: Source/modules/permissions/PermissionStatus.cpp |
diff --git a/Source/modules/permissions/PermissionStatus.cpp b/Source/modules/permissions/PermissionStatus.cpp |
index 0441f3688fa91ea8c640a306ca3e7e4afab024d8..c3e41baa628cebad48bbed3ef052838c8d9e5dcb 100644 |
--- a/Source/modules/permissions/PermissionStatus.cpp |
+++ b/Source/modules/permissions/PermissionStatus.cpp |
@@ -6,14 +6,37 @@ |
#include "modules/permissions/PermissionStatus.h" |
#include "bindings/core/v8/ScriptPromiseResolver.h" |
+#include "core/dom/Document.h" |
+#include "core/events/Event.h" |
#include "modules/EventTargetModulesNames.h" |
+#include "modules/permissions/PermissionController.h" |
+#include "public/platform/Platform.h" |
+#include "public/platform/modules/permissions/WebPermissionClient.h" |
namespace blink { |
+namespace { |
+ |
+// TODO(mlamouri): move that to a common place. |
Miguel Garcia
2015/04/01 17:41:50
nit: move *this*
mlamouri (slow - plz ping)
2015/04/01 17:53:10
Done.
|
+WebPermissionClient* permissionClient(ExecutionContext* executionContext) |
+{ |
+ if (executionContext->isDocument()) { |
Miguel Garcia
2015/04/01 17:41:51
this might sound stupid but why do we have two pos
mlamouri (slow - plz ping)
2015/04/01 17:53:10
The client associated with the frame will talk to
|
+ Document* document = toDocument(executionContext); |
+ if (!document->frame()) |
+ return nullptr; |
+ PermissionController* controller = PermissionController::from(*document->frame()); |
+ return controller ? controller->client() : nullptr; |
+ } |
+ return Platform::current()->permissionClient(); |
+} |
+ |
+} // anonymous namespace |
+ |
// static |
PermissionStatus* PermissionStatus::take(ScriptPromiseResolver* resolver, WebPermissionStatus* status, WebPermissionType type) |
{ |
- PermissionStatus* permissionStatus = new PermissionStatus(resolver->executionContext(), *status); |
+ PermissionStatus* permissionStatus = PermissionStatus::create(resolver->executionContext(), *status, type); |
+ permissionStatus->startListening(); |
delete status; |
return permissionStatus; |
} |
@@ -24,14 +47,25 @@ void PermissionStatus::dispose(WebPermissionStatus* status) |
delete status; |
} |
-PermissionStatus::PermissionStatus(ExecutionContext* executionContext, WebPermissionStatus status) |
- : ContextLifecycleObserver(executionContext) |
+PermissionStatus* PermissionStatus::create(ExecutionContext* executionContext, WebPermissionStatus status, WebPermissionType type) |
+{ |
+ PermissionStatus* permissionStatus = new PermissionStatus(executionContext, status, type); |
+ permissionStatus->suspendIfNeeded(); |
+ return permissionStatus; |
+} |
+ |
+PermissionStatus::PermissionStatus(ExecutionContext* executionContext, WebPermissionStatus status, WebPermissionType type) |
+ : ActiveDOMObject(executionContext) |
, m_status(status) |
+ , m_type(type) |
+ , m_listening(false) |
{ |
} |
PermissionStatus::~PermissionStatus() |
{ |
+ if (m_listening) |
+ stopListening(); |
} |
const AtomicString& PermissionStatus::interfaceName() const |
@@ -41,13 +75,60 @@ const AtomicString& PermissionStatus::interfaceName() const |
ExecutionContext* PermissionStatus::executionContext() const |
{ |
- return ContextLifecycleObserver::executionContext(); |
+ return ActiveDOMObject::executionContext(); |
} |
-DEFINE_TRACE(PermissionStatus) |
+void PermissionStatus::permissionChanged(WebPermissionType type, WebPermissionStatus status) |
{ |
- RefCountedGarbageCollectedEventTargetWithInlineData<PermissionStatus>::trace(visitor); |
- ContextLifecycleObserver::trace(visitor); |
+ ASSERT(m_type == type); |
+ if (m_status == status) |
+ return; |
+ |
+ m_status = status; |
+ dispatchEvent(Event::create(EventTypeNames::change)); |
+} |
+ |
+bool PermissionStatus::hasPendingActivity() const |
+{ |
+ return m_listening; |
+} |
+ |
+void PermissionStatus::resume() |
+{ |
+ startListening(); |
+} |
+ |
+void PermissionStatus::suspend() |
+{ |
+ stopListening(); |
+} |
+ |
+void PermissionStatus::stop() |
+{ |
+ stopListening(); |
+} |
+ |
+void PermissionStatus::startListening() |
+{ |
+ ASSERT(!m_listening); |
+ |
+ WebPermissionClient* client = permissionClient(executionContext()); |
+ if (!client) |
+ return; |
+ m_listening = true; |
+ client->startListening(m_type, KURL(KURL(), executionContext()->securityOrigin()->toString()), this); |
+} |
+ |
+void PermissionStatus::stopListening() |
+{ |
+ ASSERT(m_listening); |
+ ASSERT(executionContext()); |
+ |
+ m_listening = false; |
+ WebPermissionClient* client = permissionClient(executionContext()); |
+ if (!client) |
+ return; |
+ client->stopListening(this); |
} |
String PermissionStatus::status() const |
@@ -65,4 +146,10 @@ String PermissionStatus::status() const |
return "denied"; |
} |
+DEFINE_TRACE(PermissionStatus) |
+{ |
+ RefCountedGarbageCollectedEventTargetWithInlineData<PermissionStatus>::trace(visitor); |
+ ActiveDOMObject::trace(visitor); |
+} |
+ |
} // namespace blink |