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

Side by Side Diff: chrome/browser/wake_lock/wake_lock_infobar_delegate.cc

Issue 406483004: Initial implementation of API WakeLock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
(Empty)
1 // Copyright (c) 2014 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/wake_lock/wake_lock_infobar_delegate.h"
6
7 #include "chrome/browser/infobars/infobar_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/tab_contents/tab_util.h"
10 #include "chrome/browser/wake_lock/wake_lock_preference.h"
11 #include "components/infobars/core/infobar.h"
12 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
15
16 // static
17 infobars::InfoBar* WakeLockInfoBarDelegate::Create(
18 InfoBarService* infobar_service,
19 int render_process_id,
20 int routed_id,
21 WakeLockCallback callback) {
22 std::string url = infobar_service->web_contents()->GetURL().spec();
23
24 WakeLockInfoBarDelegate* const delegate =
25 new WakeLockInfoBarDelegate(render_process_id,
26 routed_id,
27 url,
28 callback);
29
30 infobars::InfoBar* infobar = ConfirmInfoBarDelegate::CreateInfoBar(
31 scoped_ptr<ConfirmInfoBarDelegate>(delegate)).release();
32 return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar));
33 }
34
35 WakeLockInfoBarDelegate::WakeLockInfoBarDelegate(
36 int render_process_id,
37 int routed_id,
38 const std::string& url,
39 WakeLockCallback callback)
40 : ConfirmInfoBarDelegate(),
41 user_has_interacted_(false),
42 render_process_id_(render_process_id),
43 routed_id_(routed_id),
44 url_(url),
45 callback_(callback) {
46 }
47
48 WakeLockInfoBarDelegate::~WakeLockInfoBarDelegate() {
49 if (!user_has_interacted_)
50 SetPermission(false, false);
51 }
52
53 bool WakeLockInfoBarDelegate::Accept() {
54 set_user_has_interacted();
55 SetPermission(true, true);
56 return true;
57 }
58
59 bool WakeLockInfoBarDelegate::Cancel() {
60 set_user_has_interacted();
61 SetPermission(true, false);
62 return true;
63 }
64
65 void WakeLockInfoBarDelegate::InfoBarDismissed() {
66 set_user_has_interacted();
67 SetPermission(false, false);
68 }
69
70 int WakeLockInfoBarDelegate::GetIconID() const {
71 return IDR_INFOBAR_GEOLOCATION;
72 }
73
74 infobars::InfoBarDelegate::Type WakeLockInfoBarDelegate::GetInfoBarType()
75 const {
76 return PAGE_ACTION_TYPE;
77 }
78
79 base::string16 WakeLockInfoBarDelegate::GetButtonLabel(
80 InfoBarButton button) const {
81 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
82 IDS_WAKE_LOCK_OK_BUTTON : IDS_WAKE_LOCK_CANCEL_BUTTON);
83 }
84
85 base::string16 WakeLockInfoBarDelegate::GetMessageText() const {
86 return l10n_util::GetStringUTF16(IDS_WAKE_LOCK_INFOBAR_QUESTION);
87 }
88
89 void WakeLockInfoBarDelegate::SetPermission(bool update_content_setting,
90 bool allowed) {
91 if (update_content_setting /*&& remember_value()*/) {
92 scoped_ptr<WakeLockPreference> pref =
93 WakeLockPreference::createWakeLockPreference(
94 render_process_id_, routed_id_);
95 pref->setAllowed(url_, allowed);
96 }
97 callback_.Run(allowed);
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698