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

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: pkasting comments 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
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 } else if (security_info.sha1_deprecation_status == 1354 } else if (security_info.sha1_deprecation_status ==
1329 connection_security::DEPRECATED_SHA1_WARNING) { 1355 SecurityStateModel::DEPRECATED_SHA1_WARNING) {
1330 security_style_explanations->warning_explanations.push_back( 1356 security_style_explanations->warning_explanations.push_back(
1331 content::SecurityStyleExplanation( 1357 content::SecurityStyleExplanation(
1332 l10n_util::GetStringUTF8(IDS_WARNING_SHA1), 1358 l10n_util::GetStringUTF8(IDS_WARNING_SHA1),
1333 l10n_util::GetStringUTF8(IDS_WARNING_SHA1_DESCRIPTION))); 1359 l10n_util::GetStringUTF8(IDS_WARNING_SHA1_DESCRIPTION)));
1334 } 1360 }
1335 1361
1336 security_style_explanations->ran_insecure_content = 1362 security_style_explanations->ran_insecure_content =
1337 security_info.mixed_content_status == 1363 security_info.mixed_content_status ==
1338 connection_security::RAN_MIXED_CONTENT || 1364 SecurityStateModel::RAN_MIXED_CONTENT ||
1339 security_info.mixed_content_status == 1365 security_info.mixed_content_status ==
1340 connection_security::RAN_AND_DISPLAYED_MIXED_CONTENT; 1366 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT;
1341 security_style_explanations->displayed_insecure_content = 1367 security_style_explanations->displayed_insecure_content =
1342 security_info.mixed_content_status == 1368 security_info.mixed_content_status ==
1343 connection_security::DISPLAYED_MIXED_CONTENT || 1369 SecurityStateModel::DISPLAYED_MIXED_CONTENT ||
1344 security_info.mixed_content_status == 1370 security_info.mixed_content_status ==
1345 connection_security::RAN_AND_DISPLAYED_MIXED_CONTENT; 1371 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT;
1346 1372
1347 if (net::IsCertStatusError(security_info.cert_status)) { 1373 if (net::IsCertStatusError(security_info.cert_status)) {
1348 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString( 1374 base::string16 error_string = base::UTF8ToUTF16(net::ErrorToString(
1349 net::MapCertStatusToNetError(security_info.cert_status))); 1375 net::MapCertStatusToNetError(security_info.cert_status)));
1350 1376
1351 content::SecurityStyleExplanation explanation( 1377 content::SecurityStyleExplanation explanation(
1352 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR), 1378 l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR),
1353 l10n_util::GetStringFUTF8( 1379 l10n_util::GetStringFUTF8(
1354 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string)); 1380 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string));
1355 1381
1356 if (net::IsCertStatusMinorError(security_info.cert_status)) 1382 if (net::IsCertStatusMinorError(security_info.cert_status))
1357 security_style_explanations->warning_explanations.push_back(explanation); 1383 security_style_explanations->warning_explanations.push_back(explanation);
1358 else 1384 else
1359 security_style_explanations->broken_explanations.push_back(explanation); 1385 security_style_explanations->broken_explanations.push_back(explanation);
1360 } else { 1386 } else {
1361 // If the certificate does not have errors and is not using 1387 // If the certificate does not have errors and is not using
1362 // deprecated SHA1, then add an explanation that the certificate is 1388 // deprecated SHA1, then add an explanation that the certificate is
1363 // valid. 1389 // valid.
1364 if (security_info.sha1_deprecation_status == 1390 if (security_info.sha1_deprecation_status ==
1365 connection_security::NO_DEPRECATED_SHA1) { 1391 SecurityStateModel::NO_DEPRECATED_SHA1) {
1366 security_style_explanations->secure_explanations.push_back( 1392 security_style_explanations->secure_explanations.push_back(
1367 content::SecurityStyleExplanation( 1393 content::SecurityStyleExplanation(
1368 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE), 1394 l10n_util::GetStringUTF8(IDS_VALID_SERVER_CERTIFICATE),
1369 l10n_util::GetStringUTF8( 1395 l10n_util::GetStringUTF8(
1370 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION))); 1396 IDS_VALID_SERVER_CERTIFICATE_DESCRIPTION)));
1371 } 1397 }
1372 } 1398 }
1373 1399
1374 return security_info.security_style; 1400 return security_style;
1375 } 1401 }
1376 1402
1377 bool Browser::IsMouseLocked() const { 1403 bool Browser::IsMouseLocked() const {
1378 return exclusive_access_manager_->mouse_lock_controller()->IsMouseLocked(); 1404 return exclusive_access_manager_->mouse_lock_controller()->IsMouseLocked();
1379 } 1405 }
1380 1406
1381 void Browser::OnWindowDidShow() { 1407 void Browser::OnWindowDidShow() {
1382 if (window_has_shown_) 1408 if (window_has_shown_)
1383 return; 1409 return;
1384 window_has_shown_ = true; 1410 window_has_shown_ = true;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 // need to update the command state early on load to always present usable 1491 // need to update the command state early on load to always present usable
1466 // actions in the face of slow-to-commit pages. 1492 // actions in the face of slow-to-commit pages.
1467 if (changed_flags & (content::INVALIDATE_TYPE_URL | 1493 if (changed_flags & (content::INVALIDATE_TYPE_URL |
1468 content::INVALIDATE_TYPE_LOAD)) 1494 content::INVALIDATE_TYPE_LOAD))
1469 command_controller_->TabStateChanged(); 1495 command_controller_->TabStateChanged();
1470 1496
1471 if (hosted_app_controller_) 1497 if (hosted_app_controller_)
1472 hosted_app_controller_->UpdateLocationBarVisibility(true); 1498 hosted_app_controller_->UpdateLocationBarVisibility(true);
1473 } 1499 }
1474 1500
1475 void Browser::VisibleSSLStateChanged(const WebContents* source) { 1501 void Browser::VisibleSSLStateChanged(WebContents* source) {
1476 // When the current tab's SSL state changes, we need to update the URL 1502 // When the current tab's SSL state changes, we need to update the URL
1477 // bar to reflect the new state. 1503 // bar to reflect the new state.
1478 DCHECK(source); 1504 DCHECK(source);
1505
1506 // Notify the model that the security state has changed, so that the
1507 // URL bar updates with up-to-date data computed by the model.
1508 SecurityStateModel::CreateForWebContents(source);
Avi (use Gerrit) 2015/09/03 22:57:36 Why are you creating it here? We probably want one
estark 2015/09/03 23:16:40 Done.
1509 SecurityStateModel* model = SecurityStateModel::FromWebContents(source);
1510 DCHECK(model);
1511 model->SecurityStateChanged();
1512
1479 if (tab_strip_model_->GetActiveWebContents() == source) 1513 if (tab_strip_model_->GetActiveWebContents() == source)
1480 UpdateToolbar(false); 1514 UpdateToolbar(false);
1481 } 1515 }
1482 1516
1483 void Browser::AddNewContents(WebContents* source, 1517 void Browser::AddNewContents(WebContents* source,
1484 WebContents* new_contents, 1518 WebContents* new_contents,
1485 WindowOpenDisposition disposition, 1519 WindowOpenDisposition disposition,
1486 const gfx::Rect& initial_rect, 1520 const gfx::Rect& initial_rect,
1487 bool user_gesture, 1521 bool user_gesture,
1488 bool* was_blocked) { 1522 bool* was_blocked) {
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 if (contents && !allow_js_access) { 2680 if (contents && !allow_js_access) {
2647 contents->web_contents()->GetController().LoadURL( 2681 contents->web_contents()->GetController().LoadURL(
2648 target_url, 2682 target_url,
2649 content::Referrer(), 2683 content::Referrer(),
2650 ui::PAGE_TRANSITION_LINK, 2684 ui::PAGE_TRANSITION_LINK,
2651 std::string()); // No extra headers. 2685 std::string()); // No extra headers.
2652 } 2686 }
2653 2687
2654 return contents != NULL; 2688 return contents != NULL;
2655 } 2689 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698