Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/webshare/NavigatorShare.h" | 5 #include "modules/webshare/NavigatorShare.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/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/frame/Navigator.h" | 11 #include "core/frame/Navigator.h" |
| 12 #include "modules/webshare/ShareData.h" | 12 #include "modules/webshare/ShareData.h" |
| 13 #include "platform/UserGestureIndicator.h" | 13 #include "platform/UserGestureIndicator.h" |
| 14 #include "platform/mojo/MojoHelper.h" | 14 #include "platform/mojo/MojoHelper.h" |
| 15 #include "public/platform/InterfaceProvider.h" | 15 #include "public/platform/InterfaceProvider.h" |
| 16 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 namespace { | |
| 21 | |
| 22 // Gets the human-friendly error message for a ShareError. |error| must not be | |
| 23 // ShareError::OK. | |
| 24 String errorToString(mojom::blink::ShareError error) { | |
| 25 switch (error) { | |
| 26 case mojom::blink::ShareError::OK: | |
| 27 NOTREACHED(); | |
| 28 break; | |
| 29 case mojom::blink::ShareError::INTERNAL_ERROR: | |
| 30 return "Share failed"; | |
| 31 case mojom::blink::ShareError::CANCELED: | |
| 32 return "Share canceled"; | |
| 33 case mojom::blink::ShareError::INVALID_TEMPLATE: | |
| 34 return "The target's url_template was invalid"; | |
| 35 } | |
| 36 NOTREACHED(); | |
| 37 return String(); | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 20 class NavigatorShare::ShareClientImpl final | 42 class NavigatorShare::ShareClientImpl final |
| 21 : public GarbageCollected<ShareClientImpl> { | 43 : public GarbageCollected<ShareClientImpl> { |
| 22 public: | 44 public: |
| 23 ShareClientImpl(NavigatorShare*, ScriptPromiseResolver*); | 45 ShareClientImpl(NavigatorShare*, ScriptPromiseResolver*); |
| 24 | 46 |
| 25 void callback(const String& error); | 47 void callback(mojom::blink::ShareError); |
| 26 | 48 |
| 27 void onConnectionError(); | 49 void onConnectionError(); |
| 28 | 50 |
| 29 DEFINE_INLINE_TRACE() { | 51 DEFINE_INLINE_TRACE() { |
| 30 visitor->trace(m_navigator); | 52 visitor->trace(m_navigator); |
| 31 visitor->trace(m_resolver); | 53 visitor->trace(m_resolver); |
| 32 } | 54 } |
| 33 | 55 |
| 34 private: | 56 private: |
| 35 WeakMember<NavigatorShare> m_navigator; | 57 WeakMember<NavigatorShare> m_navigator; |
| 36 Member<ScriptPromiseResolver> m_resolver; | 58 Member<ScriptPromiseResolver> m_resolver; |
| 37 }; | 59 }; |
| 38 | 60 |
| 39 NavigatorShare::ShareClientImpl::ShareClientImpl( | 61 NavigatorShare::ShareClientImpl::ShareClientImpl( |
| 40 NavigatorShare* navigator_share, | 62 NavigatorShare* navigator_share, |
| 41 ScriptPromiseResolver* resolver) | 63 ScriptPromiseResolver* resolver) |
| 42 : m_navigator(navigator_share), m_resolver(resolver) {} | 64 : m_navigator(navigator_share), m_resolver(resolver) {} |
| 43 | 65 |
| 44 void NavigatorShare::ShareClientImpl::callback(const String& error) { | 66 void NavigatorShare::ShareClientImpl::callback(mojom::blink::ShareError error) { |
| 45 if (m_navigator) | 67 if (m_navigator) |
| 46 m_navigator->m_clients.erase(this); | 68 m_navigator->m_clients.erase(this); |
| 47 | 69 |
| 48 if (error.isNull()) { | 70 if (error == mojom::blink::ShareError::OK) { |
| 49 m_resolver->resolve(); | 71 m_resolver->resolve(); |
| 50 } else { | 72 } else { |
| 51 // TODO(mgiuca): Work out which error type to use. | 73 // TODO(mgiuca): Work out which error type to use. |
|
Sam McNally
2017/02/21 23:02:40
Maybe it's time for this?
Matt Giuca
2017/02/23 04:18:37
Hmm, it's kind of a spec issue. What types would y
| |
| 52 m_resolver->reject(DOMException::create(AbortError, error)); | 74 m_resolver->reject(DOMException::create(AbortError, errorToString(error))); |
| 53 } | 75 } |
| 54 } | 76 } |
| 55 | 77 |
| 56 void NavigatorShare::ShareClientImpl::onConnectionError() { | 78 void NavigatorShare::ShareClientImpl::onConnectionError() { |
| 57 m_resolver->reject( | 79 m_resolver->reject( |
| 58 DOMException::create(SecurityError, "WebShare is disabled.")); | 80 DOMException::create(SecurityError, "WebShare is disabled.")); |
| 59 } | 81 } |
| 60 | 82 |
| 61 NavigatorShare::~NavigatorShare() = default; | 83 NavigatorShare::~NavigatorShare() = default; |
| 62 | 84 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 150 |
| 129 void NavigatorShare::onConnectionError() { | 151 void NavigatorShare::onConnectionError() { |
| 130 for (auto& client : m_clients) { | 152 for (auto& client : m_clients) { |
| 131 client->onConnectionError(); | 153 client->onConnectionError(); |
| 132 } | 154 } |
| 133 m_clients.clear(); | 155 m_clients.clear(); |
| 134 m_service.reset(); | 156 m_service.reset(); |
| 135 } | 157 } |
| 136 | 158 |
| 137 } // namespace blink | 159 } // namespace blink |
| OLD | NEW |