Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/browser/webui/web_ui_mojo_browsertest.cc

Issue 285333003: Support exposing Mojo services between render frames, render threads, and their respective hosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: InterfaceRequest in RenderFrameSetup Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "content/browser/webui/web_ui_controller_factory_registry.h" 13 #include "content/browser/webui/web_ui_controller_factory_registry.h"
14 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui_controller.h" 19 #include "content/public/browser/web_ui_controller.h"
18 #include "content/public/browser/web_ui_data_source.h" 20 #include "content/public/browser/web_ui_data_source.h"
19 #include "content/public/common/content_paths.h" 21 #include "content/public/common/content_paths.h"
20 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
23 #include "content/public/common/service_registry.h"
21 #include "content/public/common/url_utils.h" 24 #include "content/public/common/url_utils.h"
22 #include "content/public/test/content_browser_test.h" 25 #include "content/public/test/content_browser_test.h"
23 #include "content/public/test/content_browser_test_utils.h" 26 #include "content/public/test/content_browser_test_utils.h"
24 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" 27 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h"
25 #include "grit/content_resources.h" 28 #include "grit/content_resources.h"
26 #include "mojo/common/test/test_utils.h" 29 #include "mojo/common/test/test_utils.h"
27 #include "mojo/public/js/bindings/constants.h" 30 #include "mojo/public/js/bindings/constants.h"
28 31
29 namespace content { 32 namespace content {
30 namespace { 33 namespace {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); 121 DISALLOW_COPY_AND_ASSIGN(TestWebUIController);
119 }; 122 };
120 123
121 // TestWebUIController that additionally creates the ping test BrowserTarget 124 // TestWebUIController that additionally creates the ping test BrowserTarget
122 // implementation at the right time. 125 // implementation at the right time.
123 class PingTestWebUIController : public TestWebUIController { 126 class PingTestWebUIController : public TestWebUIController {
124 public: 127 public:
125 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) 128 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop)
126 : TestWebUIController(web_ui, run_loop) { 129 : TestWebUIController(web_ui, run_loop) {
127 } 130 }
131 virtual ~PingTestWebUIController() {}
128 132
129 // WebUIController overrides: 133 // WebUIController overrides:
130 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { 134 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE {
131 mojo::MessagePipe pipe; 135 render_view_host->GetProcess()->ActivateMojo();
132 browser_target_.reset( 136 render_view_host->GetMainFrame()->GetServiceRegistry()->AddService(
133 new PingBrowserTargetImpl(pipe.handle0.Pass(), run_loop_)); 137 "webui_controller",
134 render_view_host->SetWebUIHandle(pipe.handle1.Pass()); 138 base::Bind(&PingTestWebUIController::CreateHandler,
139 base::Unretained(this)));
140 }
141
142 void CreateHandler(mojo::ScopedMessagePipeHandle handle) {
143 browser_target_.reset(new PingBrowserTargetImpl(handle.Pass(), run_loop_));
135 } 144 }
136 145
137 private: 146 private:
138 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); 147 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController);
139 }; 148 };
140 149
141 // WebUIControllerFactory that creates TestWebUIController. 150 // WebUIControllerFactory that creates TestWebUIController.
142 class TestWebUIControllerFactory : public WebUIControllerFactory { 151 class TestWebUIControllerFactory : public WebUIControllerFactory {
143 public: 152 public:
144 TestWebUIControllerFactory() : run_loop_(NULL) {} 153 TestWebUIControllerFactory() : run_loop_(NULL) {}
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 factory()->set_run_loop(&run_loop); 218 factory()->set_run_loop(&run_loop);
210 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); 219 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping"));
211 NavigateToURL(shell(), test_url); 220 NavigateToURL(shell(), test_url);
212 // RunLoop is quit when message received from page. 221 // RunLoop is quit when message received from page.
213 run_loop.Run(); 222 run_loop.Run();
214 EXPECT_TRUE(got_message); 223 EXPECT_TRUE(got_message);
215 } 224 }
216 225
217 } // namespace 226 } // namespace
218 } // namespace content 227 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698