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

Side by Side Diff: chrome/browser/three_d_api_observer.cc

Issue 11378008: Raise an infobar and deny access to WebGL if a GPU reset was detected while a web page containing W… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Work around build failure on Mac OS with 10.6 SDK. Created 8 years, 1 month 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 | « chrome/browser/three_d_api_observer.h ('k') | chrome/browser/ui/tab_contents/tab_contents.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/three_d_api_observer.h"
6
7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
8 #include "chrome/browser/api/infobars/infobar_service.h"
9 #include "content/public/browser/gpu_data_manager.h"
10 #include "content/public/common/three_d_api_types.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ThreeDAPIObserver)
15
16 // ThreeDAPIInfoBarDelegate ---------------------------------------------
17
18 // TODO(kbr): write a "learn more" article about the issues associated
19 // with client 3D APIs and GPU resets, and override GetLinkText(), etc.
20
21 class ThreeDAPIInfoBarDelegate : public ConfirmInfoBarDelegate {
22 public:
23 ThreeDAPIInfoBarDelegate(
24 InfoBarService* owner,
25 const GURL& url,
26 content::ThreeDAPIType requester);
27
28 private:
29 virtual ~ThreeDAPIInfoBarDelegate();
30
31 // ConfirmInfoBarDelegate:
32 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE;
33 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate() OVERRIDE;
34 virtual string16 GetMessageText() const OVERRIDE;
35 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
36 virtual bool Accept() OVERRIDE;
37 virtual bool Cancel() OVERRIDE;
38
39 GURL url_;
40 content::ThreeDAPIType requester_;
41
42 DISALLOW_COPY_AND_ASSIGN(ThreeDAPIInfoBarDelegate);
43 };
44
45 ThreeDAPIInfoBarDelegate::ThreeDAPIInfoBarDelegate(
46 InfoBarService* owner,
47 const GURL& url,
48 content::ThreeDAPIType requester)
49 : ConfirmInfoBarDelegate(owner),
50 url_(url),
51 requester_(requester) {
52 }
53
54 ThreeDAPIInfoBarDelegate::~ThreeDAPIInfoBarDelegate() {
55 }
56
57 bool ThreeDAPIInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
58 ThreeDAPIInfoBarDelegate* three_d_delegate =
59 delegate->AsThreeDAPIInfoBarDelegate();
60 // For the time being, if a given web page is actually using both
61 // WebGL and Pepper 3D and both APIs are blocked, just leave the
62 // first infobar up. If the user selects "try again", both APIs will
63 // be unblocked and the web page reload will succeed.
64 return (three_d_delegate != NULL);
65 }
66
67 ThreeDAPIInfoBarDelegate*
68 ThreeDAPIInfoBarDelegate::AsThreeDAPIInfoBarDelegate() {
69 return this;
70 }
71
72 string16 ThreeDAPIInfoBarDelegate::GetMessageText() const {
73 string16 api_name;
74 switch (requester_) {
75 case content::THREE_D_API_TYPE_WEBGL:
76 api_name = l10n_util::GetStringUTF16(IDS_3D_APIS_WEBGL_NAME);
77 break;
78 case content::THREE_D_API_TYPE_PEPPER_3D:
79 api_name = l10n_util::GetStringUTF16(IDS_3D_APIS_PEPPER_3D_NAME);
80 break;
81 }
82
83 return l10n_util::GetStringFUTF16(IDS_3D_APIS_BLOCKED_TEXT,
84 api_name);
85 }
86
87 string16 ThreeDAPIInfoBarDelegate::GetButtonLabel(
88 InfoBarButton button) const {
89 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
90 IDS_3D_APIS_BLOCKED_OK_BUTTON_LABEL :
91 IDS_3D_APIS_BLOCKED_TRY_AGAIN_BUTTON_LABEL);
92 }
93
94 bool ThreeDAPIInfoBarDelegate::Accept() {
95 // TODO(kbr): add UMA stats.
96 return true;
97 }
98
99 bool ThreeDAPIInfoBarDelegate::Cancel() {
100 // TODO(kbr): add UMA stats.
101 content::GpuDataManager::GetInstance()->UnblockDomainFrom3DAPIs(url_);
102 owner()->GetWebContents()->GetController().Reload(true);
103 return true;
104 }
105
106
107 // ThreeDAPIObserver ----------------------------------------------------
108
109 ThreeDAPIObserver::ThreeDAPIObserver(content::WebContents* web_contents)
110 : WebContentsObserver(web_contents) {}
111
112 ThreeDAPIObserver::~ThreeDAPIObserver() {}
113
114 void ThreeDAPIObserver::DidBlock3DAPIs(const GURL& url,
115 content::ThreeDAPIType requester) {
116 InfoBarService* service = InfoBarService::FromWebContents(web_contents());
117 service->AddInfoBar(new ThreeDAPIInfoBarDelegate(service, url, requester));
118 }
OLDNEW
« no previous file with comments | « chrome/browser/three_d_api_observer.h ('k') | chrome/browser/ui/tab_contents/tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698