| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ |
| 6 #define CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ | 6 #define CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 |
| 8 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 9 #include "base/id_map.h" | |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "third_party/WebKit/public/platform/modules/manifest/manifest_manager.m
ojom.h" |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 | 17 |
| 15 class RenderFrameHost; | 18 class RenderFrameHost; |
| 16 class WebContents; | 19 class WebContents; |
| 17 struct Manifest; | 20 struct Manifest; |
| 18 | 21 |
| 19 // ManifestManagerHost is a helper class that allows callers to get the Manifest | 22 // ManifestManagerHost is a helper class that allows callers to get the Manifest |
| 20 // associated with a frame. It handles the IPC messaging with the child process. | 23 // associated with a frame. It handles the IPC messaging with the child process. |
| 21 // TODO(mlamouri): keep a cached version and a dirty bit here. | 24 // TODO(mlamouri): keep a cached version and a dirty bit here. |
| 22 class ManifestManagerHost : public WebContentsObserver { | 25 class ManifestManagerHost : public WebContentsObserver { |
| 23 public: | 26 public: |
| 24 explicit ManifestManagerHost(WebContents* web_contents); | 27 explicit ManifestManagerHost(WebContents* web_contents); |
| 25 ~ManifestManagerHost() override; | 28 ~ManifestManagerHost() override; |
| 26 | 29 |
| 27 using GetManifestCallback = base::Callback<void(const Manifest&)>; | 30 using GetManifestCallback = base::Callback<void(const Manifest&)>; |
| 28 using HasManifestCallback = base::Callback<void(bool)>; | 31 using HasManifestCallback = base::Callback<void(bool)>; |
| 29 | 32 |
| 30 // Calls the given callback with the manifest associated with the | 33 // Calls the given callback with the manifest associated with the |
| 31 // given RenderFrameHost. If the frame has no manifest or if getting it failed | 34 // given RenderFrameHost. If the frame has no manifest or if getting it failed |
| 32 // the callback will have an empty manifest. | 35 // the callback will have an empty manifest. |
| 33 void GetManifest(RenderFrameHost*, const GetManifestCallback&); | 36 void GetManifest(RenderFrameHost* render_frame_host, |
| 37 const GetManifestCallback& callback); |
| 34 | 38 |
| 35 // Calls the given callback with a bool indicating whether or not the document | 39 // Calls the given callback with a bool indicating whether or not the document |
| 36 // associated with the given RenderFrameHost has a manifest. | 40 // associated with the given RenderFrameHost has a manifest. |
| 37 void HasManifest(RenderFrameHost*, const HasManifestCallback&); | 41 void HasManifest(RenderFrameHost* render_frame_host, |
| 42 const HasManifestCallback& callback); |
| 38 | 43 |
| 39 // WebContentsObserver | 44 // WebContentsObserver |
| 40 bool OnMessageReceived(const IPC::Message&, RenderFrameHost*) override; | 45 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 41 void RenderFrameDeleted(RenderFrameHost*) override; | |
| 42 | 46 |
| 43 private: | 47 private: |
| 44 using GetCallbackMap = IDMap<GetManifestCallback, IDMapOwnPointer>; | 48 class FrameManifestManagerHost; |
| 45 using HasCallbackMap = IDMap<HasManifestCallback, IDMapOwnPointer>; | |
| 46 using FrameGetCallbackMap = base::hash_map<RenderFrameHost*, GetCallbackMap*>; | |
| 47 using FrameHasCallbackMap = base::hash_map<RenderFrameHost*, HasCallbackMap*>; | |
| 48 | 49 |
| 49 void OnRequestManifestResponse( | 50 void OnRequestManifestResponse( |
| 50 RenderFrameHost*, int request_id, const Manifest&); | 51 RenderFrameHost*, int request_id, const Manifest&); |
| 51 void OnHasManifestResponse( | 52 void OnHasManifestResponse( |
| 52 RenderFrameHost*, int request_id, bool); | 53 RenderFrameHost*, int request_id, bool); |
| 53 | 54 |
| 54 // Returns the CallbackMap associated with the given RenderFrameHost, or null. | 55 FrameManifestManagerHost& GetOrCreateHostForFrame( |
| 55 GetCallbackMap* GetCallbackMapForFrame(RenderFrameHost*); | 56 RenderFrameHost* render_frame_host); |
| 56 HasCallbackMap* HasCallbackMapForFrame(RenderFrameHost*); | |
| 57 | 57 |
| 58 FrameGetCallbackMap pending_get_callbacks_; | 58 std::map<RenderFrameHost*, std::unique_ptr<FrameManifestManagerHost>> hosts_; |
| 59 FrameHasCallbackMap pending_has_callbacks_; | |
| 60 | 59 |
| 61 DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost); | 60 DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost); |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 } // namespace content | 63 } // namespace content |
| 65 | 64 |
| 66 #endif // CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ | 65 #endif // CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ |
| OLD | NEW |