| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_ | 5 #ifndef EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_ |
| 6 #define EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_ | 6 #define EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h" | 9 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h" |
| 10 #include "extensions/browser/user_script_loader.h" | 10 #include "extensions/browser/user_script_loader.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 class BrowserContext; | 13 class BrowserContext; |
| 14 } | 14 } |
| 15 | 15 |
| 16 // UserScriptLoader for WebUI. | 16 // UserScriptLoader for WebUI. |
| 17 class WebUIUserScriptLoader : public extensions::UserScriptLoader { | 17 class WebUIUserScriptLoader : public extensions::UserScriptLoader { |
| 18 public: | 18 public: |
| 19 WebUIUserScriptLoader(content::BrowserContext* browser_context, | 19 WebUIUserScriptLoader(content::BrowserContext* browser_context, |
| 20 const HostID& host_id); | 20 const HostID& host_id); |
| 21 ~WebUIUserScriptLoader() override; | 21 ~WebUIUserScriptLoader() override; |
| 22 | 22 |
| 23 private: | 23 private: |
| 24 struct UserScriptRenderInfo; | 24 struct UserScriptRenderInfo; |
| 25 using UserScriptRenderInfoMap = std::map<int, UserScriptRenderInfo>; | 25 using UserScriptRenderInfoMap = std::map<int, UserScriptRenderInfo>; |
| 26 | 26 |
| 27 // UserScriptLoader: | 27 // UserScriptLoader: |
| 28 void AddScripts(const std::set<extensions::UserScript>& scripts, | 28 void AddScripts(const std::set<extensions::UserScript>& scripts, |
| 29 int render_process_id, | 29 int render_process_id, |
| 30 int render_view_id) override; | 30 int render_view_id, |
| 31 bool is_incognito) override; |
| 31 void LoadScripts(scoped_ptr<extensions::UserScriptList> user_scripts, | 32 void LoadScripts(scoped_ptr<extensions::UserScriptList> user_scripts, |
| 32 const std::set<HostID>& changed_hosts, | 33 const std::set<HostID>& changed_hosts, |
| 33 const std::set<int>& added_script_ids) override; | 34 const std::set<int>& added_script_ids) override; |
| 34 | 35 |
| 35 // Called when every single URL fetch is done. It also traces whether all the | 36 // Called when every single URL fetch is done. It also traces whether all the |
| 36 // URL fetches are done. If yes, will call OnWebUIURLFetchComplete(). | 37 // URL fetches are done. If yes, will call OnWebUIURLFetchComplete(). |
| 37 void OnSingleWebUIURLFetchComplete(extensions::UserScript::File* script_file, | 38 void OnSingleWebUIURLFetchComplete(extensions::UserScript::File* script_file, |
| 38 bool success, | 39 bool success, |
| 39 const std::string& data); | 40 const std::string& data); |
| 40 | 41 |
| 41 // Called when the loads of the user scripts are done. | 42 // Called when the loads of the user scripts are done. |
| 42 void OnWebUIURLFetchComplete(); | 43 void OnWebUIURLFetchComplete(); |
| 43 | 44 |
| 44 // Creates WebUiURLFetchers for the given |script_files|. | 45 // Creates WebUiURLFetchers for the given |script_files|. |
| 45 void CreateWebUIURLFetchers(extensions::UserScript::FileList* script_files, | 46 void CreateWebUIURLFetchers(extensions::UserScript::FileList* script_files, |
| 47 content::BrowserContext* browser_context, |
| 46 int render_process_id, | 48 int render_process_id, |
| 47 int render_view_id); | 49 int render_view_id); |
| 48 | 50 |
| 49 // Caches the render info of script from WebUI when AddScripts is called. | 51 // Caches the render info of script from WebUI when AddScripts is called. |
| 50 // When starting to load the script, we look up this map to retrieve the | 52 // When starting to load the script, we look up this map to retrieve the |
| 51 // render info. It is used for the script from WebUI only, since the fetch | 53 // render info. It is used for the script from WebUI only, since the fetch |
| 52 // of script content requires the info of associated render. | 54 // of script content requires the info of associated render. |
| 53 UserScriptRenderInfoMap script_render_info_map_; | 55 UserScriptRenderInfoMap script_render_info_map_; |
| 54 | 56 |
| 55 // The number of complete fetchs. | 57 // The number of complete fetchs. |
| 56 size_t complete_fetchers_; | 58 size_t complete_fetchers_; |
| 57 | 59 |
| 58 // Caches |user_scripts_| from UserScriptLoader when loading. | 60 // Caches |user_scripts_| from UserScriptLoader when loading. |
| 59 scoped_ptr<extensions::UserScriptList> user_scripts_cache_; | 61 scoped_ptr<extensions::UserScriptList> user_scripts_cache_; |
| 60 | 62 |
| 61 ScopedVector<WebUIURLFetcher> fetchers_; | 63 ScopedVector<WebUIURLFetcher> fetchers_; |
| 62 | 64 |
| 63 base::WeakPtrFactory<WebUIUserScriptLoader> weak_factory_; | 65 base::WeakPtrFactory<WebUIUserScriptLoader> weak_factory_; |
| 64 | 66 |
| 65 DISALLOW_COPY_AND_ASSIGN(WebUIUserScriptLoader); | 67 DISALLOW_COPY_AND_ASSIGN(WebUIUserScriptLoader); |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 #endif // EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_ | 70 #endif // EXTENSIONS_BROWSER_WEB_UI_USER_SCRIPT_LOADER_H_ |
| OLD | NEW |