| 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/dom/ExecutionContext.h" |
| 10 #include "core/frame/UseCounter.h" | 11 #include "core/frame/UseCounter.h" |
| 11 #include "modules/app_banner/BeforeInstallPromptEventInit.h" | 12 #include "modules/app_banner/BeforeInstallPromptEventInit.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 BeforeInstallPromptEvent::BeforeInstallPromptEvent( | 16 BeforeInstallPromptEvent::BeforeInstallPromptEvent( |
| 16 const AtomicString& name, | 17 const AtomicString& name, |
| 17 LocalFrame& frame, | 18 LocalFrame& frame, |
| 18 mojom::blink::AppBannerServicePtr service_ptr, | 19 mojom::blink::AppBannerServicePtr service_ptr, |
| 19 mojom::blink::AppBannerEventRequest event_request, | 20 mojom::blink::AppBannerEventRequest event_request, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 44 void BeforeInstallPromptEvent::Dispose() { | 45 void BeforeInstallPromptEvent::Dispose() { |
| 45 banner_service_.reset(); | 46 banner_service_.reset(); |
| 46 binding_.Close(); | 47 binding_.Close(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 Vector<String> BeforeInstallPromptEvent::platforms() const { | 50 Vector<String> BeforeInstallPromptEvent::platforms() const { |
| 50 return platforms_; | 51 return platforms_; |
| 51 } | 52 } |
| 52 | 53 |
| 53 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* script_state) { | 54 ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* script_state) { |
| 54 UseCounter::Count(script_state->GetExecutionContext(), | 55 UseCounter::Count(ExecutionContext::From(script_state), |
| 55 UseCounter::kBeforeInstallPromptEventUserChoice); | 56 UseCounter::kBeforeInstallPromptEventUserChoice); |
| 56 // |m_binding| must be bound to allow the AppBannerService to resolve the | 57 // |m_binding| must be bound to allow the AppBannerService to resolve the |
| 57 // userChoice promise. | 58 // userChoice promise. |
| 58 if (user_choice_ && binding_.is_bound()) | 59 if (user_choice_ && binding_.is_bound()) |
| 59 return user_choice_->Promise(script_state->World()); | 60 return user_choice_->Promise(script_state->World()); |
| 60 return ScriptPromise::RejectWithDOMException( | 61 return ScriptPromise::RejectWithDOMException( |
| 61 script_state, | 62 script_state, |
| 62 DOMException::Create(kInvalidStateError, | 63 DOMException::Create(kInvalidStateError, |
| 63 "userChoice cannot be accessed on this event.")); | 64 "userChoice cannot be accessed on this event.")); |
| 64 } | 65 } |
| 65 | 66 |
| 66 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* script_state) { | 67 ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* script_state) { |
| 67 // |m_bannerService| must be bound to allow us to inform the AppBannerService | 68 // |m_bannerService| must be bound to allow us to inform the AppBannerService |
| 68 // to display the banner now. | 69 // to display the banner now. |
| 69 if (!defaultPrevented() || prompt_called_ || !banner_service_.is_bound()) { | 70 if (!defaultPrevented() || prompt_called_ || !banner_service_.is_bound()) { |
| 70 return ScriptPromise::RejectWithDOMException( | 71 return ScriptPromise::RejectWithDOMException( |
| 71 script_state, | 72 script_state, |
| 72 DOMException::Create(kInvalidStateError, | 73 DOMException::Create(kInvalidStateError, |
| 73 "The prompt() method may only be called once, " | 74 "The prompt() method may only be called once, " |
| 74 "following preventDefault().")); | 75 "following preventDefault().")); |
| 75 } | 76 } |
| 76 | 77 |
| 77 UseCounter::Count(script_state->GetExecutionContext(), | 78 UseCounter::Count(ExecutionContext::From(script_state), |
| 78 UseCounter::kBeforeInstallPromptEventPrompt); | 79 UseCounter::kBeforeInstallPromptEventPrompt); |
| 79 | 80 |
| 80 prompt_called_ = true; | 81 prompt_called_ = true; |
| 81 banner_service_->DisplayAppBanner(); | 82 banner_service_->DisplayAppBanner(); |
| 82 return ScriptPromise::CastUndefined(script_state); | 83 return ScriptPromise::CastUndefined(script_state); |
| 83 } | 84 } |
| 84 | 85 |
| 85 const AtomicString& BeforeInstallPromptEvent::InterfaceName() const { | 86 const AtomicString& BeforeInstallPromptEvent::InterfaceName() const { |
| 86 return EventNames::BeforeInstallPromptEvent; | 87 return EventNames::BeforeInstallPromptEvent; |
| 87 } | 88 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 user_choice_->Resolve(AppBannerPromptResult::Create( | 104 user_choice_->Resolve(AppBannerPromptResult::Create( |
| 104 g_empty_atom, AppBannerPromptResult::Outcome::kDismissed)); | 105 g_empty_atom, AppBannerPromptResult::Outcome::kDismissed)); |
| 105 } | 106 } |
| 106 | 107 |
| 107 DEFINE_TRACE(BeforeInstallPromptEvent) { | 108 DEFINE_TRACE(BeforeInstallPromptEvent) { |
| 108 visitor->Trace(user_choice_); | 109 visitor->Trace(user_choice_); |
| 109 Event::Trace(visitor); | 110 Event::Trace(visitor); |
| 110 } | 111 } |
| 111 | 112 |
| 112 } // namespace blink | 113 } // namespace blink |
| OLD | NEW |