Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/app_banner/BeforeInstallPromptEvent.h" | 5 #include "modules/app_banner/BeforeInstallPromptEvent.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "core/frame/UseCounter.h" | 10 #include "core/frame/UseCounter.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 UserChoiceProperty::UserChoice)), | 27 UserChoiceProperty::UserChoice)), |
| 28 m_promptCalled(false) { | 28 m_promptCalled(false) { |
| 29 DCHECK(m_bannerService); | 29 DCHECK(m_bannerService); |
| 30 DCHECK(m_binding.is_bound()); | 30 DCHECK(m_binding.is_bound()); |
| 31 UseCounter::count(&frame, UseCounter::BeforeInstallPromptEvent); | 31 UseCounter::count(&frame, UseCounter::BeforeInstallPromptEvent); |
| 32 } | 32 } |
| 33 | 33 |
| 34 BeforeInstallPromptEvent::BeforeInstallPromptEvent( | 34 BeforeInstallPromptEvent::BeforeInstallPromptEvent( |
| 35 const AtomicString& name, | 35 const AtomicString& name, |
| 36 const BeforeInstallPromptEventInit& init) | 36 const BeforeInstallPromptEventInit& init) |
| 37 : Event(name, false, true), m_binding(this), m_promptCalled(false) { | 37 : Event(name, init), m_binding(this), m_promptCalled(false) { |
| 38 if (init.hasPlatforms()) | 38 if (init.hasPlatforms()) |
| 39 m_platforms = init.platforms(); | 39 m_platforms = init.platforms(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 BeforeInstallPromptEvent::~BeforeInstallPromptEvent() {} | 42 BeforeInstallPromptEvent::~BeforeInstallPromptEvent() {} |
| 43 | 43 |
| 44 void BeforeInstallPromptEvent::dispose() { | 44 void BeforeInstallPromptEvent::dispose() { |
| 45 m_bannerService.reset(); | 45 m_bannerService.reset(); |
| 46 m_binding.Close(); | 46 m_binding.Close(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 Vector<String> BeforeInstallPromptEvent::platforms() const { | 49 Vector<String> BeforeInstallPromptEvent::platforms() const { |
| 50 return m_platforms; | 50 return m_platforms; |
| 51 } | 51 } |
| 52 | 52 |
| 53 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) { | 53 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) { |
| 54 UseCounter::count(scriptState->getExecutionContext(), | 54 UseCounter::count(scriptState->getExecutionContext(), |
| 55 UseCounter::BeforeInstallPromptEventUserChoice); | 55 UseCounter::BeforeInstallPromptEventUserChoice); |
| 56 // |m_binding| must be bound to allow the AppBannerService to resolve the | 56 // |m_binding| must be bound to allow the AppBannerService to resolve the |
| 57 // userChoice promise. | 57 // userChoice promise. |
| 58 if (m_userChoice && m_binding.is_bound()) | 58 if (m_userChoice && m_binding.is_bound()) |
| 59 return m_userChoice->promise(scriptState->world()); | 59 return m_userChoice->promise(scriptState->world()); |
| 60 return ScriptPromise::rejectWithDOMException( | 60 return ScriptPromise::rejectWithDOMException( |
| 61 scriptState, | 61 scriptState, |
| 62 DOMException::create(InvalidStateError, | 62 DOMException::create(NotAllowedError, |
|
Matt Giuca
2017/04/26 05:28:50
This is technically a breaking change (though NOBO
Matt Giuca
2017/05/11 01:42:05
Per https://crbug.com/658639, this bug was a mista
dominickn
2017/05/11 01:51:57
Done.
| |
| 63 "userChoice cannot be accessed on this event.")); | 63 "userChoice cannot be accessed on this event.")); |
| 64 } | 64 } |
| 65 | 65 |
| 66 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState) { | 66 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState) { |
| 67 // |m_bannerService| must be bound to allow us to inform the AppBannerService | 67 // |m_bannerService| must be bound to allow us to inform the AppBannerService |
| 68 // to display the banner now. | 68 // to display the banner now. |
| 69 if (!defaultPrevented() || m_promptCalled || !m_bannerService.is_bound()) { | 69 if (!defaultPrevented() || m_promptCalled || !m_bannerService.is_bound()) { |
| 70 return ScriptPromise::rejectWithDOMException( | 70 return ScriptPromise::rejectWithDOMException( |
| 71 scriptState, | 71 scriptState, |
| 72 DOMException::create(InvalidStateError, | 72 DOMException::create(NotAllowedError, |
| 73 "The prompt() method may only be called once, " | 73 "The prompt() method may only be called once, " |
| 74 "following preventDefault().")); | 74 "following preventDefault().")); |
| 75 } | 75 } |
| 76 | 76 |
| 77 UseCounter::count(scriptState->getExecutionContext(), | 77 UseCounter::count(scriptState->getExecutionContext(), |
| 78 UseCounter::BeforeInstallPromptEventPrompt); | 78 UseCounter::BeforeInstallPromptEventPrompt); |
| 79 | 79 |
| 80 m_promptCalled = true; | 80 m_promptCalled = true; |
| 81 m_bannerService->DisplayAppBanner(); | 81 m_bannerService->DisplayAppBanner(); |
| 82 return ScriptPromise::castUndefined(scriptState); | 82 return ScriptPromise::castUndefined(scriptState); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 103 m_userChoice->resolve(AppBannerPromptResult::create( | 103 m_userChoice->resolve(AppBannerPromptResult::create( |
| 104 emptyAtom, AppBannerPromptResult::Outcome::Dismissed)); | 104 emptyAtom, AppBannerPromptResult::Outcome::Dismissed)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 DEFINE_TRACE(BeforeInstallPromptEvent) { | 107 DEFINE_TRACE(BeforeInstallPromptEvent) { |
| 108 visitor->trace(m_userChoice); | 108 visitor->trace(m_userChoice); |
| 109 Event::trace(visitor); | 109 Event::trace(visitor); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace blink | 112 } // namespace blink |
| OLD | NEW |