OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/three_d_api_observer.h" | 5 #include "chrome/browser/three_d_api_observer.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 9 #include "chrome/browser/infobars/infobar.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "chrome/browser/tab_contents/tab_util.h" | 11 #include "chrome/browser/tab_contents/tab_util.h" |
11 #include "content/public/browser/gpu_data_manager.h" | 12 #include "content/public/browser/gpu_data_manager.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
14 | 15 |
15 | 16 |
16 // ThreeDAPIInfoBarDelegate --------------------------------------------------- | 17 // ThreeDAPIInfoBarDelegate --------------------------------------------------- |
17 | 18 |
18 class ThreeDAPIInfoBarDelegate : public ConfirmInfoBarDelegate { | 19 class ThreeDAPIInfoBarDelegate : public ConfirmInfoBarDelegate { |
19 public: | 20 public: |
20 // Creates a 3D API infobar delegate and adds it to |infobar_service|. | 21 // Creates a 3D API infobar and delegate and adds the infobar to |
| 22 // |infobar_service|. |
21 static void Create(InfoBarService* infobar_service, | 23 static void Create(InfoBarService* infobar_service, |
22 const GURL& url, | 24 const GURL& url, |
23 content::ThreeDAPIType requester); | 25 content::ThreeDAPIType requester); |
24 | 26 |
25 private: | 27 private: |
26 enum DismissalHistogram { | 28 enum DismissalHistogram { |
27 IGNORED, | 29 IGNORED, |
28 RELOADED, | 30 RELOADED, |
29 CLOSED_WITHOUT_ACTION, | 31 CLOSED_WITHOUT_ACTION, |
30 DISMISSAL_MAX | 32 DISMISSAL_MAX |
31 }; | 33 }; |
32 | 34 |
33 ThreeDAPIInfoBarDelegate(InfoBarService* owner, | 35 ThreeDAPIInfoBarDelegate(const GURL& url, content::ThreeDAPIType requester); |
34 const GURL& url, | |
35 content::ThreeDAPIType requester); | |
36 virtual ~ThreeDAPIInfoBarDelegate(); | 36 virtual ~ThreeDAPIInfoBarDelegate(); |
37 | 37 |
38 // ConfirmInfoBarDelegate: | 38 // ConfirmInfoBarDelegate: |
39 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; | 39 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; |
40 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate() OVERRIDE; | 40 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate() OVERRIDE; |
41 virtual string16 GetMessageText() const OVERRIDE; | 41 virtual string16 GetMessageText() const OVERRIDE; |
42 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 42 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
43 virtual bool Accept() OVERRIDE; | 43 virtual bool Accept() OVERRIDE; |
44 virtual bool Cancel() OVERRIDE; | 44 virtual bool Cancel() OVERRIDE; |
45 virtual string16 GetLinkText() const OVERRIDE; | 45 virtual string16 GetLinkText() const OVERRIDE; |
46 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | 46 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
47 | 47 |
48 GURL url_; | 48 GURL url_; |
49 content::ThreeDAPIType requester_; | 49 content::ThreeDAPIType requester_; |
50 // Basically indicates whether the infobar was displayed at all, or | 50 // Basically indicates whether the infobar was displayed at all, or |
51 // was a temporary instance thrown away by the InfobarService. | 51 // was a temporary instance thrown away by the InfobarService. |
52 mutable bool message_text_queried_; | 52 mutable bool message_text_queried_; |
53 bool action_taken_; | 53 bool action_taken_; |
54 | 54 |
55 DISALLOW_COPY_AND_ASSIGN(ThreeDAPIInfoBarDelegate); | 55 DISALLOW_COPY_AND_ASSIGN(ThreeDAPIInfoBarDelegate); |
56 }; | 56 }; |
57 | 57 |
58 // static | 58 // static |
59 void ThreeDAPIInfoBarDelegate::Create(InfoBarService* infobar_service, | 59 void ThreeDAPIInfoBarDelegate::Create(InfoBarService* infobar_service, |
60 const GURL& url, | 60 const GURL& url, |
61 content::ThreeDAPIType requester) { | 61 content::ThreeDAPIType requester) { |
62 if (!infobar_service) | 62 if (!infobar_service) |
63 return; // NULL for apps. | 63 return; // NULL for apps. |
64 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 64 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
65 new ThreeDAPIInfoBarDelegate(infobar_service, url, requester))); | 65 scoped_ptr<ConfirmInfoBarDelegate>( |
| 66 new ThreeDAPIInfoBarDelegate(url, requester)))); |
66 } | 67 } |
67 | 68 |
68 ThreeDAPIInfoBarDelegate::ThreeDAPIInfoBarDelegate( | 69 ThreeDAPIInfoBarDelegate::ThreeDAPIInfoBarDelegate( |
69 InfoBarService* owner, | |
70 const GURL& url, | 70 const GURL& url, |
71 content::ThreeDAPIType requester) | 71 content::ThreeDAPIType requester) |
72 : ConfirmInfoBarDelegate(owner), | 72 : ConfirmInfoBarDelegate(), |
73 url_(url), | 73 url_(url), |
74 requester_(requester), | 74 requester_(requester), |
75 message_text_queried_(false), | 75 message_text_queried_(false), |
76 action_taken_(false) { | 76 action_taken_(false) { |
77 } | 77 } |
78 | 78 |
79 ThreeDAPIInfoBarDelegate::~ThreeDAPIInfoBarDelegate() { | 79 ThreeDAPIInfoBarDelegate::~ThreeDAPIInfoBarDelegate() { |
80 if (message_text_queried_ && !action_taken_) { | 80 if (message_text_queried_ && !action_taken_) { |
81 UMA_HISTOGRAM_ENUMERATION("GPU.ThreeDAPIInfoBarDismissal", | 81 UMA_HISTOGRAM_ENUMERATION("GPU.ThreeDAPIInfoBarDismissal", |
82 CLOSED_WITHOUT_ACTION, DISMISSAL_MAX); | 82 CLOSED_WITHOUT_ACTION, DISMISSAL_MAX); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 void ThreeDAPIObserver::DidBlock3DAPIs(const GURL& url, | 164 void ThreeDAPIObserver::DidBlock3DAPIs(const GURL& url, |
165 int render_process_id, | 165 int render_process_id, |
166 int render_view_id, | 166 int render_view_id, |
167 content::ThreeDAPIType requester) { | 167 content::ThreeDAPIType requester) { |
168 content::WebContents* web_contents = tab_util::GetWebContentsByID( | 168 content::WebContents* web_contents = tab_util::GetWebContentsByID( |
169 render_process_id, render_view_id); | 169 render_process_id, render_view_id); |
170 ThreeDAPIInfoBarDelegate::Create( | 170 ThreeDAPIInfoBarDelegate::Create( |
171 InfoBarService::FromWebContents(web_contents), url, requester); | 171 InfoBarService::FromWebContents(web_contents), url, requester); |
172 } | 172 } |
OLD | NEW |