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

Side by Side Diff: chrome/common/extensions/user_script.h

Issue 339064: Add new user script injection point: document_idle. (Closed)
Patch Set: smaller, cleaner, better Created 11 years, 1 month 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 2009 The Chromium Authors. All rights reserved. 1 // Copyright 2009 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_COMMON_EXTENSIONS_USER_SCRIPT_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_
6 #define CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ 6 #define CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_
7 7
8 #include <vector> 8 #include <vector>
9 #include <string> 9 #include <string>
10 10
(...skipping 10 matching lines...) Expand all
21 class UserScript { 21 class UserScript {
22 public: 22 public:
23 typedef std::vector<URLPattern> PatternList; 23 typedef std::vector<URLPattern> PatternList;
24 24
25 // Locations that user scripts can be run inside the document. 25 // Locations that user scripts can be run inside the document.
26 enum RunLocation { 26 enum RunLocation {
27 DOCUMENT_START, // After the documentElemnet is created, but before 27 DOCUMENT_START, // After the documentElemnet is created, but before
28 // anything else happens. 28 // anything else happens.
29 DOCUMENT_END, // After the entire document is parsed. Same as 29 DOCUMENT_END, // After the entire document is parsed. Same as
30 // DOMContentLoaded. 30 // DOMContentLoaded.
31 DOCUMENT_IDLE, // Sometime after DOMContentLoaded, as soon as the document
32 // is "idle". Currently this uses the simple heuristic of:
33 // min(DOM_CONTENT_LOADED + TIMEOUT, ONLOAD), but no
34 // particular injection point is guaranteed.
31 35
32 RUN_LOCATION_LAST // Leave this as the last item. 36 RUN_LOCATION_LAST // Leave this as the last item.
33 }; 37 };
34 38
35 // Holds actual script file info. 39 // Holds actual script file info.
36 class File { 40 class File {
37 public: 41 public:
38 File(const FilePath& extension_root, const FilePath& relative_path, 42 File(const FilePath& extension_root, const FilePath& relative_path,
39 const GURL& url): 43 const GURL& url):
40 extension_root_(extension_root), 44 extension_root_(extension_root),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // The script content. It can be set to either loaded_content_ or 85 // The script content. It can be set to either loaded_content_ or
82 // externally allocated string. 86 // externally allocated string.
83 base::StringPiece external_content_; 87 base::StringPiece external_content_;
84 88
85 // Set when the content is loaded by LoadContent 89 // Set when the content is loaded by LoadContent
86 std::string content_; 90 std::string content_;
87 }; 91 };
88 92
89 typedef std::vector<File> FileList; 93 typedef std::vector<File> FileList;
90 94
91 // Constructor. Default the run location to document end, which is like 95 // Constructor. Default the run location to document idle, which is similar
92 // Greasemonkey and probably more useful for typical scripts. 96 // to Greasemonkey but should result in better page load times for fast-
93 UserScript() : run_location_(DOCUMENT_END) {} 97 // loading pages.
98 UserScript() : run_location_(DOCUMENT_IDLE) {}
94 99
95 // The place in the document to run the script. 100 // The place in the document to run the script.
96 RunLocation run_location() const { return run_location_; } 101 RunLocation run_location() const { return run_location_; }
97 void set_run_location(RunLocation location) { run_location_ = location; } 102 void set_run_location(RunLocation location) { run_location_ = location; }
98 103
99 // The globs, if any, that determine which pages this script runs against. 104 // The globs, if any, that determine which pages this script runs against.
100 // These are only used with "standalone" Greasemonkey-like user scripts. 105 // These are only used with "standalone" Greasemonkey-like user scripts.
101 const std::vector<std::string>& globs() const { return globs_; } 106 const std::vector<std::string>& globs() const { return globs_; }
102 void add_glob(const std::string& glob) { globs_.push_back(glob); } 107 void add_glob(const std::string& glob) { globs_.push_back(glob); }
103 void clear_globs() { globs_.clear(); } 108 void clear_globs() { globs_.clear(); }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 FileList css_scripts_; 160 FileList css_scripts_;
156 161
157 // The ID of the extension this script is a part of, if any. Can be empty if 162 // The ID of the extension this script is a part of, if any. Can be empty if
158 // the script is a "standlone" user script. 163 // the script is a "standlone" user script.
159 std::string extension_id_; 164 std::string extension_id_;
160 }; 165 };
161 166
162 typedef std::vector<UserScript> UserScriptList; 167 typedef std::vector<UserScript> UserScriptList;
163 168
164 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ 169 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698