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

Side by Side Diff: Source/bindings/v8/CallbackPromiseAdapter.h

Issue 236133002: Pass script state to Web API object->script wrappable converter. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Also pass script state to "from" for error types. Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/modules/push_messaging/PushError.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 // This class provides an easy way to convert from a Script-exposed 40 // This class provides an easy way to convert from a Script-exposed
41 // class (i.e. a class that has a toV8() overload) that uses Promises 41 // class (i.e. a class that has a toV8() overload) that uses Promises
42 // to a WebKit API class that uses WebCallbacks. You can define 42 // to a WebKit API class that uses WebCallbacks. You can define
43 // seperate Success and Error classes, but this example just uses one 43 // seperate Success and Error classes, but this example just uses one
44 // object for both. 44 // object for both.
45 // 45 //
46 // To use: 46 // To use:
47 // 47 //
48 // class MyClass ... { 48 // class MyClass ... {
49 // typedef blink::WebMyClass WebType; 49 // typedef blink::WebMyClass WebType;
50 // static PassRefPtr<MyClass> from(blink::WebMyClass* webInstance) { 50 // static PassRefPtr<MyClass> from(NewScriptState*,
51 // blink::WebMyClass* webInstance) {
51 // // convert/create as appropriate, but often it's just: 52 // // convert/create as appropriate, but often it's just:
52 // return MyClass::create(adoptPtr(webInstance)); 53 // return MyClass::create(adoptPtr(webInstance));
53 // } 54 // }
54 // 55 //
55 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC lass, blink::WebMyClass>*: 56 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC lass, blink::WebMyClass>*:
56 // 57 //
57 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s) 58 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s)
58 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext)); 59 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext));
59 // 60 //
60 // Note that this class does not manage its own lifetime. In this 61 // Note that this class does not manage its own lifetime. In this
61 // example that ownership of the WebCallbacks instance is being passed 62 // example that ownership of the WebCallbacks instance is being passed
62 // in and it is up to the callee to free the WebCallbacks instace. 63 // in and it is up to the callee to free the WebCallbacks instace.
63 template<typename S, typename T> 64 template<typename S, typename T>
64 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> { 65 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> {
65 public: 66 public:
66 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver, Execution Context* context) 67 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver, Execution Context* context)
67 : m_resolver(resolver) 68 : m_resolver(resolver)
68 , m_scriptState(NewScriptState::current(toIsolate(context))) 69 , m_scriptState(NewScriptState::current(toIsolate(context)))
69 { 70 {
70 } 71 }
71 virtual ~CallbackPromiseAdapter() { } 72 virtual ~CallbackPromiseAdapter() { }
72 73
73 virtual void onSuccess(typename S::WebType* result) OVERRIDE 74 virtual void onSuccess(typename S::WebType* result) OVERRIDE
74 { 75 {
75 NewScriptState::Scope scope(m_scriptState.get()); 76 NewScriptState::Scope scope(m_scriptState.get());
76 m_resolver->resolve(S::from(result)); 77 m_resolver->resolve(S::from(m_scriptState.get(), result));
77 } 78 }
78 virtual void onError(typename T::WebType* error) OVERRIDE 79 virtual void onError(typename T::WebType* error) OVERRIDE
79 { 80 {
80 NewScriptState::Scope scope(m_scriptState.get()); 81 NewScriptState::Scope scope(m_scriptState.get());
81 m_resolver->reject(T::from(error)); 82 m_resolver->reject(T::from(m_scriptState.get(), error));
82 } 83 }
83 private: 84 private:
84 RefPtr<ScriptPromiseResolver> m_resolver; 85 RefPtr<ScriptPromiseResolver> m_resolver;
85 RefPtr<NewScriptState> m_scriptState; 86 RefPtr<NewScriptState> m_scriptState;
86 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); 87 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter);
87 }; 88 };
88 89
89 } // namespace WebCore 90 } // namespace WebCore
90 91
91 #endif 92 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/modules/push_messaging/PushError.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698