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

Side by Side Diff: chrome/browser/ui/media_stream_infobar_delegate.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months 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
OLDNEW
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/ui/media_stream_infobar_delegate.h" 5 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/api/infobars/infobar_service.h" 9 #include "chrome/browser/api/infobars/infobar_service.h"
10 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
18 19
19 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( 20 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() {}
20 InfoBarService* infobar_service, 21
21 MediaStreamDevicesController* controller) 22 // static
22 : ConfirmInfoBarDelegate(infobar_service), 23 bool MediaStreamInfoBarDelegate::Create(
23 controller_(controller) { 24 content::WebContents* web_contents,
24 DCHECK(controller_.get()); 25 const content::MediaStreamRequest& request,
25 DCHECK(controller_->has_audio() || controller_->has_video()); 26 const content::MediaResponseCallback& callback) {
27 Profile* profile =
28 Profile::FromBrowserContext(web_contents->GetBrowserContext());
29
30 scoped_ptr<MediaStreamDevicesController> controller(
31 new MediaStreamDevicesController(profile, request, callback));
32 if (!controller->DismissInfoBarAndTakeActionOnSettings()) {
33 InfoBarService* infobar_service =
34 InfoBarService::FromWebContents(web_contents);
35 InfoBarDelegate* old_infobar = NULL;
36 for (size_t i = 0; i < infobar_service->GetInfoBarCount(); ++i) {
37 old_infobar = infobar_service->GetInfoBarDelegateAt(i)->
38 AsMediaStreamInfoBarDelegate();
39 if (old_infobar)
40 break;
41 }
42
43 scoped_ptr<InfoBarDelegate> infobar(
44 new MediaStreamInfoBarDelegate(infobar_service, controller.release()));
45 if (old_infobar)
46 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass());
47 else
48 infobar_service->AddInfoBar(infobar.Pass());
49 return true;
50 }
51 return false;
26 } 52 }
27 53
28 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() {}
29
30 void MediaStreamInfoBarDelegate::InfoBarDismissed() { 54 void MediaStreamInfoBarDelegate::InfoBarDismissed() {
31 // Deny the request if the infobar was closed with the 'x' button, since 55 // Deny the request if the infobar was closed with the 'x' button, since
32 // we don't want WebRTC to be waiting for an answer that will never come. 56 // we don't want WebRTC to be waiting for an answer that will never come.
33 controller_->Deny(false); 57 controller_->Deny(false);
34 } 58 }
35 59
36 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const { 60 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const {
37 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 61 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
38 controller_->has_video() ? 62 controller_->has_video() ?
39 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC); 63 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 google_util::AppendGoogleLocaleParam( 108 google_util::AppendGoogleLocaleParam(
85 GURL(chrome::kMediaAccessLearnMoreUrl)), 109 GURL(chrome::kMediaAccessLearnMoreUrl)),
86 content::Referrer(), 110 content::Referrer(),
87 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 111 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
88 content::PAGE_TRANSITION_LINK, 112 content::PAGE_TRANSITION_LINK,
89 false); 113 false);
90 owner()->GetWebContents()->OpenURL(params); 114 owner()->GetWebContents()->OpenURL(params);
91 115
92 return false; // Do not dismiss the info bar. 116 return false; // Do not dismiss the info bar.
93 } 117 }
118
119 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate(
120 InfoBarService* infobar_service,
121 MediaStreamDevicesController* controller)
122 : ConfirmInfoBarDelegate(infobar_service),
123 controller_(controller) {
124 DCHECK(controller_.get());
125 DCHECK(controller_->has_audio() || controller_->has_video());
126 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/media_stream_infobar_delegate.h ('k') | chrome/browser/ui/startup/autolaunch_prompt_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698