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

Side by Side Diff: mojo/edk/js/handle.cc

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
« no previous file with comments | « mojo/edk/js/handle.h ('k') | mojo/edk/js/handle_close_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/edk/js/handle.h"
6
7 #include "mojo/edk/js/handle_close_observer.h"
8
9 namespace mojo {
10 namespace js {
11
12 gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin };
13
14 HandleWrapper::HandleWrapper(MojoHandle handle)
15 : handle_(mojo::Handle(handle)) {
16 }
17
18 HandleWrapper::~HandleWrapper() {
19 NotifyCloseObservers();
20 }
21
22 void HandleWrapper::Close() {
23 NotifyCloseObservers();
24 handle_.reset();
25 }
26
27 void HandleWrapper::AddCloseObserver(HandleCloseObserver* observer) {
28 close_observers_.AddObserver(observer);
29 }
30
31 void HandleWrapper::RemoveCloseObserver(HandleCloseObserver* observer) {
32 close_observers_.RemoveObserver(observer);
33 }
34
35 void HandleWrapper::NotifyCloseObservers() {
36 if (!handle_.is_valid())
37 return;
38
39 FOR_EACH_OBSERVER(HandleCloseObserver, close_observers_, OnWillCloseHandle());
40 }
41
42 } // namespace js
43 } // namespace mojo
44
45 namespace gin {
46
47 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate,
48 const mojo::Handle& val) {
49 if (!val.is_valid())
50 return v8::Null(isolate);
51 return mojo::js::HandleWrapper::Create(isolate, val.value()).ToV8();
52 }
53
54 bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate,
55 v8::Handle<v8::Value> val,
56 mojo::Handle* out) {
57 if (val->IsNull()) {
58 *out = mojo::Handle();
59 return true;
60 }
61
62 gin::Handle<mojo::js::HandleWrapper> handle;
63 if (!Converter<gin::Handle<mojo::js::HandleWrapper> >::FromV8(
64 isolate, val, &handle))
65 return false;
66
67 *out = handle->get();
68 return true;
69 }
70
71 v8::Handle<v8::Value> Converter<mojo::MessagePipeHandle>::ToV8(
72 v8::Isolate* isolate, mojo::MessagePipeHandle val) {
73 return Converter<mojo::Handle>::ToV8(isolate, val);
74 }
75
76 bool Converter<mojo::MessagePipeHandle>::FromV8(v8::Isolate* isolate,
77 v8::Handle<v8::Value> val,
78 mojo::MessagePipeHandle* out) {
79 return Converter<mojo::Handle>::FromV8(isolate, val, out);
80 }
81
82
83 } // namespace gin
OLDNEW
« no previous file with comments | « mojo/edk/js/handle.h ('k') | mojo/edk/js/handle_close_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698