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

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

Issue 946623002: [Code cleanup]Remove webui keyboard mojo binding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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
« 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/keyboard/webui/vk_webui_controller.h"
6
7 #include "base/strings/string_util.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"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_ui_data_source.h"
13 #include "content/public/common/service_registry.h"
14 #include "grit/keyboard_resources.h"
15 #include "grit/keyboard_resources_map.h"
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
17 #include "third_party/mojo/src/mojo/public/cpp/system/core.h"
18 #include "ui/keyboard/keyboard_constants.h"
19 #include "ui/keyboard/keyboard_util.h"
20 #include "ui/keyboard/webui/vk_mojo_handler.h"
21
22 namespace keyboard {
23
24 namespace {
25
26 content::WebUIDataSource* CreateKeyboardUIDataSource() {
27 content::WebUIDataSource* source =
28 content::WebUIDataSource::Create(kKeyboardHost);
29
30 size_t count = 0;
31 const GritResourceMap* resources = GetKeyboardExtensionResources(&count);
32 source->SetDefaultResource(IDR_KEYBOARD_INDEX);
33
34 const std::string keyboard_host = base::StringPrintf("%s/", kKeyboardHost);
35 for (size_t i = 0; i < count; ++i) {
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.
39 if (StartsWithASCII(std::string(resources[i].name), keyboard_host, false))
40 offset = keyboard_host.length();
41 source->AddResourcePath(resources[i].name + offset, resources[i].value);
42 }
43 return source;
44 }
45
46 } // namespace
47
48 ////////////////////////////////////////////////////////////////////////////////
49 // VKWebUIController:
50
51 VKWebUIController::VKWebUIController(content::WebUI* web_ui)
52 : WebUIController(web_ui), weak_factory_(this) {
53 content::BrowserContext* browser_context =
54 web_ui->GetWebContents()->GetBrowserContext();
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);
58 }
59
60 VKWebUIController::~VKWebUIController() {
61 }
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_ = make_scoped_ptr(new VKMojoHandler(request.Pass()));
72 }
73
74 ////////////////////////////////////////////////////////////////////////////////
75 // VKWebUIControllerFactory:
76
77 content::WebUI::TypeID VKWebUIControllerFactory::GetWebUIType(
78 content::BrowserContext* browser_context,
79 const GURL& url) const {
80 if (url == GURL(kKeyboardURL))
81 return const_cast<VKWebUIControllerFactory*>(this);
82
83 return content::WebUI::kNoWebUI;
84 }
85
86 bool VKWebUIControllerFactory::UseWebUIForURL(
87 content::BrowserContext* browser_context,
88 const GURL& url) const {
89 return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
90 }
91
92 bool VKWebUIControllerFactory::UseWebUIBindingsForURL(
93 content::BrowserContext* browser_context,
94 const GURL& url) const {
95 return UseWebUIForURL(browser_context, url);
96 }
97
98 content::WebUIController* VKWebUIControllerFactory::CreateWebUIControllerForURL(
99 content::WebUI* web_ui,
100 const GURL& url) const {
101 if (url == GURL(kKeyboardURL))
102 return new VKWebUIController(web_ui);
103 return NULL;
104 }
105
106 // static
107 VKWebUIControllerFactory* VKWebUIControllerFactory::GetInstance() {
108 return Singleton<VKWebUIControllerFactory>::get();
109 }
110
111 // protected
112 VKWebUIControllerFactory::VKWebUIControllerFactory() {
113 }
114
115 VKWebUIControllerFactory::~VKWebUIControllerFactory() {
116 }
117
118 } // 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