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

Side by Side Diff: chrome/browser/ui/views/toolbar/site_chip_view.cc

Issue 110893004: [SiteChip] Add UMA, finish wiring site chip experiment up to the omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/views/toolbar/toolbar_view.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/views/toolbar/site_chip_view.h" 5 #include "chrome/browser/ui/views/toolbar/site_chip_view.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/extension_icon_image.h" 13 #include "chrome/browser/extensions/extension_icon_image.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_system.h" 15 #include "chrome/browser/extensions/extension_system.h"
15 #include "chrome/browser/favicon/favicon_tab_helper.h" 16 #include "chrome/browser/favicon/favicon_tab_helper.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/safe_browsing/client_side_detection_host.h" 18 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
20 #include "chrome/browser/safe_browsing/ui_manager.h" 21 #include "chrome/browser/safe_browsing/ui_manager.h"
21 #include "chrome/browser/search/search.h" 22 #include "chrome/browser/search/search.h"
22 #include "chrome/browser/themes/theme_properties.h" 23 #include "chrome/browser/themes/theme_properties.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/omnibox/omnibox_view.h" 25 #include "chrome/browser/ui/omnibox/omnibox_view.h"
25 #include "chrome/browser/ui/toolbar/toolbar_model.h" 26 #include "chrome/browser/ui/toolbar/toolbar_model.h"
26 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 27 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
27 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 28 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
28 #include "chrome/common/extensions/extension_constants.h" 29 #include "chrome/common/extensions/extension_constants.h"
29 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" 30 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
33 #include "content/public/browser/user_metrics.h"
32 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
33 #include "content/public/common/url_constants.h" 35 #include "content/public/common/url_constants.h"
34 #include "extensions/common/constants.h" 36 #include "extensions/common/constants.h"
35 #include "grit/component_strings.h" 37 #include "grit/component_strings.h"
36 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
37 #include "grit/theme_resources.h" 39 #include "grit/theme_resources.h"
38 #include "net/base/net_util.h" 40 #include "net/base/net_util.h"
39 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h" 42 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/base/theme_provider.h" 43 #include "ui/base/theme_provider.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (icon_view_) 96 if (icon_view_)
95 icon_view_->SetImage(&icon_image_->image_skia()); 97 icon_view_->SetImage(&icon_image_->image_skia());
96 } 98 }
97 99
98 100
99 // SiteChipView --------------------------------------------------------------- 101 // SiteChipView ---------------------------------------------------------------
100 102
101 namespace { 103 namespace {
102 104
103 const int kEdgeThickness = 5; 105 const int kEdgeThickness = 5;
104 const int k16x16IconLeadingSpacing = 3; 106 const int k16x16IconLeadingSpacing = 1;
105 const int k16x16IconTrailingSpacing = 3; 107 const int k16x16IconTrailingSpacing = 2;
106 const int kIconTextSpacing = 3; 108 const int kIconTextSpacing = 3;
107 const int kTrailingLabelMargin = 0; 109 const int kTrailingLabelMargin = 0;
108 110
111 const SkColor kEVBackgroundColor = SkColorSetRGB(163, 226, 120);
112 const SkColor kMalwareBackgroundColor = SkColorSetRGB(145, 0, 0);
113 const SkColor kBrokenSSLBackgroundColor = SkColorSetRGB(253, 196, 36);
Peter Kasting 2013/12/18 00:33:35 Do we want these colors on every possible toolbar
Greg Billock 2013/12/18 16:43:07 That's a good question. The images have a bit of t
Peter Kasting 2013/12/18 21:30:59 I think rather than hardcode these values (which m
114
109 // Detect client-side or SB malware/phishing hits. 115 // Detect client-side or SB malware/phishing hits.
110 bool IsMalware(const GURL& url, content::WebContents* tab) { 116 bool IsMalware(const GURL& url, content::WebContents* tab) {
111 if (tab->GetURL() != url) 117 if (tab->GetURL() != url)
112 return false; 118 return false;
113 119
114 safe_browsing::SafeBrowsingTabObserver* sb_observer = 120 safe_browsing::SafeBrowsingTabObserver* sb_observer =
115 safe_browsing::SafeBrowsingTabObserver::FromWebContents(tab); 121 safe_browsing::SafeBrowsingTabObserver::FromWebContents(tab);
116 return sb_observer && sb_observer->detection_host() && 122 return sb_observer && sb_observer->detection_host() &&
117 sb_observer->detection_host()->DidPageReceiveSafeBrowsingMatch(); 123 sb_observer->detection_host()->DidPageReceiveSafeBrowsingMatch();
118 } 124 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 326
321 if ((url == url_displayed_) && 327 if ((url == url_displayed_) &&
322 (security_level == security_level_) && 328 (security_level == security_level_) &&
323 (url_malware == url_malware_)) 329 (url_malware == url_malware_))
324 return; 330 return;
325 331
326 url_displayed_ = url; 332 url_displayed_ = url;
327 url_malware_ = url_malware; 333 url_malware_ = url_malware;
328 security_level_ = security_level; 334 security_level_ = security_level;
329 335
330 if (url_malware_) 336 SkColor label_background =
337 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR);
338 if (url_malware_) {
331 painter_ = malware_background_painter_.get(); 339 painter_ = malware_background_painter_.get();
332 else if (security_level_ == ToolbarModel::SECURITY_ERROR) 340 label_background = kMalwareBackgroundColor;
341 } else if (security_level_ == ToolbarModel::SECURITY_ERROR) {
333 painter_ = broken_ssl_background_painter_.get(); 342 painter_ = broken_ssl_background_painter_.get();
334 else if (security_level_ == ToolbarModel::EV_SECURE) 343 label_background = kBrokenSSLBackgroundColor;
344 } else if (security_level_ == ToolbarModel::EV_SECURE) {
335 painter_ = ev_background_painter_.get(); 345 painter_ = ev_background_painter_.get();
336 else 346 label_background = kEVBackgroundColor;
347 } else {
337 painter_ = NULL; 348 painter_ = NULL;
349 }
338 350
339 string16 host = SiteLabelFromURL(url_displayed_); 351 string16 host = SiteLabelFromURL(url_displayed_);
340 if (security_level_ == ToolbarModel::EV_SECURE) { 352 if (security_level_ == ToolbarModel::EV_SECURE) {
341 host = l10n_util::GetStringFUTF16(IDS_SITE_CHIP_EV_SSL_LABEL, 353 host = l10n_util::GetStringFUTF16(IDS_SITE_CHIP_EV_SSL_LABEL,
342 toolbar_view_->GetToolbarModel()->GetEVCertName(), 354 toolbar_view_->GetToolbarModel()->GetEVCertName(),
343 host); 355 host);
344 } 356 }
345 357
346 host_label_->SetText(host); 358 host_label_->SetText(host);
347 host_label_->SetTooltipText(host); 359 host_label_->SetTooltipText(host);
348 // TODO(gbillock): Instead of this, just set 360 host_label_->SetBackgroundColor(label_background);
Peter Kasting 2013/12/18 00:33:35 Hmm, maybe we should be using GetReadableColor() s
Greg Billock 2013/12/18 16:43:07 Michael helped me work this out -- that's what Lab
349 // host_label_->SetBackgroundColor() to either the COLOR_TOOLBAR or
350 // the painter background color if we're using a background painter.
351 SkColor toolbar_background =
352 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR);
353 host_label_->SetEnabledColor(
354 color_utils::GetReadableColor(SK_ColorBLACK, toolbar_background));
355 361
356 int icon = toolbar_view_->GetToolbarModel()->GetIconForSecurityLevel( 362 int icon = toolbar_view_->GetToolbarModel()->GetIconForSecurityLevel(
357 security_level_); 363 security_level_);
358 showing_16x16_icon_ = false; 364 showing_16x16_icon_ = false;
359 365
360 if (url_displayed_.is_empty() || 366 if (url_displayed_.is_empty() ||
361 url_displayed_.SchemeIs(chrome::kChromeUIScheme) || 367 url_displayed_.SchemeIs(chrome::kChromeUIScheme) ||
362 url_displayed_.SchemeIs(chrome::kAboutScheme)) { 368 url_displayed_.SchemeIs(chrome::kAboutScheme)) {
363 icon = IDR_PRODUCT_LOGO_16; 369 icon = IDR_PRODUCT_LOGO_16;
364 showing_16x16_icon_ = true; 370 showing_16x16_icon_ = true;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 if (painter_) 439 if (painter_)
434 views::Painter::PaintPainterAt(canvas, painter_, rect); 440 views::Painter::PaintPainterAt(canvas, painter_, rect);
435 441
436 ToolbarButton::OnPaint(canvas); 442 ToolbarButton::OnPaint(canvas);
437 } 443 }
438 444
439 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for 445 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for
440 // this button. 446 // this button.
441 void SiteChipView::ButtonPressed(views::Button* sender, 447 void SiteChipView::ButtonPressed(views::Button* sender,
442 const ui::Event& event) { 448 const ui::Event& event) {
449 UMA_HISTOGRAM_COUNTS("SiteChip.Pressed", 1);
450 content::RecordAction(content::UserMetricsAction("SiteChipPress"));
451
443 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus(); 452 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus();
444 toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true);
445 toolbar_view_->location_bar()->GetOmniboxView()->model()-> 453 toolbar_view_->location_bar()->GetOmniboxView()->model()->
446 SetCaretVisibility(true); 454 SetCaretVisibility(true);
455 toolbar_view_->location_bar()->GetOmniboxView()->ShowURL();
447 } 456 }
448 457
449 void SiteChipView::WriteDragDataForView(View* sender, 458 void SiteChipView::WriteDragDataForView(View* sender,
450 const gfx::Point& press_pt, 459 const gfx::Point& press_pt,
451 OSExchangeData* data) { 460 OSExchangeData* data) {
452 // TODO(gbillock): Consolidate this with the identical logic in 461 // TODO(gbillock): Consolidate this with the identical logic in
453 // LocationBarView. 462 // LocationBarView.
454 content::WebContents* web_contents = toolbar_view_->GetWebContents(); 463 content::WebContents* web_contents = toolbar_view_->GetWebContents();
455 FaviconTabHelper* favicon_tab_helper = 464 FaviconTabHelper* favicon_tab_helper =
456 FaviconTabHelper::FromWebContents(web_contents); 465 FaviconTabHelper::FromWebContents(web_contents);
(...skipping 19 matching lines...) Expand all
476 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will 485 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will
477 // have already been called. 486 // have already been called.
478 void SiteChipView::OnSafeBrowsingHit( 487 void SiteChipView::OnSafeBrowsingHit(
479 const SafeBrowsingUIManager::UnsafeResource& resource) {} 488 const SafeBrowsingUIManager::UnsafeResource& resource) {}
480 489
481 void SiteChipView::OnSafeBrowsingMatch( 490 void SiteChipView::OnSafeBrowsingMatch(
482 const SafeBrowsingUIManager::UnsafeResource& resource) { 491 const SafeBrowsingUIManager::UnsafeResource& resource) {
483 OnChanged(); 492 OnChanged();
484 } 493 }
485 494
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/toolbar/toolbar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698