diff options
author | donnd <donnd@chromium.org> | 2015-12-01 18:39:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-02 02:40:45 +0000 |
commit | bd8a661bac1bd8616dc47db6aef02150a395b312 (patch) | |
tree | 8abb483de7ff15fd0cab600afbc896eaab0f7841 /content/public/renderer | |
parent | 09b1142c792685a7d133a551107af7143dd0b50f (diff) | |
download | chromium_src-bd8a661bac1bd8616dc47db6aef02150a395b312.zip chromium_src-bd8a661bac1bd8616dc47db6aef02150a395b312.tar.gz chromium_src-bd8a661bac1bd8616dc47db6aef02150a395b312.tar.bz2 |
Make GetOrCreateChromeObject public.
BUG=523554
Review URL: https://codereview.chromium.org/1458283002
Cr-Commit-Position: refs/heads/master@{#362597}
Diffstat (limited to 'content/public/renderer')
-rw-r--r-- | content/public/renderer/DEPS | 1 | ||||
-rw-r--r-- | content/public/renderer/chrome_object_extensions_utils.cc | 26 | ||||
-rw-r--r-- | content/public/renderer/chrome_object_extensions_utils.h | 24 |
3 files changed, 51 insertions, 0 deletions
diff --git a/content/public/renderer/DEPS b/content/public/renderer/DEPS index 2cfaa2e..0e936af 100644 --- a/content/public/renderer/DEPS +++ b/content/public/renderer/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+media/base", "+media/renderers", "+media/video", + "+gin", "+v8/include/v8.h", ] diff --git a/content/public/renderer/chrome_object_extensions_utils.cc b/content/public/renderer/chrome_object_extensions_utils.cc new file mode 100644 index 0000000..c2d0dc3 --- /dev/null +++ b/content/public/renderer/chrome_object_extensions_utils.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2014 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 "content/public/renderer/chrome_object_extensions_utils.h" + +#include "gin/converter.h" +#include "v8/include/v8.h" + +namespace content { + +v8::Local<v8::Object> GetOrCreateChromeObject(v8::Isolate* isolate, + v8::Local<v8::Object> global) { + v8::Local<v8::Object> chrome; + v8::Local<v8::Value> chrome_value = + global->Get(gin::StringToV8(isolate, "chrome")); + if (chrome_value.IsEmpty() || !chrome_value->IsObject()) { + chrome = v8::Object::New(isolate); + global->Set(gin::StringToSymbol(isolate, "chrome"), chrome); + } else { + chrome = v8::Local<v8::Object>::Cast(chrome_value); + } + return chrome; +} + +} // namespace content diff --git a/content/public/renderer/chrome_object_extensions_utils.h b/content/public/renderer/chrome_object_extensions_utils.h new file mode 100644 index 0000000..edb6d25 --- /dev/null +++ b/content/public/renderer/chrome_object_extensions_utils.h @@ -0,0 +1,24 @@ +// Copyright (c) 2014 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. + +#ifndef CONTENT_PUBLIC_RENDERER_CHROME_OBJECT_EXTENSIONS_UTILS_H_ +#define CONTENT_PUBLIC_RENDERER_CHROME_OBJECT_EXTENSIONS_UTILS_H_ + +#include "content/common/content_export.h" + +namespace v8 { +template<class T> class Local; +class Object; +class Isolate; +} // namespace v8 + +namespace content { + +CONTENT_EXPORT v8::Local<v8::Object> GetOrCreateChromeObject( + v8::Isolate* isolate, + v8::Local<v8::Object> global); + +} // namespace content + +#endif // CONTENT_PUBLIC_RENDERER_CHROME_OBJECT_EXTENSIONS_UTILS_H_ |