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

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

Issue 899983002: Revert of 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: rebase Created 5 years, 10 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,
71 const Extension* extension, 70 const Extension* extension,
72 const base::Value& json_action, 71 const base::Value& json_action,
73 std::string* error, 72 std::string* error,
74 bool* bad_message); 73 bool* bad_message);
75 74
76 // Shared procedure for resetting error state within factories. 75 // Shared procedure for resetting error state within factories.
77 static void ResetErrorData(std::string* error, bool* bad_message) { 76 static void ResetErrorData(std::string* error, bool* bad_message) {
78 *error = ""; 77 *error = "";
79 *bad_message = false; 78 *bad_message = false;
80 } 79 }
81 80
82 // Shared procedure for validating JSON data. 81 // Shared procedure for validating JSON data.
83 static bool Validate(const base::Value& json_action, 82 static bool Validate(const base::Value& json_action,
84 std::string* error, 83 std::string* error,
85 bool* bad_message, 84 bool* bad_message,
86 const base::DictionaryValue** action_dict, 85 const base::DictionaryValue** action_dict,
87 std::string* instance_type); 86 std::string* instance_type);
88 87
89 protected: 88 protected:
90 friend class base::RefCounted<ContentAction>; 89 friend class base::RefCounted<ContentAction>;
91 virtual ~ContentAction(); 90 virtual ~ContentAction();
92 }; 91 };
93 92
94 // Action that injects a content script. 93 // Action that injects a content script.
95 class RequestContentScript : public ContentAction { 94 class RequestContentScript : public ContentAction {
96 public: 95 public:
97 struct ScriptData; 96 struct ScriptData;
98 97
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.
102 RequestContentScript(content::BrowserContext* browser_context, 98 RequestContentScript(content::BrowserContext* browser_context,
103 const HostID& host_id,
104 const Extension* extension, 99 const Extension* extension,
105 const ScriptData& script_data); 100 const ScriptData& script_data);
106 RequestContentScript(DeclarativeUserScriptMaster* master, 101 RequestContentScript(DeclarativeUserScriptMaster* master,
107 const HostID& host_id,
108 const Extension* extension, 102 const Extension* extension,
109 const ScriptData& script_data); 103 const ScriptData& script_data);
110 104
111 static scoped_refptr<ContentAction> Create( 105 static scoped_refptr<ContentAction> Create(
112 content::BrowserContext* browser_context, 106 content::BrowserContext* browser_context,
113 const HostID& host_id,
114 const Extension* extension, 107 const Extension* extension,
115 const base::DictionaryValue* dict, 108 const base::DictionaryValue* dict,
116 std::string* error, 109 std::string* error,
117 bool* bad_message); 110 bool* bad_message);
118 111
119 static scoped_refptr<ContentAction> CreateForTest( 112 static scoped_refptr<ContentAction> CreateForTest(
120 DeclarativeUserScriptMaster* master, 113 DeclarativeUserScriptMaster* master,
121 const HostID& host_id,
122 const Extension* extension, 114 const Extension* extension,
123 const base::Value& json_action, 115 const base::Value& json_action,
124 std::string* error, 116 std::string* error,
125 bool* bad_message); 117 bool* bad_message);
126 118
127 static bool InitScriptData(const base::DictionaryValue* dict, 119 static bool InitScriptData(const base::DictionaryValue* dict,
128 std::string* error, 120 std::string* error,
129 bool* bad_message, 121 bool* bad_message,
130 ScriptData* script_data); 122 ScriptData* script_data);
131 123
132 // Implementation of ContentAction: 124 // Implementation of ContentAction:
133 Type GetType() const override; 125 Type GetType() const override;
134 126
135 void Apply(const std::string& extension_id, 127 void Apply(const std::string& extension_id,
136 const base::Time& extension_install_time, 128 const base::Time& extension_install_time,
137 ApplyInfo* apply_info) const override; 129 ApplyInfo* apply_info) const override;
138 130
139 void Reapply(const std::string& extension_id, 131 void Reapply(const std::string& extension_id,
140 const base::Time& extension_install_time, 132 const base::Time& extension_install_time,
141 ApplyInfo* apply_info) const override; 133 ApplyInfo* apply_info) const override;
142 134
143 void Revert(const std::string& extension_id, 135 void Revert(const std::string& extension_id,
144 const base::Time& extension_install_time, 136 const base::Time& extension_install_time,
145 ApplyInfo* apply_info) const override; 137 ApplyInfo* apply_info) const override;
146 138
147 private: 139 private:
148 void InitScript(const HostID& host_id, 140 void InitScript(const Extension* extension, const ScriptData& script_data);
149 const Extension* extension,
150 const ScriptData& script_data);
151 141
152 void AddScript() { 142 void AddScript() {
153 DCHECK(master_); 143 DCHECK(master_);
154 master_->AddScript(script_); 144 master_->AddScript(script_);
155 } 145 }
156 146
157 ~RequestContentScript() override; 147 ~RequestContentScript() override;
158 148
159 void InstructRenderProcessToInject(content::WebContents* contents, 149 void InstructRenderProcessToInject(content::WebContents* contents,
160 const std::string& extension_id) const; 150 const std::string& extension_id) const;
161 151
162 UserScript script_; 152 UserScript script_;
163 DeclarativeUserScriptMaster* master_; 153 DeclarativeUserScriptMaster* master_;
164 154
165 DISALLOW_COPY_AND_ASSIGN(RequestContentScript); 155 DISALLOW_COPY_AND_ASSIGN(RequestContentScript);
166 }; 156 };
167 157
168 typedef DeclarativeActionSet<ContentAction> ContentActionSet; 158 typedef DeclarativeActionSet<ContentAction> ContentActionSet;
169 159
170 } // namespace extensions 160 } // namespace extensions
171 161
172 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ 162 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698