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