Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/infobars/infobar_tab_helper.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 // ---------------------------------------------------------------------- | |
| 17 // ThreeDAPIInfoBarDelegate | |
|
Peter Kasting
2012/11/15 21:59:59
Tiny nit: This is somewhat unusual for a divider s
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
OK, changed.
| |
| 18 | |
| 19 // TODO(kbr): write a "learn more" article about the issues associated | |
| 20 // with client 3D APIs and GPU resets. | |
|
Peter Kasting
2012/11/15 21:59:59
Does this comment really belong here in the infoba
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
I really want it tied closely to the code, and hav
Peter Kasting
2012/11/15 23:41:24
Ah. It makes more sense now, thanks.
| |
| 21 | |
| 22 class ThreeDAPIInfoBarDelegate : public ConfirmInfoBarDelegate { | |
| 23 public: | |
| 24 static void Show( | |
|
Peter Kasting
2012/11/15 21:59:59
This method doesn't seem to be defined or used.
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Oops. Thanks for catching this. Removed.
| |
| 25 content::WebContents* web_contents, | |
| 26 const GURL& url); | |
| 27 | |
| 28 ThreeDAPIInfoBarDelegate( | |
| 29 InfoBarTabHelper* helper, | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: Please take an InfoBarService* instead of an
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 30 const GURL& url, | |
| 31 content::ThreeDAPIType requester); | |
| 32 virtual ~ThreeDAPIInfoBarDelegate(); | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: Please make everything but the constructor pr
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 33 | |
| 34 // InfoBarDelegate: | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: You don't directly inherit from InfoBarDelega
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 35 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; | |
| 36 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate() OVERRIDE; | |
| 37 | |
| 38 // ConfirmInfoBarDelegate: | |
| 39 virtual string16 GetMessageText() const OVERRIDE; | |
| 40 virtual int GetButtons() const OVERRIDE; | |
| 41 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
| 42 virtual bool Accept() OVERRIDE; | |
| 43 virtual bool Cancel() OVERRIDE; | |
| 44 virtual string16 GetLinkText() const OVERRIDE; | |
| 45 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | |
| 46 virtual gfx::Image* GetIcon() const OVERRIDE; | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: This should be placed between EqualsDelegate(
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 47 | |
| 48 private: | |
| 49 GURL url_; | |
| 50 content::ThreeDAPIType requester_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(ThreeDAPIInfoBarDelegate); | |
| 53 }; | |
| 54 | |
| 55 ThreeDAPIInfoBarDelegate::ThreeDAPIInfoBarDelegate( | |
| 56 InfoBarTabHelper* helper, | |
| 57 const GURL& url, | |
| 58 content::ThreeDAPIType requester) | |
| 59 : ConfirmInfoBarDelegate(helper), | |
| 60 url_(url), | |
| 61 requester_(requester) { | |
| 62 } | |
| 63 | |
| 64 ThreeDAPIInfoBarDelegate::~ThreeDAPIInfoBarDelegate() { | |
| 65 } | |
| 66 | |
| 67 bool ThreeDAPIInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { | |
| 68 ThreeDAPIInfoBarDelegate* three_d_delegate = | |
| 69 delegate->AsThreeDAPIInfoBarDelegate(); | |
| 70 // For the time being, if a given web page is actually using both | |
| 71 // WebGL and Pepper 3D and both APIs are blocked, just leave the | |
| 72 // first infobar up. If the user selects "try again", both APIs will | |
| 73 // be unblocked and the web page reload will succeed. | |
| 74 return (three_d_delegate != NULL); | |
| 75 } | |
| 76 | |
| 77 ThreeDAPIInfoBarDelegate* | |
| 78 ThreeDAPIInfoBarDelegate::AsThreeDAPIInfoBarDelegate() { | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: Indent 4
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
The C++ style guide doesn't require this here; fur
| |
| 79 return this; | |
| 80 } | |
| 81 | |
| 82 string16 ThreeDAPIInfoBarDelegate::GetMessageText() const { | |
| 83 string16 api_name; | |
| 84 switch (requester_) { | |
| 85 case content::THREE_D_API_TYPE_WEBGL: | |
| 86 api_name = l10n_util::GetStringUTF16(IDS_3D_APIS_WEBGL_NAME); | |
| 87 break; | |
| 88 case content::THREE_D_API_TYPE_PEPPER_3D: | |
| 89 api_name = l10n_util::GetStringUTF16(IDS_3D_APIS_PEPPER_3D_NAME); | |
| 90 break; | |
| 91 } | |
| 92 | |
| 93 return l10n_util::GetStringFUTF16(IDS_3D_APIS_BLOCKED_TEXT, | |
| 94 api_name); | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: Shorter and simpler:
return l10n_util::Get
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
It's desired for the build to break here if anothe
Peter Kasting
2012/11/15 23:41:24
Is the build guaranteed to break on all our target
Ken Russell (switch to Gerrit)
2012/11/16 02:26:59
It definitely breaks with clang, so there is no wa
| |
| 95 } | |
| 96 | |
| 97 int ThreeDAPIInfoBarDelegate::GetButtons() const { | |
| 98 return BUTTON_OK | BUTTON_CANCEL; | |
|
Peter Kasting
2012/11/15 21:59:59
This is the default behavior, don't override this
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Oops, thanks. Done.
| |
| 99 } | |
| 100 | |
| 101 string16 ThreeDAPIInfoBarDelegate::GetButtonLabel( | |
| 102 InfoBarButton button) const { | |
| 103 switch (button) { | |
| 104 case BUTTON_OK: | |
| 105 return l10n_util::GetStringUTF16(IDS_3D_APIS_BLOCKED_OK_BUTTON_LABEL); | |
| 106 case BUTTON_CANCEL: | |
| 107 return l10n_util::GetStringUTF16( | |
| 108 IDS_3D_APIS_BLOCKED_TRY_AGAIN_BUTTON_LABEL); | |
| 109 default: | |
| 110 NOTREACHED(); | |
| 111 return string16(); | |
| 112 } | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: Our infobar code explicitly assumes that BUTT
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 113 } | |
| 114 | |
| 115 bool ThreeDAPIInfoBarDelegate::Accept() { | |
| 116 // TODO(kbr): add UMA stats. | |
| 117 return true; | |
| 118 } | |
| 119 | |
| 120 bool ThreeDAPIInfoBarDelegate::Cancel() { | |
| 121 // TODO(kbr): add UMA stats. | |
| 122 content::GpuDataManager::GetInstance()->UnblockDomainFrom3DAPIs(url_); | |
| 123 owner()->GetWebContents()->GetController().Reload(true); | |
| 124 return true; | |
| 125 } | |
| 126 | |
| 127 string16 ThreeDAPIInfoBarDelegate::GetLinkText() const { | |
| 128 return string16(); | |
|
Peter Kasting
2012/11/15 21:59:59
This is the default behavior, don't override this
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 129 } | |
| 130 | |
| 131 bool ThreeDAPIInfoBarDelegate::LinkClicked( | |
| 132 WindowOpenDisposition disposition) { | |
| 133 return false; | |
|
Peter Kasting
2012/11/15 21:59:59
You have no link, don't override this function.
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 134 } | |
| 135 | |
| 136 gfx::Image* ThreeDAPIInfoBarDelegate::GetIcon() const { | |
| 137 return NULL; | |
|
Peter Kasting
2012/11/15 21:59:59
This is the default behavior, don't override this
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done.
| |
| 138 } | |
| 139 | |
| 140 | |
| 141 // ---------------------------------------------------------------------- | |
| 142 // ThreeDAPIObserver | |
| 143 | |
| 144 ThreeDAPIObserver::ThreeDAPIObserver(content::WebContents* web_contents) | |
| 145 : WebContentsObserver(web_contents) {} | |
| 146 | |
| 147 ThreeDAPIObserver::~ThreeDAPIObserver() {} | |
| 148 | |
| 149 void ThreeDAPIObserver::DidBlock3DAPIs(const GURL& url, | |
| 150 content::ThreeDAPIType requester) { | |
| 151 InfoBarTabHelper* infobar_helper = | |
| 152 InfoBarTabHelper::FromWebContents(web_contents()); | |
|
Peter Kasting
2012/11/15 21:59:59
Nit: Use InfoBarService* infobar_service = ... her
Ken Russell (switch to Gerrit)
2012/11/15 22:59:23
Done, thanks. Also updated the #include above.
| |
| 153 infobar_helper->AddInfoBar( | |
| 154 new ThreeDAPIInfoBarDelegate(infobar_helper, url, requester)); | |
| 155 } | |
| OLD | NEW |