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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/content_action.h

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 ApplyInfo* apply_info) const = 0; 60 ApplyInfo* apply_info) const = 0;
61 61
62 // Factory method that instantiates a concrete ContentAction 62 // Factory method that instantiates a concrete ContentAction
63 // implementation according to |json_action|, the representation of the 63 // implementation according to |json_action|, the representation of the
64 // ContentAction as received from the extension API. 64 // ContentAction as received from the extension API.
65 // Sets |error| and returns NULL in case of a semantic error that cannot 65 // Sets |error| and returns NULL in case of a semantic error that cannot
66 // be caught by schema validation. Sets |bad_message| and returns NULL 66 // be caught by schema validation. Sets |bad_message| and returns NULL
67 // in case the input is syntactically unexpected. 67 // in case the input is syntactically unexpected.
68 static scoped_refptr<ContentAction> Create( 68 static scoped_refptr<ContentAction> Create(
69 content::BrowserContext* browser_context, 69 content::BrowserContext* browser_context,
70 const HostID& host_id,
70 const Extension* extension, 71 const Extension* extension,
71 const base::Value& json_action, 72 const base::Value& json_action,
72 std::string* error, 73 std::string* error,
73 bool* bad_message); 74 bool* bad_message);
74 75
75 // Shared procedure for resetting error state within factories. 76 // Shared procedure for resetting error state within factories.
76 static void ResetErrorData(std::string* error, bool* bad_message) { 77 static void ResetErrorData(std::string* error, bool* bad_message) {
77 *error = ""; 78 *error = "";
78 *bad_message = false; 79 *bad_message = false;
79 } 80 }
80 81
81 // Shared procedure for validating JSON data. 82 // Shared procedure for validating JSON data.
82 static bool Validate(const base::Value& json_action, 83 static bool Validate(const base::Value& json_action,
83 std::string* error, 84 std::string* error,
84 bool* bad_message, 85 bool* bad_message,
85 const base::DictionaryValue** action_dict, 86 const base::DictionaryValue** action_dict,
86 std::string* instance_type); 87 std::string* instance_type);
87 88
88 protected: 89 protected:
89 friend class base::RefCounted<ContentAction>; 90 friend class base::RefCounted<ContentAction>;
90 virtual ~ContentAction(); 91 virtual ~ContentAction();
91 }; 92 };
92 93
93 // Action that injects a content script. 94 // Action that injects a content script.
94 class RequestContentScript : public ContentAction { 95 class RequestContentScript : public ContentAction {
95 public: 96 public:
96 struct ScriptData; 97 struct ScriptData;
97 98
99 // TODO(hanxi): remove the plumbing of |host_id| when introducing class
100 // Host/Consumer to de-couple extension from the ContentAction.
101 // |host_id| will be a part of Host/Consumer class.
98 RequestContentScript(content::BrowserContext* browser_context, 102 RequestContentScript(content::BrowserContext* browser_context,
103 const HostID& host_id,
99 const Extension* extension, 104 const Extension* extension,
100 const ScriptData& script_data); 105 const ScriptData& script_data);
101 RequestContentScript(DeclarativeUserScriptMaster* master, 106 RequestContentScript(DeclarativeUserScriptMaster* master,
107 const HostID& host_id,
102 const Extension* extension, 108 const Extension* extension,
103 const ScriptData& script_data); 109 const ScriptData& script_data);
104 110
105 static scoped_refptr<ContentAction> Create( 111 static scoped_refptr<ContentAction> Create(
106 content::BrowserContext* browser_context, 112 content::BrowserContext* browser_context,
113 const HostID& host_id,
107 const Extension* extension, 114 const Extension* extension,
108 const base::DictionaryValue* dict, 115 const base::DictionaryValue* dict,
109 std::string* error, 116 std::string* error,
110 bool* bad_message); 117 bool* bad_message);
111 118
112 static scoped_refptr<ContentAction> CreateForTest( 119 static scoped_refptr<ContentAction> CreateForTest(
113 DeclarativeUserScriptMaster* master, 120 DeclarativeUserScriptMaster* master,
121 const HostID& host_id,
114 const Extension* extension, 122 const Extension* extension,
115 const base::Value& json_action, 123 const base::Value& json_action,
116 std::string* error, 124 std::string* error,
117 bool* bad_message); 125 bool* bad_message);
118 126
119 static bool InitScriptData(const base::DictionaryValue* dict, 127 static bool InitScriptData(const base::DictionaryValue* dict,
120 std::string* error, 128 std::string* error,
121 bool* bad_message, 129 bool* bad_message,
122 ScriptData* script_data); 130 ScriptData* script_data);
123 131
124 // Implementation of ContentAction: 132 // Implementation of ContentAction:
125 Type GetType() const override; 133 Type GetType() const override;
126 134
127 void Apply(const std::string& extension_id, 135 void Apply(const std::string& extension_id,
128 const base::Time& extension_install_time, 136 const base::Time& extension_install_time,
129 ApplyInfo* apply_info) const override; 137 ApplyInfo* apply_info) const override;
130 138
131 void Reapply(const std::string& extension_id, 139 void Reapply(const std::string& extension_id,
132 const base::Time& extension_install_time, 140 const base::Time& extension_install_time,
133 ApplyInfo* apply_info) const override; 141 ApplyInfo* apply_info) const override;
134 142
135 void Revert(const std::string& extension_id, 143 void Revert(const std::string& extension_id,
136 const base::Time& extension_install_time, 144 const base::Time& extension_install_time,
137 ApplyInfo* apply_info) const override; 145 ApplyInfo* apply_info) const override;
138 146
139 private: 147 private:
140 void InitScript(const Extension* extension, const ScriptData& script_data); 148 void InitScript(const HostID& host_id,
149 const Extension* extension,
150 const ScriptData& script_data);
141 151
142 void AddScript() { 152 void AddScript() {
143 DCHECK(master_); 153 DCHECK(master_);
144 master_->AddScript(script_); 154 master_->AddScript(script_);
145 } 155 }
146 156
147 ~RequestContentScript() override; 157 ~RequestContentScript() override;
148 158
149 void InstructRenderProcessToInject(content::WebContents* contents, 159 void InstructRenderProcessToInject(content::WebContents* contents,
150 const std::string& extension_id) const; 160 const std::string& extension_id) const;
151 161
152 UserScript script_; 162 UserScript script_;
153 DeclarativeUserScriptMaster* master_; 163 DeclarativeUserScriptMaster* master_;
154 164
155 DISALLOW_COPY_AND_ASSIGN(RequestContentScript); 165 DISALLOW_COPY_AND_ASSIGN(RequestContentScript);
156 }; 166 };
157 167
158 typedef DeclarativeActionSet<ContentAction> ContentActionSet; 168 typedef DeclarativeActionSet<ContentAction> ContentActionSet;
159 169
160 } // namespace extensions 170 } // namespace extensions
161 171
162 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ 172 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698