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

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

Issue 19624: Add early-injection capability to user scripts. I haven't yet (Closed)
Patch Set: Use new documentElementAvailable() callback Created 11 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 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 #include "chrome/common/extensions/user_script.h" 5 #include "chrome/common/extensions/user_script.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 8
9 bool UserScript::MatchesUrl(const GURL& url) { 9 bool UserScript::MatchesUrl(const GURL& url) {
10 for (std::vector<std::string>::iterator glob = globs_.begin(); 10 for (std::vector<std::string>::iterator glob = globs_.begin();
11 glob != globs_.end(); ++glob) { 11 glob != globs_.end(); ++glob) {
12 if (MatchPattern(url.spec(), *glob)) 12 if (MatchPattern(url.spec(), *glob))
13 return true; 13 return true;
14 } 14 }
15 15
16 for (std::vector<URLPattern>::iterator pattern = url_patterns_.begin(); 16 for (std::vector<URLPattern>::iterator pattern = url_patterns_.begin();
17 pattern != url_patterns_.end(); ++pattern) { 17 pattern != url_patterns_.end(); ++pattern) {
18 if (pattern->MatchesUrl(url)) 18 if (pattern->MatchesUrl(url))
19 return true; 19 return true;
20 } 20 }
21 21
22 return false; 22 return false;
23 } 23 }
24 24
25 void UserScript::Pickle(::Pickle* pickle) { 25 void UserScript::Pickle(::Pickle* pickle) {
26 pickle->WriteString(url_.spec()); 26 pickle->WriteString(url_.spec());
27 pickle->WriteInt(run_location_);
27 28
28 // Don't write path as we don't need that in the renderer. 29 // Don't write path as we don't need that in the renderer.
29 30
30 pickle->WriteSize(globs_.size()); 31 pickle->WriteSize(globs_.size());
31 for (std::vector<std::string>::iterator glob = globs_.begin(); 32 for (std::vector<std::string>::iterator glob = globs_.begin();
32 glob != globs_.end(); ++glob) { 33 glob != globs_.end(); ++glob) {
33 pickle->WriteString(*glob); 34 pickle->WriteString(*glob);
34 } 35 }
35 36
36 pickle->WriteSize(url_patterns_.size()); 37 pickle->WriteSize(url_patterns_.size());
37 for (std::vector<URLPattern>::iterator pattern = url_patterns_.begin(); 38 for (std::vector<URLPattern>::iterator pattern = url_patterns_.begin();
38 pattern != url_patterns_.end(); ++pattern) { 39 pattern != url_patterns_.end(); ++pattern) {
39 pickle->WriteString(pattern->GetAsString()); 40 pickle->WriteString(pattern->GetAsString());
40 } 41 }
41 } 42 }
42 43
43 void UserScript::Unpickle(const ::Pickle& pickle, void** iter) { 44 void UserScript::Unpickle(const ::Pickle& pickle, void** iter) {
44 std::string url_spec; 45 std::string url_spec;
45 CHECK(pickle.ReadString(iter, &url_spec)); 46 CHECK(pickle.ReadString(iter, &url_spec));
46 url_ = GURL(url_spec); 47 url_ = GURL(url_spec);
47 48
49 int run_location = 0;
50 CHECK(pickle.ReadInt(iter, &run_location));
51 CHECK(run_location >= 0 && run_location < UserScript::RUN_LOCATION_LAST);
52 run_location_ = static_cast<UserScript::RunLocation>(run_location);
53
48 size_t num_globs = 0; 54 size_t num_globs = 0;
49 CHECK(pickle.ReadSize(iter, &num_globs)); 55 CHECK(pickle.ReadSize(iter, &num_globs));
50 56
51 globs_.clear(); 57 globs_.clear();
52 for (size_t i = 0; i < num_globs; ++i) { 58 for (size_t i = 0; i < num_globs; ++i) {
53 std::string glob; 59 std::string glob;
54 CHECK(pickle.ReadString(iter, &glob)); 60 CHECK(pickle.ReadString(iter, &glob));
55 globs_.push_back(glob); 61 globs_.push_back(glob);
56 } 62 }
57 63
58 size_t num_patterns = 0; 64 size_t num_patterns = 0;
59 CHECK(pickle.ReadSize(iter, &num_patterns)); 65 CHECK(pickle.ReadSize(iter, &num_patterns));
60 66
61 url_patterns_.clear(); 67 url_patterns_.clear();
62 for (size_t i = 0; i < num_patterns; ++i) { 68 for (size_t i = 0; i < num_patterns; ++i) {
63 std::string pattern_str; 69 std::string pattern_str;
64 URLPattern pattern; 70 URLPattern pattern;
65 CHECK(pickle.ReadString(iter, &pattern_str)); 71 CHECK(pickle.ReadString(iter, &pattern_str));
66 CHECK(pattern.Parse(pattern_str)); 72 CHECK(pattern.Parse(pattern_str));
67 url_patterns_.push_back(pattern); 73 url_patterns_.push_back(pattern);
68 } 74 }
69 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698