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