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 "components/web_view/frame_connection.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/callback.h" | |
11 #include "build/build_config.h" | |
12 #include "components/clipboard/public/interfaces/clipboard.mojom.h" | |
13 #include "components/mus/public/interfaces/display.mojom.h" | |
14 #include "components/mus/public/interfaces/gpu.mojom.h" | |
15 #include "components/mus/public/interfaces/window_tree_host.mojom.h" | |
16 #include "components/resource_provider/public/interfaces/resource_provider.mojom
.h" | |
17 #include "components/web_view/frame_tree.h" | |
18 #include "components/web_view/frame_utils.h" | |
19 #include "components/web_view/test_runner/public/interfaces/layout_test_runner.m
ojom.h" | |
20 #include "mojo/services/network/public/interfaces/cookie_store.mojom.h" | |
21 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | |
22 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" | |
23 #include "mojo/services/network/public/interfaces/web_socket_factory.mojom.h" | |
24 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" | |
25 #include "mojo/shell/public/cpp/connection.h" | |
26 #include "mojo/shell/public/cpp/shell.h" | |
27 | |
28 #if defined(OS_LINUX) && !defined(OS_ANDROID) | |
29 #include "components/font_service/public/interfaces/font_service.mojom.h" | |
30 #endif | |
31 | |
32 namespace web_view { | |
33 namespace { | |
34 | |
35 // Callback from when the content handler id is obtained. | |
36 void OnGotContentHandlerForFrame( | |
37 const uint32_t existing_content_handler_id, | |
38 const FrameTreeDelegate::CanNavigateFrameCallback& callback, | |
39 scoped_ptr<FrameConnection> connection) { | |
40 mus::mojom::WindowTreeClientPtr window_tree_client; | |
41 if (!AreAppIdsEqual(existing_content_handler_id, | |
42 connection->GetContentHandlerID())) { | |
43 window_tree_client = connection->GetWindowTreeClient(); | |
44 } | |
45 FrameConnection* connection_ptr = connection.get(); | |
46 callback.Run(connection_ptr->GetContentHandlerID(), | |
47 connection_ptr->frame_client(), std::move(connection), | |
48 std::move(window_tree_client)); | |
49 } | |
50 | |
51 } // namespace | |
52 | |
53 FrameConnection::FrameConnection() : connection_(nullptr) { | |
54 } | |
55 | |
56 FrameConnection::~FrameConnection() { | |
57 } | |
58 | |
59 // static | |
60 void FrameConnection::CreateConnectionForCanNavigateFrame( | |
61 mojo::Shell* shell, | |
62 Frame* frame, | |
63 mojo::URLRequestPtr request, | |
64 const FrameTreeDelegate::CanNavigateFrameCallback& callback) { | |
65 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); | |
66 FrameConnection* connection = frame_connection.get(); | |
67 connection->Init(shell, std::move(request), | |
68 base::Bind(&OnGotContentHandlerForFrame, frame->app_id(), | |
69 callback, base::Passed(&frame_connection))); | |
70 } | |
71 | |
72 void FrameConnection::Init(mojo::Shell* shell, | |
73 mojo::URLRequestPtr request, | |
74 const base::Closure& on_got_id_callback) { | |
75 DCHECK(!connection_); | |
76 | |
77 mojo::shell::mojom::CapabilityFilterPtr filter( | |
78 mojo::shell::mojom::CapabilityFilter::New()); | |
79 mojo::Array<mojo::String> resource_provider_interfaces; | |
80 resource_provider_interfaces.push_back( | |
81 resource_provider::ResourceProvider::Name_); | |
82 filter->filter.insert("mojo:resource_provider", | |
83 std::move(resource_provider_interfaces)); | |
84 | |
85 mojo::Array<mojo::String> network_service_interfaces; | |
86 network_service_interfaces.push_back(mojo::CookieStore::Name_); | |
87 network_service_interfaces.push_back(mojo::NetworkService::Name_); | |
88 network_service_interfaces.push_back(mojo::URLLoaderFactory::Name_); | |
89 network_service_interfaces.push_back(mojo::WebSocketFactory::Name_); | |
90 filter->filter.insert("mojo:network_service", | |
91 std::move(network_service_interfaces)); | |
92 | |
93 mojo::Array<mojo::String> clipboard_interfaces; | |
94 clipboard_interfaces.push_back(mojo::Clipboard::Name_); | |
95 filter->filter.insert("mojo:clipboard", std::move(clipboard_interfaces)); | |
96 | |
97 mojo::Array<mojo::String> tracing_interfaces; | |
98 tracing_interfaces.push_back(tracing::StartupPerformanceDataCollector::Name_); | |
99 tracing_interfaces.push_back(tracing::TraceCollector::Name_); | |
100 filter->filter.insert("mojo:tracing", std::move(tracing_interfaces)); | |
101 | |
102 mojo::Array<mojo::String> window_manager_interfaces; | |
103 window_manager_interfaces.push_back(mus::mojom::Gpu::Name_); | |
104 window_manager_interfaces.push_back(mus::mojom::WindowTreeHostFactory::Name_); | |
105 window_manager_interfaces.push_back(mus::mojom::DisplayManager::Name_); | |
106 filter->filter.insert("mojo:mus", std::move(window_manager_interfaces)); | |
107 | |
108 mojo::Array<mojo::String> test_runner_interfaces; | |
109 test_runner_interfaces.push_back(LayoutTestRunner::Name_); | |
110 filter->filter.insert("mojo:web_view_test_runner", | |
111 std::move(test_runner_interfaces)); | |
112 | |
113 #if defined(OS_LINUX) && !defined(OS_ANDROID) | |
114 mojo::Array<mojo::String> font_service_interfaces; | |
115 font_service_interfaces.push_back(font_service::FontService::Name_); | |
116 filter->filter.insert("mojo:font_service", | |
117 std::move(font_service_interfaces)); | |
118 #endif | |
119 | |
120 mojo::Shell::ConnectParams params(std::move(request)); | |
121 params.set_filter(std::move(filter)); | |
122 connection_ = shell->Connect(¶ms); | |
123 connection_->ConnectToService(&frame_client_); | |
124 connection_->AddRemoteIDCallback(on_got_id_callback); | |
125 } | |
126 | |
127 mus::mojom::WindowTreeClientPtr FrameConnection::GetWindowTreeClient() { | |
128 DCHECK(connection_); | |
129 mus::mojom::WindowTreeClientPtr window_tree_client; | |
130 connection_->ConnectToService(&window_tree_client); | |
131 return window_tree_client; | |
132 } | |
133 | |
134 uint32_t FrameConnection::GetContentHandlerID() const { | |
135 uint32_t content_handler_id = | |
136 mojo::shell::mojom::Shell::kInvalidApplicationID; | |
137 if (!connection_->GetRemoteContentHandlerID(&content_handler_id)) | |
138 NOTREACHED(); | |
139 return content_handler_id; | |
140 } | |
141 | |
142 } // namespace web_view | |
OLD | NEW |