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