| OLD | NEW |
| 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/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 base::RefCountedString* ref_contents = new base::RefCountedString; | 57 base::RefCountedString* ref_contents = new base::RefCountedString; |
| 58 ref_contents->data() = contents; | 58 ref_contents->data() = contents; |
| 59 callback.Run(ref_contents); | 59 callback.Run(ref_contents); |
| 60 return true; | 60 return true; |
| 61 } | 61 } |
| 62 | 62 |
| 63 class BrowserTargetImpl : public mojo::InterfaceImpl<BrowserTarget> { | 63 class BrowserTargetImpl : public mojo::InterfaceImpl<BrowserTarget> { |
| 64 public: | 64 public: |
| 65 explicit BrowserTargetImpl(base::RunLoop* run_loop) : run_loop_(run_loop) {} | 65 explicit BrowserTargetImpl(base::RunLoop* run_loop) : run_loop_(run_loop) {} |
| 66 | 66 |
| 67 virtual ~BrowserTargetImpl() {} | 67 ~BrowserTargetImpl() override {} |
| 68 | 68 |
| 69 // mojo::InterfaceImpl<BrowserTarget> overrides: | 69 // mojo::InterfaceImpl<BrowserTarget> overrides: |
| 70 virtual void PingResponse() override { | 70 void PingResponse() override { NOTREACHED(); } |
| 71 NOTREACHED(); | |
| 72 } | |
| 73 | 71 |
| 74 protected: | 72 protected: |
| 75 base::RunLoop* run_loop_; | 73 base::RunLoop* run_loop_; |
| 76 | 74 |
| 77 private: | 75 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); | 76 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); |
| 79 }; | 77 }; |
| 80 | 78 |
| 81 class PingBrowserTargetImpl : public BrowserTargetImpl { | 79 class PingBrowserTargetImpl : public BrowserTargetImpl { |
| 82 public: | 80 public: |
| 83 explicit PingBrowserTargetImpl(base::RunLoop* run_loop) | 81 explicit PingBrowserTargetImpl(base::RunLoop* run_loop) |
| 84 : BrowserTargetImpl(run_loop) {} | 82 : BrowserTargetImpl(run_loop) {} |
| 85 | 83 |
| 86 virtual ~PingBrowserTargetImpl() {} | 84 ~PingBrowserTargetImpl() override {} |
| 87 | 85 |
| 88 // mojo::InterfaceImpl<BrowserTarget> overrides: | 86 // mojo::InterfaceImpl<BrowserTarget> overrides: |
| 89 virtual void OnConnectionEstablished() override { | 87 void OnConnectionEstablished() override { client()->Ping(); } |
| 90 client()->Ping(); | |
| 91 } | |
| 92 | 88 |
| 93 // Quit the RunLoop when called. | 89 // Quit the RunLoop when called. |
| 94 virtual void PingResponse() override { | 90 void PingResponse() override { |
| 95 got_message = true; | 91 got_message = true; |
| 96 run_loop_->Quit(); | 92 run_loop_->Quit(); |
| 97 } | 93 } |
| 98 | 94 |
| 99 private: | 95 private: |
| 100 DISALLOW_COPY_AND_ASSIGN(PingBrowserTargetImpl); | 96 DISALLOW_COPY_AND_ASSIGN(PingBrowserTargetImpl); |
| 101 }; | 97 }; |
| 102 | 98 |
| 103 // WebUIController that sets up mojo bindings. | 99 // WebUIController that sets up mojo bindings. |
| 104 class TestWebUIController : public WebUIController { | 100 class TestWebUIController : public WebUIController { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); | 116 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); |
| 121 }; | 117 }; |
| 122 | 118 |
| 123 // TestWebUIController that additionally creates the ping test BrowserTarget | 119 // TestWebUIController that additionally creates the ping test BrowserTarget |
| 124 // implementation at the right time. | 120 // implementation at the right time. |
| 125 class PingTestWebUIController : public TestWebUIController { | 121 class PingTestWebUIController : public TestWebUIController { |
| 126 public: | 122 public: |
| 127 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 123 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
| 128 : TestWebUIController(web_ui, run_loop) { | 124 : TestWebUIController(web_ui, run_loop) { |
| 129 } | 125 } |
| 130 virtual ~PingTestWebUIController() {} | 126 ~PingTestWebUIController() override {} |
| 131 | 127 |
| 132 // WebUIController overrides: | 128 // WebUIController overrides: |
| 133 virtual void RenderViewCreated(RenderViewHost* render_view_host) override { | 129 void RenderViewCreated(RenderViewHost* render_view_host) override { |
| 134 render_view_host->GetMainFrame()->GetServiceRegistry()-> | 130 render_view_host->GetMainFrame()->GetServiceRegistry()-> |
| 135 AddService<BrowserTarget>(base::Bind( | 131 AddService<BrowserTarget>(base::Bind( |
| 136 &PingTestWebUIController::CreateHandler, base::Unretained(this))); | 132 &PingTestWebUIController::CreateHandler, base::Unretained(this))); |
| 137 } | 133 } |
| 138 | 134 |
| 139 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { | 135 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { |
| 140 browser_target_.reset(mojo::WeakBindToRequest( | 136 browser_target_.reset(mojo::WeakBindToRequest( |
| 141 new PingBrowserTargetImpl(run_loop_), &request)); | 137 new PingBrowserTargetImpl(run_loop_), &request)); |
| 142 } | 138 } |
| 143 | 139 |
| 144 private: | 140 private: |
| 145 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); | 141 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); |
| 146 }; | 142 }; |
| 147 | 143 |
| 148 // WebUIControllerFactory that creates TestWebUIController. | 144 // WebUIControllerFactory that creates TestWebUIController. |
| 149 class TestWebUIControllerFactory : public WebUIControllerFactory { | 145 class TestWebUIControllerFactory : public WebUIControllerFactory { |
| 150 public: | 146 public: |
| 151 TestWebUIControllerFactory() : run_loop_(NULL) {} | 147 TestWebUIControllerFactory() : run_loop_(NULL) {} |
| 152 | 148 |
| 153 void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; } | 149 void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; } |
| 154 | 150 |
| 155 virtual WebUIController* CreateWebUIControllerForURL( | 151 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, |
| 156 WebUI* web_ui, const GURL& url) const override { | 152 const GURL& url) const override { |
| 157 if (url.query() == "ping") | 153 if (url.query() == "ping") |
| 158 return new PingTestWebUIController(web_ui, run_loop_); | 154 return new PingTestWebUIController(web_ui, run_loop_); |
| 159 return NULL; | 155 return NULL; |
| 160 } | 156 } |
| 161 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 157 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
| 162 const GURL& url) const override { | 158 const GURL& url) const override { |
| 163 return reinterpret_cast<WebUI::TypeID>(1); | 159 return reinterpret_cast<WebUI::TypeID>(1); |
| 164 } | 160 } |
| 165 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 161 bool UseWebUIForURL(BrowserContext* browser_context, |
| 162 const GURL& url) const override { |
| 163 return true; |
| 164 } |
| 165 bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
| 166 const GURL& url) const override { | 166 const GURL& url) const override { |
| 167 return true; | 167 return true; |
| 168 } | 168 } |
| 169 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | |
| 170 const GURL& url) const override { | |
| 171 return true; | |
| 172 } | |
| 173 | 169 |
| 174 private: | 170 private: |
| 175 base::RunLoop* run_loop_; | 171 base::RunLoop* run_loop_; |
| 176 | 172 |
| 177 DISALLOW_COPY_AND_ASSIGN(TestWebUIControllerFactory); | 173 DISALLOW_COPY_AND_ASSIGN(TestWebUIControllerFactory); |
| 178 }; | 174 }; |
| 179 | 175 |
| 180 class WebUIMojoTest : public ContentBrowserTest { | 176 class WebUIMojoTest : public ContentBrowserTest { |
| 181 public: | 177 public: |
| 182 WebUIMojoTest() { | 178 WebUIMojoTest() { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 NavigateToURL(other_shell, test_url); | 231 NavigateToURL(other_shell, test_url); |
| 236 // RunLoop is quit when message received from page. | 232 // RunLoop is quit when message received from page. |
| 237 other_run_loop.Run(); | 233 other_run_loop.Run(); |
| 238 EXPECT_TRUE(got_message); | 234 EXPECT_TRUE(got_message); |
| 239 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 235 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
| 240 other_shell->web_contents()->GetRenderProcessHost()); | 236 other_shell->web_contents()->GetRenderProcessHost()); |
| 241 } | 237 } |
| 242 | 238 |
| 243 } // namespace | 239 } // namespace |
| 244 } // namespace content | 240 } // namespace content |
| OLD | NEW |