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

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

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 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
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/media/media_stream_infobar_delegate.h" 5 #include "chrome/browser/media/media_stream_infobar_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
11 #include "chrome/browser/infobars/infobar.h" 11 #include "chrome/browser/infobars/infobar.h"
12 #include "chrome/browser/infobars/infobar_manager.h"
12 #include "chrome/browser/infobars/infobar_service.h" 13 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 namespace { 21 namespace {
21 22
(...skipping 22 matching lines...) Expand all
44 45
45 InfoBarService* infobar_service = 46 InfoBarService* infobar_service =
46 InfoBarService::FromWebContents(web_contents); 47 InfoBarService::FromWebContents(web_contents);
47 if (!infobar_service) { 48 if (!infobar_service) {
48 // Deny the request if there is no place to show the infobar, e.g. when 49 // Deny the request if there is no place to show the infobar, e.g. when
49 // the request comes from a background extension page. 50 // the request comes from a background extension page.
50 controller->Deny(false, content::MEDIA_DEVICE_INVALID_STATE); 51 controller->Deny(false, content::MEDIA_DEVICE_INVALID_STATE);
51 return false; 52 return false;
52 } 53 }
53 54
54 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( 55 scoped_ptr<InfoBar> infobar(
55 scoped_ptr<ConfirmInfoBarDelegate>( 56 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
56 new MediaStreamInfoBarDelegate(controller.Pass())))); 57 new MediaStreamInfoBarDelegate(web_contents, controller.Pass()))));
57 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { 58 InfoBarManager& manager = infobar_service->infobar_manager();
58 InfoBar* old_infobar = infobar_service->infobar_at(i); 59 for (size_t i = 0; i < manager.infobar_count(); ++i) {
60 InfoBar* old_infobar = manager.infobar_at(i);
59 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegate()) { 61 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegate()) {
60 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); 62 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass());
61 return true; 63 return true;
62 } 64 }
63 } 65 }
64 infobar_service->AddInfoBar(infobar.Pass()); 66 infobar_service->AddInfoBar(infobar.Pass());
65 return true; 67 return true;
66 } 68 }
67 69
68 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( 70 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate(
71 content::WebContents* web_contents,
69 scoped_ptr<MediaStreamDevicesController> controller) 72 scoped_ptr<MediaStreamDevicesController> controller)
70 : ConfirmInfoBarDelegate(), 73 : ContentConfirmInfoBarDelegate(web_contents),
71 controller_(controller.Pass()) { 74 controller_(controller.Pass()) {
72 DCHECK(controller_.get()); 75 DCHECK(controller_.get());
73 DCHECK(controller_->HasAudio() || controller_->HasVideo()); 76 DCHECK(controller_->HasAudio() || controller_->HasVideo());
74 } 77 }
75 78
76 void MediaStreamInfoBarDelegate::InfoBarDismissed() { 79 void MediaStreamInfoBarDelegate::InfoBarDismissed() {
77 // Deny the request if the infobar was closed with the 'x' button, since 80 // Deny the request if the infobar was closed with the 'x' button, since
78 // we don't want WebRTC to be waiting for an answer that will never come. 81 // we don't want WebRTC to be waiting for an answer that will never come.
79 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", 82 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions",
80 kCancel, kPermissionActionsMax); 83 kCancel, kPermissionActionsMax);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 web_contents()->OpenURL(content::OpenURLParams( 143 web_contents()->OpenURL(content::OpenURLParams(
141 google_util::AppendGoogleLocaleParam( 144 google_util::AppendGoogleLocaleParam(
142 GURL(chrome::kMediaAccessLearnMoreUrl)), 145 GURL(chrome::kMediaAccessLearnMoreUrl)),
143 content::Referrer(), 146 content::Referrer(),
144 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 147 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
145 content::PAGE_TRANSITION_LINK, 148 content::PAGE_TRANSITION_LINK,
146 false)); 149 false));
147 150
148 return false; // Do not dismiss the info bar. 151 return false; // Do not dismiss the info bar.
149 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698