OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 11 #include "chrome/common/url_constants.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/web_ui.h" |
| 14 #include "content/public/browser/web_ui_message_handler.h" |
| 15 #include "grit/browser_resources.h" |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 namespace { |
| 20 |
| 21 //////////////////////////////////////////////////////////////////////////////// |
| 22 // DiagnosticsHandler |
| 23 |
| 24 // Class to handle messages from chrome://diagnostics. |
| 25 class DiagnosticsWebUIHandler : public content::WebUIMessageHandler { |
| 26 public: |
| 27 DiagnosticsWebUIHandler() |
| 28 : weak_ptr_factory_(this) { |
| 29 } |
| 30 virtual ~DiagnosticsWebUIHandler() {} |
| 31 |
| 32 private: |
| 33 // WebUIMessageHandler implementation. |
| 34 virtual void RegisterMessages() OVERRIDE; |
| 35 |
| 36 // Called when the page is first loaded. |
| 37 void OnPageLoaded(const base::ListValue* args); |
| 38 |
| 39 base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_; |
| 40 DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler); |
| 41 }; |
| 42 |
| 43 void DiagnosticsWebUIHandler::RegisterMessages() { |
| 44 web_ui()->RegisterMessageCallback( |
| 45 "pageLoaded", |
| 46 base::Bind(&DiagnosticsWebUIHandler::OnPageLoaded, |
| 47 weak_ptr_factory_.GetWeakPtr())); |
| 48 } |
| 49 |
| 50 void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) { |
| 51 // TODO: invoke debugd methods to retrieve diagnostics information, and |
| 52 // upon completion call javascript function to update status. |
| 53 } |
| 54 |
| 55 } // namespace |
| 56 |
| 57 //////////////////////////////////////////////////////////////////////////////// |
| 58 // DiagnosticsUI |
| 59 |
| 60 DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui) |
| 61 : WebUIController(web_ui) { |
| 62 web_ui->AddMessageHandler(new DiagnosticsWebUIHandler()); |
| 63 |
| 64 ChromeWebUIDataSource* source = |
| 65 new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost); |
| 66 source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML); |
| 67 |
| 68 Profile* profile = Profile::FromWebUI(web_ui); |
| 69 ChromeURLDataManager::AddDataSource(profile, source); |
| 70 } |
| 71 |
| 72 } // namespace chromeos |
OLD | NEW |