| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/physical_web/physical_web_ui.h" | 5 #include "chrome/browser/ui/webui/physical_web/physical_web_ui.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 9 #include "chrome/browser/browser_process_impl.h" | 9 #include "chrome/browser/browser_process_impl.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "components/grit/components_resources.h" | 12 #include "components/grit/components_resources.h" |
| 13 #include "components/physical_web/data_source/physical_web_data_source.h" | 13 #include "components/physical_web/data_source/physical_web_data_source.h" |
| 14 #include "components/physical_web/webui/physical_web_base_message_handler.h" | 14 #include "components/physical_web/webui/physical_web_base_message_handler.h" |
| 15 #include "components/physical_web/webui/physical_web_ui_constants.h" | 15 #include "components/physical_web/webui/physical_web_ui_constants.h" |
| 16 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 17 #include "content/public/browser/web_ui_data_source.h" | 17 #include "content/public/browser/web_ui_data_source.h" |
| 18 #include "content/public/browser/web_ui_message_handler.h" | 18 #include "content/public/browser/web_ui_message_handler.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 content::WebUIDataSource* CreatePhysicalWebHTMLSource() { | 22 content::WebUIDataSource* CreatePhysicalWebHTMLSource() { |
| 23 content::WebUIDataSource* source = content::WebUIDataSource::Create( | 23 content::WebUIDataSource* source = |
| 24 chrome::kChromeUIPhysicalWebHost); | 24 content::WebUIDataSource::Create(chrome::kChromeUIPhysicalWebHost); |
| 25 | 25 |
| 26 source->AddLocalizedString(physical_web_ui::kTitle, | 26 source->AddLocalizedString(physical_web_ui::kTitle, |
| 27 IDS_PHYSICAL_WEB_UI_TITLE); | 27 IDS_PHYSICAL_WEB_UI_TITLE); |
| 28 source->AddLocalizedString(physical_web_ui::kEmptyMessage, | 28 source->AddLocalizedString(physical_web_ui::kEmptyMessage, |
| 29 IDS_PHYSICAL_WEB_UI_EMPTY_MESSAGE); | 29 IDS_PHYSICAL_WEB_UI_EMPTY_MESSAGE); |
| 30 source->SetJsonPath("strings.js"); | 30 source->SetJsonPath("strings.js"); |
| 31 source->AddResourcePath(physical_web_ui::kPhysicalWebJS, | 31 source->AddResourcePath(physical_web_ui::kPhysicalWebJS, |
| 32 IDR_PHYSICAL_WEB_UI_JS); | 32 IDR_PHYSICAL_WEB_UI_JS); |
| 33 source->AddResourcePath(physical_web_ui::kPhysicalWebCSS, | 33 source->AddResourcePath(physical_web_ui::kPhysicalWebCSS, |
| 34 IDR_PHYSICAL_WEB_UI_CSS); | 34 IDR_PHYSICAL_WEB_UI_CSS); |
| 35 source->SetDefaultResource(IDR_PHYSICAL_WEB_UI_HTML); | 35 source->SetDefaultResource(IDR_PHYSICAL_WEB_UI_HTML); |
| 36 source->AddResourcePath(physical_web_ui::kPhysicalWebLinkIcon, |
| 37 IDR_PHYSICAL_WEB_UI_LINK_ICON); |
| 36 return source; | 38 return source; |
| 37 } | 39 } |
| 38 | 40 |
| 39 // Implements all MessageHandler core functionality. This is extends the | 41 // Implements all MessageHandler core functionality. This is extends the |
| 40 // PhysicalWebBaseMessageHandler and implements functions to manipulate an | 42 // PhysicalWebBaseMessageHandler and implements functions to manipulate an |
| 41 // Android-specific WebUI object. | 43 // Android-specific WebUI object. |
| 42 class MessageHandlerImpl | 44 class MessageHandlerImpl |
| 43 : public physical_web_ui::PhysicalWebBaseMessageHandler { | 45 : public physical_web_ui::PhysicalWebBaseMessageHandler { |
| 44 public: | 46 public: |
| 45 explicit MessageHandlerImpl(content::WebUI* web_ui) : web_ui_(web_ui) {} | 47 explicit MessageHandlerImpl(content::WebUI* web_ui) : web_ui_(web_ui) {} |
| (...skipping 27 matching lines...) Expand all Loading... |
| 73 impl_->RegisterMessages(); | 75 impl_->RegisterMessages(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 std::unique_ptr<MessageHandlerImpl> impl_; | 79 std::unique_ptr<MessageHandlerImpl> impl_; |
| 78 DISALLOW_COPY_AND_ASSIGN(PhysicalWebMessageHandler); | 80 DISALLOW_COPY_AND_ASSIGN(PhysicalWebMessageHandler); |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 } // namespace | 83 } // namespace |
| 82 | 84 |
| 83 PhysicalWebUI::PhysicalWebUI(content::WebUI* web_ui) | 85 PhysicalWebUI::PhysicalWebUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 84 : WebUIController(web_ui) { | |
| 85 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 86 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 86 CreatePhysicalWebHTMLSource()); | 87 CreatePhysicalWebHTMLSource()); |
| 87 web_ui->AddMessageHandler(base::MakeUnique<PhysicalWebMessageHandler>()); | 88 web_ui->AddMessageHandler(base::MakeUnique<PhysicalWebMessageHandler>()); |
| 88 base::RecordAction(base::UserMetricsAction("PhysicalWeb.WebUI.Open")); | 89 base::RecordAction(base::UserMetricsAction("PhysicalWeb.WebUI.Open")); |
| 89 } | 90 } |
| 90 | 91 |
| 91 PhysicalWebUI::~PhysicalWebUI() = default; | 92 PhysicalWebUI::~PhysicalWebUI() = default; |
| OLD | NEW |