Chromium Code Reviews| 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 class WebContents; | |
| 20 } | |
| 21 | |
| 22 namespace extensions { | |
| 23 class UserScript; | |
| 24 | |
| 25 // WebViewContentScriptManager manages the content scripts that each webview | |
| 26 // guest adds and removes programmatically. | |
| 27 class WebViewContentScriptManager : public base::SupportsUserData::Data { | |
| 28 public: | |
| 29 explicit WebViewContentScriptManager( | |
| 30 content::BrowserContext* browser_context); | |
| 31 ~WebViewContentScriptManager() override; | |
| 32 | |
| 33 static WebViewContentScriptManager* Get( | |
| 34 content::BrowserContext* browser_context); | |
| 35 | |
| 36 // Adds content scripts for the guest specified by the |embedder_web_contents, | |
| 37 // view_instance_id|. | |
| 38 // The name of each content sccript is its key in |user_scripts| map. | |
| 39 void AddContentScripts(content::WebContents* embedder_web_contents, | |
| 40 int view_instance_id, | |
| 41 const HostID& host_id, | |
| 42 const std::map<std::string, UserScript>& user_scripts); | |
| 43 | |
| 44 // Removes contents scipts whose names are in the |script_name_list| for the | |
| 45 // guest specified by |embedder_web_contents, view_instance_id|. | |
| 46 // If the |script_name_list| is empty, removes all the content scripts added | |
| 47 // for this guest. | |
| 48 void RemoveContentScripts(content::WebContents* embedder_web_contents, | |
| 49 int view_instance_id, | |
| 50 const HostID& host_id, | |
| 51 const std::vector<std::string>& script_name_list); | |
| 52 | |
| 53 // Removes contents scripts from all the guests owned by the given embedder, | |
| 54 // which is specified by |embedder_web_content|. | |
| 55 // Called by OwnerWebContentsObserver when the observer sees a main frame | |
| 56 // navigation or sees the process has went away or the |embedder_web_content| | |
| 57 // is being destroyed. | |
| 58 void RemoveContentScripts(content::WebContents* embedder_web_content, | |
|
Fady Samuel
2015/04/10 16:16:04
Make this private and make OwnerWebContentsObserve
Xi Han
2015/04/10 18:27:07
You are absolute right, forget to update here. Upd
| |
| 59 const HostID& host_id); | |
| 60 | |
| 61 // Returns whether the content script with |script_id| belonges to the guest | |
| 62 // specified by |embedder_process_id, view_instance_id|. | |
| 63 bool OwnsUserScript(int embedder_process_id, | |
| 64 int view_instance_id, | |
| 65 int script_id); | |
| 66 | |
| 67 // Returns the content script IDs added by the guest specified by | |
| 68 // |embedder_process_id, view_instance_id|. | |
| 69 std::set<int> GetContentScriptIDSet(int embedder_process_id, | |
| 70 int view_instance_id); | |
| 71 | |
| 72 private: | |
| 73 class OwnerWebContentsObserver; | |
| 74 | |
| 75 using GuestMapKey = std::pair<int, int>; | |
| 76 using ContentScriptMap = std::map<std::string, extensions::UserScript>; | |
| 77 using GuestContentScriptMap = std::map<GuestMapKey, ContentScriptMap>; | |
| 78 | |
| 79 using OwnerWebContentsObserverMap = | |
| 80 std::map<content::WebContents*, linked_ptr<OwnerWebContentsObserver>>; | |
| 81 | |
| 82 OwnerWebContentsObserverMap owner_web_contents_observer_map_; | |
| 83 | |
| 84 GuestContentScriptMap guest_content_script_map_; | |
| 85 | |
| 86 content::BrowserContext* browser_context_; | |
| 87 }; | |
| 88 | |
| 89 } // namespace extensions | |
| 90 | |
| 91 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGE R_H | |
| OLD | NEW |