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

Delta Between Two Patch Sets: shell/src/Main.cpp

Issue 10198022: Pass application data into libadblockplus (Closed)
Left Patch Set: Created April 12, 2013, 1:23 p.m.
Right Patch Set: Merged upstream, addressed issues, renamed AppInfo fields Created April 17, 2013, 2:47 p.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
LEFTRIGHT
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <fstream>
3 #include <iostream> 2 #include <iostream>
4 #include <sstream> 3 #include <sstream>
5 4
6 #include "GcCommand.h" 5 #include "GcCommand.h"
7 #include "HelpCommand.h" 6 #include "HelpCommand.h"
8 #include "FiltersCommand.h" 7 #include "FiltersCommand.h"
9 #include "SubscriptionsCommand.h" 8 #include "SubscriptionsCommand.h"
10 #include "MatchesCommand.h" 9 #include "MatchesCommand.h"
11 10
12 namespace 11 namespace
13 { 12 {
14 class LibFileReader : public AdblockPlus::FileReader
15 {
16 public:
17 std::auto_ptr<std::istream> Read(const std::string& path) const
18 {
19 std::ifstream* file = new std::ifstream;
20 file->open(("lib/" + path).c_str());
21 return std::auto_ptr<std::istream>(file);
22 }
23 };
24
25 class CerrErrorCallback : public AdblockPlus::ErrorCallback 13 class CerrErrorCallback : public AdblockPlus::ErrorCallback
26 { 14 {
27 public: 15 public:
28 void operator()(const std::string& message) 16 void operator()(const std::string& message)
29 { 17 {
30 std::cerr << "Error: " << message << std::endl; 18 std::cerr << "Error: " << message << std::endl;
31 } 19 }
32 }; 20 };
33 21
34 void Add(CommandMap& commands, Command* command) 22 void Add(CommandMap& commands, Command* command)
(...skipping 16 matching lines...) Expand all
51 std::istringstream lineStream(commandLine); 39 std::istringstream lineStream(commandLine);
52 lineStream >> name; 40 lineStream >> name;
53 std::getline(lineStream, arguments); 41 std::getline(lineStream, arguments);
54 } 42 }
55 } 43 }
56 44
57 int main() 45 int main()
58 { 46 {
59 try 47 try
60 { 48 {
61 LibFileReader fileReader; 49 AdblockPlus::DefaultFileSystem fileSystem;
62 AdblockPlus::DefaultWebRequest webRequest; 50 AdblockPlus::DefaultWebRequest webRequest;
63 CerrErrorCallback errorCallback; 51 CerrErrorCallback errorCallback;
64 AdblockPlus::AppInfo appInfo; 52 AdblockPlus::AppInfo appInfo;
65 appInfo.addonVersion = "1.0"; 53 appInfo.version = "1.0";
66 appInfo.addonName = "Adblock Plus Shell"; 54 appInfo.name = "Adblock Plus Shell";
67 appInfo.application = "abpshell"; 55 AdblockPlus::JsEngine jsEngine(appInfo, &fileSystem, &webRequest,
68 AdblockPlus::JsEngine jsEngine(appInfo, &fileReader, &webRequest,
69 &errorCallback); 56 &errorCallback);
70 AdblockPlus::FilterEngine filterEngine(jsEngine); 57 AdblockPlus::FilterEngine filterEngine(jsEngine);
71 58
72 CommandMap commands; 59 CommandMap commands;
73 Add(commands, new GcCommand(jsEngine)); 60 Add(commands, new GcCommand(jsEngine));
74 Add(commands, new HelpCommand(commands)); 61 Add(commands, new HelpCommand(commands));
75 Add(commands, new FiltersCommand(filterEngine)); 62 Add(commands, new FiltersCommand(filterEngine));
76 Add(commands, new SubscriptionsCommand(filterEngine)); 63 Add(commands, new SubscriptionsCommand(filterEngine));
77 Add(commands, new MatchesCommand(filterEngine)); 64 Add(commands, new MatchesCommand(filterEngine));
78 65
(...skipping 16 matching lines...) Expand all
95 std::cout << error.what() << std::endl; 82 std::cout << error.what() << std::endl;
96 } 83 }
97 } 84 }
98 } 85 }
99 catch (const std::exception& e) 86 catch (const std::exception& e)
100 { 87 {
101 std::cerr << "Exception: " << e.what() << std::endl; 88 std::cerr << "Exception: " << e.what() << std::endl;
102 } 89 }
103 return 0; 90 return 0;
104 } 91 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld