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

Unified Diff: src/shared/ContentType.cpp

Issue 5316782940225536: Issue 1557 - Update to the recent libadblockplus to reduce additional updates in the logic later. (Closed)
Patch Set: fix according to the comments Created Jan. 28, 2015, 1:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/shared/ContentType.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/shared/ContentType.cpp
diff --git a/src/shared/ContentType.cpp b/src/shared/ContentType.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9cf58c2af29bf0d51504adedd0f7f16817c8c1d4
--- /dev/null
+++ b/src/shared/ContentType.cpp
@@ -0,0 +1,54 @@
+#include "ContentType.h"
+
+// Based on impl from libadblockplus
+
+using AdblockPlus::FilterEngine;
+
+namespace
+{
+ typedef std::map<FilterEngine::ContentType, std::string> ContentTypeMap;
+ ContentTypeMap CreateContentTypeMap()
+ {
+ ContentTypeMap contentTypes;
+ contentTypes[FilterEngine::CONTENT_TYPE_OTHER] = "OTHER";
+ contentTypes[FilterEngine::CONTENT_TYPE_SCRIPT] = "SCRIPT";
+ contentTypes[FilterEngine::CONTENT_TYPE_IMAGE] = "IMAGE";
+ contentTypes[FilterEngine::CONTENT_TYPE_STYLESHEET] = "STYLESHEET";
+ contentTypes[FilterEngine::CONTENT_TYPE_OBJECT] = "OBJECT";
+ contentTypes[FilterEngine::CONTENT_TYPE_SUBDOCUMENT] = "SUBDOCUMENT";
+ contentTypes[FilterEngine::CONTENT_TYPE_DOCUMENT] = "DOCUMENT";
+ contentTypes[FilterEngine::CONTENT_TYPE_XMLHTTPREQUEST] = "XMLHTTPREQUEST";
+ contentTypes[FilterEngine::CONTENT_TYPE_OBJECT_SUBREQUEST] = "OBJECT_SUBREQUEST";
+ contentTypes[FilterEngine::CONTENT_TYPE_FONT] = "FONT";
+ contentTypes[FilterEngine::CONTENT_TYPE_MEDIA] = "MEDIA";
+ contentTypes[FilterEngine::CONTENT_TYPE_ELEMHIDE] = "ELEMHIDE";
+ return contentTypes;
+ }
+ const ContentTypeMap g_contentTypes = CreateContentTypeMap();
+}
+
+std::string ContentTypeToString(AdblockPlus::FilterEngine::ContentType contentType)
+{
+ ContentTypeMap::const_iterator it = g_contentTypes.find(contentType);
+ if (it != g_contentTypes.end())
+ return it->second;
+ throw std::invalid_argument("Argument is not a valid ContentType");
+}
+
+#include "Communication.h"
+
+using Communication::InputBuffer;
+using Communication::OutputBuffer;
+
+InputBuffer& operator>>(InputBuffer& in, FilterEngine::ContentType& contentType)
+{
+ int32_t type;
+ in >> type;
+ contentType = static_cast<FilterEngine::ContentType>(contentType);
+ return in;
+}
+
+OutputBuffer& operator<<(OutputBuffer& out, FilterEngine::ContentType contentType)
+{
+ return out << static_cast<int32_t>(contentType);
+}
« no previous file with comments | « src/shared/ContentType.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld