| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NotificationResourcesLoader_h | 5 #ifndef NotificationResourcesLoader_h |
| 6 #define NotificationResourcesLoader_h | 6 #define NotificationResourcesLoader_h |
| 7 | 7 |
| 8 #include "modules/ModulesExport.h" | 8 #include "modules/ModulesExport.h" |
| 9 #include "modules/notifications/NotificationImageLoader.h" | 9 #include "modules/notifications/NotificationImageLoader.h" |
| 10 #include "platform/heap/GarbageCollected.h" | 10 #include "platform/heap/GarbageCollected.h" |
| 11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 12 #include "platform/heap/HeapAllocator.h" | 12 #include "platform/heap/HeapAllocator.h" |
| 13 #include "platform/heap/ThreadState.h" | 13 #include "platform/heap/ThreadState.h" |
| 14 #include "public/platform/modules/notifications/notification.mojom-blink.h" |
| 15 #include "public/platform/modules/notifications/notification_resources.mojom-bli
nk.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "wtf/Functional.h" | 17 #include "wtf/Functional.h" |
| 16 #include "wtf/OwnPtr.h" | 18 #include "wtf/OwnPtr.h" |
| 17 #include "wtf/PassOwnPtr.h" | 19 #include "wtf/PassOwnPtr.h" |
| 18 #include "wtf/Vector.h" | 20 #include "wtf/Vector.h" |
| 19 #include <memory> | |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| 23 class ExecutionContext; | 24 class ExecutionContext; |
| 24 struct WebNotificationData; | |
| 25 struct WebNotificationResources; | |
| 26 | 25 |
| 27 // Fetches the resources specified in a given WebNotificationData. Uses a | 26 // Fetches the resources specified in a given notification. Uses a callback to |
| 28 // callback to notify the caller when all fetches have finished. | 27 // notify the caller when all fetches have finished. |
| 29 class MODULES_EXPORT NotificationResourcesLoader final : public GarbageCollected
Finalized<NotificationResourcesLoader> { | 28 class MODULES_EXPORT NotificationResourcesLoader final : public GarbageCollected
Finalized<NotificationResourcesLoader> { |
| 30 USING_PRE_FINALIZER(NotificationResourcesLoader, stop); | 29 USING_PRE_FINALIZER(NotificationResourcesLoader, stop); |
| 31 public: | 30 public: |
| 32 // Called when all fetches have finished. Passes a pointer to the | 31 // Called when all fetches have finished. Passes a pointer to the loader so |
| 33 // NotificationResourcesLoader so callers that use multiple loaders can use | 32 // that callers having multiple loaders can distinguish them, as well as the |
| 34 // the same function to handle the callbacks. | 33 // notification for which resources have been loaded. |
| 35 using CompletionCallback = Function<void(NotificationResourcesLoader*)>; | 34 using CompletionCallback = Function<void(NotificationResourcesLoader*, mojom
::blink::NotificationPtr)>; |
| 36 | 35 |
| 37 explicit NotificationResourcesLoader(PassOwnPtr<CompletionCallback>); | 36 explicit NotificationResourcesLoader(PassOwnPtr<CompletionCallback>); |
| 38 ~NotificationResourcesLoader(); | 37 ~NotificationResourcesLoader(); |
| 39 | 38 |
| 40 // Starts fetching the resources specified in the given WebNotificationData. | 39 // Starts fetching the resources specified in the given notification. If all |
| 41 // If all the urls for the resources are empty or invalid, | 40 // the urls for the resources are empty or invalid, |m_completionCallback| |
| 42 // |m_completionCallback| will be run synchronously, otherwise it will be | 41 // will be run synchronously, otherwise it will be run asynchronously when |
| 43 // run asynchronously when all fetches have finished. Should not be called | 42 // all fetches have finished. Should not be called more than once. |
| 44 // more than once. | 43 void start(ExecutionContext*, mojom::blink::NotificationPtr notification); |
| 45 void start(ExecutionContext*, const WebNotificationData&); | |
| 46 | 44 |
| 47 // Returns a new WebNotificationResources populated with the resources that | 45 // Returns a new Mojo NotificationResources object populated with the |
| 48 // have been fetched. | 46 // resources that have been fetched. |
| 49 std::unique_ptr<WebNotificationResources> getResources() const; | 47 mojom::blink::NotificationResourcesPtr getResources() const; |
| 50 | 48 |
| 51 // Stops every loader in |m_imageLoaders|. This is also used as the | 49 // Stops every loader in |m_imageLoaders|. This is also used as the |
| 52 // pre-finalizer. | 50 // pre-finalizer. |
| 53 void stop(); | 51 void stop(); |
| 54 | 52 |
| 55 DECLARE_VIRTUAL_TRACE(); | 53 DECLARE_VIRTUAL_TRACE(); |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 void loadImage(ExecutionContext*, const KURL&, PassOwnPtr<NotificationImageL
oader::ImageCallback>); | 56 void loadImage(ExecutionContext*, const KURL&, PassOwnPtr<NotificationImageL
oader::ImageCallback>); |
| 59 void didLoadIcon(const SkBitmap& image); | 57 void didLoadIcon(const SkBitmap& image); |
| 60 void didLoadBadge(const SkBitmap& image); | 58 void didLoadBadge(const SkBitmap& image); |
| 61 void didLoadActionIcon(size_t actionIndex, const SkBitmap& image); | 59 void didLoadActionIcon(size_t actionIndex, const SkBitmap& image); |
| 62 | 60 |
| 63 // Decrements |m_pendingRequestCount| and runs |m_completionCallback| if | 61 // Decrements |m_pendingRequestCount| and runs |m_completionCallback| if |
| 64 // there are no more pending requests. | 62 // there are no more pending requests. |
| 65 void didFinishRequest(); | 63 void didFinishRequest(); |
| 66 | 64 |
| 67 bool m_started; | 65 // The notification for which resources are being loaded. |
| 66 mojom::blink::NotificationPtr m_notification; |
| 67 |
| 68 OwnPtr<CompletionCallback> m_completionCallback; | 68 OwnPtr<CompletionCallback> m_completionCallback; |
| 69 int m_pendingRequestCount; | 69 int m_pendingRequestCount; |
| 70 HeapVector<Member<NotificationImageLoader>> m_imageLoaders; | 70 HeapVector<Member<NotificationImageLoader>> m_imageLoaders; |
| 71 SkBitmap m_icon; | 71 SkBitmap m_icon; |
| 72 SkBitmap m_badge; | 72 SkBitmap m_badge; |
| 73 Vector<SkBitmap> m_actionIcons; | 73 Vector<SkBitmap> m_actionIcons; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace blink | 76 } // namespace blink |
| 77 | 77 |
| 78 #endif // NotificationResourcesLoader_h | 78 #endif // NotificationResourcesLoader_h |
| OLD | NEW |