| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/keyboard/keyboard.h" | 5 #include "ui/keyboard/keyboard.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/singleton.h" | |
| 9 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 10 #include "content/public/browser/browser_context.h" | |
| 11 #include "content/public/browser/web_ui_controller_factory.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/keyboard/keyboard_constants.h" | |
| 14 #include "ui/keyboard/keyboard_ui_controller.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 using content::BrowserContext; | |
| 20 using content::WebUI; | |
| 21 using content::WebUIController; | |
| 22 | |
| 23 class KeyboardWebUIControllerFactory : public content::WebUIControllerFactory { | |
| 24 public: | |
| 25 // |WebUIControllerFactory| implementation: | |
| 26 virtual content::WebUI::TypeID GetWebUIType( | |
| 27 content::BrowserContext* browser_context, | |
| 28 const GURL& url) const OVERRIDE { | |
| 29 if (url == GURL(keyboard::kKeyboardWebUIURL)) | |
| 30 return const_cast<KeyboardWebUIControllerFactory*>(this); | |
| 31 | |
| 32 return WebUI::kNoWebUI; | |
| 33 } | |
| 34 virtual bool UseWebUIForURL(content::BrowserContext* browser_context, | |
| 35 const GURL& url) const OVERRIDE { | |
| 36 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; | |
| 37 } | |
| 38 virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, | |
| 39 const GURL& url) const OVERRIDE { | |
| 40 return UseWebUIForURL(browser_context, url); | |
| 41 } | |
| 42 virtual content::WebUIController* CreateWebUIControllerForURL( | |
| 43 content::WebUI* web_ui, | |
| 44 const GURL& url) const OVERRIDE { | |
| 45 if (url == GURL(keyboard::kKeyboardWebUIURL)) | |
| 46 return new keyboard::KeyboardUIController(web_ui); | |
| 47 return NULL; | |
| 48 } | |
| 49 | |
| 50 static KeyboardWebUIControllerFactory* GetInstance() { | |
| 51 return Singleton<KeyboardWebUIControllerFactory>::get(); | |
| 52 } | |
| 53 | |
| 54 protected: | |
| 55 KeyboardWebUIControllerFactory() {} | |
| 56 virtual ~KeyboardWebUIControllerFactory() {} | |
| 57 | |
| 58 private: | |
| 59 friend struct DefaultSingletonTraits<KeyboardWebUIControllerFactory>; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(KeyboardWebUIControllerFactory); | |
| 62 }; | |
| 63 | |
| 64 } // namespace | |
| 65 | 10 |
| 66 namespace keyboard { | 11 namespace keyboard { |
| 67 | 12 |
| 68 static bool initialized = false; | 13 static bool initialized = false; |
| 69 | 14 |
| 70 void ResetKeyboardForTesting() { | 15 void ResetKeyboardForTesting() { |
| 71 content::WebUIControllerFactory::UnregisterFactoryForTesting( | |
| 72 KeyboardWebUIControllerFactory::GetInstance()); | |
| 73 initialized = false; | 16 initialized = false; |
| 74 } | 17 } |
| 75 | 18 |
| 76 void InitializeKeyboard() { | 19 void InitializeKeyboard() { |
| 77 if (initialized) | 20 if (initialized) |
| 78 return; | 21 return; |
| 79 initialized = true; | 22 initialized = true; |
| 80 | 23 |
| 81 base::FilePath pak_dir; | 24 base::FilePath pak_dir; |
| 82 PathService::Get(base::DIR_MODULE, &pak_dir); | 25 PathService::Get(base::DIR_MODULE, &pak_dir); |
| 83 base::FilePath pak_file = pak_dir.Append( | 26 base::FilePath pak_file = pak_dir.Append( |
| 84 FILE_PATH_LITERAL("keyboard_resources.pak")); | 27 FILE_PATH_LITERAL("keyboard_resources.pak")); |
| 85 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 28 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
| 86 pak_file, ui::SCALE_FACTOR_100P); | 29 pak_file, ui::SCALE_FACTOR_100P); |
| 87 | |
| 88 content::WebUIControllerFactory::RegisterFactory( | |
| 89 KeyboardWebUIControllerFactory::GetInstance()); | |
| 90 } | 30 } |
| 91 | 31 |
| 92 } // namespace keyboard | 32 } // namespace keyboard |
| OLD | NEW |