| 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 = | 27 using GetManifestCallback = |
| 28 base::Callback<void(const GURL&, const Manifest&)>; | 28 base::Callback<void(const GURL&, const Manifest&)>; |
| 29 using HasManifestCallback = base::Callback<void(bool)>; | |
| 30 | 29 |
| 31 // Calls the given callback with the manifest associated with the | 30 // Calls the given callback with the manifest associated with the |
| 32 // given RenderFrameHost. If the frame has no manifest or if getting it failed | 31 // given RenderFrameHost. If the frame has no manifest or if getting it failed |
| 33 // the callback will have an empty manifest. | 32 // the callback will have an empty manifest. |
| 34 void GetManifest(RenderFrameHost*, const GetManifestCallback&); | 33 void GetManifest(RenderFrameHost*, const GetManifestCallback&); |
| 35 | 34 |
| 36 // Calls the given callback with a bool indicating whether or not the document | |
| 37 // associated with the given RenderFrameHost has a manifest. | |
| 38 void HasManifest(RenderFrameHost*, const HasManifestCallback&); | |
| 39 | |
| 40 // WebContentsObserver | 35 // WebContentsObserver |
| 41 bool OnMessageReceived(const IPC::Message&, RenderFrameHost*) override; | 36 bool OnMessageReceived(const IPC::Message&, RenderFrameHost*) override; |
| 42 void RenderFrameDeleted(RenderFrameHost*) override; | 37 void RenderFrameDeleted(RenderFrameHost*) override; |
| 43 | 38 |
| 44 private: | 39 private: |
| 45 using GetCallbackMap = IDMap<GetManifestCallback, IDMapOwnPointer>; | 40 using GetCallbackMap = IDMap<GetManifestCallback, IDMapOwnPointer>; |
| 46 using HasCallbackMap = IDMap<HasManifestCallback, IDMapOwnPointer>; | |
| 47 using FrameGetCallbackMap = base::hash_map<RenderFrameHost*, GetCallbackMap*>; | 41 using FrameGetCallbackMap = base::hash_map<RenderFrameHost*, GetCallbackMap*>; |
| 48 using FrameHasCallbackMap = base::hash_map<RenderFrameHost*, HasCallbackMap*>; | |
| 49 | 42 |
| 50 void OnRequestManifestResponse( | 43 void OnRequestManifestResponse( |
| 51 RenderFrameHost*, int request_id, const GURL&, const Manifest&); | 44 RenderFrameHost*, int request_id, const GURL&, const Manifest&); |
| 52 void OnHasManifestResponse( | |
| 53 RenderFrameHost*, int request_id, bool); | |
| 54 | 45 |
| 55 // Returns the CallbackMap associated with the given RenderFrameHost, or null. | 46 // Returns the CallbackMap associated with the given RenderFrameHost, or null. |
| 56 GetCallbackMap* GetCallbackMapForFrame(RenderFrameHost*); | 47 GetCallbackMap* GetCallbackMapForFrame(RenderFrameHost*); |
| 57 HasCallbackMap* HasCallbackMapForFrame(RenderFrameHost*); | |
| 58 | 48 |
| 59 FrameGetCallbackMap pending_get_callbacks_; | 49 FrameGetCallbackMap pending_get_callbacks_; |
| 60 FrameHasCallbackMap pending_has_callbacks_; | |
| 61 | 50 |
| 62 DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost); | 51 DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost); |
| 63 }; | 52 }; |
| 64 | 53 |
| 65 } // namespace content | 54 } // namespace content |
| 66 | 55 |
| 67 #endif // CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ | 56 #endif // CONTENT_BROWSER_MANIFEST_MANIFEST_MANAGER_HOST_H_ |
| OLD | NEW |