summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/dev/selection_dev.cc
blob: 7e1284bb66fba179eb253ed62bf5f70676173fc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/cpp/dev/selection_dev.h"

#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"

namespace pp {

namespace {

static const char kPPPSelectionInterface[] = PPP_SELECTION_DEV_INTERFACE;

PP_Var GetSelectedText(PP_Instance instance, PP_Bool html) {
  void* object =
      pp::Instance::GetPerInstanceObject(instance, kPPPSelectionInterface);
  if (!object)
    return Var().Detach();
  return static_cast<Selection_Dev*>(object)->
      GetSelectedText(PP_ToBool(html)).Detach();
}

const PPP_Selection_Dev ppp_selection = {
  &GetSelectedText
};

}  // namespace

Selection_Dev::Selection_Dev(Instance* instance)
    : associated_instance_(instance) {
  Module::Get()->AddPluginInterface(kPPPSelectionInterface, &ppp_selection);
  instance->AddPerInstanceObject(kPPPSelectionInterface, this);
}

Selection_Dev::~Selection_Dev() {
  Instance::RemovePerInstanceObject(associated_instance_,
                                    kPPPSelectionInterface, this);
}

}  // namespace pp