Chromium Code Reviews| 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..c42fcd2db91b6ce1ab3d5463653c6d7093d153be |
| --- /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. |
| +class WebViewContentScriptManager : public base::SupportsUserData::Data { |
|
Devlin
2015/04/13 19:21:48
Please file a bug and add a TODO here linking to i
Xi Han
2015/04/14 19:05:52
Done.
|
| + 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|. |
| + // The name of each content sccript is its key in |user_scripts| map. |
| + void AddContentScripts(content::WebContents* embedder_web_contents, |
| + int view_instance_id, |
| + const HostID& host_id, |
| + const std::map<std::string, UserScript>& user_scripts); |
|
Devlin
2015/04/13 19:21:48
The name is stored on the UserScript, so we don't
Xi Han
2015/04/14 19:05:52
Done.
|
| + |
| + // 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, |
| + 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>>; |
| + |
| + // Removes contents scripts from all the guests owned by the given embedder, |
| + // which is specified by |embedder_web_content|. |
| + // 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 RemoveContentScripts(content::WebContents* embedder_web_contents, |
| + const HostID& host_id); |
| + |
| + OwnerWebContentsObserverMap owner_web_contents_observer_map_; |
| + |
| + GuestContentScriptMap guest_content_script_map_; |
| + |
| + content::BrowserContext* browser_context_; |
|
Devlin
2015/04/13 19:21:48
DISALLOW_COPY_AND_ASSIGN
Xi Han
2015/04/14 19:05:52
Done.
|
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_CONTENT_SCRIPT_MANAGER_H |