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

Side by Side Diff: chrome/renderer/user_script_slave.cc

Issue 193072: Move StringPiece into the base namespace. It is colliding (Closed)
Patch Set: take 2 Created 11 years, 3 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
« no previous file with comments | « chrome/renderer/user_script_slave.h ('k') | chrome/test/v8_unit_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/histogram.h" 8 #include "base/histogram.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/perftimer.h" 10 #include "base/perftimer.h"
(...skipping 24 matching lines...) Expand all
35 "chrome.self.onConnect = chrome.extension.onConnect;"; 35 "chrome.self.onConnect = chrome.extension.onConnect;";
36 36
37 UserScriptSlave::UserScriptSlave() 37 UserScriptSlave::UserScriptSlave()
38 : shared_memory_(NULL), 38 : shared_memory_(NULL),
39 script_deleter_(&scripts_), 39 script_deleter_(&scripts_),
40 user_script_start_line_(0) { 40 user_script_start_line_(0) {
41 api_js_ = ResourceBundle::GetSharedInstance().GetRawDataResource( 41 api_js_ = ResourceBundle::GetSharedInstance().GetRawDataResource(
42 IDR_GREASEMONKEY_API_JS); 42 IDR_GREASEMONKEY_API_JS);
43 43
44 // Count the number of lines that will be injected before the user script. 44 // Count the number of lines that will be injected before the user script.
45 StringPiece::size_type pos = 0; 45 base::StringPiece::size_type pos = 0;
46 while ((pos = api_js_.find('\n', pos)) != StringPiece::npos) { 46 while ((pos = api_js_.find('\n', pos)) != base::StringPiece::npos) {
47 user_script_start_line_++; 47 user_script_start_line_++;
48 pos++; 48 pos++;
49 } 49 }
50 50
51 // NOTE: There is actually one extra line in the injected script because the 51 // NOTE: There is actually one extra line in the injected script because the
52 // function header includes a newline as well. But WebKit expects the 52 // function header includes a newline as well. But WebKit expects the
53 // numbering to be one-based, not zero-based, so actually *not* accounting for 53 // numbering to be one-based, not zero-based, so actually *not* accounting for
54 // this extra line ends us up with the right offset. 54 // this extra line ends us up with the right offset.
55 } 55 }
56 56
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 script->Unpickle(pickle, &iter); 88 script->Unpickle(pickle, &iter);
89 89
90 // Note that this is a pointer into shared memory. We don't own it. It gets 90 // Note that this is a pointer into shared memory. We don't own it. It gets
91 // cleared up when the last renderer or browser process drops their 91 // cleared up when the last renderer or browser process drops their
92 // reference to the shared memory. 92 // reference to the shared memory.
93 for (size_t j = 0; j < script->js_scripts().size(); ++j) { 93 for (size_t j = 0; j < script->js_scripts().size(); ++j) {
94 const char* body = NULL; 94 const char* body = NULL;
95 int body_length = 0; 95 int body_length = 0;
96 CHECK(pickle.ReadData(&iter, &body, &body_length)); 96 CHECK(pickle.ReadData(&iter, &body, &body_length));
97 script->js_scripts()[j].set_external_content( 97 script->js_scripts()[j].set_external_content(
98 StringPiece(body, body_length)); 98 base::StringPiece(body, body_length));
99 } 99 }
100 for (size_t j = 0; j < script->css_scripts().size(); ++j) { 100 for (size_t j = 0; j < script->css_scripts().size(); ++j) {
101 const char* body = NULL; 101 const char* body = NULL;
102 int body_length = 0; 102 int body_length = 0;
103 CHECK(pickle.ReadData(&iter, &body, &body_length)); 103 CHECK(pickle.ReadData(&iter, &body, &body_length));
104 script->css_scripts()[j].set_external_content( 104 script->css_scripts()[j].set_external_content(
105 StringPiece(body, body_length)); 105 base::StringPiece(body, body_length));
106 } 106 }
107 } 107 }
108 108
109 return true; 109 return true;
110 } 110 }
111 111
112 bool UserScriptSlave::InjectScripts(WebFrame* frame, 112 bool UserScriptSlave::InjectScripts(WebFrame* frame,
113 UserScript::RunLocation location) { 113 UserScript::RunLocation location) {
114 // Don't bother if this is not a URL we inject script into. 114 // Don't bother if this is not a URL we inject script into.
115 if (!URLPattern::IsValidScheme(GURL(frame->url()).scheme())) 115 if (!URLPattern::IsValidScheme(GURL(frame->url()).scheme()))
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 HISTOGRAM_TIMES("UserScripts:DocStart:Time", timer.Elapsed()); 173 HISTOGRAM_TIMES("UserScripts:DocStart:Time", timer.Elapsed());
174 } else { 174 } else {
175 HISTOGRAM_COUNTS_100("UserScripts:DocEnd:Count", num_matched); 175 HISTOGRAM_COUNTS_100("UserScripts:DocEnd:Count", num_matched);
176 HISTOGRAM_TIMES("UserScripts:DocEnd:Time", timer.Elapsed()); 176 HISTOGRAM_TIMES("UserScripts:DocEnd:Time", timer.Elapsed());
177 } 177 }
178 178
179 LOG(INFO) << "Injected " << num_matched << " user scripts into " << 179 LOG(INFO) << "Injected " << num_matched << " user scripts into " <<
180 frame->url().spec().data(); 180 frame->url().spec().data();
181 return true; 181 return true;
182 } 182 }
OLDNEW
« no previous file with comments | « chrome/renderer/user_script_slave.h ('k') | chrome/test/v8_unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698