Chromium Code Reviews| 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 |
|
Jialiu Lin
2017/07/06 23:58:27
safe_browsing namespace
hkamila
2017/07/07 01:29:49
Acknowledged.
| |
| 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 SafeBrowsingUIHandler::SafeBrowsingUIHandler(){}; | |
| 48 void SafeBrowsingUIHandler::ExpParamList(const base::ListValue* unused) { | |
| 49 AllowJavascript(); | |
| 50 CallJavascriptFunction("safe_browsing.addExperiment", | |
| 51 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
| |
| 52 } | |
| 53 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.
| |
| 54 web_ui()->RegisterMessageCallback( | |
| 55 "expParamList", | |
| 56 base::Bind(&SafeBrowsingUIHandler::ExpParamList, base::Unretained(this))); | |
| 57 } | |
| 58 SafeBrowsingUIHandler::~SafeBrowsingUIHandler() {} | |
| OLD | NEW |