| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 | |
| 5 #include "components/safe_browsing/web_ui/safe_browsing_ui.h" | 4 #include "components/safe_browsing/web_ui/safe_browsing_ui.h" |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <utility> | |
| 9 #include "base/macros.h" | |
| 10 #include "base/values.h" | |
| 11 #include "components/grit/components_resources.h" | 5 #include "components/grit/components_resources.h" |
| 12 #include "components/grit/components_scaled_resources.h" | 6 #include "components/grit/components_scaled_resources.h" |
| 13 #include "components/safe_browsing/features.h" | |
| 14 #include "components/safe_browsing/web_ui/constants.h" | 7 #include "components/safe_browsing/web_ui/constants.h" |
| 15 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
| 16 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_ui.h" | 11 #include "content/public/browser/web_ui.h" |
| 19 #include "content/public/browser/web_ui_message_handler.h" | 12 #include "content/public/browser/web_ui_data_source.h" |
| 20 namespace safe_browsing { | 13 |
| 21 SafeBrowsingUI::SafeBrowsingUI(content::WebUI* web_ui) | 14 SafeBrowsingUI::SafeBrowsingUI(content::WebUI* web_ui) |
| 22 : content::WebUIController(web_ui) { | 15 : content::WebUIController(web_ui) { |
| 23 // Set up the chrome://safe-browsing source. | 16 // Set up the chrome://safe-browsing source. |
| 24 | |
| 25 content::WebUIDataSource* html_source = content::WebUIDataSource::Create( | 17 content::WebUIDataSource* html_source = content::WebUIDataSource::Create( |
| 26 safe_browsing::kChromeUISafeBrowsingHost); | 18 safe_browsing::kChromeUISafeBrowsingHost); |
| 27 | 19 |
| 28 // Register callback handler. | |
| 29 // Handles messages from JavaScript to C++ via chrome.send(). | |
| 30 web_ui->AddMessageHandler(base::MakeUnique<SafeBrowsingUIHandler>()); | |
| 31 | |
| 32 // Add localized string resources. | 20 // Add localized string resources. |
| 33 html_source->AddLocalizedString("sbUnderConstruction", | 21 html_source->AddLocalizedString("sbUnderConstruction", |
| 34 IDS_SB_UNDER_CONSTRUCTION); | 22 IDS_SB_UNDER_CONSTRUCTION); |
| 35 | 23 |
| 36 // Add required resources. | 24 // Add required resources. |
| 37 html_source->AddResourcePath("safe_browsing.css", IDR_SAFE_BROWSING_CSS); | 25 html_source->AddResourcePath("safe_browsing.css", IDR_SAFE_BROWSING_CSS); |
| 38 html_source->AddResourcePath("safe_browsing.js", IDR_SAFE_BROWSING_JS); | |
| 39 html_source->SetDefaultResource(IDR_SAFE_BROWSING_HTML); | 26 html_source->SetDefaultResource(IDR_SAFE_BROWSING_HTML); |
| 40 | 27 |
| 41 content::BrowserContext* browser_context = | 28 content::BrowserContext* browser_context = |
| 42 web_ui->GetWebContents()->GetBrowserContext(); | 29 web_ui->GetWebContents()->GetBrowserContext(); |
| 43 content::WebUIDataSource::Add(browser_context, html_source); | 30 content::WebUIDataSource::Add(browser_context, html_source); |
| 44 } | 31 } |
| 45 | 32 |
| 46 SafeBrowsingUI::~SafeBrowsingUI() {} | 33 SafeBrowsingUI::~SafeBrowsingUI() {} |
| 47 | |
| 48 SafeBrowsingUIHandler::SafeBrowsingUIHandler(){}; | |
| 49 | |
| 50 void SafeBrowsingUIHandler::ExpParamList(const base::ListValue* unused) { | |
| 51 AllowJavascript(); | |
| 52 CallJavascriptFunction("safe_browsing.addExperiment", GetFeatureStatusList()); | |
| 53 } | |
| 54 | |
| 55 void SafeBrowsingUIHandler::RegisterMessages() { | |
| 56 web_ui()->RegisterMessageCallback( | |
| 57 "expParamList", | |
| 58 base::Bind(&SafeBrowsingUIHandler::ExpParamList, base::Unretained(this))); | |
| 59 } | |
| 60 | |
| 61 SafeBrowsingUIHandler::~SafeBrowsingUIHandler() {} | |
| 62 } // namespace safe_browsing | |
| OLD | NEW |