| 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 "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class RenderFrameHost; | 15 class RenderFrameHost; |
| 16 class WebContents; | 16 class WebContents; |
| 17 struct Manifest; | 17 struct Manifest; |
| 18 | 18 |
| 19 // ManifestManagerHost is a helper class that allows callers to get the Manifest | 19 // 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. | 20 // 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. | 21 // TODO(mlamouri): keep a cached version and a dirty bit here. |
| 22 class ManifestManagerHost : public WebContentsObserver { | 22 class ManifestManagerHost : public WebContentsObserver { |
| 23 public: | 23 public: |
| 24 explicit ManifestManagerHost(WebContents* web_contents); | 24 explicit ManifestManagerHost(WebContents* web_contents); |
| 25 ~ManifestManagerHost() override; | 25 ~ManifestManagerHost() override; |
| 26 | 26 |
| 27 using GetManifestCallback = base::Callback<void(const Manifest&)>; | 27 using GetManifestCallback = |
| 28 base::Callback<void(const GURL&, const Manifest&)>; |
| 28 using HasManifestCallback = base::Callback<void(bool)>; | 29 using HasManifestCallback = base::Callback<void(bool)>; |
| 29 | 30 |
| 30 // Calls the given callback with the manifest associated with the | 31 // Calls the given callback with the manifest associated with the |
| 31 // given RenderFrameHost. If the frame has no manifest or if getting it failed | 32 // given RenderFrameHost. If the frame has no manifest or if getting it failed |
| 32 // the callback will have an empty manifest. | 33 // the callback will have an empty manifest. |
| 33 void GetManifest(RenderFrameHost*, const GetManifestCallback&); | 34 void GetManifest(RenderFrameHost*, const GetManifestCallback&); |
| 34 | 35 |
| 35 // Calls the given callback with a bool indicating whether or not the document | 36 // Calls the given callback with a bool indicating whether or not the document |
| 36 // associated with the given RenderFrameHost has a manifest. | 37 // associated with the given RenderFrameHost has a manifest. |
| 37 void HasManifest(RenderFrameHost*, const HasManifestCallback&); | 38 void HasManifest(RenderFrameHost*, const HasManifestCallback&); |
| 38 | 39 |
| 39 // WebContentsObserver | 40 // WebContentsObserver |
| 40 bool OnMessageReceived(const IPC::Message&, RenderFrameHost*) override; | 41 bool OnMessageReceived(const IPC::Message&, RenderFrameHost*) override; |
| 41 void RenderFrameDeleted(RenderFrameHost*) override; | 42 void RenderFrameDeleted(RenderFrameHost*) override; |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 using GetCallbackMap = IDMap<GetManifestCallback, IDMapOwnPointer>; | 45 using GetCallbackMap = IDMap<GetManifestCallback, IDMapOwnPointer>; |
| 45 using HasCallbackMap = IDMap<HasManifestCallback, IDMapOwnPointer>; | 46 using HasCallbackMap = IDMap<HasManifestCallback, IDMapOwnPointer>; |
| 46 using FrameGetCallbackMap = base::hash_map<RenderFrameHost*, GetCallbackMap*>; | 47 using FrameGetCallbackMap = base::hash_map<RenderFrameHost*, GetCallbackMap*>; |
| 47 using FrameHasCallbackMap = base::hash_map<RenderFrameHost*, HasCallbackMap*>; | 48 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 GURL&, 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 // Returns the CallbackMap associated with the given RenderFrameHost, or null. |
| 55 GetCallbackMap* GetCallbackMapForFrame(RenderFrameHost*); | 56 GetCallbackMap* GetCallbackMapForFrame(RenderFrameHost*); |
| 56 HasCallbackMap* HasCallbackMapForFrame(RenderFrameHost*); | 57 HasCallbackMap* HasCallbackMapForFrame(RenderFrameHost*); |
| 57 | 58 |
| 58 FrameGetCallbackMap pending_get_callbacks_; | 59 FrameGetCallbackMap pending_get_callbacks_; |
| 59 FrameHasCallbackMap pending_has_callbacks_; | 60 FrameHasCallbackMap pending_has_callbacks_; |
| 60 | 61 |
| 61 DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost); | 62 DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 } // namespace content | 65 } // namespace content |
| 65 | 66 |
| 66 #endif // CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ | 67 #endif // CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ |
| OLD | NEW |