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

Side by Side Diff: chrome/renderer/user_script_slave.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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/renderer/user_script_slave.h" 5 #include "chrome/renderer/user_script_slave.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
10 #include "chrome/common/resource_bundle.h" 10 #include "chrome/common/resource_bundle.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 int body_length = 0; 80 int body_length = 0;
81 CHECK(pickle.ReadData(&iter, &body, &body_length)); 81 CHECK(pickle.ReadData(&iter, &body, &body_length));
82 82
83 scripts_.push_back(script); 83 scripts_.push_back(script);
84 script_contents_[script] = StringPiece(body, body_length); 84 script_contents_[script] = StringPiece(body, body_length);
85 } 85 }
86 86
87 return true; 87 return true;
88 } 88 }
89 89
90 bool UserScriptSlave::InjectScripts(WebFrame* frame) { 90 bool UserScriptSlave::InjectScripts(WebFrame* frame,
91 UserScript::RunLocation location) {
91 for (std::vector<UserScript*>::iterator script = scripts_.begin(); 92 for (std::vector<UserScript*>::iterator script = scripts_.begin();
92 script != scripts_.end(); ++script) { 93 script != scripts_.end(); ++script) {
93 if ((*script)->MatchesUrl(frame->GetURL())) { 94 if ((*script)->MatchesUrl(frame->GetURL()) &&
95 (*script)->run_location() == location) {
94 std::string inject(kUserScriptHead); 96 std::string inject(kUserScriptHead);
95 inject.append(api_js_.as_string()); 97 inject.append(api_js_.as_string());
96 inject.append(script_contents_[*script].as_string()); 98 inject.append(script_contents_[*script].as_string());
97 inject.append(kUserScriptTail); 99 inject.append(kUserScriptTail);
98 frame->ExecuteJavaScript(inject, 100 frame->ExecuteJavaScript(inject,
99 GURL((*script)->url().spec()), 101 GURL((*script)->url().spec()),
100 -user_script_start_line_); 102 -user_script_start_line_);
101 } 103 }
102 } 104 }
103 105
104 return true; 106 return true;
105 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698