summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorerg <erg@chromium.org>2015-04-22 12:40:35 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-22 19:40:39 +0000
commit2c7c723477f83a3ae5fae494948c24163fd3aa0e (patch)
treec79cf0996625c47905bb5eee23c44039b96ded0a /mojo
parent5a547d598313ce43915d0f626dc73ed67c6e7fc2 (diff)
downloadchromium_src-2c7c723477f83a3ae5fae494948c24163fd3aa0e.zip
chromium_src-2c7c723477f83a3ae5fae494948c24163fd3aa0e.tar.gz
chromium_src-2c7c723477f83a3ae5fae494948c24163fd3aa0e.tar.bz2
html_viewer: Implement a minimal WebBlobRegistry.
This implements a minimal, in-memory version of WebBlobRegistry for html_viewer based on the MockWebBlobRegistryImpl from content. The mock only allowed adding and removing blobs. This implementation also adds registering these blobs to URLs, and hacking the WebURLLoaderImpl to serve these blob: urls. With this patch, you can now navigate to individual Github project pages without crashing. (Github uses WebBlobs to implement issue/pull request counts on the right sidebar.) BUG=none Review URL: https://codereview.chromium.org/1072273004 Cr-Commit-Position: refs/heads/master@{#326359}
Diffstat (limited to 'mojo')
-rw-r--r--mojo/services/html_viewer/BUILD.gn2
-rw-r--r--mojo/services/html_viewer/blink_platform_impl.cc6
-rw-r--r--mojo/services/html_viewer/blink_platform_impl.h3
-rw-r--r--mojo/services/html_viewer/mock_web_blob_registry_impl.cc121
-rw-r--r--mojo/services/html_viewer/mock_web_blob_registry_impl.h64
-rw-r--r--mojo/services/html_viewer/web_url_loader_impl.cc54
-rw-r--r--mojo/services/html_viewer/web_url_loader_impl.h9
7 files changed, 251 insertions, 8 deletions
diff --git a/mojo/services/html_viewer/BUILD.gn b/mojo/services/html_viewer/BUILD.gn
index ff66ab8..bba9ff8 100644
--- a/mojo/services/html_viewer/BUILD.gn
+++ b/mojo/services/html_viewer/BUILD.gn
@@ -62,6 +62,8 @@ source_set("lib") {
"discardable_memory_allocator.h",
"html_document.cc",
"html_document.h",
+ "mock_web_blob_registry_impl.cc",
+ "mock_web_blob_registry_impl.h",
"touch_handler.cc",
"touch_handler.h",
"web_clipboard_impl.cc",
diff --git a/mojo/services/html_viewer/blink_platform_impl.cc b/mojo/services/html_viewer/blink_platform_impl.cc
index 3d20a10..7861926 100644
--- a/mojo/services/html_viewer/blink_platform_impl.cc
+++ b/mojo/services/html_viewer/blink_platform_impl.cc
@@ -105,6 +105,10 @@ blink::WebString BlinkPlatformImpl::defaultLocale() {
return blink::WebString::fromUTF8("en-US");
}
+blink::WebBlobRegistry* BlinkPlatformImpl::blobRegistry() {
+ return &blob_registry_;
+}
+
double BlinkPlatformImpl::currentTime() {
return base::Time::Now().ToDoubleT();
}
@@ -201,7 +205,7 @@ blink::WebData BlinkPlatformImpl::loadResource(const char* resource) {
}
blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() {
- return new WebURLLoaderImpl(network_service_.get());
+ return new WebURLLoaderImpl(network_service_.get(), &blob_registry_);
}
blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() {
diff --git a/mojo/services/html_viewer/blink_platform_impl.h b/mojo/services/html_viewer/blink_platform_impl.h
index 513c3ea..68ae94d 100644
--- a/mojo/services/html_viewer/blink_platform_impl.h
+++ b/mojo/services/html_viewer/blink_platform_impl.h
@@ -12,6 +12,7 @@
#include "cc/blink/web_compositor_support_impl.h"
#include "components/webcrypto/webcrypto_impl.h"
#include "mojo/services/html_viewer/blink_resource_map.h"
+#include "mojo/services/html_viewer/mock_web_blob_registry_impl.h"
#include "mojo/services/html_viewer/web_mime_registry_impl.h"
#include "mojo/services/html_viewer/web_notification_manager_impl.h"
#include "mojo/services/html_viewer/web_scheduler_impl.h"
@@ -42,6 +43,7 @@ class BlinkPlatformImpl : public blink::Platform {
virtual blink::WebThemeEngine* themeEngine();
virtual blink::WebScheduler* scheduler();
virtual blink::WebString defaultLocale();
+ virtual blink::WebBlobRegistry* blobRegistry();
virtual double currentTime();
virtual double monotonicallyIncreasingTime();
virtual void cryptographicallyRandomValues(unsigned char* buffer,
@@ -106,6 +108,7 @@ class BlinkPlatformImpl : public blink::Platform {
blink::WebScrollbarBehavior scrollbar_behavior_;
BlinkResourceMap blink_resource_map_;
mojo::NetworkServicePtr network_service_;
+ MockWebBlobRegistryImpl blob_registry_;
scoped_ptr<WebCookieJarImpl> cookie_jar_;
scoped_ptr<WebClipboardImpl> clipboard_;
diff --git a/mojo/services/html_viewer/mock_web_blob_registry_impl.cc b/mojo/services/html_viewer/mock_web_blob_registry_impl.cc
new file mode 100644
index 0000000..65ed92f
--- /dev/null
+++ b/mojo/services/html_viewer/mock_web_blob_registry_impl.cc
@@ -0,0 +1,121 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/html_viewer/mock_web_blob_registry_impl.h"
+
+#include "third_party/WebKit/public/platform/WebBlobData.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+#include "third_party/WebKit/public/platform/WebURL.h"
+#include "third_party/WebKit/public/platform/WebVector.h"
+
+using blink::WebBlobData;
+using blink::WebString;
+using blink::WebURL;
+using blink::WebVector;
+
+namespace html_viewer {
+
+MockWebBlobRegistryImpl::MockWebBlobRegistryImpl() {
+}
+
+MockWebBlobRegistryImpl::~MockWebBlobRegistryImpl() {
+}
+
+void MockWebBlobRegistryImpl::registerBlobData(const WebString& uuid,
+ const WebBlobData& data) {
+ const std::string uuid_str(uuid.utf8());
+ blob_ref_count_map_[uuid_str] = 1;
+ scoped_ptr<ScopedVector<blink::WebBlobData::Item>> items(
+ new ScopedVector<blink::WebBlobData::Item>);
+ items->reserve(data.itemCount());
+ for (size_t i = 0; i < data.itemCount(); ++i) {
+ scoped_ptr<blink::WebBlobData::Item> item(new blink::WebBlobData::Item);
+ data.itemAt(i, *item);
+ items->push_back(item.release());
+ }
+ blob_data_items_map_.set(uuid_str, items.Pass());
+}
+
+void MockWebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) {
+ blob_ref_count_map_[uuid.utf8()]++;
+}
+
+void MockWebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) {
+ const std::string uuid_str(uuid.utf8());
+ auto it = blob_ref_count_map_.find(uuid_str);
+ if (it != blob_ref_count_map_.end() && !--it->second) {
+ blob_data_items_map_.erase(uuid_str);
+ blob_ref_count_map_.erase(it);
+ }
+}
+
+void MockWebBlobRegistryImpl::registerPublicBlobURL(const WebURL& url,
+ const WebString& uuid) {
+ public_url_to_uuid_[url.spec()] = uuid;
+ addBlobDataRef(uuid);
+}
+
+void MockWebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) {
+ auto it = public_url_to_uuid_.find(url.spec());
+ if (it != public_url_to_uuid_.end()) {
+ removeBlobDataRef(it->second);
+ public_url_to_uuid_.erase(it);
+ }
+}
+
+void MockWebBlobRegistryImpl::registerStreamURL(const WebURL& url,
+ const WebString& content_type) {
+ NOTIMPLEMENTED();
+}
+
+void MockWebBlobRegistryImpl::registerStreamURL(const WebURL& url,
+ const blink::WebURL& src_url) {
+ NOTIMPLEMENTED();
+}
+
+void MockWebBlobRegistryImpl::addDataToStream(const WebURL& url,
+ const char* data,
+ size_t length) {
+ NOTIMPLEMENTED();
+}
+
+void MockWebBlobRegistryImpl::flushStream(const WebURL& url) {
+ NOTIMPLEMENTED();
+}
+
+void MockWebBlobRegistryImpl::finalizeStream(const WebURL& url) {
+ NOTIMPLEMENTED();
+}
+
+void MockWebBlobRegistryImpl::abortStream(const WebURL& url) {
+ NOTIMPLEMENTED();
+}
+
+void MockWebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) {
+ NOTIMPLEMENTED();
+}
+
+bool MockWebBlobRegistryImpl::GetUUIDForURL(const blink::WebURL& url,
+ blink::WebString* uuid) const {
+ auto it = public_url_to_uuid_.find(url.spec());
+ if (it != public_url_to_uuid_.end()) {
+ *uuid = it->second;
+ return true;
+ }
+
+ return false;
+}
+
+bool MockWebBlobRegistryImpl::GetBlobItems(
+ const WebString& uuid,
+ WebVector<WebBlobData::Item*>* items) const {
+ ScopedVector<WebBlobData::Item>* item_vector =
+ blob_data_items_map_.get(uuid.utf8());
+ if (!item_vector)
+ return false;
+ *items = item_vector->get();
+ return true;
+}
+
+} // namespace html_viewer
diff --git a/mojo/services/html_viewer/mock_web_blob_registry_impl.h b/mojo/services/html_viewer/mock_web_blob_registry_impl.h
new file mode 100644
index 0000000..feae9d0
--- /dev/null
+++ b/mojo/services/html_viewer/mock_web_blob_registry_impl.h
@@ -0,0 +1,64 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_HTML_VIEWER_MOCK_WEB_BLOB_REGISTRY_IMPL_H_
+#define MOJO_SERVICES_HTML_VIEWER_MOCK_WEB_BLOB_REGISTRY_IMPL_H_
+
+#include <map>
+
+#include "base/containers/scoped_ptr_hash_map.h"
+#include "base/macros.h"
+#include "base/memory/scoped_vector.h"
+#include "third_party/WebKit/public/platform/WebBlobData.h"
+#include "third_party/WebKit/public/platform/WebBlobRegistry.h"
+#include "third_party/WebKit/public/platform/WebVector.h"
+
+namespace html_viewer {
+
+// TODO(erg): For now, this is a just a copy of content's testing
+// mock. Eventually, this should be turned into a real implementation, but this
+// at least lets us get github working.
+class MockWebBlobRegistryImpl : public blink::WebBlobRegistry {
+ public:
+ MockWebBlobRegistryImpl();
+ virtual ~MockWebBlobRegistryImpl();
+
+ virtual void registerBlobData(const blink::WebString& uuid,
+ const blink::WebBlobData& data);
+ virtual void addBlobDataRef(const blink::WebString& uuid);
+ virtual void removeBlobDataRef(const blink::WebString& uuid);
+ virtual void registerPublicBlobURL(const blink::WebURL&,
+ const blink::WebString& uuid);
+ virtual void revokePublicBlobURL(const blink::WebURL&);
+
+ // Additional support for Streams.
+ virtual void registerStreamURL(const blink::WebURL& url,
+ const blink::WebString& content_type);
+ virtual void registerStreamURL(const blink::WebURL& url,
+ const blink::WebURL& src_url);
+ virtual void addDataToStream(const blink::WebURL& url,
+ const char* data,
+ size_t length);
+ virtual void flushStream(const blink::WebURL& url);
+ virtual void finalizeStream(const blink::WebURL& url);
+ virtual void abortStream(const blink::WebURL& url);
+ virtual void unregisterStreamURL(const blink::WebURL& url);
+
+ bool GetUUIDForURL(const blink::WebURL& url, blink::WebString* uuid) const;
+ bool GetBlobItems(const blink::WebString& uuid,
+ blink::WebVector<blink::WebBlobData::Item*>* items) const;
+
+ private:
+ base::ScopedPtrHashMap<std::string, ScopedVector<blink::WebBlobData::Item>>
+ blob_data_items_map_;
+ std::map<std::string, int> blob_ref_count_map_;
+
+ std::map<std::string, blink::WebString> public_url_to_uuid_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockWebBlobRegistryImpl);
+};
+
+} // namespace html_viewer
+
+#endif // MOJO_SERVICES_HTML_VIEWER_MOCK_WEB_BLOB_REGISTRY_IMPL_H_
diff --git a/mojo/services/html_viewer/web_url_loader_impl.cc b/mojo/services/html_viewer/web_url_loader_impl.cc
index 09c795f..14d6bbe 100644
--- a/mojo/services/html_viewer/web_url_loader_impl.cc
+++ b/mojo/services/html_viewer/web_url_loader_impl.cc
@@ -80,8 +80,10 @@ WebURLRequestExtraData::WebURLRequestExtraData() {
WebURLRequestExtraData::~WebURLRequestExtraData() {
}
-WebURLLoaderImpl::WebURLLoaderImpl(mojo::NetworkService* network_service)
+WebURLLoaderImpl::WebURLLoaderImpl(mojo::NetworkService* network_service,
+ MockWebBlobRegistryImpl* web_blob_registry)
: client_(NULL),
+ web_blob_registry_(web_blob_registry),
referrer_policy_(blink::WebReferrerPolicyDefault),
weak_factory_(this) {
network_service->CreateURLLoader(GetProxy(&url_loader_));
@@ -119,12 +121,24 @@ void WebURLLoaderImpl::loadAsynchronously(const blink::WebURLRequest& request,
weak_factory_.GetWeakPtr(),
request,
base::Passed(&extra_data->synthetic_response)));
- } else {
- url_loader_->Start(url_request.Pass(),
- base::Bind(&WebURLLoaderImpl::OnReceivedResponse,
- weak_factory_.GetWeakPtr(),
- request));
+ return;
+ }
+
+ blink::WebString uuid;
+ if (web_blob_registry_->GetUUIDForURL(url_, &uuid)) {
+ blink::WebVector<blink::WebBlobData::Item*> items;
+ if (web_blob_registry_->GetBlobItems(uuid, &items)) {
+ // The blob data exists in our service, and we don't want to create a
+ // data pipe just to do a funny dance where at the end, we stuff data
+ // from memory into data pipes so we can read back the data.
+ OnReceiveWebBlobData(request, items);
+ return;
+ }
}
+
+ url_loader_->Start(url_request.Pass(),
+ base::Bind(&WebURLLoaderImpl::OnReceivedResponse,
+ weak_factory_.GetWeakPtr(), request));
}
void WebURLLoaderImpl::cancel() {
@@ -218,6 +232,34 @@ void WebURLLoaderImpl::OnReceivedRedirect(const blink::WebURLRequest& request,
request));
}
+void WebURLLoaderImpl::OnReceiveWebBlobData(
+ const blink::WebURLRequest& request,
+ const blink::WebVector<blink::WebBlobData::Item*>& items) {
+ blink::WebURLResponse result;
+ result.initialize();
+ result.setURL(url_);
+ result.setHTTPStatusCode(200);
+ result.setExpectedContentLength(-1); // Not available.
+
+ base::WeakPtr<WebURLLoaderImpl> self(weak_factory_.GetWeakPtr());
+ client_->didReceiveResponse(this, result);
+
+ // We may have been deleted during didReceiveResponse.
+ if (!self)
+ return;
+
+ // Send a receive data for each blob item.
+ for (size_t i = 0; i < items.size(); ++i) {
+ client_->didReceiveData(this, items[i]->data.data(), items[i]->data.size(),
+ -1);
+ }
+
+ // Send a closing finish.
+ double finish_time = base::Time::Now().ToDoubleT();
+ client_->didFinishLoading(
+ this, finish_time, blink::WebURLLoaderClient::kUnknownEncodedDataLength);
+}
+
void WebURLLoaderImpl::ReadMore() {
const void* buf;
uint32_t buf_size;
diff --git a/mojo/services/html_viewer/web_url_loader_impl.h b/mojo/services/html_viewer/web_url_loader_impl.h
index 8c09185..f184917 100644
--- a/mojo/services/html_viewer/web_url_loader_impl.h
+++ b/mojo/services/html_viewer/web_url_loader_impl.h
@@ -8,7 +8,9 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/common/handle_watcher.h"
+#include "mojo/services/html_viewer/mock_web_blob_registry_impl.h"
#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
+#include "third_party/WebKit/public/platform/WebBlobData.h"
#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
#include "third_party/WebKit/public/platform/WebURLLoader.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
@@ -30,7 +32,8 @@ class WebURLRequestExtraData : public blink::WebURLRequest::ExtraData {
class WebURLLoaderImpl : public blink::WebURLLoader {
public:
- explicit WebURLLoaderImpl(mojo::NetworkService* network_service);
+ explicit WebURLLoaderImpl(mojo::NetworkService* network_service,
+ MockWebBlobRegistryImpl* web_blob_registry);
private:
virtual ~WebURLLoaderImpl();
@@ -50,11 +53,15 @@ class WebURLLoaderImpl : public blink::WebURLLoader {
void OnReceivedError(mojo::URLResponsePtr response);
void OnReceivedRedirect(const blink::WebURLRequest& request,
mojo::URLResponsePtr response);
+ void OnReceiveWebBlobData(
+ const blink::WebURLRequest& request,
+ const blink::WebVector<blink::WebBlobData::Item*>& items);
void ReadMore();
void WaitToReadMore();
void OnResponseBodyStreamReady(MojoResult result);
blink::WebURLLoaderClient* client_;
+ MockWebBlobRegistryImpl* web_blob_registry_;
GURL url_;
blink::WebReferrerPolicy referrer_policy_;
mojo::URLLoaderPtr url_loader_;