Chromium Code Reviews| Index: third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp |
| diff --git a/third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp b/third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..70b2dfd5f90f191d13317c32b67d6611adfe7251 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/installedapp/InstalledAppController.h" |
| + |
| +#include "core/frame/LocalFrame.h" |
| +#include "platform/RuntimeEnabledFeatures.h" |
| +#include "public/platform/WebSecurityOrigin.h" |
| + |
| +namespace blink { |
| + |
| +InstalledAppController::~InstalledAppController() |
| +{ |
| +} |
| + |
| +void InstalledAppController::provideTo(LocalFrame& frame, WebInstalledApp* client) |
| +{ |
| + ASSERT(RuntimeEnabledFeatures::installedAppEnabled()); |
| + |
| + InstalledAppController* controller = new InstalledAppController(frame, client); |
| + WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPtrWillBeNoop(controller)); |
|
haraken
2016/02/27 15:53:11
OwnPtr<InstalledAppController> controllers = adopt
Daniel Nishi
2016/02/29 18:38:38
.release() for an OwnPtr is an OwnPtr, whereas pro
|
| +} |
| + |
| +InstalledAppController* InstalledAppController::from(LocalFrame& frame) |
| +{ |
| + return static_cast<InstalledAppController*>(WillBeHeapSupplement<LocalFrame>::from(frame, supplementName())); |
|
haraken
2016/02/27 15:53:11
Can we add an assert to check that the returned In
Daniel Nishi
2016/02/29 18:38:39
Done.
|
| +} |
| + |
| +InstalledAppController::InstalledAppController(LocalFrame& frame, WebInstalledApp* client) |
| + : LocalFrameLifecycleObserver(&frame) |
| + , m_client(client) |
| +{ |
| +} |
| + |
| +const char* InstalledAppController::supplementName() |
| +{ |
| + return "InstalledAppController"; |
| +} |
| + |
| +void InstalledAppController::getInstalledApps(const WebSecurityOrigin& url, AppInstalledCallbacks* callback) |
| +{ |
| + // When detached, the client is no longer valid. |
| + if (!m_client) { |
| + callback->onError(); |
| + delete callback; |
|
haraken
2016/02/27 15:53:11
It's really nasty to call delete manually... Can w
Daniel Nishi
2016/02/29 18:38:38
Done.
|
| + return; |
| + } |
| + |
| + // Client is expected to take ownership of the callback |
| + m_client->getInstalledRelatedApps(url, callback); |
| +} |
| + |
| +void InstalledAppController::willDetachFrameHost() |
| +{ |
| + m_client = nullptr; |
| +} |
| + |
| +DEFINE_TRACE(InstalledAppController) |
| +{ |
| + WillBeHeapSupplement<LocalFrame>::trace(visitor); |
| + LocalFrameLifecycleObserver::trace(visitor); |
| +} |
| + |
| +} // namespace blink |