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

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

Issue 302573002: Add a Javascript wrapper around ServiceRegistry and expose it to WebUI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@render-view-shell
Patch Set: 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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 &contents, 51 &contents,
52 std::string::npos)) << id; 52 std::string::npos)) << id;
53 base::RefCountedString* ref_contents = new base::RefCountedString; 53 base::RefCountedString* ref_contents = new base::RefCountedString;
54 ref_contents->data() = contents; 54 ref_contents->data() = contents;
55 callback.Run(ref_contents); 55 callback.Run(ref_contents);
56 return true; 56 return true;
57 } 57 }
58 58
59 class BrowserTargetImpl : public BrowserTarget { 59 class BrowserTargetImpl : public BrowserTarget {
60 public: 60 public:
61 BrowserTargetImpl(mojo::ScopedMessagePipeHandle handle, 61 BrowserTargetImpl(mojo::InterfaceRequest<BrowserTarget> request,
62 base::RunLoop* run_loop) 62 base::RunLoop* run_loop)
63 : run_loop_(run_loop) { 63 : run_loop_(run_loop) {
64 renderer_.Bind(handle.Pass()); 64 renderer_.Bind(request.PassMessagePipe());
65 renderer_.set_client(this); 65 renderer_.set_client(this);
66 } 66 }
67 67
68 virtual ~BrowserTargetImpl() {} 68 virtual ~BrowserTargetImpl() {}
69 69
70 // BrowserTarget overrides: 70 // BrowserTarget overrides:
71 virtual void PingResponse() OVERRIDE { 71 virtual void PingResponse() OVERRIDE {
72 NOTREACHED(); 72 NOTREACHED();
73 } 73 }
74 74
75 protected: 75 protected:
76 RendererTargetPtr renderer_; 76 RendererTargetPtr renderer_;
77 base::RunLoop* run_loop_; 77 base::RunLoop* run_loop_;
78 78
79 private: 79 private:
80 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); 80 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl);
81 }; 81 };
82 82
83 class PingBrowserTargetImpl : public BrowserTargetImpl { 83 class PingBrowserTargetImpl : public BrowserTargetImpl {
84 public: 84 public:
85 PingBrowserTargetImpl(mojo::ScopedMessagePipeHandle handle, 85 PingBrowserTargetImpl(mojo::InterfaceRequest<BrowserTarget> request,
86 base::RunLoop* run_loop) 86 base::RunLoop* run_loop)
87 : BrowserTargetImpl(handle.Pass(), run_loop) { 87 : BrowserTargetImpl(request.Pass(), run_loop) {
88 renderer_->Ping(); 88 renderer_->Ping();
89 } 89 }
90 90
91 virtual ~PingBrowserTargetImpl() {} 91 virtual ~PingBrowserTargetImpl() {}
92 92
93 // BrowserTarget overrides: 93 // BrowserTarget overrides:
94 // Quit the RunLoop when called. 94 // Quit the RunLoop when called.
95 virtual void PingResponse() OVERRIDE { 95 virtual void PingResponse() OVERRIDE {
96 got_message = true; 96 got_message = true;
97 run_loop_->Quit(); 97 run_loop_->Quit();
(...skipping 28 matching lines...) Expand all
126 class PingTestWebUIController : public TestWebUIController { 126 class PingTestWebUIController : public TestWebUIController {
127 public: 127 public:
128 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) 128 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop)
129 : TestWebUIController(web_ui, run_loop) { 129 : TestWebUIController(web_ui, run_loop) {
130 } 130 }
131 virtual ~PingTestWebUIController() {} 131 virtual ~PingTestWebUIController() {}
132 132
133 // WebUIController overrides: 133 // WebUIController overrides:
134 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { 134 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE {
135 render_view_host->GetProcess()->ActivateMojo(); 135 render_view_host->GetProcess()->ActivateMojo();
136 render_view_host->GetMainFrame()->GetServiceRegistry()->AddService( 136 render_view_host->GetMainFrame()
137 "webui_controller", 137 ->GetServiceRegistry()
darin (slow to review) 2014/06/21 04:44:15 ditto
Sam McNally 2014/06/24 08:45:01 Done.
138 base::Bind(&PingTestWebUIController::CreateHandler, 138 ->AddService<BrowserTarget>(base::Bind(
139 base::Unretained(this))); 139 &PingTestWebUIController::CreateHandler, base::Unretained(this)));
140 } 140 }
141 141
142 void CreateHandler(mojo::ScopedMessagePipeHandle handle) { 142 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) {
143 browser_target_.reset(new PingBrowserTargetImpl(handle.Pass(), run_loop_)); 143 browser_target_.reset(new PingBrowserTargetImpl(request.Pass(), run_loop_));
144 } 144 }
145 145
146 private: 146 private:
147 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); 147 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController);
148 }; 148 };
149 149
150 // WebUIControllerFactory that creates TestWebUIController. 150 // WebUIControllerFactory that creates TestWebUIController.
151 class TestWebUIControllerFactory : public WebUIControllerFactory { 151 class TestWebUIControllerFactory : public WebUIControllerFactory {
152 public: 152 public:
153 TestWebUIControllerFactory() : run_loop_(NULL) {} 153 TestWebUIControllerFactory() : run_loop_(NULL) {}
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 factory()->set_run_loop(&run_loop); 218 factory()->set_run_loop(&run_loop);
219 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"));
220 NavigateToURL(shell(), test_url); 220 NavigateToURL(shell(), test_url);
221 // RunLoop is quit when message received from page. 221 // RunLoop is quit when message received from page.
222 run_loop.Run(); 222 run_loop.Run();
223 EXPECT_TRUE(got_message); 223 EXPECT_TRUE(got_message);
224 } 224 }
225 225
226 } // namespace 226 } // namespace
227 } // namespace content 227 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698