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.
5 #ifndef CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_
6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_
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"
23 class ManifestFetcher
;
25 // The ManifestManager is a helper class that takes care of fetching and parsing
26 // the Manifest of the associated RenderFrame. It uses the ManifestFetcher and
27 // the ManifestParser in order to do so.
28 // There are two expected consumers of this helper: ManifestManagerHost, via IPC
29 // messages and callers inside the renderer process. The latter should use
31 class ManifestManager
: public RenderFrameObserver
{
33 typedef base::Callback
<void(const Manifest
&)> GetManifestCallback
;
35 explicit ManifestManager(RenderFrame
* render_frame
);
36 ~ManifestManager() override
;
38 // Will call the given |callback| with the Manifest associated with the
39 // RenderFrame if any. Will pass an empty Manifest in case of error.
40 void GetManifest(const GetManifestCallback
& callback
);
42 // RenderFrameObserver implementation.
43 bool OnMessageReceived(const IPC::Message
& message
) override
;
44 void DidChangeManifest() override
;
45 void DidCommitProvisionalLoad(bool is_new_navigation
,
46 bool is_same_page_navigation
) override
;
54 // Called when receiving a ManifestManagerMsg_RequestManifest from the browser
56 void OnRequestManifest(int request_id
);
57 void OnRequestManifestComplete(int request_id
, const Manifest
&);
60 void OnManifestFetchComplete(const GURL
& document_url
,
61 const blink::WebURLResponse
& response
,
62 const std::string
& data
);
63 void ResolveCallbacks(ResolveState state
);
65 scoped_ptr
<ManifestFetcher
> fetcher_
;
67 // Whether the RenderFrame may have an associated Manifest. If true, the frame
68 // may have a manifest, if false, it can't have one. This boolean is true when
69 // DidChangeManifest() is called, if it is never called, it means that the
70 // associated document has no <link rel='manifest'>.
71 bool may_have_manifest_
;
73 // Whether the current Manifest is dirty.
76 // Current Manifest. Might be outdated if manifest_dirty_ is true.
79 std::list
<GetManifestCallback
> pending_callbacks_
;
81 DISALLOW_COPY_AND_ASSIGN(ManifestManager
);
84 } // namespace content
86 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_