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

Side by Side Diff: chrome/browser/ui/webui/mojo_web_ui_controller.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: handle the case where handles arrive before the RenderFrame is ready 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 "chrome/browser/ui/webui/mojo_web_ui_controller.h" 5 #include "chrome/browser/ui/webui/mojo_web_ui_controller.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/webui/mojo_web_ui_handler.h" 8 #include "chrome/browser/ui/webui/mojo_web_ui_handler.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/render_process_host.h"
9 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_ui_data_source.h" 12 #include "content/public/browser/web_ui_data_source.h"
11 #include "content/public/common/bindings_policy.h" 13 #include "content/public/common/bindings_policy.h"
14 #include "content/public/common/service_registry.h"
12 #include "mojo/public/cpp/system/core.h" 15 #include "mojo/public/cpp/system/core.h"
13 16
14 MojoWebUIController::MojoWebUIController(content::WebUI* contents) 17 MojoWebUIController::MojoWebUIController(content::WebUI* contents)
15 : WebUIController(contents), 18 : WebUIController(contents), mojo_data_source_(NULL), weak_factory_(this) {
16 mojo_data_source_(NULL) {
17 } 19 }
18 20
19 MojoWebUIController::~MojoWebUIController() { 21 MojoWebUIController::~MojoWebUIController() {
20 } 22 }
21 23
22 void MojoWebUIController::RenderViewCreated( 24 void MojoWebUIController::RenderViewCreated(
23 content::RenderViewHost* render_view_host) { 25 content::RenderViewHost* render_view_host) {
24 render_view_host->AllowBindings(content::BINDINGS_POLICY_WEB_UI); 26 render_view_host->AllowBindings(content::BINDINGS_POLICY_WEB_UI);
25 27 render_view_host->GetProcess()->ActivateMojo();
darin (slow to review) 2014/06/18 00:09:28 I don't think we want to call ActivateMojo() here.
Sam McNally 2014/06/18 01:31:40 Done.
26 mojo::MessagePipe pipe; 28 render_view_host->GetMainFrame()->GetServiceRegistry()->AddService(
27 ui_handler_ = CreateUIHandler(pipe.handle0.Pass()); 29 "webui_controller",
28 render_view_host->SetWebUIHandle(pipe.handle1.Pass()); 30 base::Bind(&MojoWebUIController::CreateAndStoreUIHandler,
31 weak_factory_.GetWeakPtr()));
29 } 32 }
30 33
31 void MojoWebUIController::AddMojoResourcePath(const std::string& path, 34 void MojoWebUIController::AddMojoResourcePath(const std::string& path,
32 int resource_id) { 35 int resource_id) {
33 if (!mojo_data_source_) { 36 if (!mojo_data_source_) {
34 mojo_data_source_ = content::WebUIDataSource::AddMojoDataSource( 37 mojo_data_source_ = content::WebUIDataSource::AddMojoDataSource(
35 Profile::FromWebUI(web_ui())); 38 Profile::FromWebUI(web_ui()));
36 } 39 }
37 mojo_data_source_->AddResourcePath(path, resource_id); 40 mojo_data_source_->AddResourcePath(path, resource_id);
38 } 41 }
42
43 void MojoWebUIController::CreateAndStoreUIHandler(
44 mojo::ScopedMessagePipeHandle handle) {
45 ui_handler_ = CreateUIHandler(handle.Pass());
46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698