Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 1314843007: Refactor connection_security into SecurityStateModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: create SecurityStateModel for chromeos login webview Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "chrome/browser/profiles/profile_metrics.h" 70 #include "chrome/browser/profiles/profile_metrics.h"
71 #include "chrome/browser/profiles/profiles_state.h" 71 #include "chrome/browser/profiles/profiles_state.h"
72 #include "chrome/browser/repost_form_warning_controller.h" 72 #include "chrome/browser/repost_form_warning_controller.h"
73 #include "chrome/browser/search/search.h" 73 #include "chrome/browser/search/search.h"
74 #include "chrome/browser/sessions/session_restore.h" 74 #include "chrome/browser/sessions/session_restore.h"
75 #include "chrome/browser/sessions/session_service.h" 75 #include "chrome/browser/sessions/session_service.h"
76 #include "chrome/browser/sessions/session_service_factory.h" 76 #include "chrome/browser/sessions/session_service_factory.h"
77 #include "chrome/browser/sessions/session_tab_helper.h" 77 #include "chrome/browser/sessions/session_tab_helper.h"
78 #include "chrome/browser/sessions/tab_restore_service.h" 78 #include "chrome/browser/sessions/tab_restore_service.h"
79 #include "chrome/browser/sessions/tab_restore_service_factory.h" 79 #include "chrome/browser/sessions/tab_restore_service_factory.h"
80 #include "chrome/browser/ssl/security_state_model.h"
80 #include "chrome/browser/sync/profile_sync_service.h" 81 #include "chrome/browser/sync/profile_sync_service.h"
81 #include "chrome/browser/sync/profile_sync_service_factory.h" 82 #include "chrome/browser/sync/profile_sync_service_factory.h"
82 #include "chrome/browser/sync/sync_ui_util.h" 83 #include "chrome/browser/sync/sync_ui_util.h"
83 #include "chrome/browser/tab_contents/retargeting_details.h" 84 #include "chrome/browser/tab_contents/retargeting_details.h"
84 #include "chrome/browser/tab_contents/tab_util.h" 85 #include "chrome/browser/tab_contents/tab_util.h"
85 #include "chrome/browser/task_management/web_contents_tags.h" 86 #include "chrome/browser/task_management/web_contents_tags.h"
86 #include "chrome/browser/themes/theme_service.h" 87 #include "chrome/browser/themes/theme_service.h"
87 #include "chrome/browser/themes/theme_service_factory.h" 88 #include "chrome/browser/themes/theme_service_factory.h"
88 #include "chrome/browser/translate/chrome_translate_client.h" 89 #include "chrome/browser/translate/chrome_translate_client.h"
89 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" 90 #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 BrowserWindow* CreateBrowserWindow(Browser* browser) { 248 BrowserWindow* CreateBrowserWindow(Browser* browser) {
248 return BrowserWindow::CreateBrowserWindow(browser); 249 return BrowserWindow::CreateBrowserWindow(browser);
249 } 250 }
250 251
251 // Is the fast tab unload experiment enabled? 252 // Is the fast tab unload experiment enabled?
252 bool IsFastTabUnloadEnabled() { 253 bool IsFastTabUnloadEnabled() {
253 return base::CommandLine::ForCurrentProcess()->HasSwitch( 254 return base::CommandLine::ForCurrentProcess()->HasSwitch(
254 switches::kEnableFastUnload); 255 switches::kEnableFastUnload);
255 } 256 }
256 257
258 // Note: This is a lossy operation. Not all of the policies that can be
259 // expressed by a SecurityLevel (a //chrome concept) can be expressed by
260 // a content::SecurityStyle.
261 content::SecurityStyle SecurityLevelToSecurityStyle(
262 SecurityStateModel::SecurityLevel security_level) {
263 switch (security_level) {
264 case SecurityStateModel::NONE:
265 return content::SECURITY_STYLE_UNAUTHENTICATED;
266 case SecurityStateModel::SECURITY_WARNING:
267 case SecurityStateModel::SECURITY_POLICY_WARNING:
268 return content::SECURITY_STYLE_WARNING;
269 case SecurityStateModel::EV_SECURE:
270 case SecurityStateModel::SECURE:
271 return content::SECURITY_STYLE_AUTHENTICATED;
272 case SecurityStateModel::SECURITY_ERROR:
273 return content::SECURITY_STYLE_AUTHENTICATION_BROKEN;
274 }
275
276 NOTREACHED();
277 return content::SECURITY_STYLE_UNKNOWN;
278 }
279
257 } // namespace 280 } // namespace
258 281
259 //////////////////////////////////////////////////////////////////////////////// 282 ////////////////////////////////////////////////////////////////////////////////
260 // Browser, CreateParams: 283 // Browser, CreateParams:
261 284
262 Browser::CreateParams::CreateParams(Profile* profile, 285 Browser::CreateParams::CreateParams(Profile* profile,
263 chrome::HostDesktopType host_desktop_type) 286 chrome::HostDesktopType host_desktop_type)
264 : type(TYPE_TABBED), 287 : type(TYPE_TABBED),
265 profile(profile), 288 profile(profile),
266 host_desktop_type(host_desktop_type), 289 host_desktop_type(host_desktop_type),
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 if ((operations_allowed & blink::WebDragOperationLink) && 1312 if ((operations_allowed & blink::WebDragOperationLink) &&
1290 chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(this)) { 1313 chrome::SettingsWindowManager::GetInstance()->IsSettingsBrowser(this)) {
1291 return false; 1314 return false;
1292 } 1315 }
1293 return true; 1316 return true;
1294 } 1317 }
1295 1318
1296 content::SecurityStyle Browser::GetSecurityStyle( 1319 content::SecurityStyle Browser::GetSecurityStyle(
1297 WebContents* web_contents, 1320 WebContents* web_contents,
1298 content::SecurityStyleExplanations* security_style_explanations) { 1321 content::SecurityStyleExplanations* security_style_explanations) {
1299 connection_security::SecurityInfo security_info; 1322 SecurityStateModel* model = SecurityStateModel::FromWebContents(web_contents);
1300 connection_security::GetSecurityInfoForWebContents(web_contents, 1323 DCHECK(model);
1301 &security_info); 1324 const SecurityStateModel::SecurityInfo& security_info =
1325 model->security_info();
1326
1327 const content::SecurityStyle security_style =
1328 SecurityLevelToSecurityStyle(security_info.security_level);
1302 1329
1303 security_style_explanations->ran_insecure_content_style = 1330 security_style_explanations->ran_insecure_content_style =
1304 connection_security::kRanInsecureContentStyle; 1331 SecurityStateModel::kRanInsecureContentStyle;
1305 security_style_explanations->displayed_insecure_content_style = 1332 security_style_explanations->displayed_insecure_content_style =
1306 connection_security::kDisplayedInsecureContentStyle; 1333 SecurityStateModel::kDisplayedInsecureContentStyle;
1307 1334
1308 // Check if the page is HTTP; if so, no explanations are needed. Note 1335 // Check if the page is HTTP; if so, no explanations are needed. Note
1309 // that SECURITY_STYLE_UNAUTHENTICATED does not necessarily mean that 1336 // that SECURITY_STYLE_UNAUTHENTICATED does not necessarily mean that
1310 // the page is loaded over HTTP, because the security style merely 1337 // the page is loaded over HTTP, because the security style merely
1311 // represents how the embedder wishes to display the security state of 1338 // represents how the embedder wishes to display the security state of
1312 // the page, and the embedder can choose to display HTTPS page as HTTP 1339 // the page, and the embedder can choose to display HTTPS page as HTTP
1313 // if it wants to (for example, displaying deprecated crypto 1340 // if it wants to (for example, displaying deprecated crypto
1314 // algorithms with the same UI treatment as HTTP pages). 1341 // algorithms with the same UI treatment as HTTP pages).
1315 security_style_explanations->scheme_is_cryptographic = 1342 security_style_explanations->scheme_is_cryptographic =
1316 security_info.scheme_is_cryptographic; 1343 security_info.scheme_is_cryptographic;
1317 if (!security_info.scheme_is_cryptographic || 1344 if (!security_info.scheme_is_cryptographic) {
1318 security_info.security_style == content::SECURITY_STYLE_UNKNOWN) { 1345 return security_style;
1319 return security_info.security_style;
1320 } 1346 }
1321 1347
1322 if (security_info.sha1_deprecation_status == 1348 if (security_info.sha1_deprecation_status ==
1323 connection_security::DEPRECATED_SHA1_BROKEN) { 1349 SecurityStateModel::DEPRECATED_SHA1_BROKEN) {
1324 security_style_explanations->broken_explanations.push_back( 1350 security_style_explanations->broken_explanations.push_back(
1325 content::SecurityStyleExplanation( 1351 content::SecurityStyleExplanation(
1326 l10n_util::GetStringUTF8(IDS_BROKEN_SHA1), 1352 l10n_util::GetStringUTF8(IDS_BROKEN_SHA1),
1327 l10n_util::GetStringUTF8(IDS_BROKEN_SHA1_DESCRIPTION), 1353 l10n_util::GetStringUTF8(IDS_BROKEN_SHA1_DESCRIPTION),
1328 security_info.cert_id)); 1354 security_info.cert_id));
1329 } else if (security_info.sha1_deprecation_status == 1355 } else if (security_info.sha1_deprecation_status ==
1330 connection_security::DEPRECATED_SHA1_WARNING) { 1356 SecurityStateModel::DEPRECATED_SHA1_WARNING) {
1331 security_style_explanations->warning_explanations.push_back( 1357 security_style_explanations->warning_explanations.push_back(
1332 content::SecurityStyleExplanation( 1358 content::SecurityStyleExplanation(
1333 l10n_util::GetStringUTF8(IDS_WARNING_SHA1), 1359 l10n_util::GetStringUTF8(IDS_WARNING_SHA1),
1334 l10n_util::GetStringUTF8(IDS_WARNING_SHA1_DESCRIPTION), 1360 l10n_util::GetStringUTF8(IDS_WARNING_SHA1_DESCRIPTION),
1335 security_info.cert_id)); 1361 security_info.cert_id));
1336 } 1362 }
1337 1363
1338 security_style_explanations->ran_insecure_content = 1364 security_style_explanations->ran_insecure_content =
1339 security_info.mixed_content_status == 1365 security_info.mixed_content_status ==
1340 connection_security::RAN_MIXED_CONTENT || 1366 SecurityStateModel::RAN_MIXED_CONTENT ||
1341 security_info.mixed_content_status == 1367 security_info.mixed_content_status ==
1342 connection_security::RAN_AND_DISPLAYED_MIXED_CONTENT; 1368 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT;
1343 security_style_explanations->displayed_insecure_content = 1369 security_style_explanations->displayed_insecure_content =
1344 security_info.mixed_content_status == 1370 security_info.mixed_content_status ==
1345 connection_security::DISPLAYED_MIXED_CONTENT || 1371 SecurityStateModel::DISPLAYED_MIXED_CONTENT ||
1346 security_info.mixed_content_status == 1372 security_info.mixed_content_status ==
1347 connection_security::RAN_AND_DISPLAYED_MIXED_CONTENT; 1373 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT;
1348 1374
1349 if (net::IsCertStatusError(security_info.cert_status)) { 1375 if (net::IsCertStatusError(security_info.cert_status)) {
1350 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString( 1376 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(
1351 net::MapCertStatusToNetError(security_info.cert_status))); 1377 net::MapCertStatusToNetError(security_info.cert_status)));
1352 1378
1353 content::SecurityStyleExplanation explanation( 1379 content::SecurityStyleExplanation explanation(
1354 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR), 1380 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR),
1355 l10n_util::GetStringFUTF8( 1381 l10n_util::GetStringFUTF8(
1356 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string), 1382 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string),
1357 security_info.cert_id); 1383 security_info.cert_id);
1358 1384
1359 if (net::IsCertStatusMinorError(security_info.cert_status)) 1385 if (net::IsCertStatusMinorError(security_info.cert_status))
1360 security_style_explanations->warning_explanations.push_back(explanation); 1386 security_style_explanations->warning_explanations.push_back(explanation);
1361 else 1387 else
1362 security_style_explanations->broken_explanations.push_back(explanation); 1388 security_style_explanations->broken_explanations.push_back(explanation);
1363 } else { 1389 } else {
1364 // If the certificate does not have errors and is not using 1390 // If the certificate does not have errors and is not using
1365 // deprecated SHA1, then add an explanation that the certificate is 1391 // deprecated SHA1, then add an explanation that the certificate is
1366 // valid. 1392 // valid.
1367 if (security_info.sha1_deprecation_status == 1393 if (security_info.sha1_deprecation_status ==
1368 connection_security::NO_DEPRECATED_SHA1) { 1394 SecurityStateModel::NO_DEPRECATED_SHA1) {
1369 security_style_explanations->secure_explanations.push_back( 1395 security_style_explanations->secure_explanations.push_back(
1370 content::SecurityStyleExplanation( 1396 content::SecurityStyleExplanation(
1371 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE), 1397 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE),
1372 l10n_util::GetStringUTF8( 1398 l10n_util::GetStringUTF8(
1373 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION), 1399 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION),
1374 security_info.cert_id)); 1400 security_info.cert_id));
1375 } 1401 }
1376 } 1402 }
1377 1403
1378 return security_info.security_style; 1404 return security_style;
1379 } 1405 }
1380 1406
1381 void Browser::ShowCertificateViewerInDevTools( 1407 void Browser::ShowCertificateViewerInDevTools(
1382 content::WebContents* web_contents, int cert_id) { 1408 content::WebContents* web_contents, int cert_id) {
1383 DevToolsWindow* devtools_window = 1409 DevToolsWindow* devtools_window =
1384 DevToolsWindow::GetInstanceForInspectedWebContents(web_contents); 1410 DevToolsWindow::GetInstanceForInspectedWebContents(web_contents);
1385 if (devtools_window) 1411 if (devtools_window)
1386 devtools_window->ShowCertificateViewer(cert_id); 1412 devtools_window->ShowCertificateViewer(cert_id);
1387 } 1413 }
1388 1414
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 // need to update the command state early on load to always present usable 1503 // need to update the command state early on load to always present usable
1478 // actions in the face of slow-to-commit pages. 1504 // actions in the face of slow-to-commit pages.
1479 if (changed_flags & (content::INVALIDATE_TYPE_URL | 1505 if (changed_flags & (content::INVALIDATE_TYPE_URL |
1480 content::INVALIDATE_TYPE_LOAD)) 1506 content::INVALIDATE_TYPE_LOAD))
1481 command_controller_->TabStateChanged(); 1507 command_controller_->TabStateChanged();
1482 1508
1483 if (hosted_app_controller_) 1509 if (hosted_app_controller_)
1484 hosted_app_controller_->UpdateLocationBarVisibility(true); 1510 hosted_app_controller_->UpdateLocationBarVisibility(true);
1485 } 1511 }
1486 1512
1487 void Browser::VisibleSSLStateChanged(const WebContents* source) { 1513 void Browser::VisibleSSLStateChanged(WebContents* source) {
1488 // When the current tab's SSL state changes, we need to update the URL 1514 // When the current tab's SSL state changes, we need to update the URL
1489 // bar to reflect the new state. 1515 // bar to reflect the new state.
1490 DCHECK(source); 1516 DCHECK(source);
1517
1518 // Notify the model that the security state has changed, so that the
1519 // URL bar updates with up-to-date data computed by the model.
1520 SecurityStateModel* model = SecurityStateModel::FromWebContents(source);
1521 DCHECK(model);
1522 model->SecurityStateChanged();
1523
1491 if (tab_strip_model_->GetActiveWebContents() == source) 1524 if (tab_strip_model_->GetActiveWebContents() == source)
1492 UpdateToolbar(false); 1525 UpdateToolbar(false);
1493 } 1526 }
1494 1527
1495 void Browser::AddNewContents(WebContents* source, 1528 void Browser::AddNewContents(WebContents* source,
1496 WebContents* new_contents, 1529 WebContents* new_contents,
1497 WindowOpenDisposition disposition, 1530 WindowOpenDisposition disposition,
1498 const gfx::Rect& initial_rect, 1531 const gfx::Rect& initial_rect,
1499 bool user_gesture, 1532 bool user_gesture,
1500 bool* was_blocked) { 1533 bool* was_blocked) {
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 if (contents && !allow_js_access) { 2691 if (contents && !allow_js_access) {
2659 contents->web_contents()->GetController().LoadURL( 2692 contents->web_contents()->GetController().LoadURL(
2660 target_url, 2693 target_url,
2661 content::Referrer(), 2694 content::Referrer(),
2662 ui::PAGE_TRANSITION_LINK, 2695 ui::PAGE_TRANSITION_LINK,
2663 std::string()); // No extra headers. 2696 std::string()); // No extra headers.
2664 } 2697 }
2665 2698
2666 return contents != NULL; 2699 return contents != NULL;
2667 } 2700 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698