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

Side by Side Diff: third_party/WebKit/Source/modules/webshare/NavigatorShare.cpp

Issue 2703333002: Web Share: Refactor Mojo interface to now return an enum error. (Closed)
Patch Set: Fix assignment statement. #oops Created 3 years, 9 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
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 }
34 NOTREACHED();
35 return String();
36 }
37
38 } // namespace
39
20 class NavigatorShare::ShareClientImpl final 40 class NavigatorShare::ShareClientImpl final
21 : public GarbageCollected<ShareClientImpl> { 41 : public GarbageCollected<ShareClientImpl> {
22 public: 42 public:
23 ShareClientImpl(NavigatorShare*, ScriptPromiseResolver*); 43 ShareClientImpl(NavigatorShare*, ScriptPromiseResolver*);
24 44
25 void callback(const String& error); 45 void callback(mojom::blink::ShareError);
26 46
27 void onConnectionError(); 47 void onConnectionError();
28 48
29 DEFINE_INLINE_TRACE() { 49 DEFINE_INLINE_TRACE() {
30 visitor->trace(m_navigator); 50 visitor->trace(m_navigator);
31 visitor->trace(m_resolver); 51 visitor->trace(m_resolver);
32 } 52 }
33 53
34 private: 54 private:
35 WeakMember<NavigatorShare> m_navigator; 55 WeakMember<NavigatorShare> m_navigator;
36 Member<ScriptPromiseResolver> m_resolver; 56 Member<ScriptPromiseResolver> m_resolver;
37 }; 57 };
38 58
39 NavigatorShare::ShareClientImpl::ShareClientImpl( 59 NavigatorShare::ShareClientImpl::ShareClientImpl(
40 NavigatorShare* navigator_share, 60 NavigatorShare* navigator_share,
41 ScriptPromiseResolver* resolver) 61 ScriptPromiseResolver* resolver)
42 : m_navigator(navigator_share), m_resolver(resolver) {} 62 : m_navigator(navigator_share), m_resolver(resolver) {}
43 63
44 void NavigatorShare::ShareClientImpl::callback(const String& error) { 64 void NavigatorShare::ShareClientImpl::callback(mojom::blink::ShareError error) {
45 if (m_navigator) 65 if (m_navigator)
46 m_navigator->m_clients.erase(this); 66 m_navigator->m_clients.erase(this);
47 67
48 if (error.isNull()) { 68 if (error == mojom::blink::ShareError::OK) {
49 m_resolver->resolve(); 69 m_resolver->resolve();
50 } else { 70 } else {
51 // TODO(mgiuca): Work out which error type to use. 71 // TODO(mgiuca): Work out which error type to use.
52 m_resolver->reject(DOMException::create(AbortError, error)); 72 m_resolver->reject(DOMException::create(AbortError, errorToString(error)));
53 } 73 }
54 } 74 }
55 75
56 void NavigatorShare::ShareClientImpl::onConnectionError() { 76 void NavigatorShare::ShareClientImpl::onConnectionError() {
57 m_resolver->reject( 77 m_resolver->reject(
58 DOMException::create(SecurityError, "WebShare is disabled.")); 78 DOMException::create(SecurityError, "WebShare is disabled."));
59 } 79 }
60 80
61 NavigatorShare::~NavigatorShare() = default; 81 NavigatorShare::~NavigatorShare() = default;
62 82
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 148
129 void NavigatorShare::onConnectionError() { 149 void NavigatorShare::onConnectionError() {
130 for (auto& client : m_clients) { 150 for (auto& client : m_clients) {
131 client->onConnectionError(); 151 client->onConnectionError();
132 } 152 }
133 m_clients.clear(); 153 m_clients.clear();
134 m_service.reset(); 154 m_service.reset();
135 } 155 }
136 156
137 } // namespace blink 157 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698