1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23  * DAMAGE.
24  */
25 
26 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_APPLICATION_CACHE_AGENT_H_
27 #define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_APPLICATION_CACHE_AGENT_H_
28 
29 #include "base/macros.h"
30 #include "third_party/blink/renderer/core/core_export.h"
31 #include "third_party/blink/renderer/core/inspector/inspector_base_agent.h"
32 #include "third_party/blink/renderer/core/inspector/protocol/ApplicationCache.h"
33 #include "third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.h"
34 
35 namespace blink {
36 
37 class LocalFrame;
38 class InspectedFrames;
39 
40 class CORE_EXPORT InspectorApplicationCacheAgent final
41     : public InspectorBaseAgent<protocol::ApplicationCache::Metainfo> {
42  public:
43   explicit InspectorApplicationCacheAgent(InspectedFrames*);
44   ~InspectorApplicationCacheAgent() override = default;
45   void Trace(Visitor*) override;
46 
47   // InspectorBaseAgent
48   void Restore() override;
49   protocol::Response disable() override;
50 
51   // InspectorInstrumentation API
52   void UpdateApplicationCacheStatus(LocalFrame*);
53   void NetworkStateChanged(LocalFrame*, bool online);
54 
55   // ApplicationCache API for frontend
56   protocol::Response getFramesWithManifests(
57       std::unique_ptr<
58           protocol::Array<protocol::ApplicationCache::FrameWithManifest>>*
59           frame_ids) override;
60   protocol::Response enable() override;
61   protocol::Response getManifestForFrame(const String& frame_id,
62                                          String* manifest_url) override;
63   protocol::Response getApplicationCacheForFrame(
64       const String& frame_id,
65       std::unique_ptr<protocol::ApplicationCache::ApplicationCache>*) override;
66 
67  private:
68   // Unconditionally enables the agent, even if |enabled_.Get()==true|.
69   // For idempotence, call enable().
70   void InnerEnable();
71 
72   std::unique_ptr<protocol::ApplicationCache::ApplicationCache>
73   BuildObjectForApplicationCache(
74       const Vector<mojom::blink::AppCacheResourceInfo>&,
75       const ApplicationCacheHost::CacheInfo&);
76   std::unique_ptr<
77       protocol::Array<protocol::ApplicationCache::ApplicationCacheResource>>
78   BuildArrayForApplicationCacheResources(
79       const Vector<mojom::blink::AppCacheResourceInfo>&);
80   std::unique_ptr<protocol::ApplicationCache::ApplicationCacheResource>
81   BuildObjectForApplicationCacheResource(
82       const mojom::blink::AppCacheResourceInfo&);
83 
84   protocol::Response AssertFrameWithDocumentLoader(String frame_id,
85                                                    DocumentLoader*&);
86 
87   Member<InspectedFrames> inspected_frames_;
88   InspectorAgentState::Boolean enabled_;
89   DISALLOW_COPY_AND_ASSIGN(InspectorApplicationCacheAgent);
90 };
91 
92 }  // namespace blink
93 
94 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_APPLICATION_CACHE_AGENT_H_
95