Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / extensions / browser / web_ui_user_script_loader.h
blobf74ef00da3fdebbe9985c7e729d58a18e4c56f68
1 // Copyright 2015 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 EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_
6 #define EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "extensions/browser/user_script_loader.h"
13 class WebUIURLFetcher;
15 namespace content {
16 class BrowserContext;
19 // UserScriptLoader for WebUI.
20 class WebUIUserScriptLoader : public extensions::UserScriptLoader {
21 public:
22 WebUIUserScriptLoader(content::BrowserContext* browser_context,
23 const HostID& host_id);
24 ~WebUIUserScriptLoader() override;
26 private:
27 struct UserScriptRenderInfo;
28 using UserScriptRenderInfoMap = std::map<int, UserScriptRenderInfo>;
30 // UserScriptLoader:
31 void AddScripts(const std::set<extensions::UserScript>& scripts,
32 int render_process_id,
33 int render_view_id) override;
34 void LoadScripts(scoped_ptr<extensions::UserScriptList> user_scripts,
35 const std::set<HostID>& changed_hosts,
36 const std::set<int>& added_script_ids,
37 LoadScriptsCallback callback) override;
39 // Called at the end of each fetch, tracking whether all fetches are done.
40 void OnSingleWebUIURLFetchComplete(extensions::UserScript::File* script_file,
41 bool success,
42 const std::string& data);
44 // Called when the loads of the user scripts are done.
45 void OnWebUIURLFetchComplete();
47 // Creates WebUiURLFetchers for the given |script_files|.
48 void CreateWebUIURLFetchers(extensions::UserScript::FileList* script_files,
49 content::BrowserContext* browser_context,
50 int render_process_id,
51 int render_view_id);
53 // Caches the render info of script from WebUI when AddScripts is called.
54 // When starting to load the script, we look up this map to retrieve the
55 // render info. It is used for the script from WebUI only, since the fetch
56 // of script content requires the info of associated render.
57 UserScriptRenderInfoMap script_render_info_map_;
59 // The number of complete fetchs.
60 size_t complete_fetchers_;
62 // Caches |user_scripts_| from UserScriptLoader when loading.
63 scoped_ptr<extensions::UserScriptList> user_scripts_cache_;
65 LoadScriptsCallback scripts_loaded_callback_;
67 ScopedVector<WebUIURLFetcher> fetchers_;
69 DISALLOW_COPY_AND_ASSIGN(WebUIUserScriptLoader);
72 #endif // EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_