| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/services/html_viewer/mock_web_blob_registry_impl.h" | |
| 6 | |
| 7 #include "third_party/WebKit/public/platform/WebBlobData.h" | |
| 8 #include "third_party/WebKit/public/platform/WebString.h" | |
| 9 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 10 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 11 | |
| 12 using blink::WebBlobData; | |
| 13 using blink::WebString; | |
| 14 using blink::WebURL; | |
| 15 using blink::WebVector; | |
| 16 | |
| 17 namespace html_viewer { | |
| 18 | |
| 19 MockWebBlobRegistryImpl::MockWebBlobRegistryImpl() { | |
| 20 } | |
| 21 | |
| 22 MockWebBlobRegistryImpl::~MockWebBlobRegistryImpl() { | |
| 23 } | |
| 24 | |
| 25 void MockWebBlobRegistryImpl::registerBlobData(const WebString& uuid, | |
| 26 const WebBlobData& data) { | |
| 27 const std::string uuid_str(uuid.utf8()); | |
| 28 blob_ref_count_map_[uuid_str] = 1; | |
| 29 scoped_ptr<ScopedVector<blink::WebBlobData::Item>> items( | |
| 30 new ScopedVector<blink::WebBlobData::Item>); | |
| 31 items->reserve(data.itemCount()); | |
| 32 for (size_t i = 0; i < data.itemCount(); ++i) { | |
| 33 scoped_ptr<blink::WebBlobData::Item> item(new blink::WebBlobData::Item); | |
| 34 data.itemAt(i, *item); | |
| 35 items->push_back(item.release()); | |
| 36 } | |
| 37 blob_data_items_map_.set(uuid_str, items.Pass()); | |
| 38 } | |
| 39 | |
| 40 void MockWebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) { | |
| 41 blob_ref_count_map_[uuid.utf8()]++; | |
| 42 } | |
| 43 | |
| 44 void MockWebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) { | |
| 45 const std::string uuid_str(uuid.utf8()); | |
| 46 auto it = blob_ref_count_map_.find(uuid_str); | |
| 47 if (it != blob_ref_count_map_.end() && !--it->second) { | |
| 48 blob_data_items_map_.erase(uuid_str); | |
| 49 blob_ref_count_map_.erase(it); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void MockWebBlobRegistryImpl::registerPublicBlobURL(const WebURL& url, | |
| 54 const WebString& uuid) { | |
| 55 public_url_to_uuid_[url.spec()] = uuid; | |
| 56 addBlobDataRef(uuid); | |
| 57 } | |
| 58 | |
| 59 void MockWebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { | |
| 60 auto it = public_url_to_uuid_.find(url.spec()); | |
| 61 if (it != public_url_to_uuid_.end()) { | |
| 62 removeBlobDataRef(it->second); | |
| 63 public_url_to_uuid_.erase(it); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void MockWebBlobRegistryImpl::registerStreamURL(const WebURL& url, | |
| 68 const WebString& content_type) { | |
| 69 NOTIMPLEMENTED(); | |
| 70 } | |
| 71 | |
| 72 void MockWebBlobRegistryImpl::registerStreamURL(const WebURL& url, | |
| 73 const blink::WebURL& src_url) { | |
| 74 NOTIMPLEMENTED(); | |
| 75 } | |
| 76 | |
| 77 void MockWebBlobRegistryImpl::addDataToStream(const WebURL& url, | |
| 78 const char* data, | |
| 79 size_t length) { | |
| 80 NOTIMPLEMENTED(); | |
| 81 } | |
| 82 | |
| 83 void MockWebBlobRegistryImpl::flushStream(const WebURL& url) { | |
| 84 NOTIMPLEMENTED(); | |
| 85 } | |
| 86 | |
| 87 void MockWebBlobRegistryImpl::finalizeStream(const WebURL& url) { | |
| 88 NOTIMPLEMENTED(); | |
| 89 } | |
| 90 | |
| 91 void MockWebBlobRegistryImpl::abortStream(const WebURL& url) { | |
| 92 NOTIMPLEMENTED(); | |
| 93 } | |
| 94 | |
| 95 void MockWebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { | |
| 96 NOTIMPLEMENTED(); | |
| 97 } | |
| 98 | |
| 99 bool MockWebBlobRegistryImpl::GetUUIDForURL(const blink::WebURL& url, | |
| 100 blink::WebString* uuid) const { | |
| 101 auto it = public_url_to_uuid_.find(url.spec()); | |
| 102 if (it != public_url_to_uuid_.end()) { | |
| 103 *uuid = it->second; | |
| 104 return true; | |
| 105 } | |
| 106 | |
| 107 return false; | |
| 108 } | |
| 109 | |
| 110 bool MockWebBlobRegistryImpl::GetBlobItems( | |
| 111 const WebString& uuid, | |
| 112 WebVector<WebBlobData::Item*>* items) const { | |
| 113 ScopedVector<WebBlobData::Item>* item_vector = | |
| 114 blob_data_items_map_.get(uuid.utf8()); | |
| 115 if (!item_vector) | |
| 116 return false; | |
| 117 *items = item_vector->get(); | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 } // namespace html_viewer | |
| OLD | NEW |