Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / download / download_danger_prompt_views.cc
index 41bdea0..a5dc28f 100644 (file)
@@ -5,12 +5,13 @@
 #include "base/compiler_specific.h"
 #include "chrome/browser/download/download_danger_prompt.h"
 #include "chrome/browser/download/download_stats.h"
-#include "chrome/browser/ui/views/constrained_window_views.h"
+#include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/constrained_window/constrained_window_views.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/download_danger_type.h"
 #include "content/public/browser/download_item.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/resource/resource_bundle.h"
 #include "ui/views/controls/button/label_button.h"
@@ -21,6 +22,8 @@
 #include "ui/views/window/dialog_client_view.h"
 #include "ui/views/window/dialog_delegate.h"
 
+using extensions::ExperienceSamplingEvent;
+
 namespace {
 
 const int kMessageWidth = 320;
@@ -38,24 +41,23 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
                             const OnDone& done);
 
   // DownloadDangerPrompt methods:
-  virtual void InvokeActionForTesting(Action action) OVERRIDE;
+  void InvokeActionForTesting(Action action) override;
 
   // views::DialogDelegate methods:
-  virtual base::string16 GetDialogButtonLabel(
-      ui::DialogButton button) const OVERRIDE;
-  virtual base::string16 GetWindowTitle() const OVERRIDE;
-  virtual void DeleteDelegate() OVERRIDE;
-  virtual ui::ModalType GetModalType() const OVERRIDE;
-  virtual bool Cancel() OVERRIDE;
-  virtual bool Accept() OVERRIDE;
-  virtual bool Close() OVERRIDE;
-  virtual views::View* GetInitiallyFocusedView() OVERRIDE;
-  virtual views::View* GetContentsView() OVERRIDE;
-  virtual views::Widget* GetWidget() OVERRIDE;
-  virtual const views::Widget* GetWidget() const OVERRIDE;
+  base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
+  base::string16 GetWindowTitle() const override;
+  void DeleteDelegate() override;
+  ui::ModalType GetModalType() const override;
+  bool Cancel() override;
+  bool Accept() override;
+  bool Close() override;
+  views::View* GetInitiallyFocusedView() override;
+  views::View* GetContentsView() override;
+  views::Widget* GetWidget() override;
+  const views::Widget* GetWidget() const override;
 
   // content::DownloadItem::Observer:
-  virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
+  void OnDownloadUpdated(content::DownloadItem* download) override;
 
  private:
   base::string16 GetAcceptButtonTitle() const;
@@ -69,6 +71,8 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
   bool show_context_;
   OnDone done_;
 
+  scoped_ptr<ExperienceSamplingEvent> sampling_event_;
+
   views::View* contents_view_;
 };
 
@@ -117,6 +121,14 @@ DownloadDangerPromptViews::DownloadDangerPromptViews(
   layout->AddView(message_body_label);
 
   RecordOpenedDangerousConfirmDialog(download_->GetDangerType());
+
+  // ExperienceSampling: A malicious download warning is being shown to the
+  // user, so we start a new SamplingEvent and track it.
+  sampling_event_.reset(new ExperienceSamplingEvent(
+      ExperienceSamplingEvent::kDownloadDangerPrompt,
+      item->GetURL(),
+      item->GetReferrerUrl(),
+      item->GetBrowserContext()));
 }
 
 // DownloadDangerPrompt methods:
@@ -170,18 +182,24 @@ ui::ModalType DownloadDangerPromptViews::GetModalType() const {
 
 bool DownloadDangerPromptViews::Cancel() {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+  // ExperienceSampling: User canceled the warning.
+  sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
   RunDone(CANCEL);
   return true;
 }
 
 bool DownloadDangerPromptViews::Accept() {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+  // ExperienceSampling: User proceeded through the warning.
+  sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
   RunDone(ACCEPT);
   return true;
 }
 
 bool DownloadDangerPromptViews::Close() {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+  // ExperienceSampling: User canceled the warning.
+  sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
   RunDone(DISMISS);
   return true;
 }