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

Side by Side Diff: third_party/WebKit/Source/modules/webusb/USB.cpp

Issue 2091713002: Specialize base::IsWeakReceiver for Blink weak pointers to support base::Bind (1/5) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +#include for build fix Created 4 years, 6 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 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/webusb/USB.h" 5 #include "modules/webusb/USB.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 USB::USB(LocalFrame& frame) 53 USB::USB(LocalFrame& frame)
54 : ContextLifecycleObserver(frame.document()) 54 : ContextLifecycleObserver(frame.document())
55 , m_clientBinding(this) 55 , m_clientBinding(this)
56 { 56 {
57 ThreadState::current()->registerPreFinalizer(this); 57 ThreadState::current()->registerPreFinalizer(this);
58 frame.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_deviceMana ger)); 58 frame.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_deviceMana ger));
59 m_deviceManager.set_connection_error_handler(createBaseCallback(bind(&USB::o nDeviceManagerConnectionError, WeakPersistentThisPointer<USB>(this)))); 59 m_deviceManager.set_connection_error_handler(createBaseCallback(bind(&USB::o nDeviceManagerConnectionError, wrapWeakPersistent(this))));
60 m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); 60 m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind());
61 } 61 }
62 62
63 USB::~USB() 63 USB::~USB()
64 { 64 {
65 // |m_deviceManager| and |m_chooserService| may still be valid but there 65 // |m_deviceManager| and |m_chooserService| may still be valid but there
66 // should be no more outstanding requests to them because each holds a 66 // should be no more outstanding requests to them because each holds a
67 // persistent handle to this object. 67 // persistent handle to this object.
68 DCHECK(m_deviceManagerRequests.isEmpty()); 68 DCHECK(m_deviceManagerRequests.isEmpty());
69 DCHECK(m_chooserServiceRequests.isEmpty()); 69 DCHECK(m_chooserServiceRequests.isEmpty());
(...skipping 29 matching lines...) Expand all
99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
100 ScriptPromise promise = resolver->promise(); 100 ScriptPromise promise = resolver->promise();
101 101
102 if (!m_chooserService) { 102 if (!m_chooserService) {
103 LocalFrame* frame = getExecutionContext() ? toDocument(getExecutionConte xt())->frame() : nullptr; 103 LocalFrame* frame = getExecutionContext() ? toDocument(getExecutionConte xt())->frame() : nullptr;
104 if (!frame) { 104 if (!frame) {
105 resolver->reject(DOMException::create(NotSupportedError)); 105 resolver->reject(DOMException::create(NotSupportedError));
106 return promise; 106 return promise;
107 } 107 }
108 frame->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_choos erService)); 108 frame->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_choos erService));
109 m_chooserService.set_connection_error_handler(createBaseCallback(bind(&U SB::onChooserServiceConnectionError, WeakPersistentThisPointer<USB>(this)))); 109 m_chooserService.set_connection_error_handler(createBaseCallback(bind(&U SB::onChooserServiceConnectionError, wrapWeakPersistent(this))));
110 } 110 }
111 111
112 String errorMessage; 112 String errorMessage;
113 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { 113 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) {
114 resolver->reject(DOMException::create(SecurityError, errorMessage)); 114 resolver->reject(DOMException::create(SecurityError, errorMessage));
115 } else if (!UserGestureIndicator::consumeUserGesture()) { 115 } else if (!UserGestureIndicator::consumeUserGesture()) {
116 resolver->reject(DOMException::create(SecurityError, "Must be handling a user gesture to show a permission request.")); 116 resolver->reject(DOMException::create(SecurityError, "Must be handling a user gesture to show a permission request."));
117 } else { 117 } else {
118 Vector<usb::DeviceFilterPtr> filters; 118 Vector<usb::DeviceFilterPtr> filters;
119 if (options.hasFilters()) { 119 if (options.hasFilters()) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DEFINE_TRACE(USB) 227 DEFINE_TRACE(USB)
228 { 228 {
229 EventTargetWithInlineData::trace(visitor); 229 EventTargetWithInlineData::trace(visitor);
230 ContextLifecycleObserver::trace(visitor); 230 ContextLifecycleObserver::trace(visitor);
231 visitor->trace(m_deviceManagerRequests); 231 visitor->trace(m_deviceManagerRequests);
232 visitor->trace(m_chooserServiceRequests); 232 visitor->trace(m_chooserServiceRequests);
233 visitor->trace(m_deviceCache); 233 visitor->trace(m_deviceCache);
234 } 234 }
235 235
236 } // namespace blink 236 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698