Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: extensions/browser/guest_view/web_view/web_view_content_script_manager.h

Issue 959413003: Implement <webview>.addContentScript/removeContentScript API [1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Devlin's comments and fix the incognito mode issue. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 {
+ 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,
Fady Samuel 2015/04/08 22:40:04 Take in the embedder_web_contents
+ 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,
Fady Samuel 2015/04/08 22:40:04 Take in the 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,
+ 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

Powered by Google App Engine
This is Rietveld 408576698