Index: extensions/browser/guest_view/web_view/web_view_content_script_manager.h |
diff --git a/extensions/browser/guest_view/web_view/web_view_content_script_manager.h b/extensions/browser/guest_view/web_view/web_view_content_script_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0330af46574d1a2dacb71515c99b861237b76e7c |
--- /dev/null |
+++ b/extensions/browser/guest_view/web_view/web_view_content_script_manager.h |
@@ -0,0 +1,91 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H |
+#define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H |
+ |
+#include <map> |
+#include <set> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/supports_user_data.h" |
+ |
+struct HostID; |
+ |
+namespace content { |
+class BrowserContext; |
+class WebContents; |
+} |
+ |
+namespace extensions { |
+class UserScript; |
+ |
+// WebViewContentScriptManager manages the content scripts that each webview |
+// guest adds and removes programmatically. |
+// TODO(hanxi): crbug.com/476938. Introduces a new class to manage the lifetime |
Devlin
2015/04/14 23:04:57
s/introduces/introduce
Xi Han
2015/04/15 19:43:56
Done.
|
+// of <webview> and clean up WebViewContentScriptManager. |
+class WebViewContentScriptManager : public base::SupportsUserData::Data { |
+ public: |
+ explicit WebViewContentScriptManager( |
+ content::BrowserContext* browser_context); |
+ ~WebViewContentScriptManager() override; |
+ |
+ static WebViewContentScriptManager* Get( |
+ content::BrowserContext* browser_context); |
+ |
+ // Adds content scripts for the guest specified by the |embedder_web_contents, |
+ // view_instance_id|. |
+ void AddContentScripts(content::WebContents* embedder_web_contents, |
+ int view_instance_id, |
+ const HostID& host_id, |
+ const std::set<UserScript>& user_scripts); |
+ |
+ // Removes contents scipts whose names are in the |script_name_list| for the |
+ // guest specified by |embedder_web_contents, view_instance_id|. |
+ // If the |script_name_list| is empty, removes all the content scripts added |
+ // for this guest. |
+ void RemoveContentScripts(content::WebContents* embedder_web_contents, |
+ int view_instance_id, |
+ const HostID& host_id, |
+ const std::vector<std::string>& script_name_list); |
+ |
+ // Returns whether the content script with |script_id| belonges to the guest |
+ // specified by |embedder_process_id, view_instance_id|. |
+ bool OwnsUserScript(int embedder_process_id, |
Devlin
2015/04/14 23:04:57
This doesn't exist?
Xi Han
2015/04/15 19:43:55
Oh, it is legacy code and should be removed.
|
+ int view_instance_id, |
+ int script_id); |
+ |
+ // Returns the content script IDs added by the guest specified by |
+ // |embedder_process_id, view_instance_id|. |
+ std::set<int> GetContentScriptIDSet(int embedder_process_id, |
+ int view_instance_id); |
+ |
+ private: |
+ class OwnerWebContentsObserver; |
+ |
+ using GuestMapKey = std::pair<int, int>; |
+ using ContentScriptMap = std::map<std::string, extensions::UserScript>; |
+ using GuestContentScriptMap = std::map<GuestMapKey, ContentScriptMap>; |
+ |
+ using OwnerWebContentsObserverMap = |
+ std::map<content::WebContents*, linked_ptr<OwnerWebContentsObserver>>; |
+ |
+ // Called by OwnerWebContentsObserver when the observer sees a main frame |
+ // navigation or sees the process has went away or the |embedder_web_contents| |
+ // is being destroyed. |
+ void RemoveObserver(content::WebContents* embedder_web_contents); |
+ |
+ OwnerWebContentsObserverMap owner_web_contents_observer_map_; |
+ |
+ GuestContentScriptMap guest_content_script_map_; |
+ |
+ content::BrowserContext* browser_context_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebViewContentScriptManager); |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H |