diff options
author | aa <aa@chromium.org> | 2014-11-20 13:25:56 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-20 21:26:40 +0000 |
commit | 34cf1b98e64108d50969638dc39a1b1bc92ee8f7 (patch) | |
tree | 591839aad622d464c2334a3d8ed95c8ca5d0ac4e /mojo | |
parent | 6e387ed08adbf8b1f823e55ff9f9f0f9fe9a97d4 (diff) | |
download | chromium_src-34cf1b98e64108d50969638dc39a1b1bc92ee8f7.zip chromium_src-34cf1b98e64108d50969638dc39a1b1bc92ee8f7.tar.gz chromium_src-34cf1b98e64108d50969638dc39a1b1bc92ee8f7.tar.bz2 |
Beginning of an accessibility implementation for html_viewer.
This depends on the interface definition here:
https://codereview.chromium.org/715463002/
Review URL: https://codereview.chromium.org/710803002
Cr-Commit-Position: refs/heads/master@{#305080}
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/services/html_viewer/BUILD.gn | 35 | ||||
-rw-r--r-- | mojo/services/html_viewer/ax_provider_impl.cc | 82 | ||||
-rw-r--r-- | mojo/services/html_viewer/ax_provider_impl.h | 38 | ||||
-rw-r--r-- | mojo/services/html_viewer/ax_provider_impl_unittest.cc | 173 | ||||
-rw-r--r-- | mojo/services/html_viewer/blink_basic_type_converters.cc | 12 | ||||
-rw-r--r-- | mojo/services/html_viewer/blink_basic_type_converters.h | 7 | ||||
-rw-r--r-- | mojo/services/html_viewer/blink_platform_impl.cc | 28 | ||||
-rw-r--r-- | mojo/services/html_viewer/blink_platform_impl.h | 11 | ||||
-rw-r--r-- | mojo/services/html_viewer/html_document_view.cc | 15 | ||||
-rw-r--r-- | mojo/services/html_viewer/html_document_view.h | 17 | ||||
-rw-r--r-- | mojo/services/html_viewer/html_viewer.cc | 8 | ||||
-rw-r--r-- | mojo/services/html_viewer/mojo_blink_platform_impl.cc | 38 | ||||
-rw-r--r-- | mojo/services/html_viewer/mojo_blink_platform_impl.h | 35 | ||||
-rw-r--r-- | mojo/services/html_viewer/test_blink_platform_impl.cc | 23 | ||||
-rw-r--r-- | mojo/services/html_viewer/test_blink_platform_impl.h | 31 |
15 files changed, 505 insertions, 48 deletions
diff --git a/mojo/services/html_viewer/BUILD.gn b/mojo/services/html_viewer/BUILD.gn index 4e7fee3..1170685 100644 --- a/mojo/services/html_viewer/BUILD.gn +++ b/mojo/services/html_viewer/BUILD.gn @@ -5,9 +5,10 @@ import("//mojo/public/mojo.gni") import("//mojo/public/mojo_application.gni") -# GYP version: mojo/mojo_services.gypi:html_viewer -mojo_native_application("html_viewer") { +source_set("lib") { sources = [ + "ax_provider_impl.cc", + "ax_provider_impl.h", "blink_basic_type_converters.cc", "blink_basic_type_converters.h", "blink_input_events_type_converters.cc", @@ -16,9 +17,10 @@ mojo_native_application("html_viewer") { "blink_platform_impl.h", "blink_url_request_type_converters.cc", "blink_url_request_type_converters.h", - "html_viewer.cc", "html_document_view.cc", "html_document_view.h", + "mojo_blink_platform_impl.cc", + "mojo_blink_platform_impl.h", "webclipboard_impl.cc", "webclipboard_impl.h", "webcookiejar_impl.cc", @@ -62,6 +64,7 @@ mojo_native_application("html_viewer") { "//mojo/public/interfaces/application", "//mojo/services/public/cpp/network", "//mojo/services/public/cpp/view_manager", + "//mojo/services/public/interfaces/accessibility", "//mojo/services/public/interfaces/clipboard", "//mojo/services/public/interfaces/content_handler", "//mojo/services/public/interfaces/gpu", @@ -71,8 +74,32 @@ mojo_native_application("html_viewer") { "//mojo/services/public/interfaces/surfaces", "//net", "//skia", - "//third_party/WebKit/public:blink", "//ui/native_theme", "//url", ] + + public_deps = [ + "//third_party/WebKit/public:blink", + ] +} + +# GYP version: mojo/mojo_services.gypi:html_viewer +shared_library("html_viewer") { + sources = [ + "html_viewer.cc", + ] + deps = [ + ":lib", + ] +} + +test("tests") { + output_name = "html_viewer_unittests" + sources = [ + "ax_provider_impl_unittest.cc", + ] + deps = [ + ":lib", + "//base/test:run_all_unittests", + ] } diff --git a/mojo/services/html_viewer/ax_provider_impl.cc b/mojo/services/html_viewer/ax_provider_impl.cc new file mode 100644 index 0000000..19f8912 --- /dev/null +++ b/mojo/services/html_viewer/ax_provider_impl.cc @@ -0,0 +1,82 @@ +// Copyright 2014 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/ax_provider_impl.h" + +#include "mojo/services/html_viewer/blink_basic_type_converters.h" +#include "third_party/WebKit/public/platform/WebURL.h" +#include "third_party/WebKit/public/web/WebAXObject.h" +#include "third_party/WebKit/public/web/WebSettings.h" +#include "third_party/WebKit/public/web/WebView.h" + +using blink::WebAXObject; +using blink::WebURL; +using blink::WebView; + +namespace mojo { + +AxProviderImpl::AxProviderImpl(WebView* web_view) : web_view_(web_view) { +} + +void AxProviderImpl::GetTree( + const Callback<void(Array<AxNodePtr> nodes)>& callback) { + web_view_->settings()->setAccessibilityEnabled(true); + web_view_->settings()->setInlineTextBoxAccessibilityEnabled(true); + + Array<AxNodePtr> result; + Populate(web_view_->accessibilityObject(), 0, 0, &result); + callback.Run(result.Pass()); +} + +int AxProviderImpl::Populate(const WebAXObject& ax_object, + int parent_id, + int next_sibling_id, + Array<AxNodePtr>* result) { + AxNodePtr ax_node(ConvertAxNode(ax_object, parent_id, next_sibling_id)); + int ax_node_id = ax_node->id; + if (ax_node.is_null()) + return 0; + + result->push_back(ax_node.Pass()); + + unsigned num_children = ax_object.childCount(); + next_sibling_id = 0; + for (unsigned i = 0; i < num_children; ++i) { + int new_id = Populate(ax_object.childAt(num_children - i - 1), + ax_node_id, + next_sibling_id, + result); + if (new_id != 0) + next_sibling_id = new_id; + } + + return ax_node_id; +} + +AxNodePtr AxProviderImpl::ConvertAxNode(const WebAXObject& ax_object, + int parent_id, + int next_sibling_id) { + AxNodePtr result; + if (!const_cast<WebAXObject&>(ax_object).updateLayoutAndCheckValidity()) + return result.Pass(); + + result = AxNode::New(); + result->id = static_cast<int>(ax_object.axID()); + result->parent_id = parent_id; + result->next_sibling_id = next_sibling_id; + result->bounds = Rect::From(ax_object.boundingBoxRect()); + + if (ax_object.isAnchor()) { + result->link = AxLink::New(); + result->link->url = String::From(ax_object.url().string()); + } else if (ax_object.childCount() == 0 && + !ax_object.stringValue().isEmpty()) { + result->text = AxText::New(); + result->text->content = String::From(ax_object.stringValue()); + } + + return result.Pass(); +} + +} // namespace mojo diff --git a/mojo/services/html_viewer/ax_provider_impl.h b/mojo/services/html_viewer/ax_provider_impl.h new file mode 100644 index 0000000..35882f8 --- /dev/null +++ b/mojo/services/html_viewer/ax_provider_impl.h @@ -0,0 +1,38 @@ +// Copyright 2014 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_AX_PROVIDER_IMPL_H_ +#define MOJO_SERVICES_HTML_VIEWER_AX_PROVIDER_IMPL_H_ + +#include "mojo/public/cpp/bindings/interface_impl.h" +#include "mojo/services/public/interfaces/accessibility/accessibility.mojom.h" + +namespace blink { +class WebAXObject; +class WebView; +} // namespace blink + +namespace mojo { + +// Caller must ensure that |web_view| outlives AxProviderImpl. +class AxProviderImpl : public InterfaceImpl<AxProvider> { + public: + explicit AxProviderImpl(blink::WebView* web_view); + void GetTree(const Callback<void(Array<AxNodePtr> nodes)>& callback) override; + + private: + int Populate(const blink::WebAXObject& ax_object, + int parent_id, + int next_sibling_id, + Array<AxNodePtr>* result); + AxNodePtr ConvertAxNode(const blink::WebAXObject& ax_object, + int parent_id, + int next_sibling_id); + + blink::WebView* web_view_; +}; + +} // namespace mojo + +#endif // MOJO_SERVICES_HTML_VIEWER_AX_PROVIDER_IMPL_H_ diff --git a/mojo/services/html_viewer/ax_provider_impl_unittest.cc b/mojo/services/html_viewer/ax_provider_impl_unittest.cc new file mode 100644 index 0000000..1b326c6 --- /dev/null +++ b/mojo/services/html_viewer/ax_provider_impl_unittest.cc @@ -0,0 +1,173 @@ +// Copyright 2014 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/ax_provider_impl.h" + +#include "base/bind.h" +#include "base/message_loop/message_loop.h" +#include "base/metrics/stats_counters.h" +#include "mojo/services/html_viewer/blink_platform_impl.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/public/platform/WebData.h" +#include "third_party/WebKit/public/platform/WebURL.h" +#include "third_party/WebKit/public/web/WebFrameClient.h" +#include "third_party/WebKit/public/web/WebKit.h" +#include "third_party/WebKit/public/web/WebLocalFrame.h" +#include "third_party/WebKit/public/web/WebView.h" +#include "third_party/WebKit/public/web/WebViewClient.h" +#include "url/gurl.h" + +using blink::WebData; +using blink::WebLocalFrame; +using blink::WebFrameClient; +using blink::WebURL; +using blink::WebView; +using blink::WebViewClient; + +namespace mojo { + +namespace { + +class TestWebFrameClient : public WebFrameClient { + public: + virtual ~TestWebFrameClient() {} + virtual void didStopLoading() { base::MessageLoop::current()->Quit(); } +}; + +class TestWebViewClient : public WebViewClient { + public: + virtual bool allowsBrokenNullLayerTreeView() const { return true; } + virtual ~TestWebViewClient() {} +}; + +class AxProviderImplTest : public testing::Test { + public: + AxProviderImplTest() { blink::initialize(new BlinkPlatformImpl()); } + + virtual ~AxProviderImplTest() override { blink::shutdown(); } + + private: + base::MessageLoopForUI message_loop; +}; + +struct NodeCatcher { + void OnNodes(Array<AxNodePtr> nodes) { this->nodes = nodes.Pass(); } + Array<AxNodePtr> nodes; +}; + +AxNodePtr CreateNode(int id, + int parent_id, + int next_sibling_id, + const RectPtr& bounds, + const std::string& url, + const std::string& text) { + AxNodePtr node(AxNode::New()); + node->id = id; + node->parent_id = parent_id; + node->next_sibling_id = next_sibling_id; + node->bounds = bounds.Clone(); + + if (!url.empty()) { + node->link = AxLink::New(); + node->link->url = url; + } + if (!text.empty()) { + node->text = AxText::New(); + node->text->content = text; + } + return node.Pass(); +} + +} // namespace + +TEST_F(AxProviderImplTest, Basic) { + TestWebViewClient web_view_client; + TestWebFrameClient web_frame_client; + WebView* view = WebView::create(&web_view_client); + view->setMainFrame(WebLocalFrame::create(&web_frame_client)); + view->mainFrame()->loadHTMLString( + WebData( + "<html><body>foo<a " + "href='http://monkey.net'>bar</a>baz</body></html>"), + WebURL(GURL("http://someplace.net"))); + base::MessageLoop::current()->Run(); + + AxProviderImpl ax_provider_impl(view); + NodeCatcher catcher; + ax_provider_impl.GetTree( + base::Bind(&NodeCatcher::OnNodes, base::Unretained(&catcher))); + + std::map<uint32, AxNode*> lookup; + for (size_t i = 0; i < catcher.nodes.size(); ++i) { + auto& node = catcher.nodes[i]; + lookup[node->id] = node.get(); + } + + typedef decltype(lookup)::value_type MapEntry; + auto is_link = [](MapEntry pair) { return pair.second->link.get(); }; + auto is_text = [](MapEntry pair, const char* content) { + return pair.second->text.get() && + pair.second->text->content.To<std::string>() == content; + }; + auto is_foo = [&is_text](MapEntry pair) { return is_text(pair, "foo"); }; + auto is_bar = [&is_text](MapEntry pair) { return is_text(pair, "bar"); }; + auto is_baz = [&is_text](MapEntry pair) { return is_text(pair, "baz"); }; + + EXPECT_EQ(1, std::count_if(lookup.begin(), lookup.end(), is_link)); + EXPECT_EQ(1, std::count_if(lookup.begin(), lookup.end(), is_foo)); + EXPECT_EQ(1, std::count_if(lookup.begin(), lookup.end(), is_bar)); + EXPECT_EQ(1, std::count_if(lookup.begin(), lookup.end(), is_baz)); + + auto root = lookup[1u]; + auto link = std::find_if(lookup.begin(), lookup.end(), is_link)->second; + auto foo = std::find_if(lookup.begin(), lookup.end(), is_foo)->second; + auto bar = std::find_if(lookup.begin(), lookup.end(), is_bar)->second; + auto baz = std::find_if(lookup.begin(), lookup.end(), is_baz)->second; + + // Test basic content of each node. The properties we copy (like parent_id) + // here are tested differently below. + EXPECT_TRUE(CreateNode(root->id, 0, 0, root->bounds, "", "")->Equals(*root)); + EXPECT_TRUE(CreateNode(foo->id, foo->parent_id, 0, foo->bounds, "", "foo") + ->Equals(*foo)); + EXPECT_TRUE(CreateNode(bar->id, bar->parent_id, 0, bar->bounds, "", "bar") + ->Equals(*bar)); + EXPECT_TRUE(CreateNode(baz->id, baz->parent_id, 0, baz->bounds, "", "baz") + ->Equals(*baz)); + EXPECT_TRUE(CreateNode(link->id, + link->parent_id, + link->next_sibling_id, + link->bounds, + "http://monkey.net/", + "")->Equals(*link)); + + auto is_descendant_of = [&lookup](uint32 id, uint32 ancestor) { + for (; (id = lookup[id]->parent_id) != 0;) { + if (id == ancestor) + return true; + } + return false; + }; + + EXPECT_TRUE(is_descendant_of(bar->id, link->id)); + for (auto pair : lookup) { + AxNode* node = pair.second; + if (node != root) + EXPECT_TRUE(is_descendant_of(node->id, 1u)); + if (node != link && node != foo && node != bar && node != baz) { + EXPECT_TRUE(CreateNode(node->id, + node->parent_id, + node->next_sibling_id, + node->bounds, + "", + "")); + } + } + + // TODO(aa): Test bounds. + // TODO(aa): Test sibling ordering of foo/bar/baz. + + view->close(); +} + +} // namespace mojo diff --git a/mojo/services/html_viewer/blink_basic_type_converters.cc b/mojo/services/html_viewer/blink_basic_type_converters.cc index eb52652..cf6d610 100644 --- a/mojo/services/html_viewer/blink_basic_type_converters.cc +++ b/mojo/services/html_viewer/blink_basic_type_converters.cc @@ -5,8 +5,10 @@ #include "mojo/services/html_viewer/blink_basic_type_converters.h" #include "mojo/public/cpp/bindings/string.h" +#include "third_party/WebKit/public/platform/WebRect.h" #include "third_party/WebKit/public/platform/WebString.h" +using blink::WebRect; using blink::WebString; namespace mojo { @@ -22,6 +24,16 @@ WebString TypeConverter<WebString, String>::Convert(const String& str) { } // static +RectPtr TypeConverter<RectPtr, WebRect>::Convert(const WebRect& input) { + RectPtr result(Rect::New()); + result->x = input.x; + result->y = input.y; + result->width = input.width; + result->height = input.height; + return result.Pass(); +}; + +// static Array<uint8_t> TypeConverter<Array<uint8_t>, blink::WebString>::Convert( const blink::WebString& input) { std::string utf8 = input.utf8(); diff --git a/mojo/services/html_viewer/blink_basic_type_converters.h b/mojo/services/html_viewer/blink_basic_type_converters.h index 60ddeee..987d0a3 100644 --- a/mojo/services/html_viewer/blink_basic_type_converters.h +++ b/mojo/services/html_viewer/blink_basic_type_converters.h @@ -8,9 +8,11 @@ #include "mojo/public/cpp/bindings/type_converter.h" #include "mojo/public/cpp/bindings/array.h" +#include "mojo/services/public/interfaces/geometry/geometry.mojom.h" #include "third_party/WebKit/public/platform/WebVector.h" namespace blink { +struct WebRect; class WebString; } @@ -30,6 +32,11 @@ struct TypeConverter<Array<uint8_t>, blink::WebString> { static Array<uint8_t> Convert(const blink::WebString& input); }; +template <> +struct TypeConverter<RectPtr, blink::WebRect> { + static RectPtr Convert(const blink::WebRect& input); +}; + template<typename T, typename U> struct TypeConverter<Array<T>, blink::WebVector<U> > { static Array<T> Convert(const blink::WebVector<U>& vector) { diff --git a/mojo/services/html_viewer/blink_platform_impl.cc b/mojo/services/html_viewer/blink_platform_impl.cc index 1981eb2..c5014a1 100644 --- a/mojo/services/html_viewer/blink_platform_impl.cc +++ b/mojo/services/html_viewer/blink_platform_impl.cc @@ -11,12 +11,7 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/platform_thread.h" #include "base/time/time.h" -#include "mojo/public/cpp/application/application_impl.h" -#include "mojo/services/html_viewer/webclipboard_impl.h" -#include "mojo/services/html_viewer/webcookiejar_impl.h" -#include "mojo/services/html_viewer/websockethandle_impl.h" #include "mojo/services/html_viewer/webthread_impl.h" -#include "mojo/services/html_viewer/weburlloader_impl.h" #include "net/base/data_url.h" #include "net/base/mime_util.h" #include "net/base/net_errors.h" @@ -49,35 +44,18 @@ class WebWaitableEventImpl : public blink::WebWaitableEvent { } // namespace -BlinkPlatformImpl::BlinkPlatformImpl(ApplicationImpl* app) +BlinkPlatformImpl::BlinkPlatformImpl() : main_loop_(base::MessageLoop::current()), shared_timer_func_(NULL), shared_timer_fire_time_(0.0), shared_timer_fire_time_was_set_while_suspended_(false), shared_timer_suspended_(0), current_thread_slot_(&DestroyCurrentThread) { - app->ConnectToService("mojo:network_service", &network_service_); - - CookieStorePtr cookie_store; - network_service_->GetCookieStore(GetProxy(&cookie_store)); - cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); - - ClipboardPtr clipboard; - app->ConnectToService("mojo:clipboard", &clipboard); - clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); } BlinkPlatformImpl::~BlinkPlatformImpl() { } -blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { - return cookie_jar_.get(); -} - -blink::WebClipboard* BlinkPlatformImpl::clipboard() { - return clipboard_.get(); -} - blink::WebMimeRegistry* BlinkPlatformImpl::mimeRegistry() { return &mime_registry_; } @@ -166,11 +144,11 @@ const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( } blink::WebURLLoader* BlinkPlatformImpl::createURLLoader() { - return new WebURLLoaderImpl(network_service_.get()); + return NULL; } blink::WebSocketHandle* BlinkPlatformImpl::createWebSocketHandle() { - return new WebSocketHandleImpl(network_service_.get()); + return NULL; } blink::WebString BlinkPlatformImpl::userAgent() { diff --git a/mojo/services/html_viewer/blink_platform_impl.h b/mojo/services/html_viewer/blink_platform_impl.h index 9abd336..28872ea 100644 --- a/mojo/services/html_viewer/blink_platform_impl.h +++ b/mojo/services/html_viewer/blink_platform_impl.h @@ -12,23 +12,17 @@ #include "cc/blink/web_compositor_support_impl.h" #include "mojo/services/html_viewer/webmimeregistry_impl.h" #include "mojo/services/html_viewer/webthemeengine_impl.h" -#include "mojo/services/public/interfaces/network/network_service.mojom.h" #include "third_party/WebKit/public/platform/Platform.h" #include "third_party/WebKit/public/platform/WebScrollbarBehavior.h" namespace mojo { -class ApplicationImpl; -class WebClipboardImpl; -class WebCookieJarImpl; class BlinkPlatformImpl : public blink::Platform { public: - explicit BlinkPlatformImpl(ApplicationImpl* app); + explicit BlinkPlatformImpl(); virtual ~BlinkPlatformImpl(); // blink::Platform methods: - virtual blink::WebCookieJar* cookieJar(); - virtual blink::WebClipboard* clipboard(); virtual blink::WebMimeRegistry* mimeRegistry(); virtual blink::WebThemeEngine* themeEngine(); virtual blink::WebString defaultLocale(); @@ -70,7 +64,6 @@ class BlinkPlatformImpl : public blink::Platform { static void DestroyCurrentThread(void*); - NetworkServicePtr network_service_; base::MessageLoop* main_loop_; base::OneShotTimer<BlinkPlatformImpl> shared_timer_; void (*shared_timer_func_)(); @@ -80,8 +73,6 @@ class BlinkPlatformImpl : public blink::Platform { base::ThreadLocalStorage::Slot current_thread_slot_; cc_blink::WebCompositorSupportImpl compositor_support_; WebThemeEngineImpl theme_engine_; - scoped_ptr<WebCookieJarImpl> cookie_jar_; - scoped_ptr<WebClipboardImpl> clipboard_; WebMimeRegistryImpl mime_registry_; blink::WebScrollbarBehavior scrollbar_behavior_; diff --git a/mojo/services/html_viewer/html_document_view.cc b/mojo/services/html_viewer/html_document_view.cc index 01af412..80b7bcd 100644 --- a/mojo/services/html_viewer/html_document_view.cc +++ b/mojo/services/html_viewer/html_document_view.cc @@ -8,6 +8,7 @@ #include "base/location.h" #include "base/message_loop/message_loop_proxy.h" #include "base/single_thread_task_runner.h" +#include "base/stl_util.h" #include "base/strings/string_util.h" #include "base/thread_task_runner_handle.h" #include "mojo/public/cpp/application/connect.h" @@ -95,12 +96,13 @@ HTMLDocumentView::HTMLDocumentView( root_(NULL), view_manager_client_factory_(shell_.get(), this), compositor_thread_(compositor_thread), - web_media_player_factory_(web_media_player_factory), - weak_factory_(this) { + web_media_player_factory_(web_media_player_factory) { shell_.set_client(this); } HTMLDocumentView::~HTMLDocumentView() { + STLDeleteElements(&ax_provider_impls_); + if (web_view_) web_view_->close(); if (root_) @@ -109,6 +111,7 @@ HTMLDocumentView::~HTMLDocumentView() { void HTMLDocumentView::AcceptConnection(const String& requestor_url, ServiceProviderPtr provider) { + exported_services_.AddService(this); exported_services_.AddService(&view_manager_client_factory_); WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); Load(response_.Pass()); @@ -133,6 +136,14 @@ void HTMLDocumentView::OnEmbed( root_->AddObserver(this); } +void HTMLDocumentView::Create(ApplicationConnection* connection, + InterfaceRequest<AxProvider> request) { + if (!web_view_) + return; + ax_provider_impls_.insert( + WeakBindToRequest(new AxProviderImpl(web_view_), &request)); +} + void HTMLDocumentView::OnViewManagerDisconnected(ViewManager* view_manager) { // TODO(aa): Need to figure out how shutdown works. } diff --git a/mojo/services/html_viewer/html_document_view.h b/mojo/services/html_viewer/html_document_view.h index 6831485..d1cd1eb 100644 --- a/mojo/services/html_viewer/html_document_view.h +++ b/mojo/services/html_viewer/html_document_view.h @@ -5,12 +5,15 @@ #ifndef MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_ #define MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_ +#include <set> + #include "base/macros.h" -#include "base/memory/weak_ptr.h" +#include "mojo/public/cpp/application/interface_factory.h" #include "mojo/public/cpp/application/lazy_interface_ptr.h" #include "mojo/public/cpp/application/service_provider_impl.h" #include "mojo/public/cpp/bindings/interface_impl.h" #include "mojo/public/interfaces/application/application.mojom.h" +#include "mojo/services/html_viewer/ax_provider_impl.h" #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" #include "mojo/services/public/cpp/view_manager/view_observer.h" @@ -26,6 +29,7 @@ class MessageLoopProxy; namespace mojo { +class AxProviderImpl; class WebMediaPlayerFactory; class ViewManager; class View; @@ -36,7 +40,8 @@ class HTMLDocumentView : public mojo::InterfaceImpl<mojo::Application>, public blink::WebViewClient, public blink::WebFrameClient, public ViewManagerDelegate, - public ViewObserver { + public ViewObserver, + public InterfaceFactory<AxProvider> { public: // Load a new HTMLDocument with |response|. // @@ -107,6 +112,10 @@ class HTMLDocumentView : public mojo::InterfaceImpl<mojo::Application>, void OnViewDestroyed(View* view) override; void OnViewInputEvent(View* view, const EventPtr& event) override; + // InterfaceFactory<AxProvider> + void Create(ApplicationConnection* connection, + InterfaceRequest<AxProvider> request) override; + void Load(URLResponsePtr response); URLResponsePtr response_; @@ -121,7 +130,9 @@ class HTMLDocumentView : public mojo::InterfaceImpl<mojo::Application>, scoped_refptr<base::MessageLoopProxy> compositor_thread_; WebMediaPlayerFactory* web_media_player_factory_; - base::WeakPtrFactory<HTMLDocumentView> weak_factory_; + // HTMLDocumentView owns these pointers. + std::set<AxProviderImpl*> ax_provider_impls_; + DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView); }; diff --git a/mojo/services/html_viewer/html_viewer.cc b/mojo/services/html_viewer/html_viewer.cc index 518f28e..3ec9e45 100644 --- a/mojo/services/html_viewer/html_viewer.cc +++ b/mojo/services/html_viewer/html_viewer.cc @@ -11,8 +11,8 @@ #include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/interface_factory_impl.h" -#include "mojo/services/html_viewer/blink_platform_impl.h" #include "mojo/services/html_viewer/html_document_view.h" +#include "mojo/services/html_viewer/mojo_blink_platform_impl.h" #include "mojo/services/html_viewer/webmediaplayer_factory.h" #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h" #include "third_party/WebKit/public/web/WebKit.h" @@ -68,8 +68,8 @@ class HTMLViewer : public ApplicationDelegate, private: // Overridden from ApplicationDelegate: void Initialize(ApplicationImpl* app) override { - blink_platform_impl_.reset(new BlinkPlatformImpl(app)); - blink::initialize(blink_platform_impl_.get()); + blink_platform_.reset(new MojoBlinkPlatformImpl(app)); + blink::initialize(blink_platform_.get()); #if !defined(COMPONENT_BUILD) base::i18n::InitializeICU(); @@ -107,7 +107,7 @@ class HTMLViewer : public ApplicationDelegate, &request); } - scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; + scoped_ptr<MojoBlinkPlatformImpl> blink_platform_; base::Thread compositor_thread_; scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_; diff --git a/mojo/services/html_viewer/mojo_blink_platform_impl.cc b/mojo/services/html_viewer/mojo_blink_platform_impl.cc new file mode 100644 index 0000000..3b9dab3 --- /dev/null +++ b/mojo/services/html_viewer/mojo_blink_platform_impl.cc @@ -0,0 +1,38 @@ +// Copyright 2014 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/mojo_blink_platform_impl.h" + +#include "mojo/public/cpp/application/application_impl.h" +#include "mojo/services/html_viewer/webclipboard_impl.h" +#include "mojo/services/html_viewer/webcookiejar_impl.h" +#include "mojo/services/html_viewer/websockethandle_impl.h" +#include "mojo/services/html_viewer/weburlloader_impl.h" + +namespace mojo { + +MojoBlinkPlatformImpl::MojoBlinkPlatformImpl(ApplicationImpl* app) { + app->ConnectToService("mojo:network_service", &network_service_); + + CookieStorePtr cookie_store; + network_service_->GetCookieStore(GetProxy(&cookie_store)); + cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); + + ClipboardPtr clipboard; + app->ConnectToService("mojo:clipboard", &clipboard); + clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); +} + +MojoBlinkPlatformImpl::~MojoBlinkPlatformImpl() { +} + +blink::WebURLLoader* MojoBlinkPlatformImpl::createURLLoader() { + return new WebURLLoaderImpl(network_service_.get()); +} + +blink::WebSocketHandle* MojoBlinkPlatformImpl::createWebSocketHandle() { + return new WebSocketHandleImpl(network_service_.get()); +} + +} // namespace mojo diff --git a/mojo/services/html_viewer/mojo_blink_platform_impl.h b/mojo/services/html_viewer/mojo_blink_platform_impl.h new file mode 100644 index 0000000..817c8d4 --- /dev/null +++ b/mojo/services/html_viewer/mojo_blink_platform_impl.h @@ -0,0 +1,35 @@ +// Copyright 2014 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_MOJO_BLINK_PLATFORM_IMPL_H_ +#define MOJO_SERVICES_HTML_VIEWER_MOJO_BLINK_PLATFORM_IMPL_H_ + +#include "mojo/services/html_viewer/blink_platform_impl.h" + +#include "mojo/services/public/interfaces/network/network_service.mojom.h" + +namespace mojo { + +class ApplicationImpl; +class WebClipboardImpl; +class WebCookieJarImpl; + +class MojoBlinkPlatformImpl : public BlinkPlatformImpl { + public: + MojoBlinkPlatformImpl(ApplicationImpl* app); + virtual ~MojoBlinkPlatformImpl(); + + private: + // BlinkPlatform + virtual blink::WebURLLoader* createURLLoader() override; + virtual blink::WebSocketHandle* createWebSocketHandle() override; + + NetworkServicePtr network_service_; + scoped_ptr<WebCookieJarImpl> cookie_jar_; + scoped_ptr<WebClipboardImpl> clipboard_; +}; + +} // namespace mojo + +#endif // MOJO_SERVICES_HTML_VIEWER_MOJO_BLINK_PLATFORM_IMPL_H_ diff --git a/mojo/services/html_viewer/test_blink_platform_impl.cc b/mojo/services/html_viewer/test_blink_platform_impl.cc new file mode 100644 index 0000000..d8bc08f --- /dev/null +++ b/mojo/services/html_viewer/test_blink_platform_impl.cc @@ -0,0 +1,23 @@ +// Copyright 2014 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/test_blink_platform_impl.h" + +namespace mojo { + +TestBlinkPlatformImpl::TestBlinkPlatformImpl() { +} + +TestBlinkPlatformImpl::~TestBlinkPlatformImpl() { +} + +blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { + return cookie_jar_.get(); +} + +blink::WebClipboard* BlinkPlatformImpl::clipboard() { + return clipboard_.get(); +} + +} // namespace mojo diff --git a/mojo/services/html_viewer/test_blink_platform_impl.h b/mojo/services/html_viewer/test_blink_platform_impl.h new file mode 100644 index 0000000..e2fcf76 --- /dev/null +++ b/mojo/services/html_viewer/test_blink_platform_impl.h @@ -0,0 +1,31 @@ +// Copyright 2014 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_TEST_BLINK_PLATFORM_IMPL_H_ +#define MOJO_SERVICES_HTML_VIEWER_TEST_BLINK_PLATFORM_IMPL_H_ + +#include "mojo/services/html_viewer/blink_platform_impl.h" + +#include "third_party/WebKit/public/platform/WebClipboard.h" +#include "third_party/WebKit/public/platform/WebCookieJar.h" + +namespace mojo { + +class TestBlinkPlatformImpl : public BlinkPlatformImpl { + public: + TestBlinkPlatformImpl(); + virtual ~TestBlinkPlatformImpl(); + + private: + // blink::Platform methods: + virtual blink::WebCookieJar* cookieJar(); + virtual blink::WebClipboard* clipboard(); + + blink::WebClipboard clipboard_; + blink::WebCookieJar cookie_jar_; +}; + +} // namespace mojo + +#endif // MOJO_SERVICES_HTML_VIEWER_TEST_BLINK_PLATFORM_IMPL_H_ |