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

Side by Side Diff: ui/keyboard/webui/vk_webui_controller.cc

Issue 328303008: athena: Use mojo to provide the bindings for the virtual keyboard. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/keyboard/webui/vk_webui_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "athena/virtual_keyboard/vk_webui_controller.h" 5 #include "ui/keyboard/webui/vk_webui_controller.h"
6 6
7 #include "athena/virtual_keyboard/vk_message_handler.h"
8 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_ui_data_source.h" 12 #include "content/public/browser/web_ui_data_source.h"
13 #include "content/public/common/service_registry.h"
12 #include "grit/keyboard_resources.h" 14 #include "grit/keyboard_resources.h"
13 #include "grit/keyboard_resources_map.h" 15 #include "grit/keyboard_resources_map.h"
16 #include "mojo/public/cpp/bindings/interface_impl.h"
17 #include "mojo/public/cpp/system/core.h"
14 #include "ui/keyboard/keyboard_constants.h" 18 #include "ui/keyboard/keyboard_constants.h"
15 #include "ui/keyboard/keyboard_util.h" 19 #include "ui/keyboard/keyboard_util.h"
20 #include "ui/keyboard/webui/vk_mojo_handler.h"
16 21
17 namespace athena { 22 namespace keyboard {
18 23
19 namespace { 24 namespace {
20 25
21 content::WebUIDataSource* CreateKeyboardUIDataSource() { 26 content::WebUIDataSource* CreateKeyboardUIDataSource() {
22 content::WebUIDataSource* source = 27 content::WebUIDataSource* source =
23 content::WebUIDataSource::Create(keyboard::kKeyboardHost); 28 content::WebUIDataSource::Create(kKeyboardHost);
24 29
25 size_t count = 0; 30 size_t count = 0;
26 const GritResourceMap* resources = 31 const GritResourceMap* resources = GetKeyboardExtensionResources(&count);
27 keyboard::GetKeyboardExtensionResources(&count);
28 source->SetDefaultResource(IDR_KEYBOARD_INDEX); 32 source->SetDefaultResource(IDR_KEYBOARD_INDEX);
29 33
30 const std::string keyboard_host = 34 const std::string keyboard_host = base::StringPrintf("%s/", kKeyboardHost);
31 base::StringPrintf("%s/", keyboard::kKeyboardHost);
32 for (size_t i = 0; i < count; ++i) { 35 for (size_t i = 0; i < count; ++i) {
33 size_t offset = 0; 36 size_t offset = 0;
37 // The webui URL needs to skip the 'keyboard/' at the front of the resource
38 // names, since it is part of the data-source name.
34 if (StartsWithASCII(std::string(resources[i].name), keyboard_host, false)) 39 if (StartsWithASCII(std::string(resources[i].name), keyboard_host, false))
35 offset = keyboard_host.length(); 40 offset = keyboard_host.length();
36 source->AddResourcePath(resources[i].name + offset, resources[i].value); 41 source->AddResourcePath(resources[i].name + offset, resources[i].value);
37 } 42 }
38 return source; 43 return source;
39 } 44 }
40 45
41 } // namespace 46 } // namespace
42 47
43 //////////////////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////////////////
44 // VKWebUIController: 49 // VKWebUIController:
45 50
46 VKWebUIController::VKWebUIController(content::WebUI* web_ui) 51 VKWebUIController::VKWebUIController(content::WebUI* web_ui)
47 : WebUIController(web_ui) { 52 : WebUIController(web_ui), weak_factory_(this) {
48 content::BrowserContext* browser_context = 53 content::BrowserContext* browser_context =
49 web_ui->GetWebContents()->GetBrowserContext(); 54 web_ui->GetWebContents()->GetBrowserContext();
50 web_ui->AddMessageHandler(new VKMessageHandler());
51 content::WebUIDataSource::Add(browser_context, CreateKeyboardUIDataSource()); 55 content::WebUIDataSource::Add(browser_context, CreateKeyboardUIDataSource());
56 content::WebUIDataSource::AddMojoDataSource(browser_context)->AddResourcePath(
57 "ui/keyboard/webui/keyboard.mojom", IDR_KEYBOARD_MOJO_GEN_JS);
52 } 58 }
53 59
54 VKWebUIController::~VKWebUIController() { 60 VKWebUIController::~VKWebUIController() {
55 } 61 }
56 62
63 void VKWebUIController::RenderViewCreated(content::RenderViewHost* host) {
64 host->GetMainFrame()->GetServiceRegistry()->AddService<KeyboardUIHandlerMojo>(
65 base::Bind(&VKWebUIController::CreateAndStoreUIHandler,
66 weak_factory_.GetWeakPtr()));
67 }
68
69 void VKWebUIController::CreateAndStoreUIHandler(
70 mojo::InterfaceRequest<KeyboardUIHandlerMojo> request) {
71 ui_handler_ = scoped_ptr<VKMojoHandler>(
72 mojo::WeakBindToRequest(new VKMojoHandler(), &request));
73 }
74
57 //////////////////////////////////////////////////////////////////////////////// 75 ////////////////////////////////////////////////////////////////////////////////
58 // VKWebUIControllerFactory: 76 // VKWebUIControllerFactory:
59 77
60 content::WebUI::TypeID VKWebUIControllerFactory::GetWebUIType( 78 content::WebUI::TypeID VKWebUIControllerFactory::GetWebUIType(
61 content::BrowserContext* browser_context, 79 content::BrowserContext* browser_context,
62 const GURL& url) const { 80 const GURL& url) const {
63 if (url == GURL(keyboard::kKeyboardURL)) 81 if (url == GURL(kKeyboardURL))
64 return const_cast<VKWebUIControllerFactory*>(this); 82 return const_cast<VKWebUIControllerFactory*>(this);
65 83
66 return content::WebUI::kNoWebUI; 84 return content::WebUI::kNoWebUI;
67 } 85 }
68 86
69 bool VKWebUIControllerFactory::UseWebUIForURL( 87 bool VKWebUIControllerFactory::UseWebUIForURL(
70 content::BrowserContext* browser_context, 88 content::BrowserContext* browser_context,
71 const GURL& url) const { 89 const GURL& url) const {
72 return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI; 90 return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
73 } 91 }
74 92
75 bool VKWebUIControllerFactory::UseWebUIBindingsForURL( 93 bool VKWebUIControllerFactory::UseWebUIBindingsForURL(
76 content::BrowserContext* browser_context, 94 content::BrowserContext* browser_context,
77 const GURL& url) const { 95 const GURL& url) const {
78 return UseWebUIForURL(browser_context, url); 96 return UseWebUIForURL(browser_context, url);
79 } 97 }
80 98
81 content::WebUIController* VKWebUIControllerFactory::CreateWebUIControllerForURL( 99 content::WebUIController* VKWebUIControllerFactory::CreateWebUIControllerForURL(
82 content::WebUI* web_ui, 100 content::WebUI* web_ui,
83 const GURL& url) const { 101 const GURL& url) const {
84 if (url == GURL(keyboard::kKeyboardURL)) 102 if (url == GURL(kKeyboardURL))
85 return new VKWebUIController(web_ui); 103 return new VKWebUIController(web_ui);
86 return NULL; 104 return NULL;
87 } 105 }
88 106
89 // static 107 // static
90 VKWebUIControllerFactory* VKWebUIControllerFactory::GetInstance() { 108 VKWebUIControllerFactory* VKWebUIControllerFactory::GetInstance() {
91 return Singleton<VKWebUIControllerFactory>::get(); 109 return Singleton<VKWebUIControllerFactory>::get();
92 } 110 }
93 111
94 // protected 112 // protected
95 VKWebUIControllerFactory::VKWebUIControllerFactory() { 113 VKWebUIControllerFactory::VKWebUIControllerFactory() {
96 } 114 }
97 115
98 VKWebUIControllerFactory::~VKWebUIControllerFactory() { 116 VKWebUIControllerFactory::~VKWebUIControllerFactory() {
99 } 117 }
100 118
101 } // namespace athena 119 } // namespace keyboard
OLDNEW
« no previous file with comments | « ui/keyboard/webui/vk_webui_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698