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

Side by Side 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: Delvin's comments. 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 unified diff | Download patch
OLDNEW
(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. 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.
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 whether the content script with |script_id| belonges to the guest
55 // specified by |embedder_process_id, view_instance_id|.
56 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.
57 int view_instance_id,
58 int script_id);
59
60 // Returns the content script IDs added by the guest specified by
61 // |embedder_process_id, view_instance_id|.
62 std::set<int> GetContentScriptIDSet(int embedder_process_id,
63 int view_instance_id);
64
65 private:
66 class OwnerWebContentsObserver;
67
68 using GuestMapKey = std::pair<int, int>;
69 using ContentScriptMap = std::map<std::string, extensions::UserScript>;
70 using GuestContentScriptMap = std::map<GuestMapKey, ContentScriptMap>;
71
72 using OwnerWebContentsObserverMap =
73 std::map<content::WebContents*, linked_ptr<OwnerWebContentsObserver>>;
74
75 // Called by OwnerWebContentsObserver when the observer sees a main frame
76 // navigation or sees the process has went away or the |embedder_web_contents|
77 // is being destroyed.
78 void RemoveObserver(content::WebContents* embedder_web_contents);
79
80 OwnerWebContentsObserverMap owner_web_contents_observer_map_;
81
82 GuestContentScriptMap guest_content_script_map_;
83
84 content::BrowserContext* browser_context_;
85
86 DISALLOW_COPY_AND_ASSIGN(WebViewContentScriptManager);
87 };
88
89 } // namespace extensions
90
91 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGE R_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698