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 // TODO(hanxi): crbug.com/476938. Introduce a new class to manage the lifetime |
| 28 // of <webview> and clean up WebViewContentScriptManager. |
| 29 class WebViewContentScriptManager : public base::SupportsUserData::Data { |
| 30 public: |
| 31 explicit WebViewContentScriptManager( |
| 32 content::BrowserContext* browser_context); |
| 33 ~WebViewContentScriptManager() override; |
| 34 |
| 35 static WebViewContentScriptManager* Get( |
| 36 content::BrowserContext* browser_context); |
| 37 |
| 38 // Adds content scripts for the guest specified by the |embedder_web_contents, |
| 39 // view_instance_id|. |
| 40 void AddContentScripts(content::WebContents* embedder_web_contents, |
| 41 int view_instance_id, |
| 42 const HostID& host_id, |
| 43 const std::set<UserScript>& user_scripts); |
| 44 |
| 45 // Removes contents scipts whose names are in the |script_name_list| for the |
| 46 // guest specified by |embedder_web_contents, view_instance_id|. |
| 47 // If the |script_name_list| is empty, removes all the content scripts added |
| 48 // for this guest. |
| 49 void RemoveContentScripts(content::WebContents* embedder_web_contents, |
| 50 int view_instance_id, |
| 51 const HostID& host_id, |
| 52 const std::vector<std::string>& script_name_list); |
| 53 |
| 54 // Returns the content script IDs added by the guest specified by |
| 55 // |embedder_process_id, view_instance_id|. |
| 56 std::set<int> GetContentScriptIDSet(int embedder_process_id, |
| 57 int view_instance_id); |
| 58 |
| 59 private: |
| 60 class OwnerWebContentsObserver; |
| 61 |
| 62 using GuestMapKey = std::pair<int, int>; |
| 63 using ContentScriptMap = std::map<std::string, extensions::UserScript>; |
| 64 using GuestContentScriptMap = std::map<GuestMapKey, ContentScriptMap>; |
| 65 |
| 66 using OwnerWebContentsObserverMap = |
| 67 std::map<content::WebContents*, linked_ptr<OwnerWebContentsObserver>>; |
| 68 |
| 69 // Called by OwnerWebContentsObserver when the observer sees a main frame |
| 70 // navigation or sees the process has went away or the |embedder_web_contents| |
| 71 // is being destroyed. |
| 72 void RemoveObserver(content::WebContents* embedder_web_contents); |
| 73 |
| 74 OwnerWebContentsObserverMap owner_web_contents_observer_map_; |
| 75 |
| 76 GuestContentScriptMap guest_content_script_map_; |
| 77 |
| 78 content::BrowserContext* browser_context_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(WebViewContentScriptManager); |
| 81 }; |
| 82 |
| 83 } // namespace extensions |
| 84 |
| 85 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGE
R_H |
OLD | NEW |