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