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

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: Clean up. 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
98 RequestContentScript(content::BrowserContext* browser_context, 99 RequestContentScript(content::BrowserContext* browser_context,
100 const HostID& host_id,
Devlin 2015/01/27 22:06:39 This still kind of makes me sad that we plumb thes
99 const Extension* extension, 101 const Extension* extension,
100 const ScriptData& script_data); 102 const ScriptData& script_data);
101 RequestContentScript(DeclarativeUserScriptMaster* master, 103 RequestContentScript(DeclarativeUserScriptMaster* master,
104 const HostID& host_id,
102 const Extension* extension, 105 const Extension* extension,
103 const ScriptData& script_data); 106 const ScriptData& script_data);
104 107
105 static scoped_refptr<ContentAction> Create( 108 static scoped_refptr<ContentAction> Create(
106 content::BrowserContext* browser_context, 109 content::BrowserContext* browser_context,
110 const HostID& host_id,
107 const Extension* extension, 111 const Extension* extension,
108 const base::DictionaryValue* dict, 112 const base::DictionaryValue* dict,
109 std::string* error, 113 std::string* error,
110 bool* bad_message); 114 bool* bad_message);
111 115
112 static scoped_refptr<ContentAction> CreateForTest( 116 static scoped_refptr<ContentAction> CreateForTest(
113 DeclarativeUserScriptMaster* master, 117 DeclarativeUserScriptMaster* master,
118 const HostID& host_id,
114 const Extension* extension, 119 const Extension* extension,
115 const base::Value& json_action, 120 const base::Value& json_action,
116 std::string* error, 121 std::string* error,
117 bool* bad_message); 122 bool* bad_message);
118 123
119 static bool InitScriptData(const base::DictionaryValue* dict, 124 static bool InitScriptData(const base::DictionaryValue* dict,
120 std::string* error, 125 std::string* error,
121 bool* bad_message, 126 bool* bad_message,
122 ScriptData* script_data); 127 ScriptData* script_data);
123 128
124 // Implementation of ContentAction: 129 // Implementation of ContentAction:
125 Type GetType() const override; 130 Type GetType() const override;
126 131
127 void Apply(const std::string& extension_id, 132 void Apply(const std::string& extension_id,
128 const base::Time& extension_install_time, 133 const base::Time& extension_install_time,
129 ApplyInfo* apply_info) const override; 134 ApplyInfo* apply_info) const override;
130 135
131 void Reapply(const std::string& extension_id, 136 void Reapply(const std::string& extension_id,
132 const base::Time& extension_install_time, 137 const base::Time& extension_install_time,
133 ApplyInfo* apply_info) const override; 138 ApplyInfo* apply_info) const override;
134 139
135 void Revert(const std::string& extension_id, 140 void Revert(const std::string& extension_id,
136 const base::Time& extension_install_time, 141 const base::Time& extension_install_time,
137 ApplyInfo* apply_info) const override; 142 ApplyInfo* apply_info) const override;
138 143
139 private: 144 private:
140 void InitScript(const Extension* extension, const ScriptData& script_data); 145 void InitScript(const HostID& host_id,
146 const Extension* extension,
147 const ScriptData& script_data);
141 148
142 void AddScript() { 149 void AddScript() {
143 DCHECK(master_); 150 DCHECK(master_);
144 master_->AddScript(script_); 151 master_->AddScript(script_);
145 } 152 }
146 153
147 ~RequestContentScript() override; 154 ~RequestContentScript() override;
148 155
149 void InstructRenderProcessToInject(content::WebContents* contents, 156 void InstructRenderProcessToInject(content::WebContents* contents,
150 const std::string& extension_id) const; 157 const std::string& extension_id) const;
151 158
152 UserScript script_; 159 UserScript script_;
153 DeclarativeUserScriptMaster* master_; 160 DeclarativeUserScriptMaster* master_;
154 161
155 DISALLOW_COPY_AND_ASSIGN(RequestContentScript); 162 DISALLOW_COPY_AND_ASSIGN(RequestContentScript);
156 }; 163 };
157 164
158 typedef DeclarativeActionSet<ContentAction> ContentActionSet; 165 typedef DeclarativeActionSet<ContentAction> ContentActionSet;
159 166
160 } // namespace extensions 167 } // namespace extensions
161 168
162 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ 169 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698