| 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_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ |
| 6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ | 6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <memory> | 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "content/public/common/manifest.h" | 14 #include "content/public/common/manifest.h" |
| 14 #include "content/public/renderer/render_frame_observer.h" | 15 #include "content/public/renderer/render_frame_observer.h" |
| 16 #include "mojo/public/cpp/bindings/binding_set.h" |
| 17 #include "third_party/WebKit/public/platform/modules/manifest/manifest.mojom.h" |
| 18 #include "third_party/WebKit/public/platform/modules/manifest/manifest_manager.m
ojom.h" |
| 15 | 19 |
| 16 class GURL; | 20 class GURL; |
| 17 | 21 |
| 18 namespace blink { | 22 namespace blink { |
| 19 class WebURLResponse; | 23 class WebURLResponse; |
| 20 } | 24 } |
| 21 | 25 |
| 22 namespace content { | 26 namespace content { |
| 23 | 27 |
| 24 class ManifestFetcher; | 28 class ManifestFetcher; |
| 25 | 29 |
| 26 // The ManifestManager is a helper class that takes care of fetching and parsing | 30 // The ManifestManager is a helper class that takes care of fetching and parsing |
| 27 // the Manifest of the associated RenderFrame. It uses the ManifestFetcher and | 31 // the Manifest of the associated RenderFrame. It uses the ManifestFetcher and |
| 28 // the ManifestParser in order to do so. | 32 // the ManifestParser in order to do so. |
| 29 // There are two expected consumers of this helper: ManifestManagerHost, via IPC | 33 // There are two expected consumers of this helper: ManifestManagerHost, via IPC |
| 30 // messages and callers inside the renderer process. The latter should use | 34 // messages and callers inside the renderer process. The latter should use |
| 31 // GetManifest(). | 35 // GetManifest(). |
| 32 class ManifestManager : public RenderFrameObserver { | 36 class ManifestManager : public RenderFrameObserver, |
| 37 public blink::mojom::ManifestManager { |
| 33 public: | 38 public: |
| 34 typedef base::Callback<void(const Manifest&)> GetManifestCallback; | 39 typedef base::Callback<void(const Manifest&)> GetManifestCallback; |
| 35 | 40 |
| 36 explicit ManifestManager(RenderFrame* render_frame); | 41 explicit ManifestManager(RenderFrame* render_frame); |
| 37 ~ManifestManager() override; | 42 ~ManifestManager() override; |
| 38 | 43 |
| 39 // Will call the given |callback| with the Manifest associated with the | 44 // Will call the given |callback| with the Manifest associated with the |
| 40 // RenderFrame if any. Will pass an empty Manifest in case of error. | 45 // RenderFrame if any. Will pass an empty Manifest in case of error. |
| 41 void GetManifest(const GetManifestCallback& callback); | 46 void GetManifest(const GetManifestCallback& callback); |
| 42 | 47 |
| 43 // RenderFrameObserver implementation. | 48 // RenderFrameObserver implementation. |
| 44 bool OnMessageReceived(const IPC::Message& message) override; | |
| 45 void DidChangeManifest() override; | 49 void DidChangeManifest() override; |
| 46 void DidCommitProvisionalLoad(bool is_new_navigation, | 50 void DidCommitProvisionalLoad(bool is_new_navigation, |
| 47 bool is_same_page_navigation) override; | 51 bool is_same_page_navigation) override; |
| 48 | 52 |
| 53 void BindToRequest(blink::mojom::ManifestManagerRequest request); |
| 54 |
| 49 private: | 55 private: |
| 50 enum ResolveState { | 56 enum ResolveState { |
| 51 ResolveStateSuccess, | 57 ResolveStateSuccess, |
| 52 ResolveStateFailure | 58 ResolveStateFailure |
| 53 }; | 59 }; |
| 54 | 60 |
| 55 // Called when receiving a ManifestManagerMsg_RequestManifest from the browser | 61 // blink::mojom::ManifestManager implementation. |
| 56 // process. | 62 void HasManifest(const HasManifestCallback& callback) override; |
| 57 void OnHasManifest(int request_id); | 63 void RequestManifest(const RequestManifestCallback& callback) override; |
| 58 void OnRequestManifest(int request_id); | 64 |
| 59 void OnRequestManifestComplete(int request_id, const Manifest&); | 65 // Called when receiving a RequestManifest() call from the browser process. |
| 66 void OnRequestManifestComplete(const RequestManifestCallback& callback, |
| 67 const Manifest&); |
| 60 | 68 |
| 61 void FetchManifest(); | 69 void FetchManifest(); |
| 62 void OnManifestFetchComplete(const GURL& document_url, | 70 void OnManifestFetchComplete(const GURL& document_url, |
| 63 const blink::WebURLResponse& response, | 71 const blink::WebURLResponse& response, |
| 64 const std::string& data); | 72 const std::string& data); |
| 65 void ResolveCallbacks(ResolveState state); | 73 void ResolveCallbacks(ResolveState state); |
| 66 | 74 |
| 67 std::unique_ptr<ManifestFetcher> fetcher_; | 75 std::unique_ptr<ManifestFetcher> fetcher_; |
| 68 | 76 |
| 69 // Whether the RenderFrame may have an associated Manifest. If true, the frame | 77 // Whether the RenderFrame may have an associated Manifest. If true, the frame |
| 70 // may have a manifest, if false, it can't have one. This boolean is true when | 78 // may have a manifest, if false, it can't have one. This boolean is true when |
| 71 // DidChangeManifest() is called, if it is never called, it means that the | 79 // DidChangeManifest() is called, if it is never called, it means that the |
| 72 // associated document has no <link rel='manifest'>. | 80 // associated document has no <link rel='manifest'>. |
| 73 bool may_have_manifest_; | 81 bool may_have_manifest_; |
| 74 | 82 |
| 75 // Whether the current Manifest is dirty. | 83 // Whether the current Manifest is dirty. |
| 76 bool manifest_dirty_; | 84 bool manifest_dirty_; |
| 77 | 85 |
| 78 // Current Manifest. Might be outdated if manifest_dirty_ is true. | 86 // Current Manifest. Might be outdated if manifest_dirty_ is true. |
| 79 Manifest manifest_; | 87 Manifest manifest_; |
| 80 | 88 |
| 81 std::list<GetManifestCallback> pending_callbacks_; | 89 std::vector<GetManifestCallback> pending_callbacks_; |
| 90 |
| 91 mojo::BindingSet<blink::mojom::ManifestManager> bindings_; |
| 82 | 92 |
| 83 DISALLOW_COPY_AND_ASSIGN(ManifestManager); | 93 DISALLOW_COPY_AND_ASSIGN(ManifestManager); |
| 84 }; | 94 }; |
| 85 | 95 |
| 86 } // namespace content | 96 } // namespace content |
| 87 | 97 |
| 88 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ | 98 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ |
| OLD | NEW |