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..9e8dfd24490de07a623a52ecd655a5ebe85ae12f |
--- /dev/null |
+++ b/extensions/browser/guest_view/web_view/web_view_content_script_manager.h |
@@ -0,0 +1,75 @@ |
+// 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; |
+} |
+ |
+namespace extensions { |
+class UserScript; |
+ |
+// WebViewContentScriptManager manages the content scripts that each webview |
+// guest adds and removes programmatically. |
+class WebViewContentScriptManager : public base::SupportsUserData::Data { |
Devlin
2015/04/08 17:50:56
Do we really need this class? Couldn't adding/rem
Xi Han
2015/04/08 22:10:36
It is better to have this class to keep other clas
Devlin
2015/04/10 16:04:31
I'm still not entirely convinced of the usefulness
Fady Samuel
2015/04/10 16:44:28
Devlin, the content scripts are tied to the lifeti
Devlin
2015/04/10 17:38:57
Ah, interesting. So a WebViewInfo is removed when
Xi Han
2015/04/10 18:27:06
WebViewInfo contains the routing info for a guest
Devlin
2015/04/10 18:31:36
But that routing info is still valid for the next
|
+ 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_process_id, |
+ // view_instance_id|. |
+ // The name of each content sccript is its key in |user_scripts| map. |
+ void AddContentScripts(int embedder_process_id, |
+ int view_instance_id, |
+ const HostID& host_id, |
+ const std::map<std::string, UserScript>& user_scripts); |
+ |
+ // Removes contents scipts whose names are in the |script_name_list| for the |
+ // guest specified by |embedder_process_id, view_instance_id|. |
+ // If the |script_name_list| is empty, removes all the content scripts added |
+ // for this guest. |
+ void RemoveContentScripts(int embedder_process_id, |
+ 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, |
+ 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: |
+ using GuestMapKey = std::pair<int, int>; |
+ using ContentScriptMap = std::map<std::string, extensions::UserScript>; |
+ using GuestContentScriptMap = std::map<GuestMapKey, ContentScriptMap>; |
+ |
+ GuestContentScriptMap guest_content_script_map_; |
+ |
+ content::BrowserContext* browser_context_; |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H |