Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 10420020: Made sure FilterEngine instances are always initialized (Closed)
Left Patch Set: Created May 16, 2013, 2:27 p.m.
Right Patch Set: Using a generic messaging mechanism Created May 23, 2013, 6:35 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/init.js ('k') | src/GlobalJsObject.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 130
131 bool Subscription::operator==(const Subscription& subscription) const 131 bool Subscription::operator==(const Subscription& subscription) const
132 { 132 {
133 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring(); 133 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring();
134 } 134 }
135 135
136 FilterEngine::FilterEngine(JsEnginePtr jsEngine) 136 FilterEngine::FilterEngine(JsEnginePtr jsEngine)
137 : jsEngine(jsEngine), initialized(false) 137 : jsEngine(jsEngine), initialized(false)
138 { 138 {
139 jsEngine->SetInitCallback(std::tr1::bind(&FilterEngine::InitDone, this)); 139 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, thi s));
140 for (int i = 0; !jsSources[i].empty(); i += 2) 140 for (int i = 0; !jsSources[i].empty(); i += 2)
141 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); 141 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]);
142 142
143 // TODO: This should really be implemented via a conditional variable 143 // TODO: This should really be implemented via a conditional variable
144 while (!initialized) 144 while (!initialized)
145 ::Sleep(10); 145 ::Sleep(10);
146 } 146 }
147 147
148 void FilterEngine::InitDone() 148 void FilterEngine::InitDone()
149 { 149 {
150 jsEngine->RemoveEventCallback("init");
150 initialized = true; 151 initialized = true;
151 } 152 }
152 153
153 FilterPtr FilterEngine::GetFilter(const std::string& text) 154 FilterPtr FilterEngine::GetFilter(const std::string& text)
154 { 155 {
155 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); 156 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText");
156 JsValueList params; 157 JsValueList params;
157 params.push_back(jsEngine->NewValue(text)); 158 params.push_back(jsEngine->NewValue(text));
158 return FilterPtr(new Filter(func->Call(params))); 159 return FilterPtr(new Filter(func->Call(params)));
159 } 160 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 { 217 {
217 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 218 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
218 JsValueList params; 219 JsValueList params;
219 params.push_back(jsEngine->NewValue(domain)); 220 params.push_back(jsEngine->NewValue(domain));
220 JsValueList result = func->Call(params)->AsList(); 221 JsValueList result = func->Call(params)->AsList();
221 std::vector<std::string> selectors; 222 std::vector<std::string> selectors;
222 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) 223 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it)
223 selectors.push_back((*it)->AsString()); 224 selectors.push_back((*it)->AsString());
224 return selectors; 225 return selectors;
225 } 226 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld