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

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: address comment Created 6 years, 5 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 &contents, 52 &contents,
53 std::string::npos)) << id; 53 std::string::npos)) << id;
54 base::RefCountedString* ref_contents = new base::RefCountedString; 54 base::RefCountedString* ref_contents = new base::RefCountedString;
55 ref_contents->data() = contents; 55 ref_contents->data() = contents;
56 callback.Run(ref_contents); 56 callback.Run(ref_contents);
57 return true; 57 return true;
58 } 58 }
59 59
60 class BrowserTargetImpl : public BrowserTarget { 60 class BrowserTargetImpl : public BrowserTarget {
61 public: 61 public:
62 BrowserTargetImpl(mojo::ScopedMessagePipeHandle handle, 62 BrowserTargetImpl(mojo::InterfaceRequest<BrowserTarget> request,
63 base::RunLoop* run_loop) 63 base::RunLoop* run_loop)
64 : run_loop_(run_loop) { 64 : run_loop_(run_loop) {
65 renderer_.Bind(handle.Pass()); 65 renderer_.Bind(request.PassMessagePipe());
darin (slow to review) 2014/06/28 21:10:38 It is kind of awkward to be connecting an Interfac
Sam McNally 2014/06/30 01:26:14 Done.
66 renderer_.set_client(this); 66 renderer_.set_client(this);
67 } 67 }
68 68
69 virtual ~BrowserTargetImpl() {} 69 virtual ~BrowserTargetImpl() {}
70 70
71 // BrowserTarget overrides: 71 // BrowserTarget overrides:
72 virtual void PingResponse() OVERRIDE { 72 virtual void PingResponse() OVERRIDE {
73 NOTREACHED(); 73 NOTREACHED();
74 } 74 }
75 75
76 protected: 76 protected:
77 RendererTargetPtr renderer_; 77 RendererTargetPtr renderer_;
78 base::RunLoop* run_loop_; 78 base::RunLoop* run_loop_;
79 79
80 private: 80 private:
81 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); 81 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl);
82 }; 82 };
83 83
84 class PingBrowserTargetImpl : public BrowserTargetImpl { 84 class PingBrowserTargetImpl : public BrowserTargetImpl {
85 public: 85 public:
86 PingBrowserTargetImpl(mojo::ScopedMessagePipeHandle handle, 86 PingBrowserTargetImpl(mojo::InterfaceRequest<BrowserTarget> request,
87 base::RunLoop* run_loop) 87 base::RunLoop* run_loop)
88 : BrowserTargetImpl(handle.Pass(), run_loop) { 88 : BrowserTargetImpl(request.Pass(), run_loop) {
89 renderer_->Ping(); 89 renderer_->Ping();
90 } 90 }
91 91
92 virtual ~PingBrowserTargetImpl() {} 92 virtual ~PingBrowserTargetImpl() {}
93 93
94 // BrowserTarget overrides: 94 // BrowserTarget overrides:
95 // Quit the RunLoop when called. 95 // Quit the RunLoop when called.
96 virtual void PingResponse() OVERRIDE { 96 virtual void PingResponse() OVERRIDE {
97 got_message = true; 97 got_message = true;
98 run_loop_->Quit(); 98 run_loop_->Quit();
(...skipping 27 matching lines...) Expand all
126 // implementation at the right time. 126 // implementation at the right time.
127 class PingTestWebUIController : public TestWebUIController { 127 class PingTestWebUIController : public TestWebUIController {
128 public: 128 public:
129 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) 129 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop)
130 : TestWebUIController(web_ui, run_loop) { 130 : TestWebUIController(web_ui, run_loop) {
131 } 131 }
132 virtual ~PingTestWebUIController() {} 132 virtual ~PingTestWebUIController() {}
133 133
134 // WebUIController overrides: 134 // WebUIController overrides:
135 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { 135 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE {
136 render_view_host->GetMainFrame()->GetServiceRegistry()->AddService( 136 render_view_host->GetMainFrame()->GetServiceRegistry()->
137 "webui_controller", 137 AddService<BrowserTarget>(base::Bind(
138 base::Bind(&PingTestWebUIController::CreateHandler, 138 &PingTestWebUIController::CreateHandler, base::Unretained(this)));
139 base::Unretained(this)));
140 } 139 }
141 140
142 void CreateHandler(mojo::ScopedMessagePipeHandle handle) { 141 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) {
143 browser_target_.reset(new PingBrowserTargetImpl(handle.Pass(), run_loop_)); 142 browser_target_.reset(new PingBrowserTargetImpl(request.Pass(), run_loop_));
144 } 143 }
145 144
146 private: 145 private:
147 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); 146 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController);
148 }; 147 };
149 148
150 // WebUIControllerFactory that creates TestWebUIController. 149 // WebUIControllerFactory that creates TestWebUIController.
151 class TestWebUIControllerFactory : public WebUIControllerFactory { 150 class TestWebUIControllerFactory : public WebUIControllerFactory {
152 public: 151 public:
153 TestWebUIControllerFactory() : run_loop_(NULL) {} 152 TestWebUIControllerFactory() : run_loop_(NULL) {}
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 NavigateToURL(other_shell, test_url); 230 NavigateToURL(other_shell, test_url);
232 // RunLoop is quit when message received from page. 231 // RunLoop is quit when message received from page.
233 other_run_loop.Run(); 232 other_run_loop.Run();
234 EXPECT_TRUE(got_message); 233 EXPECT_TRUE(got_message);
235 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), 234 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(),
236 other_shell->web_contents()->GetRenderProcessHost()); 235 other_shell->web_contents()->GetRenderProcessHost());
237 } 236 }
238 237
239 } // namespace 238 } // namespace
240 } // namespace content 239 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698