OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H |
| 6 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/supports_user_data.h" |
| 14 |
| 15 struct HostID; |
| 16 |
| 17 namespace content { |
| 18 class BrowserContext; |
| 19 } |
| 20 |
| 21 namespace extensions { |
| 22 class UserScript; |
| 23 |
| 24 // WebViewContentScriptManager manages the content scripts that each webview |
| 25 // guest adds and removes programmatically. |
| 26 class WebViewContentScriptManager : public base::SupportsUserData::Data { |
| 27 public: |
| 28 explicit WebViewContentScriptManager( |
| 29 content::BrowserContext* browser_context); |
| 30 ~WebViewContentScriptManager() override; |
| 31 |
| 32 static WebViewContentScriptManager* Get( |
| 33 content::BrowserContext* browser_context); |
| 34 |
| 35 // Adds content scripts for the guest specified by the |embedder_process_id, |
| 36 // view_instance_id|. |
| 37 // The name of each content sccript is its key in |user_scripts| map. |
| 38 void AddContentScripts(int embedder_process_id, |
| 39 int view_instance_id, |
| 40 const HostID& host_id, |
| 41 const std::map<std::string, UserScript>& user_scripts); |
| 42 |
| 43 // Removes contents scipts whose names are in the |script_name_list| for the |
| 44 // guest specified by |embedder_process_id, view_instance_id|. |
| 45 // If the |script_name_list| is empty, removes all the content scripts added |
| 46 // for this guest. |
| 47 void RemoveContentScripts(int embedder_process_id, |
| 48 int view_instance_id, |
| 49 const HostID& host_id, |
| 50 const std::vector<std::string>& script_name_list); |
| 51 |
| 52 // Returns whether the content script with |script_id| belonges to the guest |
| 53 // specified by |embedder_process_id, view_instance_id|. |
| 54 bool OwnsUserScript(int embedder_process_id, |
| 55 int view_instance_id, |
| 56 int script_id); |
| 57 |
| 58 // Returns the content script IDs added by the guest specified by |
| 59 // |embedder_process_id, view_instance_id|. |
| 60 std::set<int> GetContentScriptIDSet(int embedder_process_id, |
| 61 int view_instance_id); |
| 62 |
| 63 private: |
| 64 using GuestMapKey = std::pair<int, int>; |
| 65 using ContentScriptMap = std::map<std::string, extensions::UserScript>; |
| 66 using GuestContentScriptMap = std::map<GuestMapKey, ContentScriptMap>; |
| 67 |
| 68 GuestContentScriptMap guest_content_script_map_; |
| 69 |
| 70 content::BrowserContext* browser_context_; |
| 71 }; |
| 72 |
| 73 } // namespace extensions |
| 74 |
| 75 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGE
R_H |
OLD | NEW |