summaryrefslogtreecommitdiffstats
path: root/chrome_frame/np_utils.cc
blob: 60beb1be29d7ada3c94ba009ef1a22b5ad48b6e7 (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 "chrome_frame/np_utils.h"

#include "chrome_frame/np_browser_functions.h"

namespace np_utils {

std::string GetLocation(NPP instance, NPObject* window) {
  if (!window) {
    // Can fail if the browser is closing (seen in Opera).
    return "";
  }

  std::string result;
  ScopedNpVariant href;
  ScopedNpVariant location;

  bool ok = npapi::GetProperty(instance,
                               window,
                               npapi::GetStringIdentifier("location"),
                               &location);
  DCHECK(ok);
  DCHECK(location.type == NPVariantType_Object);

  if (ok) {
    ok = npapi::GetProperty(instance,
                            location.value.objectValue,
                            npapi::GetStringIdentifier("href"),
                            &href);
    DCHECK(ok);
    DCHECK(href.type == NPVariantType_String);
    if (ok) {
      result.assign(href.value.stringValue.UTF8Characters,
                    href.value.stringValue.UTF8Length);
    }
  }

  return result;
}

}  // namespace np_utils