Chromium Code Reviews| Index: components/safe_browsing/web_ui/safe_browsing_ui.cc |
| diff --git a/components/safe_browsing/web_ui/safe_browsing_ui.cc b/components/safe_browsing/web_ui/safe_browsing_ui.cc |
| index 761b7cbd217c7c3b48efb4a40fe621912b217653..d40059d2503130b158d251bbd2798dd12d8dba87 100644 |
| --- a/components/safe_browsing/web_ui/safe_browsing_ui.cc |
| +++ b/components/safe_browsing/web_ui/safe_browsing_ui.cc |
| @@ -1,28 +1,41 @@ |
| -// Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| + |
| #include "components/safe_browsing/web_ui/safe_browsing_ui.h" |
| + |
| +#include <algorithm> |
| +#include <utility> |
| +#include "base/macros.h" |
| +#include "base/values.h" |
| #include "components/grit/components_resources.h" |
| #include "components/grit/components_scaled_resources.h" |
| +#include "components/safe_browsing/features.h" |
| #include "components/safe_browsing/web_ui/constants.h" |
| #include "components/strings/grit/components_strings.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_ui.h" |
| -#include "content/public/browser/web_ui_data_source.h" |
| +#include "content/public/browser/web_ui_message_handler.h" |
|
Jialiu Lin
2017/07/06 23:58:27
safe_browsing namespace
hkamila
2017/07/07 01:29:49
Acknowledged.
|
| SafeBrowsingUI::SafeBrowsingUI(content::WebUI* web_ui) |
| : content::WebUIController(web_ui) { |
| // Set up the chrome://safe-browsing source. |
| + |
| content::WebUIDataSource* html_source = content::WebUIDataSource::Create( |
| safe_browsing::kChromeUISafeBrowsingHost); |
| + // Register callback handler. |
| + // Handles messages from JavaScript to C++ via chrome.send(). |
| + web_ui->AddMessageHandler(base::MakeUnique<SafeBrowsingUIHandler>()); |
| + |
| // Add localized string resources. |
| html_source->AddLocalizedString("sbUnderConstruction", |
| IDS_SB_UNDER_CONSTRUCTION); |
| // Add required resources. |
| html_source->AddResourcePath("safe_browsing.css", IDR_SAFE_BROWSING_CSS); |
| + html_source->AddResourcePath("safe_browsing.js", IDR_SAFE_BROWSING_JS); |
| html_source->SetDefaultResource(IDR_SAFE_BROWSING_HTML); |
| content::BrowserContext* browser_context = |
| @@ -31,3 +44,15 @@ SafeBrowsingUI::SafeBrowsingUI(content::WebUI* web_ui) |
| } |
| SafeBrowsingUI::~SafeBrowsingUI() {} |
| +SafeBrowsingUIHandler::SafeBrowsingUIHandler(){}; |
| +void SafeBrowsingUIHandler::ExpParamList(const base::ListValue* unused) { |
| + AllowJavascript(); |
| + CallJavascriptFunction("safe_browsing.addExperiment", |
| + GetTrueParametersList()); |
|
vakh (use Gerrit instead)
2017/07/07 00:23:40
Where is GetTrueParametersList defined in JS?
hkamila
2017/07/07 01:29:50
To my understanding, function addExperiment(result
|
| +} |
| +void SafeBrowsingUIHandler::RegisterMessages() { |
|
vakh (use Gerrit instead)
2017/07/07 00:23:40
Please insert a blank line between function defini
hkamila
2017/07/07 01:29:49
Acknowledged.
|
| + web_ui()->RegisterMessageCallback( |
| + "expParamList", |
| + base::Bind(&SafeBrowsingUIHandler::ExpParamList, base::Unretained(this))); |
| +} |
| +SafeBrowsingUIHandler::~SafeBrowsingUIHandler() {} |